本文整理汇总了C#中Peg.Base.PegNode.GetAsString方法的典型用法代码示例。如果您正苦于以下问题:C# PegNode.GetAsString方法的具体用法?C# PegNode.GetAsString怎么用?C# PegNode.GetAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Peg.Base.PegNode
的用法示例。
在下文中一共展示了PegNode.GetAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Accessor
/// <summary>
/// accessor: accessor_name '[' accessor_key ']';
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <returns></returns>
private INode Accessor(PegNode node, Element element)
{
var ident = node.GetAsString(Src);
var key = node.next_.GetAsString(Src).Replace("'", "");
var el = element.NearestAs<Element>(ident);
if (el!=null)
{
var prop = el.GetAs<Property>(key);
if (((INode)prop) != null) return prop.Value;
}
return new Anonymous("");
}
示例2: PegNodeToXmlRecurse
public static void PegNodeToXmlRecurse(PegNode pn, string text, XmlWriter xml)
{
var name = pn.id_ > 0 ? Enum.GetName(typeof (EUPnPContentDirectorySearch), pn.id_) : "Node";
xml.WriteStartElement(name);
xml.WriteAttributeString("match", pn.GetAsString(text));
if (pn.child_ != null)
{
PegNodeToXmlRecurse(pn.child_, text, xml);
}
xml.WriteEndElement();
if (pn.next_ != null)
{
PegNodeToXmlRecurse(pn.next_, text, xml);
}
}
示例3: TreeNodeToString
public override string TreeNodeToString(PegNode node)
{
string label = base.TreeNodeToString(node);
if (node.id_ == (int)ESpecialNodes.eAnonymousNode)
{
string value = node.GetAsString(src_);
if (value.Length < 32) label += " <" + value + ">";
else label += " <" + value.Substring(0, 29) + "...>";
}
return label;
}
示例4: SetLimit
void SetLimit(PegNode limitNode, ref int limit, ref string limitInto)
{
switch (limitNode.id_)
{
case (int)EPegGrammar.numeric_limit:
limit = Int32.Parse(limitNode.GetAsString(src_));
return;
case (int)EPegGrammar.into_variable:
limitInto = limitNode.GetAsString(src_);
return;
default: Debug.Assert(false);
return;
}
}
示例5: Eval
internal static double Eval(PegNode node, string src, TextWriter errOut)
{
switch ((Ecalc0_tree)node.id_)
{
case Ecalc0_tree.Calc:
{
double res=0;
for (node = node.child_; node != null; node = node.next_)
{
res = Eval(node, src, errOut);
}
Console.WriteLine("-->{0}<--", res);
return res;
}
case Ecalc0_tree.Assign:
{
double res = Eval(node.child_.next_, src, errOut);
string ident = node.child_.GetAsString(src);
variables[ident] = res;
Console.WriteLine("{0}={1}", ident, res);
return res;
}
case Ecalc0_tree.Sum:
case Ecalc0_tree.Prod:
{
double res = Eval(node.child_,src,errOut);
for (PegNode op = node.child_.next_; op != null; op = node.next_)
{
node = op.next_;
switch (op.GetAsString(src))
{
case "+": res += Eval(node, src, errOut); break;
case "-": res -= Eval(node, src, errOut); break;
case "*": res *= Eval(node, src, errOut); break;
case "/": res /= Eval(node, src, errOut); break;
default: Debug.Assert(false); break;
}
}
return res;
}
case Ecalc0_tree.Number:
{
double res;
double.TryParse(node.GetAsString(src),out res);
return res;
}
case Ecalc0_tree.Call:
{
double res = Eval(node.child_.next_, src, errOut);
string operation=node.child_.GetAsString(src).ToLower();
switch (operation)
{
case "sin": return Math.Sin(res);
case "cos": return Math.Cos(res);
case "tan": return Math.Tan(res);
case "sqrt": return Math.Sqrt(res);
case "abs": return Math.Abs(res);
case "acos": return Math.Acos(res);
case "asin": return Math.Asin(res);
case "atan": return Math.Atan(res);
case "ceiling": return Math.Ceiling(res);
case "cosh": return Math.Cosh(res);
case "exp": return Math.Exp(res);
case "floor":return Math.Floor(res);
case "log": return Math.Log10(res);
case "sinh": return Math.Sinh(res);
case "tanh": return Math.Tanh(res);
default: errOut.WriteLine(
"ERROR from CALCOTreeEval: function '{0}' not supported", operation);
return 0;
}
}
case Ecalc0_tree.ident:
{
string ident = node.GetAsString(src);
if (variables.ContainsKey(ident)) return variables[ident];
else return 0;
}
case (Ecalc0_tree)ESpecialNodes.eAnonymousNode:
{
if( node.GetAsString(src)=="print" )
{
foreach(var v in variables)
{
Console.WriteLine("{0,-20}{1}",v.Key,v.Value);
}
}
return 0;
}
}
return 0;
}
示例6: Variable
/// <summary>
/// variable: '@' [-_a-zA-Z0-9]+;
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private INode Variable(PegNode node)
{
return new Variable(node.GetAsString(Src));
}
示例7: LinkToGenericParam
void LinkToGenericParam(PegNode n)
{
Debug.Assert(n.id_ == (int)EPegGrammar.rule_ref);
string refName = n.GetAsString(normalizeTree_.c_.src_);
PegNode genericParam = FindGenericParam(refName);
if (genericParam != null)
{
PegNode genericCall = new NormalizeTree.GenericCall(genericParam, n);
PUtils.ReplaceNode(n, genericCall);
}
}
示例8: Expressions
/// <summary>
/// expressions: operation_expressions / space_delimited_expressions / [-a-zA-Z0-9_%*/.&=:,#+? \[\]()]+ ;
/// </summary>
/// <param name="node"></param>
/// <param name="elementBlock"></param>
/// <returns></returns>
private IEnumerable<INode> Expressions(PegNode node, ElementBlock elementBlock)
{
// Expression
switch (node.id_.ToEnLess())
{
case EnLess.operation_expressions:
return OperationExpressions(node.child_, elementBlock).ToList();
case EnLess.space_delimited_expressions:
return SpaceDelimitedExpressions(node.child_, elementBlock).ToList();
default:
if (node.child_ == null) //CatchAll
return new List<INode>
{
new Anonymous(node.GetAsString(Src))
};
return Expressions(node.child_, elementBlock);
}
}
示例9: Number
/// <summary>
/// number: '-'? [0-9]* '.' [0-9]+ / '-'? [0-9]+;
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private INode Number(PegNode node)
{
var val = float.Parse(node.GetAsString(Src), NumberFormatInfo.InvariantInfo);
var unit = "";
node = node.next_;
if (node != null && node.id_.ToEnLess() == EnLess.unit) unit = node.GetAsString(Src);
return new Number(unit, val);
}
示例10: Import
/// <summary>
/// import : ws '@import' S import_url medias? s ';' ;
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
private void Import(PegNode node, Element element)
{
var path = node.GetAsString(Src);
if(node.child_ != null){
path = node.child_.GetAsString(Src);
}
path = path.Replace("\"", "").Replace("'", "");
//TODO: Fuck around with pah to make it absolute relative
if(HttpContext.Current!=null)
{
path = HttpContext.Current.Server.MapPath(path);
}
if(File.Exists(path))
{
var engine = new Engine(File.ReadAllText(path), null);
element.Rules.AddRange(engine.Parse().Root.Rules);
}
}
示例11: Keyword
/// <summary>
/// keyword: [-a-zA-Z]+ !ns;
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <returns></returns>
private INode Keyword(PegNode node, Element element)
{
return new Keyword(node.GetAsString(Src));
}
示例12: Fonts
/// <summary>
/// fonts : font (s ',' s font)+ ;
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <returns></returns>
private INode Fonts(PegNode node, Element element)
{
var fonts = new List<Literal>();
while (node!=null)
{
if (node.child_ != null) fonts.Add(new String(node.child_.GetAsString(Src)));
else fonts.Add(new Keyword(node.GetAsString(Src)));
node = node.next_;
}
return new FontFamily(fonts.ToArray());
}
示例13: Function
/// <summary>
/// function: function_name arguments ;
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
/// <returns></returns>
private INode Function(PegNode node, Element element)
{
var funcName = node.GetAsString(Src);
var arguments = Arguments(node.next_, element);
return new Function(funcName, arguments);
}
示例14: Declaration
/// <summary>
/// declaration: standard_declaration / catchall_declaration ;
/// </summary>
/// <param name="node"></param>
/// <param name="element"></param>
private void Declaration(PegNode node, Element element)
{
if (node.id_.ToEnLess() == EnLess.standard_declaration)
{
node = node.child_;
var name = node.GetAsString(Src).Replace(" ", "");
if (name.Substring(0, 1) == "@")
{
var property = new Variable(name, Expressions(node.next_, element));
element.Add(property);
}
else
{
var property = new Property(name, Expressions(node.next_, element));
element.Add(property);
}
}
else if (node.id_.ToEnLess() == EnLess.catchall_declaration)
{
/* node = node.child_;
var name = node.GetAsString(Src).Replace(" ", "");
element.Add(new Property(name));*/
//TODO: Should I be doing something here?
}
}
示例15: LinkSemanticFunctions
void LinkSemanticFunctions(PegNode n)
{
Debug.Assert(n.id_ == (int)EPegGrammar.rule_ref);
string semanticFunction = n.GetAsString(normalizeTree_.c_.src_);
if (normalizeTree_.setRules_.Contains(semanticFunction)) return; //was a rule reference
PegNode method;
bool isLocal;
PegNode semBlock = normalizeTree_.FindSemanticBlock(FindSemanticFunctionInTree, semanticFunction, n, out method, out isLocal);
if (semBlock != null)
{
var semanticFuncWithContext = new NormalizeTree.SemanticVarOrFuncWithContext((int)EPegGeneratorNodes.SemanticFunctionWithContext, semBlock, method, n, isLocal);
normalizeTree_.c_.semanticInfoNodes_.Add(method);
PUtils.ReplaceNode(n, semanticFuncWithContext);
}
else
{
normalizeTree_.c_.errOut_.WriteLine(normalizeTree_.c_.sErrorPrefix + "ERROR: no rule found and no semantic function <" + semanticFunction + "> found in semantic block candidates");
normalizeTree_.bOk_ = false;
}
}