Ruby rubocop-ast: Difference between revisions
From wikinotes
No edit summary |
|||
(One intermediate revision by the same user not shown) | |||
Line 6: | Line 6: | ||
|- | |- | ||
| All AST nodes || https://github.com/rubocop/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_types.adoc | | All AST nodes || https://github.com/rubocop/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_types.adoc | ||
|- | |||
| Node Patterns (like AST selectors) || https://docs.rubocop.org/rubocop-ast/node_pattern.html | |||
|- | |- | ||
| official docs || https://docs.rubocop.org/rubocop-ast/ | | official docs || https://docs.rubocop.org/rubocop-ast/ | ||
Line 16: | Line 18: | ||
= Usage = | = Usage = | ||
<blockquote> | <blockquote> | ||
you can show the ast for a file | |||
<source lang="bash"> | |||
ruby-parse --legacy -e 'foo(1)' # print the AST | |||
(send nil :foo (int 1)) | |||
</source> | |||
there's a lisp-like DSL for matching nodes | there's a lisp-like DSL for matching nodes | ||
<source lang="javascript"> | <source lang="javascript"> |
Latest revision as of 00:22, 1 February 2024
A DSL for ruby parser that simplifies matching AST nodes.
Documentation
All AST nodes https://github.com/rubocop/rubocop-ast/blob/master/docs/modules/ROOT/pages/node_types.adoc Node Patterns (like AST selectors) https://docs.rubocop.org/rubocop-ast/node_pattern.html official docs https://docs.rubocop.org/rubocop-ast/ test patterns https://nodepattern.herokuapp.com/
Usage
you can show the ast for a file
ruby-parse --legacy -e 'foo(1)' # print the AST (send nil :foo (int 1))there's a lisp-like DSL for matching nodes
_ // any one thing ... // any number of items(const _ _) # any const (casgn <(const _ _) ...>) # any const being assigned via 'casgn'