Exemplo n.º 1
0
        public override void EnterEveryRule([ValidatedNotNull] ParserRuleContext context)
        {
            context.ValidateNotNull(nameof(context));
            string typeName = context.GetType( ).Name;

            Push(new XElement(typeName.Substring(0, typeName.Length - ContextTypeNameSuffix.Length)));
        }
Exemplo n.º 2
0
        public IExpressionBinding BuildTree(Declaration module, Declaration parent, ParserRuleContext expression, IBoundExpression withBlockVariable, StatementResolutionContext statementContext)
        {
            dynamic dynamicExpression = expression;
            var     type = expression.GetType();

            return(Visit(module, parent, dynamicExpression, withBlockVariable, statementContext));
        }
Exemplo n.º 3
0
        public VBBaseCodeModel CreateCodeModel(ParserRuleContext context)
        {
            try
            {
                // Create code model based on context name
                // e.g: DeclareStmtContext will create VBDeclareStmt class
                var contextClassName   = context.GetType().Name;
                var codeModelClassName = "VB" + contextClassName.Replace("Context", string.Empty);

                var cxt  = new VB6CodeModelFactoryContext(_rootModule, _parentCodeBlock, context, _parentCodeBlock.Scope);
                var args = new object[] { cxt };
                var t    = Type.GetType($"VB6ActiveXDllConverter.CodeModels.{codeModelClassName}", true);
                var obj  = (VBBaseCodeModel)t.Assembly.CreateInstance($"VB6ActiveXDllConverter.CodeModels.{codeModelClassName}", true, BindingFlags.Instance | BindingFlags.NonPublic, null, args, null, null);

                obj.BeforeVisitChild();
                _parentCodeBlock.AddCodeModel(obj);
                obj.VisitChild();
                obj.AfterVisitChild();

                return(obj);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 4
0
            public void EnterEveryRule(ParserRuleContext ctx)
            {
                var node = new ParserNode {
                    Type = ctx.GetType().ToString(), Parent = stack.Peek(), LocationParserRule = ctx
                };

                node.AddAttr("Text", input, ctx);
                stack.Push(node);
            }
Exemplo n.º 5
0
        private void DefaultExit(ParserRuleContext context)
        {
            string contextName = context.GetType().Name;
            string tag         = contextName.Substring(0, contextName.IndexOf("Context"));

            Space(depth);
            output.WriteLine($"</{tag}>");
            depth -= 2;
        }
Exemplo n.º 6
0
        public override void EnterEveryRule([NotNull] ParserRuleContext context)
        {
            var name = context.GetType().Name;

            if (name.EndsWith("Context", StringComparison.InvariantCultureIgnoreCase))
            {
                name = name.Remove(name.IndexOf("Context", StringComparison.InvariantCultureIgnoreCase));
            }
            Logger.Info(string.Format("ENTER:{0}{1}", new string('\t', context.Depth()), name));
        }
Exemplo n.º 7
0
        public override void ExitEveryRule([NotNull] ParserRuleContext context)
        {
            var name = context.GetType().Name;

            if (name.EndsWith("Context", StringComparison.InvariantCultureIgnoreCase))
            {
                name = name.Remove(name.IndexOf("Context", StringComparison.InvariantCultureIgnoreCase));
            }
            Logger.Info(string.Format("EXIT :{0:#####}{1}{2}: {3}", context.start.Line, new string('\t', context.Depth()), name, context.GetText()));
        }
            public BoxRuleContext(ParserRuleContext node)
            {
                this._node = node;
                this.Text  = this._node.GetText();
                this.Start = this._node.Start;
                this.Stop  = this._node.Stop;

                var n = node.GetType().Name;

                this.Type = n.Substring(0, n.Length - "Context".Length);
            }
Exemplo n.º 9
0
        public override void EnterEveryRule(ParserRuleContext context)
        {
            string typeName = context.GetType( ).Name;

            Push(new Node( )
            {
                Id       = context.GetUniqueNodeId( ),
                Label    = typeName.Substring(0, typeName.Length - ContextTypeNameSuffix.Length),
                Category = "TreeNode"
            });
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a node when a rule is visited
        /// </summary>
        /// <param name="context"></param>
        public override void EnterEveryRule([NotNull] ParserRuleContext context)
        {
            base.EnterEveryRule(context);
            //create metadata to save some information of context
            TreeViewerNodeMeta node = new TreeViewerNodeMeta();

            node.StartIndex = context.Start.StartIndex;
            node.StopIndex  = context.Stop.StopIndex;

            //current node is parent of context, add context to child list of current node
            if (_currentNode.Text == context.Parent?.GetType().Name)
            {
                _currentNode.Nodes.Add(context.GetType().Name);
                _currentNode     = _currentNode.Nodes[_currentNode.Nodes.Count - 1];
                _currentNode.Tag = node;
            }
            else
            {
                //current node is root node
                if (_currentNode.Parent == null)
                {
                    _currentNode.Nodes.Add(context.GetType().Name);
                    _currentNode     = _currentNode.Nodes[_currentNode.Nodes.Count - 1];
                    _currentNode.Tag = node;
                }
                else
                {
                    //current node and context node is same lever
                    _currentNode.Parent.Nodes.Add(context.GetType().Name);
                    _currentNode     = _currentNode.Parent.Nodes[_currentNode.Parent.Nodes.Count - 1];
                    _currentNode.Tag = node;
                }
            }
            //context is leaf node
            if (context.ChildCount == 1 && context.GetChild(0).ChildCount <= 0)
            {
                node.Token = context.GetText();
                _currentNode.Nodes.Add(context.GetText());
                _currentNode.Nodes[0].Tag = node;
            }
        }
Exemplo n.º 11
0
        public void Remove(ParserRuleContext target)
        {
            var info = Finders.TryGetValue(target.GetType(), out var finder)
                ? finder.GetRewriterInfo(target)
                : new DefaultRewriterInfoFinder().GetRewriterInfo(target);

            if (info.Equals(RewriterInfo.RewriterInfo.None))
            {
                return;
            }
            _rewriter.Delete(info.StartTokenIndex, info.StopTokenIndex);
        }
Exemplo n.º 12
0
 static void PrintContext(ParserRuleContext context)
 {
     if (context == null)
     {
         return;
     }
     Log.Write($"{new string(' ', (context.Depth() - 1) * 4)}{context.GetType().Name} [{context.start.Line}, {context.start.Column}] {context.GetText()}");
     foreach (var child in context.children)
     {
         PrintContext(child as ParserRuleContext);
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Return first ancestor node up the chain towards the root that is clazz.
 ///  Search includes the current node.
 /// </summary>
 public static ParserRuleContext getFirstAncestorOfType(ParserRuleContext t, Type clazz)
 {
     while (t != null)
     {
         if (t.GetType() == clazz)
         {
             return(t);
         }
         t = (ParserRuleContext)t.Parent;
     }
     return(null);
 }
Exemplo n.º 14
0
 public static void Context(ParserRuleContext ctx, LogEventLevel level = LogEventLevel.Debug)
 {
     Log.Write(
         level,
         "[{Depth}:{ContextType}] [{SourceInterval}] | children: {ChildrenCount} | {Code}",
         ctx.Depth(),
         ctx.GetType().Name,
         ctx.SourceInterval,
         ctx.ChildCount,
         ctx.GetText()
         );
 }
Exemplo n.º 15
0
        /// <summary>
        /// Return first ancestor node up the chain towards the root that is clazz.
        ///  Search includes the current node.
        /// </summary>
        public static ParserRuleContext getFirstAncestorOfType(ParserRuleContext t, IType clazz)
        {
            while (t != null)
            {
#pragma warning disable CS0253 // Possible unintended reference comparison; right hand side needs cast
                if (t.GetType() == clazz)
#pragma warning restore CS0253 // Possible unintended reference comparison; right hand side needs cast
                {
                    return(t);
                }
                t = (ParserRuleContext)t.Parent;
            }
            return(null);
        }
Exemplo n.º 16
0
        public override void EnterEveryRule([NotNull] ParserRuleContext context)
        {
            //
            string fullName = context.GetType().ToString();
            int    from     = fullName.LastIndexOf('+');
            string name     = fullName.Substring(from + 1, fullName.Length - from - 1).Replace("Context", "");
            //Console.WriteLine(name);

            var node = new TreeNode();

            node.TypeNode = name;

            Nodes.Put(context, node);
            //
        }
Exemplo n.º 17
0
 public BaseRule(Interval ruleInterval, ParserRuleContext context, string text)
 {
     _sourceInterval = ruleInterval;
     _context        = context;
     _text           = text;
     _divideSym      = " ";
     if (context != null)
     {
         _ruleType = context.GetType().ToString().ToLower().Replace("context", "").Replace("mysqlparser+", "");
     }
     else
     {
         _ruleType = "terminal";
     }
 }
Exemplo n.º 18
0
        public Variable GetVariable(string name, ParserRuleContext ctx)
        {
            if (ctx.GetType().IsAssignableFrom(StatementContextType) &&
                _environmentsByContext.TryGetValue(ctx, out var env))
            {
                return(env.GetVariable(name));
            }

            var statementAncestor = ctx.FindParentOfType <QuestScriptParser.StatementContext>();

            if (statementAncestor != null &&
                _environmentsByContext.TryGetValue(statementAncestor, out var statementEnvironment))
            {
                return(statementEnvironment.GetVariable(name));
            }

            return(null);
        }
Exemplo n.º 19
0
        public void RaiseAction(ParserRuleContext context, List <ErrorInformation> errorInformationList)
        {
            PropertyInfo pro  = this.GetType().GetProperty(context.GetType().Name);
            dynamic      data = pro.GetValue(this);

            foreach (var x in data)
            {
                try
                {
                    var action = x.Value;
                    ErrorInformation error;
                    action(context, out error);
                    if (error != null && errorInformationList != null)
                    {
                        errorInformationList.Add(error);
                    }
                }catch (Exception ex)
                {
                }
            }
        }
Exemplo n.º 20
0
 /// <inheritdoc/>
 public virtual void ExitEveryRule(ParserRuleContext ctx)
 {
     ctx.ValidateNotNull(nameof(ctx));
     Trace.TraceInformation($"exit[{ctx.SourceInterval}] {Parser.RuleNames[ ctx.RuleIndex ]} [{ctx.GetType( ).Name}] Lt(1)='{( ( ITokenStream )Parser.InputStream ).Lt( 1 ).Text}'");
 }
Exemplo n.º 21
0
 public void ExitEveryRule([NotNull] ParserRuleContext ctx)
 {
     UnindentOuput($"}} {ctx.GetType().Name} @{ctx.Stop?.Line}:{ctx.Stop?.Column}");
 }
Exemplo n.º 22
0
 public void EnterEveryRule([NotNull] ParserRuleContext ctx)
 {
     IndentOuput($"{{ {ctx.GetType().Name}: @{ctx.Start?.Line}:{ctx.Start?.Column} ");
 }
Exemplo n.º 23
0
        private bool _foundTerminal;                    // A terminal was found and printed to console.

        public void EnterEveryRule([NotNull] ParserRuleContext ctx)
        {
            if (_isPreviousTerminal)
            {
                Console.Write("\b\"" + "\n"); // \b backs up one char
                _isPreviousTerminal = false;
            }

            Console.WriteLine(new string(' ', ++_currentIndentation * INDENTATION_WS_COUNT) + ctx.GetType().Name.Replace("Context", string.Empty));

            _foundTerminal = false;
        }
Exemplo n.º 24
0
        public void EnterEveryRule([NotNull] ParserRuleContext context)
        {
            T dummy = new T();

            sb.AppendLine($"I'm a {dummy.RuleNames[context.RuleIndex]} ({context.GetType().Name}) and I'm running from {context.Start.StartIndex} to {context.Stop.StopIndex}");
        }
Exemplo n.º 25
0
 private IEnumerable <GraphqlParseException> FindExceptions(ParserRuleContext context)
 {
     if (context.exception != null)
     {
         yield return(new GraphqlParseException($"Unable to parse, could not match {context.GetType().Name} at {context.Start.Line}:{context.Start.Column}", context.Location(), context.exception));
     }
     if (context.children != null)
     {
         foreach (var child in context.children.OfType <ParserRuleContext>())
         {
             foreach (var ex in FindExceptions(child))
             {
                 yield return(ex);
             }
         }
     }
 }
Exemplo n.º 26
0
 private static ExpressionSyntax visitNode(ParserRuleContext node)
 {
     var typename = node.GetType().Name;
     return _handlers[typename](node);
 }
Exemplo n.º 27
0
        private static ExpressionSyntax visitNode(ParserRuleContext node)
        {
            var typename = node.GetType().Name;

            return(_handlers[typename](node));
        }
 /// <inheritdoc/>
 public virtual void EnterEveryRule(ParserRuleContext ctx)
 {
     Trace.TraceInformation($"enter[{ctx.SourceInterval}] {Parser.RuleNames[ ctx.RuleIndex ]} [{ctx.GetType( ).Name}] Lt(1)='{( ( ITokenStream )Parser.InputStream ).Lt( 1 ).Text}'");
 }
Exemplo n.º 29
0
 public static bool IsScopeRule(ParserRuleContext context)
 {
     return(scopeRules.Contains(context.GetType()));
 }
Exemplo n.º 30
0
 public static void Log(this ParserRuleContext ctx)
 {
     Console.WriteLine(">>>[{0},{1}][{2}] ChildCount : {3}, Text : {4}",
                       ctx.Start.Line, ctx.Start.Column, ctx.GetType().Name, ctx.ChildCount, ctx.GetText());
 }
        private Declaration ResolveInternal(ParserRuleContext callSiteContext, Declaration localScope, ContextAccessorType accessorType = ContextAccessorType.GetValueOrReference, VBAParser.DictionaryCallStmtContext fieldCall = null, bool hasExplicitLetStatement = false, bool isAssignmentTarget = false)
        {
            if (callSiteContext == null || _alreadyResolved.Contains(callSiteContext))
            {
                return(null);
            }

            if (!IdentifierContexts.Contains(callSiteContext.GetType()))
            {
                throw new ArgumentException("'" + callSiteContext.GetType().Name + "' is not an identifier context.", "callSiteContext");
            }

            if (localScope == null)
            {
                localScope = _currentScope;
            }

            var         parentContext  = callSiteContext.Parent;
            var         identifierName = callSiteContext.GetText();
            Declaration callee         = null;

            if (localScope.DeclarationType == DeclarationType.Variable)
            {
                // localScope is probably a UDT
                var udt = ResolveType(localScope);
                if (udt != null && udt.DeclarationType == DeclarationType.UserDefinedType)
                {
                    callee = _declarations[identifierName].SingleOrDefault(item => item.Context != null && item.Context.Parent == udt.Context);
                }
            }
            else
            {
                callee = FindLocalScopeDeclaration(identifierName, localScope, parentContext, isAssignmentTarget)
                         ?? FindModuleScopeProcedure(identifierName, localScope, accessorType, isAssignmentTarget)
                         ?? FindModuleScopeDeclaration(identifierName, localScope)
                         ?? FindProjectScopeDeclaration(identifierName);
            }

            if (callee == null)
            {
                // calls inside With block can still refer to identifiers in _currentScope
                localScope     = _currentScope;
                identifierName = callSiteContext.GetText();
                callee         = FindLocalScopeDeclaration(identifierName, localScope, parentContext, isAssignmentTarget)
                                 ?? FindModuleScopeProcedure(identifierName, localScope, accessorType, isAssignmentTarget)
                                 ?? FindModuleScopeDeclaration(identifierName, localScope)
                                 ?? FindProjectScopeDeclaration(identifierName);
            }

            if (callee == null)
            {
                return(null);
            }

            var reference = CreateReference(callSiteContext, callee, isAssignmentTarget, hasExplicitLetStatement);

            callee.AddReference(reference);
            _alreadyResolved.Add(reference.Context);
            _alreadyResolved.Add(callSiteContext);

            if (fieldCall != null)
            {
                return(ResolveInternal(fieldCall, callee));
            }

            return(callee);
        }