Hello.
I’m trying to create a mode for my little markup language (simple mode). In my language, a comment starts with a # and ends when a line break is encountered. This is my actual code :
When I look in the console, the message “blank line” appears 14 times when I refresh the page, while there are exactly 13 empty lines in my code. If I type text at the top of my code, the message appears 13 times. And if I type code at the bottom, the message appears 0 times. This may have a relationship?
That code doesn’t consume any token when there’s no comment, so it’d lead to a bunch of ‘mode failed to advance stream’ errors when you use it. If I fix that (always calling skipToEnd after the first if), it seems to work.
Sorry, I forgot to put stream.next () in my previous example, at the end of token function. But the problem is still there. It seems to work, but for me, it doesn’t work well (like on previous screenshot).
I’m confused. By doing a demo on JSFiddle, I realize that everything is working fine. The problem seems to come from elsewhere in my code. I’ll look. Thank you for your help.
I found !
It’s a bit strange. In the code of my application, I put the states in an object. Leaving the state of the object, everything works well. I did this to organize my code and find myself there, because I have many states and some are groupable. I modified the JSFiddle to show that it worked badly as it was. I wonder why.
State is copied by the editor, when creating resume points in the document to partially re-highlight it. By default, that does a shallow object copy, so your block object would be accidentally shared between all instances of the state. (You can define a custom copyState to work around this.)
This has nothing to do directly with blank lines, but if you’re asking because they’re causing trouble with your comments, this may be a better solution for your comments. Based on your requirements (a comment starts with a # and ends when a line break is encountered) it should be as simple as this:
/#.*/ works because ‘.’ does not include newline characters in javascript, so it will start with your ‘#’ and run through the end of the line. No need for a second state.
If you want to require that the comment is at the start of the line then you’ll need to add the ‘sol: true’ back in.