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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow underscore for method name with receiver #63

Merged
merged 1 commit into from
Apr 5, 2019

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Apr 4, 2019

Problem

_ matcher with method chain raises a syntax error.

example

rules:
  - id: sample.abc
    pattern:
      - b._
    message: a
    examples:
      - before: 'b.c'
        after: 'b'

m

$ querly test
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/parser-2.6.2.0/lib/parser/lexer.rb:10861: warning: assigned but unused variable - testEof
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/node_pair.rb:28: warning: `&' interpreted as argument prefix
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/pattern/parser.rb:825: warning: mismatched indentations at 'end' with 'module' at 9
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/pattern/parser.rb:826: warning: mismatched indentations at 'end' with 'module' at 8
Fatal error:
#<Querly::Rule::PatternSyntaxError: Pattern syntax error: rule=sample.abc, index=0, pattern=b._, where={}: 
parse error on value "_" (UNDERBAR)>
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/rule.rb:86:in `rescue in block in load'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/rule.rb:83:in `block in load'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/rule.rb:73:in `map'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/rule.rb:73:in `with_index'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/rule.rb:73:in `load'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/config.rb:62:in `block in config'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/config.rb:62:in `map'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/config.rb:62:in `config'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/config.rb:18:in `load'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/cli/test.rb:156:in `load_config'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/cli/test.rb:24:in `run'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/lib/querly/cli.rb:100:in `test'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
  /home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/querly-0.15.1/exe/querly:8:in `<top (required)>'
  /home/pocke/.rbenv/versions/trunk/bin/querly:23:in `load'
  /home/pocke/.rbenv/versions/trunk/bin/querly:23:in `<main>'

I think it is useful if it allows _ in method chain.

link: https://mobile.twitter.com/hanachin_/status/1113674668815159297

Goal

  • Allow _ in method chain, without args, without block. It means it supports only most simple case.
  • Support more syntax
    • like foo._(arg), block, etc
  • Add test

cc: @hanachin

@pocke pocke force-pushed the support-_-for-method-name branch from 67ae06d to c02a853 Compare April 4, 2019 12:15
| receiver method_name_or_ident LPAREN args RPAREN block { result = Expr::Send.new(receiver: val[0],
name: val[1],
args: val[3],
block: val[5]) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These patterns are completely duplicated.

@pocke pocke changed the title [WIP] Allow underscore for method name with receiver Allow underscore for method name with receiver Apr 4, 2019
@pocke pocke marked this pull request as ready for review April 4, 2019 12:16
@soutaro
Copy link
Owner

soutaro commented Apr 4, 2019

Looks great! I had worried about the pattern to match _ method calls but finally discovered there is no real problem; Querly has not supported it at all! 😄

Do you have any idea for this conflict?

@pocke
Copy link
Collaborator Author

pocke commented Apr 5, 2019

I guess we can use the meta (') and where features to detect actual _ method call. It looks a workaround, but it is a rare case.

@soutaro soutaro merged commit d4edd76 into soutaro:master Apr 5, 2019
@pocke pocke deleted the support-_-for-method-name branch April 5, 2019 07:14
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.

2 participants