|
|
@@ -1,6 +1,5 @@
|
|
1
|
1
|
module Chervil
|
|
2
|
|
- class Parser
|
|
3
|
|
- def initialize(lexer)
|
|
|
2
|
+ class Parser def initialize(lexer)
|
|
4
|
3
|
@lexer = lexer
|
|
5
|
4
|
@tree = Array.new
|
|
6
|
5
|
@current_token = @lexer.get_next_token
|
|
|
@@ -14,7 +13,7 @@ module Chervil
|
|
14
|
13
|
end
|
|
15
|
14
|
|
|
16
|
15
|
def expr
|
|
17
|
|
- if @current_token.type == :number
|
|
|
16
|
+ if [:string, :number].include?(@current_token.type)
|
|
18
|
17
|
constant
|
|
19
|
18
|
elsif @current_token.type == :identifier
|
|
20
|
19
|
identifier
|
|
|
@@ -47,6 +46,9 @@ module Chervil
|
|
47
|
46
|
when :number
|
|
48
|
47
|
token = eat(:number)
|
|
49
|
48
|
AST::Number.new(token.value.to_f)
|
|
|
49
|
+ when :string
|
|
|
50
|
+ token = eat(:string)
|
|
|
51
|
+ AST::String.new(token.value)
|
|
50
|
52
|
end
|
|
51
|
53
|
end
|
|
52
|
54
|
|