Conversation
msujew
left a comment
There was a problem hiding this comment.
Nice! Can you resolve the merge conflict so we can check the performance in the GitHub CI? Locally, it seems to look good. Only a 2-3% loss on the statemachine example, which is acceptable.
|
@msujew I discovered a problem with my main grammar. The problem arises when I create a token mode and start to create token declarations within this token mode. As soon as I complete the word "token", the language server seems to end up in a endless loop. It does not react anymore. After completing the declaration and restarting the LS, it works. So the problem is during editing incomplete grammars :-/... The rule If I would refactor the grammar to have no common prefix in the subrules of Before I refactor it would be good to discuss whether these members have a good syntax or whether we should alternate it (which could remove the common prefix automatically). |
|
Ideas... Some quick fixes or code actions come into my mind:
Or
|
467be1d to
2996cda
Compare
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 1ee2bcd | Previous: d803417 | Ratio |
|---|---|---|---|
BenchmarkWorkspaceCycle (typefox.dev/fastbelt/examples/statemachine) - MB/s |
11.92 MB/s |
5.21 MB/s |
2.29 |
This comment was automatically generated by workflow using github-action-benchmark.
No, it should fail out of the box. I can also complete this line as you started. But afterwards EDIT: I found out how to debug. Some kind of endless-loop in entered in this case. EDIT: Fixed the endless loop and another issue with the help of @msujew |
Lotes
left a comment
There was a problem hiding this comment.
Added some findings and also questions from my side.
msujew
left a comment
There was a problem hiding this comment.
Really solid contribution. Thanks a lot!
I noticed another few missing validations that we should add as part of this PR:
- Duplicate keyword/token definitions in the same token mode should result in an error. I.e. you can currently write
token mode default { "x" "x" }. - Similarly Token references should be unique in the same token mode. Right know, you can write something like
token mode default { hidden WS comment WS }without a validation error appearing. - When a token is declared, but not referenced in any token mode, the diagnostic appears on the first usage site. I would expect it on the token declaration itself. Also, similar to the keyword issue, this should be an error.
- A non-default token mode without a
popcommand should show a diagnostic.
17d7c0e to
557bdc7
Compare
msujew
left a comment
There was a problem hiding this comment.
Looking closer at some of the logic, I found some issues with some specific constellations. Works much better in general now, though!
There was a problem hiding this comment.
Good job @Lotes,
did a medium deep dive into this PR, Claude (Sonnet) did a much deeper one (the long headlined comments).
I like the tests you contributed a lot. However, esp. in the util tests I had trouble to get what the tested behavior is supposed to be.
Please add some docs, I left some remarks.
If the remarks provided by Claude don't make sense, feel free to ignore them.
(Maybe it's worth a comment, why they're invalid?)
sailingKieler
left a comment
There was a problem hiding this comment.
Thanks @Lotes for your updates.
I have a few more remark & questions for the sake of making things clear and precise.
Generate code # Conflicts: # internal/grammar/types_gen.go # Conflicts: # internal/grammar/types_gen.go Make my grammar changes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Rename Token Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Go back some steps Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Intermediate save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> # Conflicts: # lexer/lexer.go Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Last corrections Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add main generated files Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix examples Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix token groups internal language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix lookahead internal language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix completion internal language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix lexer mode pushing/popping Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Save generated files Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add parser tests for nested strings Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Rename back Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix grammar for keywords Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Bootstrap Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add some util tests Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix keyword positions Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix statemachine grammar Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add TokenTypeUsage Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add TokenModeMembers to token modes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Bootstrap Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix bootstrap Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove keywords by AstNode Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Bootstrap Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Clean up Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add token mode's keyword usages + Bootstrap Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Generate token modes language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add a validation for unique token mode names Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix lookahead language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix token_groups language Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add keyword selector for token modes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add token decls inside token modes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix scoping Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add group type and command to token groups Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Reduce redundancy when computing token modes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Split out lexer util functions Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Split generate token types Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Refactor collecting of lexer information Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix validation about unassigned rules Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Reintroduced another open TODO Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix two crossref tests Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix test about token group contaiining invalid token ref Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Apply review comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Reduce nesting by refactor out sub function Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix generated types Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add a benchmark test Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix linting errors Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Revert Fastbelt main grammar Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Shorten completion grammar Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add more unique rule name validations Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix rebase Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Rename GroupType to TokenModifier Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix recovery and check token names for nil Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add diagnostic for required default token mode Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add new validations Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add more tests Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix `token_modes.fb` STRING_CONTENT rule Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Persist more decisions Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add code about non-cross-file-token-modes Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Update docs Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove TODO.md Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Revert statemachine and arithmetics example Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Renamed groups and token types to token modifiers Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove unrelevant capacity, remove parser from lexer benchmark Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Use WaitGroup.Go(...) Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove doc.FindAstNode(...) Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add test for unreachable token mode cycle Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add more validations Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add validations Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix tests Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add another validation Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Removed the prefix from state number enum Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Finish rebasing with MAIN branch Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove unused private function Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix first comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Renamed token elements Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix tests finally Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove linting issues Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Replace repeating message with single function call Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add more suggestions from review comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add RegExpLiteral validation Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add token group names Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add all names instead Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Next 2 findings Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix markdown token names Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Update docs, resolve more comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix wording of groups to modifiers Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add docs Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add brief explanation Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Quick save Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add documentation Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Rephrase docs Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix docs Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Polishing comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add a validation Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Make helper classes private Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add clarifications Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Add clarifications about connections between token types, modes and usages Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fixed further comments Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> # Conflicts: # examples/arithmetics/benchmark_test.go # examples/arithmetics/lexer_gen.go # internal/atn/state_names.go # internal/generator/atn_generator.go # internal/generator/atn_md_generator.go # internal/generator/lexer_generator.go # internal/generator/parser_generator.go # internal/grammar/atn.md # internal/grammar/atn_gen.go # internal/grammar/completion_gen.go # internal/grammar/grammar.fb # internal/grammar/lexer_gen.go # internal/grammar/linker_gen.go # internal/grammar/parser_lookahead_gen.go # internal/grammar/symbol_kinds.go # internal/grammar/types_gen.go # internal/grammar/validator.go # internal/languages/completion/atn_gen.go # internal/languages/completion/parser_gen.go # internal/languages/token_groups/atn_gen.go # internal/languages/token_groups/parser_gen.go # internal/vscode-extensions/fastbelt/data/fastbelt.tmLanguage.json
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
16e70d8 to
67a8823
Compare
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
msujew
left a comment
There was a problem hiding this comment.
I let AI review the PR again. I believe some issues slipped in after rebasing on top of the infix rule changes. Also, some minor other issues have been found as well.
| return core.NewMapScopeFromSlice(symbols, nil) | ||
| } | ||
|
|
||
| func (s *scopeProviderImpl) ScopeRuleCallRule(ctx context.Context, reference *core.Reference[AbstractRule]) core.Scope { |
There was a problem hiding this comment.
Mode-local tokens cannot be referenced from another mode or a top-level group. Only this scope hoists TokenDecls nested under TokenMode > TokenDeclUsage. The generated ScopeTokenUsageTokenRef and ScopeTokenGroupTokenRefs (linker_gen.go:60-64) use the default chain, which only exports root children.
Repro: token mode S { token STR: /[a-z]+/ "" -> pop }andtoken mode O { STR "~" -> pop }(ortoken group G { STR }): Could not resolve reference to 'STR'and generation aborts, whileValue=STRin a parser rule links fine andcheckUniqueRuleNames` already treats the name as grammar-global.
Fix: register mode-level TokenDecl/TokenGroup under the grammar root in DescribeLocal (then this hand-walk and the Members() re-walks in the generator can go), or override the two token-ref scopes the same way.
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Fix unquoted lookup bug Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io> Remove compiled artifact Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
a07bd6f to
1d01544
Compare
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>

Closes #50
push(name)to push a token mode onto the token mode stackpopto pop the topmost token modemode(name)to set the topmost token modeKeywordSelector