Class: Org::Rule
- Inherits:
-
Object
- Object
- Org::Rule
- Defined in:
- lib/org/rule.rb
Constant Summary collapse
- DEFAULT =
{ :bol => false, :start => nil, :end => nil, :unscan => false, }
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#regex ⇒ Object
Returns the value of attribute regex.
Instance Method Summary collapse
-
#initialize(name, regex, options = {}, &block) ⇒ Rule
constructor
A new instance of Rule.
- #match(state) ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/org/rule.rb', line 10 def name @name end |
#regex ⇒ Object
Returns the value of attribute regex.
10 11 12 |
# File 'lib/org/rule.rb', line 10 def regex @regex end |
Instance Method Details
#match(state) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/org/rule.rb', line 17 def match(state) scope, parent, scanner = state.scope, state.parent, state.scanner return if @options[:bol] and not scanner.bol? return false unless scanner.scan(@regex) scanner.unscan if @options[:unscan] name = @options[:tag] || @name token = Token.new(name, scanner.captures, &@block) return true if @options[:ignore] if mode = @options[:start] # puts "Start #{mode}" state.scope = mode.is_a?(Scope) ? mode : scope.scopes[mode] parent << token state.parent = token elsif mode = @options[:end] # puts "End #{mode}" state.parent = parent.parent state.scope = scope.parent else parent << token return true end end |