Split Token class into Token/Pattern
This commit is contained in:
1 parent
bf075a69f6
commit
38ae5ac7a1
8 files changed
+72
-38
No files matched your search
@@ -6,10 +6,6 @@ class Propane
|
||||
# Token name.
|
||||
attr_reader :name
|
||||
|
||||
# @return [String, nil]
|
||||
# Token pattern.
|
||||
attr_reader :pattern
|
||||
|
||||
# @return [Integer, nil]
|
||||
# Token ID.
|
||||
attr_reader :id
|
||||
@@ -18,46 +14,26 @@ class Propane
|
||||
# Line number where the token was defined in the input grammar.
|
||||
attr_reader :line_number
|
||||
|
||||
# @return [Regex::NFA, nil]
|
||||
# Regex NFA for matching the token.
|
||||
attr_reader :nfa
|
||||
|
||||
# Construct a Token.
|
||||
#
|
||||
# @param options [Hash]
|
||||
# Optional parameters.
|
||||
# @option options [String, nil] :name
|
||||
# Token name.
|
||||
# @option options [String, nil] :pattern
|
||||
# Token pattern.
|
||||
# @option options [Integer, nil] :id
|
||||
# Token ID.
|
||||
# @option options [Integer, nil] :line_number
|
||||
# Line number where the token was defined in the input grammar.
|
||||
def initialize(options)
|
||||
@name = options[:name]
|
||||
@pattern = options[:pattern]
|
||||
@id = options[:id]
|
||||
@line_number = options[:line_number]
|
||||
unless @pattern.nil?
|
||||
regex = Regex.new(@pattern)
|
||||
regex.nfa.end_state.accepts = self
|
||||
@nfa = regex.nfa
|
||||
end
|
||||
end
|
||||
|
||||
def c_name
|
||||
@name.upcase
|
||||
end
|
||||
|
||||
# Whether the token is a drop token.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the token is a drop token.
|
||||
def drop?
|
||||
@name.nil?
|
||||
end
|
||||
|
||||
def to_s
|
||||
@name
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user