-
Hopefully the title makes sense. I have a grammar which I've simplified to this: module.exports = grammar({
name: 'buglang',
conflicts: $ => [
[$.with_foo, $.with_foo]
],
rules: {
source_file: $ => $.expr,
expr: $ => choice(
$.txt,
$.without_foo,
$.with_foo
),
txt: $ => "txt",
hsep: $ => /:{1,3}/,
without_foo: $ => seq(
$.expr,
$.hsep,
$.txt,
),
foo: $ => "foo",
bar: $ => "bar",
with_foo: $ => seq(
optional(seq($.bar, ",")),
$.expr,
":",
$.txt,
$.foo,
),
}
}); Here are two test files which SHOULD both parse: This one should parse as a
and this one as a
However, only the second one will actually parse, I think because it goes down the The error when parsing the first file is:
Anyway, a couple of things:
I'd appreciate any insight on how to write a parser to handle this kind of case. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I haven't wrapped my head around the details, but I tried tweaking the grammar a bit. For with_foo: $ =>
seq(optional(seq($.bar, ",")),
$.expr,
//":",
$.hsep,
$.txt,
$.foo), The following shows invocations [1] and corresponding results:
Neither seems to have any Sorry I'm not really answering your specific questions -- just sharing what some tinkering turned up here. Possibly it gives some additional information related to 4 though? [1] I used ahlinc's alpha from here for convenience of posting, but I also verified with the tree-sitter at commit c6d663f. |
Beta Was this translation helpful? Give feedback.
-
Thanks for looking at this. Yeah, I think it's because if you use Using just So, that's one thing to do, but I actually don't want that, because in my real grammar the |
Beta Was this translation helpful? Give feedback.
-
May be you have already -- but have you tried observing the output of the Those should give some details [1] about what actually happened, though interpreting the results takes getting used to (still not very good at that). [1] For |
Beta Was this translation helpful? Give feedback.
I also tried the following:
The results with
parse
were: