本文整理汇总了C#中CharStream.CreateException方法的典型用法代码示例。如果您正苦于以下问题:C# CharStream.CreateException方法的具体用法?C# CharStream.CreateException怎么用?C# CharStream.CreateException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharStream
的用法示例。
在下文中一共展示了CharStream.CreateException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static AST.INode Parse(CharStream stream)
{
string raw;
if (!stream.ReadReg(@"[\-\+]?[0-9]+", out raw))
{
throw stream.CreateException("a number literal whas expected");
}
return new AST.Literal(raw);
}
示例2: Parse
public static string Parse(CharStream stream, bool allow_underscore)
{
string identifier;
if (!Identifier.PeekAndParse(stream, out identifier, allow_underscore))
{
throw stream.CreateException(
"expected to read an <identifier>, but non-word character was found");
}
return identifier;
}
示例3: Parse
public static int Parse(CharStream stream, bool optional)
{
int pos = stream.Position;
int n = stream.SkipWhile(char.IsWhiteSpace);
if (!optional && n == 0)
{
throw stream.CreateException(
"at least one whitespace character is required",
pos - stream.Position);
}
return n;
}
示例4: Parse
public static void Parse(CharStream stream)
{
if (!stream.SkipIfPossible('/') || !(stream.SkipIfPossible('*')))
{
throw stream.CreateException(
"a comment has to be opened with '/*'");
}
char c;
string content = "";
while (stream.ReadNext(out c))
{
if (c == '*' && stream.SkipIfPossible('/'))
{
return;
}
content += c;
}
throw new ParseException(
"a comment entry was opened, but not closed",
stream.CreateEOFException());
}
示例5: Parse
public static AST.INode Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
// Parse the quote and store that in the AST of the stringValue
var quote = Quote.Parse(stream);
var value = new AST.StringValue(quote);
AST.INode expression;
char c;
// Trim starting space
WhiteSpace.Parse(stream, true);
// as long as we have more characters left
// we'll keep reading, and break from within this loop body
// when we reached the same quote that started this entire parser logic.
while ((c = stream.PeekNext()) != '\0')
{
if (c == '\\')
{
// skip the escape character && read the next one
stream.Skip();
c = stream.PeekNext();
if (c == '\\' || c == '{' || c == '}' || c == '\'' || c == '"')
{
c = stream.ForceReadNext();
value.appendChar(c);
} else if (c == 'u')
{
// skip the starter character
stream.Skip();
// try to read unicode character
value.appendChar(ReadUnicodeCharacter(stream));
} else
{
var msg = String.Format(
"character \\{0} is not a valid escape character", c);
throw stream.CreateException(msg);
}
// unicode characters are also supported in the classical U+xxxxxx notation
} else if (c == 'U' && stream.PeekNext(1) == '+')
{
// skip the starter characters
stream.Skip(2);
// try to read unicode character
value.appendChar(ReadUnicodeCharacter(stream));
} else if (c == '\n' || c == '\r') // newlines get converted to a space
{
stream.Skip();
var lc = value.LastCharacter;
// we add this dummy character, such that we wouldn't add a space in
// languages that don't use a space in general, such as chinese.
if (!Char.IsWhiteSpace(lc) && lc != AST.StringValue.DummyNewlineWhitespaceCharacter)
value.appendChar(AST.StringValue.DummyNewlineWhitespaceCharacter);
} else
{
if (Quote.Peek(stream, quote))
{
break; // un-escaped quote means we're ending the string
} else if (Expander.PeekAndParse(stream, out expression))
{
value.appendExpression(expression);
} else
{
c = stream.ForceReadNext();
var lc = value.LastCharacter;
if(!Char.IsWhiteSpace(c)
|| (lc != AST.StringValue.DummyNewlineWhitespaceCharacter
&& !Char.IsWhiteSpace(lc)))
value.appendChar(c);
}
}
}
// Eventually we expect exactly the same string back
Quote.Parse(stream, quote);
return value;
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <string_value> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}
示例6: ReadUnicodeCharacter
private static char ReadUnicodeCharacter(CharStream stream)
{
string unicodeValue;
if (stream.ReadReg("(0|1)?[0-9a-fA-F]{4,5}", out unicodeValue))
{
return (char)Convert.ToInt32(unicodeValue, 16);
} else
{
throw stream.CreateException("not a valid unicode character");
}
}