- Author: Aday Cuesta Correa
- Email: alu0101483887@ull.edu.es
- npm i @adaycuestacorrea/lexer-generator-solution
https://ull-esit-gradoii-pl.github.io/practicas/lexer-generator.html
if (!validTokens.get(type).skip) {
let value = match.groups[type];
if (validTokens.get(type).value) value = validTokens.get(type).value(value);
result.push({type, value, line, col, length: regexp.lastIndex - start});
}
test('Assignment to string', () => {
const str = 'const varName = "value"';
const result = lexer(str);
const expected = [
{
type: 'RESERVEDWORD',
value: 'const',
col: 1,
line: 1,
length: 5,
},
{
type: 'ID',
value: 'varName',
col: 7,
line: 1,
length: 7,
},
{
type: 'OP',
value: '=',
col: 15,
line: 1,
length: 1,
},
{
type: 'STRING',
value: '"value"',
col: 17,
line: 1,
length: 7,
},
];
expect(result).toEqual(expected);
});