-
-
Save deanebarker/fb292bc4f4cfea320904ca84d0b39db6 to your computer and use it in GitHub Desktop.
| Moved to a permanent repo here: https://github.com/deanebarker/Nemmet |
@sebastienros Here's what I'm having trouble with:
Line 75 reads:
.And(Literals.String())
This will capture quoted strings. But I'm also fine with unquoted strings that have no whitespace.
So I try this:
.And(OneOf(
Literals.String(), Literals.NonWhiteSpace()
))
If the string is quoted, it still works. But if I remove the quotes, now it totally breaks -- like, the entire thing stops parsing there.
But I feel like that should be right. What am I missing?
I wonder how you can skip Up/Down/Next ... seems like important to me. And maybe there is a way to not need the Organize step.
I thought about this, but I'm not worried about it. That's a trivial step, and it's so much easier and clearer to parse to a serial list. Trying to organize the hierarchy within the parser would complicate it enormously for no practical benefit. Parsing is hard enough to understand as it is.
NonwhiteSpace should work, maybe I should add a unit test and see why it may fail.
You can pass a custom Context class that would have "LastParent" and then when a Up/Down/Next is found you can read the LastParent property. You are storing some information about what you parse for later when it needs to use it.
Weirdly, changing it to this...
.And(Literals.NonWhiteSpace())
...breaks with or without quotes.
I just realized if we got rid of the >^+ business and derived that based on indentation (see lines 22-29), then we'd essentially have re-created HAML.
UPDATE: and here we go... https://gist.github.com/deanebarker/fb292bc4f4cfea320904ca84d0b39db6#file-pleasehaml__donthurtem-cs
lettersAndNumbersis always used with aToString()you could return thestringdirectly by adding.Then(ToString))lettersAndNumbers. It could be better to give it a semantic name, likeidentifier. If you think that they have different rules then you can create others liketagName,className,identifier, ...]in strings between contained in[ ... ]. Maybe take a look at the "shortcodes" project on github that has a similar syntax.Literals.Pattern(v => v != '}'),is necessary, it is equivalent to any char, since the separator should detect the ending automatically.Organizestep.