class ConstraintParser::Lexer
Constants
- AND
- CASCADE
- CHECK
- COMMA
- DELETE
- EQ
- FOREIGN_KEY
- GT
- GTEQ
- IDENT
- INT
- LPAREN
- LT
- LTEQ
- MATCH_OP
- NEQ
- NEWLINE
- ON
- PLUS
- PRIMARY_KEY
- REFERENCES
- RESTRICT
- RPAREN
- SPACE
- STRLIT
- TYPE
- UNIQUE
Public Class Methods
new(io)
click to toggle source
# File lib/lexer.rb, line 33 def initialize io @ss = StringScanner.new io.read end
Public Instance Methods
next_token()
click to toggle source
# File lib/lexer.rb, line 37 def next_token return if @ss.eos? result = false while !result result = case when text = @ss.scan(SPACE) then #ignore whitespace # Operators when text = @ss.scan(GTEQ) then [:GTEQ, text] when text = @ss.scan(LTEQ) then [:LTEQ, text] when text = @ss.scan(NEQ) then [:NEQ, text] when text = @ss.scan(GT) then [:GT, text] when text = @ss.scan(LT) then [:LT, text] when text = @ss.scan(EQ) then [:EQ, text] when text = @ss.scan(PLUS) then [:PLUS, text] when text = @ss.scan(MATCH_OP) then [:MATCH_OP, text] when text = @ss.scan(AND) then [:AND, text] # SQL Keywords when text = @ss.scan(CHECK) then [:CHECK, text] when text = @ss.scan(UNIQUE) then [:UNIQUE, text] when text = @ss.scan(PRIMARY_KEY) then [:PRIMARY_KEY, text] when text = @ss.scan(FOREIGN_KEY) then [:FOREIGN_KEY, text] when text = @ss.scan(REFERENCES) then [:REFERENCES, text] when text = @ss.scan(DELETE) then [:DELETE, text] when text = @ss.scan(ON) then [:ON, text] when text = @ss.scan(RESTRICT) then [:RESTRICT, text] when text = @ss.scan(CASCADE) then [:CASCADE, text] # Values when text = @ss.scan(IDENT) then [:IDENT, text] when text = @ss.scan(STRLIT) then [:STRLIT, text] when text = @ss.scan(INT) then [:INT, text] # Syntax when text = @ss.scan(LPAREN) then [:LPAREN, text] when text = @ss.scan(RPAREN) then [:RPAREN, text] when text = @ss.scan(TYPE) then [:TYPE, text] when text = @ss.scan(COMMA) then [:COMMA, text] else x = @ss.getch [x, x] end end result end
tokenize()
click to toggle source
# File lib/lexer.rb, line 85 def tokenize out = [] while (tok = next_token) out << tok end out end