Today I discovered Marpa::R2 and it looks interesting. I am particularly interested in its scanless interface. I have looked throughthe JSON parser implemented with the scanless interface but I am still in doubt whether it would allow to convertmy grammer .. which is very unstrict .. almost any kind of string can be an expression and needs to accept unicode in \w.Expressions need to be separated by semicolon, but semicolons are optional where possible.text: /(?:\\\\|\\\)|\\\(|\w|[^()])+/
text3: /(?:\\\\|\\\[|\\}|\\{|\\;|\w|[^\[;{}])+/
expression: text3 (';'|)
else_block: 'else' instruction
if_block: 'if' '(' text ')' instruction
ifs_chain: if_block else_block(?)
comment: /\/\/[^\n]*(\n|$)/ {$item[1];} | /\/\*(\s|\S)+?\*\//
instruction: comment | ifs_chain | expressionSimplified example input:
Some ↑Unicode↑ in\;put;// comment which needs to be parsed, not ignoredSecond expression;
if(Something)
First thing
else
Other thing;
End
I would glad to get the advice first about practicality of converting such grammar .. if possible I would welcome any tips you could give. :)
Best Regards,Damian Kaczmarek--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
I am trying to make the AST a little more friendly for the code I already have for processing the format created by Parse::RecDescent, meaning:$ast->{start}->{instructions}->[0]->{instruction}->{expression}->{text} .. you get the ideaNow converting the format from Marpa would be simple enough but still requires doing a lot of manual work so I am wondering is there maybe some better way or preferred way for creating such AST structure?Such format would be especially nice if converted to JSON. Thanks a lot.
I have an issue with Marpa I find hard to understand: given this gist https://gist.github.com/jddurand/5173485 by Durand Jean-Damien when I change input to:my $input = "first; second; if(a) b; else c; d;";then I seem to trigger an error:Error in Scanless read: G1 Parse exhausted* Error was at string position: 24* String before error:first; second; if(a) b;\s* String after error:else c; d;Which is weird .. because I can't seem to find anything wrong with the grammar definition. Particularly buffing is that Given the string "first; second;" it reads out the second expression with the leading space, but the expression definition clearly says:expression ::= text3 ';'| text3text3_0 ~ '\\' | '\[' | '\}' | '\{' | '\;' | [\w] | [^\[;{}]text3 ::= text3_0+ws ~ [\s]+:discard ~ wsSo after encountering the ';' scanner should finish the text3 element for the parser and skip the latter whitespace but it doesn't happen here - could anybody point me in the right direction? How do you debug what the scanner does?Best Regards,Damian Kaczmarek--
You received this message because you are subscribed to a topic in the Google Groups "marpa parser" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/marpa-parser/8QK1x69MmXA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to marpa-parser...@googlegroups.com.
Thanks for the interest. ;) Don't want to be picky but current update reads "Second expression;" (from original example input) as "Secondexpression" disregarding the middle whitespace. The right approach I think would be to treat first character separately and accept only non-white then accept all characters until encountered a non-escaped semicolon. Unfortunately the way I tried to do it yields error in Marpa:text3_lead_0 ~ '\\' | '\[' | '\}' | '\{' | '\;' | [\w] | [^\s\[;{}]text3_rest_0 ~ '\\' | '\[' | '\}' | '\{' | '\;' | [\w] | [^\[;{}]text3_rest ::= text3_0+text3_lead ::= text3_lead_0text3 ::= text3_lead text3_restThe error:"::lhs" blessing only allowed if LHS is whitespace and alphanumericsLHS was <text3_rest>What's the rule of thumb in such cases?Thanks a lot,Best Regards, Damian