sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
Parser::Source::Comment::Associator#associate
Compute a mapping between AST nodes and comments.
A comment belongs to a certain node if it begins after end
of the previous node (if one exists) and ends before beginning of
the current node.
This rule is unambiguous and produces the result
one could reasonably expect; for example, this code
# foo
hoge # bar
+ fuga
will result in the following association:
{
(send (lvar :hoge) :+ (lvar :fuga)) =>
[#<Parser::Source::Comment (string):2:1 "# foo">],
(lvar :fuga) =>
[#<Parser::Source::Comment (string):3:8 "# bar">]
}
Note that {associate} produces unexpected result for nodes which are
equal but have distinct locations; comments for these nodes are merged.Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/parser-2.2.2.1/lib/parser/source/comment/associator.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Parser--Source--Comment--Associator-associate-for-pr
# Commit to gitgit add app/server/ruby/vendor/parser-2.2.2.1/lib/parser/source/comment/associator.rbgit commit -m "better docs for Parser::Source::Comment::Associator#associate"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Parser--Source--Comment--Associator-associate-for-pr
hub pull-request
# Celebrate!