Class XQuery

java.lang.Object
gnu.expr.Language
gnu.xquery.lang.XQuery
Direct Known Subclasses:
XSLT

public class XQuery extends Language
The XQuery language.
  • Field Details

    • XQUERY_FUNCTION_NAMESPACE

      public static final String XQUERY_FUNCTION_NAMESPACE
      See Also:
    • KAWA_FUNCTION_NAMESPACE

      public static final String KAWA_FUNCTION_NAMESPACE
      See Also:
    • QEXO_FUNCTION_NAMESPACE

      public static final String QEXO_FUNCTION_NAMESPACE
      See Also:
    • LOCAL_NAMESPACE

      public static final String LOCAL_NAMESPACE
      See Also:
    • SCHEMA_NAMESPACE

      public static final String SCHEMA_NAMESPACE
      See Also:
    • SCHEMA_INSTANCE_NAMESPACE

      public static final String SCHEMA_INSTANCE_NAMESPACE
      See Also:
    • XHTML_NAMESPACE

      public static final String XHTML_NAMESPACE
      See Also:
    • xqueryFunctionNamespace

      public static final Namespace xqueryFunctionNamespace
    • kawaFunctionNamespace

      public static final Namespace kawaFunctionNamespace
    • qexoFunctionNamespace

      public static final Namespace qexoFunctionNamespace
    • defaultFunctionNamespacePath

      public static final Namespace[] defaultFunctionNamespacePath
    • 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.
      See Also:
    • PARSE_WITH_FOCUS

      public static final int PARSE_WITH_FOCUS
      Special parser flag used by evalToFocusProc.
      See Also:
    • VARIADIC_FUNCTION_NAMESPACE

      public static final int VARIADIC_FUNCTION_NAMESPACE
      See Also:
    • extensionsEnvEnv

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

      public static final Environment xqEnvironment
    • instance

      public static final XQuery instance
    • falseExp

      public static QuoteExp falseExp
    • trueExp

      public static QuoteExp trueExp
    • falseFunction

      public static final ConstantFunction0 falseFunction
    • trueFunction

      public static final ConstantFunction0 trueFunction
  • Constructor Details

    • XQuery

      public XQuery()
  • Method Details

    • hasSeparateFunctionNamespace

      public boolean hasSeparateFunctionNamespace()
      Description copied from class: Language
      True if functions are in a separate name space from variable. Is true for e.g. Common Lisp, Emacs Lisp; false for Scheme.
      Overrides:
      hasSeparateFunctionNamespace in class Language
    • asNumber

      public static Numeric asNumber(Object arg)
    • asChar

      public static char asChar(Object x)
    • isTrue

      public boolean isTrue(Object value)
      Description copied from class: Language
      Test if a value is considered "true" in this language. Throws an exception if value can't be used in a boolean context. Use booleanValue to catch that exception.
      Overrides:
      isTrue in class Language
    • getLexer

      public Lexer getLexer(gnu.kawa.io.InPort inp, SourceMessages messages)
      Specified by:
      getLexer in class Language
    • getCompilation

      public Compilation getCompilation(Lexer lexer, SourceMessages messages, NameLookup lexical)
    • parse

      public boolean parse(Compilation tr, int options) throws IOException, SyntaxException
      Specified by:
      parse in class Language
      Throws:
      IOException
      SyntaxException
    • resolve

      public void resolve(Compilation comp)
      Description copied from class: Language
      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 class Language
    • namespaceForFunctions

      public static int namespaceForFunctions(int argCount)
    • getNamespaceOf

      public int getNamespaceOf(Declaration decl)
      Description copied from class: Language
      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 class Language
    • hasNamespace

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

      public Symbol getSymbol(String name)
      Overrides:
      getSymbol in class Language
    • define

      public void define(String name, Object value)
      Description copied from class: Language
      Enter a value into the current environment.
      Overrides:
      define in class Language
    • define_method

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

      public String getName()
      Overrides:
      getName in class Language
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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.
      Throws:
      Throwable
    • 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.
      Throws:
      Throwable
    • 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.
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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
      Throws:
      Throwable
    • 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)
      Throws:
      Throwable
    • 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)
      Throws:
      Throwable
    • getInstance

      public static XQuery getInstance()
    • registerEnvironment

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

      public Consumer getOutputConsumer(Writer out)
      Overrides:
      getOutputConsumer in class Language
    • getStandardType

      public Type getStandardType(String name)
    • getTypeFor

      public Type getTypeFor(String name)
      Overrides:
      getTypeFor in class Language
    • formatType

      public String formatType(Type type)
      Overrides:
      formatType in class Language
    • getTypeFor

      public Type getTypeFor(Class clas)
      Overrides:
      getTypeFor in class Language
    • getPrimaryPrompt

      public String getPrimaryPrompt()
      Overrides:
      getPrimaryPrompt in class Language
    • getSecondaryPrompt

      public String getSecondaryPrompt()
      Overrides:
      getSecondaryPrompt in class Language
    • mangle

      public static String mangle(String name)
    • makeClassName

      public static String makeClassName(String source)
    • getExternal

      public static Object getExternal(Symbol name, Object type)