Beispiel #1
0
        public void Visit <Result>(IParseTreeVisitor <Result> visitor)
        {
            if (visitor is IFile f)
            {
                f.Filename = this.File;
            }

            if (System.Diagnostics.Debugger.IsAttached)
            {
                System.Diagnostics.Trace.WriteLine(this.File);
            }

            var context = this._context;

            visitor.Visit(context);
        }
Beispiel #2
0
        private static INode Visit(IParseTreeVisitor <INode> visitor, bool hasTerminal, ITerminalNode terminal, Func <List <INode>, INode> fun, string errMess = "Ошибка разбора выражения", params IParseTree[] children)
        {
            try
            {
                if (hasTerminal && terminal == null)
                {
                    return(new NodeError());
                }

                var subParse = new List <INode>();
                foreach (var node in children)
                {
                    if (node == null)
                    {
                        if (terminal == null)
                        {
                            return(new NodeError());
                        }
                        return(new NodeError(terminal, errMess));
                    }
                    if (!(node is ITerminalNode))
                    {
                        var res = visitor.Visit(node);
                        subParse.Add(res);
                        if (res == null)
                        {
                            if (terminal == null)
                            {
                                return(new NodeError());
                            }
                            return(new NodeError(terminal, errMess));
                        }
                        if (res is NodeError)
                        {
                            if (terminal == null || res.Token != null || ((NodeError)res).ErrMess != null)
                            {
                                return(res);
                            }
                            return(new NodeError(terminal, errMess));
                        }
                    }
                }
                return(fun(subParse));
            }
            catch { return(new NodeError()); }
        }
        public void VisitWith <TResult>(ICharStream input, IParseTreeVisitor <TResult> parseTreeVisitor,
                                        IEnumerable <IAntlrErrorListener <int> > lexerErrorListeners,
                                        IEnumerable <IAntlrErrorListener <IToken> > errorListeners)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (parseTreeVisitor == null)
            {
                throw new ArgumentNullException("parseTreeVisitor");
            }

            var tree = base.CreateTree(input, lexerErrorListeners, errorListeners);

            if (tree != null)
            {
                parseTreeVisitor.Visit(tree);
            }
        }
 public override void AcceptVisitor(IParseTreeVisitor visitor)
 {
     visitor.Visit(this);
 }
Beispiel #5
0
 public static T Visit <T>(this ParserRuleContext context, IParseTreeVisitor <T> visitor)
 {
     return(visitor.Visit(context));
 }