class EBNF::LL1::Lexer::Terminal
Terminal
class, representing the terminal identifier and matching regular expression. Optionally, a Terminal
may include a map to turn case-insensitively matched terminals into their canonical form
Attributes
partial_regexp[R]
regexp[R]
type[R]
Public Class Methods
new(type, regexp, **options)
click to toggle source
@param [Symbol, nil] type @param [Regexp] regexp @param [Hash{Symbol => Object}] options @option options [Hash{String => String}] :map ({})
A mapping from terminals, in lower-case form, to their canonical value
@option options [Boolean] :unescape
Cause strings and codepoints to be unescaped.
@option options [Regexp] :partial_regexp
A regular expression matching the beginning of this terminal; useful for terminals that match things longer than the scanner low water mark.
# File lib/ebnf/ll1/lexer.rb, line 284 def initialize(type, regexp, **options) @type, @regexp, @options = type, regexp, options @partial_regexp = options[:partial_regexp] @map = options.fetch(:map, {}) end
Public Instance Methods
==(other)
click to toggle source
# File lib/ebnf/ll1/lexer.rb, line 301 def ==(other) case other when Array @type == other.first && @regexp == other.last when Terminal @type == other.type && @regexp == other.regexp end end
canonicalize(value)
click to toggle source
Map a terminal to it’s canonical form. If there is no map, ‘value` is returned. `value` is unescaped if there is no canonical mapping, and the `:unescape` option is set.
@param [String] value
value to canonicalize
@return [String]
# File lib/ebnf/ll1/lexer.rb, line 297 def canonicalize(value) @map.fetch(value.downcase, unescape(value)) end
Protected Instance Methods
unescape(string)
click to toggle source
Perform string and codepoint unescaping if defined for this terminal @param [String] string @return [String]
# File lib/ebnf/ll1/lexer.rb, line 315 def unescape(string) if @options[:unescape] EBNF::Unescape.unescape(string) else string end end