@@ -16,58 +16,92 @@ if (process.arch == "x64") {
16
16
module . exports = {
17
17
consume_NUM : function ( ) {
18
18
let ch = this . yytext [ 0 ] ;
19
- let hasPoint = this . yytext [ 0 ] === "." ;
19
+ let hasPoint = ch === "." ;
20
20
if ( ch === "0" ) {
21
21
ch = this . input ( ) ;
22
22
// check if hexa
23
23
if ( ch === "x" || ch === "X" ) {
24
24
ch = this . input ( ) ;
25
- if ( this . is_HEX ( ) ) {
25
+ if ( ch !== "_" && this . is_HEX ( ) ) {
26
26
return this . consume_HNUM ( ) ;
27
27
} else {
28
28
this . unput ( ch ? 2 : 1 ) ;
29
29
}
30
+ // check binary notation
30
31
} else if ( ch === "b" || ch === "B" ) {
31
32
ch = this . input ( ) ;
32
- if ( ch === "0" || ch === "1" ) {
33
+ if ( ( ch !== "_" && ch === "0" ) || ch === "1" ) {
33
34
return this . consume_BNUM ( ) ;
34
35
} else {
35
36
this . unput ( ch ? 2 : 1 ) ;
36
37
}
38
+ // @fixme check octal notation ? not usefull
37
39
} else if ( ! this . is_NUM ( ) ) {
38
40
if ( ch ) this . unput ( 1 ) ;
39
41
}
40
42
}
41
43
42
44
while ( this . offset < this . size ) {
45
+ const prev = ch ;
43
46
ch = this . input ( ) ;
44
- if ( ! this . is_NUM ( ) ) {
45
- if ( ch === "." && ! hasPoint ) {
46
- hasPoint = true ;
47
- } else if ( ch === "e" || ch === "E" ) {
48
- ch = this . input ( ) ;
49
- if ( ch === "+" || ch === "-" ) {
50
- ch = this . input ( ) ;
51
- if ( this . is_NUM ( ) ) {
52
- this . consume_LNUM ( ) ;
53
- return this . tok . T_DNUMBER ;
54
- } else {
55
- this . unput ( ch ? 3 : 2 ) ;
56
- break ;
57
- }
58
- } else if ( this . is_NUM ( ) ) {
59
- this . consume_LNUM ( ) ;
60
- return this . tok . T_DNUMBER ;
61
- } else {
62
- this . unput ( ch ? 2 : 1 ) ;
63
- break ;
64
- }
65
- } else {
66
- if ( ch ) this . unput ( 1 ) ;
47
+
48
+ if ( ch === "_" ) {
49
+ if ( prev === "_" ) {
50
+ // restriction : next to underscore / 1__1;
51
+ this . unput ( 2 ) ; // keep 1
52
+ break ;
53
+ }
54
+ if ( prev === "." ) {
55
+ // next to decimal point "1._0"
56
+ this . unput ( 1 ) ; // keep 1.
57
+ break ;
58
+ }
59
+ if ( prev === "e" || prev === "E" ) {
60
+ // next to e "1e_10"
61
+ this . unput ( 2 ) ; // keep 1
62
+ break ;
63
+ }
64
+ } else if ( ch === "." ) {
65
+ if ( hasPoint ) {
66
+ // no multiple points "1.0.5"
67
+ this . unput ( 1 ) ; // keep 1.0
68
+ break ;
69
+ }
70
+ if ( prev === "_" ) {
71
+ // next to decimal point "1_.0"
72
+ this . unput ( 2 ) ; // keep 1
67
73
break ;
68
74
}
75
+ hasPoint = true ;
76
+ continue ;
77
+ } else if ( ch === "e" || ch === "E" ) {
78
+ if ( prev === "_" ) {
79
+ // next to e "1_e10"
80
+ this . unput ( 1 ) ;
81
+ break ;
82
+ }
83
+ let undo = 2 ;
84
+ ch = this . input ( ) ;
85
+ if ( ch === "+" || ch === "-" ) {
86
+ // 1e-5
87
+ undo = 3 ;
88
+ ch = this . input ( ) ;
89
+ }
90
+ if ( this . is_NUM_START ( ) ) {
91
+ this . consume_LNUM ( ) ;
92
+ return this . tok . T_DNUMBER ;
93
+ }
94
+ this . unput ( ch ? undo : undo - 1 ) ; // keep only 1
95
+ break ;
96
+ }
97
+
98
+ if ( ! this . is_NUM ( ) ) {
99
+ // example : 10.0a
100
+ if ( ch ) this . unput ( 1 ) ; // keep 10.0
101
+ break ;
69
102
}
70
103
}
104
+
71
105
if ( hasPoint ) {
72
106
return this . tok . T_DNUMBER ;
73
107
} else if ( this . yytext . length < MAX_LENGTH_OF_LONG - 1 ) {
@@ -110,7 +144,7 @@ module.exports = {
110
144
let ch ;
111
145
while ( this . offset < this . size ) {
112
146
ch = this . input ( ) ;
113
- if ( ch !== "0" && ch !== "1" ) {
147
+ if ( ch !== "0" && ch !== "1" && ch !== "_" ) {
114
148
if ( ch ) this . unput ( 1 ) ;
115
149
break ;
116
150
}
0 commit comments