Add grammar syntax to specify lexer mode for tokens and patterns
This commit is contained in:
1 parent
6bd9d4a09b
commit
b2d11321fe
3 files changed
+85
-5
No files matched your search
@@ -26,6 +26,10 @@ class Propane
|
||||
# Regex NFA for matching the pattern.
|
||||
attr_reader :nfa
|
||||
|
||||
# @return [String, nil]
|
||||
# Lexer mode for this pattern.
|
||||
attr_reader :mode
|
||||
|
||||
# Construct a Pattern.
|
||||
#
|
||||
# @param options [Hash]
|
||||
@@ -40,12 +44,15 @@ class Propane
|
||||
# Token to be returned by this pattern.
|
||||
# @option options [Integer, nil] :line_number
|
||||
# Line number where the token was defined in the input grammar.
|
||||
# @option options [String, nil] :mode
|
||||
# Lexer mode for this pattern.
|
||||
def initialize(options)
|
||||
@code = options[:code]
|
||||
@drop = options[:drop]
|
||||
@pattern = options[:pattern]
|
||||
@token = options[:token]
|
||||
@line_number = options[:line_number]
|
||||
@mode = options[:mode]
|
||||
regex = Regex.new(@pattern)
|
||||
regex.nfa.end_state.accepts = self
|
||||
@nfa = regex.nfa
|
||||
|
||||
Reference in new issue
Block a user