Skip to content

Commit

Permalink
🐛 Fixed lexer infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexW00 committed Mar 3, 2022
1 parent 6e8b387 commit bc9358c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const compilerOptions: TinyCompOptions = {
// instantiate the compiler and compile the input
const compiler = new TinyComp(attributeGrammar, compilerOptions);
const compileResult = compiler.compile(
`print(Hello World,Optional Hello World)`
`print("Hello World", "Optional Hello World")`
);

// execute the compiled code (in this case it is a function that prints "Hello World" and "Optional Hello World")"),
Expand Down
4 changes: 2 additions & 2 deletions ts/attributeGrammar/lexicalRuleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default interface LexicalRuleset {
const exampleLexicalRuleset: LexicalRuleset = {
// the name of the token
whitespace: {
regex: /([^\S\r\n])/, // the regex that matches the token
regex: /([\s\r\n])/, // the regex that matches the token
},
printFunctionName: {
regex: /print/,
Expand All @@ -28,7 +28,7 @@ const exampleLexicalRuleset: LexicalRuleset = {
regex: /\)/,
},
parameter: {
regex: /[\w\d ]+/,
regex: /"[\w\d ]+"/,
},
parameterSeperator: {
regex: /,/,
Expand Down
2 changes: 1 addition & 1 deletion ts/lexer/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Lexer {
const matchResult = this.#matchNextToken(input, pos, line, char);
const match = matchResult?.token;

if (match) {
if (match && match.name != null && match.name !== "") {
// push token to tokens and update pos, line, char
tokens.push(match);
({ pos, line, char } = matchResult);
Expand Down

0 comments on commit bc9358c

Please sign in to comment.