Class: SrlRuby::Tokenizer
- Inherits:
-
Object
- Object
- SrlRuby::Tokenizer
- Defined in:
- lib/srl_ruby/tokenizer.rb
Overview
The tokenizer should recognize: Keywords: as, capture, letter Integer literals including single digit String literals (quote delimited) Single character literal Delimiters: parentheses '(' and ')' Separators: comma (optional)
Defined Under Namespace
Classes: ScanError
Constant Summary collapse
- @@lexeme2name =
{ '(' => 'LPAREN', ')' => 'RPAREN', ',' => 'COMMA' }.freeze
- @@keywords =
Here are all the SRL keywords (in uppercase)
%w[ ALL ALREADY AND ANY ANYTHING AS AT BACKSLASH BEGIN BETWEEN BY CAPTURE CASE CHARACTER DIGIT END EXACTLY FOLLOWED FROM HAD IF INSENSITIVE LAZY LEAST LETTER LINE LITERALLY MORE MULTI MUST NEVER NEW NO NOT NUMBER OF ONCE ONE OPTIONAL OR STARTS TAB TIMES TO TWICE UNTIL UPPERCASE WHITESPACE WITH ].map { |x| [x, x] } .to_h
Instance Attribute Summary collapse
-
#line_start ⇒ Object
readonly
Returns the value of attribute line_start.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
Instance Method Summary collapse
-
#initialize(source) ⇒ Tokenizer
constructor
A new instance of Tokenizer.
- #tokens ⇒ Object
Constructor Details
#initialize(source) ⇒ Tokenizer
Returns a new instance of Tokenizer.
80 81 82 83 |
# File 'lib/srl_ruby/tokenizer.rb', line 80 def initialize(source) @scanner = StringScanner.new(source) @lineno = 1 end |
Instance Attribute Details
#line_start ⇒ Object (readonly)
Returns the value of attribute line_start.
17 18 19 |
# File 'lib/srl_ruby/tokenizer.rb', line 17 def line_start @line_start end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
16 17 18 |
# File 'lib/srl_ruby/tokenizer.rb', line 16 def lineno @lineno end |
#scanner ⇒ Object (readonly)
Returns the value of attribute scanner.
15 16 17 |
# File 'lib/srl_ruby/tokenizer.rb', line 15 def scanner @scanner end |
Instance Method Details
#tokens ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/srl_ruby/tokenizer.rb', line 85 def tokens() tok_sequence = [] until @scanner.eos? token = _next_token tok_sequence << token unless token.nil? end return tok_sequence end |