Skip to content

Commit

Permalink
Merge pull request #88 from makenowjust/lex-at
Browse files Browse the repository at this point in the history
Fix lexing `@10` in user codes correctly
  • Loading branch information
yui-knk committed Aug 22, 2023
2 parents a201d21 + 87ab5c3 commit 47b3912
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def lex_user_code(ss, line, column, lines)
references << [:dollar, ss[2], tag, str.length, str.length + ss[0].length - 1]
when ss.scan(/@\$/) # @$
references << [:at, "$", nil, str.length, str.length + ss[0].length - 1]
when ss.scan(/@(\d)+/) # @1
when ss.scan(/@(\d+)/) # @1
references << [:at, Integer(ss[1]), nil, str.length, str.length + ss[0].length - 1]
when ss.scan(/{/)
brace_count += 1
Expand Down
12 changes: 10 additions & 2 deletions spec/lrama/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ class : keyword_class tSTRING keyword_end %prec tPLUS
tARGS
{ 5; }
tBODY
{ $2; $3; $5; $7; $$ = 1; }
{ $2; $3; $5; $7; $10; $$ = 1;
@2; @3; @5; @7; @10; @$ = 1; }
;
%%
INPUT
Expand All @@ -362,7 +363,14 @@ class : keyword_class tSTRING keyword_end %prec tPLUS
[:dollar, 3, nil, 6, 7],
[:dollar, 5, nil, 10, 11],
[:dollar, 7, nil, 14, 15],
[:dollar, "$", nil, 18, 19]
[:dollar, 10, nil, 18, 20],
[:dollar, "$", nil, 23, 24],
[:at, 2, nil, 43, 44],
[:at, 3, nil, 47, 48],
[:at, 5, nil, 51, 52],
[:at, 7, nil, 55, 56],
[:at, 10, nil, 59, 61],
[:at, "$", nil, 64, 65],
],
])
end
Expand Down

0 comments on commit 47b3912

Please sign in to comment.