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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy