Class: Fabulator::Grammar::Expr::Token
- Inherits:
-
Object
- Object
- Fabulator::Grammar::Expr::Token
- Defined in:
- lib/fabulator/grammar/expr/token.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_alternative(a) ⇒ Object
-
#initialize ⇒ Token
constructor
A new instance of Token.
- #parse(cursor) ⇒ Object
- #to_regex ⇒ Object
Constructor Details
#initialize ⇒ Token
Returns a new instance of Token.
5 6 7 |
# File 'lib/fabulator/grammar/expr/token.rb', line 5 def initialize @alternatives = [ ] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/fabulator/grammar/expr/token.rb', line 3 def name @name end |
Instance Method Details
#add_alternative(a) ⇒ Object
9 10 11 |
# File 'lib/fabulator/grammar/expr/token.rb', line 9 def add_alternative(a) @alternatives << a end |
#parse(cursor) ⇒ Object
17 18 19 |
# File 'lib/fabulator/grammar/expr/token.rb', line 17 def parse(cursor) cursor.match_token(self.to_regex) end |
#to_regex ⇒ Object
13 14 15 |
# File 'lib/fabulator/grammar/expr/token.rb', line 13 def to_regex Regexp.union(@alternatives.collect{|a| a.to_regex }) end |