gnu.xquery.lang

Class XQuery

Known Direct Subclasses:
XSLT

public class XQuery
extends Language

The XQuery language.

Field Summary

static String
DEFAULT_ELEMENT_PREFIX
Pseudo-namespace "prefix" for the default element namespace.
static String
DEFAULT_FUNCTION_PREFIX
Pseudo-namespace "prefix" for the default function namespace.
static String
KAWA_FUNCTION_NAMESPACE
static String
LOCAL_NAMESPACE
static int
PARSE_WITH_FOCUS
Special parser flag used by evalToFocusProc.
static String
QEXO_FUNCTION_NAMESPACE
static String
SCHEMA_INSTANCE_NAMESPACE
static String
SCHEMA_NAMESPACE
static int
VARIADIC_FUNCTION_NAMESPACE
static String
XHTML_NAMESPACE
static String
XQUERY_FUNCTION_NAMESPACE
static Namespace[]
defaultFunctionNamespacePath
static Environment
extensionsEnvEnv
Environment of pre-defined non-standard Qexo/Kawa functions.
static QuoteExp
falseExp
static ConstantFunction0
falseFunction
static XQuery
instance
static Namespace
kawaFunctionNamespace
static Namespace
qexoFunctionNamespace
static QuoteExp
trueExp
static ConstantFunction0
trueFunction
static Environment
xqEnvironment
static Namespace
xqueryFunctionNamespace

Fields inherited from class gnu.expr.Language

FUNCTION_NAMESPACE, NAMESPACE_PREFIX_NAMESPACE, PARSE_IMMEDIATE, PARSE_ONE_LINE, PARSE_PROLOG, VALUE_NAMESPACE, current, env_counter, environ, requirePedantic, userEnv

Constructor Summary

XQuery()

Method Summary

Object
applyWithFocus(Procedure proc, Object values)
Call a procedure with each item in a sequence as the context item.
void
applyWithFocus(Procedure proc, Object values, Consumer out)
Call a procedure with each item in a sequence as the context item.
Object
applyWithFocus(Procedure proc, Object item, int position, int size)
Call a procedure with a given focus (context).
void
applyWithFocus(Procedure proc, Object item, int position, int size, Consumer out)
Call a procedure with a given focus (context).
void
applyWithFocus$X(Procedure proc, Object values, CallContext ctx)
Call a procedure with each item in a sequence as the context item.
static char
asChar(Object x)
static Numeric
asNumber(Object arg)
void
define(String name, Object value)
Enter a value into the current environment.
protected void
define_method(String name, String cname, String mname)
Procedure
evalToFocusProc(Reader in, SourceMessages messages)
Parse an XQuery expression from a Reader that is the body of a procedure.
Procedure
evalToFocusProc(String expr)
Parse an XQuery expression that is the body of a procedure.
void
evalWithFocus(Reader in, SourceMessages messages, Object values, Consumer out)
Evaluate an expression with each item in a sequence as the context item.
void
evalWithFocus(Reader in, SourceMessages messages, Object item, int position, int size, Consumer out)
Evaluate an expression with a given focus (context).
Object
evalWithFocus(String expr, Object values)
Evaluate an expression with each item in a sequence as the context item.
Object
evalWithFocus(String expr, Object item, int position, int size)
Evaluate an expression with a given focus (context).
void
eval_with_focus$X(String expr, Object values, CallContext ctx)
Evaluate an expression with a given focus (context).
void
eval_with_focus$X(String expr, Object item, int position, int size, CallContext ctx)
Evaluate an expression with a given focus (context).
String
formatType(Type type)
Compilation
getCompilation(Lexer lexer, SourceMessages messages)
static Object
getExternal(Symbol name, Object type)
static XQuery
getInstance()
Lexer
getLexer(InPort inp, SourceMessages messages)
String
getName()
int
getNamespaceOf(Declaration decl)
Return the namespace (e.g value or function) of a Declaration.
Consumer
getOutputConsumer(java.io.Writer out)
Procedure
getPrompter()
static Type
getStandardType(String name)
Symbol
getSymbol(String name)
Type
getTypeFor(Class clas)
Type
getTypeFor(String name)
boolean
hasNamespace(Declaration decl, int namespace)
True if a Declaration is in the specified namespace.
boolean
hasSeparateFunctionNamespace()
True if functions are in a separate anme space from variable.
boolean
isTrue(Object value)
Test if a value is considered "true" in this language.
static String
makeClassName(String source)
static String
mangle(String name)
static int
namespaceForFunctions(int argCount)
boolean
parse(Compilation tr, int options)
static void
registerEnvironment()
The compiler insert calls to this method for applications and applets.
void
resolve(Compilation comp)
Perform any need post-processing after we've read all the modules to be compiled.

Methods inherited from class gnu.expr.Language

asType, booleanObject, coerceFromObject, coerceToObject, coerceToObject, declFromField, defAliasStFld, defProcStFld, defProcStFld, define, defineFunction, defineFunction, detect, detect, detect, emitCoerceToBoolean, emitPushBoolean, eval, eval, eval, eval, eval, eval, eval, eval, eval, formatType, getCompilation, getDefaultLanguage, getEnvPropertyFor, getEnvPropertyFor, getEnvironment, getFormat, getInstance, getInstance, getInstanceFromFilenameExtension, getLangEnvironment, getLangTypeFor, getLanguages, getLexer, getName, getNamespaceOf, getNewEnvironment, getOutputConsumer, getPrompter, getSymbol, getTypeFor, getTypeFor, getTypeFor, getTypeFor, getTypeFor, hasNamespace, hasSeparateFunctionNamespace, isTrue, loadClass, lookup, lookupBuiltin, noValue, parse, parse, parse, parse, registerLanguage, resolve, runAsApplication, setDefaultLanguage, setDefaults, string2Type

Field Details

DEFAULT_ELEMENT_PREFIX

public static final String DEFAULT_ELEMENT_PREFIX
Pseudo-namespace "prefix" for the default element namespace.

DEFAULT_FUNCTION_PREFIX

public static final String DEFAULT_FUNCTION_PREFIX
Pseudo-namespace "prefix" for the default function namespace.

KAWA_FUNCTION_NAMESPACE

public static final String KAWA_FUNCTION_NAMESPACE

LOCAL_NAMESPACE

public static final String LOCAL_NAMESPACE

PARSE_WITH_FOCUS

public static final int PARSE_WITH_FOCUS
Special parser flag used by evalToFocusProc.
Field Value:
65536

QEXO_FUNCTION_NAMESPACE

public static final String QEXO_FUNCTION_NAMESPACE

SCHEMA_INSTANCE_NAMESPACE

public static final String SCHEMA_INSTANCE_NAMESPACE

SCHEMA_NAMESPACE

public static final String SCHEMA_NAMESPACE

VARIADIC_FUNCTION_NAMESPACE

public static final int VARIADIC_FUNCTION_NAMESPACE
Field Value:
-2

XHTML_NAMESPACE

public static final String XHTML_NAMESPACE

XQUERY_FUNCTION_NAMESPACE

public static final String XQUERY_FUNCTION_NAMESPACE

defaultFunctionNamespacePath

public static final Namespace[] defaultFunctionNamespacePath

extensionsEnvEnv

public static Environment extensionsEnvEnv
Environment of pre-defined non-standard Qexo/Kawa functions.

falseExp

public static QuoteExp falseExp

falseFunction

public static final ConstantFunction0 falseFunction

instance

public static final XQuery instance

kawaFunctionNamespace

public static final Namespace kawaFunctionNamespace

qexoFunctionNamespace

public static final Namespace qexoFunctionNamespace

trueExp

public static QuoteExp trueExp

trueFunction

public static final ConstantFunction0 trueFunction

xqEnvironment

public static final Environment xqEnvironment

xqueryFunctionNamespace

public static final Namespace xqueryFunctionNamespace

Constructor Details

XQuery

public XQuery()

Method Details

applyWithFocus

public Object applyWithFocus(Procedure proc,
                             Object values)
            throws Throwable
Call a procedure with each item in a sequence as the context item.
Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
Returns:
the result of applying proc

applyWithFocus

public void applyWithFocus(Procedure proc,
                           Object values,
                           Consumer out)
            throws Throwable
Call a procedure with each item in a sequence as the context item.
Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
out - where to send the result of proc

applyWithFocus

public Object applyWithFocus(Procedure proc,
                             Object item,
                             int position,
                             int size)
            throws Throwable
Call a procedure with a given focus (context).
Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
item - the context item, passed as the first argument to proc
position - the context position, passed as the second argument
size - the context size, passed as the second argument
Returns:
the result of applying proc

applyWithFocus

public void applyWithFocus(Procedure proc,
                           Object item,
                           int position,
                           int size,
                           Consumer out)
            throws Throwable
Call a procedure with a given focus (context).
Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
item - the context item, passed as the first argument to proc
position - the context position, passed as the second argument
size - the context size, passed as the second argument
out - where to send the result of proc

applyWithFocus$X

public void applyWithFocus$X(Procedure proc,
                             Object values,
                             CallContext ctx)
            throws Throwable
Call a procedure with each item in a sequence as the context item.
Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
ctx - the CallContext. The $X in the method name tells Kawa that this argument is implicit when invoked from XQuery.

asChar

public static char asChar(Object x)

asNumber

public static Numeric asNumber(Object arg)

define

public void define(String name,
                   Object value)
Enter a value into the current environment.
Overrides:
define in interface Language

define_method

protected void define_method(String name,
                             String cname,
                             String mname)

evalToFocusProc

public Procedure evalToFocusProc(Reader in,
                                 SourceMessages messages)
            throws Throwable
Parse an XQuery expression from a Reader that is the body of a procedure. Helper method used by evalWithFocus methods.
Parameters:
in - where we read the expression from
messages - where to write syntax errors
Returns:
a 3-operand Procedure whose arguments become the context item, position, and size.

evalToFocusProc

public Procedure evalToFocusProc(String expr)
            throws Throwable
Parse an XQuery expression that is the body of a procedure. Helper method used by evalWithFocus methods.
Parameters:
expr - an XQuery expression (query) to evaluate
Returns:
a 3-operand Procedure whose arguments become the context item, position, and size.

evalWithFocus

public void evalWithFocus(Reader in,
                          SourceMessages messages,
                          Object values,
                          Consumer out)
            throws Throwable
Evaluate an expression with each item in a sequence as the context item.
Parameters:
in - where we read the expression from
messages - where to write syntax errors
values - becomes the context sequence while evaluating expr.
out - where to send the result of the expression

evalWithFocus

public void evalWithFocus(Reader in,
                          SourceMessages messages,
                          Object item,
                          int position,
                          int size,
                          Consumer out)
            throws Throwable
Evaluate an expression with a given focus (context).
Parameters:
in - where we read the expression from
messages - where to write syntax errors
item - becomes the context item while evaluating the expression
position - becomes the context position
size - becomes the context size
out - where to send the result of the expression

evalWithFocus

public Object evalWithFocus(String expr,
                            Object values)
            throws Throwable
Evaluate an expression with each item in a sequence as the context item.
Parameters:
expr - an XQuery expression (query) to evaluate
values - becomes the context sequence while evaluating the expression
Returns:
the result of evaluating the expression

evalWithFocus

public Object evalWithFocus(String expr,
                            Object item,
                            int position,
                            int size)
            throws Throwable
Evaluate an expression with a given focus (context).
Parameters:
expr - an XQuery expression (query) to evaluate
item - becomes the context item while evaluating expr.
position - becomes the context position
size - becomes the context size
Returns:
the result of evaluating expr

eval_with_focus$X

public void eval_with_focus$X(String expr,
                              Object values,
                              CallContext ctx)
            throws Throwable
Evaluate an expression with a given focus (context). Similar to evalWithFocus(String, Object, Consumer). The "$X" in the method name tells the Kawa compiler that the CallContext argument is implicit, so it can be invoked from XQuery code thus: XQuery:eval-with-focus($xquery, "expr", $sequence)

eval_with_focus$X

public void eval_with_focus$X(String expr,
                              Object item,
                              int position,
                              int size,
                              CallContext ctx)
            throws Throwable
Evaluate an expression with a given focus (context). Similar to evalWithFocus(String, Object, int, int, Consumer). The "$X" in the method name tells the Kawa compiler that the CallContext argument is implicit, so it can be invoked from XQuery code thus: XQuery:eval-with-focus($xquery, "expr", $item, $pos, $size)

formatType

public String formatType(Type type)
Overrides:
formatType in interface Language

getCompilation

public Compilation getCompilation(Lexer lexer,
                                  SourceMessages messages)
Overrides:
getCompilation in interface Language

getExternal

public static Object getExternal(Symbol name,
                                 Object type)

getInstance

public static XQuery getInstance()

getLexer

public Lexer getLexer(InPort inp,
                      SourceMessages messages)
Overrides:
getLexer in interface Language

getName

public String getName()
Overrides:
getName in interface Language

getNamespaceOf

public int getNamespaceOf(Declaration decl)
Return the namespace (e.g value or function) of a Declaration. Return a bitmask of all the namespaces "covered" by the Declaration. Note this isn't a namespace in the XML sense; if a Declaration has a specific namespace URI, then that is part of its symbol. This namespace bitmap is a separate dimension, for the use of languages that have separate namespaces for different kinds of declarations, such as variables and functions.
Overrides:
getNamespaceOf in interface Language

getOutputConsumer

public Consumer getOutputConsumer(java.io.Writer out)

getPrompter

public Procedure getPrompter()
Overrides:
getPrompter in interface Language

getStandardType

public static Type getStandardType(String name)

getSymbol

public Symbol getSymbol(String name)
Overrides:
getSymbol in interface Language

getTypeFor

public Type getTypeFor(Class clas)
Overrides:
getTypeFor in interface Language

getTypeFor

public Type getTypeFor(String name)
Overrides:
getTypeFor in interface Language

hasNamespace

public boolean hasNamespace(Declaration decl,
                            int namespace)
True if a Declaration is in the specified namespace.
Overrides:
hasNamespace in interface Language
Parameters:
namespace - normally a bitmask as returned by getNamespaceOf.

hasSeparateFunctionNamespace

public boolean hasSeparateFunctionNamespace()
True if functions are in a separate anme space from variable. Is true for e.g. Common Lisp, Emacs Lisp; false for Scheme.
Overrides:
hasSeparateFunctionNamespace in interface Language

isTrue

public boolean isTrue(Object value)
Test if a value is considered "true" in this language.
Overrides:
isTrue in interface Language

makeClassName

public static String makeClassName(String source)

mangle

public static String mangle(String name)

namespaceForFunctions

public static int namespaceForFunctions(int argCount)

parse

public boolean parse(Compilation tr,
                     int options)
            throws java.io.IOException,
                   SyntaxException
Overrides:
parse in interface Language

registerEnvironment

public static void registerEnvironment()
The compiler insert calls to this method for applications and applets.

resolve

public void resolve(Compilation comp)
Perform any need post-processing after we've read all the modules to be compiled. Using a separate pass allows compiling mutually recursive modules.
Overrides:
resolve in interface Language