本文整理汇总了C#中Internal.AddMacro方法的典型用法代码示例。如果您正苦于以下问题:C# Internal.AddMacro方法的具体用法?C# Internal.AddMacro怎么用?C# Internal.AddMacro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal
的用法示例。
在下文中一共展示了Internal.AddMacro方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static void Parse(
CharStream stream,
string identifier, Internal.LocaleContext.Builder builder)
{
var startingPos = stream.Position;
try
{
var macroAST = new AST.Macro(identifier);
stream.SkipCharacter('(');
WhiteSpace.Parse(stream, true);
// variables are optional,
// but we do have them, we need at least one (duh)
if (Expressions.Variable.Peek(stream))
{
macroAST.AddParameter(Macro.ParseVariable(stream));
// more than 1 is possible as well
while (stream.SkipIfPossible(','))
{
WhiteSpace.Parse(stream, true);
macroAST.AddParameter(Macro.ParseVariable(stream));
}
}
stream.SkipCharacter(')');
WhiteSpace.Parse(stream, false);
stream.SkipCharacter('{');
WhiteSpace.Parse(stream, true);
// Parse the Actual Macro Expression
macroAST.SetExpression(Expression.Parse(stream));
WhiteSpace.Parse(stream, true);
stream.SkipCharacter('}');
WhiteSpace.Parse(stream, true);
stream.SkipCharacter('>');
// return the fully parsed macro
try
{
var macro = (Objects.Macro)macroAST.Eval();
builder.AddMacro(identifier, macro);
} catch (Exception e)
{
throw new Exceptions.EvaluateException(
String.Format("couldn't evaluate `{0}`", macroAST.Display()),
e);
}
} catch (Exception e)
{
string msg = String.Format(
"something went wrong parsing a <macro> starting at {0}",
stream.ComputeDetailedPosition(startingPos));
throw new Exceptions.ParseException(msg, e);
}
}