mondo: support line comments
This commit is contained in:
parent
30fd4c5dec
commit
e3a6444f41
2 changed files with 12 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
export class MondoParser {
|
export class MondoParser {
|
||||||
// these are the tokens we expect
|
// these are the tokens we expect
|
||||||
token_types = {
|
token_types = {
|
||||||
|
comment: /^\/\/(.*?)(?=\n|$)/,
|
||||||
quotes_double: /^"(.*?)"/,
|
quotes_double: /^"(.*?)"/,
|
||||||
quotes_single: /^'(.*?)'/,
|
quotes_single: /^'(.*?)'/,
|
||||||
open_list: /^\(/,
|
open_list: /^\(/,
|
||||||
|
|
@ -428,7 +429,9 @@ export class MondoRunner {
|
||||||
}
|
}
|
||||||
evaluate_list(ast, scope) {
|
evaluate_list(ast, scope) {
|
||||||
// evaluate all children before evaluating list (dont mutate!!!)
|
// evaluate all children before evaluating list (dont mutate!!!)
|
||||||
const args = ast.children.map((arg) => this.evaluate(arg, scope));
|
const args = ast.children
|
||||||
|
.filter((child) => child.type !== 'comment') // ignore comments
|
||||||
|
.map((arg) => this.evaluate(arg, scope));
|
||||||
const node = { type: 'list', children: args };
|
const node = { type: 'list', children: args };
|
||||||
return this.evaluator(node, scope);
|
return this.evaluator(node, scope);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,14 @@ describe('mondo s-expressions parser', () => {
|
||||||
{ type: 'number', value: '22.3' },
|
{ type: 'number', value: '22.3' },
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
|
it('should parse comments', () =>
|
||||||
|
expect(p('a // hello')).toEqual({
|
||||||
|
type: 'list',
|
||||||
|
children: [
|
||||||
|
{ type: 'plain', value: 'a' },
|
||||||
|
{ type: 'comment', value: '// hello' },
|
||||||
|
],
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
let desguar = (a) => {
|
let desguar = (a) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue