Class: Rouge::RegexLexer::StateDSL
- Inherits:
-
Object
- Object
- Rouge::RegexLexer::StateDSL
- Defined in:
- lib/rouge/regex_lexer.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(rules) ⇒ StateDSL
constructor
A new instance of StateDSL.
-
#mixin(lexer_name) ⇒ Object
Mix in the rules from another state into this state.
-
#rule(re, tok = nil, next_state = nil, &callback) ⇒ Object
Define a new rule for this state.
Constructor Details
#initialize(rules) ⇒ StateDSL
Returns a new instance of StateDSL.
63 64 65 |
# File 'lib/rouge/regex_lexer.rb', line 63 def initialize(rules) @rules = rules end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
62 63 64 |
# File 'lib/rouge/regex_lexer.rb', line 62 def rules @rules end |
Instance Method Details
#mixin(lexer_name) ⇒ Object
Mix in the rules from another state into this state. The rules from the mixed-in state will be tried in order before moving on to the rest of the rules in this state.
102 103 104 |
# File 'lib/rouge/regex_lexer.rb', line 102 def mixin(lexer_name) rules << lexer_name.to_s end |
#rule(re, token, next_state = nil) ⇒ Object #rule(re, &callback) ⇒ Object
Define a new rule for this state.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rouge/regex_lexer.rb', line 86 def rule(re, tok=nil, next_state=nil, &callback) callback ||= case next_state when :pop! proc { token tok; pop! } when Symbol proc { token tok; push next_state } else proc { token tok } end rules << Rule.new(re, callback) end |