Class: Archsight::Query::Lexer
- Inherits:
-
Object
- Object
- Archsight::Query::Lexer
- Defined in:
- lib/archsight/query/lexer.rb
Defined Under Namespace
Classes: Token
Constant Summary collapse
- KEYWORDS =
Keywords are case-insensitive
{ "and" => :AND, "or" => :OR, "not" => :NOT, "kind" => :KIND, "name" => :NAME, "none" => :NONE, "in" => :IN }.freeze
- TWO_CHAR_OPERATORS =
Two-character operators (must be checked before single-character)
{ "==" => :EQ, "!=" => :NEQ, "=~" => :MATCH, ">=" => :GTE, "<=" => :LTE, "->" => :OUTGOING_DIRECT, "~>" => :OUTGOING_TRANSITIVE, "<-" => :INCOMING_DIRECT, "<~" => :INCOMING_TRANSITIVE }.freeze
- SINGLE_CHAR_OPERATORS =
Single-character operators
{ ">" => :GT, "<" => :LT, "&" => :AND, "|" => :OR, "!" => :NOT }.freeze
Instance Method Summary collapse
-
#initialize(input) ⇒ Lexer
constructor
A new instance of Lexer.
- #tokenize ⇒ Object
Constructor Details
#initialize(input) ⇒ Lexer
Returns a new instance of Lexer.
53 54 55 56 57 |
# File 'lib/archsight/query/lexer.rb', line 53 def initialize(input) @input = input @position = 0 @tokens = [] end |
Instance Method Details
#tokenize ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/archsight/query/lexer.rb', line 59 def tokenize @tokens = [] while @position < @input.length skip_whitespace break if @position >= @input.length token = scan_token @tokens << token if token end @tokens << Token.new(:EOF, nil, @position) @tokens end |