本文整理汇总了C#中Irony.Parsing.ParsingContext类的典型用法代码示例。如果您正苦于以下问题:C# ParsingContext类的具体用法?C# ParsingContext怎么用?C# ParsingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsingContext类属于Irony.Parsing命名空间,在下文中一共展示了ParsingContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Init
public override void Init(ParsingContext context, ParseTreeNode parseNode)
{
base.Init(context, parseNode);
foreach (var node in parseNode.ChildNodes)
{
if (node.AstNode is Function)
{
AddFunction(node.AstNode as Function);
}
else if (node.AstNode is AuxiliaryNode)
{
var ids = (node.AstNode as AuxiliaryNode).ChildNodes.OfType<IdentifierNode>();
foreach (var id in ids)
{
ExternalFunction ef = new ExternalFunction();
ef.SetSpan(id.Span);
ef.Name = id.Symbol;
AddFunction(ef);
}
}
}
AsString = "Refal-5 program";
}
开发者ID:MarcusTheBold,项目名称:Irony,代码行数:26,代码来源:Program.cs
示例2: DirectInit
public void DirectInit(ParsingContext context, ParseTreeNode parseNode)
{
var idChain = ((IDNode)parseNode.ChildNodes[2].AstNode).IDChainDefinition;
var tupleDefinition = ((TupleNode)parseNode.ChildNodes[3].AstNode).TupleDefinition;
var AttrName = parseNode.ChildNodes[2].FirstChild.FirstChild.Token.ValueString;
ToBeRemovedList = new AttributeRemoveList(idChain, AttrName, tupleDefinition);
}
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:RemoveFromListAttrUpdateAddToRemoveFromNode.cs
示例3: CreateIncompleteToken
private Token CreateIncompleteToken(ParsingContext context, ISourceStream source) {
source.PreviewPosition = source.Text.Length;
Token result = source.CreateToken(this.OutputTerminal);
result.Flags |= TokenFlags.IsIncomplete;
context.VsLineScanState.TerminalIndex = this.MultilineIndex;
return result;
}
开发者ID:kayateia,项目名称:climoo,代码行数:7,代码来源:CommentTerminal.cs
示例4: TryMatch
public override Token TryMatch(ParsingContext context, ISourceStream source) {
Match m = _expression.Match(source.Text, source.PreviewPosition);
if (!m.Success || m.Index != source.PreviewPosition)
return null;
source.PreviewPosition += m.Length;
return source.CreateToken(this.OutputTerminal);
}
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:7,代码来源:RegExBasedTerminal.cs
示例5: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
if (HasChildNodes(parseNode))
{
BinExprNode = (BinaryExpressionNode)parseNode.ChildNodes[1].AstNode;
}
}
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:HavingExpressionNode.cs
示例6: ReadQuotedBody
private static string ReadQuotedBody(ParsingContext context, ISourceStream source)
{
const char dQuoute = '"';
StringBuilder sb = null;
var from = source.Location.Position + 1; //skip initial double quote
while(true) {
var until = source.Text.IndexOf(dQuoute, from);
if (until < 0)
throw new Exception(Resources.ErrDsvNoClosingQuote); // "Could not find a closing quote for quoted value."
source.PreviewPosition = until; //now points at double-quote
var piece = source.Text.Substring(from, until - from);
source.PreviewPosition++; //move after double quote
if (source.PreviewChar != dQuoute && sb == null)
return piece; //quick path - if sb (string builder) was not created yet, we are looking at the very first segment;
// and if we found a standalone dquote, then we are done - the "piece" is the result.
if (sb == null)
sb = new StringBuilder(100);
sb.Append(piece);
if (source.PreviewChar != dQuoute)
return sb.ToString();
//we have doubled double-quote; add a single double-quoute char to the result and move over both symbols
sb.Append(dQuoute);
from = source.PreviewPosition + 1;
}
}
开发者ID:dbremner,项目名称:irony,代码行数:25,代码来源:DsvLiteral.cs
示例7: Init
public override void Init(ParsingContext context, ParseTreeNode treeNode) {
base.Init(context, treeNode);
TargetRef = AddChild("Target", treeNode.ChildNodes[0]);
_targetName = treeNode.ChildNodes[0].FindTokenAndGetText();
Arguments = AddChild("Args", treeNode.ChildNodes[1]);
AsString = "Call " + _targetName;
}
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:FunctionCallNode.cs
示例8: Parser
/// <summary>
/// Initializes a new instance of the <see cref="Parser"/> class.
/// </summary>
/// <param name="language">The language.</param>
/// <param name="scanner">The scanner.</param>
/// <param name="root">The root.</param>
/// <exception cref="Exception">
/// </exception>
public Parser(LanguageData language, Scanner scanner, NonTerminal root)
{
Language = language;
Context = new ParsingContext(this);
Scanner = scanner ?? language.CreateScanner();
if (Scanner != null)
{
Scanner.Initialize(this);
}
else
{
Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
}
CoreParser = new CoreParser(this);
Root = root;
if (Root == null)
{
Root = Language.Grammar.Root;
InitialState = Language.ParserData.InitialState;
}
else
{
if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
{
throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
}
InitialState = Language.ParserData.InitialStates[Root];
}
}
开发者ID:cg123,项目名称:xenko,代码行数:39,代码来源:Parser.cs
示例9: DirectInit
public void DirectInit(ParsingContext context, ParseTreeNode parseNode)
{
var _elementsToBeAdded = (CollectionOfDBObjectsNode)parseNode.ChildNodes[3].AstNode;
var _AttrName = parseNode.ChildNodes[2].FirstChild.FirstChild.Token.ValueString;
AttributeUpdateList = new AttributeAssignOrUpdateList(_elementsToBeAdded.CollectionDefinition, ((IDNode)parseNode.ChildNodes[2].AstNode).IDChainDefinition, false);
}
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:AddToListAttrUpdateAddToNode.cs
示例10: InitNode
/// <summary>
/// Converts identifiers to compound symbols (strings in double quotes),
/// expands character strings (in single quotes) to arrays of characters
/// </summary>
public static void InitNode(ParsingContext context, ParseTreeNode parseNode)
{
foreach (var node in parseNode.ChildNodes)
{
if (node.AstNode is LiteralValueNode)
{
if (node.Term.Name == "Char")
{
var literal = node.AstNode as LiteralValueNode;
literal.Value = literal.Value.ToString().ToCharArray();
}
parseNode.AstNode = node.AstNode;
}
else
{
// identifiers in expressions are treated as strings (True is same as "True")
parseNode.AstNode = new LiteralValueNode()
{
Value = node.FindTokenAndGetText(),
Span = node.Span
};
}
}
}
开发者ID:MarcusTheBold,项目名称:Irony,代码行数:29,代码来源:LiteralValueNodeHelper.cs
示例11: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
if (HasChildNodes(parseNode))
{
ParallelTasks = Convert.ToUInt32(parseNode.ChildNodes[1].Token.Value);
}
}
开发者ID:anukat2015,项目名称:sones,代码行数:7,代码来源:ParallelTasksNode.cs
示例12: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
if (HasChildNodes(parseNode))
{
//get type
if (parseNode.ChildNodes[1] != null && parseNode.ChildNodes[1].AstNode != null)
{
_type = ((AstNode)(parseNode.ChildNodes[1].AstNode)).AsString;
}
else
{
throw new NotImplementedQLException("");
}
if (parseNode.ChildNodes[3] != null && HasChildNodes(parseNode.ChildNodes[3]))
{
_attributeAssignList = (parseNode.ChildNodes[3].AstNode as AttributeAssignListNode).AttributeAssigns;
}
if (parseNode.ChildNodes[4] != null && ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition != null)
{
_whereExpression = ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition;
}
}
}
开发者ID:anukat2015,项目名称:sones,代码行数:28,代码来源:InsertOrReplaceNode.cs
示例13: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
var multiplyString = parseNode.ChildNodes[0].Token.Text.ToUpper();
CollectionType collectionType;
switch (multiplyString)
{
case SonesGQLConstants.LISTOF:
collectionType = CollectionType.List;
break;
case SonesGQLConstants.SETOF:
collectionType = CollectionType.Set;
break;
case SonesGQLConstants.SETOFUUIDS:
default:
throw new InvalidOperationException(
String.Format("The specified command [{0}] is not valid.", multiplyString));
}
if (parseNode.ChildNodes[1].AstNode is TupleNode)
{
CollectionDefinition =
new CollectionDefinition(collectionType,
((TupleNode)parseNode.ChildNodes[1].AstNode).TupleDefinition);
}
else
{
throw new NotImplementedException("The following node cannot be created.");
}
}
开发者ID:anukat2015,项目名称:sones,代码行数:35,代码来源:CollectionOfBasicDBObjectsNode.cs
示例14: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
#region get Name
_TypeName = parseNode.ChildNodes[0].Token.ValueString;
#endregion
#region get Extends
if (HasChildNodes(parseNode.ChildNodes[1]))
_Extends = parseNode.ChildNodes[1].ChildNodes[1].Token.ValueString;
#endregion
#region get myAttributes
if (HasChildNodes(parseNode.ChildNodes[2]))
_Attributes = GetAttributeList(parseNode.ChildNodes[2].ChildNodes[1]);
#endregion
#region get Comment
if (HasChildNodes(parseNode.ChildNodes[3]))
_Comment = parseNode.ChildNodes[3].ChildNodes[2].Token.ValueString;
#endregion
}
开发者ID:anukat2015,项目名称:sones,代码行数:29,代码来源:BulkEdgeTypeNode.cs
示例15: TryMatch
public override Token TryMatch(ParsingContext context, ISourceStream source) {
string tokenText = string.Empty;
while (true) {
//Find next position
var newPos = source.Text.IndexOfAny(_stopChars, source.PreviewPosition);
if(newPos == -1) {
if(IsSet(FreeTextOptions.AllowEof)) {
source.PreviewPosition = source.Text.Length;
return source.CreateToken(this.OutputTerminal);
} else
return null;
}
if (newPos == source.PreviewPosition) // DC
{
context.AddParserError("(DC) in TryMatch, newPos == source.PreviewPosition", new object[] {});
break; // DC
}
tokenText += source.Text.Substring(source.PreviewPosition, newPos - source.PreviewPosition);
source.PreviewPosition = newPos;
//if it is escape, add escaped text and continue search
if (CheckEscape(source, ref tokenText))
continue;
//check terminators
if (CheckTerminators(source, ref tokenText))
break; //from while (true)
}
return source.CreateToken(this.OutputTerminal, tokenText);
}
开发者ID:pusp,项目名称:o2platform,代码行数:28,代码来源:FreeTextLiteral.cs
示例16: BeginFiltering
public override IEnumerable<Token> BeginFiltering(ParsingContext context, IEnumerable<Token> tokens)
{
this.pcontext = context;
foreach (Token t in tokens)
{
Console.WriteLine(" -> {0} ({1})", t, bracket_indent_level);
currentLoc = t.Location;
if (t.Terminal == grammar.Eof)
{
Console.WriteLine("CLI: {0}, CIL: {1}", current_line_indent, current_indent_level);
current_line_indent = 0;
while(current_indent_level > 0)
{
current_indent_level--;
Console.WriteLine(" <- DEDENT");
yield return new Token(grammar.Dedent,currentLoc,string.Empty,null);
}
yield return t;
break;
}
if (bracket_indent_level == 0)
{
while (ProcessToken(t)) { ;}
while (OutputTokens.Count > 0)
yield return OutputTokens.Pop();
continue;
}
if (t.Terminal == opening_bracket) { bracket_indent_level++; yield return new Token(grammar.Indent, currentLoc, string.Empty, null); continue; }
else if (t.Terminal == closing_bracket) { Debug.Assert(bracket_indent_level > 0); bracket_indent_level--; yield return new Token(grammar.Dedent, currentLoc, string.Empty, null); continue; }
yield return t;
}
}
开发者ID:bgare89,项目名称:OpenBYOND-1,代码行数:32,代码来源:IndentFilter.cs
示例17: Init
public void Init(ParsingContext context, ParseTreeNode parseNode)
{
if (HasChildNodes(parseNode))
{
//get type
if (parseNode.ChildNodes[1] != null && parseNode.ChildNodes[1].AstNode != null)
{
_Type = ((AstNode)(parseNode.ChildNodes[1].AstNode)).AsString;
}
else
{
throw new NotImplementedQLException("");
}
if (parseNode.ChildNodes[3] != null && HasChildNodes(parseNode.ChildNodes[3]))
{
_AttributeAssignList = new List<AAttributeAssignOrUpdate>((parseNode.ChildNodes[3].AstNode as AttributeUpdateOrAssignListNode).ListOfUpdate.Select(e => e as AAttributeAssignOrUpdate));
}
if (parseNode.ChildNodes[4] != null && ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition != null)
{
_WhereExpression = ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition;
}
}
}
开发者ID:anukat2015,项目名称:sones,代码行数:30,代码来源:InsertOrUpdateNode.cs
示例18: Init
public override void Init(ParsingContext context, ParseTreeNode treeNode)
{
base.Init(context, treeNode);
foreach (var child in treeNode.MappedChildNodes)
AddChild(NodeUseType.Parameter, "param", child);
AsString = "param_list[" + ChildNodes.Count + "]";
}
开发者ID:MarcusTheBold,项目名称:Irony,代码行数:7,代码来源:ParamListNode.cs
示例19: CompleteReduce
//Completes reduce: pops child nodes from the stack and pushes result node into the stack
protected void CompleteReduce(ParsingContext context) {
var resultNode = context.CurrentParserInput;
var childCount = Production.RValues.Count;
//Pop stack
context.ParserStack.Pop(childCount);
//Copy comment block from first child; if comments precede child node, they precede the parent as well.
if (resultNode.ChildNodes.Count > 0)
resultNode.Comments = resultNode.ChildNodes[0].Comments;
//Inherit precedence and associativity, to cover a standard case: BinOp->+|-|*|/;
// BinOp node should inherit precedence from underlying operator symbol.
//TODO: this special case will be handled differently. A ToTerm method should be expanded to allow "combined" terms like "NOT LIKE".
// OLD COMMENT: A special case is SQL operator "NOT LIKE" which consists of 2 tokens. We therefore inherit "max" precedence from any children
if (Production.LValue.Flags.IsSet(TermFlags.InheritPrecedence))
InheritPrecedence(resultNode);
//Push new node into stack and move to new state
//First read the state from top of the stack
context.CurrentParserState = context.ParserStack.Top.State;
if (context.TracingEnabled)
context.AddTrace(Resources.MsgTracePoppedState, Production.LValue.Name);
#region comments on special case
//Special case: if a non-terminal is Transient (ex: BinOp), then result node is not this NonTerminal, but its its child (ex: symbol).
// Shift action will invoke OnShifting on actual term being shifted (symbol); we need to invoke Shifting even on NonTerminal itself
// - this would be more expected behavior in general. ImpliedPrecHint relies on this
#endregion
if (resultNode.Term != Production.LValue) //special case
Production.LValue.OnShifting(context.SharedParsingEventArgs);
// Shift to new state - execute shift over the non-terminal of the production.
var shift = context.CurrentParserState.Actions[Production.LValue];
// Execute shift to new state
shift.Execute(context);
//Invoke Reduce event
Production.LValue.OnReduced(context, Production, resultNode);
}
开发者ID:androdev4u,项目名称:XLParser,代码行数:34,代码来源:ReduceParserActions.cs
示例20: CompleteMatch
private Token CompleteMatch(ParsingContext context, ISourceStream source, byte level)
{
string text = source.Text.Substring(source.PreviewPosition);
var matches = Regex.Matches(text, @"\](=*)\]");
foreach(Match match in matches)
{
if (match.Groups[1].Value.Length == (int)level)
{
source.PreviewPosition += match.Index + match.Length;
if (context.VsLineScanState.Value != 0)
{
SourceLocation tokenStart = new SourceLocation();
tokenStart.Position = 0;
string lexeme = source.Text.Substring(0, source.PreviewPosition);
context.VsLineScanState.Value = 0;
return new Token(this, tokenStart, lexeme, null);
}
else
{
return source.CreateToken(this.OutputTerminal);
}
}
}
context.VsLineScanState.TerminalIndex = this.MultilineIndex;
context.VsLineScanState.TokenSubType = level;
return null;
}
开发者ID:peterdocter,项目名称:BabeLua,代码行数:32,代码来源:LuaLongStringTerminal.cs
注:本文中的Irony.Parsing.ParsingContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论