44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/predicator/lexer.rb', line 44
def tokenize
until @ss.eos?
case
when @ss.scan(SPACE)
when text = @ss.scan(DOT)
@tokens.push [:tDOT, text]
when text = @ss.scan(LPAREN)
@tokens.push [:tLPAREN, text]
when text = @ss.scan(RPAREN)
@tokens.push [:tRPAREN, text]
when text = @ss.scan(NEQ)
@tokens.push [:tNEQ, text]
when text = @ss.scan(GEQ)
@tokens.push [:tGEQ, text]
when text = @ss.scan(LEQ)
@tokens.push [:tLEQ, text]
when text = @ss.scan(GT)
@tokens.push [:tGT, text]
when text = @ss.scan(LT)
@tokens.push [:tLT, text]
when text = @ss.scan(EQ)
@tokens.push [:tEQ, text]
when text = @ss.scan(BANG)
@tokens.push [:tBANG, text]
when text = @ss.scan(DATE)
args = [ @ss[1], @ss[2], @ss[3] ].map(&:to_i)
@tokens.push [:tDATE, args]
when text = @ss.scan(FLOAT)
@tokens.push [:tFLOAT, text]
when text = @ss.scan(INTEGER)
@tokens.push [:tINTEGER, text]
when text = @ss.scan(TRUE)
@tokens.push [:tTRUE, text]
when text = @ss.scan(FALSE)
@tokens.push [:tFALSE, text]
when text = @ss.scan(AND)
@tokens.push [:tAND, text]
when text = @ss.scan(OR)
@tokens.push [:tOR, text]
when text = @ss.scan(BETWEEN)
@tokens.push [:tBETWEEN, text]
when text = @ss.scan(BLANK)
@tokens.push [:tBLANK, text]
when text = @ss.scan(PRESENT)
@tokens.push [:tPRESENT, text]
when text = @ss.scan(STRING)
@tokens.push [:tSTRING, text[1..-2]]
when text = @ss.scan(IDENTIFIER)
@tokens.push [:tIDENTIFIER, text]
else
raise "Unexpected characters: #{@ss.peek(5).inspect}"
end
end
@tokens.push [false, false]
end
|