XML-XSH2

 view release on metacpan or  search on metacpan

lib/XML/XSH2/Grammar.pm  view on Meta::CPAN

	    /([^()\\"']|\\.|\"([^\"\\]|\\.)*\"|\'([^\'\\]|\\\'|\\\\|\\[^\'\\])*\')*/

  shline_bracket:
	    '(' shline_inter shline_bracket(?) shline_inter ')'
		{ join("",'(',$item[2],@{$item[3]},$item[4],')') }
  	

  shline:
	    shline_nosc shline_bracket(?) shline_nosc
		{ join("",$item[1],@{$item[2]},$item[3]) }
  	

  shell:
	    /!\s*/ <commit> /.*/
		{ [[$thisline,$thiscolumn,$thisoffset,$XML::XSH2::Functions::SCRIPT,'sh_noev',$item[3]]] }
  	
	  | <error?:Parse error near: "! }.substr($text,0,40).qq{ ..."> <reject>

  elsif_block:
	    /(elsif)\b/ <commit> exp block elsif_block
		{ [[$item[3],$item[4]],@{$item[5]}] }
  	
	  | /(?!elsif)/
		{ [] }
  	
	  | <uncommit> <error:Parse error near keyword elsif: "}.substr($text,0,40).qq{ ...">

  else_block:
	    /(else)\b/ <commit> block
		{ [[undef,$item[3]]] }
  	
	  | /(?!else)/
		{ [] }
  	
	  | <uncommit> <error:Parse error near keyword else: "}.substr($text,0,40).qq{ ...">

  local_var:
	   ( /(local|my)\s/
	   )(?) variable
		{ [$item[2],@{$item[1]}] }
  	

  local_var_in:
	    local_var 'in'
		{ $item[1] }
  	

  undef:
	    /(undef|undefine)\b/ <commit> /\$?[a-zA-Z_][a-zA-Z0-9_]*/
		{ 
	  [$thisline,$thiscolumn,$thisoffset,$XML::XSH2::Functions::SCRIPT,'undefine',$item[3]];
	 }
  	

  param:
	    /[^=\s]+/ '=' exp
		{ [$item[1],$item[3]] }
  	

  nodetype:
	    /element|attribute|attributes|text|cdata|pi|comment|chunk|entity_reference/

  loc:
	    /after\s/
		{ "after" }
  	
	  | /before\s/
		{ "before" }
  	
	  | /(in)?to\s/
		{ "into" }
  	
	  | /(append(ing)?|as\s+(a\s+)child(\s+of)?)\s/
		{ "append" }
  	
	  | /(prepend(ing)?|(as\s+)(the\s+)first(\s+child(\s+of)?)?)\s/
		{ "prepend" }
  	
	  | /(replace|instead( of)?)\s/
		{ "replace" }
  	

  xpaxis:
	    /[-a-z]+::/

  xpnodetest:
	    /node\(\)|text\(\)|comment\(\)|processing-instruction\(\s*(?:"[^"]*"\s*|'[^'*]'\s*)?\)|[^\(\[\/\"\'\&\;\s]+/

  xplocationstep:
	    xpaxis(?) xpnodetest
		{ [ (@{$item[1]} ? $item[1][0] : 'child::'),$item[3] ] }
  	

  xpstep:
	    xplocationstep <skip:""> xpfilter(?)
		{ [ @{$item[1]}, @{$item[3]}] }
  	

  stream_select:
	    /select\s/ xpath block
		{ [$item[2],$item[3]] }
  	



_EO_GRAMMAR_

sub compile {
  my @opts = ( { -standalone => 1 },
               $grammar,
               "XML::XSH2::Parser",
             );
  shift @opts
      if $Parse::RecDescent::VERSION < 1.967_005; # Standalone not supported.
  Parse::RecDescent->Precompile(@opts);
}

sub new {
  return new Parse::RecDescent ($grammar);
}



( run in 0.489 second using v1.01-cache-2.11-cpan-39bf76dae61 )