| 1 | # This file was automatically generated from src/xsh_grammar.xml on | ||
| 2 | # Wed Sep 10 17:53:03 2003 | ||
| 3 | |||
| 4 | |||
| 5 | package XML::XSH::Grammar; | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use Parse::RecDescent; | ||
| 9 | use vars qw/$grammar/; | ||
| 10 | |||
| 11 | $Parse::RecDescent::skip = '(\s|\n|#[^\n]*)*'; | ||
| 12 | $grammar=<<'_EO_GRAMMAR_'; | ||
| 13 | |||
| 14 | |||
| 15 | command: | ||
| 16 | ... /\s*[}{;]/ <commit> <reject> | ||
| 17 | | /(switch-to-new-documents|switch_to_new_documents)\s/ expression | ||
| 18 | { [\&XML::XSH::Functions::set_cdonopen,$item[2]] } | ||
| 19 | |||
| 20 | | /(backups)/ | ||
| 21 | { [\&XML::XSH::Functions::set_backups,1] } | ||
| 22 | |||
| 23 | | /(nobackups)/ | ||
| 24 | { [\&XML::XSH::Functions::set_backups,0] } | ||
| 25 | |||
| 26 | | /(quiet)/ | ||
| 27 | { [\&XML::XSH::Functions::set_quiet,1] } | ||
| 28 | |||
| 29 | | /(verbose)/ | ||
| 30 | { [\&XML::XSH::Functions::set_quiet,0] } | ||
| 31 | |||
| 32 | | /(test-mode|test_mode)/ | ||
| 33 | { ["test-mode"] } | ||
| 34 | |||
| 35 | | /(run-mode|run_mode)/ | ||
| 36 | { ["run-mode"] } | ||
| 37 | |||
| 38 | | /(debug)/ | ||
| 39 | { [\&XML::XSH::Functions::set_debug,1] } | ||
| 40 | |||
| 41 | | /(nodebug)/ | ||
| 42 | { [\&XML::XSH::Functions::set_debug,0] } | ||
| 43 | |||
| 44 | | /(version)/ | ||
| 45 | { [\&XML::XSH::Functions::print_version,0] } | ||
| 46 | |||
| 47 | | /(validation)\s/ <commit> expression | ||
| 48 | { [\&XML::XSH::Functions::set_validation,$item[3]] } | ||
| 49 | |||
| 50 | | /(recovering)\s/ <commit> expression | ||
| 51 | { [\&XML::XSH::Functions::set_recovering,$item[3]] } | ||
| 52 | |||
| 53 | | /(parser-expands-entities|parser_expands_entities)\s/ <commit> expression | ||
| 54 | { [\&XML::XSH::Functions::set_expand_entities,$item[3]] } | ||
| 55 | |||
| 56 | | /(keep-blanks|keep_blanks)\s/ <commit> expression | ||
| 57 | { [\&XML::XSH::Functions::set_keep_blanks,$item[3]] } | ||
| 58 | |||
| 59 | | /(pedantic-parser|pedantic_parser)\s/ <commit> expression | ||
| 60 | { [\&XML::XSH::Functions::set_pedantic_parser,$item[3]] } | ||
| 61 | |||
| 62 | | /(parser-completes-attributes|complete_attributes|complete-attributes|parser_completes_attributes)\s/ <commit> expression | ||
| 63 | { [\&XML::XSH::Functions::set_complete_attributes,$item[3]] } | ||
| 64 | |||
| 65 | | /(indent)\s/ <commit> expression | ||
| 66 | { [\&XML::XSH::Functions::set_indent,$item[3]] } | ||
| 67 | |||
| 68 | | /(empty-tags|empty_tags)\s/ <commit> expression | ||
| 69 | { [\&XML::XSH::Functions::set_empty_tags,$item[3]] } | ||
| 70 | |||
| 71 | | /(skip-dtd|skip_dtd)\s/ <commit> expression | ||
| 72 | { [\&XML::XSH::Functions::set_skip_dtd,$item[3]] } | ||
| 73 | |||
| 74 | | /(parser-expands-xinclude|parser_expands_xinclude)\s/ <commit> expression | ||
| 75 | { [\&XML::XSH::Functions::set_expand_xinclude,$item[3]] } | ||
| 76 | |||
| 77 | | /(load-ext-dtd|load_ext_dtd)\s/ <commit> expression | ||
| 78 | { [\&XML::XSH::Functions::set_load_ext_dtd,$item[3]] } | ||
| 79 | |||
| 80 | | /(encoding)\s/ <commit> expression | ||
| 81 | { [\&XML::XSH::Functions::set_encoding,$item[3]] } | ||
| 82 | |||
| 83 | | /(query-encoding|query_encoding)\s/ <commit> expression | ||
| 84 | { [\&XML::XSH::Functions::set_qencoding,$item[3]] } | ||
| 85 | |||
| 86 | | /(options|flags)/ <commit> | ||
| 87 | { [\&XML::XSH::Functions::list_flags] } | ||
| 88 | |||
| 89 | | /(copy|cp)\s/ <commit> xpath loc xpath | ||
| 90 | { [\&XML::XSH::Functions::copy,@item[3,5,4]] } | ||
| 91 | |||
| 92 | | /(xcopy|xcp)\s/ <commit> xpath loc xpath | ||
| 93 | { [\&XML::XSH::Functions::copy,@item[3,5,4],1] } | ||
| 94 | |||
| 95 | | /(move|mv)\s/ <commit> xpath loc xpath | ||
| 96 | { [\&XML::XSH::Functions::move,@item[3,5,4]] } | ||
| 97 | |||
| 98 | | /(xmove|xmv)\s/ <commit> xpath loc xpath | ||
| 99 | { [\&XML::XSH::Functions::move,@item[3,5,4],1] } | ||
| 100 | |||
| 101 | | /(ls|list)\s/ xpath expression | ||
| 102 | { [\&XML::XSH::Functions::list,$item[2],$item[3]] } | ||
| 103 | |||
| 104 | | /(ls|list)\s/ xpath | ||
| 105 | { [\&XML::XSH::Functions::list,$item[2],-1] } | ||
| 106 | |||
| 107 | | /(ls|list)/ | ||
| 108 | { [\&XML::XSH::Functions::list,[undef,'.'],1] } | ||
| 109 | |||
| 110 | | /(exit|quit)/ <commit> optional_expression(?) | ||
| 111 | { [\&XML::XSH::Functions::quit,@{$item[3]}] } | ||
| 112 | |||
| 113 | | /(remove|rm|prune|delete|del)\s/ <commit> xpath | ||
| 114 | { [\&XML::XSH::Functions::prune,$item[3]] } | ||
| 115 | |||
| 116 | | /(map|sed)\s/ <commit> perl_code xpath | ||
| 117 | { [\&XML::XSH::Functions::perlmap,@item[4,3]] } | ||
| 118 | |||
| 119 | | /(rename)\s/ <commit> perl_code xpath | ||
| 120 | { [\&XML::XSH::Functions::perlrename,@item[4,3]] } | ||
| 121 | |||
| 122 | | /(sort)\s/ <commit> condition perl_code nodelistvariable | ||
| 123 | { [\&XML::XSH::Functions::perlsort,@item[3..5]] } | ||
| 124 | |||
| 125 | | /(close)/ <commit> optional_expression(?) | ||
| 126 | { [\&XML::XSH::Functions::close_doc,@{$item[3]}] } | ||
| 127 | |||
| 128 | | /(validate)/ validation_scheme optional_expression(?) | ||
| 129 | { [\&XML::XSH::Functions::validate_doc,1,$item[2],@{$item[3]}] } | ||
| 130 | |||
| 131 | | /(validate)/ <commit> optional_expression(?) | ||
| 132 | { [\&XML::XSH::Functions::validate_doc,1,[],@{$item[3]}] } | ||
| 133 | |||
| 134 | | /(valid)/ validation_scheme optional_expression(?) | ||
| 135 | { [\&XML::XSH::Functions::validate_doc,0,$item[2],@{$item[3]}] } | ||
| 136 | |||
| 137 | | /(valid)/ <commit> optional_expression(?) | ||
| 138 | { [\&XML::XSH::Functions::validate_doc,0,[],@{$item[3]}] } | ||
| 139 | |||
| 140 | | /(dtd)/ <commit> optional_expression(?) | ||
| 141 | { [\&XML::XSH::Functions::list_dtd,@{$item[3]}] } | ||
| 142 | |||
| 143 | | /(enc)/ <commit> optional_expression(?) | ||
| 144 | { [\&XML::XSH::Functions::print_enc,@{$item[3]}] } | ||
| 145 | |||
| 146 | | /(set-enc)\s/ <commit> expression optional_expression(?) | ||
| 147 | { [\&XML::XSH::Functions::set_doc_enc,$item[3],@{$item[4]}] } | ||
| 148 | |||
| 149 | | /(set-standalone)\s/ <commit> expression optional_expression(?) | ||
| 150 | { [\&XML::XSH::Functions::set_doc_standalone,$item[3],@{$item[4]}] } | ||
| 151 | |||
| 152 | | /(lcd|chdir)/ <commit> optional_expression(?) | ||
| 153 | { [\&XML::XSH::Functions::cd,@{$item[3]}] } | ||
| 154 | |||
| 155 | | /(clone|dup)\s/ <commit> id_or_var /\s*=\s*/ expression | ||
| 156 | { [\&XML::XSH::Functions::clone,@item[3,5]] } | ||
| 157 | |||
| 158 | | /(count|print_value|get)\s/ <commit> xpath | ||
| 159 | { [\&XML::XSH::Functions::print_count,$item[3]] } | ||
| 160 | |||
| 161 | | /(perl|eval)\s/ <commit> perl_code | ||
| 162 | { [\&XML::XSH::Functions::print_eval,$item[3]] } | ||
| 163 | |||
| 164 | | /save(as|_as|-as)?((\s*|_|-)(HTML|html|XML|xml|XINCLUDE|Xinclude|xinclude))?((\s*|_|-)(FILE|file|PIPE|pipe|STRING|string))?/ expression filename encoding_param(?) | ||
| 165 | { [\&XML::XSH::Functions::save_doc,@item[1,2,3,4]] } | ||
| 166 | |||
| 167 | | /save(as|_as|-as)?((\s*|_|-)(HTML|html|XML|xml|XINCLUDE|Xinclude|xinclude))?((\s*|_|-)(FILE|file|STRING|string))?/ expression encoding_param(?) | ||
| 168 | { [\&XML::XSH::Functions::save_doc,@item[1,2],undef,$item[3]] } | ||
| 169 | |||
| 170 | | /save(as|_as|-as)?([-_](HTML|html|XML|xml|XINCLUDE|Xinclude|xinclude))?/ <commit> | ||
| 171 | { [\&XML::XSH::Functions::save_doc,$item[1]] } | ||
| 172 | |||
| 173 | | /(documents|files|docs)/ | ||
| 174 | { [\&XML::XSH::Functions::files] } | ||
| 175 | |||
| 176 | | /(xslt|transform|xsl|xsltproc|process)\s/ <commit> expression filename expression xslt_params(?) | ||
| 177 | { [\&XML::XSH::Functions::xslt,@item[3,4,5],@{$item[6]}] } | ||
| 178 | |||
| 179 | | /(insert|add)\s/ <commit> nodetype expression namespace(?) loc xpath | ||
| 180 | { [\&XML::XSH::Functions::insert,@item[3,4,7,6],$item[5][0],0] } | ||
| 181 | |||
| 182 | | /(xinsert|xadd)\s/ <commit> nodetype expression namespace(?) loc xpath | ||
| 183 | { [\&XML::XSH::Functions::insert,@item[3,4,7,6],$item[5][0],1] } | ||
| 184 | |||
| 185 | | /(help|\?)/ <commit> optional_expression(?) | ||
| 186 | { [\&XML::XSH::Functions::help,@{$item[3]}] } | ||
| 187 | |||
| 188 | | /(exec|system)\s/ <commit> expression(s) | ||
| 189 | { [\&XML::XSH::Functions::sh,join(" ",@{$item[3]})] } | ||
| 190 | |||
| 191 | | /(include|\.)\s/ <commit> filename | ||
| 192 | { [\&XML::XSH::Functions::include,$item[3]] } | ||
| 193 | |||
| 194 | | /(ifinclude)\s/ <commit> filename | ||
| 195 | { [\&XML::XSH::Functions::include,$item[3],1] } | ||
| 196 | |||
| 197 | |( /(assign)\s/ | ||
| 198 | )(?) variable '=' xpath | ||
| 199 | { [\&XML::XSH::Functions::xpath_assign,$item[2],$item[4]] } | ||
| 200 | |||
| 201 | |( /(assign)\s/ | ||
| 202 | )(?) nodelistvariable '=' xpath | ||
| 203 | { [\&XML::XSH::Functions::nodelist_assign,$item[2],$item[4]] } | ||
| 204 | |||
| 205 | | /(local)\s/ variable '=' xpath | ||
| 206 | { [\&XML::XSH::Functions::xpath_assign_local,$item[2],$item[4]] } | ||
| 207 | |||
| 208 | | /(local)\s/ nodelistvariable '=' xpath | ||
| 209 | { [\&XML::XSH::Functions::nodelist_assign_local,$item[2],$item[4]] } | ||
| 210 | |||
| 211 | | /(local)\s/ anyvariable(s) | ||
| 212 | { [\&XML::XSH::Functions::make_local,@{$item[2]}] } | ||
| 213 | |||
| 214 | | variable | ||
| 215 | { [\&XML::XSH::Functions::print_var,$item[1]] } | ||
| 216 | |||
| 217 | | /(variables|vars|var)/ | ||
| 218 | { [\&XML::XSH::Functions::variables] } | ||
| 219 | |||
| 220 | | /(print|echo)\s/ expression(s) | ||
| 221 | { [\&XML::XSH::Functions::echo,@{$item[2]}] } | ||
| 222 | |||
| 223 | | /(print|echo)/ | ||
| 224 | { [\&XML::XSH::Functions::echo] } | ||
| 225 | |||
| 226 | | /(create|new)\s/ <commit> expression expression | ||
| 227 | { [\&XML::XSH::Functions::create_doc,@item[3,4]] } | ||
| 228 | |||
| 229 | | /(defs)/ <commit> | ||
| 230 | { [\&XML::XSH::Functions::list_defs] } | ||
| 231 | |||
| 232 | | /(select)\s/ <commit> expression | ||
| 233 | { [\&XML::XSH::Functions::set_local_xpath,[$item[3],"/"]] } | ||
| 234 | |||
| 235 | | /(if)\s/ <commit> condition command | ||
| 236 | { [\&XML::XSH::Functions::if_statement,[$item[3],[$item[4]]]] } | ||
| 237 | |||
| 238 | | /(unless)\s/ <commit> condition command | ||
| 239 | { [\&XML::XSH::Functions::unless_statement,$item[3],[$item[4]]] } | ||
| 240 | |||
| 241 | | /(while)\s/ <commit> condition command | ||
| 242 | { [\&XML::XSH::Functions::while_statement,$item[3],[$item[4]]] } | ||
| 243 | |||
| 244 | | /(foreach|for)\s/ <commit> condition command | ||
| 245 | { [\&XML::XSH::Functions::foreach_statement,$item[3],[$item[4]]] } | ||
| 246 | |||
| 247 | | /(process-xinclude|process_xinclude|process-xincludes|process_xincludes|xinclude|xincludes|load_xincludes|load-xincludes|load_xinclude|load-xinclude)/ <commit> optional_expression(?) | ||
| 248 | { [\&XML::XSH::Functions::process_xinclude,@{$item[3]}] } | ||
| 249 | |||
| 250 | | /(cd|chxpath)/ <commit> optional_xpath(?) | ||
| 251 | { [\&XML::XSH::Functions::set_local_xpath,@{$item[3]}] } | ||
| 252 | |||
| 253 | | /(pwd)/ | ||
| 254 | { [\&XML::XSH::Functions::print_pwd] } | ||
| 255 | |||
| 256 | | /(locate)/ <commit> optional_xpath(?) | ||
| 257 | { [\&XML::XSH::Functions::locate,@{$item[3]}] } | ||
| 258 | |||
| 259 | | /(xupdate)\s/ <commit> expression expression(?) | ||
| 260 | { [\&XML::XSH::Functions::xupdate,$item[3],@{$item[4]}] } | ||
| 261 | |||
| 262 | | /open((\s*|_|-)(HTML|XML|DOCBOOK|html|xml|docbook)(?!\s*=))?((\s*|_|-)(FILE|file|PIPE|pipe|STRING|string)(?!\s*=))?/ <commit> id_or_var /\s*=\s*/ expression | ||
| 263 | { [\&XML::XSH::Functions::open_doc,@item[3,5,1]] } | ||
| 264 | |||
| 265 | | ID /\s*=\s*/ <commit> filename | ||
| 266 | { [\&XML::XSH::Functions::open_doc,@item[1,4]] } | ||
| 267 | |||
| 268 | | /(fold)\s/ xpath expression(?) | ||
| 269 | { [\&XML::XSH::Functions::mark_fold,$item[2],@{$item[3]}] } | ||
| 270 | |||
| 271 | | /(unfold)\s/ xpath | ||
| 272 | { [\&XML::XSH::Functions::mark_unfold,$item[2]] } | ||
| 273 | |||
| 274 | | /(normalize)\s/ <commit> xpath | ||
| 275 | { [\&XML::XSH::Functions::normalize_nodes,$item[3]] } | ||
| 276 | |||
| 277 | | /(strip-whitespace|strip_whitespace)\s/ <commit> xpath | ||
| 278 | { [\&XML::XSH::Functions::strip_ws,$item[3]] } | ||
| 279 | |||
| 280 | | /(last)/ <commit> optional_expression(?) | ||
| 281 | { [\&XML::XSH::Functions::loop_last,@{$item[3]}] } | ||
| 282 | |||
| 283 | | /(next)/ <commit> optional_expression(?) | ||
| 284 | { [\&XML::XSH::Functions::loop_next,@{$item[3]}] } | ||
| 285 | |||
| 286 | | /(prev)/ <commit> optional_expression(?) | ||
| 287 | { [\&XML::XSH::Functions::loop_prev,@{$item[3]}] } | ||
| 288 | |||
| 289 | | /(redo)/ <commit> optional_expression(?) | ||
| 290 | { [\&XML::XSH::Functions::loop_redo,@{$item[3]}] } | ||
| 291 | |||
| 292 | | /(return)/ | ||
| 293 | { [\&XML::XSH::Functions::call_return] } | ||
| 294 | |||
| 295 | | /(throw)\s/ expression | ||
| 296 | { [\&XML::XSH::Functions::throw_exception,$item[2]] } | ||
| 297 | |||
| 298 | | /(catalog)\s/ expression | ||
| 299 | { [\&XML::XSH::Functions::load_catalog,$item[2]] } | ||
| 300 | |||
| 301 | | /(register-namespace|regns)\s/ <commit> expression expression | ||
| 302 | { [\&XML::XSH::Functions::register_ns, | ||
| 303 | $item[3],$item[4]] } | ||
| 304 | |||
| 305 | | /(unregister-namespace|unregns)\s/ <commit> expression | ||
| 306 | { [\&XML::XSH::Functions::unregister_ns, | ||
| 307 | $item[3]] } | ||
| 308 | |||
| 309 | | /(register-xhtml-namespace|regns-xhtml)\s/ <commit> expression | ||
| 310 | { [\&XML::XSH::Functions::register_ns, | ||
| 311 | $item[3],'http://www.w3.org/1999/xhtml'] } | ||
| 312 | |||
| 313 | | /(register-xsh-namespace|regns-xsh)\s/ <commit> expression | ||
| 314 | { [\&XML::XSH::Functions::register_ns, | ||
| 315 | $item[3],$XML::XSH::xshNS] } | ||
| 316 | |||
| 317 | | /(unregister-function|unregfunc)\s/ <commit> expression | ||
| 318 | { [\&XML::XSH::Functions::unregister_func, $item[3]] } | ||
| 319 | |||
| 320 | | /(register-function|regfunc)\s/ <commit> expression perl_code | ||
| 321 | { [\&XML::XSH::Functions::register_func, | ||
| 322 | $item[3],$item[4]] } | ||
| 323 | |||
| 324 | | /(stream)\s/ <commit> /input((\s*|_|-)(FILE|file|PIPE|pipe|STRING|string))?\s/ filename /output((\s*|_|-)(FILE|file|PIPE|pipe|STRING|string))?\s/ filename stream_select(s) | ||
| 325 | { [\&XML::XSH::Functions::stream_process,$item[3],$item[4],$item[5],$item[6],$item[7]] } | ||
| 326 | |||
| 327 | | /(namespaces)/ <commit> xpath(?) | ||
| 328 | { [\&XML::XSH::Functions::list_namespaces,@{$item[3]}] } | ||
| 329 | |||
| 330 | | /(xpath-completion|xpath_completion)\s/ <commit> expression | ||
| 331 | { [\&XML::XSH::Functions::set_xpath_completion,$item[3]] } | ||
| 332 | |||
| 333 | | /(xpath-axis-completion|xpath_axis_completion)\s/ <commit> expression | ||
| 334 | { [\&XML::XSH::Functions::set_xpath_axis_completion,$item[3]] } | ||
| 335 | |||
| 336 | | /(doc-info|doc_info)/ <commit> optional_expression(?) | ||
| 337 | { [\&XML::XSH::Functions::doc_info,@{$item[3]}] } | ||
| 338 | |||
| 339 | | /(use)\s/ <commit> /Inline::XSH/ | ||
| 340 | { 1 } | ||
| 341 | |||
| 342 | | call_command | ||
| 343 | |||
| 344 | statement: | ||
| 345 | ... /\s*[}{;]/ <commit> <reject> | ||
| 346 | | /(if)\s/ <commit> condition block elsif_block else_block | ||
| 347 | { [\&XML::XSH::Functions::if_statement,[$item[3],$item[4]],@{$item[5]},@{$item[6]}] } | ||
| 348 | |||
| 349 | | /(unless)\s/ <commit> condition block else_block(?) | ||
| 350 | { [\&XML::XSH::Functions::unless_statement,$item[3],$item[4],@{$item[5]}] } | ||
| 351 | |||
| 352 | | /(while)\s/ <commit> condition block | ||
| 353 | { [\&XML::XSH::Functions::while_statement,$item[3],$item[4]] } | ||
| 354 | |||
| 355 | | /(foreach|for)\s/ <commit> condition block | ||
| 356 | { [\&XML::XSH::Functions::foreach_statement,$item[3],$item[4]] } | ||
| 357 | |||
| 358 | | /(try)\s/ <commit> block 'catch' local_var(?) block | ||
| 359 | { [\&XML::XSH::Functions::try_catch,$item[3],$item[6],@{$item[5]}] } | ||
| 360 | |||
| 361 | | /(iterate)\s/ <commit> xpstep block | ||
| 362 | { [\&XML::XSH::Functions::iterate,$item[4],@{$item[3]}] } | ||
| 363 | |||
| 364 | |||
| 365 | complex_command: | ||
| 366 | ';' | ||
| 367 | | statement <commit> trail(?) | ||
| 368 | { | ||
| 369 | if (scalar(@{$item[3]})) { | ||
| 370 | if ($item[3][0][0] eq 'pipe') { | ||
| 371 | $return=[\&XML::XSH::Functions::pipe_command,[$item[1]],$item[3][0][1]] | ||
| 372 | } else { | ||
| 373 | $return=[\&XML::XSH::Functions::string_pipe_command,[$item[1]],$item[3][0][1]] | ||
| 374 | } | ||
| 375 | } else { | ||
| 376 | $return=$item[1] | ||
| 377 | } | ||
| 378 | } | ||
| 379 | |||
| 380 | | command <commit> trail(?) | ||
| 381 | ( ';' | ||
| 382 | | ... /^\s*(}|\Z)/ | ||
| 383 | ) | ||
| 384 | { | ||
| 385 | if (scalar(@{$item[3]})) { | ||
| 386 | if ($item[3][0][0] eq 'pipe') { | ||
| 387 | $return=[\&XML::XSH::Functions::pipe_command,[$item[1]],$item[3][0][1]] | ||
| 388 | } else { | ||
| 389 | $return=[\&XML::XSH::Functions::string_pipe_command,[$item[1]],$item[3][0][1]] | ||
| 390 | } | ||
| 391 | } else { | ||
| 392 | $return=$item[1] | ||
| 393 | } | ||
| 394 | } | ||
| 395 | |||
| 396 | | <error:Parse error near: "}.substr($text,0,40).qq{ ..."> | ||
| 397 | |||
| 398 | statement_or_command: | ||
| 399 | def | ||
| 400 | | undef | ||
| 401 | | complex_command | ||
| 402 | |||
| 403 | block: | ||
| 404 | '{' <commit> complex_command(s) '}' | ||
| 405 | { [grep ref,@{$item[3]}] } | ||
| 406 | |||
| 407 | |||
| 408 | type: | ||
| 409 | |||
| 410 | |||
| 411 | TOKEN: | ||
| 412 | /\S+/ | ||
| 413 | |||
| 414 | STRING: | ||
| 415 | /([^'"\$\\ \t\n\r\|;\{\}]|\$[^{]|\$\{[^{}]*\}|]|\\.)+/ | ||
| 416 | |||
| 417 | single_quoted_string: | ||
| 418 | /\'([^\'\\]|\\\'|\\\\|\\[^\'\\])*\'/ | ||
| 419 | { | ||
| 420 | local $_=$item[1]; | ||
| 421 | s/^\'|\'$//g; | ||
| 422 | s{(\\)(.|\n)|(\$)}{ ($3 eq '$') ? "\\\$" : (($2 eq "\\") | ||
| 423 | ? "\\\\" : (($2 eq "'") ? "'" : ( ($2 eq '$') ? "\\\\\\$2" : | ||
| 424 | "\\\\$2"))) }eg; | ||
| 425 | $_; | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | double_quoted_string: | ||
| 430 | /\"([^\"\\]|\\.)*\"/ | ||
| 431 | { | ||
| 432 | local $_=$item[1]; | ||
| 433 | s/^\"|\"$//g; | ||
| 434 | $_; | ||
| 435 | } | ||
| 436 | |||
| 437 | |||
| 438 | exp_part: | ||
| 439 | STRING | ||
| 440 | | exp_inline_count | ||
| 441 | | single_quoted_string | ||
| 442 | | double_quoted_string | ||
| 443 | |||
| 444 | exp_inline_count: | ||
| 445 | /\$\{\((.+?)\)\}/ | ||
| 446 | | /\$\{\{\{(.+?)\}\}\}/ | ||
| 447 | | /\$\{\{([^{].*?)\}\}/ | ||
| 448 | |||
| 449 | expression: | ||
| 450 | /<</ /(\'|\")?/ ID /$item[2]/ <skip:""> /.*\n/ /(.|\n)*?\n$item[3]\s*(\n|$)/ | ||
| 451 | { | ||
| 452 | $text=$item[6].$text; | ||
| 453 | local $_=$item[7]; s/\n$item[3]\s*$//; | ||
| 454 | if ($item[2] eq "'") { | ||
| 455 | s{(\\)(.|\n)|(\$)}{ ($3 eq '$') ? "\\\$" : (($2 eq "\\") | ||
| 456 | ? "\\\\" : (($2 eq "'") ? "'" : ( ($2 eq '$') ? "\\\\\\$2" : | ||
| 457 | "\\\\$2"))) }eg; | ||
| 458 | } | ||
| 459 | $_; | ||
| 460 | } | ||
| 461 | |||
| 462 | | exp_part <skip:""> expression(?) | ||
| 463 | { $item[1].join("",@{$item[3]}) } | ||
| 464 | |||
| 465 | |||
| 466 | ws: | ||
| 467 | /(\s|\n|#[^\n]*)+/ | ||
| 468 | |||
| 469 | optional_expression: | ||
| 470 | <skip:""> ws expression | ||
| 471 | { $item[3] } | ||
| 472 | |||
| 473 | |||
| 474 | optional_expressions: | ||
| 475 | <skip:""> ws expression(s) | ||
| 476 | { $item[3] } | ||
| 477 | |||
| 478 | |||
| 479 | optional_xpath: | ||
| 480 | <skip:""> ws xpath | ||
| 481 | { $item[3] } | ||
| 482 | |||
| 483 | |||
| 484 | enc_string: | ||
| 485 | expression | ||
| 486 | |||
| 487 | ID: | ||
| 488 | /[a-zA-Z_][a-zA-Z0-9_]*/ | ||
| 489 | |||
| 490 | id_or_var: | ||
| 491 | ID | ||
| 492 | | variable | ||
| 493 | |||
| 494 | public_dtd: | ||
| 495 | 'PUBLIC' expression | ||
| 496 | { $item[2] } | ||
| 497 | |||
| 498 | |||
| 499 | system_dtd: | ||
| 500 | /SYSTEM|FILE/ filename | ||
| 501 | { $item[2] } | ||
| 502 | |||
| 503 | |||
| 504 | validation_scheme: | ||
| 505 | 'DTD' public_dtd system_dtd | ||
| 506 | { ['DTD','FILE',$item[2],$item[3]] } | ||
| 507 | |||
| 508 | | 'DTD' public_dtd | ||
| 509 | { ['DTD','FILE',$item[2],undef] } | ||
| 510 | |||
| 511 | | 'DTD' system_dtd | ||
| 512 | { ['DTD','FILE',undef,$item[2]] } | ||
| 513 | |||
| 514 | | 'DTD' 'STRING' expression | ||
| 515 | { ['DTD','STRING',$item[3]] } | ||
| 516 | |||
| 517 | | /RNG|RelaxNG|RELAXNG/ /FILE|STRING|DOC/ filename | ||
| 518 | { ['RNG',@item[2,3]] } | ||
| 519 | |||
| 520 | | /Schema|SCHEMA|XSD/ /FILE|STRING|DOC/ filename | ||
| 521 | { ['XSD',@item[2,3]] } | ||
| 522 | |||
| 523 | |||
| 524 | filename: | ||
| 525 | expression | ||
| 526 | |||
| 527 | xpath: | ||
| 528 | id_or_var <skip:""> /:(?!:)/ xp | ||
| 529 | { [$item[1],$item[4]] } | ||
| 530 | |||
| 531 | | xp | ||
| 532 | { [undef,$item[1]] } | ||
| 533 | |||
| 534 | | <error:expected ID:XPath or XPath, but got "}.substr($text,0,40).qq{ ..."> | ||
| 535 | |||
| 536 | xpcont: | ||
| 537 | ( xpfilters | ||
| 538 | | xpbrackets | ||
| 539 | ) <skip:""> xp(?) | ||
| 540 | { $item[1].join("",@{$item[3]}) } | ||
| 541 | |||
| 542 | | xp | ||
| 543 | { $item[1] } | ||
| 544 | |||
| 545 | |||
| 546 | xp: | ||
| 547 | xpsimple <skip:""> xpcont(?) | ||
| 548 | { $item[1].join("",@{$item[3]}) } | ||
| 549 | |||
| 550 | | xpstring | ||
| 551 | |||
| 552 | xpfilters: | ||
| 553 | xpfilter(s) | ||
| 554 | { join("",@{$item[1]}) } | ||
| 555 | |||
| 556 | |||
| 557 | xpfilter: | ||
| 558 | '[' xpinter ']' | ||
| 559 | { "[$item[2]]" } | ||
| 560 | |||
| 561 | |||
| 562 | xpbracket: | ||
| 563 | '(' xpinter ')' | ||
| 564 | { "($item[2])" } | ||
| 565 | |||
| 566 | |||
| 567 | xpbrackets: | ||
| 568 | xpbracket <skip:""> xpfilters(?) | ||
| 569 | { join "",$item[1],@{$item[3]} } | ||
| 570 | |||
| 571 | |||
| 572 | xpintercont: | ||
| 573 | ( xpfilters | ||
| 574 | | xpbrackets | ||
| 575 | ) <skip:""> xpinter(?) | ||
| 576 | { join("",$item[1],@{$item[3]}) } | ||
| 577 | |||
| 578 | |||
| 579 | xpinter: | ||
| 580 | xps <skip:""> xpintercont(?) | ||
| 581 | { join("",$item[1],@{$item[3]}) } | ||
| 582 | |||
| 583 | |||
| 584 | xps: | ||
| 585 | /([^][()'"]|'[^']*'|"[^"]*")*/ | ||
| 586 | |||
| 587 | xpstring: | ||
| 588 | /'[^']*'|"[^"]*"/ | ||
| 589 | |||
| 590 | xpsimple: | ||
| 591 | /[^]}|"' [();]+/ | ||
| 592 | | xpbrackets | ||
| 593 | |||
| 594 | perl_expression: | ||
| 595 | expression | ||
| 596 | |||
| 597 | variable: | ||
| 598 | '$' <skip:""> ID | ||
| 599 | { "$item[1]$item[3]" } | ||
| 600 | |||
| 601 | |||
| 602 | nodelistvariable: | ||
| 603 | '%' <skip:""> ID | ||
| 604 | { $item[3] } | ||
| 605 | |||
| 606 | |||
| 607 | loosenodelistvariable: | ||
| 608 | '%' <skip:""> id_or_var | ||
| 609 | { $item[3] } | ||
| 610 | |||
| 611 | |||
| 612 | eof: | ||
| 613 | /^\Z/ | ||
| 614 | { 1; } | ||
| 615 | |||
| 616 | |||
| 617 | startrule: | ||
| 618 | shell <commit> eof | ||
| 619 | { XML::XSH::Functions::run_commands($item[1],1) } | ||
| 620 | |||
| 621 | | statement_or_command(s) <commit> eof | ||
| 622 | { XML::XSH::Functions::run_commands($item[1],1) } | ||
| 623 | |||
| 624 | |||
| 625 | trail: | ||
| 626 | '|>' <commit> variable | ||
| 627 | { ['var',$item[3]] } | ||
| 628 | |||
| 629 | | '|' <commit> shline | ||
| 630 | { ['pipe',$item[3]] } | ||
| 631 | |||
| 632 | |||
| 633 | shline_nosc: | ||
| 634 | /([^;()\\"'\|]|\|[^>]|\\.|\"([^\"\\]|\\.)*\"|\'([^\'\\]|\\\'|\\\\|\\[^\'\\])*\')*/ | ||
| 635 | |||
| 636 | shline_inter: | ||
| 637 | /([^()\\"']|\\.|\"([^\"\\]|\\.)*\"|\'([^\'\\]|\\\'|\\\\|\\[^\'\\])*\')*/ | ||
| 638 | |||
| 639 | shline_bracket: | ||
| 640 | '(' shline_inter shline_bracket(?) shline_inter ')' | ||
| 641 | { join("",'(',$item[2],@{$item[3]},$item[4],')') } | ||
| 642 | |||
| 643 | |||
| 644 | shline: | ||
| 645 | shline_nosc shline_bracket(?) shline_nosc | ||
| 646 | { join("",$item[1],@{$item[2]},$item[3]) } | ||
| 647 | |||
| 648 | |||
| 649 | shell: | ||
| 650 | /!\s*/ <commit> /.*/ | ||
| 651 | { [[\&XML::XSH::Functions::sh,$item[3]]] } | ||
| 652 | |||
| 653 | | <error?:Parse error near: "! }.substr($text,0,40).qq{ ..."> <reject> | ||
| 654 | |||
| 655 | condition: | ||
| 656 | <perl_codeblock> | ||
| 657 | | xpath | ||
| 658 | |||
| 659 | elsif_block: | ||
| 660 | /(elsif)\s/ <commit> condition block elsif_block | ||
| 661 | { [[$item[3],$item[4]],@{$item[5]}] } | ||
| 662 | |||
| 663 | | ...! /(elsif)/ | ||
| 664 | { [] } | ||
| 665 | |||
| 666 | | <uncommit> <error:Parse error near keyword elsif: "}.substr($text,0,40).qq{ ..."> | ||
| 667 | |||
| 668 | else_block: | ||
| 669 | /(else)\s/ <commit> block | ||
| 670 | { [[undef,$item[3]]] } | ||
| 671 | |||
| 672 | | ...! /(else)/ | ||
| 673 | { [] } | ||
| 674 | |||
| 675 | | <uncommit> <error:Parse error near keyword else: "}.substr($text,0,40).qq{ ..."> | ||
| 676 | |||
| 677 | local_var: | ||
| 678 | ( /local\s/ | ||
| 679 | )(?) variable | ||
| 680 | { [$item[2],@{$item[1]}] } | ||
| 681 | |||
| 682 | |||
| 683 | typedvariable: | ||
| 684 | /[\$\%]/ <skip:""> ID | ||
| 685 | { "$item[1]$item[3]" } | ||
| 686 | |||
| 687 | |||
| 688 | undef: | ||
| 689 | /(undef|undefine)\s/ <commit> expression | ||
| 690 | { | ||
| 691 | &XML::XSH::Functions::undef_sub($item[3]); | ||
| 692 | } | ||
| 693 | |||
| 694 | |||
| 695 | def: | ||
| 696 | /(def|define)\s/ <commit> ID typedvariable(s?) block(?) | ||
| 697 | { | ||
| 698 | &XML::XSH::Functions::def($item[3],$item[5],$item[4]); | ||
| 699 | } | ||
| 700 | |||
| 701 | | <error?:Parse error near: "}.substr($text,0,40).qq{ ..."> <reject> | ||
| 702 | |||
| 703 | anyvariable: | ||
| 704 | variable | ||
| 705 | { ['$',$item[1]] } | ||
| 706 | |||
| 707 | | nodelistvariable | ||
| 708 | { ['%',$item[1]] } | ||
| 709 | |||
| 710 | |||
| 711 | match_typedargs: | ||
| 712 | |||
| 713 | { | ||
| 714 | $return = ((@arg and $arg[0]<=$#arg and $arg[$arg[0]]=~m/^%/) | ||
| 715 | ? $arg[$arg[0]] : undef) | ||
| 716 | } | ||
| 717 | xpath match_typedargs[$arg[0]+1,@arg[1..$#arg]] | ||
| 718 | { | ||
| 719 | $return=(defined($item[3]) ? [$item[2],@{$item[3]}] : undef); | ||
| 720 | } | ||
| 721 | |||
| 722 | | | ||
| 723 | { | ||
| 724 | $return = ((@arg and $arg[0]<=$#arg and $arg[$arg[0]]=~m/^\$/) | ||
| 725 | ? $arg[$arg[0]] : undef) | ||
| 726 | } | ||
| 727 | expression match_typedargs[$arg[0]+1,@arg[1..$#arg]] | ||
| 728 | { | ||
| 729 | $return=(defined($item[3]) ? [$item[2],@{$item[3]}] : undef); | ||
| 730 | } | ||
| 731 | |||
| 732 | | | ||
| 733 | { | ||
| 734 | $return= (($arg[0]==$#arg+1) ? [] : undef); | ||
| 735 | } | ||
| 736 | |||
| 737 | |||
| 738 | subroutine_arguments: | ||
| 739 | |||
| 740 | { | ||
| 741 | if (exists($XML::XSH::Functions::_defs{$arg[0]})) { | ||
| 742 | $return=[ @{$XML::XSH::Functions::_defs{$arg[0]}} ]; | ||
| 743 | shift @$return; | ||
| 744 | } else { | ||
| 745 | $return=undef; | ||
| 746 | } | ||
| 747 | } | ||
| 748 | |||
| 749 | | <error:Call to undefined subroutine $arg[0]!> | ||
| 750 | |||
| 751 | call_command: | ||
| 752 | <rulevar:@args> | ||
| 753 | | /(call)\s/ <commit> ID subroutine_arguments[$item[3]] match_typedargs[1,@{$item[4]}] | ||
| 754 | { | ||
| 755 | $return=[\&XML::XSH::Functions::call,$item[3],$item[5]] | ||
| 756 | } | ||
| 757 | |||
| 758 | |||
| 759 | xslt_params: | ||
| 760 | /(params|parameters)\s/ param(s) | ||
| 761 | { $item[2] } | ||
| 762 | |||
| 763 | |||
| 764 | param: | ||
| 765 | /[^=\s]+/ '=' expression | ||
| 766 | { [$item[1],$item[3]] } | ||
| 767 | |||
| 768 | |||
| 769 | nodetype: | ||
| 770 | /element|attribute|attributes|text|cdata|pi|comment|chunk|entity_reference/ | ||
| 771 | |||
| 772 | namespace: | ||
| 773 | /namespace\s/ expression | ||
| 774 | { $item[2] } | ||
| 775 | |||
| 776 | |||
| 777 | loc: | ||
| 778 | /after\s/ | ||
| 779 | { "after" } | ||
| 780 | |||
| 781 | | /before\s/ | ||
| 782 | { "before" } | ||
| 783 | |||
| 784 | | /(in)?to\s/ | ||
| 785 | { "into" } | ||
| 786 | |||
| 787 | | /(append(ing)?|as\s+(a\s+)child(\s+of)?)\s/ | ||
| 788 | { "append" } | ||
| 789 | |||
| 790 | | /(prepend(ing)?|(as\s+)(the\s+)first(\s+child(\s+of)?)?)\s/ | ||
| 791 | { "prepend" } | ||
| 792 | |||
| 793 | | /(replace|instead( of)?)\s/ | ||
| 794 | { "replace" } | ||
| 795 | |||
| 796 | |||
| 797 | perl_code: | ||
| 798 | <perl_codeblock> | ||
| 799 | | perl_expression | ||
| 800 | |||
| 801 | encoding_param: | ||
| 802 | /encoding\s/ expression | ||
| 803 | { $item[2] } | ||
| 804 | |||
| 805 | |||
| 806 | xpaxis: | ||
| 807 | /[-a-z]+::/ | ||
| 808 | |||
| 809 | xpnodetest: | ||
| 810 | /node\(\)|text\(\)|comment\(\)|processing-instruction\(\)|[^\(\[\/\"\'\&\;\s]+/ | ||
| 811 | |||
| 812 | xplocationstep: | ||
| 813 | xpaxis(?) <skip:""> xpnodetest | ||
| 814 | { [ (@{$item[1]} ? $item[1][0] : 'child::'),$item[3] ] } | ||
| 815 | |||
| 816 | |||
| 817 | xpstep: | ||
| 818 | xplocationstep <skip:""> xpfilter(?) | ||
| 819 | { [ @{$item[1]}, @{$item[3]}] } | ||
| 820 | |||
| 821 | |||
| 822 | stream_select: | ||
| 823 | /select\s/ xp block | ||
| 824 | { [$item[2],$item[3]] } | ||
| 825 | |||
| 826 | |||
| 827 | |||
| 828 | |||
| 829 | _EO_GRAMMAR_ | ||
| 830 | |||
| 831 | sub compile { | ||
| 832 | Parse::RecDescent->Precompile($grammar,"XML::XSH::Parser"); | ||
| 833 | } | ||
| 834 | |||
| 835 | sub new { | ||
| 836 | return new Parse::RecDescent ($grammar); | ||
| 837 | } | ||
| 838 | |||
| 839 | 1; | ||
| 840 | |||
| 841 |