本文整理汇总了C#中CharStream.ReadReg方法的典型用法代码示例。如果您正苦于以下问题:C# CharStream.ReadReg方法的具体用法?C# CharStream.ReadReg怎么用?C# CharStream.ReadReg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharStream
的用法示例。
在下文中一共展示了CharStream.ReadReg方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static AST.INode Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
var condition = Expressions.Logic.Parse(stream);
// check if we have an IfElse case or simply a logical expression
string s;
if (stream.ReadReg(@"\s*\?\s*", out s))
{
var first = Expression.Parse(stream);
WhiteSpace.Parse(stream, true);
stream.SkipCharacter(':');
WhiteSpace.Parse(stream, true);
var second = Expression.Parse(stream);
return new AST.Conditional(condition, first, second);
} else
{ // it's simply a logical expression
return condition;
}
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <expression> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}
示例2: Parse
public static Info Parse(CharStream stream, Info expected = null)
{
string output;
int pos = stream.Position;
if (!stream.ReadReg("(\'|\")", out output))
{
throw new Exceptions.ParseException(
String.Format(
"expected to read a <quote> (starting at {0}), but no characters were left",
stream.ComputeDetailedPosition(pos)));
}
Info info;
if (output[0] == '"')
{
info = new Info(Type.Double);
} else
{
info = new Info(Type.Single);
}
if (expected != null && expected.CompareTo(info) != 0)
{
throw new Exceptions.ParseException(
String.Format(
"expected to read {0} (starting at {1}), but found {2}",
expected.ToString(),
stream.ComputeDetailedPosition(pos),
info.ToString()));
}
return info;
}
示例3: Parse
public static AST.INode Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
var first = Binary.Parse(stream);
string op;
if (stream.ReadReg(@"\s*(\|\||\&\&)", out op))
{
WhiteSpace.Parse(stream, true);
var second = Logic.Parse(stream);
return new AST.LogicExpression(
first, second, op.Trim());
} else
{
return first;
}
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <logical_expression> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}
示例4: 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);
}
示例5: PeekAndParse
public static bool PeekAndParse(CharStream stream, out string identifier, bool allow_underscore)
{
var reg = allow_underscore ? @"[_a-zA-Z]\w*" : @"[a-zA-Z]\w*";
if (!stream.EndOfStream() && stream.ReadReg(reg, out identifier))
{
return true;
}
identifier = null;
return false;
}
示例6: Chain
// The constructor collects all the nodes
public Chain(CharStream stream, AST.INode node, string op)
{
m_Nodes = new List<Node>(2);
do
{
m_Nodes.Add(new Node(node, op));
WhiteSpace.Parse(stream, true);
node = Unary.Parse(stream);
} while(stream.ReadReg (@"\s*(\=\=|\!\=|\<\=|\>\=|\<|\>|\+|\-|\*|\/|\%)", out op));
m_Nodes.Add(new Node(node));
}
示例7: Parse
public static AST.INode Parse(CharStream stream)
{
var startingPos = stream.Position;
try
{
var first = Unary.Parse(stream);
string raw;
if (stream.ReadReg(@"\s*(\=\=|\!\=|\<\=|\>\=|\<|\>|\+|\-|\*|\/|\%)", out raw))
{
var chain = new Chain(stream, first, raw);
return chain.Build();
} else
{
return first;
}
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing an <binary_expression> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}
示例8: 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");
}
}