BRACES = /[\(\)\[\]\{\}\.]/
OPERATORS = /[:,<>*\/=+\-\$?!]+/
INTEGER = /[0-9]+/
- FLOATING = /[0-9]+(\.[0-9]+)?/
+ FLOATING = /[0-9]+\.[0-9]+/
STRING = /"(\\"|[^"])*"/
ID_TYPES = {
"true" => :bool,
type = :eof
if @data.scan(IDENT)
type = get_id_type(@data.matched)
-# elsif @data.scan(FLOATING)
-# type = :float
+ elsif @data.scan(FLOATING)
+ type = :float
elsif @data.scan(INTEGER)
type = :int
elsif @data.scan(STRING)
:if => { prefix: :if_expr, infix: nil, level: :none },
:ident => { prefix: :variable, infix: nil, level: :none },
:bool => { prefix: :constant, infix: nil, level: :none },
+ :float => { prefix: :constant, infix: nil, level: :none },
:int => { prefix: :constant, infix: nil, level: :none },
:string => { prefix: :constant, infix: nil, level: :none },
:char => { prefix: :constant, infix: nil, level: :none },
def constant()
if (@prev.type == :int)
- Val.new(location(), :int, @prev.text.to_f)
+ Val.new(location(), :int, @prev.text.to_i)
+ elsif (@prev.type == :float)
+ Val.new(location(), :float, @prev.text.to_f)
elsif (@prev.type == :string)
Val.new(location(), :string, @prev.text)
elsif (@prev.type == :bool)
it "will recognize 'true' as a bool" do
expect(parse_and_check("true")).to eq :bool
end
+
it "will recognize 'false' as a bool" do
expect(parse_and_check("false")).to eq :bool
end
+
it "will recognize '123' as an int" do
expect(parse_and_check("123")).to eq :int
end
- it "will recognize '123.0' as a float"
+
+ it "will recognize '123.0' as a float" do
+ expect(parse_and_check("123.0")).to eq :float
+ end
+
it "will recognize '\"abc\"' as a string" do
expect(parse_and_check("\"abc\"")).to eq :string
end