private void command_BeforeExecute(Command source, Notation notation, Optimizer optimizer, QueryContext context) { this.context = context; Notation.Record[] recs = notation.Select(Descriptor.Root, 1); if (recs.Length > 0) { Notation.Record[] recsd = notation.Select(recs[0].Arg0, Descriptor.Binding, 1); if (recsd.Length > 0) throw new ESQLException("Query parameters is not supported in XQueryConsole", null); } if (context.UseSampleData) { String path = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data"); if (Directory.Exists(path)) context.DatabaseDictionary.SearchPath = path; } }
private void ProcessQueryExp(Notation notation, Symbol qexpr, QueryContext context) { Notation.Record[] recs = notation.Select(qexpr, new Descriptor[] { Descriptor.Union, Descriptor.Except }, 2); if (recs.Length > 0) { ProcessQueryExp(notation, recs[0].Arg0, context); ProcessQueryTerm(notation, recs[0].Arg1, context); } else ProcessQueryTerm(notation, qexpr, context); ConfirmBindings(notation, qexpr, context); }
private object ProcessComputedConstructor(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.CompDocConstructor, Descriptor.CompElemConstructor, Descriptor.CompAttrConstructor, Descriptor.CompTextConstructor, Descriptor.CompCommentConstructor, Descriptor.CompPIConstructor }); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.CompDocConstructor: return Lisp.List(ID.DynCreateDocument, ProcessExprList(notation, recs[0].args[0])); case Descriptor.CompElemConstructor: case Descriptor.CompAttrConstructor: { object expr = EmptyIterator.Shared; if (recs[0].args[1] != null) expr = ProcessExprList(notation, recs[0].args[1]); object name; if (recs[0].args[0] is Qname) { Qname qn = (Qname)recs[0].args[0]; if (recs[0].descriptor == Descriptor.CompElemConstructor) name = QNameValue.Parse(qn.Name, _context.NamespaceManager, _context.NamespaceManager.DefaultNamespace); else name = QNameValue.Parse(qn.Name, _context.NamespaceManager, String.Empty); if (recs[0].descriptor == Descriptor.CompElemConstructor) return Lisp.List(ID.DynCreateElement, name, expr); else return Lisp.List(ID.DynCreateAttribute, name, Lisp.List(ID.FormatValue, expr)); } else { XmlNamespaceManager nsmgr = new XmlNamespaceManager(_context.nameTable); foreach (KeyValuePair<string, string> k in _context.NamespaceManager.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)) nsmgr.AddNamespace(k.Key, k.Value); name = Lisp.List(ID.AtomizeX, ProcessExprList(notation, recs[0].args[0])); if (recs[0].descriptor == Descriptor.CompElemConstructor) return Lisp.List(ID.DynCreateElement, name, nsmgr, expr); else return Lisp.List(ID.DynCreateAttribute, name, nsmgr, Lisp.List(ID.FormatValue, expr)); } } case Descriptor.CompTextConstructor: return Lisp.List(ID.DynCreateText, Lisp.List(ID.FormatValue, ProcessExprList(notation, recs[0].args[0]))); case Descriptor.CompCommentConstructor: return Lisp.List(ID.DynCreateComment, Lisp.List(ID.FormatValue, ProcessExprList(notation, recs[0].args[0]))); case Descriptor.CompPIConstructor: { object name; if (recs[0].args[0] is Qname) name = ((Qname)recs[0].args[0]).Name; else name = Lisp.List(ID.FormatValue, ProcessExprList(notation, recs[0].args[0])); return Lisp.List(ID.DynCreatePi, name, Lisp.List(ID.FormatValue, ProcessExprList(notation, recs[0].args[1]))); } default: throw new InvalidOperationException(); } } else throw new InvalidOperationException(); }
private object ProcessFLORExpr(Notation notation, Notation.Record rec) { int stack_pos = _varTable.BeginFrame(); Symbol[] arr = Lisp.ToArray<Symbol>(rec.args[0]); List<FLWORItem> flworItems = new List<FLWORItem>(); bool stable = false; for (int k = 0; k < arr.Length; k++) { Notation.Record[] recs = notation.Select(arr[k]); switch (recs[0].descriptor) { case Descriptor.For: { Symbol[] arr2 = Lisp.ToArray<Symbol>(recs[0].args[0]); for (int s = 0; s < arr2.Length; s++) { Notation.Record[] recs2 = notation.Select(arr2[s], Descriptor.ForClauseOperator, 4); if (recs.Length > 0) { FLWORItem item = new FLWORItem(); item.desc = Descriptor.For; if (notation.Flag(arr[k], Descriptor.Parallel)) item.parallel = true; VarName name = (VarName)recs2[0].Arg0; item.var = ProcessVarName(name); item.assignExpr = ProcessExprSingle(notation, recs2[0].Arg3); item.convert = true; if (recs2[0].Arg1 == null) { XQuerySequenceType type = EvalExprType(item.assignExpr); if (type.TypeCode != XmlTypeCode.Item) { item.varType = new XQuerySequenceType(type.TypeCode, XmlTypeCardinality.One); item.convert = false; } else item.varType = XQuerySequenceType.Item; } else item.varType = ProcessTypeDecl(notation, recs2[0].Arg1); item.pos = null; if (recs2[0].Arg2 != null) { VarName posname = (VarName)recs2[0].Arg2; if (posname.Name == name.Name) throw new XQueryException(Properties.Resources.XQST0089, posname.Name); item.pos = ProcessVarName(posname); } _varTable.PushVar(item.var, item.varType); if (item.pos != null) _varTable.PushVar(item.pos, new XQuerySequenceType(XmlTypeCode.Integer)); flworItems.Add(item); } } } break; case Descriptor.Let: { Symbol[] arr2 = Lisp.ToArray<Symbol>(recs[0].args[0]); for (int s = 0; s < arr2.Length; s++) { Notation.Record[] recs2 = notation.Select(arr2[s], Descriptor.LetClauseOperator, 3); if (recs.Length > 0) { FLWORItem item = new FLWORItem(); item.desc = Descriptor.Let; item.var = ProcessVarName((VarName)recs2[0].Arg0); item.assignExpr = ProcessExprSingle(notation, recs2[0].Arg2); item.convert = true; if (recs2[0].Arg1 == null) { XQuerySequenceType type = EvalExprType(item.assignExpr); if (type.Cardinality == XmlTypeCardinality.One) { item.varType = type; item.convert = false; } else item.varType = XQuerySequenceType.Item; } else item.varType = ProcessTypeDecl(notation, recs2[0].Arg1); _varTable.PushVar(item.var, item.varType); flworItems.Add(item); } } } break; } } XQueryOrderSpec[] orderSpec = null; XQueryExprBase expr = XQueryExpr.Create(_context, new object[] { ProcessExprSingle(notation, rec.Arg3) }); if (rec.Arg2 != null) { Notation.Record[] recs = notation.Select(rec.Arg2, new Descriptor[] { Descriptor.OrderBy, Descriptor.StableOrderBy }); if (recs.Length > 0) { if (!(expr is XQueryExpr)) expr = new XQueryExpr(_context, new object[] { expr.ToLispFunction() }); stable = (recs[0].descriptor == Descriptor.StableOrderBy); Symbol[] arr3 = Lisp.ToArray<Symbol>(recs[0].args[0]); orderSpec = new XQueryOrderSpec[arr3.Length]; object[] sortKey = new object[arr3.Length]; for (int k = 0; k < arr3.Length; k++) { sortKey[k] = ProcessExprSingle(notation, arr3[k]); orderSpec[k].emptySpec = _context.EmptyOrderSpec; orderSpec[k].collation = _context.DefaultCollation; Notation.Record[] recs1 = notation.Select(arr3[k], Descriptor.Modifier, 1); if (recs1.Length > 0) { Symbol[] modifier = Lisp.ToArray<Symbol>(recs1[0].args[0]); if (modifier[0] != null) switch (((TokenWrapper)modifier[0]).Data) { case Token.ASCENDING: orderSpec[k].direction = XQueryOrderDirection.Ascending; break; case Token.DESCENDING: orderSpec[k].direction = XQueryOrderDirection.Descending; break; } if (modifier[1] != null) switch (((TokenWrapper)modifier[1]).Data) { case Token.EMPTY_GREATEST: orderSpec[k].emptySpec = XQueryEmptyOrderSpec.Greatest; break; case Token.EMPTY_LEAST: orderSpec[k].emptySpec = XQueryEmptyOrderSpec.Least; break; } if (modifier[2] != null) orderSpec[k].collation = ((Literal)modifier[2]).Data; } } ((XQueryExpr)expr).Annotation = sortKey; } } object whereExpr = null; if (rec.Arg1 != null) { Notation.Record[] recs3 = notation.Select(rec.Arg1, Descriptor.Where, 1); if (recs3.Length > 0) whereExpr = ProcessExprSingle(notation, recs3[0].Arg0); } for (int k = flworItems.Count - 1; k >= 0; k--) { FLWORItem item = flworItems[k]; switch (item.desc) { case Descriptor.For: expr = new XQueryFLWOR(_context, item.var, item.varType, item.pos, item.assignExpr, expr, item.convert); if (item.parallel && _context.EnableHPC) ((XQueryFLWOR)expr).Parallel = true; break; case Descriptor.Let: expr = new XQueryLET(_context, item.var, item.varType, item.assignExpr, expr, item.convert); break; } if (k == flworItems.Count - 1) { XQueryFLWORBase flworExpr = (XQueryFLWORBase)expr; flworExpr.ConditionExpr = whereExpr; } } _varTable.EndFrame(stack_pos); if (orderSpec != null) expr = new XQuerySorter(_context, orderSpec, stable, expr); return Lisp.List(ID.DynExecuteExpr, expr, ID.Context, Lisp.ARGV, Lisp.MPOOL); }
private object ProcessExtensionExpr(Notation notation, Notation.Record rec) { Symbol[] arr = Lisp.ToArray<Symbol>(rec.args[0]); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym, Descriptor.Pragma, 2); if (recs.Length > 0) { QNameValue qn = QNameValue.Parse(((Qname)recs[0].Arg0).Name, _context.NamespaceManager, ""); if (qn.Prefix == "") throw new XQueryException(Properties.Resources.ExpectedQNamePrefix, "pragma", qn.ToString()); Literal lit = (Literal)recs[0].Arg1; if (qn.NamespaceUri == XmlReservedNs.NsWmhExt) { if (qn.LocalName == "cache") { XQueryExprBase expr = ProcessExpr(notation, rec.args[1]); if (expr is XQueryExpr) return new XQueryCachedExpr(_context, (XQueryExpr)expr).ToLispFunction(); else return expr.ToLispFunction(); } } } } return ProcessExpr(notation, rec.args[1]).ToLispFunction(); }
private void PostProcess(Notation notation, object prolog) { if (prolog != null) { Symbol[] arr = Lisp.ToArray<Symbol>(prolog); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0) switch (recs[0].descriptor) { case Descriptor.DeclareFunction: ProcessFuncDecl(notation, recs[0]); break; case Descriptor.VarDecl: ProcessVarDecl(notation, recs[0]); break; } } } }
private FunctionParameter[] ProcessParamList(Notation notation, object p) { List<FunctionParameter> res = new List<FunctionParameter>(); if (p != null) { Symbol[] arr = Lisp.ToArray<Symbol>(p); HashSet<VarName> hs = new HashSet<VarName>(); for (int k = 0; k < arr.Length; k++) { FunctionParameter parameter = new FunctionParameter(); VarName name = (VarName)arr[k]; if (hs.Contains(name)) throw new XQueryException(Properties.Resources.XQST0039, name); hs.Add(name); parameter.id = ProcessVarName(name); Notation.Record[] recs = notation.Select(arr[k], Descriptor.TypeDecl, 1); if (recs.Length > 0) parameter.type = ProcessTypeDecl(notation, recs[0].Arg0); else parameter.type = XQuerySequenceType.Item; res.Add(parameter); } } return res.ToArray(); }
private XQuerySequenceType ProcessTypeDecl(Notation notation, Symbol sym) { if (sym.Tag == Tag.TokenWrapper && ((TokenWrapper)sym).Data == Token.EMPTY_SEQUENCE) return XQuerySequenceType.Void; else { XQuerySequenceType type = ProcessItemType(notation, sym); Notation.Record[] recs = notation.Select(sym, Descriptor.Occurrence, 1); if (recs.Length > 0) { type = new XQuerySequenceType(type); TokenWrapper w = (TokenWrapper)recs[0].Arg0; switch (w.Data) { case Token.Indicator1: // (*) type.Cardinality = XmlTypeCardinality.ZeroOrMore; break; case Token.Indicator2: // (+) type.Cardinality = XmlTypeCardinality.OneOrMore; break; case Token.Indicator3: // (?) type.Cardinality = XmlTypeCardinality.ZeroOrOne; break; } } return type; } }
private void ProcessImportModule(Notation notation, object prolog) { if (prolog != null) { Symbol[] arr = Lisp.ToArray<Symbol>(prolog); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0 && recs[0].descriptor == Descriptor.ImportModule) ProcessImportModule(notation, recs[0]); } } }
private object ProcessNodeTest(Notation notation, Symbol sym, bool attr) { if (sym.Tag == Tag.TokenWrapper) return XmlQualifiedNameTest.New(null, null); else if (sym.Tag == Tag.Qname) { Qname qn = (Qname)sym; XmlQualifiedName qualifiedName = QNameParser.Parse(qn.Name, _context.NamespaceManager, attr ? "" : _context.NamespaceManager.DefaultNamespace, _context.nameTable); return XmlQualifiedNameTest.New(qualifiedName.Name, qualifiedName.Namespace); } else { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.Wildcard1, Descriptor.Wildcard2 }, 1); if (recs.Length > 0) { Qname qname = (Qname)recs[0].Arg0; switch (recs[0].descriptor) { case Descriptor.Wildcard1: { string ns = _context.NamespaceManager.LookupNamespace(qname.Name); if (ns == null) throw new XQueryException(Properties.Resources.XPST0081, qname.Name); return XmlQualifiedNameTest.New(null, ns); } case Descriptor.Wildcard2: return XmlQualifiedNameTest.New(_context.nameTable.Add(qname.Name), null); default: throw new InvalidOperationException(); } } else return ProcessKindTest(notation, sym); } }
private XQueryExprBase ProcessPredicateList(Notation notation, Symbol sym, XQueryExprBase ancestor) { Notation.Record[] recs = notation.Select(sym, Descriptor.PredicateList, 1); if (recs.Length > 0) { Symbol[] arr = Lisp.ToArray<Symbol>(recs[0].args[0]); List<XQueryExprBase> filter = new List<XQueryExprBase>(); for (int k = 0; k < arr.Length; k++) { Notation.Record[] recs1 = notation.Select(arr[k], Descriptor.Predicate, 1); if (recs1.Length > 0) filter.Add(ProcessExpr(notation, recs1[0].args[0])); } XQueryFilterExpr filterExpr = new XQueryFilterExpr(_context, filter.ToArray()); filterExpr.Source = ancestor; return filterExpr; } return ancestor; }
private XQueryExprBase ProcessAxisStep(Notation notation, Notation.Record rec) { if (rec.Arg0.Tag == Tag.TokenWrapper && ((TokenWrapper)rec.Arg0).Data == Token.DOUBLE_PERIOD) return new XQueryStepExpr(XQueryPathExprType.Parent, _context); else { Notation.Record[] recs = notation.Select(rec.Arg0, new Descriptor[] { Descriptor.ForwardStep, Descriptor.AbbrevForward, Descriptor.ReverseStep }); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.ForwardStep: return ProcessPredicateList(notation, rec.Arg0, ProcessForwardStep(notation, recs[0])); case Descriptor.AbbrevForward: return ProcessPredicateList(notation, rec.Arg0, ProcessAbbrevForward(notation, recs[0])); case Descriptor.ReverseStep: return ProcessPredicateList(notation, rec.Arg0, ProcessReverseStep(notation, recs[0])); default: throw new InvalidOperationException(); } } else return ProcessPredicateList(notation, rec.Arg0, new XQueryStepExpr( ProcessNodeTest(notation, rec.Arg0, false), XQueryPathExprType.Child, _context)); } }
private void ProcessModuleDecl(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, Descriptor.ModuleNamespace, 2); if (recs.Length > 0) { Qname name = (Qname)recs[0].Arg0; Literal ns = (Literal)recs[0].Arg1; _context.AddNamespace(name.Name, ns.Data); } }
private XQueryExprBase ProcessStepExpr(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.AxisStep, Descriptor.FilterExpr }, 1); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.AxisStep: return ProcessAxisStep(notation, recs[0]); case Descriptor.FilterExpr: return ProcessFilterExpr(notation, recs[0]); default: throw new InvalidOperationException(); } } else throw new InvalidOperationException(); }
private void ProcessRelativePathExpr(Notation notation, Symbol sym, List<XQueryExprBase> steps) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.Child, Descriptor.Descendant }, 2); if (recs.Length > 0) { ProcessRelativePathExpr(notation, recs[0].Arg0, steps); if (recs[0].descriptor == Descriptor.Descendant) steps.Add(new XQueryStepExpr(XQuerySequenceType.Node, XQueryPathExprType.DescendantOrSelf, _context)); steps.Add(ProcessStepExpr(notation, recs[0].Arg1)); } else steps.Add(ProcessStepExpr(notation, sym)); }
private object ProcessPathExpr(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.Child, Descriptor.Descendant }, 1); List<XQueryExprBase> steps = new List<XQueryExprBase>(); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.Child: if (recs[0].Arg0 == null) return Lisp.List(ID.Seq, Lisp.List(ID.Root, Lisp.List(ID.ContextNode, ID.Context))); break; case Descriptor.Descendant: steps.Add(new XQueryStepExpr(XQuerySequenceType.Node, XQueryPathExprType.DescendantOrSelf, _context)); break; default: throw new InvalidOperationException(); } ProcessRelativePathExpr(notation, recs[0].Arg0, steps); } else ProcessRelativePathExpr(notation, sym, steps); if (steps.Count == 1 && steps[0] is XQueryExprBase) { XQueryExprBase expr = (XQueryExprBase)steps[0]; return expr.ToLispFunction(); } else { XQueryExprBase[] path = OptimizeXPath(steps); return Lisp.List(ID.DynExecuteExpr, new XQueryPathExpr(_context, path, _context.IsOrdered), ID.Context, Lisp.ARGV, Lisp.MPOOL); } }
private XQuerySequenceType ProcessKindTest(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, Descriptor.KindTest, 1); if (recs.Length > 0) { if (recs[0].Arg0.Tag == Tag.TokenWrapper) { TokenWrapper w = (TokenWrapper)recs[0].Arg0; switch (w.Data) { case Token.NODE: return XQuerySequenceType.Node; case Token.TEXT: return XQuerySequenceType.Text; case Token.COMMENT: return XQuerySequenceType.Comment; case Token.ELEMENT: return XQuerySequenceType.Element; case Token.ATTRIBUTE: return XQuerySequenceType.Attribute; case Token.DOCUMENT_NODE: return XQuerySequenceType.Document; case Token.PROCESSING_INSTRUCTION: return XQuerySequenceType.ProcessingInstruction; default: throw new InvalidOperationException(); } } else { Notation.Record[] recs1 = notation.Select(recs[0].Arg0); switch (recs1[0].descriptor) { case Descriptor.DocumentNode: return ProcessDocumentTest(notation, recs1[0]); case Descriptor.ProcessingInstruction: return ProcessPITest(notation, recs1[0]); case Descriptor.Element: return ProcessElementTest(notation, recs1[0]); case Descriptor.Attribute: return ProcessAttributeTest(notation, recs1[0]); case Descriptor.SchemaElement: return ProcessSchemaElementTest(notation, recs1[0]); case Descriptor.SchemaAttribute: return ProcessSchemaAttributeTest(notation, recs1[0]); default: throw new InvalidOperationException(); } } } else throw new InvalidOperationException(); }
private object ProcessPrimaryExpr(Notation notation, Symbol sym) { if (sym.Tag == Tag.Literal) return ((Literal)sym).Data; else if (sym.Tag == Tag.Integer) return ((IntegerValue)sym).Data; else if (sym.Tag == Tag.Double) return ((DoublelValue)sym).Data; else if (sym.Tag == Tag.Decimal) return ((DecimalValue)sym).Data; else if (sym.Tag == Tag.VarName) { XQuerySequenceType type; bool external; object var = ProcessVarName((VarName)sym); if (!_varTable.GetType(var, out type, out external)) throw new XQueryException(Properties.Resources.XPST0008, sym); if (external) _context.MarkExternalVariable(var); return var; } else if (sym.Tag == Tag.TokenWrapper) { if (((TokenWrapper)sym).Data == '.') return Lisp.List(ID.ContextNode, ID.Context); else throw new InvalidOperationException(); } else { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.ParenthesizedExpr, Descriptor.Ordered, Descriptor.Unordered, Descriptor.Funcall }); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.ParenthesizedExpr: return ProcessParenthesizedExpr(notation, recs[0]); case Descriptor.Ordered: case Descriptor.Unordered: return ProcessOrderedExpr(notation, recs[0]); case Descriptor.Funcall: return ProcessFuncallExpr(notation, recs[0]); default: throw new InvalidOperationException(); } } else return ProcessDirectConstructor(notation, sym); } }
private XQuerySequenceType ProcessDocumentTest(Notation notation, Notation.Record rec) { XQuerySequenceType typeTest = null; Notation.Record[] recs = notation.Select(rec.Arg0); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.Element: typeTest = ProcessElementTest(notation, recs[0]); break; case Descriptor.SchemaElement: typeTest = ProcessSchemaElementTest(notation, recs[0]); break; default: throw new InvalidOperationException(); } typeTest.TypeCode = XmlTypeCode.Document; } return typeTest; }
private void ProcessProlog(Notation notation, object prolog) { if (prolog != null) { Symbol[] arr = Lisp.ToArray<Symbol>(prolog); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.DefaultFunction: ProcessDefaultFunctionNS(notation, recs[0]); break; case Descriptor.Namespace: ProcessNamespace(notation, recs[0]); break; case Descriptor.BaseUri: ProcessBaseUri(notation, recs[0]); break; case Descriptor.ConstructionDecl: ProcessConstructionDecl(notation, recs[0]); break; case Descriptor.BoundarySpace: ProcessBoundarySpace(notation, recs[0]); break; case Descriptor.Ordering: ProcessOrdering(notation, recs[0]); break; case Descriptor.DefaultOrder: ProcessDefaultOrder(notation, recs[0]); break; case Descriptor.DefaultElement: ProcessDefaultElementNS(notation, recs[0]); break; case Descriptor.CopyNamespace: ProcessCopyNamespace(notation, recs[0]); break; } } } _context.InitNamespaces(); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.OptionDecl: ProcessOptionDecl(notation, recs[0]); break; case Descriptor.DefaultCollation: ProcessDefaultCollation(notation, recs[0]); break; } } } } else _context.InitNamespaces(); }
private void ProcessSchemaImport(Notation notation, object prolog) { if (prolog != null) { bool compile_flag = false; Symbol[] arr = Lisp.ToArray<Symbol>(prolog); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0 && recs[0].descriptor == Descriptor.ImportSchema) { compile_flag = true; ProcessImportSchema(notation, recs[0]); } } if (compile_flag) _context.schemaSet.Compile(); } }
private object ProcessDirectConstructor(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.DirElemConstructor, Descriptor.DirCommentConstructor, Descriptor.DirPIConstructor }); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.DirElemConstructor: { bool mapping = false; object builder = ATOM.Create("b"); List<object> stmt = new List<object>(); stmt.Add(Funcs.Progn); WriteDirElemConstructor(notation, recs[0], builder, stmt, ref mapping); stmt.Add(Lisp.List(ID.CreateNavigator, builder)); object body = Lisp.List(stmt.ToArray()); object res; if (mapping) res = new XQueryLET(_context, builder, XQuerySequenceType.Item, Lisp.Cons(ID.CreateBuilder), new XQueryExpr(_context, new object[] { body }), false); else res = Lisp.List(Funcs.Let1, Lisp.Cons(Lisp.List(builder, Lisp.Cons(ID.CreateBuilder))), body); Notation.Record[] recs1 = notation.Select(sym, Descriptor.MappingExpr, 1); if (recs1.Length > 0) // Mapping extension support { if (!mapping) res = new XQueryExpr(_context, new object[] { res }); return new XQueryMapping(_context, ProcessPathExpr(notation, recs1[0].Arg0), (XQueryExprBase)res, true).ToLispFunction(); } else { if (mapping) return ((XQueryExprBase)res).ToLispFunction(); return res; } } case Descriptor.DirCommentConstructor: { Literal lit = (Literal)recs[0].Arg0; return Lisp.List(ID.CreateNavigator, Lisp.List(ID.WriteComment, Lisp.Cons(ID.CreateBuilder), lit.Data)); } case Descriptor.DirPIConstructor: { Literal name = (Literal)recs[0].Arg0; Literal data = (Literal)recs[0].Arg1; return Lisp.List(ID.CreateNavigator, Lisp.List(ID.WritePi, Lisp.Cons(ID.CreateBuilder), name.Data, data != null ? data.Data : String.Empty)); } default: throw new InvalidOperationException(); } } else return ProcessComputedConstructor(notation, sym); }
private void ProcessFunctionDecl(Notation notation, object prolog) { if (prolog != null) { Symbol[] arr = Lisp.ToArray<Symbol>(prolog); foreach (Symbol sym in arr) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0 && recs[0].descriptor == Descriptor.DeclareFunction) PreProcessFuncDecl(notation, recs[0]); } } }
private void WriteDirElemConstructor(Notation notation, Notation.Record rec, object builder, List<object> stmt, ref bool mapping) { string prefix; string localName; string ns; bool openScope = false; HashSet<XmlQualifiedName> hs = new HashSet<XmlQualifiedName>(); foreach (Symbol sym in Lisp.getIterator<Symbol>(rec.args[1])) if (sym.Tag != Tag.Literal) { Notation.Record[] recs = notation.Select(sym, Descriptor.DirAttribute, 5); if (recs.Length > 0) { Qname name = (Qname)recs[0].Arg0; QNameParser.Split(name.Name, out prefix, out localName); if (prefix == "xmlns" || (prefix == "" && localName == "xmlns")) { if (!openScope) { _context.NamespaceManager.PushScope(); openScope = true; } Symbol[] arr = Lisp.ToArray<Symbol>(recs[0].args[4]); if (arr.Length != 1 || !(arr[0] is Literal)) throw new XQueryException(Properties.Resources.XQST0022, localName); Literal targetNamespace = (Literal)arr[0]; if (prefix != "" && targetNamespace.Data == "") throw new XQueryException(Properties.Resources.XQST0088); if (localName == "xml" || (prefix == "xmlns" && localName == "xmlns")) throw new XQueryException(Properties.Resources.XQST0070, targetNamespace.Data); if (prefix == "" && localName == "xmlns") _context.NamespaceManager.AddNamespace("", targetNamespace.Data); else _context.NamespaceManager.AddNamespace(localName, targetNamespace.Data); } } } ProcessElementQName((Qname)rec.Arg0, out prefix, out localName, out ns); stmt.Add(Lisp.List(ID.WriteBeginElement, builder, new QNameValue(prefix, localName, ns, _context.nameTable))); if (rec.args[1] != null) { foreach (Symbol sym in Lisp.getIterator<Symbol>(rec.args[1])) { if (sym.Tag != Tag.Literal) { Notation.Record[] recs = notation.Select(sym, Descriptor.DirAttribute, 5); if (recs.Length > 0) { Qname name = (Qname)recs[0].Arg0; ProcessAttributeQName(name, out prefix, out localName, out ns); XmlQualifiedName qn = new XmlQualifiedName(localName, ns); if (hs.Contains(qn)) throw new XQueryException(Properties.Resources.XQST0040, name); hs.Add(qn); if (prefix != "xmlns" && (prefix != "" || localName != "xmlns")) { stmt.Add(Lisp.List(ID.WriteBeginAttribute, builder, new QNameValue(prefix, localName, ns, _context.nameTable))); WriteDirAttributeValue(notation, recs[0].args[4], builder, stmt); stmt.Add(Lisp.List(ID.WriteEndAttribute, builder)); } else { Symbol[] arr = Lisp.ToArray<Symbol>(recs[0].args[4]); Literal targetNamespace = (Literal)arr[0]; stmt.Add(Lisp.List(ID.WriteBeginAttribute, builder, new QNameValue(prefix, localName, XmlReservedNs.NsXmlNs, _context.nameTable))); stmt.Add(Lisp.List(ID.WriteString, builder, targetNamespace.Data)); stmt.Add(Lisp.List(ID.WriteEndAttribute, builder)); } } } } } if (rec.args.Length > 2 && rec.args[2] != null) foreach (Symbol sym in Lisp.getIterator<Symbol>(rec.args[2])) WriteDirElemContent(notation, sym, builder, stmt, ref mapping); stmt.Add(Lisp.List(ID.WriteEndElement, builder)); if (openScope) _context.NamespaceManager.PopScope(); }
private void ProcessImportSchema(Notation notation, Notation.Record rec) { _context.NeedValidatedParser = true; Literal uri = (Literal)rec.Arg1; if (rec.Arg0 != null) { Notation.Record[] recs = notation.Select(rec.Arg0, Descriptor.Namespace, 1); if (recs.Length > 0) { Qname prefix = (Qname)recs[0].Arg0; if (_context.NamespaceManager.HasNamespace(prefix.Name)) throw new XQueryException(Properties.Resources.XQST0033, prefix.Name); _context.AddNamespace(prefix.Name, uri.Data); } else { recs = notation.Select(rec.Arg0, Descriptor.DefaultElement, 0); if (recs.Length > 0) { if (_context.NamespaceManager.DefaultNamespace != "") throw new XQueryException(Properties.Resources.XQST0066); _context.NamespaceManager.AddNamespace("", uri.Data); } else throw new InvalidOperationException(); } } if (_schemaNs.IndexOf(uri.Data) != -1) throw new XQueryException(Properties.Resources.XQST0058, uri.Data); _schemaNs.Add(uri.Data); Literal[] arr; if (rec.args[2] != null) arr = Lisp.ToArray<Literal>(rec.args[2]); else arr = _context.ResolveSchemaImport(String.Empty, uri.Data); for (int k = 0; k < arr.Length; k++) { string filename; if (_context.uri != null) { Uri targetUri = new Uri(new Uri(_context.uri), arr[k].Data); if (targetUri.Scheme == "file") filename = targetUri.LocalPath; else filename = targetUri.AbsoluteUri; } else { filename = _context.GetFileName(arr[k].Data); if (filename == null) throw new XQueryException(Properties.Resources.FileNotFound, filename); } try { _context.schemaSet.Add(uri.Data, filename); } catch (WebException ex) { throw new XQueryException(ex.Message, ex); } } }
public XQueryExprBase Process(Notation notation) { // Phase 2. Generation Notation.Record[] recs = notation.Select(Descriptor.Root, 1); if (recs.Length == 0) throw new InvalidOperationException(); Notation.Record[] recs_c = notation.Select(recs[0].Arg0, new Descriptor[] { Descriptor.Query, Descriptor.Library }); if (recs_c.Length > 0) if (recs_c[0].descriptor == Descriptor.Query) { ProcessSchemaImport(notation, recs_c[0].args[0]); ProcessImportModule(notation, recs_c[0].args[0]); ProcessFunctionDecl(notation, recs_c[0].args[0]); PostProcess(notation, recs_c[0].args[0]); return ProcessExpr(notation, recs_c[0].args[1]); } else { ProcessSchemaImport(notation, recs_c[0].args[1]); ProcessImportModule(notation, recs_c[0].args[1]); ProcessFunctionDecl(notation, recs_c[0].args[1]); PostProcess(notation, recs_c[0].args[1]); } return null; }
private object ProcessExprSingle(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym); switch (recs[0].descriptor) { case Descriptor.FLWORExpr: return ProcessFLORExpr(notation, recs[0]); case Descriptor.Some: case Descriptor.Every: return ProcessQuantifiedExpr(notation, recs[0]); case Descriptor.Typeswitch: return ProcessTypeswitchExpr(notation, recs[0]); case Descriptor.If: return ProcessIfExpr(notation, recs[0]); default: return ProcessOrExpr(notation, sym); } }
private void WriteCommonContent(Notation notation, Symbol sym, object builder, List<object> stmt, bool attr) { if (sym.Tag == Tag.Literal) { string value = ((Literal)sym).Data; stmt.Add(Lisp.List(ID.WriteString, builder, value)); } else if (sym.Tag == Tag.PredefinedEntityRef) stmt.Add(Lisp.List(ID.WriteString, builder, ((PredefinedEntityRef)sym).Data)); else if (sym.Tag == Tag.CharRef) { if (sym is CharRefHex) { CharRefHex charRef = (CharRefHex)sym; stmt.Add(Lisp.List(ID.WriteString, builder, String.Format("&#x{0};", charRef.Data))); } else { CharRef charRef = (CharRef)sym; stmt.Add(Lisp.List(ID.WriteString, builder, String.Format("&#{0};", charRef.Data))); } } else { Notation.Record[] recs = notation.Select(sym, Descriptor.EnclosedExpr, 1); if (recs.Length > 0) { object expr = ProcessExprList(notation, recs[0].args[0]); if (attr) stmt.Add(Lisp.List(ID.WriteString, builder, Lisp.List(ID.FormatValue, expr))); else stmt.Add(Lisp.List(ID.WriteNode, builder, expr)); } else throw new InvalidOperationException(); } }
private void WriteDirElemContent(Notation notation, Symbol sym, object builder, List<object> stmt, ref bool mapping) { if (sym.Tag == Tag.Literal) { Literal lit = (Literal)sym; if (XmlCharType.Instance.IsOnlyWhitespace(lit.Data)) { if (_context.PreserveBoundarySpace) stmt.Add(Lisp.List(ID.WriteString, builder, lit.Data)); } else stmt.Add(Lisp.List(ID.WriteString, builder, lit.Data)); } else if (sym.Tag == Tag.Constructor) { Notation.Record[] recs = notation.Select(sym, new Descriptor[] { Descriptor.DirElemConstructor, Descriptor.DirCommentConstructor, Descriptor.DirPIConstructor }); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.DirElemConstructor: { Notation.Record[] recs1 = notation.Select(recs[0].sym, Descriptor.MappingExpr, 1); if (recs1.Length > 0) // Mapping extension support { List<object> group = new List<object>(); group.Add(Funcs.Progn); WriteDirElemConstructor(notation, recs[0], builder, group, ref mapping); stmt.Add(new XQueryMapping(_context, ProcessPathExpr(notation, recs1[0].Arg0), new XQueryExpr(_context, new object[] { Lisp.List(group.ToArray()) }), false).ToLispFunction()); mapping = true; } else WriteDirElemConstructor(notation, recs[0], builder, stmt, ref mapping); } break; case Descriptor.DirCommentConstructor: { Literal lit = (Literal)recs[0].Arg0; stmt.Add(Lisp.List(ID.WriteComment, builder, lit.Data)); } break; case Descriptor.DirPIConstructor: { Literal name = (Literal)recs[0].Arg0; Literal data = (Literal)recs[0].Arg1; stmt.Add(Lisp.List(ID.WritePi, builder, name.Data, data != null ? data.Data : String.Empty)); } break; default: throw new InvalidOperationException(); } } else throw new InvalidOperationException(); } else { Notation.Record[] recs = notation.Select(sym, Descriptor.CDataSection, 1); if (recs.Length > 0) stmt.Add(Lisp.List(ID.WriteCdata, builder, ((Literal)recs[0].Arg0).Data)); else WriteCommonContent(notation, sym, builder, stmt, false); } }
private object ProcessValueExpr(Notation notation, Symbol sym) { Notation.Record[] recs = notation.Select(sym); if (recs.Length > 0) { switch (recs[0].descriptor) { case Descriptor.ExtensionExpr: return ProcessExtensionExpr(notation, recs[0]); case Descriptor.Validate: return ProcessValidateExpr(notation, recs[0]); default: return ProcessPathExpr(notation, sym); } } else throw new InvalidOperationException(); }