-
Hello! So I have an almost-complete grammar for linker scripts (repo here: https://github.com/mtoohey31/tree-sitter-ld). I've translated things pretty carefully from the upstream yacc grammar ( I'm struggling with an issue though, where syntactically valid assignment statements inside sections result in errors (here's a test which demonstrates the bug). I've spent a while trying to figure it out on my own but haven't made any progress really. Assignment statements inside sections are correctly accepted without errors if I remove the Does anyone have any suggestions about what I might be doing wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
Well, I haven't looked deeply into your problem but I've made a linkerscript grammar here 😁 https://github.com/tree-sitter-grammars/tree-sitter-linkerscript N.B: it was quite annoying that there was no official spec/ebnf grammar for linkerscript, and I didn't feel like deeply understanding |
Beta Was this translation helpful? Give feedback.
-
I've been looking at it and found that changing the order of Looking the original lexer here https://github.com/bminor/binutils-gdb/blob/0fd455766e7f1bd7df328e104281b49a5268677f/ld/ldlex.l#L95 we can see that the character set for each type of Probably you should review the order of the other
|
Beta Was this translation helpful? Give feedback.
-
The link provided by @amaanq to his tree-sitter parser/grammar doesn't parse the problematic example https://github.com/mtoohey31/tree-sitter-ld/blob/52ce5060f5fa6d75c6b4cc6c0510f86e34747d8a/test/corpus/corpus.txt . |
Beta Was this translation helpful? Give feedback.
-
The original grammar have a lot of lexer states to help filter which/how tokens are valid in a specific context. |
Beta Was this translation helpful? Give feedback.
-
Hello @amaanq, thanks for reply ! |
Beta Was this translation helpful? Give feedback.
I've been looking at it and found that changing the order of
wildcard_name
seems to fix the problem (see bellow).Looking the original lexer here https://github.com/bminor/binutils-gdb/blob/0fd455766e7f1bd7df328e104281b49a5268677f/ld/ldlex.l#L95 we can see that the character set for each type of
NAME
is shown form the more general to less general, to reproduce it in tree-sitter we should order then in less general to more general (shortest match first, longest match last).Probably you should review the order of the other
NAME
s too.