Skip to content

Commit

Permalink
feat(INT-723): add support for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Sep 27, 2023
1 parent d981710 commit d8746a2
Show file tree
Hide file tree
Showing 50 changed files with 600 additions and 89 deletions.
37 changes: 35 additions & 2 deletions src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export class JsonTemplateLexer {
return token.type === TokenType.PUNCT && token.value === value;
}

matchAssignment(): boolean {
return (
this.match('=') ||
this.match('+=') ||
this.match('-=') ||
this.match('*=') ||
this.match('/=')
);
}

matchLiteral(): boolean {
return JsonTemplateLexer.isLiteralToken(this.lookahead());
}
Expand Down Expand Up @@ -77,6 +87,14 @@ export class JsonTemplateLexer {
return this.match('...');
}

matchIncrement(): boolean {
return this.match('++');
}

matchDecrement(): boolean {
return this.match('--');
}

matchPathPartSelector(): boolean {
let token = this.lookahead();
if (token.type === TokenType.PUNCT) {
Expand Down Expand Up @@ -488,7 +506,7 @@ export class JsonTemplateLexer {
range: [start, this.idx],
};
}
} else if ('=!^$*><'.indexOf(ch1) >= 0) {
} else if ('=!^$><'.indexOf(ch1) >= 0) {
this.idx += 2;
return {
type: TokenType.PUNCT,
Expand Down Expand Up @@ -581,14 +599,29 @@ export class JsonTemplateLexer {
}
}

private scanPunctuatorForArithmeticAssignment(): Token | undefined {
let start = this.idx,
ch1 = this.codeChars[this.idx],
ch2 = this.codeChars[this.idx + 1];
if ('+-/*'.includes(ch1) && ch2 === '=') {
this.idx += 2;
return {
type: TokenType.PUNCT,
value: ch1 + ch2,
range: [start, this.idx],
};
}
}

private scanPunctuator(): Token | undefined {
return (
this.scanPunctuatorForDots() ||
this.scanPunctuatorForQuestionMarks() ||
this.scanPunctuatorForArithmeticAssignment() ||
this.scanPunctuatorForEquality() ||
this.scanPunctuatorForPaths() ||
this.scanPunctuatorForRepeatedTokens('?', 3) ||
this.scanPunctuatorForRepeatedTokens('|&*.=>?<', 2) ||
this.scanPunctuatorForRepeatedTokens('|&*.=>?<+-', 2) ||
this.scanSingleCharPunctuators()
);
}
Expand Down
4 changes: 0 additions & 4 deletions src/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export const binaryOperators = {
return endsWith(val2, val1);
},

'*==': containsStrict,

'==*': function (val1, val2): string {
return containsStrict(val2, val1);
},
Expand All @@ -107,8 +105,6 @@ export const binaryOperators = {
return contains(val2, val1);
},

'*=': contains,

'+': function (val1, val2): string {
return `${val1}+${val2}`;
},
Expand Down
Loading

0 comments on commit d8746a2

Please sign in to comment.