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

Generated Ruby code contains invalid synthax in Ruby 3.0 #49

Closed
andsel opened this issue Jan 23, 2023 · 3 comments
Closed

Generated Ruby code contains invalid synthax in Ruby 3.0 #49

andsel opened this issue Jan 23, 2023 · 3 comments

Comments

@andsel
Copy link

andsel commented Jan 23, 2023

Using the following grammar:

my_grammar.treetop

grammar MyGrammar
  rule config
    (_ plugin_section)*  
  end

  rule comment
    (whitespace? "#" [^\r\n]* "\r"? "\n")+ 
  end

  rule _
    (comment / whitespace)* 
  end

  rule whitespace
    [ \t\r\n]+ 
  end

  rule plugin_section
    plugin_type _ "{"
      _ (plugin _)*
    "}"
    
  end

  rule plugin_type
    ("input" / "filter" / "output")
  end

  rule plugin
    name 
  end

  rule name
    (
      ([A-Za-z0-9_-]+ )
    )
  end
end

and compiling with

tt my_grammar.treetop

Generates my_grammar.rb which contains method named _1 which is not anymore valid syntax in Ruby 3.0, was deprecated since Ruby 2.7

module PluginSection1
    def plugin_type
      elements[0]
    end

    def _1
      elements[1]
    end

    def _2
      elements[3]
    end

  end

Usage of methods named with _, which now represents "numbered parameters" generates an error like:

_1 is reserved for numbered parameter
@cjheath
Copy link
Owner

cjheath commented Jan 24, 2023

Rename rule _. I can't make a global change to the names of accessor methods.

@andsel
Copy link
Author

andsel commented Jan 24, 2023

Thanks @cjheath that worked!

@andsel
Copy link
Author

andsel commented Jan 24, 2023

Not an issue in the library

@andsel andsel closed this as completed Jan 24, 2023
andsel added a commit to andsel/logstash that referenced this issue Jan 30, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue Feb 23, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue Mar 23, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue Apr 12, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue May 31, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue Jun 15, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
andsel added a commit to andsel/logstash that referenced this issue Jun 26, 2023
With Ruby 2.7 was deprecated the usage of `_1` (`_<n>`) identifier for future reseved usage.
With Ruby 3.0 the new synthax for "numbered parameters" was used, avoiding the usage of `_n` as method names.

Treetop's generated grammar contained `def _n` methods, mainly implied to the usage of `_` symbol in LSCL grammar.

This commit rename the `_` rule in the grammar to `cs` and replaces everywhere it's needed.

Explanation at cjheath/treetop#49
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

No branches or pull requests

2 participants