本文整理汇总了C#中ParseTreeNode.FindTokenAndGetText方法的典型用法代码示例。如果您正苦于以下问题:C# ParseTreeNode.FindTokenAndGetText方法的具体用法?C# ParseTreeNode.FindTokenAndGetText怎么用?C# ParseTreeNode.FindTokenAndGetText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTreeNode
的用法示例。
在下文中一共展示了ParseTreeNode.FindTokenAndGetText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
// this is where data is initially passed to the item
public override void Init(AstContext context, ParseTreeNode treeNode)
{
string sVal = treeNode.FindTokenAndGetText();
base.Init(context, treeNode);
var nodes = treeNode.GetMappedChildNodes();
var functionOrProperty = AddChild("FunctionOrId", nodes[0]);
if (functionOrProperty is SelectFunctionNode)
{
_TheFunction = (SelectFunctionNode)functionOrProperty;
}
else if (functionOrProperty is SelectPropertyNode)
{
_PropNode = (SelectPropertyNode)functionOrProperty;
}
else
{
throw new Exception("Unmanaged type in selectmemberaccessnode");
}
if (nodes.Count > 1)
{
var child = AddChild("Queue", nodes[1]);
string sval = nodes[1].FindTokenAndGetText();
if (child is LeftObjectNode)
{
_queue = (LeftObjectNode)child;
}
}
}
示例2: CreateDefinedRulesList
//-----------------------------------------
public void CreateDefinedRulesList(ParseTreeNode node, List<string> rulenames)
{
foreach (var child in node.ChildNodes)
CreateDefinedRulesList(child, rulenames);
if (node.Term.Name == "newrulename")
rulenames.Add(node.FindTokenAndGetText());
}
示例3: Init
public override void Init(AstContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
//TODO: units conversion
_Value=decimal.Parse(treeNode.FindTokenAndGetText(), CultureInfo.InvariantCulture);
AsString=string.Format(
CultureInfo.InvariantCulture,
"{0:G}m",
_Value
);
}
示例4: BuildRuleExpressions
private void BuildRuleExpressions(ParseTreeNode node)
{
var ruleName = node.FindTokenAndGetText();
var rule = rules.ContainsKey(ruleName) ? rules[ruleName] : rules[ruleName] = new AlternationExpression();
ParseTreeNode elements = null;
foreach (var child in node.ChildNodes)
if (child.Term.Name == "elements")
elements = child;
rule.Add(
BuildAlternationExpression(elements.ChildNodes[0]));
}
示例5: Init
// this is where data is initially passed to the item
public override void Init(AstContext context, ParseTreeNode treeNode)
{
string sVal = treeNode.FindTokenAndGetText();
base.Init(context, treeNode);
var nodes = treeNode.GetMappedChildNodes();
property = treeNode;
if (nodes.Count > 1)
{
var child = AddChild("Queue", nodes[1]);
string sval = nodes[1].FindTokenAndGetText();
if (child is LeftObjectNode)
{
_queue = (LeftObjectNode)child;
}
}
}
示例6: CreateCharval
public string CreateCharval(ParseTreeNode node)
{
return "FromString(" + node.FindTokenAndGetText().Replace("\\", "\\\\") + ",rulenames)";
}
示例7: BuildExpandableStringLiteralAst
ExpressionAst BuildExpandableStringLiteralAst(ParseTreeNode parseTreeNode)
{
var matches = Regex.Match(parseTreeNode.FindTokenAndGetText(), this._grammar.expandable_string_literal.Pattern, RegexOptions.IgnoreCase);
string value = matches.Groups[this._grammar.expandable_string_characters.Name].Value +
matches.Groups[this._grammar.dollars.Name].Value
;
var ast = new ExpandableStringExpressionAst(new ScriptExtent(parseTreeNode), value, StringConstantType.DoubleQuoted);
if (ast.NestedExpressions.Any())
{
return ast;
}
return new StringConstantExpressionAst(new ScriptExtent(parseTreeNode), value, StringConstantType.DoubleQuoted);
}
示例8: BuildDecimalRealLiteralAst
private ConstantExpressionAst BuildDecimalRealLiteralAst(ParseTreeNode parseTreeNode, Group multiplier, Group decimalTypeSuffix)
{
string digits = parseTreeNode.FindTokenAndGetText();
if (multiplier.Success)
{
digits = RemoveMatchedString(digits, multiplier);
}
digits = RemoveMatchedString(digits, decimalTypeSuffix);
decimal value;
if (!decimal.TryParse(digits, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value))
{
throw new OverflowException(string.Format("Bad numeric constant: {0}.", parseTreeNode.FindTokenAndGetText()));
}
if (multiplier.Success)
{
value *= NumericMultiplier.GetValue(multiplier.Value);
}
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), value);
}
示例9: SelectTokenKind
TokenKind SelectTokenKind(ParseTreeNode parseTreeNode)
{
if (!(parseTreeNode.Term is Terminal)) throw new InvalidOperationException(parseTreeNode.ToString());
var text = parseTreeNode.FindTokenAndGetText();
switch (text)
{
case "=":
return TokenKind.Equals;
case "+=":
return TokenKind.PlusEquals;
case "-=":
return TokenKind.MinusEquals;
case "*=":
return TokenKind.MultiplyEquals;
case "/=":
return TokenKind.DivideEquals;
case "%=":
return TokenKind.RemainderEquals;
default:
throw new NotImplementedException(parseTreeNode.ToString());
}
}
示例10: BuildRealLiteralAst
ConstantExpressionAst BuildRealLiteralAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.real_literal);
var matches = Regex.Match(parseTreeNode.FindTokenAndGetText(), this._grammar.real_literal.Pattern, RegexOptions.IgnoreCase);
Group multiplier = matches.Groups[this._grammar.numeric_multiplier.Name];
Group decimalTypeSuffix = matches.Groups[this._grammar.decimal_type_suffix.Name];
if (decimalTypeSuffix.Success)
{
return BuildDecimalRealLiteralAst(parseTreeNode, multiplier, decimalTypeSuffix);
}
return BuildDoubleRealLiteralAst(parseTreeNode, multiplier);
}
示例11: BuildDecimalIntegerLiteralAst
ConstantExpressionAst BuildDecimalIntegerLiteralAst(ParseTreeNode parseTreeNode)
{
VerifyTerm(parseTreeNode, this._grammar.decimal_integer_literal);
var matches = Regex.Match(parseTreeNode.FindTokenAndGetText(), this._grammar.decimal_integer_literal.Pattern, RegexOptions.IgnoreCase);
string digits = matches.Groups[this._grammar.decimal_digits.Name].Value;
string typeSuffix = matches.Groups[this._grammar.numeric_type_suffix.Name].Value;
string longTypeSuffix = matches.Groups[this._grammar.long_type_suffix.Name].Value;
string multiplier = matches.Groups[this._grammar.numeric_multiplier.Name].Value;
// The type of an integer literal is determined by its value, the presence or absence of long-type-suffix, and the
// presence of a numeric-multiplier (§2.3.5.1.3).
object value;
if (typeSuffix == string.Empty)
{
// For an integer literal with no long-type-suffix
// • If its value can be represented by type int (§4.2.3), that is its type;
// • Otherwise, if its value can be represented by type long (§4.2.3), that is its type.
if (!ParseIntOrLongLiteral(digits, multiplier, NumberStyles.Integer, out value))
{
decimal decimalValue;
double doubleValue;
if (decimal.TryParse(digits, out decimalValue))
// • Otherwise, if its value can be represented by type decimal (§2.3.5.1.2), that is its type.
value = NumericMultiplier.Multiply(decimalValue, multiplier);
else if (double.TryParse(digits, out doubleValue))
// • Otherwise, it is represented by type double (§2.3.5.1.2).
value = NumericMultiplier.Multiply(doubleValue, multiplier);
else
// For PowerShell compatibility throw an error here instead of saturating the double to infinity.
throw new OverflowException(string.Format("The integer literal {0} is too large.", matches.Value));
}
}
else if (longTypeSuffix != string.Empty)
{
// For an integer literal with long-type-suffix
long longValue;
// • If its value can be represented by type long (§4.2.3), that is its type;
if (long.TryParse(digits, out longValue))
value = NumericMultiplier.Multiply(longValue, multiplier);
else
// • Otherwise, that literal is ill formed.
throw new ArithmeticException(string.Format("The integer literal {0} is invalid because it does not fit into a long.", matches.Value));
}
else
{
// The spec doesn't explicitly mention this case, but it seems to be handled
// similar to a long suffix.
decimal decimalValue;
if (decimal.TryParse(digits, out decimalValue))
value = NumericMultiplier.Multiply(decimalValue, multiplier);
else
throw new ArithmeticException(string.Format("The integer literal {0} is invalid because it does not fit into a decimal.", matches.Value));
}
return new ConstantExpressionAst(new ScriptExtent(parseTreeNode), value);
}
示例12: GetMessage
public static string GetMessage(ParseTreeNode node, string message)
{
return string.Format(@"ParseTreeNode: {0}, Error: {1}", node.FindTokenAndGetText(), message);
}
示例13: CreateUsedRulesList
public void CreateUsedRulesList(ParseTreeNode node, List<string> rulenames)
{
foreach (var child in node.ChildNodes)
CreateUsedRulesList(child, rulenames);
if (node.Term.Name == "rulename")
{
var rulename = node.FindTokenAndGetText();
if (rulenames.Find((fromList) => { return fromList == rulename; }) == null)
rulenames.Add(node.FindTokenAndGetText());
}
}
示例14: BuildCharvalExpression
private IExpression BuildCharvalExpression(ParseTreeNode node)
{
var charval = node.FindTokenAndGetText();//.Replace("\\", "\\\\");
charval = charval.Substring(1, charval.Length - 2);
return new CharvalExpression(this, charval);
}
示例15: GetParseTreeNodeText
private static string GetParseTreeNodeText(ParseTreeNode parseTreeNode)
{
if (parseTreeNode == null)
{
return string.Empty;
}
// We cannot use FindTokenAndGetText always because it will give us only the text of the root node in
// case of complex expressions. So we have to do that:
if (parseTreeNode.ChildNodes.Count > 0)
{
var result = new StringBuilder();
foreach (var node in parseTreeNode.ChildNodes)
{
int offset = node.Span.Location.Position - parseTreeNode.Span.Location.Position;
if (result.Length < offset)
{
result.Append(' ', offset - result.Length);
}
result.Append(GetParseTreeNodeText(node));
}
return result.ToString();
}
return parseTreeNode.FindTokenAndGetText() ?? string.Empty;
}