Freewind
Freewind

Reputation: 198388

How to write a parser for haml-like languages?

I want to write a parser and converter of haml-like languages, to parse them, and convert them into html content.

I found people usually use regular-expression to do this, but we have to write a lot of difficult regular expressions, which is not easy. Is there any tools or libraries to do it? I hope it in java and easy to use.

And, is there any articles about how to write such a parser? Thanks in advance!

Upvotes: 0

Views: 628

Answers (3)

Freewind
Freewind

Reputation: 198388

After some research and testing, I have to say, parboiled is the best tool for this job.

I have spent one day on the PEG and the good examples parboiled has provided, and another day on writing a simple sass parser. It was so easy and nature. Much easier and clearer than Regex. And the best thing is that I can use only Java to write the program, no external DSL needs to learn.

I want to say thank you very much to the author of parboiled, it's a great tool that I'm looking for.

Upvotes: 1

athena
athena

Reputation: 5709

You can use JavaCC. It is a yacc like parser generator. The output is the Java source code for the parser.

Upvotes: 0

Sjoerd
Sjoerd

Reputation: 75659

Regular expressions are usually a poor-mans-parser. A regex is not a real parser.

Parsers are usually generated by a parser generator. You specify the language in a specification file and the parser generator will convert this to sourcecode for your parser.

Upvotes: 1

Related Questions