Fable-Fauna / Fable.Flora

Css theme type provider and tools
MIT License
59 stars 3 forks source link

Is there an easy way to ignore things that cannot be parsed? #7

Closed drk-mtr closed 5 years ago

drk-mtr commented 5 years ago

Thanks for sharing this - it's brilliant!

I was wondering whether there's an easy way to simply ignore everything that the CssParser cannot parse?

I started trying to get around some issues I was having by copy-paste hacking some parsers, for example to ignore the Keyframes section:

let parseKeyframesSection =
        whitespace >>. pstringCI "@keyframes" >>. whitespace >>. identifier >>. whitespace >>.
        between (pchar '{') (whitespace >>. pchar '}') parseCss2 |>> ignore

However I then realised I don't actually need types generated for most things, so I'd rather just ignore anything that fails to parse. My FParsec knowledge is poor though so I'm not getting very far.

musheddev commented 5 years ago

There is not a lot of cases where it is easy to do. I ignore all the rules and focus on getting selectors. This was only easy because a rules are in a {} block but media queries also have a {} block which I can't ignore, so I have to parse some of that. src

But as I re-read your question I realize you want to ignore stuff that doesn't parse, the issue with that is that you may wan't to recover and continue parsing on the other-side of the unparseable, however determining where to pickup... is the problem that I don't see an easy solution to.

musheddev commented 5 years ago

I added a contribution guide, recommendation thing, let me know what needs to be improved. https://github.com/Fable-Fauna/Fable.Flora/wiki/Contributing

drk-mtr commented 5 years ago

Thanks for the pointers. Yes that's what I was starting to suspect - each time I successfully ignored a line I'd soon find another case that failed - but I was looking at the whole of Bulma to be fair!

I was struggling to understand the order of operations. Sometimes things seemed to work when I called my test parser directly, but I couldn't seem to put my parser in the right place in terms of precedent, so other 'patterns' (probably misleading terminology in this context, hence the inverted commas) were matching first and failing. I was just using F# Interactive though, so I'm sure it'll be easier with a debugger on it. Unfortunately I'm new to both F# and development generally so my chances of helping make a properly spec-compliant parser are slim I'm afraid... but thanks again for the tool!