mondo: use stepcat for curly braces

This commit is contained in:
Felix Roos 2025-03-20 14:09:32 +01:00
parent 9626f3cc9a
commit e16295623d
No known key found for this signature in database
2 changed files with 18 additions and 10 deletions

View file

@ -12,10 +12,12 @@ export class MondoParser {
quotes_single: /^'(.*?)'/,
open_list: /^\(/,
close_list: /^\)/,
open_cat: /^</,
open_cat: /^</, // todo: rename angle
close_cat: /^>/,
open_seq: /^\[/,
open_seq: /^\[/, // todo: rename square
close_seq: /^\]/,
open_curly: /^\{/,
close_curly: /^\}/,
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
op: /^[*/:!@%]|^\.{2}/, // * / : ! @ % ..
pipe: /^\./,
@ -93,6 +95,9 @@ export class MondoParser {
if (next === 'open_seq') {
return this.parse_seq();
}
if (next === 'open_curly') {
return this.parse_curly();
}
return this.consume(next);
}
desugar_children(children) {
@ -256,6 +261,12 @@ export class MondoParser {
children = this.desugar(children, 'seq');
return { type: 'list', children };
}
parse_curly() {
let children = this.parse_pair('open_curly', 'close_curly');
children = [{ type: 'plain', value: 'curly' }, ...children];
children = this.desugar(children, 'curly');
return { type: 'list', children };
}
consume(type) {
// shift removes first element and returns it
const token = this.tokens.shift();