title: How to parse/identify double quoted string from the big expression using MARPA:R2 perl
body: <p>Problem in parsing/identifying double quoted string from the big expression.</p>
  
  <pre><code>use strict;
  use Marpa::R2;
  use Data::Dumper;
  
  my $grammar = Marpa::R2::Scanless::G-&gt;new({
      default_action =&gt; '[values]',
      source =&gt; \(&lt;&lt;'END_OF_SOURCE'),
  
  :start ::= expression
  
  expression ::= expression OP expression
  expression ::= expression COMMA expression
  expression ::= func LPAREN PARAM RPAREN
  expression ::= PARAM
  PARAM ::= STRING | REGEX_STRING
  
  :discard    ~ sp
  sp          ~ [\s]+
  
  COMMA                      ~ [,]
  STRING                     ~ [^ \/\(\),&amp;:\"~]+
  REGEX_STRING               ~ yet to identify
  OP                         ~ ' - ' | '&amp;'
  LPAREN                     ~ '('
  RPAREN                     ~ ')'
  func                       ~ 'func'
  
  END_OF_SOURCE
  });
  
  my $recce = Marpa::R2::Scanless::R-&gt;new({grammar =&gt; $grammar});
  </code></pre>
  
  <p><code>my $input1 = "func(foo)&amp;func(bar)";</code> -> able to parse it properly by parsing foo and bar as STRING LEXEME.</p>
  
  <p><code>my $input2 = "\"foo\"";</code> -> Here, I want to parse foo as regex_string LEXEME. REGEX_STRING is something which is enclosed in double quotes.</p>
  
  <p><code>my $input3 = "func(\"foo\") - func(\"bar\")";</code> -> Here, func should be taken as func LEXEME, ( should be LPAREN, ) should be RPAREN, foo as REGEX_STRING, - as OP and same for func(\"bar\")</p>
  
  <p><code>my $input4 = "func(\"foo\")";</code> -> Here, func should be taken as func LEXEME, ( should be LPAREN, ) should be RPAREN, foo as REGEX_STRING</p>
  
  <pre><code>print "Trying to parse:\n$input\n\n";
  $recce-&gt;read(\$input);
  my $value_ref = ${$recce-&gt;value};
  print "Output:\n".Dumper($value_ref);
  </code></pre>
  
  <p>What did i try :
   <strong>1st method:</strong>
  My REGEX_STRING should be something : <code>REGEX_STRING  -&gt; ~ '\"([^:]*?)\"'</code></p>
  
  <p>If i try putting above <code>REGEX_STRING</code> in the code with input expression as <code>my $input4 = "func(\"foo\")";</code> i get error like :</p>
  
  <p>Error in SLIF parse: No lexeme found at line 1, column 5
  * String before error: func(
  * The error was at line 1, column 5, and at character 0x0022 '"', ...
  * here: "foo")
  Marpa::R2 exception</p>
  
  <p><strong>2nd method:</strong></p>
  
  <p>Tried including a rule like :</p>
  
  <pre><code>PARAM ::= STRING | REGEX_STRING
  REGEX_STRING ::= '"' QUOTED_STRING '"'
  
  STRING ~ [^ \/\(\),&amp;:\"~]+
  QUOTED_STRING ~ [^ ,&amp;:\"~]+
  </code></pre>
  
  <p>The problem here is-> Input is given using:</p>
  
  <p><code>my $input4 = "func(\"foo\")";</code></p>
  
  <p>So, here it gives error because there are now two ways to parse this expression, either whole thing between double quotes which is func(\"foo\")
  is taken as QUOTED_STRING or func should be taken as func LEXEME and so on.</p>
  
  <p>Please help how do i fix this thing.</p>