Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node pattern compiler #105

Closed
wants to merge 2 commits into from

Conversation

marcandre
Copy link
Contributor

@marcandre marcandre commented Aug 29, 2020

This PR is a complete rewrite of the NodePattern compilation.

It aims to be 100% compatible, and also:

  • parser outputing AST (optionally with locations and comments)
  • debugging functionality (basic rake task for now)
  • allows multiple variable-length terms (strictly eager only)
  • also outputs code for a lambda

It's a big PR... I wrote a hacker's guide that should help explaining the main concepts.

Anyone interested in reviewing this? Thanks to @MaxLap for reviewing an initial draft 馃憤

@marcandre marcandre force-pushed the node_pattern_compiler branch 2 times, most recently from b0eb31b to 7637762 Compare August 29, 2020 21:34
@marcandre marcandre marked this pull request as draft August 30, 2020 04:24
@marcandre marcandre marked this pull request as ready for review August 30, 2020 04:54
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't dive into compiling, the rest looks very readable and elegant 馃憦

lib/rubocop/ast/node_pattern/lexer.rb Outdated Show resolved Hide resolved
a.is_a?(Range) ? a : INT_TO_RANGE[a]
end

INT_TO_RANGE = Hash.new { |h, k| h[k] = k..k }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a memory optimization technique? Why?
How does it work?

INT_TO_RANGE[1] === INT_TO_RANGE[1] # => false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure it's that useful. INT_TO_RANGE[42] # => 42..42. I wanted to avoid returning new Ranges all the time, or having to memoize it per node, but I might do that in the end (in the constructor, coz they are frozen).

lib/rubocop/ast/node_pattern/node.rb Outdated Show resolved Hide resolved
lib/rubocop/ast/node_pattern/node.rb Show resolved Hide resolved
.gitignore Show resolved Hide resolved
lib/rubocop/ast/node_pattern/compiler.rb Show resolved Hide resolved
lib/rubocop/ast/node_pattern/compiler.rb Outdated Show resolved Hide resolved
@marcandre marcandre marked this pull request as draft August 30, 2020 19:51
@marcandre marcandre force-pushed the node_pattern_compiler branch 2 times, most recently from 33bddc4 to f011935 Compare August 30, 2020 19:57
@marcandre
Copy link
Contributor Author

I have a proof of concept for multiple length union #79 (e.g. (send { nil? :foo | const :bar int+ })) which made apparent some needed small refactoring of the SequenceSubcompiler (upcoming), and of Node#in_sequence_head (pushed), so I put this as draft, but should be ready soon.

@jonatas
Copy link
Contributor

jonatas commented Sep 4, 2020

More than a year of compiler classes on a single PR @marcandre! 馃く
I'd love to spend an hour in a sharing session and you could walk through all these changes with me and other people interested in the code. We can even record or live stream it. wdyt?

@marcandre marcandre force-pushed the node_pattern_compiler branch 6 times, most recently from 5055a2c to 8b9c1b0 Compare September 11, 2020 18:33
@marcandre marcandre marked this pull request as ready for review September 11, 2020 18:36
@marcandre
Copy link
Contributor Author

Merged 馃帀 . To be released tomorrow.

@marcandre marcandre closed this Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants