Skip to content

Commit 1950ac4

Browse files
committed
Parse numbers
1 parent 8c9be74 commit 1950ac4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

parser/grammar.y

+1-2
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,7 @@ atom:
11171117
}
11181118
| NUMBER
11191119
{
1120-
// FIXME
1121-
$$ = nil
1120+
$$ = &ast.Num{ExprBase: ast.ExprBase{$<pos>$}, N: $1}
11221121
}
11231122
| strings
11241123
{

parser/grammar_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func TestGrammar(t *testing.T) {
2929
{"\"abc\" \"\"\"123\"\"\"", "eval", "Expression(body=Str(s='abc123'))"},
3030
{"b'abc'", "eval", "Expression(body=Bytes(s=b'abc'))"},
3131
{"b'abc' b'''123'''", "eval", "Expression(body=Bytes(s=b'abc123'))"},
32+
{"1234", "eval", "Expression(body=Num(n=1234))"},
33+
{"0x1234", "eval", "Expression(body=Num(n=4660))"},
34+
{"12.34", "eval", "Expression(body=Num(n=12.34))"},
3235
// END TESTS
3336
} {
3437
Ast, err := ParseString(test.in, test.mode)

parser/make_grammar_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
('"abc" """123"""', "eval"),
2222
("b'abc'", "eval"),
2323
("b'abc' b'''123'''", "eval"),
24+
("1234", "eval"),
25+
("0x1234", "eval"),
26+
("12.34", "eval"),
2427
]
2528

2629
def dump(source, mode):

0 commit comments

Comments
 (0)