XPointer lexical analyzer.
Example #1
0
 private static XPointerSchema.SchemaType GetSchema(XPointerLexer lexer, ArrayList parts) 
 {	        
     string schemaNSURI;
     if (lexer.Prefix != String.Empty) 
     {
         schemaNSURI = null;
         //resolve prefix
         for (int i=parts.Count-1; i>=0; i--) 
         {
             PointerPart part = (PointerPart)parts[i];
             if (part is XmlnsSchemaPointerPart) 
             {
                 XmlnsSchemaPointerPart xmlnsPart = (XmlnsSchemaPointerPart)part;
                 if (xmlnsPart.Prefix == lexer.Prefix) 
                 {
                     schemaNSURI = xmlnsPart.Uri;	                    	                            
                     break;
                 }
             }
         }
         if (schemaNSURI == null) 
             //No binding for the prefix - ignore pointer part
             return XPointerSchema.SchemaType.Unknown;
     } 
     else
         schemaNSURI = String.Empty;    
     object o = _schemas[schemaNSURI + ':' + lexer.NCName];
     if (o == null)
         return XPointerSchema.SchemaType.Unknown;                
     else
         return (XPointerSchema.SchemaType)o;
 }		    	                        
Example #2
0
        private static XPointerSchema.SchemaType GetSchema(XPointerLexer lexer, IList <PointerPart> parts)
        {
            string schemaNsuri;

            if (lexer.Prefix != string.Empty)
            {
                schemaNsuri = null;
                //resolve prefix
                for (int i = parts.Count - 1; i >= 0; i--)
                {
                    PointerPart part = parts[i];
                    if (part is XmlnsSchemaPointerPart xmlnsPart &&
                        xmlnsPart.Prefix == lexer.Prefix)
                    {
                        schemaNsuri = xmlnsPart.Uri;
                        break;
                    }
                }
                if (schemaNsuri == null)
                //No binding for the prefix - ignore pointer part
                {
                    return(XPointerSchema.SchemaType.Unknown);
                }
            }
            else
            {
                schemaNsuri = string.Empty;
            }

            string schemaQName = schemaNsuri + ':' + lexer.NcName;

            return(schemas.ContainsKey(schemaQName) ? schemas[schemaQName] : XPointerSchema.SchemaType.Unknown);
        }
Example #3
0
 private static XPointerSchema.SchemaType GetSchema(XPointerLexer lexer, IList<PointerPart> parts)
 {
   string schemaNSURI;
   if (lexer.Prefix != String.Empty)
   {
     schemaNSURI = null;
     //resolve prefix
     for (int i = parts.Count - 1; i >= 0; i--)
     {
       PointerPart part = parts[i];
       if (part is XmlnsSchemaPointerPart)
       {
         XmlnsSchemaPointerPart xmlnsPart = (XmlnsSchemaPointerPart)part;
         if (xmlnsPart.Prefix == lexer.Prefix)
         {
           schemaNSURI = xmlnsPart.Uri;
           break;
         }
       }
     }
     if (schemaNSURI == null)
       //No binding for the prefix - ignore pointer part
       return XPointerSchema.SchemaType.Unknown;
   }
   else
     schemaNSURI = String.Empty;
   string schemaQName = schemaNSURI + ':' + lexer.NCName;
   return _schemas.ContainsKey(schemaQName)? _schemas[schemaQName] : XPointerSchema.SchemaType.Unknown;      
 }
 public static XmlnsSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
   //[1]   	XmlnsSchemeData	   ::=   	 NCName S? '=' S? EscapedNamespaceName
   //[2]   	EscapedNamespaceName	   ::=   	EscapedData*                      	                    
   //Read prefix as NCName
   lexer.NextLexeme();
   if (lexer.Kind != XPointerLexer.LexKind.NCName)
   {
     Debug.WriteLine(SR.InvalidTokenInXmlnsSchemeWhileNCNameExpected);
     return null;
   }
   string prefix = lexer.NCName;
   lexer.SkipWhiteSpace();
   lexer.NextLexeme();
   if (lexer.Kind != XPointerLexer.LexKind.Eq)
   {
     Debug.WriteLine(SR.InvalidTokenInXmlnsSchemeWhileEqualsSignExpected);
     return null;
   }
   lexer.SkipWhiteSpace();
   string nsURI;
   try
   {
     nsURI = lexer.ParseEscapedData();
   }
   catch (Exception e)
   {
     throw new XPointerSyntaxException(SR.GetString("SyntaxErrorInXmlnsSchemeData", e.Message));
   }
   return new XmlnsSchemaPointerPart(prefix, nsURI);
 }
 public static XmlnsSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
     //[1]   	XmlnsSchemeData	   ::=   	 NCName S? '=' S? EscapedNamespaceName
     //[2]   	EscapedNamespaceName	   ::=   	EscapedData*
     //Read prefix as NCName
     lexer.NextLexeme();
     if (lexer.Kind != XPointerLexer.LexKind.NCName)
     {
         Debug.WriteLine(Monobjc.Tools.Sdp.Properties.Resources.InvalidTokenInXmlnsSchemeWhileNCNameExpected);
         return null;
     }
     string prefix = lexer.NCName;
     lexer.SkipWhiteSpace();
     lexer.NextLexeme();
     if (lexer.Kind != XPointerLexer.LexKind.Eq)
     {
         Debug.WriteLine(Monobjc.Tools.Sdp.Properties.Resources.InvalidTokenInXmlnsSchemeWhileEqualsSignExpected);
         return null;
     }
     lexer.SkipWhiteSpace();
     string nsURI;
     try
     {
         nsURI = lexer.ParseEscapedData();
     }
     catch (Exception e)
     {
         throw new XPointerSyntaxException(String.Format(CultureInfo.CurrentCulture, Monobjc.Tools.Sdp.Properties.Resources.SyntaxErrorInXmlnsSchemeData, e.Message));
     }
     return new XmlnsSchemaPointerPart(prefix, nsURI);
 }
        public static XmlnsSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
        {
            //[1]       XmlnsSchemeData	   ::=       NCName S? '=' S? EscapedNamespaceName
            //[2]       EscapedNamespaceName	   ::=      EscapedData*
            //Read prefix as NCName
            lexer.NextLexeme();
            if (lexer.Kind != XPointerLexer.LexKind.NCName)
            {
                Debug.WriteLine(Properties.Resources.InvalidTokenInXmlnsSchemeWhileNCNameExpected);
                return(null);
            }
            string prefix = lexer.NCName;

            lexer.SkipWhiteSpace();
            lexer.NextLexeme();
            if (lexer.Kind != XPointerLexer.LexKind.Eq)
            {
                Debug.WriteLine(Properties.Resources.InvalidTokenInXmlnsSchemeWhileEqualsSignExpected);
                return(null);
            }
            lexer.SkipWhiteSpace();
            string nsURI;

            try
            {
                nsURI = lexer.ParseEscapedData();
            }
            catch (Exception e)
            {
                throw new XPointerSyntaxException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.SyntaxErrorInXmlnsSchemeData, e.Message));
            }
            return(new XmlnsSchemaPointerPart(prefix, nsURI));
        }
Example #7
0
 public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
     try
     {
         return(new XPointerSchemaPointerPart(lexer.ParseEscapedData()));
     }
     catch (Exception e)
     {
         throw new XPointerSyntaxException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.SyntaxErrorInXPointerSchemeData, e.Message));
     }
 }
		public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
		{
			try
			{
				return new XPointerSchemaPointerPart(lexer.ParseEscapedData());
			}
			catch (Exception e)
			{
				throw new XPointerSyntaxException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.SyntaxErrorInXPointerSchemeData, e.Message));
			}
		}
 public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
     try
     {
         return(new XPointerSchemaPointerPart(lexer.ParseEscapedData()));
     }
     catch (Exception e)
     {
         throw new XPointerSyntaxException(SR.GetString("SyntaxErrorInXPointerSchemeData", e.Message));
     }
 }
 public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
   try
   {
     return new XPointerSchemaPointerPart(lexer.ParseEscapedData());
   }
   catch (Exception e)
   {
     throw new XPointerSyntaxException(SR.GetString("SyntaxErrorInXPointerSchemeData", e.Message));
   }
 }
 public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer) 
 {                                    
     XPointerSchemaPointerPart part = new XPointerSchemaPointerPart();
     try 
     {
         part.XPath = lexer.ParseEscapedData();
     } 
     catch (Exception e) 
     {
         throw new XPointerSyntaxException(SR.GetString("SyntaxErrorInXPointerSchemeData", e.Message));                
     }                                   
     return part;
 }		
        public static XPointerSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
        {
            XPointerSchemaPointerPart part = new XPointerSchemaPointerPart();

            try
            {
                part.XPath = lexer.ParseEscapedData();
            }
            catch (Exception e)
            {
                throw new XPointerSyntaxException(SR.GetString("SyntaxErrorInXPointerSchemeData", e.Message));
            }
            return(part);
        }
        /// <summary>
        /// Parses element() based pointer part and builds instance of <c>ElementSchemaPointerPart</c> class.
        /// </summary>
        /// <param name="lexer">Lexical analizer.</param>
        /// <returns>Newly created <c>ElementSchemaPointerPart</c> object.</returns>
        public static ElementSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
        {
            //Productions:
            //[1]       ElementSchemeData	   ::=      (NCName ChildSequence?) | ChildSequence
            //[2]       ChildSequence	   ::=      ('/' [1-9] [0-9]*)+
            StringBuilder            xpathBuilder = new StringBuilder();
            ElementSchemaPointerPart part         = new ElementSchemaPointerPart();

            lexer.NextLexeme();
            if (lexer.Kind == XPointerLexer.LexKind.NCName)
            {
                xpathBuilder.Append("id('");
                xpathBuilder.Append(lexer.NCName);
                xpathBuilder.Append("')");
                lexer.NextLexeme();
            }
            int childSequenceLen = 0;

            while (lexer.Kind == XPointerLexer.LexKind.Slash)
            {
                lexer.NextLexeme();
                if (lexer.Kind != XPointerLexer.LexKind.Number)
                {
                    Debug.WriteLine(Monobjc.Tools.Sdp.Properties.Resources.InvalidTokenInElementSchemeWhileNumberExpected);
                    return(null);
                }
                if (lexer.Number == 0)
                {
                    Debug.WriteLine(Monobjc.Tools.Sdp.Properties.Resources.ZeroIndexInElementSchemechildSequence);
                    return(null);
                }
                childSequenceLen++;
                xpathBuilder.Append("/*[");
                xpathBuilder.Append(lexer.Number);
                xpathBuilder.Append("]");
                lexer.NextLexeme();
            }
            if (lexer.Kind != XPointerLexer.LexKind.RRBracket)
            {
                throw new XPointerSyntaxException(Monobjc.Tools.Sdp.Properties.Resources.InvalidTokenInElementSchemeWhileClosingRoundBracketExpected);
            }
            if (xpathBuilder.Length == 0 && childSequenceLen == 0)
            {
                Debug.WriteLine(Monobjc.Tools.Sdp.Properties.Resources.EmptyElementSchemeXPointer);
                return(null);
            }
            part.XPath = xpathBuilder.ToString();
            return(part);
        }
        /// <summary>
        /// Parses element() based pointer part and builds instance of <c>ElementSchemaPointerPart</c> class.
        /// </summary>
        /// <param name="lexer">Lexical analizer.</param>
        /// <returns>Newly created <c>ElementSchemaPointerPart</c> object.</returns>
        public static ElementSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
        {
            //Productions:
            //[1]       ElementSchemeData	   ::=      (NCName ChildSequence?) | ChildSequence
            //[2]       ChildSequence	   ::=      ('/' [1-9] [0-9]*)+
            StringBuilder            xpathBuilder = new StringBuilder();
            ElementSchemaPointerPart part         = new ElementSchemaPointerPart();

            lexer.NextLexeme();
            if (lexer.Kind == XPointerLexer.LexKind.NCName)
            {
                part.NCName = lexer.NCName;
                xpathBuilder.Append("id('");
                xpathBuilder.Append(lexer.NCName);
                xpathBuilder.Append("')");
                lexer.NextLexeme();
            }
            part.ChildSequence = new ArrayList();
            while (lexer.Kind == XPointerLexer.LexKind.Slash)
            {
                lexer.NextLexeme();
                if (lexer.Kind != XPointerLexer.LexKind.Number)
                {
                    Debug.WriteLine(SR.InvalidTokenInElementSchemeWhileNumberExpected);
                    return(null);
                }
                if (lexer.Number == 0)
                {
                    Debug.WriteLine(SR.ZeroIndexInElementSchemechildSequence);
                    return(null);
                }
                part.ChildSequence.Add(lexer.Number);
                xpathBuilder.Append("/*[");
                xpathBuilder.Append(lexer.Number);
                xpathBuilder.Append("]");
                lexer.NextLexeme();
            }
            if (lexer.Kind != XPointerLexer.LexKind.RRBracket)
            {
                throw new XPointerSyntaxException(SR.InvalidTokenInElementSchemeWhileClosingRoundBracketExpected);
            }
            if (part.NCName == null && part.ChildSequence.Count == 0)
            {
                Debug.WriteLine(SR.EmptyElementSchemeXPointer);
                return(null);
            }
            part.XPath = xpathBuilder.ToString();
            return(part);
        }
 public static XPath1SchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
     XPath1SchemaPointerPart part = new XPath1SchemaPointerPart();
     try
     {
         part._xpath = lexer.ParseEscapedData();
     }
     catch (Exception e)
     {
         throw new XPointerSyntaxException(String.Format(
             CultureInfo.CurrentCulture,
             Monobjc.Tools.Sdp.Properties.Resources.SyntaxErrorInXPath1SchemeData,
             e.Message));
     }
     return part;
 }
 /// <summary>
 /// Parses element() based pointer part and builds instance of <c>ElementSchemaPointerPart</c> class.
 /// </summary>
 /// <param name="lexer">Lexical analizer.</param>
 /// <returns>Newly created <c>ElementSchemaPointerPart</c> object.</returns>
 public static ElementSchemaPointerPart ParseSchemaData(XPointerLexer lexer)
 {
   //Productions:
   //[1]   	ElementSchemeData	   ::=   	(NCName ChildSequence?) | ChildSequence
   //[2]   	ChildSequence	   ::=   	('/' [1-9] [0-9]*)+                        
   StringBuilder xpathBuilder = new StringBuilder();
   ElementSchemaPointerPart part = new ElementSchemaPointerPart();
   lexer.NextLexeme();
   if (lexer.Kind == XPointerLexer.LexKind.NCName)
   {
     xpathBuilder.Append("id('");
     xpathBuilder.Append(lexer.NCName);
     xpathBuilder.Append("')");
     lexer.NextLexeme();
   }
   int childSequenceLen = 0;
   while (lexer.Kind == XPointerLexer.LexKind.Slash)
   {
     lexer.NextLexeme();
     if (lexer.Kind != XPointerLexer.LexKind.Number)
     {
       Debug.WriteLine(SR.InvalidTokenInElementSchemeWhileNumberExpected);
       return null;
     }
     if (lexer.Number == 0)
     {
       Debug.WriteLine(SR.ZeroIndexInElementSchemechildSequence);
       return null;
     }
     childSequenceLen++;
     xpathBuilder.Append("/*[");
     xpathBuilder.Append(lexer.Number);
     xpathBuilder.Append("]");
     lexer.NextLexeme();
   }
   if (lexer.Kind != XPointerLexer.LexKind.RRBracket)
   {
     throw new XPointerSyntaxException(SR.InvalidTokenInElementSchemeWhileClosingRoundBracketExpected);
   }
   if (xpathBuilder.Length == 0 && childSequenceLen == 0)
   {
     Debug.WriteLine(SR.EmptyElementSchemeXPointer);
     return null;
   }
   part.XPath = xpathBuilder.ToString();
   return part;
 }
Example #17
0
        public static XPath1SchemaPointerPart ParseSchemaData(XPointerLexer lexer)
        {
            XPath1SchemaPointerPart part = new XPath1SchemaPointerPart();

            try
            {
                part.xpath = lexer.ParseEscapedData();
            }
            catch (Exception e)
            {
                throw new XPointerSyntaxException(string.Format(
                                                      CultureInfo.CurrentCulture,
                                                      Properties.Resources.SyntaxErrorInXPath1SchemeData,
                                                      e.Message));
            }
            return(part);
        }
Example #18
0
        private static XPointerSchema.SchemaType GetSchema(XPointerLexer lexer, ArrayList parts)
        {
            string schemaNSURI;

            if (lexer.Prefix != String.Empty)
            {
                schemaNSURI = null;
                //resolve prefix
                for (int i = parts.Count - 1; i >= 0; i--)
                {
                    PointerPart part = (PointerPart)parts[i];
                    if (part is XmlnsSchemaPointerPart)
                    {
                        XmlnsSchemaPointerPart xmlnsPart = (XmlnsSchemaPointerPart)part;
                        if (xmlnsPart.Prefix == lexer.Prefix)
                        {
                            schemaNSURI = xmlnsPart.Uri;
                            break;
                        }
                    }
                }
                if (schemaNSURI == null)
                {
                    //No binding for the prefix - ignore pointer part
                    return(XPointerSchema.SchemaType.Unknown);
                }
            }
            else
            {
                schemaNSURI = String.Empty;
            }
            object o = _schemas[schemaNSURI + ':' + lexer.NCName];

            if (o == null)
            {
                return(XPointerSchema.SchemaType.Unknown);
            }
            else
            {
                return((XPointerSchema.SchemaType)o);
            }
        }
Example #19
0
        public static Pointer ParseXPointer(string xpointer)
        {
            var lexer = new XPointerLexer(xpointer);

            lexer.NextLexeme();
            if (lexer.Kind == XPointerLexer.LexKind.NcName && !lexer.CanBeSchemaName)
            {
                //Shorthand pointer
                Pointer ptr = new ShorthandPointer(lexer.NcName);
                lexer.NextLexeme();
                if (lexer.Kind != XPointerLexer.LexKind.Eof)
                {
                    throw new XPointerSyntaxException(Properties.Resources.InvalidTokenAfterShorthandPointer);
                }

                return(ptr);
            }

            //SchemaBased pointer
            IList <PointerPart> parts = new List <PointerPart>();

            while (lexer.Kind != XPointerLexer.LexKind.Eof)
            {
                if ((lexer.Kind == XPointerLexer.LexKind.NcName ||
                     lexer.Kind == XPointerLexer.LexKind.QName) &&
                    lexer.CanBeSchemaName)
                {
                    XPointerSchema.SchemaType schemaType = GetSchema(lexer, parts);
                    //Move to '('
                    lexer.NextLexeme();
                    switch (schemaType)
                    {
                    case XPointerSchema.SchemaType.Element:
                        ElementSchemaPointerPart elemPart = ElementSchemaPointerPart.ParseSchemaData(lexer);
                        if (elemPart != null)
                        {
                            parts.Add(elemPart);
                        }

                        break;

                    case XPointerSchema.SchemaType.Xmlns:
                        XmlnsSchemaPointerPart xmlnsPart = XmlnsSchemaPointerPart.ParseSchemaData(lexer);
                        if (xmlnsPart != null)
                        {
                            parts.Add(xmlnsPart);
                        }

                        break;

                    case XPointerSchema.SchemaType.XPath1:
                        XPath1SchemaPointerPart xpath1Part = XPath1SchemaPointerPart.ParseSchemaData(lexer);
                        if (xpath1Part != null)
                        {
                            parts.Add(xpath1Part);
                        }

                        break;

                    case XPointerSchema.SchemaType.XPointer:
                        XPointerSchemaPointerPart xpointerPart = XPointerSchemaPointerPart.ParseSchemaData(lexer);
                        if (xpointerPart != null)
                        {
                            parts.Add(xpointerPart);
                        }

                        break;

                    default:
                        //Unknown scheme
                        lexer.ParseEscapedData();
                        break;
                    }
                    //Skip ')'
                    lexer.NextLexeme();
                    //Skip possible whitespace
                    if (lexer.Kind == XPointerLexer.LexKind.Space)
                    {
                        lexer.NextLexeme();
                    }
                }
                else
                {
                    throw new XPointerSyntaxException(Properties.Resources.InvalidToken);
                }
            }
            return(new SchemaBasedPointer(parts, xpointer));
        }
Example #20
0
 public static Pointer ParseXPointer(string xpointer)
 {
   IList<PointerPart> parts;
   XPointerLexer lexer;
   lexer = new XPointerLexer(xpointer);
   lexer.NextLexeme();
   if (lexer.Kind == XPointerLexer.LexKind.NCName && !lexer.CanBeSchemaName)
   {
     //Shorthand pointer
     Pointer ptr = new ShorthandPointer(lexer.NCName);
     lexer.NextLexeme();
     if (lexer.Kind != XPointerLexer.LexKind.Eof)
       throw new XPointerSyntaxException(SR.InvalidTokenAfterShorthandPointer);
     return ptr;
   }
   else
   {
     //SchemaBased pointer
     parts = new List<PointerPart>();
     while (lexer.Kind != XPointerLexer.LexKind.Eof)
     {
       if ((lexer.Kind == XPointerLexer.LexKind.NCName ||
           lexer.Kind == XPointerLexer.LexKind.QName) &&
           lexer.CanBeSchemaName)
       {
         XPointerSchema.SchemaType schemaType = GetSchema(lexer, parts);
         //Move to '('
         lexer.NextLexeme();
         switch (schemaType)
         {
           case XPointerSchema.SchemaType.Element:
             ElementSchemaPointerPart elemPart = ElementSchemaPointerPart.ParseSchemaData(lexer);
             if (elemPart != null)
               parts.Add(elemPart);
             break;
           case XPointerSchema.SchemaType.Xmlns:
             XmlnsSchemaPointerPart xmlnsPart = XmlnsSchemaPointerPart.ParseSchemaData(lexer);
             if (xmlnsPart != null)
               parts.Add(xmlnsPart);
             break;
           case XPointerSchema.SchemaType.XPath1:
             XPath1SchemaPointerPart xpath1Part = XPath1SchemaPointerPart.ParseSchemaData(lexer);
             if (xpath1Part != null)
               parts.Add(xpath1Part);
             break;
           case XPointerSchema.SchemaType.XPointer:
             XPointerSchemaPointerPart xpointerPart = XPointerSchemaPointerPart.ParseSchemaData(lexer);
             if (xpointerPart != null)
               parts.Add(xpointerPart);
             break;
           default:
             //Unknown scheme
             lexer.ParseEscapedData();
             break;
         }
         //Skip ')'
         lexer.NextLexeme();
         //Skip possible whitespace
         if (lexer.Kind == XPointerLexer.LexKind.Space)
           lexer.NextLexeme();
       }
       else
         throw new XPointerSyntaxException(SR.InvalidToken);
     }
     return new SchemaBasedPointer(parts, xpointer);
   }
 }