Class: ANTLR3::AST::Wizard::PatternLexer
- Inherits:
-
Object
- Object
- ANTLR3::AST::Wizard::PatternLexer
- Includes:
- Constants
- Defined in:
- lib/antlr3/tree/wizard.rb
Overview
A class that is used internally by AST::Wizard to tokenize tree patterns
Constant Summary collapse
- PATTERNS =
[ [ :space, /\s+/ ], [ :identifier, /[a-z_]\w*/i ], [ :open, /\(/ ], [ :close, /\)/ ], [ :percent, /%/ ], [ :colon, /:/ ], [ :dot, /\./ ], [ :argument, /\[((?:[^\[\]\\]|\\\[|\\\]|\\.)*?)\]/ ] ]
Constants included from Constants
Constants::BUILT_IN_TOKEN_NAMES, Constants::DEFAULT, Constants::DOWN, Constants::EOF, Constants::EOF_TOKEN, Constants::EOR_TOKEN_TYPE, Constants::HIDDEN, Constants::INVALID, Constants::INVALID_NODE, Constants::INVALID_TOKEN, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP
Instance Attribute Summary collapse
-
#error ⇒ Object
(also: #error?)
readonly
Returns the value of attribute error.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(pattern) ⇒ PatternLexer
constructor
A new instance of PatternLexer.
- #next_token ⇒ Object
Constructor Details
#initialize(pattern) ⇒ PatternLexer
Returns a new instance of PatternLexer.
145 146 147 148 149 150 |
# File 'lib/antlr3/tree/wizard.rb', line 145 def initialize( pattern ) @pattern = pattern.to_s @scanner = StringScanner.new( pattern ) @text = '' @error = false end |
Instance Attribute Details
#error ⇒ Object (readonly) Also known as: error?
Returns the value of attribute error.
144 145 146 |
# File 'lib/antlr3/tree/wizard.rb', line 144 def error @error end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
144 145 146 |
# File 'lib/antlr3/tree/wizard.rb', line 144 def pattern @pattern end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
144 145 146 |
# File 'lib/antlr3/tree/wizard.rb', line 144 def text @text end |
Instance Method Details
#next_token ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/antlr3/tree/wizard.rb', line 152 def next_token begin @scanner.eos? and return EOF type, = PATTERNS.find do |type, pattern| @scanner.scan( pattern ) end case type when nil type, @text, @error = EOF, '', true break when :identifier then @text = @scanner.matched when :argument # remove escapes from \] sequences in the text argument ( @text = @scanner[ 1 ] ).gsub!( /\\(?=[\[\]])/, '' ) end end while type == :space return type end |