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.
48 49 50 |
# File 'lib/rouge/regex_lexer.rb', line 48 def initialize(rules) @rules = rules end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
47 48 49 |
# File 'lib/rouge/regex_lexer.rb', line 47 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.
94 95 96 |
# File 'lib/rouge/regex_lexer.rb', line 94 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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rouge/regex_lexer.rb', line 71 def rule(re, tok=nil, next_state=nil, &callback) if block_given? next_state = tok else tok = Token[tok] callback = proc do token tok case next_state when :pop! pop! when Symbol push next_state end # else pass end end rules << Rule.new(re, callback) end |