XPath2Expression.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. //
  2. // XPath2Expression.cs - abstract syntax tree for XPath 2.0
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. using System.Xml;
  33. using System.Xml.Schema;
  34. using System.Xml.XPath;
  35. namespace Mono.Xml.XPath2
  36. {
  37. public class ExprSequence
  38. {
  39. ArrayList list = new ArrayList ();
  40. public ExprSequence ()
  41. {
  42. }
  43. public void Add (ExprSingle expr)
  44. {
  45. list.Add (expr);
  46. }
  47. public void Insert (int pos, ExprSingle expr)
  48. {
  49. list.Insert (pos, expr);
  50. }
  51. public void Reverse ()
  52. {
  53. list.Reverse ();
  54. }
  55. }
  56. public abstract class ExprSingle
  57. {
  58. }
  59. // FLWORExpr
  60. public class FLWORExpr : ExprSingle
  61. {
  62. public FLWORExpr (ForLetClauseCollection forlet, ExprSequence whereClause, OrderSpecList orderBy, ExprSingle ret)
  63. {
  64. this.fl = forlet;
  65. this.whereClause = whereClause;
  66. this.orderBy = orderBy;
  67. this.ret = ret;
  68. }
  69. ForLetClauseCollection fl;
  70. ExprSequence whereClause;
  71. OrderSpecList orderBy;
  72. ExprSingle ret;
  73. public ForLetClauseCollection ForLetClauses {
  74. get { return fl; }
  75. }
  76. public ExprSequence WhereClause {
  77. get { return whereClause; }
  78. }
  79. public OrderSpecList OrderBy {
  80. get { return orderBy; }
  81. }
  82. public ExprSingle ReturnExpr {
  83. get { return ret; }
  84. }
  85. }
  86. public class ForLetClauseCollection
  87. {
  88. ArrayList list = new ArrayList ();
  89. public void Add (ForLetClause clause)
  90. {
  91. list.Add (clause);
  92. }
  93. public void Reverse ()
  94. {
  95. list.Reverse ();
  96. }
  97. }
  98. public class OrderSpecList
  99. {
  100. bool isStable;
  101. ArrayList list = new ArrayList ();
  102. public OrderSpecList ()
  103. {
  104. }
  105. public bool IsStable {
  106. get { return isStable; }
  107. set { isStable = value; }
  108. }
  109. public void Add (OrderSpec spec)
  110. {
  111. list.Add (spec);
  112. }
  113. public void Reverse ()
  114. {
  115. list.Reverse ();
  116. }
  117. }
  118. public class OrderSpec
  119. {
  120. public OrderSpec (ExprSingle expr, OrderModifier modifier)
  121. {
  122. this.expr = expr;
  123. this.mod = modifier;
  124. }
  125. ExprSingle expr;
  126. OrderModifier mod;
  127. public ExprSingle Expression {
  128. get {return expr; }
  129. set { expr = value; }
  130. }
  131. public OrderModifier Modifier {
  132. get { return mod; }
  133. set { mod = value; }
  134. }
  135. }
  136. public class OrderModifier
  137. {
  138. public OrderModifier (XmlSortOrder order, XmlSortOrder emptyOrder, string collation)
  139. {
  140. this.sortOrder = sortOrder;
  141. this.emptyOrder = emptyOrder;
  142. this.coll = collation;
  143. }
  144. XmlSortOrder sortOrder;
  145. XmlSortOrder emptyOrder;
  146. string coll;
  147. public XmlSortOrder SortOrder{
  148. get { return sortOrder; }
  149. }
  150. public XmlSortOrder EmptyOrder {
  151. get { return emptyOrder; }
  152. }
  153. public string Collation {
  154. get { return coll; }
  155. }
  156. }
  157. public class ForLetClause
  158. {
  159. ArrayList list = new ArrayList ();
  160. protected ArrayList List {
  161. get { return list; }
  162. }
  163. public void Reverse ()
  164. {
  165. list.Reverse ();
  166. }
  167. }
  168. public class ForClause : ForLetClause
  169. {
  170. public ForClause ()
  171. {
  172. }
  173. public void Add (ForSingleBody body)
  174. {
  175. List.Add (body);
  176. }
  177. }
  178. public class LetClause : ForLetClause
  179. {
  180. public LetClause ()
  181. {
  182. }
  183. public void Add (LetSingleBody body)
  184. {
  185. List.Add (body);
  186. }
  187. }
  188. public class ForSingleBody
  189. {
  190. public ForSingleBody (XmlQualifiedName varName, SequenceType type, XmlQualifiedName positionalVar, ExprSingle expr)
  191. {
  192. this.varName = varName;
  193. this.type = type;
  194. this.positionalVar = positionalVar;
  195. this.expr = expr;
  196. }
  197. XmlQualifiedName varName;
  198. XmlQualifiedName positionalVar;
  199. SequenceType type;
  200. ExprSingle expr;
  201. public XmlQualifiedName VarName {
  202. get { return varName; }
  203. }
  204. public SequenceType ReturnType {
  205. get { return type; }
  206. }
  207. public XmlQualifiedName PositionalVar {
  208. get { return positionalVar; }
  209. }
  210. public ExprSingle Expression {
  211. get { return expr; }
  212. }
  213. }
  214. public class LetSingleBody
  215. {
  216. public LetSingleBody (XmlQualifiedName varName, SequenceType type, ExprSingle expr)
  217. {
  218. this.varName = varName;
  219. this.type = type;
  220. this.expr = expr;
  221. }
  222. XmlQualifiedName varName;
  223. SequenceType type;
  224. ExprSingle expr;
  225. public XmlQualifiedName VarName {
  226. get { return varName; }
  227. set { varName = value; }
  228. }
  229. public SequenceType ReturnType {
  230. get { return type; }
  231. set { type =value; }
  232. }
  233. public ExprSingle Expression {
  234. get { return expr; }
  235. set { expr = value; }
  236. }
  237. }
  238. // QuantifiedExpr
  239. public class QuantifiedExpr : ExprSingle
  240. {
  241. public QuantifiedExpr (bool every, QuantifiedExprBodyList body, ExprSingle satisfies)
  242. {
  243. }
  244. }
  245. public class QuantifiedExprBodyList
  246. {
  247. ArrayList list = new ArrayList ();
  248. public QuantifiedExprBodyList ()
  249. {
  250. }
  251. public void Add (QuantifiedExprBody body)
  252. {
  253. list.Add (body);
  254. }
  255. public void Reverse ()
  256. {
  257. list.Reverse ();
  258. }
  259. }
  260. public class QuantifiedExprBody
  261. {
  262. private XmlQualifiedName varName;
  263. private SequenceType typeDeclaration;
  264. private ExprSingle expr;
  265. public QuantifiedExprBody (XmlQualifiedName varName,
  266. SequenceType typeDeclaration,
  267. ExprSingle expr)
  268. {
  269. this.varName = varName;
  270. this.typeDeclaration = typeDeclaration;
  271. this.expr = expr;
  272. }
  273. public XmlQualifiedName VarName {
  274. get { return varName; }
  275. }
  276. public SequenceType TypeDeclaration {
  277. get { return typeDeclaration; }
  278. }
  279. public ExprSingle Expression {
  280. get { return expr; }
  281. }
  282. }
  283. // TypeswitchExpr
  284. public class TypeswitchExpr : ExprSingle
  285. {
  286. public TypeswitchExpr (ExprSequence switchExpr, CaseClauseList caseList, XmlQualifiedName variableSpecName, ExprSingle defaultReturn)
  287. {
  288. }
  289. }
  290. public class CaseClauseList : CollectionBase
  291. {
  292. ArrayList list = new ArrayList ();
  293. public void Add (CaseClause cc)
  294. {
  295. list.Add (cc);
  296. }
  297. public void Reverse ()
  298. {
  299. list.Reverse ();
  300. }
  301. }
  302. public class CaseClause
  303. {
  304. public CaseClause (SequenceType type, ExprSingle expr, XmlQualifiedName varName)
  305. {
  306. }
  307. }
  308. // IfExpr
  309. public class IfExpr : ExprSingle
  310. {
  311. public IfExpr (ExprSequence condition, ExprSingle trueExpr, ExprSingle falseExpr)
  312. {
  313. }
  314. }
  315. // logical expr
  316. public abstract class BinaryOperationExpr : ExprSingle
  317. {
  318. protected BinaryOperationExpr (ExprSingle left, ExprSingle right)
  319. {
  320. this.left = left;
  321. this.right = right;
  322. }
  323. ExprSingle left, right;
  324. public ExprSingle Left {
  325. get { return left; }
  326. }
  327. public ExprSingle Right{
  328. get { return right; }
  329. }
  330. }
  331. public class OrExpr : BinaryOperationExpr
  332. {
  333. public OrExpr (ExprSingle left, ExprSingle right)
  334. : base (left, right)
  335. {
  336. }
  337. }
  338. public class AndExpr : BinaryOperationExpr
  339. {
  340. public AndExpr (ExprSingle left, ExprSingle right)
  341. : base (left, right)
  342. {
  343. }
  344. }
  345. // TypeOperation expr
  346. public abstract class TypeOperationExpr : ExprSingle
  347. {
  348. protected TypeOperationExpr (ExprSingle expr, SequenceType type)
  349. {
  350. this.expr = expr;
  351. this.type = type;
  352. }
  353. ExprSingle expr;
  354. SequenceType type;
  355. public ExprSingle Expr {
  356. get { return expr; }
  357. }
  358. public SequenceType Type {
  359. get { return type; }
  360. }
  361. }
  362. public abstract class AtomicTypeOperationExpr : ExprSingle
  363. {
  364. protected AtomicTypeOperationExpr (ExprSingle expr, XmlTypeCode type, bool optional)
  365. {
  366. this.expr = expr;
  367. this.typeCode = type;
  368. this.optional = optional;
  369. }
  370. ExprSingle expr;
  371. XmlTypeCode typeCode;
  372. bool optional;
  373. public ExprSingle Expr {
  374. get { return expr; }
  375. }
  376. public XmlTypeCode TypeCode {
  377. get { return typeCode; }
  378. }
  379. public bool Optional {
  380. get { return optional; }
  381. }
  382. }
  383. public class InstanceOfExpr : TypeOperationExpr
  384. {
  385. public InstanceOfExpr (ExprSingle expr, SequenceType type)
  386. : base (expr, type)
  387. {
  388. }
  389. }
  390. public class TreatExpr : TypeOperationExpr
  391. {
  392. public TreatExpr (ExprSingle expr, SequenceType type)
  393. : base (expr, type)
  394. {
  395. }
  396. }
  397. public class CastableExpr : AtomicTypeOperationExpr
  398. {
  399. public CastableExpr (ExprSingle expr, XmlTypeCode atomicType, bool optional)
  400. : base (expr, atomicType, optional)
  401. {
  402. }
  403. }
  404. public class CastExpr : AtomicTypeOperationExpr
  405. {
  406. public CastExpr (ExprSingle expr, XmlTypeCode atomicType, bool optional)
  407. : base (expr, atomicType, optional)
  408. {
  409. }
  410. }
  411. // ComparisonExpr
  412. public class ComparisonExpr : BinaryOperationExpr
  413. {
  414. public ComparisonExpr (ExprSingle left, ExprSingle right, ComparisonOperator oper)
  415. : base (left, right)
  416. {
  417. }
  418. }
  419. public enum ComparisonOperator {
  420. ValueEQ,
  421. ValueNE,
  422. ValueLT,
  423. ValueLE,
  424. ValueGT,
  425. ValueGE,
  426. GeneralEQ,
  427. GeneralNE,
  428. GeneralLT,
  429. GeneralLE,
  430. GeneralGT,
  431. GeneralGE,
  432. NodeIs,
  433. NodeFWD,
  434. NodeBWD
  435. }
  436. // Range
  437. public class RangeExpr : BinaryOperationExpr
  438. {
  439. public RangeExpr (ExprSingle left, ExprSingle right)
  440. : base (left, right)
  441. {
  442. }
  443. }
  444. // arithmetic operation expr
  445. public enum ArithmeticOperator {
  446. Plus,
  447. Minus,
  448. Mul,
  449. Div,
  450. IDiv,
  451. IMod
  452. }
  453. public class ArithmeticOperationExpr : BinaryOperationExpr
  454. {
  455. public ArithmeticOperationExpr (ExprSingle left, ExprSingle right, ArithmeticOperator oper)
  456. : base (left, right)
  457. {
  458. }
  459. }
  460. public class MinusExpr : ExprSingle
  461. {
  462. public MinusExpr (ExprSingle expr)
  463. {
  464. }
  465. }
  466. // aggregation expr
  467. public class UnionExpr : BinaryOperationExpr
  468. {
  469. public UnionExpr (ExprSingle left, ExprSingle right)
  470. : base (left, right)
  471. {
  472. }
  473. }
  474. public class IntersectExpr : BinaryOperationExpr
  475. {
  476. public IntersectExpr (ExprSingle left, ExprSingle right)
  477. : base (left, right)
  478. {
  479. }
  480. }
  481. public class ExceptExpr : BinaryOperationExpr
  482. {
  483. public ExceptExpr (ExprSingle left, ExprSingle right)
  484. : base (left, right)
  485. {
  486. }
  487. }
  488. // validate expr
  489. public class ValidateExpr : ExprSingle
  490. {
  491. XmlSchemaContentProcessing schemaMode;
  492. ExprSequence expr;
  493. public ValidateExpr (XmlSchemaContentProcessing schemaMode, ExprSequence expr)
  494. {
  495. this.schemaMode = schemaMode;
  496. this.expr = expr;
  497. }
  498. }
  499. // Path expr
  500. public abstract class PathExpr : ExprSingle
  501. {
  502. }
  503. // '/'
  504. public class PathExprRoot : PathExpr
  505. {
  506. public PathExprRoot ()
  507. {
  508. }
  509. }
  510. // 'foo/bar'
  511. public class PathExprChild : PathExpr
  512. {
  513. ExprSingle left;
  514. ExprSingle child;
  515. public PathExprChild (ExprSingle left, ExprSingle child)
  516. {
  517. this.left = left;
  518. this.child = child;
  519. }
  520. }
  521. // 'foo//bar'
  522. public class PathExprDescendant : PathExpr
  523. {
  524. ExprSingle left;
  525. ExprSingle descendant;
  526. public PathExprDescendant (ExprSingle left, ExprSingle descendant)
  527. {
  528. this.left = left;
  529. this.descendant = descendant;
  530. }
  531. }
  532. public abstract class StepExpr : PathExpr
  533. {
  534. }
  535. public class AxisStepExpr : StepExpr
  536. {
  537. public AxisStepExpr (XPathAxis axis, NodeTestExpr test)
  538. {
  539. }
  540. static AxisStepExpr parentStep;
  541. static AxisStepExpr ()
  542. {
  543. parentStep = new AxisStepExpr (XPathAxis.Parent, null);
  544. }
  545. public static AxisStepExpr ParentStep {
  546. get { return parentStep; }
  547. }
  548. }
  549. public class FilterStepExpr : StepExpr
  550. {
  551. public FilterStepExpr (ExprSingle expr, ExprSequenceList predicates)
  552. {
  553. }
  554. }
  555. // predicates == exprsequence list == list of list of exprsingle
  556. public class ExprSequenceList
  557. {
  558. ArrayList list = new ArrayList ();
  559. public void Add (ExprSequence expr)
  560. {
  561. list.Add (expr);
  562. }
  563. public void Insert (int pos, ExprSequence expr)
  564. {
  565. list.Insert (pos, expr);
  566. }
  567. }
  568. public enum XPathAxisType
  569. {
  570. Child,
  571. Descendant,
  572. Attribute,
  573. Self,
  574. DescendantOrSelf,
  575. FollowingSibling,
  576. Following,
  577. Parent,
  578. Ancestor,
  579. PrecedingSibling,
  580. Preceding,
  581. AncestorOrSelf
  582. }
  583. public class XPathAxis
  584. {
  585. // FIXME: add more parameters to distinguish them
  586. private XPathAxis (XPathAxisType axisType)
  587. {
  588. this.axisType = axisType;
  589. switch (axisType) {
  590. case XPathAxisType.Parent:
  591. case XPathAxisType.Ancestor:
  592. case XPathAxisType.AncestorOrSelf:
  593. case XPathAxisType.Preceding:
  594. case XPathAxisType.PrecedingSibling:
  595. this.reverse = true;
  596. break;
  597. }
  598. }
  599. bool reverse;
  600. XPathAxisType axisType;
  601. public bool ReverseAxis {
  602. get { return reverse; }
  603. }
  604. public XPathAxisType AxisType {
  605. get { return axisType; }
  606. }
  607. static XPathAxis child, descendant, attribute, self,
  608. descendantOrSelf, followingSibling, following,
  609. parent, ancestor, precedingSibling, preceding,
  610. ancestorOrSelf;
  611. static XPathAxis ()
  612. {
  613. child = new XPathAxis (XPathAxisType.Child);
  614. descendant = new XPathAxis (XPathAxisType.Descendant);
  615. attribute = new XPathAxis (XPathAxisType.Attribute);
  616. self = new XPathAxis (XPathAxisType.Self);
  617. descendantOrSelf = new XPathAxis (XPathAxisType.DescendantOrSelf);
  618. followingSibling = new XPathAxis (XPathAxisType.FollowingSibling);
  619. following = new XPathAxis (XPathAxisType.Following);
  620. parent = new XPathAxis (XPathAxisType.Parent);
  621. ancestor = new XPathAxis (XPathAxisType.Ancestor);
  622. precedingSibling = new XPathAxis (XPathAxisType.PrecedingSibling);
  623. preceding = new XPathAxis (XPathAxisType.Preceding);
  624. ancestorOrSelf = new XPathAxis (XPathAxisType.AncestorOrSelf);
  625. }
  626. public static XPathAxis Child {
  627. get { return child; }
  628. }
  629. public static XPathAxis Descendant {
  630. get { return descendant; }
  631. }
  632. public static XPathAxis Attribute {
  633. get { return attribute; }
  634. }
  635. public static XPathAxis Self {
  636. get { return self; }
  637. }
  638. public static XPathAxis DescendantOrSelf {
  639. get { return descendantOrSelf; }
  640. }
  641. public static XPathAxis FollowingSibling {
  642. get { return followingSibling; }
  643. }
  644. public static XPathAxis Following {
  645. get { return following; }
  646. }
  647. public static XPathAxis Parent {
  648. get { return parent; }
  649. }
  650. public static XPathAxis Ancestor {
  651. get { return ancestor; }
  652. }
  653. public static XPathAxis PrecedingSibling {
  654. get { return precedingSibling; }
  655. }
  656. public static XPathAxis Preceding {
  657. get { return preceding; }
  658. }
  659. public static XPathAxis AncestorOrSelf {
  660. get { return ancestorOrSelf; }
  661. }
  662. }
  663. // NodeTest
  664. public abstract class NodeTestExpr : StepExpr
  665. {
  666. }
  667. public class NodeNameTestExpr : NodeTestExpr
  668. {
  669. XmlQualifiedName name;
  670. public NodeNameTestExpr (XmlQualifiedName name)
  671. {
  672. this.name = name;
  673. }
  674. public XmlQualifiedName Name {
  675. get { return name; }
  676. }
  677. }
  678. public class NodeKindTestExpr : NodeTestExpr
  679. {
  680. public NodeKindTestExpr (XmlTypeCode type)
  681. {
  682. // item() -> XPathNodeType.All
  683. this.nodeKind = type;
  684. }
  685. XmlTypeCode nodeKind;
  686. public XmlTypeCode NodeKind {
  687. get { return nodeKind; }
  688. }
  689. }
  690. public class DocumentTestExpr : NodeKindTestExpr
  691. {
  692. ElementTestExpr content;
  693. public DocumentTestExpr (ElementTestExpr content)
  694. : base (XmlTypeCode.Document)
  695. {
  696. this.content = content;
  697. }
  698. }
  699. public class ElementTestExpr : NodeKindTestExpr
  700. {
  701. public ElementTestExpr (XmlQualifiedName name)
  702. : base (XmlTypeCode.Element)
  703. {
  704. this.name = name;
  705. }
  706. public ElementTestExpr (XmlQualifiedName name, XmlQualifiedName typeName, bool nillable)
  707. : base (XmlTypeCode.Element)
  708. {
  709. this.name = name;
  710. this.typeName = typeName;
  711. this.nillable = nillable;
  712. }
  713. XmlQualifiedName name;
  714. XmlQualifiedName typeName;
  715. bool nillable;
  716. public XmlQualifiedName Name {
  717. get { return name; }
  718. }
  719. public XmlQualifiedName TypeName {
  720. get { return typeName; }
  721. }
  722. public bool Nillable {
  723. get { return nillable; }
  724. }
  725. }
  726. public class AttributeTestExpr : NodeKindTestExpr
  727. {
  728. static AttributeTestExpr anyAttribute;
  729. static AttributeTestExpr ()
  730. {
  731. anyAttribute = new AttributeTestExpr (XmlQualifiedName.Empty);
  732. }
  733. public static AttributeTestExpr AnyAttribute {
  734. get { return anyAttribute; }
  735. }
  736. public AttributeTestExpr (XmlQualifiedName name)
  737. : base (XmlTypeCode.Attribute)
  738. {
  739. this.name = name;
  740. }
  741. public AttributeTestExpr (XmlQualifiedName name, XmlQualifiedName typeName)
  742. : base (XmlTypeCode.Attribute)
  743. {
  744. this.name = name;
  745. this.typeName = typeName;
  746. }
  747. XmlQualifiedName name;
  748. XmlQualifiedName typeName;
  749. public XmlQualifiedName Name {
  750. get { return name; }
  751. }
  752. public XmlQualifiedName TypeName {
  753. get { return typeName; }
  754. }
  755. }
  756. public class XmlPITestExpr : NodeKindTestExpr
  757. {
  758. string name;
  759. public XmlPITestExpr (string nameTest)
  760. : base (XmlTypeCode.ProcessingInstruction)
  761. {
  762. this.name = nameTest;
  763. }
  764. }
  765. public class EnclosedExpr : ExprSingle
  766. {
  767. ExprSequence expr;
  768. public EnclosedExpr (ExprSequence expr)
  769. {
  770. this.expr = expr;
  771. }
  772. }
  773. // PrimaryExpr
  774. public abstract class PrimaryExpr : ExprSingle
  775. {
  776. }
  777. public class StringLiteralExpr : PrimaryExpr
  778. {
  779. string literal;
  780. public StringLiteralExpr (string literal)
  781. {
  782. this.literal = literal;
  783. }
  784. }
  785. public class NumberLiteralExpr : PrimaryExpr
  786. {
  787. decimal value;
  788. public NumberLiteralExpr (decimal value)
  789. {
  790. this.value = value;
  791. }
  792. }
  793. public class VariableReferenceExpr : PrimaryExpr
  794. {
  795. XmlQualifiedName varName;
  796. public VariableReferenceExpr (XmlQualifiedName varName)
  797. {
  798. this.varName = varName;
  799. }
  800. public XmlQualifiedName VariableName {
  801. get { return varName; }
  802. }
  803. }
  804. public class ParenthesizedExpr : PrimaryExpr
  805. {
  806. ExprSequence expr;
  807. public ParenthesizedExpr (ExprSequence expr)
  808. {
  809. this.expr = expr;
  810. }
  811. }
  812. // "."
  813. public class ContextItemExpr : PrimaryExpr
  814. {
  815. public ContextItemExpr ()
  816. {
  817. }
  818. }
  819. public class FunctionCallExpr : PrimaryExpr
  820. {
  821. XmlQualifiedName name;
  822. ExprSequence args;
  823. public FunctionCallExpr (XmlQualifiedName name, ExprSequence args)
  824. {
  825. }
  826. }
  827. public class SequenceType
  828. {
  829. NodeKindTestExpr kindTest;
  830. Occurence occurence;
  831. public SequenceType (NodeKindTestExpr test, Occurence occurence)
  832. {
  833. this.kindTest = test;
  834. this.occurence = occurence;
  835. }
  836. }
  837. public enum Occurence
  838. {
  839. One,
  840. Optional,
  841. ZeroOrMore,
  842. OneOrMore,
  843. }
  844. }
  845. #endif