public void VisitTerminal(ITerminalNode node) { foreach (var listener in _listeners) { listener.VisitTerminal(node); } }
public static string AsNotQuoted(ITerminalNode node) { if (node == null) return null; return AsNotQuoted(node.GetText()); }
public static int? PositiveInteger(ITerminalNode node) { if (node == null) return null; var text = node.GetText(); int value; if (!Int32.TryParse(text, out value)) throw new ParseCanceledException(String.Format("Numeric '{0}' is not an integer.", text)); if (value < 0) throw new ParseCanceledException(String.Format("Integer '{0}' is not positive.", text)); return value; }
private RelationalOperator GetRelationalOperator(ITerminalNode node) { switch (node.Symbol.Text) { case ">=": return(RelationalOperator.GEQ); case "<=": return(RelationalOperator.LEQ); case ">": return(RelationalOperator.GT); case "<": return(RelationalOperator.LT); case "=": return(RelationalOperator.EQUAL); case "!": return(RelationalOperator.NOT_EQUAL); } return(default(RelationalOperator)); }
public static Token GetFirstToken(IParseTree node) { if (node != null) { ITerminalNode terminalNode = GetFirstTerminalNode(node); if (terminalNode != null) { return(GetTokenFromTerminalNode(terminalNode)); } else { return(null); } } else { return(null); } }
public void VisitTerminal(ITerminalNode node) { string value = node.GetText(); { System.Console.WriteLine( indent() + "{"); System.Console.WriteLine( indent() + "\"Text\":" + "\"" + node.GetText() + "\"" ); System.Console.WriteLine( indent() + "}"); } }
public static List <string> GetCleanedTexts([NotNull] this ITerminalNode _id, List <string> _names = null) { if (_names == null) { _names = new List <string>(); } if (_id != null) { var i = _id.GetText().CleanName(); if (i != null) { _names.Add(i); } } return(_names); }
public override Node VisitTypeDecls([NotNull] TigerParser.TypeDeclsContext context) { var node = new TypeDeclListNode(context); for (int i = 0; i < context.type().Length; i++) { ITerminalNode id = context.ID(i); TigerParser.TypeContext type = context.type(i); var decl = new TypeDeclNode(id.Symbol.Line, id.Symbol.Column); decl.Children.Add( new IdNode(id.Symbol.Line, id.Symbol.Column, id.GetText())); decl.Children.Add( Visit(type)); node.Children.Add(decl); } return(node); }
public string ToCompareStringExp(ITerminalNode property, ITerminalNode op, ITerminalNode escapedString) { var propertyString = property.ToString(); var valueParam = CreateSqlParameter(escapedString); if (SqlSchemaColumns.Contains(propertyString)) { return($"({property.ToString()} {op} @{valueParam})"); } else { queryContainsProperty = true; throw new NotImplementedException(); // TODO: SqlParameter, Different Operators var propParam = CreateSqlParameter(property); return($"(X.exist('//*[@key=\"@{propParam}\" and contains(.,\"@{valueParam}\")]') = 1)"); } }
public ISessionFactory Compile(IEnumerable <IRuleDefinition> ruleDefinitions) { var rules = new List <ICompiledRule>(); var reteBuilder = new ReteBuilder(); foreach (var ruleDefinition in ruleDefinitions) { var context = new ReteBuilderContext(); ITerminalNode terminalNode = reteBuilder.AddRule(context, ruleDefinition); ICompiledRule compiledRule = CompileRule(context, ruleDefinition); BuildRuleNode(compiledRule, terminalNode); rules.Add(compiledRule); } INetwork network = reteBuilder.GetNetwork(); var factory = new SessionFactory(network); return(factory); }
private static FlowNode ParseFor(RuleContext rule) { //FOR type IDENTIFIER FOR_LOOP_SEPERATOR expression INDENT statements DEDENT ITerminalNode forNode = (ITerminalNode)rule.GetChild(0); CrawlParser.TypeContext typeNode = (CrawlParser.TypeContext)rule.GetChild(1); ITerminalNode identifierNode = (ITerminalNode)rule.GetChild(2); ITerminalNode serperatorNode = (ITerminalNode)rule.GetChild(3); RuleContext expression = (RuleContext)rule.GetChild(4); ITerminalNode indent = (ITerminalNode)rule.GetChild(5); RuleContext blockCtx = (RuleContext)rule.GetChild(6); ITerminalNode dedent = (ITerminalNode)rule.GetChild(7); TypeNode type = ParseType(typeNode); ExpressionNode iteratior = ExpressionParser.ParseExpression(expression); BlockNode block = ParseBlockNode(blockCtx); return(CrawlSyntaxNode.ForLoop(rule.SourceInterval, null, type, ParseIdentifier(identifierNode), iteratior, block)); }
public object VisitTerminal(ITerminalNode node, Dictionary<object, List<object>> treeAnnotations) { IToken token = node.Symbol; if (token != null) { List<object> annotList = null; if (this.tokenAnnotations.TryGetValue(token.Type, out annotList)) { List<object> treeAnnotList = null; if (!treeAnnotations.TryGetValue(node, out treeAnnotList)) { treeAnnotList = new List<object>(); treeAnnotations.Add(node, treeAnnotList); } treeAnnotList.AddRange(annotList); } } return null; }
private static List <ExpressionNode> ParseExpressionList(RuleContext expList) { List <ExpressionNode> n = new List <ExpressionNode>(expList.ChildCount / 2); for (int i = 0; i < expList.ChildCount; i += 2) { n.Add(ParseExpression((RuleContext)expList.GetChild(i))); if (i + 1 != expList.ChildCount) { ITerminalNode itemsep = (ITerminalNode)expList.GetChild(i + 1); if (itemsep.Symbol.Type != CrawlLexer.ITEM_SEPARATOR) { throw new NotImplementedException("Strange stuff in expression list"); } } } return(n); }
private bool TryParseIntLiteral(ITerminalNode node, out int value) { bool succeeded; if (node.Symbol.Text.StartsWith("0x")) { succeeded = int.TryParse(node.Symbol.Text.Substring(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value); } else { succeeded = int.TryParse(node.Symbol.Text, out value); } if (!succeeded) { LogError(node.Symbol, "Invalid integer format"); } return(succeeded); }
public LiteralExpression(LuaParser.StringContext context, ScriptLoadingContext lcontext) : base(context, lcontext) { ITerminalNode charStr = context.CHARSTRING(); ITerminalNode longStr = context.LONGSTRING(); ITerminalNode normStr = context.NORMALSTRING(); if (charStr != null) { m_Value = DynValue.NewString(NormalizeNormStr(charStr.GetText())).AsReadOnly(); } else if (longStr != null) { m_Value = DynValue.NewString(NormalizeLongStr(longStr.GetText())).AsReadOnly(); } else if (normStr != null) { m_Value = DynValue.NewString(NormalizeNormStr(normStr.GetText())).AsReadOnly(); } }
private static string GetName(PhpParser.FunctionDefinitionContext context) { Contract.Requires(context != null); ITerminalNode nameNode = context.PHP_IDENTIFIER(); if (nameNode == null) { return("?"); } string name = nameNode.Symbol.Text; if (string.IsNullOrEmpty(name)) { return("?"); } return(name); }
public override void VisitTerminal(ITerminalNode node) { string nodeName = KaleidoscopeLexer.DefaultVocabulary.GetDisplayName(node.Symbol.Type); Graph.Nodes.Add(new Node( ) { Id = node.GetUniqueNodeId( ), Label = nodeName, Category = "Terminal" }); if (node.Parent != null) { Graph.Links.Add(new Link( ) { Source = node.Parent.GetUniqueNodeId( ), Target = node.GetUniqueNodeId( ) }); } }
private static string GetName([NotNull] PhpParser.FunctionParameterContext context) { Debug.Assert(context != null); ITerminalNode nameNode = context.PHP_IDENTIFIER(); if (nameNode == null) { return("?"); } string name = nameNode.Symbol.Text; if (string.IsNullOrEmpty(name)) { return("?"); } return(name); }
/// <returns><see cref="Token"/></returns> public override UstNode VisitTerminal(ITerminalNode node) { string text = node.GetText(); TextSpan textSpan = node.GetTextSpan(); Token result; double doubleResult; if (text.StartsWith("'")) { result = new StringLiteral(text.Substring(1, text.Length - 2), textSpan, FileNode); } else if (text.ToLowerInvariant().StartsWith("n'")) { result = new StringLiteral(text.Substring(2, text.Length - 3), textSpan, FileNode); } else if (text.All(c => char.IsDigit(c))) { result = new IntLiteral(long.Parse(text), textSpan, FileNode); } else if (double.TryParse(text, out doubleResult)) { result = new FloatLiteral(doubleResult, textSpan, FileNode); } else if (text.All(c => char.IsLetterOrDigit(c) || c == '_')) { result = new IdToken(text, textSpan, FileNode); } else { if (text.Any(c => char.IsLetterOrDigit(c) || c == '_')) { Logger.LogDebug($"{text} converter to IdToken"); result = new IdToken(text, textSpan, FileNode); } else { result = null; } } return(result); }
public override int VisitTerminal(ITerminalNode node) { ASTComposite m_parent = m_parents.Peek(); switch (node.Symbol.Type) { case MINICLexer.NUMBER: CASTNUMBER newnode1 = new CASTNUMBER(node.Symbol.Text, m_parents.Peek()); m_parent.AddChild(newnode1, m_parentContext.Peek()); break; case MINICLexer.IDENTIFIER: CASTIDENTIFIER newnode2 = new CASTIDENTIFIER(node.Symbol.Text, m_parents.Peek()); m_parent.AddChild(newnode2, m_parentContext.Peek()); break; default: break; } return(base.VisitTerminal(node)); }
public static int?PositiveInteger(ITerminalNode node) { if (node == null) { return(null); } var text = node.GetText(); int value; if (!Int32.TryParse(text, out value)) { throw new ParseCanceledException(String.Format("Numeric '{0}' is not an integer.", text)); } if (value < 0) { throw new ParseCanceledException(String.Format("Integer '{0}' is not positive.", text)); } return(value); }
public override object VisitTerminal(ITerminalNode node) { string s = ""; int i = 0; switch (node.Symbol.Type) { case CalculatorParser.Number: { s = node.GetText(); if (s.Contains(".")) { float f = float.Parse(s); return(f); } else { i = int.Parse(s); return(i); } } case CalculatorParser.True: return(true); case CalculatorParser.False: return(false); case CalculatorParser.Id: return(node.GetText()); case CalculatorParser.String: s = node.GetText(); s = s.Substring(1, s.Length - 2); return(s); case CalculatorParser.Null: return(null); } return(base.VisitTerminal(node)); }
//Обработка токена целого числа public Node GetIntConst(ITerminalNode terminal) { if (terminal == null || terminal.Symbol == null) { return(MakeConstNode(null, 0)); } int res; if (!int.TryParse(terminal.Symbol.Text, out res)) { AddError("Недопустимое целое число", terminal); } if (res == 1) { return(MakeConstNode(terminal, true)); } if (res == 0) { return(MakeConstNode(terminal, false)); } return(MakeConstNode(terminal, res)); }
private static ExpressionNode ParseUnary(RuleContext rule) { //( INVERT | MINUS )* postfix_expression RuleContext targetContext = (RuleContext)rule.LastChild(); List <ExpressionType> unaries = new List <ExpressionType>(); for (int i = rule.ChildCount - 2; i >= 0; i--) { ITerminalNode symbol = (ITerminalNode)rule.GetChild(i); unaries.Add(ParseUnaryOp(symbol)); } ExpressionNode result = ParseExpression(targetContext); foreach (ExpressionType unaryExpressionType in unaries) { result = CrawlSyntaxNode.UnaryExpression(rule.SourceInterval, unaryExpressionType, CrawlType.UnspecifiedType, result); } return(result); }
public override object VisitTerminal(ITerminalNode terminalNode) { var token = terminalNode.Symbol; if (token.Type > 0) { var maxDepth = _lastDepth + 1; _lastDepth = terminalNode.Parent.RuleContext.Depth(); for (int i = _lastDepth + 1; i < maxDepth; i++) { _nodes.Pop(); } var count = token.TokenIndex; var tokenName = DetermineElementName(token, Code2XmlConstants.TokenSetElementName); var newNode = CreateTerminalNode( tokenName, token, token.Text, count, token.Type.ToString()); _nodes.Peek().AddLast(newNode); _nextTokenIndex = count + 1; } return(base.VisitTerminal(terminalNode)); }
private static DeclerationNode ParseVariableDecleration(RuleContext classPart, ProtectionLevel protectionLevel, Interval interval) { //This is the whole variable decleration. First the type, then individual variables of that type, with an optional initialization value //Each individual identifier is parsed in ParseSingleVariable ITerminalNode eos = classPart.LastChild() as ITerminalNode; if (eos == null || eos.Symbol.Type != CrawlLexer.END_OF_STATEMENT) { throw new NotImplementedException("Something strange happened"); } TypeNode type = ParseType((CrawlParser.TypeContext)classPart.GetChild(0)); return(CrawlSyntaxNode.VariableDecleration( interval, protectionLevel, type, classPart .AsEdgeTrimmedIEnumerable() .OfType <CrawlParser.Variable_declContext>() .Select(ParseSingleVariable))); }
public override Tree VisitPrimary(PrimaryContext primary) { var expressionContext = primary.parenthesized; if (expressionContext != null) { return((Expression)VisitExpression(expressionContext)); } LiteralContext literal = primary.literal(); if (literal != null) { return((Expression)VisitLiteral(literal)); } ITerminalNode identifier = primary.Identifier(); if (identifier != null) { return(makeIdentifier(identifier)); } return(new This(primary.start.Line, primary.start.Column, primary.stop.Line, primary.stop.Column)); }
private int CreateSqlParameter(ITerminalNode item, SqlDbType type = SqlDbType.VarChar) { var propertyCounter = Command.Parameters.Count; var p = new SqlParameter($"@{propertyCounter}", type); if (type == SqlDbType.VarChar) { var trimmedString = item.ToString().Trim('"'); p.Value = trimmedString; p.Size = trimmedString.Length; } else { //Assert Int p.Value = int.Parse(item.ToString()); } Command.Parameters.Add(p); return(propertyCounter); }
public SignalTypeNode(TablikKeeper keeper, ITerminalNode terminal) : base(keeper, terminal) { var signalCode = Token.Text.Substring(1, Token.Text.Length - 2); foreach (var con in Keeper.Module.LinkedSources) { if (con.ObjectsTypes.ContainsKey(signalCode)) { Type = con.ObjectsTypes[signalCode]; } else if (con.BaseObjectsTypes.ContainsKey(signalCode)) { Type = con.BaseObjectsTypes[signalCode]; } } if (Type == null) { AddError("Не найден тип объекта или сигнала"); Type = new SimpleType(); } }
private object UnaryOperation(CalculatorParser.ExpressionContext e, ITerminalNode op) { var n = e.Accept(this); //var varName = ""; //object varValue = null; switch (op.Symbol.Type) { case CalculatorParser.Not: return(!(bool)n); case CalculatorParser.Minus: if (n is int) { return(-(int)n); } else { return(-(float)n); } } return(n); }
private static SingleVariableDeclerationNode ParseSingleVariable(CrawlParser.Variable_declContext variable) { ITerminalNode identifier = (ITerminalNode)variable.GetChild(0); if (identifier.Symbol.Type != CrawlLexer.IDENTIFIER) { throw new NotImplementedException(); } //unitialized if (variable.ChildCount == 1) { return(CrawlSyntaxNode.SingleVariableDecleration(variable.SourceInterval, ParseVariable(identifier))); } //initialized else if (variable.ChildCount == 3) { return(CrawlSyntaxNode.SingleVariableDecleration(variable.SourceInterval, ParseVariable(identifier), ExpressionParser.ParseExpression((RuleContext)variable.GetChild(2)))); } throw new NotImplementedException("Variable declared in strange way"); }
public override object VisitTerminal(ITerminalNode node) { var resharperTokenType = skipWhitespaces(); if (resharperTokenType == null) { return(null); } IToken antlrToken = node.Symbol; if (antlrToken.Type == SpringTokenType.Identifier.Index) { var mark = Builder.Mark(); var tokenNodeType = Builder.AdvanceLexer(); Builder.Done(mark, SpringCompositeNodeWithArgumentType.VAR_REFERENCE, node); } else { var tokenNodeType = Builder.AdvanceLexer(); } return(null); }
//Обработка токена целого числа public NodeConst CheckInt(ITerminalNode terminal) { if (terminal == null || terminal.Symbol == null) { return(new NodeConst(null, 0)); } var token = terminal.Symbol; int res; if (!int.TryParse(token.Text, out res)) { AddError("Недопустимое целое число", token); } if (res == 1) { return(new NodeConst(token, true)); } if (res == 0) { return(new NodeConst(token, false)); } return(new NodeConst(token, res)); }
/// <summary> /// Consume and return the /// <linkplain> /// #getCurrentToken /// current symbol /// </linkplain> /// . /// <p>E.g., given the following input with /// <c>A</c> /// being the current /// lookahead symbol, this function moves the cursor to /// <c>B</c> /// and returns /// <c>A</c> /// .</p> /// <pre> /// A B /// ^ /// </pre> /// If the parser is not in error recovery mode, the consumed symbol is added /// to the parse tree using /// <see cref="ParserRuleContext.AddChild(IToken)"/> /// , and /// <see cref="Antlr4.Runtime.Tree.IParseTreeListener.VisitTerminal(Antlr4.Runtime.Tree.ITerminalNode)"/> /// is called on any parse listeners. /// If the parser <em>is</em> in error recovery mode, the consumed symbol is /// added to the parse tree using /// <see cref="ParserRuleContext.AddErrorNode(IToken)"/> /// , and /// <see cref="Antlr4.Runtime.Tree.IParseTreeListener.VisitErrorNode(Antlr4.Runtime.Tree.IErrorNode)"/> /// is called on any parse /// listeners. /// </summary> public virtual IToken Consume() { IToken o = CurrentToken; if (o.Type != Eof) { ((ITokenStream)InputStream).Consume(); } bool hasListener = _parseListeners != null && _parseListeners.Count != 0; if (_buildParseTrees || hasListener) { if (_errHandler.InErrorRecoveryMode(this)) { IErrorNode node = _ctx.AddErrorNode(o); if (_parseListeners != null) { foreach (IParseTreeListener listener in _parseListeners) { listener.VisitErrorNode(node); } } } else { ITerminalNode node = _ctx.AddChild(o); if (_parseListeners != null) { foreach (IParseTreeListener listener in _parseListeners) { listener.VisitTerminal(node); } } } } return(o); }
public static void TryGetUserDefinedWord(ITerminalNode node, ref string property) { if (node != null && property == null) property = node.GetText(); }
public void VisitTerminal(ITerminalNode node) { checksum.Update(VISIT_TERMINAL); updateChecksum(checksum, node.Symbol); }
private void AddNavigationTarget(IParseTree tree, ITerminalNode identifier, IEditorNavigationType navigationType, ImageSource glyph) { Contract.Requires(tree != null); Contract.Requires(navigationType != null); Interval sourceInterval = tree.SourceInterval; if (sourceInterval.a < 0 || sourceInterval.b < 0 || sourceInterval.Length <= 0) return; IToken startToken = _tokens[sourceInterval.a]; IToken stopToken = _tokens[sourceInterval.b]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); Span seek; string name = identifier != null ? identifier.GetText() : null; if (string.IsNullOrEmpty(name)) { seek = new Span(span.Start, 0); name = "?"; } else { seek = new Span(identifier.Symbol.StartIndex, 0); } if (_mode.Count > 0) { name = _mode.Peek() + "." + name; } _navigationTargets.Add(new EditorNavigationTarget(name, navigationType, new SnapshotSpan(_snapshot, span), new SnapshotSpan(_snapshot, seek), glyph)); }
public void AddAttr(string type, ITerminalNode token) { int start, end; token.GetBounds(out start, out end); AddAttrNode(type, null, start, end); }
public void AddAttr(string type, string input, ITerminalNode token) => AddAttr(type, input, token.Symbol);
private static bool IsSameTerminalNode(ITerminalNode terminalParameterNode, ITerminalNode terminalCompareNode) { return terminalParameterNode.Capture == terminalCompareNode.Capture; }
public static Token GetTokenFromTerminalNode(ITerminalNode terminalNode) { var ce = terminalNode.Symbol as CodeElements.CodeElement; if (ce != null) { if (ce.ConsumedTokens.Count < 1) return null; return ce.ConsumedTokens[0]; } return (Token)terminalNode.Symbol; }
private string parseStringLiteral(ITerminalNode node) { return node.GetText().Trim('"'); }
public static SyntaxToken CreateToken(ITerminalNode node, SyntaxTokenClassification classification, SyntaxNode parent) { return CreateToken(node.Symbol, classification, parent); }
public void Visit(ITerminalNode node) { VisitLog.Add(node.ToString()); }
internal AlphanumericValue CreateAlphanumericValue(ITerminalNode node) { var token = ParseTreeUtils.GetFirstToken(node); if (token == null) return null; // [COBOL 2002] if (token.TokenType == TokenType.DATE) token.TokenType = TokenType.UserDefinedWord; // [/COBOL 2002] return new AlphanumericValue(token); }
private SyntaxProperty<DataUsage> CreateDataUsageProperty(DataUsage usage, ITerminalNode node) { if (node == null) return null; return new SyntaxProperty<DataUsage>(usage, ParseTreeUtils.GetFirstToken(node)); }
public override void VisitTerminal(ITerminalNode node) { base.VisitTerminal(node); Console.WriteLine("term: " + node.ToString()); }