natalie-lang / natalie_parser

NatalieParser is a zero-dependency, from-scratch, hand-written recursive descent parser for the Ruby Programming Language.
MIT License
63 stars 8 forks source link

Alias of global variables #60

Closed herwinw closed 1 year ago

herwinw commented 1 year ago

Source: https://github.com/ruby/spec/blob/c037246cb4034e677493fb9fe34a9042308c261c/language/alias_spec.rb#L281

The following line:

alias $b $a

Results in a parse error in Natalie

syntax error, unexpected gvar '$b' (expected: 'alias new name (first argument)'
herwinw commented 1 year ago

This looks like a duplicate of #49, maybe I've been using an older version of the parser?

herwinw commented 1 year ago

This has been fixed in the parser. To build with a newer parser:

git -C ext/natalie_parser fetch
git -C ext/natalie_parser checkout master
rake SKIP_SUBMODULE_UPDATE=1
bin/natalie -e '$a = $b'

However, this does break the compiler:

lib/natalie/compiler/pass1.rb:51:in `transform_expression': undefined method `transform_valias' for <Natalie::Compiler::Pass1:0x3c>:Natalie::Compiler::Pass1 (NoMethodError)

          Array(send(method, exp, used: used)).flatten
                ^^^^
Did you mean?  transform_alias
               transform_false
               transform_*bunch_of_other_methods*

It does have a couple of specs in the language folder (https://github.com/ruby/spec/blob/d31cf749dfa03ef7ddc317044c858226f5370568/language/alias_spec.rb#L279), so there is no explicit need to keep this case open or open a sequel case in natalie.