File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,16 @@ export function tokenize(str: string) {
5555 const tokens = [ ] ;
5656 let buffer = '' ;
5757 let type = TokenType . UNKNOWN ;
58+ let parenDepth = 0 ;
5859
5960 for ( const s of str ) {
6061
62+ if ( [ '(' , '[' , '{' ] . includes ( s ) ) {
63+ parenDepth ++ ;
64+ } else if ( [ ')' , ']' , '}' ] . includes ( s ) ) {
65+ parenDepth -- ;
66+ }
67+
6168 // Handle Strings
6269 if ( s === '"' ) {
6370 const newType : TokenType = ( ( ( type as TokenType ) === TokenType . STR ) ? TokenType . UNKNOWN : TokenType . STR ) ;
@@ -71,6 +78,22 @@ export function tokenize(str: string) {
7178 continue ;
7279 }
7380
81+ // Special handling for commas
82+ if ( s === ',' ) {
83+ // If we're in a number and not inside parenthesis include the comma
84+ if ( type === TokenType . NUM && parenDepth === 0 ) {
85+ buffer += s ;
86+ continue ;
87+ }
88+ // Otherwise treat it as an operator
89+ const token = createToken ( buffer , type ) ;
90+ if ( token ) tokens . push ( token ) ;
91+ tokens . push ( new ExprOperator ( ',' ) ) ;
92+ buffer = '' ;
93+ type = TokenType . UNKNOWN ;
94+ continue ;
95+ }
96+
7497 const sType = s . match ( / [ 0 - 9 . ] / ) ? TokenType . NUM :
7598 IDENTIFIER_SYMBOLS . includes ( s ) ? TokenType . VAR :
7699 OPERATOR_SYMBOLS . includes ( s ) ? TokenType . OP :
You can’t perform that action at this time.
0 commit comments