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
- 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_TOKEN, Constants::INVALID_TOKEN_TYPE, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP
Instance Attribute Summary (collapse)
-
- (Object) error
(also: #error?)
readonly
Returns the value of attribute error.
-
- (Object) pattern
readonly
Returns the value of attribute pattern.
-
- (Object) text
readonly
Returns the value of attribute text.
Instance Method Summary (collapse)
-
- (PatternLexer) initialize(pattern)
constructor
A new instance of PatternLexer.
- - (Object) next_token
Constructor Details
- (PatternLexer) initialize(pattern)
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
- (Object) error (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 |
- (Object) pattern (readonly)
Returns the value of attribute pattern
144 145 146 |
# File 'lib/antlr3/tree/wizard.rb', line 144 def pattern @pattern end |
- (Object) text (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
- (Object) next_token
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 |