Ver código fonte

2004-03-22 Atsushi Enomoto <[email protected]>

	* Makefile : now it creates XSLT pattern parser files from
	  Parser.jay and Tokenizer.cs in System.Xml.XPath.

	* Parser.jay, Tokenizer.cs : Now they are used as common code base for
	  XPath parser and XSLT pattern parser. Makefile now creates two
	  set of sources of them. (This change takes effect on the next change).


svn path=/trunk/mcs/; revision=42062
Atsushi Eno 21 anos atrás
pai
commit
ad73d6ca40

+ 5 - 0
mcs/class/System.XML/ChangeLog

@@ -1,3 +1,8 @@
+2004-03-22  Atsushi Enomoto  <[email protected]>
+
+	* Makefile : now it creates XSLT pattern parser files from
+	  Parser.jay and Tokenizer.cs in System.Xml.XPath.
+
 2004-03-04  Atsushi Enomoto  <[email protected]>
 2004-03-04  Atsushi Enomoto  <[email protected]>
 
 
 	* System.Xml.dll.sources : Added XslNotSupportedOperation.cs.
 	* System.Xml.dll.sources : Added XslNotSupportedOperation.cs.

+ 18 - 5
mcs/class/System.XML/Makefile

@@ -40,7 +40,6 @@ EXTRA_DISTFILES = \
 	$(wildcard System.Xml.Serialization/standalone_tests/*.cs) \
 	$(wildcard System.Xml.Serialization/standalone_tests/*.cs) \
 	$(wildcard System.Xml.Serialization/standalone_tests/*.output) \
 	$(wildcard System.Xml.Serialization/standalone_tests/*.output) \
 	System.Xml.XPath/Parser.jay	\
 	System.Xml.XPath/Parser.jay	\
-	System.Xml.Query/XQueryParser.jay	\
 	System.Xml.Query/skeleton-2.0.cs	\
 	System.Xml.Query/skeleton-2.0.cs	\
 	Test/Microsoft.Test.csproj	\
 	Test/Microsoft.Test.csproj	\
 	Test/Mono.Test.csproj		\
 	Test/Mono.Test.csproj		\
@@ -54,10 +53,24 @@ EXTRA_DISTFILES = \
 System.Xml.XPath/Parser.cs: System.Xml.XPath/Parser.jay $(topdir)/jay/skeleton.cs
 System.Xml.XPath/Parser.cs: System.Xml.XPath/Parser.jay $(topdir)/jay/skeleton.cs
 	$(topdir)/jay/jay -ct < $(topdir)/jay/skeleton.cs $< >$@
 	$(topdir)/jay/jay -ct < $(topdir)/jay/skeleton.cs $< >$@
 
 
-System.Xml.Query/XQueryParser.cs: System.Xml.Query/XQueryParser.jay System.Xml.Query/skeleton-2.0.cs
-	$(topdir)/jay/jay -ct < System.Xml.Query/skeleton-2.0.cs $< >$@
+Mono.Xml.Xsl/PatternParser.jay: System.Xml.XPath/Parser.jay $(topdir)/jay/skeleton.cs
+	sed "s/\%start Expr/\%start Pattern/" $< >$@
 
 
-BUILT_SOURCES = System.Xml.XPath/Parser.cs #System.Xml.Query/XQueryParser.cs
-CLEAN_FILES = Test/XmlFiles/xsl/result.xml System.Xml.Query/XQueryParser.cs
+Mono.Xml.Xsl/PatternParser.cs: Mono.Xml.Xsl/PatternParser.jay $(topdir)/jay/skeleton.cs
+	echo "#define XSLT_PATTERN" > $@
+	$(topdir)/jay/jay -ct $< < $(topdir)/jay/skeleton.cs >>$@
+
+Mono.Xml.Xsl/PatternTokenizer.cs: System.Xml.XPath/Tokenizer.cs
+	echo "#define XSLT_PATTERN" > $@
+	cat $< >>$@
+
+BUILT_SOURCES = System.Xml.XPath/Parser.cs \
+	Mono.Xml.Xsl/PatternParser.cs \
+	Mono.Xml.Xsl/PatternTokenizer.cs
+
+CLEAN_FILES = Test/XmlFiles/xsl/result.xml \
+	System.Xml.XPath/Parser.cs \
+	Mono.Xml.Xsl/PatternParser.cs \
+	Mono.Xml.Xsl/PatternTokenizer.cs
 
 
 include ../../build/library.make
 include ../../build/library.make

+ 6 - 0
mcs/class/System.XML/System.Xml.XPath/ChangeLog

@@ -1,3 +1,9 @@
+2004-03-22  Atsushi Enomoto  <[email protected]>
+
+	* Parser.jay, Tokenizer.cs : Now they are used as common code base for
+	  XPath parser and XSLT pattern parser. Makefile now creates two
+	  set of sources of them. (This change takes effect on the next change).
+
 2004-03-16  Atsushi Enomoto  <[email protected]>
 2004-03-16  Atsushi Enomoto  <[email protected]>
 
 
 	* Parser.jay : rewrote step part to be reusable for upcoming XSLT
 	* Parser.jay : rewrote step part to be reusable for upcoming XSLT

+ 130 - 3
mcs/class/System.XML/System.Xml.XPath/Parser.jay

@@ -1,7 +1,12 @@
 %{
 %{
-// XPath parser
+// XPath/XSLT Pattern parser
 //
 //
-// Author - Piers Haken <[email protected]>
+// Author: Piers Haken <[email protected]>
+//         Atsushi Enomoto  <[email protected]>
+//
+// IMPORTANT:
+// Do not edit "PatternParser.jay". It is autogenerated from
+// Parser.jay. It will be overwritten!
 //
 //
 
 
 using System;
 using System;
@@ -9,15 +14,28 @@ using System.Collections;
 using System.Xml;
 using System.Xml;
 using System.Xml.XPath;
 using System.Xml.XPath;
 
 
+#if XSLT_PATTERN
+namespace Mono.Xml.Xsl
+#else
 namespace Mono.Xml.XPath
 namespace Mono.Xml.XPath
+#endif
 {
 {
+#if XSLT_PATTERN
+	internal class XsltPatternParser
+#else
 	internal class XPathParser
 	internal class XPathParser
+#endif
 	{
 	{
 	
 	
 		internal System.Xml.Xsl.IStaticXsltContext Context;
 		internal System.Xml.Xsl.IStaticXsltContext Context;
 		
 		
+#if XSLT_PATTERN
+		public XsltPatternParser () : this (null) {}
+		internal XsltPatternParser (System.Xml.Xsl.IStaticXsltContext context)
+#else
 		public XPathParser () : this (null) {}
 		public XPathParser () : this (null) {}
 		internal XPathParser (System.Xml.Xsl.IStaticXsltContext context)
 		internal XPathParser (System.Xml.Xsl.IStaticXsltContext context)
+#endif
 		{
 		{
 			Context = context;
 			Context = context;
 			ErrorOutput = System.IO.TextWriter.Null;
 			ErrorOutput = System.IO.TextWriter.Null;
@@ -29,7 +47,7 @@ namespace Mono.Xml.XPath
 			try {
 			try {
 				Tokenizer tokenizer = new Tokenizer (xpath);
 				Tokenizer tokenizer = new Tokenizer (xpath);
 				return (Expression) yyparse (tokenizer);
 				return (Expression) yyparse (tokenizer);
-			} catch (XPathException e) {
+			} catch (XPathException) {
 				throw;
 				throw;
 			} catch (Exception e) {
 			} catch (Exception e) {
 				throw new XPathException ("Error during parse of " + xpath, e);
 				throw new XPathException ("Error during parse of " + xpath, e);
@@ -144,6 +162,115 @@ namespace Mono.Xml.XPath
 
 
 %%
 %%
 
 
+/* XSLT Pattern */
+
+Pattern
+	: LocationPathPattern
+	| Pattern BAR LocationPathPattern
+	{
+		$$ = new ExprUNION ((NodeSet) $1, (NodeSet) $3);
+	}
+	;
+
+LocationPathPattern
+	: SLASH
+	{
+		$$ = new ExprRoot ();
+	}
+	| SLASH RelativePathPattern
+	{
+		$$ = new ExprSLASH (new ExprRoot (), (NodeSet) $2);
+	}
+	| IdKeyPattern
+	| IdKeyPattern SLASH RelativePathPattern
+	{
+		$$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
+	}
+	| IdKeyPattern SLASH2 RelativePathPattern
+	{
+		$$ = new ExprSLASH2 ((Expression) $1, (NodeSet) $3);
+	}
+	| SLASH2 RelativePathPattern
+	{
+		$$ = new ExprSLASH2 (new ExprRoot (), (NodeSet) $2);
+	}
+	| RelativePathPattern
+	;
+
+// to avoid context-sensitive tokenizer, I just reuse FUNCTION_NAME
+IdKeyPattern
+	: FUNCTION_NAME PAREN_OPEN LITERAL PAREN_CLOSE
+	{
+		XmlQualifiedName name = (XmlQualifiedName) $1;
+		if (name.Name != "id" || name.Namespace != String.Empty)
+			throw new XPathException (String.Format ("Expected 'id' but got '{0}'", name));
+		$$ = ExprFunctionCall.Factory (name,
+			new FunctionArguments (
+				new ExprLiteral ((string) $3),
+				null),
+			Context);
+	}
+	| FUNCTION_NAME PAREN_OPEN LITERAL COMMA LITERAL PAREN_CLOSE
+	{
+		XmlQualifiedName name = (XmlQualifiedName) $1;
+		if (name.Name != "key" || name.Namespace != String.Empty)
+			throw new XPathException (String.Format ("Expected 'key' but got '{0}'", name));
+		$$ = Context.TryGetFunction (name,
+			new FunctionArguments (
+				new ExprLiteral ((string) $3),
+				new FunctionArguments (
+					new ExprLiteral ((string) $5),
+					null)));
+	}
+	;
+
+RelativePathPattern
+	: StepPattern
+	| RelativePathPattern SLASH StepPattern
+	{
+		$$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
+	}
+	| RelativePathPattern SLASH2 StepPattern
+	{
+		$$ = new ExprSLASH2 ((Expression) $1, (NodeSet) $3);
+	}
+	;
+
+StepPattern
+	: ChildOrAttributeAxisSpecifier NodeTest Predicates
+	{
+		$$ = CreateNodeTest ((Axes) $1, $2, (ArrayList) $3);
+	}
+	;
+
+ChildOrAttributeAxisSpecifier
+	: AbbreviatedAxisSpecifier
+	| CHILD COLON2
+	{
+		$$ = Axes.Child;
+	}
+	| ATTRIBUTE COLON2
+	{
+		$$ = Axes.Attribute;
+	}
+	;
+
+Predicates
+	: // empty
+	{
+		$$ = null;
+	}
+	| Predicates Predicate
+	{
+		ArrayList al = (ArrayList) $1;
+		if (al == null)
+			al = new ArrayList ();
+		al.Add ((Expression) $2);
+		$$ = al;
+	}
+	;
+
+/* ---- end of XSLT Pattern ---- */
 
 
 
 
 Expr
 Expr

+ 15 - 4
mcs/class/System.XML/System.Xml.XPath/Tokenizer.cs

@@ -1,10 +1,16 @@
 //
 //
-// System.Xml.XPath.Tokenizer
+// System.Xml.XPath.Tokenizer.cs / Mono.Xml.Xsl/PatternTokenizer.cs
 //
 //
 // Author:
 // Author:
 //   Piers Haken ([email protected])
 //   Piers Haken ([email protected])
+//   Atsushi Enomoto ([email protected])
 //
 //
 // (C) 2002 Piers Haken
 // (C) 2002 Piers Haken
+// (C) 2005 Novell Inc,
+//
+// IMPORTANT:
+//
+// Do not edit PatternTokenizer.cs. It is autogenerated.
 //
 //
 
 
 //
 //
@@ -32,12 +38,17 @@ using System.Globalization;
 using System.IO;
 using System.IO;
 using System.Text;
 using System.Text;
 using System.Collections;
 using System.Collections;
+using System.Xml;
+using System.Xml.XPath;
 using Mono.Xml.XPath;
 using Mono.Xml.XPath;
-using Mono.Xml.XPath.yyParser;
 
 
-namespace System.Xml.XPath
+#if XSLT_PATTERN
+namespace Mono.Xml.Xsl
+#else
+namespace Mono.Xml.XPath
+#endif
 {
 {
-	internal class Tokenizer : Mono.Xml.XPath.yyParser.yyInput
+	internal class Tokenizer : yyParser.yyInput
 	{
 	{
 		private string m_rgchInput;
 		private string m_rgchInput;
 		private int m_ich;
 		private int m_ich;