Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"I don't always want to spend insane amounts of time writing full AST parsers."

This is an effect of the language, not the problem space. Backtracking REs make it very easy to write bad code, and then most languages make writing the parsing code hard.

If you're in a language that makes parsing code easier, like Haskell, then the tradeoff isn't anywhere near so bad. I don't mention Haskell just because it's the trendy thingy, I mention it because parser combinators really do make for some very easy parsers, and while parser combinators can exist in other languages they tend to be very syntactically heavyweight. Perl 6 is supposed to make parsing perhaps even easier, but I haven't played with it to know.

Parsing isn't really that hard, it just plays very poorly with Algol-inspired syntax.

To be clear, since this is the Internet and the presumption of disagreement is strong, this post is not an explanation of why you're wrong... it's an explanation of why you're right. It is absolutely a true statement that in most languages you're way better off bashing out a dangerous RE than writing a proper parser even for something as simple as this.



Interesting. Can you point to a piece of Haskell code that does some parsing of roughly the same level of complexity of that in the OP, so that we can compare how long it takes to write such a parser compared to a regex?


Haskell is, in fact, a really good way to write parser code. That's the main thing I use Haskell for.

But how are you suggesting that Haskell could solve the problem of letting CoffeeScript plugins express which text they should apply to in a CoffeeScript text editor?


He's not suggesting that.

He's suggesting that the correct solution (recursive descent parser) is not inherently hard, but CoffeeScript makes it hard enough that people reach for less good approaches.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: