Skip to content

Commit

Permalink
add more keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
peze authored and JacksonTian committed Nov 15, 2023
1 parent 5f445d6 commit aff0566
Show file tree
Hide file tree
Showing 8 changed files with 1,729 additions and 28 deletions.
118 changes: 99 additions & 19 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,27 +294,30 @@ class Lexer extends BaseLexer {
});
}

if (this.readch(1) === '*' && this.readch(2) === '*') {
// consume the /**
this.getch();
this.getch();
this.getch();
let str = '/**';
do {
str += this.peek;
if (this.readch(1) === '*') {
if(this.readch(2) === '*') {
// consume the /**
this.getch();
} while (!(this.peek === '*' && this.readch(1) === '/')); // ends with '*/'
// consume */
str += '*/';
this.getch();
this.getch();
return new Annotation(str, {
start: start,
end: this.loc()
});
this.getch();
this.getch();
let str = '/**';
do {
str += this.peek;
this.getch();
} while (!(this.peek === '*' && this.readch(1) === '/')); // ends with '*/'
// consume */
str += '*/';
this.getch();
this.getch();
return new Annotation(str, {
start: start,
end: this.loc()
});
}
//only /*
this.error(`Only '//' or '/**' allowed`);
}

this.error(`Only '//' or '/**' allowed`);
}

if (this.inTemplate) {
Expand Down Expand Up @@ -352,6 +355,78 @@ class Lexer extends BaseLexer {
}
}

if (this.peek === '+' && this.readch(1) === '+') {
// consume '++'
this.getch();
this.getch();
return new OperatorToken(Tag.INCREMENT, '++', {
start,
end: this.loc()
});
}

if (this.peek === '-' && this.readch(1) === '-') {
// consume '--'
this.getch();
this.getch();
return new OperatorToken(Tag.DECREMENT, '--', {
start,
end: this.loc()
});
}

if (this.peek === '=' && this.readch(1) === '=') {
// consume '=='
this.getch();
this.getch();
return new OperatorToken(Tag.EQ, '==', {
start,
end: this.loc()
});
}

if(this.peek === '!' && this.readch(1) === '=') {
// consume '!='
this.getch();
this.getch();
return new OperatorToken(Tag.NEQ, '!=', {
start,
end: this.loc()
});
}

if(this.peek === '>') {
this.getch();
if(this.peek === '=') {
// consume '>='
this.getch();
return new OperatorToken(Tag.GTE, '>=', {
start,
end: this.loc()
});
}
return new OperatorToken(Tag.GT, '>', {
start,
end: this.loc()
});
}

if(this.peek === '<') {
this.getch();
if(this.peek === '=') {
// consume '>='
this.getch();
return new OperatorToken(Tag.LTE, '<=', {
start,
end: this.loc()
});
}
return new OperatorToken(Tag.LT, '<', {
start,
end: this.loc()
});
}

switch (this.peek) {
case '\'':
case '"':
Expand All @@ -368,14 +443,18 @@ class Lexer extends BaseLexer {
// optionalType = "L" | "f" | "d" | ε
// decimalDigit = "0" … "9"
// optionalSign = "-" | ε
if (isDecimalDigit(this.peek) || this.peek === '-') {
if (isDecimalDigit(this.peek) ||
(this.peek === '-' && isDecimalDigit(this.readch(1)))) {
return this.parseNumber();
}

if (isLetter(this.peek) || this.peek === '_' ||
this.peek === '$') {
let str = '';
do {
if(this.peek === '-' && !isLetter(this.readch(1))) {
break;
}
str += this.peek;
this.getch();
} while (isLetter(this.peek) ||
Expand Down Expand Up @@ -457,6 +536,7 @@ class Lexer extends BaseLexer {
end: this.loc()
});
}

}

module.exports = Lexer;
Loading

0 comments on commit aff0566

Please sign in to comment.