OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Early Draft Review: XQuery for Java (JSR 225)

[ Lists Home | Date Index | Thread Index ]


> One can add a library which parses strings, and provide a "call-level
> interface" facade.

Or go the other way round and have a library that produces strings from the abstract syntax, so you can compile time check them if you want, eg:

interface MathExpression {}
interface Place {}
interface Variable extends MathExpression, Place {}

class MathStatement {
  public static MathExpression plus (final MathExpression left, final MathExpression right) {
    return new MathExpression () {
      public String toString () {
        return "(" + left + " + " + right + ")";
        // real code would walk the tree with a StringBuffer
      }
    };
  }

  public static MathExpression set (final Place place, final MathExpression value) {...
 
... a few similar methods for other operations and literal values...
 
  protected MathExpression expression;
 
  public String toString () {
    return expression + ";";
  }
  public static final MathExpression _0 = lit(0), _1 = lit(1), _2 = lit(2), _3 = lit(3);
}

public class SomeMath {
  static final boolean STATIC_CHECK = true;
 
  public static void main (String[] args) {
    if (STATIC_CHECK) {
      System.out.println(new MathStatement(){{
        Variable x = var("x"), y = var("y");

        expression = set(x, plus(times(_2, pow(x, _2)),
                                 plus(times(_3, x), _1)));
      }});
    } else {
      System.out.println("x := ((2*(x**2)) + ((3*x) + 1));");
    }
  }
}
==>
 [java] x := ((2*(x**2)) + ((3*x) + 1));
     
It should be relatively easy to add such a library to the loosely typed interface if the only concern is allowing compile time static type checking to the abstract syntax. Providing a parser and tools to act on the AST of the language would be a better option (and people might actually use it if there was something more than syntax checking available, such as programmatic construction of valid queries), but they might fall into a 'xquery syntax library' rather than a 'xquery implementation interface'.

Maybe a parser that syntax checks the currently selected text in an IDE would be more use, though that would be just bridging code to the parser library.

If both interfaces were provided, then the interface could also accept the typed objects, and the client could decide which to use. Library implementors may or may not use the AST provided, since they can always call toString() and parse the result if their AST implementation is bound to their query engine internals, or walk the tree provided (tree walking not shown in example).


Pete

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS