Skip to content

Commit bc9358c

Browse files
committed
🐛 Fixed lexer infinite loop
1 parent 6e8b387 commit bc9358c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const compilerOptions: TinyCompOptions = {
3131
// instantiate the compiler and compile the input
3232
const compiler = new TinyComp(attributeGrammar, compilerOptions);
3333
const compileResult = compiler.compile(
34-
`print(Hello World,Optional Hello World)`
34+
`print("Hello World", "Optional Hello World")`
3535
);
3636

3737
// execute the compiled code (in this case it is a function that prints "Hello World" and "Optional Hello World")"),

ts/attributeGrammar/lexicalRuleset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default interface LexicalRuleset {
1616
const exampleLexicalRuleset: LexicalRuleset = {
1717
// the name of the token
1818
whitespace: {
19-
regex: /([^\S\r\n])/, // the regex that matches the token
19+
regex: /([\s\r\n])/, // the regex that matches the token
2020
},
2121
printFunctionName: {
2222
regex: /print/,
@@ -28,7 +28,7 @@ const exampleLexicalRuleset: LexicalRuleset = {
2828
regex: /\)/,
2929
},
3030
parameter: {
31-
regex: /[\w\d ]+/,
31+
regex: /"[\w\d ]+"/,
3232
},
3333
parameterSeperator: {
3434
regex: /,/,

ts/lexer/Lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Lexer {
2828
const matchResult = this.#matchNextToken(input, pos, line, char);
2929
const match = matchResult?.token;
3030

31-
if (match) {
31+
if (match && match.name != null && match.name !== "") {
3232
// push token to tokens and update pos, line, char
3333
tokens.push(match);
3434
({ pos, line, char } = matchResult);

0 commit comments

Comments
 (0)