Skip to content

Commit d973733

Browse files
committed
support negative numbers
1 parent 523d45b commit d973733

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

doc/grammars/const-expr.peg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ ConstantExpr
99
/ ConstantFetch
1010

1111
ConstantFloat
12-
= [0-9]+ '.' [0-9]* ConstantFloatExp?
13-
/ [0-9]* '.' [0-9]+ ConstantFloatExp?
14-
/ [0-9]+ ConstantFloatExp
12+
= '-'? [0-9]+ '.' [0-9]* ConstantFloatExp?
13+
/ '-'? [0-9]* '.' [0-9]+ ConstantFloatExp?
14+
/ '-'? [0-9]+ ConstantFloatExp
1515

1616
ConstantFloatExp
17-
= [eE] [0-9]+
17+
= [eE] '-'? [0-9]+
1818

1919
ConstantInt
20-
= [0-9]+
20+
= '-'? [0-9]+
2121

2222
ConstantTrue
2323
= [tT][rR][uU][eE]

src/Lexer/Lexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ private function initialize(): void
131131
self::TOKEN_CLOSE_PHPDOC => '\\*/',
132132
self::TOKEN_PHPDOC_TAG => '@[a-z-]++',
133133

134-
self::TOKEN_FLOAT => '(?:[0-9]++\\.[0-9]*+(?:e[0-9]++)?)|(?:[0-9]*+\\.[0-9]++(?:e[0-9]++)?)|(?:[0-9]++e[0-9]++)',
135-
self::TOKEN_INTEGER => '[0-9]++',
134+
self::TOKEN_FLOAT => '(?:-?[0-9]++\\.[0-9]*+(?:e-?[0-9]++)?)|(?:-?[0-9]*+\\.[0-9]++(?:e-?[0-9]++)?)|(?:-?[0-9]++e-?[0-9]++)',
135+
self::TOKEN_INTEGER => '-?[0-9]++',
136136
self::TOKEN_SINGLE_QUOTED_STRING => '\'(?:\\\\.|[^\'])*+\'',
137137
self::TOKEN_DOUBLE_QUOTED_STRING => '"(?:\\\\.|[^"])*+"',
138138

0 commit comments

Comments
 (0)