Use the ? operator in the XPath parser

This commit is contained in:
Yorick Peterse 2015-03-20 00:17:43 +01:00
parent 3b74a55d73
commit 2714dbe419
1 changed files with 7 additions and 16 deletions

View File

@ -16,8 +16,7 @@
%terminals T_SUB T_MUL T_VAR; %terminals T_SUB T_MUL T_VAR;
xpath xpath
= expression = expression?
| _ { nil }
; ;
# Expressions And Operators # Expressions And Operators
@ -78,14 +77,13 @@ additive_expr_follow
; ;
mult_expr mult_expr
= union_expr mult_expr_follow { combine_optional_operator(val) } = union_expr mult_expr_follow? { combine_optional_operator(val) }
; ;
mult_expr_follow mult_expr_follow
= T_DIV mult_expr { [:div, val[1]] } = T_DIV mult_expr { [:div, val[1]] }
| T_MOD mult_expr { [:mod, val[1]] } | T_MOD mult_expr { [:mod, val[1]] }
| T_MUL mult_expr { [:mul, val[1]] } | T_MUL mult_expr { [:mul, val[1]] }
| _ { nil }
; ;
union_expr union_expr
@ -120,12 +118,7 @@ path_steps_follow
# /A, /A/B, etc # /A, /A/B, etc
absolute_path absolute_path
= T_SLASH absolute_path_follow { s(:absolute_path, *val[1]) } = T_SLASH path_steps? { s(:absolute_path, *val[1]) }
;
absolute_path_follow
= path_steps
| _
; ;
path_step_or_axis path_step_or_axis
@ -164,13 +157,12 @@ path_step
path_step_follow path_step_follow
= T_LPAREN call_args T_RPAREN { [:call, val[1]] } = T_LPAREN call_args T_RPAREN { [:call, val[1]] }
| T_COLON T_IDENT predicate { [:test, val[1], val[2]] } | T_COLON T_IDENT predicate? { [:test, val[1], val[2]] }
| predicate { [:test, nil, val[0]] } | predicate? { [:test, nil, val[0]] }
; ;
predicate predicate
= T_LBRACK expression T_RBRACK { val[1] } = T_LBRACK expression T_RBRACK { val[1] }
| _ { nil }
; ;
type_test type_test
@ -179,7 +171,7 @@ type_test
# Regular test (e.g. tests used as axis values) # Regular test (e.g. tests used as axis values)
test test
= T_IDENT test_follow = T_IDENT test_follow?
{ {
val[1] ? s(:test, val[0], val[1]) : s(:test, nil, val[0]) val[1] ? s(:test, val[0], val[1]) : s(:test, nil, val[0])
} }
@ -187,7 +179,6 @@ test
test_follow test_follow
= T_COLON T_IDENT { val[1] } = T_COLON T_IDENT { val[1] }
| _ { nil }
; ;
call_args call_args
@ -201,7 +192,7 @@ call_args_follow
# child::foo, descendant-or-self::foo, etc # child::foo, descendant-or-self::foo, etc
axis axis
= T_AXIS axis_value predicate = T_AXIS axis_value predicate?
{ {
ret = s(:axis, val[0], val[1]) ret = s(:axis, val[0], val[1])