Skip to content

Commit

Permalink
Add option(...) rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Nov 5, 2023
1 parent 74735f1 commit e863b49
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 265 deletions.
7 changes: 6 additions & 1 deletion lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Lexer
attr_accessor :status
attr_accessor :end_symbol

SYMBOLS = %w(%{ %} %% { } \[ \] : \| ;)
SYMBOLS = %w(%{ %} %% { } \[ \] \\( \\) : \| ;)
PERCENT_TOKENS = %w(
%union
%token
Expand All @@ -29,6 +29,9 @@ class Lexer
%empty
%code
)
PARAMETERIZING_TOKENS = %w(
option
)

def initialize(text)
@scanner = StringScanner.new(text)
Expand Down Expand Up @@ -89,6 +92,8 @@ def lex_token
return [@scanner.matched, @scanner.matched]
when @scanner.scan(/#{PERCENT_TOKENS.join('|')}/)
return [@scanner.matched, @scanner.matched]
when @scanner.scan(/#{PARAMETERIZING_TOKENS.join('|')}/)
return [@scanner.matched, @scanner.matched]
when @scanner.scan(/[\?\+\*]/)
return [@scanner.matched, @scanner.matched]
when @scanner.scan(/<\w+>/)
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/lexer/token/parameterizing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Lexer
class Token
class Parameterizing < Token
def option?
self.s_value == "?"
%w(option ?).include?(self.s_value)
end

def nonempty_list?
Expand Down
Loading

0 comments on commit e863b49

Please sign in to comment.