Exit a state at end of line
See original GitHub issueThe language I’m writing for has “to end of line” sub languages. I use a “first token of the line” root state to dispatch to sub-states, but then am having trouble exiting those sub states at end of line. It seems there’s a design feature of Monaco to not match @eos
as a token. Can anyone suggest a mechanism by which I can achieve this?
In this case, a *
at the beginning of a statement (either start of line, or after a :
), is a “to end of line” keyword. But within a line it’s a multiply.
This *
should be tokenised as an operator
PRINT 10 * 20
This needs to be a single line keyword:
*FX200, 3
This shows both, the PRINT
bit is one, the *FX
part needs to be to end of line.
PRINT 2*3:*FX200, 3
Example of me trying to do this: https://github.com/mattgodbolt/owlet-editor/commit/b5ce47c63389891866eccf315ead7422b9890af7
The approach is to go to a “submode” once the first token is determined not to be a star (or a REM
or other). A colon exits the submode, and ideally I’d like “end of line” to do the same. Any thoughts? THanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (8 by maintainers)
[/.$/, 'keyword', '@pop']
is roughly where I was going with the EOS cases. The difficulty is that it doesn’t scale well, for example when you’re not sure what the last token in the line might be.E.g. if you have a function/command that takes an arbitrary number of parameters of any type:
call myfunc: true "string" 1234 false "another string"
In this case you’d need to have at least three @\pop cases, one for each type, perhaps more if you could pass expressions, objects or functions etc.
I don’t currently see any way around that (without resorting to the SOL detection I mentioned before). I don’t know if you could match on a linebreak? I didn’t have much luck doing so, but I won’t pretend to have tried for very long.
Indeed, brilliant! Thank you so much.