internal static StringLiteralToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); // read the first character sourceChars.Add(stream.ReadChar('"')); // read the remaining characters var parser = new StringParser(); while (!stream.Eof) { var peek = stream.Peek(); sourceChars.Add(peek); if ((peek == '"') && !parser.IsEscaped) { parser.ConsumeEof(); break; } else { parser.ConsumeChar(stream.Read()); } } // read the last character sourceChars.Add(stream.ReadChar('"')); // process any escape sequences in the string var unescaped = parser.OutputString.ToString(); // return the result extent = extent.WithText(sourceChars); return new StringLiteralToken(extent, unescaped); }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <remarks> /// /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf /// /// A.17.3 String values /// /// Unless explicitly specified via ABNF rule WS, no whitespace is allowed between the elements of the rules /// in this ABNF section. /// /// stringValue = DOUBLEQUOTE *stringChar DOUBLEQUOTE /// *( *WS DOUBLEQUOTE *stringChar DOUBLEQUOTE ) /// stringChar = stringUCSchar / stringEscapeSequence /// /// </remarks> private static StringLiteralToken ReadStringLiteralToken(ILexerStream stream) { // BUGBUG - no support for *( *WS DOUBLEQUOTE *stringChar DOUBLEQUOTE ) // BUGBUG - incomplete escape sequences // BUGBUG - no support for UCS characters var sourceChars = new List <SourceChar>(); // read the first character sourceChars.Add(stream.ReadChar('"')); // read the remaining characters var parser = new StringLiteralParser(); while (!stream.Eof) { var peek = stream.Peek(); if (StringValidator.IsDoubleQuote(peek.Value) && !parser.IsEscaped) { parser.ConsumeEos(); break; } else { sourceChars.Add(peek); parser.ConsumeChar(stream.Read()); } } // read the last character sourceChars.Add(stream.ReadChar('"')); // process any escape sequences in the string var unescaped = parser.OutputString.ToString(); // return the result var extent = new SourceExtent(sourceChars); return(new StringLiteralToken(extent, unescaped)); }
internal static AliasIdentifierToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); // read the first character sourceChars.Add(stream.ReadChar('$')); // read the name var nameChars = new List<char>(); while (!stream.Eof) { extent = extent.WithEndExtent(stream); var peek = stream.Peek(); if (char.IsLetterOrDigit(peek) || ("_".IndexOf(peek) != -1) ) { var @char = stream.Read(); sourceChars.Add(@char); nameChars.Add(@char); } else { break; } } // return the result extent = extent.WithText(sourceChars); var name = new string(nameChars.ToArray()); return new AliasIdentifierToken(extent, name); }
internal static PragmaToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); sourceChars.Add(stream.ReadChar('#')); sourceChars.AddRange(stream.ReadString("pragma")); extent = extent.WithText(sourceChars); return new PragmaToken(extent); }
private static StatementEndToken ReadStatementEndToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar(';')); var extent = new SourceExtent(sourceChars); return(new StatementEndToken(extent)); }
private static ParenthesesOpenToken ReadParenthesesOpenToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar('(')); var extent = new SourceExtent(sourceChars); return(new ParenthesesOpenToken(extent)); }
private static EqualsOperatorToken ReadEqualsOperatorToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar('=')); var extent = new SourceExtent(sourceChars); return(new EqualsOperatorToken(extent)); }
private static CommaToken ReadCommaToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar(',')); var extent = new SourceExtent(sourceChars); return(new CommaToken(extent)); }
private static BlockOpenToken ReadBlockOpenToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar('{')); var extent = new SourceExtent(sourceChars); return(new BlockOpenToken(extent)); }
private static AttributeOpenToken ReadAttributeOpenToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar('[')); var extent = new SourceExtent(sourceChars); return(new AttributeOpenToken(extent)); }
internal static CloseParenthesesToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); // read the character sourceChars.Add(stream.ReadChar(')')); // return the result extent = extent.WithText(sourceChars); return new CloseParenthesesToken(extent); }
internal static AttributeOpenToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); // read the character sourceChars.Add(stream.ReadChar('[')); // return the result extent = extent.WithText(sourceChars); return new AttributeOpenToken(extent); }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <remarks> /// /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0.pdf /// /// 5.4 Comments /// Comments in a MOF file do not create, modify, or annotate language elements. They shall be treated as if /// they were whitespace. /// /// Comments may appear anywhere in MOF syntax where whitespace is allowed and are indicated by either /// a leading double slash( // ) or a pair of matching /* and */ character sequences. Occurrences of these /// character sequences in string literals shall not be treated as comments. /// /// A // comment is terminated by the end of line (see 5.3), as shown in the example below. /// /// uint16 MyProperty; // This is an example of a single-line comment /// /// A comment that begins with /* is terminated by the next */ sequence, or by the end of the MOF file, /// whichever comes first. /// /// /* example of a comment between property definition tokens and a multi-line comment */ /// uint16 /* 16-bit integer property */ MyProperty; /* and a multi-line /// comment */ /// /// </remarks> private static CommentToken ReadCommentToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); sourceChars.Add(stream.ReadChar('/')); switch (stream.Peek().Value) { case '/': // single-line sourceChars.Add(stream.ReadChar('/')); // read the comment text while (!stream.Eof && !StringValidator.IsLineTerminator(stream.Peek().Value)) { sourceChars.Add(stream.Read()); } ; break; case '*': // multi-line sourceChars.Add(stream.ReadChar('*')); // read the comment text while (!stream.Eof) { var @char = stream.Read(); sourceChars.Add(@char); if ((@char.Value == '*') && stream.PeekChar('/')) { // read the closing sequence sourceChars.Add(stream.ReadChar('/')); break; } } break; default: throw new InvalidOperationException( string.Format("Unexpected character '{0}'.", stream.Peek())); } // return the result var extent = new SourceExtent(sourceChars); return(new CommentToken(extent)); }
internal static MultilineCommentToken Read(ILexerStream stream) { var extent = new SourceExtent(stream); var sourceChars = new List<char>(); // read the opening sequence sourceChars.Add(stream.ReadChar('/')); sourceChars.Add(stream.ReadChar('*')); // read the comment text while (!stream.Eof) { var c = stream.Read(); sourceChars.Add(c); if (c == '*' && stream.PeekChar('/')) break; } // read the closing sequence sourceChars.Add(stream.ReadChar('/')); // return the result extent = extent.WithText(sourceChars); return new MultilineCommentToken(extent); }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <remarks> /// /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0.pdf /// /// A.13.2 Alias identifier /// /// No whitespace is allowed between the elements of this rule. /// /// aliasIdentifier = "$" IDENTIFIER /// /// IDENTIFIER = firstIdentifierChar *( nextIdentifierChar ) /// firstIdentifierChar = UPPERALPHA / LOWERALPHA / UNDERSCORE /// nextIdentifierChar = firstIdentifierChar / decimalDigit /// elementName = localName / schemaQualifiedName /// localName = IDENTIFIER /// /// </remarks> private static AliasIdentifierToken ReadAliasIdentifierToken(ILexerStream stream) { var sourceChars = new List <SourceChar>(); var nameChars = new List <char>(); // read the first character sourceChars.Add(stream.ReadChar('$')); // firstIdentifierChar var peek = stream.Peek(); if (!StringValidator.IsFirstIdentifierChar(peek.Value)) { throw new InvalidOperationException( string.Format("Unexpected character '{0}' encountered", peek.Value)); } // *( nextIdentifierChar ) while (!stream.Eof) { peek = stream.Peek(); if (StringValidator.IsNextIdentifierChar(peek.Value)) { var @char = stream.Read(); sourceChars.Add(@char); nameChars.Add(@char.Value); } else { break; } } // return the result var extent = new SourceExtent(sourceChars); var name = new string(nameChars.ToArray()); return(new AliasIdentifierToken(extent, name)); }