Debian Codegraph @

net/sf/saxon/expr/parser/ParserExtension.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr.parser;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.LocalBinding;
12 import net.sf.saxon.om.StructuredQName;
13 import net.sf.saxon.query.AnnotationList;
14 import net.sf.saxon.query.XQueryFunction;
15 import net.sf.saxon.query.XQueryParser;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.type.ItemType;
18 import net.sf.saxon.z.IntSet;
19
20 import java.util.ArrayList;
21
22 /**
23 * Dummy Parser extension for syntax in XPath that is accepted only in Saxon-PE and -EE. Primarily, this means
24 * XPath 3.0 syntax associated with higher-order functions.
25 */
26 public class ParserExtension {
27
28 public ParserExtension() {
29 }
30
31 private void needHof(XPathParser p, String what) throws XPathException {
32 p.grumble(what + " require support for higher-order-functions, which needs Saxon-PE or higher");
33 }
34
35 private void needExtension(XPathParser p, String what) throws XPathException {
36 p.grumble(what + " require support for Saxon extensions, available in Saxon-PE or higher");
37 }
38
39 private void needUpdate(XPathParser p, String what) throws XPathException {
40 p.grumble(what + " requires support for XQuery Update, available in Saxon-EE or higher");
41 }
42
43 /**
44 * Parse a literal function item (function#arity). On entry, the function name and
45 * the '#' token have already been read
46 *
47 * @param p the parser
48 * @return an expression representing the function value
49 * @throws XPathException in the event of a syntax error
50 */
51
52 public Expression parseNamedFunctionReference(XPathParser p) throws XPathException {
53 needHof(p, "Named function references");
54 return null;
55 }
56
57 /**
58 * Parse the item type used for function items (XQuery 3.0 higher order functions)
59 * Syntax (changed by WG decision on 2009-09-22):
60 * function '(' '*' ') |
61 * function '(' (SeqType (',' SeqType)*)? ')' 'as' SeqType
62 * For backwards compatibility with Saxon 9.2 we allow the "*" to be omitted for the time being
63 * The "function(" has already been read
64 * @param annotations the list of annotation assertions for this function item type
65 */
66
67 public ItemType parseFunctionItemType(XPathParser p, AnnotationList annotations) throws XPathException {
68 needHof(p, "Function item types");
69 return null;
70 }
71
72 /**
73 * Parse an ItemType within a SequenceType
74 *
75 * @return the ItemType after parsing
76 * @throws XPathException if a static error is found
77 */
78
79 public ItemType parseExtendedItemType(XPathParser p) throws XPathException {
80 Tokenizer t = p.getTokenizer();
81 if (t.currentToken == Token.TILDE) {
82 needExtension(p, "Type aliases");
83 } else if (t.currentToken == Token.NODEKIND && t.currentTokenValue.equals("tuple")) {
84 // Saxon 9.8 extension: tuple types
85 needExtension(p, "Tuple types");
86 } else if (t.currentToken == Token.NODEKIND && t.currentTokenValue.equals("union")) {
87 // Saxon 9.8 extension: union types
88 needExtension(p, "Inline union types");
89 }
90 return null;
91 }
92
93 /**
94 * Parse an extended XSLT pattern in the form ~type-alias (predicate)*
95 * @return the equivalent expression in the form .[. instance of type] (predicate)*
96 */
97
98 public Expression parseTildePattern(XPathParser p) throws XPathException {
99 needExtension(p, "Type aliases");
100 return null;
101 }
102
103
104 /**
105 * Parse a function argument. The special marker "?" is allowed and causes "null"
106 * to be returned
107 */
108
109 public Expression makeArgumentPlaceMarker(XPathParser p) throws XPathException {
110 needHof(p, "Argument place-holders");
111 return null;
112 }
113
114 /**
115 * Parse an inline function
116 * "function" "(" ParamList? ")" ("as" SequenceType)? EnclosedExpr
117 * On entry, "function (" has already been read
118 *
119 * @throws XPathException if a syntax error is found
120 */
121
122 protected Expression parseInlineFunction(XPathParser p, AnnotationList annotations) throws XPathException {
123 needHof(p, "Inline functions");
124 return null;
125 }
126
127 public Expression parseSimpleInlineFunction(XPathParser p) throws XPathException {
128 needExtension(p, "Simple inline functions");
129 return null;
130 }
131
132 /**
133 * Process a function call in which one or more of the argument positions are
134 * represented as "?" placemarkers (indicating partial application or currying)
135 *
136 * @param offset offset in the query source of the start of the expression
137 * @param name the function call (as if there were no currying)
138 * @param args the arguments (with EmptySequence in the placemarker positions)
139 * @param placeMarkers the positions of the placemarkers @return the curried function
140 * @throws XPathException
141 */
142
143 public Expression makeCurriedFunction(
144 XPathParser parser, int offset,
145 StructuredQName name, Expression[] args, IntSet placeMarkers) throws XPathException {
146 needHof(parser, "Partially applied functions");
147 return null;
148 }
149
150 /**
151 * When a variable reference occurs within an inline function, it might be a reference to a variable declared
152 * outside the inline function (which needs to become part of the closure. This code looks for such an outer
153 * variable
154 *
155 * @param qName the name of the variable
156 * @return a binding for the variable; this will typically be a binding to a newly added parameter
157 * for the innermost function in which the variable reference appears. As a side effect, all the inline
158 * functions between the declaration of the variable and its use will have this variable as an additional
159 * parameter, each one bound to the corresponding parameter in the containing function.
160 */
161
162 public LocalBinding findOuterRangeVariable(XPathParser p, StructuredQName qName) {
163 return null;
164 }
165
166
167
168 public Expression createDynamicCurriedFunction(XPathParser p, Expression functionItem, ArrayList<Expression> args, IntSet placeMarkers) throws XPathException {
169 needHof(p, "Partial function application");
170 return null;
171 }
172
173 public void handleExternalFunctionDeclaration(XQueryParser p, XQueryFunction func) throws XPathException {
174 needExtension(p, "External function declarations");
175 }
176
177 /**
178 * Parse a type alias declaration. Allowed only in Saxon-PE and higher
179 *
180 * @throws XPathException if parsing fails
181 */
182
183 public void parseTypeAliasDeclaration(XQueryParser p) throws XPathException {
184 needExtension(p, "Type alias declarations");
185 }
186
187 /**
188 * Parse the "declare revalidation" declaration.
189 * Syntax: not allowed unless XQuery update is in use
190 *
191 * @throws XPathException if the syntax is incorrect, or is not allowed in this XQuery processor
192 */
193
194 public void parseRevalidationDeclaration(XQueryParser p) throws XPathException {
195 needUpdate(p, "A revalidation declaration");
196 }
197
198 /**
199 * Parse an updating function declaration (allowed in XQuery Update only)
200 *
201 * @throws XPathException if parsing fails or if updating functions are not allowed
202 */
203
204 public void parseUpdatingFunctionDeclaration(XQueryParser p) throws XPathException {
205 needUpdate(p, "An updating function");
206 }
207
208 protected Expression parseExtendedExprSingle(XPathParser p) throws XPathException {
209 return null;
210 }
211 }