Skip to content

Instantly share code, notes, and snippets.

@deanebarker
Last active April 10, 2023 01:38
Show Gist options
  • Select an option

  • Save deanebarker/fb292bc4f4cfea320904ca84d0b39db6 to your computer and use it in GitHub Desktop.

Select an option

Save deanebarker/fb292bc4f4cfea320904ca84d0b39db6 to your computer and use it in GitHub Desktop.
An implementation of Emmet in C# using Parlot
Moved to a permanent repo here: https://github.com/deanebarker/Nemmet
@sebastienros

Copy link
Copy Markdown
  • Since lettersAndNumbers is always used with a ToString() you could return the string directly by adding .Then(ToString))
  • Do tags, ids and class names have the same rules for their content? Can ids start with a digit for instance? They are all using lettersAndNumbers. It could be better to give it a semantic name, like identifier. If you think that they have different rules then you can create others like tagName, className, identifier, ...
  • I am wondering who to handle escaping ] in strings between contained in [ ... ]. Maybe take a look at the "shortcodes" project on github that has a similar syntax.
  • I don't think Literals.Pattern(v => v != '}'), is necessary, it is equivalent to any char, since the separator should detect the ending automatically.
  • 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.

@deanebarker

Copy link
Copy Markdown
Author

@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?

@deanebarker

Copy link
Copy Markdown
Author

@sebastienros

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.

@sebastienros

Copy link
Copy Markdown

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.

@deanebarker

Copy link
Copy Markdown
Author

Weirdly, changing it to this...

.And(Literals.NonWhiteSpace())

...breaks with or without quotes.

@deanebarker

deanebarker commented Apr 5, 2023

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment