[DoXQuery-Devel] doxquery/src/com/doxological/doxquery/grammar Node.java,1.9,1.10 SimpleNode.java,1.
Status: Pre-Alpha
Brought to you by:
jpcs
From: John S. <jp...@us...> - 2005-05-06 01:19:03
|
Update of /cvsroot/doxquery/doxquery/src/com/doxological/doxquery/grammar In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11861/src/com/doxological/doxquery/grammar Modified Files: Node.java SimpleNode.java XQueryGrammar.jjt Log Message: Fixed bug #1196090, an issue with the lexer and comments in certain positions. Added a functional regression test suits for the parser, which compares query AST output to the expected results. The tests can be built using the ant target "compile_test", and run using the target "test". Index: Node.java =================================================================== RCS file: /cvsroot/doxquery/doxquery/src/com/doxological/doxquery/grammar/Node.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Node.java 24 Apr 2005 00:39:47 -0000 1.9 --- Node.java 6 May 2005 01:18:52 -0000 1.10 *************** *** 50,52 **** --- 50,53 ---- public void dump(String prefix); + public String dumpToString(String prefix); } Index: XQueryGrammar.jjt =================================================================== RCS file: /cvsroot/doxquery/doxquery/src/com/doxological/doxquery/grammar/XQueryGrammar.jjt,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** XQueryGrammar.jjt 9 Apr 2005 02:16:57 -0000 1.22 --- XQueryGrammar.jjt 6 May 2005 01:18:52 -0000 1.23 *************** *** 17,26 **** options { // JavaCC options ! STATIC = false; OPTIMIZE_TOKEN_MANAGER = true; ! JAVA_UNICODE_ESCAPE = true; ! // DEBUG_PARSER = true; ! // DEBUG_LOOKAHEAD = true; ! // DEBUG_TOKEN_MANAGER = true; // JJTree options --- 17,26 ---- options { // JavaCC options ! STATIC = false; OPTIMIZE_TOKEN_MANAGER = true; ! JAVA_UNICODE_ESCAPE = true; ! // DEBUG_PARSER = true; ! // DEBUG_LOOKAHEAD = true; ! // DEBUG_TOKEN_MANAGER = true; // JJTree options *************** *** 67,71 **** public static void main(String args[]) throws ParseException { XQueryEnvironment env = new XQueryEnvironment(); ! XQueryGrammar parser = new XQueryGrammar(System.in); parser.setEnvironment(env); parser.setResourceName("stdin"); --- 67,71 ---- public static void main(String args[]) throws ParseException { XQueryEnvironment env = new XQueryEnvironment(); ! XQueryGrammar parser = new XQueryGrammar(System.in); parser.setEnvironment(env); parser.setResourceName("stdin"); *************** *** 84,89 **** private static final String DEFAULT_ELEMENT_NAMESPACE_PREFIX = "#default_element_namespace"; ! private Normaliser normaliser_ = new Normaliser(); ! private StaticAnalyser analyser_ = new StaticAnalyser(); private MutableStaticContext sContext_ = null; private List declarations_ = new LinkedList(); --- 84,96 ---- private static final String DEFAULT_ELEMENT_NAMESPACE_PREFIX = "#default_element_namespace"; ! private Normaliser normaliser_ = null; ! private StaticAnalyser analyser_ = null; ! public void setNormaliser(Normaliser n) { ! normaliser_ = n; ! } ! public void setStaticAnalyser(StaticAnalyser s) { ! analyser_ = s; ! } ! private MutableStaticContext sContext_ = null; private List declarations_ = new LinkedList(); *************** *** 193,201 **** { (VersionDecl())? (MainModule() | LibraryModule()) <EOF> { ! if(!module_.isModule()) { // Perform normalisation normaliser_.normalise(module_, sContext_); ! // Perform static analysis ! analyser_.analyse(module_, sContext_); } return module_; --- 200,210 ---- { (VersionDecl())? (MainModule() | LibraryModule()) <EOF> { ! if(!module_.isModule() && normaliser_ != null) { // Perform normalisation normaliser_.normalise(module_, sContext_); ! if(analyser_ != null) { ! // Perform static analysis ! analyser_.analyse(module_, sContext_); ! } } return module_; *************** *** 253,276 **** (NamespaceSetter() Separator() ((NamespaceSetter() | BadSetter()) Separator())*)? (VarFunctionOption() Separator() ((VarFunctionOption() | BadNamespaceSetter() | BadSetter()) Separator())*)?) { ! // Perform normalisation and static analysis on the function and variable declarations ! Iterator i = declarations_.iterator(); ! while(i.hasNext()) { ! Declaration decl = (Declaration)i.next(); ! normaliser_.normalise(decl, sContext_); ! if(decl instanceof VariableDeclaration) { ! // Check for a duplicate variable ! if(sContext_.getVariableTypeResolver().getVariableType(decl.getName()) != null) { ! throw new XQueryException("XQ0049", decl); ! } ! analyser_.analyse(decl, sContext_); ! // Add the declaration to the module ! module_.addDeclaration(decl); ! } ! else { ! // Add the declaration to the module ! module_.addDeclaration(decl); ! analyser_.analyse(decl, sContext_); } } --- 262,291 ---- (NamespaceSetter() Separator() ((NamespaceSetter() | BadSetter()) Separator())*)? (VarFunctionOption() Separator() ((VarFunctionOption() | BadNamespaceSetter() | BadSetter()) Separator())*)?) { ! if(normaliser_ != null) { ! // Perform normalisation and static analysis on the function and variable declarations ! Iterator i = declarations_.iterator(); ! while(i.hasNext()) { ! Declaration decl = (Declaration)i.next(); ! normaliser_.normalise(decl, sContext_); ! if(decl instanceof VariableDeclaration) { ! // Check for a duplicate variable ! if(sContext_.getVariableTypeResolver().getVariableType(decl.getName()) != null) { ! throw new XQueryException("XQ0049", decl); ! } ! if(analyser_ != null) { ! analyser_.analyse(decl, sContext_); ! } ! // Add the declaration to the module ! module_.addDeclaration(decl); ! } ! else { ! // Add the declaration to the module ! module_.addDeclaration(decl); ! if(analyser_ != null) { ! analyser_.analyse(decl, sContext_); ! } ! } } } *************** *** 653,657 **** void FunctionDecl() #void : { Token begin; QName name; Type type = null; Node expr = null; FunctionDeclaration funcDecl; } { ! begin=<DECLARE_FUNCTION> name=FunctionName2() { if(name == null) { throw new XQueryException("XP0008", resourceName_, begin); --- 668,672 ---- void FunctionDecl() #void : { Token begin; QName name; Type type = null; Node expr = null; FunctionDeclaration funcDecl; } { ! begin=<DECLARE_FUNCTION> name=QName2(sContext_.getDefaultFunctionNamespace()) <LBRACKET> { if(name == null) { throw new XQueryException("XP0008", resourceName_, begin); *************** *** 1175,1179 **** void StepExpr() #void : {} { ! AxisStep() | FilterExpr() } --- 1190,1194 ---- void StepExpr() #void : {} { ! LOOKAHEAD(2) FilterExpr() | AxisStep() } *************** *** 1380,1418 **** * [91] FunctionCall ::= <QName "("> (ExprSingle ("," ExprSingle)*)? ")" [gn:parens] [gn:reserved-function-names] */ ! void FunctionCall() : {} ! { ! FunctionName(jjtThis) (ExprSingle() (<COMMA> ExprSingle())*)? <RBRACKET> ! } ! void FunctionName(XQFunctionCall fc) #void : { Token t; } ! { ! t=<QNAME_LBRACKET> { ! // Search for the end of the QName ! int pos = 0; ! char c; ! for(; pos < t.image.length(); ++pos) { ! c = t.image.charAt(pos); ! if(c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '(') ! break; ! } ! ! fc.set(t.image.substring(0, pos).intern()); ! } ! } ! QName FunctionName2() #void : { Token t; } { ! t=<QNAME_LBRACKET> { ! // Search for the end of the QName ! int pos = 0; ! char c; ! for(; pos < t.image.length(); ++pos) { ! c = t.image.charAt(pos); ! if(c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '(') ! break; ! } ! ! return StringUtils.makeQName(t.image.substring(0, pos), ! sContext_.getDefaultFunctionNamespace(), ! sContext_); ! } } --- 1395,1403 ---- * [91] FunctionCall ::= <QName "("> (ExprSingle ("," ExprSingle)*)? ")" [gn:parens] [gn:reserved-function-names] */ ! void FunctionCall() : { Token t; } { ! t=<QNAME> <LBRACKET> { ! jjtThis.set(t.image.intern()); ! } (ExprSingle() (<COMMA> ExprSingle())*)? <RBRACKET> } *************** *** 2564,2568 **** | <AT_STRINGLITERAL: "at" <WS> <STRINGLITERAL>> : DEFAULT ! | <LBRACKET: "("> : DEFAULT } --- 2549,2558 ---- | <AT_STRINGLITERAL: "at" <WS> <STRINGLITERAL>> : DEFAULT ! } ! ! <DEFAULT, ITEMTYPE, OPERATOR> ! TOKEN: ! { ! <LBRACKET: "("> : DEFAULT } *************** *** 2586,2595 **** } - <DEFAULT> - TOKEN: - { - <QNAME_LBRACKET: <QNAME> (<WS>)? "("> - } - <DEFAULT, OPERATOR, KINDTEST, KINDTESTFORPI, CLOSEKINDTEST> TOKEN: --- 2576,2579 ---- Index: SimpleNode.java =================================================================== RCS file: /cvsroot/doxquery/doxquery/src/com/doxological/doxquery/grammar/SimpleNode.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SimpleNode.java 12 Apr 2005 02:15:25 -0000 1.12 --- SimpleNode.java 6 May 2005 01:18:52 -0000 1.13 *************** *** 147,150 **** --- 147,161 ---- } } + + public String dumpToString(String prefix) { + String result = toString(prefix) + "\n"; + for(Node n: children_) { + if (n != null) { + result += n.dumpToString(prefix + " "); + } + } + return result; + } + } |