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
#initialize(name, regex, options = {}, &block) ⇒ Rule
Returns a new instance of Rule.
12 13 14 15 |
# File 'lib/org/rule.rb', line 12 def initialize(name, regex, = {}, &block) @name, @regex, @block = name, regex, block = DEFAULT.merge() end |
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 [:bol] and not scanner.bol? return false unless scanner.scan(@regex) scanner.unscan if [:unscan] name = [:tag] || @name token = Token.new(name, scanner.captures, &@block) return true if [:ignore] if mode = [:start] # puts "Start #{mode}" state.scope = mode.is_a?(Scope) ? mode : scope.scopes[mode] parent << token state.parent = token elsif mode = [:end] # puts "End #{mode}" state.parent = parent.parent state.scope = scope.parent else parent << token return true end end |