File tree Expand file tree Collapse file tree 4 files changed +65
-8
lines changed Expand file tree Collapse file tree 4 files changed +65
-8
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,8 @@ if (!module.parent) {
93
93
94
94
Boolean : require ( './literals/boolean' ) ,
95
95
Nil : require ( './literals/nil' ) ,
96
+ NaN : require ( './literals/nan' ) ,
97
+ Infinity : require ( './literals/infinity' ) ,
96
98
97
99
// Things to do with variables
98
100
Property : require ( './parsers/property' ) ,
Original file line number Diff line number Diff line change
1
+ import CheddarPrimitive from './primitive' ;
2
+ import * as CheddarError from '../consts/err' ;
3
+
4
+ import { ClassType } from '../consts/types' ;
5
+
6
+ export default class CheddarInfinityToken extends CheddarPrimitive {
7
+ exec ( ) {
8
+ if ( this . curchar === 'I' &&
9
+ this . Code [ this . Index + 1 ] === 'n' &&
10
+ this . Code [ this . Index + 1 ] === 'f' &&
11
+ this . Code [ this . Index + 1 ] === 'i' &&
12
+ this . Code [ this . Index + 1 ] === 'n' &&
13
+ this . Code [ this . Index + 1 ] === 'i' &&
14
+ this . Code [ this . Index + 1 ] === 't' &&
15
+ this . Code [ this . Index + 2 ] === 'y' ) {
16
+ this . Index += 8 ;
17
+ return this . close ( ) ;
18
+ }
19
+
20
+ return this . close ( CheddarError . EXIT_NOTFOUND ) ;
21
+ }
22
+
23
+ get Type ( ) { return ClassType . Number }
24
+ }
Original file line number Diff line number Diff line change
1
+ import CheddarPrimitive from './primitive' ;
2
+ import * as CheddarError from '../consts/err' ;
3
+
4
+ import { ClassType } from '../consts/types' ;
5
+
6
+ export default class CheddarNilToken extends CheddarPrimitive {
7
+ exec ( ) {
8
+ if ( this . curchar === 'N' &&
9
+ this . Code [ this . Index + 1 ] === 'a' &&
10
+ this . Code [ this . Index + 2 ] === 'N' ) {
11
+ this . Index += 3 ;
12
+ return this . close ( ) ;
13
+ }
14
+
15
+ return this . close ( CheddarError . EXIT_NOTFOUND ) ;
16
+ }
17
+
18
+ get Type ( ) { return ClassType . Number }
19
+ }
Original file line number Diff line number Diff line change @@ -8,9 +8,14 @@ export default class CheddarLexer {
8
8
this . _Tokens = [ ] ;
9
9
}
10
10
11
- toAST ( ) {
11
+ toAST ( padding = '' ) {
12
+ let result = padding + this . constructor . name . replace ( / ^ C h e d d a r / g, '' ) + '\n' ;
13
+
14
+ padding = padding . replace ( / ├ $ / , '|' ) . replace ( / └ $ / , ' ' ) ;
15
+
12
16
let node = this ,
13
- tokens = this . _Tokens ;
17
+ tokens = this . _Tokens ,
18
+ newPadding = padding + '├' ;
14
19
15
20
while ( tokens . length === 1 && tokens [ 0 ] . isExpression ) {
16
21
node = tokens [ 0 ] ;
@@ -22,12 +27,19 @@ export default class CheddarLexer {
22
27
tokens = tokens [ 0 ] . _Tokens ;
23
28
}
24
29
25
- return node . constructor . name . replace ( / ^ C h e d d a r / g, '' ) + '\n' + tokens . map ( t => typeof t === 'string' ? "'" + t + "'" : t )
26
- . map ( t => t . toAST ? t . toAST ( ) : t . toString ( ) )
27
- . join ( tokens . every ( o => ! ( o instanceof CheddarLexer ) ) ? ' ' : '\n' )
28
- . replace ( / ^ / gm, ' │' )
29
- . replace ( / ^ │ (? ! [ └ ├ │ ┬ ] ) / gm, ' ├ ' ) ;
30
- //.replace(/^((?: [^└├│┬])*)├/gm, '└'); //wait only the last one
30
+ let separator = tokens . some ( token => token instanceof CheddarLexer ) ? '\n' : ' ' ;
31
+ if ( separator === ' ' )
32
+ result += padding + '└' ;
33
+
34
+ for ( let item of tokens . slice ( 0 , - 1 ) )
35
+ result += ( item . toAST ? item . toAST ( newPadding ) : typeof item === 'string' ? "'" + item + "'" : item ) + separator ;
36
+
37
+ if ( tokens . length ) {
38
+ let item = tokens [ tokens . length - 1 ] ;
39
+ result += item . toAST ? item . toAST ( padding + '└' ) : typeof item === 'string' ? "'" + item + "'" : item ;
40
+ }
41
+
42
+ return result ;
31
43
}
32
44
33
45
getChar ( ) {
You can’t perform that action at this time.
0 commit comments