Class: Fabulator::Grammar::Expr::Rule
- Inherits:
-
Object
- Object
- Fabulator::Grammar::Expr::Rule
- Defined in:
- lib/fabulator/grammar/expr/rule.rb
Instance Method Summary collapse
- #add_sequence(s) ⇒ Object
- #anchor_end ⇒ Object
- #anchor_start ⇒ Object
-
#initialize ⇒ Rule
constructor
A new instance of Rule.
- #to_regex ⇒ Object
Constructor Details
#initialize ⇒ Rule
Returns a new instance of Rule.
3 4 5 6 7 |
# File 'lib/fabulator/grammar/expr/rule.rb', line 3 def initialize @sequences = [ ] @anchor_start = false @anchor_end = false end |
Instance Method Details
#add_sequence(s) ⇒ Object
17 18 19 |
# File 'lib/fabulator/grammar/expr/rule.rb', line 17 def add_sequence(s) @sequences << s end |
#anchor_end ⇒ Object
13 14 15 |
# File 'lib/fabulator/grammar/expr/rule.rb', line 13 def anchor_end @anchor_end = true end |
#anchor_start ⇒ Object
9 10 11 |
# File 'lib/fabulator/grammar/expr/rule.rb', line 9 def anchor_start @anchor_start = true end |
#to_regex ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fabulator/grammar/expr/rule.rb', line 21 def to_regex r = %r{#{@sequences.collect{ |s| s.to_regex }}} if @anchor_start if @anchor_end %r{^#{r}$} else %r{^#{r}} end elsif @anchor_end %r{#{r}$} else r end end |