From e3a6444f413ee01bb23aef9ac44bb0e69306296e Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 2 May 2025 08:30:09 +0200 Subject: [PATCH] mondo: support line comments --- packages/mondo/mondo.mjs | 5 ++++- packages/mondo/test/mondo.test.mjs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/mondo/mondo.mjs b/packages/mondo/mondo.mjs index bed568661..be7b2a203 100644 --- a/packages/mondo/mondo.mjs +++ b/packages/mondo/mondo.mjs @@ -8,6 +8,7 @@ This program is free software: you can redistribute it and/or modify it under th export class MondoParser { // these are the tokens we expect token_types = { + comment: /^\/\/(.*?)(?=\n|$)/, quotes_double: /^"(.*?)"/, quotes_single: /^'(.*?)'/, open_list: /^\(/, @@ -428,7 +429,9 @@ export class MondoRunner { } evaluate_list(ast, scope) { // 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 }; return this.evaluator(node, scope); } diff --git a/packages/mondo/test/mondo.test.mjs b/packages/mondo/test/mondo.test.mjs index 4ec18decb..6e9260f08 100644 --- a/packages/mondo/test/mondo.test.mjs +++ b/packages/mondo/test/mondo.test.mjs @@ -67,6 +67,14 @@ describe('mondo s-expressions parser', () => { { 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) => {