isolating cause of EOF error
[xpath20.git] / xpath.sablecc
blob1e22d78b932522b45a3349884458144e5b583944
1 Package com.interrupt.cc.xpath; \r
2 \r
3 \r
4 // declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees'; \r
5 \r
6 // $this/xq:employees/xq:employee/xq:phone[contains(., '(206)')]\r
7 \r
8 /* ./child::node()[1]/attribute::name\r
9 \r
10  *) Find value of the name attribute of the first element in the XML document \r
11  \r
12  1) The first section is only a dot (.). A dot at the start of a query means you want to start your search from the beginning of the XML document.\r
14  2) The second section (child::node()[1]) says: Find the first child element node. The combined effect of the first and second portions (./child::node()[1]) is like saying: Find the first element of this XML document.\r
16  3) The third section (attribute::name) says: Find the value of an attribute name. The combined effect of the query is like saying: .\r
17 */\r
20 /* ./child::node()[1]/child::service/child::port/child::soap:address/attribute::location\r
22     *) Find the first child node of the XML document, then find a service child element within the first child, then find a port element inside the service element, then look inside the port element for an address element that belongs to the SOAP namespace and return the value of its location attribute. \r
23  */ \r
26 Helpers \r
30 Tokens\r
33 @\r
34 ::\r
35 :\r
36 //\r
37 /\r
38 |\r
39 []\r
40 ()\r
41 ,\r
42 .\r
43 ..\r
44 alphanum_varname_seq\r
45 num_seq\r
46 =\r
47 ""\r
48 ''\r
49 *\r
50 div\r
51 mod\r
52 +\r
53 -\r
54 <\r
55 <=\r
56 >\r
57 >=\r
58 and\r
59 or\r
63 Ignored Tokens \r
67 Productions \r
69         XPath      =            Expr\r
70         Expr       =            ExprSingle ("," ExprSingle)*\r
71         ExprSingle         =    ForExpr\r
72                                                 | QuantifiedExpr\r
73                                                 | IfExpr\r
74                                                 | OrExpr\r
75         ForExpr            =    SimpleForClause "return" ExprSingle\r
76         SimpleForClause =       "for" "$" VarName "in" ExprSingle ("," "$" VarName "in" ExprSingle)*\r
78         QuantifiedExpr  =       ("some" | "every") "$" VarName "in" ExprSingle ("," "$" VarName "in" ExprSingle)* "satisfies" ExprSingle\r
80         IfExpr     =            "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle\r
82         OrExpr     =            AndExpr ( "or" AndExpr )*\r
84         AndExpr            =            ComparisonExpr ( "and" ComparisonExpr )*\r
86         ComparisonExpr     =    RangeExpr ( (ValueComp\r
87                                                         | GeneralComp\r
88                                                         | NodeComp) RangeExpr )?\r
90         RangeExpr          =            AdditiveExpr ( "to" AdditiveExpr )?\r
92         AdditiveExpr       =            MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )*\r
94         MultiplicativeExpr         =            UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )*\r
96         UnionExpr          =            IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )*\r
98         IntersectExceptExpr        =            InstanceofExpr ( ("intersect" | "except") InstanceofExpr )*\r
100         InstanceofExpr     =            TreatExpr ( "instance" "of" SequenceType )?\r
102         TreatExpr          =            CastableExpr ( "treat" "as" SequenceType )?\r
104         CastableExpr       =            CastExpr ( "castable" "as" SingleType )?\r
106         CastExpr           =            UnaryExpr ( "cast" "as" SingleType )?\r
108         UnaryExpr          =            ("-" | "+")* ValueExpr\r
110         ValueExpr          =            PathExpr\r
112         GeneralComp        =            "=" | "!=" | "<" | "<=" | ">" | ">="\r
114         ValueComp          =            "eq" | "ne" | "lt" | "le" | "gt" | "ge"\r
116         NodeComp           =            "is" | "<<" | ">>"\r
118         PathExpr           =    ("/" RelativePathExpr?)\r
119                                                 | ("//" RelativePathExpr)\r
120                                                 | RelativePathExpr      /* xgs: leading-lone-slash */\r
122         RelativePathExpr           =            StepExpr (("/" | "//") StepExpr)*\r
124         StepExpr           =            FilterExpr | AxisStep\r
127         /**\r
128          * Axes \r
129          *\r
130         child \r
131         descendant \r
132         parent \r
133         ancestor \r
134         following-sibling \r
135         preceding-sibling \r
136         following \r
137         preceding \r
138         attribute \r
139         namespace \r
140         self \r
141         descendant-or-self \r
142         ancestor-or-self\r
143         */\r
144          \r
145         AxisStep           =            (ReverseStep | ForwardStep) PredicateList\r
147         ForwardStep        =            (ForwardAxis NodeTest) | AbbrevForwardStep\r
149         ForwardAxis        =    ("child" "::")\r
150                                                         | ("descendant" "::")\r
151                                                         | ("attribute" "::")\r
152                                                         | ("self" "::")\r
153                                                         | ("descendant-or-self" "::")\r
154                                                         | ("following-sibling" "::")\r
155                                                         | ("following" "::")\r
156                                                         | ("namespace" "::")\r
158         AbbrevForwardStep          =            "@"? NodeTest\r
160         ReverseStep        =            (ReverseAxis NodeTest) | AbbrevReverseStep\r
162         ReverseAxis        =            ("parent" "::")\r
163                                                         | ("ancestor" "::")\r
164                                                         | ("preceding-sibling" "::")\r
165                                                         | ("preceding" "::")\r
166                                                         | ("ancestor-or-self" "::")\r
168         AbbrevReverseStep          =            ".."\r
170         NodeTest           =            KindTest | NameTest\r
172         NameTest           =            QName | Wildcard\r
174         Wildcard           =    "*"\r
175                                                 | (NCName ":" "*")\r
176                                                 | ("*" ":" NCName)      /* ws: explicit */\r
178         FilterExpr         =            PrimaryExpr PredicateList\r
180         PredicateList      =            Predicate*\r
182         Predicate          =            "[" Expr "]"\r
184         PrimaryExpr        =            Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall\r
186         Literal            =            NumericLiteral | StringLiteral\r
188         NumericLiteral     =            IntegerLiteral | DecimalLiteral | DoubleLiteral\r
190         VarRef     =            "$" VarName\r
192         VarName            =            QName\r
194         ParenthesizedExpr          =            "(" Expr? ")"\r
196         ContextItemExpr            =            "."\r
198         /**\r
199          * Node Set Functions\r
200          * \r
201         Function: number last()\r
202         Function: number position()\r
203         Function: number count(node-set)\r
204         Function: node-set id(object) \r
205         Function: string local-name(node-set?)\r
206         Function: string namespace-uri(node-set?)\r
207         Function: string name(node-set?) \r
208         */\r
209         \r
210         /** \r
211          * String Functions\r
212          *\r
213         Function: string string(object?)\r
214         Function: string concat(string, string, string*)\r
215         Function: boolean starts-with(string, string)\r
216         Function: boolean contains(string, string)\r
217         Function: string substring-before(string, string)\r
218         Function: string substring-after(string, string)\r
219         Function: string substring(string, number, number?) \r
220         Function: number string-length(string?)\r
221         Function: string normalize-space(string?)\r
222         Function: string translate(string, string, string) \r
223         */\r
224         \r
225         /**\r
226          * Boolean Functions\r
227          *\r
228         Function: boolean boolean(object)\r
229         Function: boolean not(boolean)\r
230         Function: boolean true()\r
231         Function: boolean false()\r
232         Function: boolean lang(string) \r
233         */\r
234         \r
235         /** \r
236          * Number Functions\r
237          *\r
238         Function: number number(object?)\r
239         Function: number sum(node-set)\r
240         Function: number floor(number) \r
241         Function: number ceiling(number)\r
242         Function: number round(number) \r
243         */\r
244         \r
245         FunctionCall       =            QName "(" (ExprSingle ("," ExprSingle)*)? ")"   /* xgs: reserved-function-names */\r
246                                                                                                                                                                 /* gn: parens */\r
248         SingleType         =            AtomicType "?"?\r
250         SequenceType       =    ("empty-sequence" "(" ")")\r
251                                                         | (ItemType OccurrenceIndicator?)\r
253         OccurrenceIndicator        =            "?" | "*" | "+"         /* xgs: occurrence-indicators */\r
255         ItemType           =    KindTest | ("item" "(" ")") | AtomicType\r
257         AtomicType         =    QName\r
259         KindTest           =    DocumentTest\r
260                                                 | ElementTest\r
261                                                 | AttributeTest\r
262                                                 | SchemaElementTest\r
263                                                 | SchemaAttributeTest\r
264                                                 | PITest\r
265                                                 | CommentTest\r
266                                                 | TextTest\r
267                                                 | AnyKindTest\r
269         AnyKindTest        =            "node" "(" ")"\r
271         DocumentTest       =            "document-node" "(" (ElementTest | SchemaElementTest)? ")"\r
273         TextTest           =            "text" "(" ")"\r
275         CommentTest        =            "comment" "(" ")"\r
277         PITest     =            "processing-instruction" "(" (NCName | StringLiteral)? ")"\r
279         AttributeTest      =            "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")"\r
281         AttribNameOrWildcard       =            AttributeName | "*"\r
283         SchemaAttributeTest        =            "schema-attribute" "(" AttributeDeclaration ")"\r
285         AttributeDeclaration       =            AttributeName\r
287         ElementTest        =            "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")"\r
289         ElementNameOrWildcard      =            ElementName | "*"\r
291         SchemaElementTest          =            "schema-element" "(" ElementDeclaration ")"\r
293         ElementDeclaration         =            ElementName\r
295         AttributeName      =            QName\r
297         ElementName        =            QName\r
299         TypeName           =            QName\r