I'm trying figure out how to write a Haskell Parsec parser for consuming any of these Ruby expressions:
hello("test", 'test2')
my_variable
hello(world("test"))
(hello + " " + world)
When the parser starts parsing at the beginning of any of these items, it should return the whole string and stop parsing at the end of item. If any of these items is followed by a comma, that comma should not be consumed.
I've tried a few times to write a parser for these types of expressions but with no success. It's not necessary to parse the sub-components of these expressions -- I don't need a full AST. I just need to consume and capture these sorts of chunks.
I thought maybe an adequate heuristic could involve just balancing any parentheses and eating all the content within outer balanced parentheses, in addition to any preceding identifier. But I need some help writing a parser that works this way.
this(example + "(with" + (weird ("bracketing)?")+"("))
unless you parse strings? You should bite the bullet and write astring
parser first, then anidentifier
parser, then mutually recursiveexpression
,argumentList
andfunction
parsers. You don't have to return an AST. – AndrewC