Exemple #1
0
 public override void Accept(ParserVisitor visitor) {
     visitor.VisitStartBlock(Type);
     foreach (SyntaxTreeNode element in Children) {
         element.Accept(visitor);
     }
     visitor.VisitEndBlock(Type);
 }
        public virtual void Parse(LookaheadTextReader input, ParserVisitor visitor)
        {
            ParserResults results = ParseCore(new SeekableTextReader(input));

            // Replay the results on the visitor
            visitor.Visit(results);
        }
Exemple #3
0
 void AcceptParserVisitor.Accept(ParserVisitor visitor)
 {
     visitor.Visit(this, x =>
     {
         _parser.Accept(x);
         _except.Accept(x);
     });
 }
Exemple #4
0
 public void Accept(ParserVisitor visitor)
 {
     visitor.Visit(this, x =>
     {
         _element.Accept(x);
         _separator.Accept(x);
     });
 }
Exemple #5
0
 public void Accept(ParserVisitor visitor)
 {
     visitor.Visit(this, x =>
     {
         _first.Accept(visitor);
         _second.Accept(visitor);
     });
 }
Exemple #6
0
 public override void Accept(ParserVisitor visitor)
 {
     visitor.VisitStartBlock(Type);
     foreach (SyntaxTreeNode element in Children)
     {
         element.Accept(visitor);
     }
     visitor.VisitEndBlock(Type);
 }
Exemple #7
0
        public void VisitThrowsOnNullVisitor()
        {
            ParserVisitor target  = null;
            ParserResults results = new ParserResults(new BlockBuilder()
            {
                Type = BlockType.Comment
            }.Build(), new List <RazorError>());

            Assert.ThrowsArgumentNull(() => target.Visit(results), "self");
        }
Exemple #8
0
 public void Accept(ParserVisitor visitor)
 {
     visitor.Visit(this, x =>
     {
         foreach (var parser in _parsers)
         {
             parser.Accept(x);
         }
     });
 }
Exemple #9
0
 /// <summary>Accept the visitor. *
 /// </summary>
 public virtual System.Object childrenAccept(ParserVisitor visitor, System.Object data)
 {
     if (children != null)
     {
         for (int i = 0; i < children.Length; ++i)
         {
             children[i].jjtAccept(visitor, data);
         }
     }
     return(data);
 }
Exemple #10
0
        public void VisitThrowsOnNullVisitor()
        {
            ParserVisitor target  = null;
            var           results = new ParserResults(new BlockBuilder()
            {
                Type = BlockType.Comment
            }.Build(),
                                                      Enumerable.Empty <TagHelperDescriptor>(),
                                                      parserErrors: new List <RazorError>());

            Assert.Throws <ArgumentNullException>("self", () => target.Visit(results));
        }
Exemple #11
0
	/// <summary>Accept the visitor. *
	/// </summary>
	public virtual System.Object childrenAccept(ParserVisitor visitor, System.Object data) {
	    if (children != null) {
		for (int i = 0; i < children.Length; ++i) {
		    children[i].jjtAccept(visitor, data);
		}
	    }
	    return data;
	}
	/// <summary>Accept the visitor. *
	/// </summary>
	public override System.Object jjtAccept(ParserVisitor visitor, System.Object data) {
	    return visitor.visit(this, data);
	}
 public virtual void Parse(TextReader input, ParserVisitor visitor)
 {
     Parse(new SeekableTextReader(input), visitor);
 }
Exemple #14
0
 /// <summary>
 /// Invokes the corresponding <see cref="ParserVisitor{TInput, TResult}"/> visit method.
 /// </summary>
 public abstract TResult Accept <TResult>(ParserVisitor <TInput, TResult> visitor);
Exemple #15
0
 /// <summary>
 /// Accepts the specified visitor
 /// </summary>
 /// <remarks>
 /// Calls the VisitSpan method on the specified visitor, passing in this
 /// </remarks>
 public override void Accept(ParserVisitor visitor)
 {
     visitor.VisitSpan(this);
 }
 public abstract void Accept(ParserVisitor visitor, Block block);
 public override void Accept(ParserVisitor visitor, Span span)
 {
     visitor.VisitMarkupSpan(this, span);
 }
Exemple #18
0
 /// <summary>
 /// Invokes the corresponding <see cref="ParserVisitor{TInput, TArg, TResult}"/> visit method.
 /// </summary>
 public abstract TResult Accept <TArg, TResult>(ParserVisitor <TInput, TArg, TResult> visitor, TArg arg);
 /// <summary>
 /// Accepts a parser visitor, calling the appropriate visit method and passing in this instance
 /// </summary>
 /// <param name="visitor">The visitor to accept</param>
 public abstract void Accept(ParserVisitor visitor);
 public override void Accept(ParserVisitor visitor, Block block)
 {
     visitor.VisitCommentBlock(this, block);
 }
Exemple #21
0
        private static void DoParse()
        {
            try {
                if (OnStart != null)
                {
                    OnStart();
                }

                DoInLock(() => {
                    // make sure to always parse the current file
                    Parse.Parser parser = null;
                    do
                    {
                        _lastFilePathParsed = Npp.CurrentFileInfo.Path;

                        if (Npp.CurrentFileInfo.IsProgress)
                        {
                            parser = new Parse.Parser(Sci.Text, _lastFilePathParsed, null, true);

                            // visitor
                            var visitor = new ParserVisitor(true);
                            parser.Accept(visitor);

                            // send completionItems
                            if (OnEndSendCompletionItems != null)
                            {
                                OnEndSendCompletionItems(visitor.ParsedCompletionItemsList);
                            }

                            // send codeExplorerItems
                            if (OnEndSendCodeExplorerItems != null)
                            {
                                OnEndSendCodeExplorerItems(visitor.ParsedExplorerItemsList);
                            }
                        }
                        else
                        {
                            var textLexer   = new TextTokenizer(Sci.GetTextAroundFirstVisibleLine(Config.Instance.NppAutoCompleteMaxLengthToParse), AutoCompletion.CurrentLangAdditionalChars);
                            var textVisitor = new TextTokenizerVisitor(_lastFilePathParsed)
                            {
                                IgnoreNumbers         = Config.Instance.NppAutoCompleteIgnoreNumbers,
                                MinWordLengthRequired = Config.Instance.NppAutoCompleteMinWordLengthRequired,
                                KnownWords            = KnownWords != null ? new HashSet <string>(KnownWords, AutoCompletion.ParserStringComparer) : new HashSet <string>(AutoCompletion.ParserStringComparer)
                            };
                            textLexer.Accept(textVisitor);

                            // send completionItems
                            if (OnEndSendCompletionItems != null)
                            {
                                OnEndSendCompletionItems(textVisitor.ParsedCompletionItemsList);
                            }

                            // send codeExplorerItems
                            if (OnEndSendCodeExplorerItems != null)
                            {
                                OnEndSendCodeExplorerItems(null);
                            }
                        }
                    } while (!_lastFilePathParsed.Equals(Npp.CurrentFileInfo.Path));

                    if (parser != null)
                    {
                        _lineInfo = new Dictionary <int, ParsedLineInfo>(parser.LineInfo);
                    }

                    // send parserItems
                    if (OnEndSendParserItems != null)
                    {
                        if (parser != null)
                        {
                            OnEndSendParserItems(parser.ParserErrors, parser.LineInfo, parser.ParsedItemsList);
                        }
                        else
                        {
                            OnEndSendParserItems(null, null, null);
                        }
                    }
                });

                if (OnEnd != null)
                {
                    OnEnd();
                }
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error while analyzing the current document");
            }
        }
Exemple #22
0
 /// <summary>Accept the visitor. *
 /// </summary>
 public virtual System.Object jjtAccept(ParserVisitor visitor, System.Object data)
 {
     return(visitor.visit(this, data));
 }
Exemple #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderContext"/> class.
 /// </summary>
 /// <param name="visitor">The visitor.</param>
 /// <param name="parentRenderContext">The parent render context.</param>
 public RenderContext(ParserVisitor <RenderContext> visitor, RenderContext parentRenderContext = null)
 {
     ParentRenderContext = parentRenderContext;
     Visitor             = visitor;
 }
Exemple #24
0
 public void Accept(ParserVisitor visitor)
 {
     visitor.Visit(this, x => _parser.Accept(x));
 }
Exemple #25
0
 public void Accept(ParserVisitor visitor)
 {
     visitor.Visit(this);
 }
        private ParserContext SetupTestRun(string document, Action <TextReader> positioningAction, ParserBase codeParser, MarkupParser markupParser, ParserBase activeParser, ParserVisitor listener)
        {
            ParserContext context = new ParserContext(new BufferingTextReader(new StringReader(document)), codeParser, markupParser, activeParser, listener);

            positioningAction(context.Source);
            context.ResetBuffers();
            return(context);
        }
Exemple #27
0
 public override void Accept(ParserVisitor visitor, Block block)
 {
     visitor.VisitTagHelperBlock(this, block);
 }
Exemple #28
0
 public override void Accept(ParserVisitor visitor, Block block)
 {
     visitor.VisitTemplateBlock(this, block);
 }
 public void Accept(ParserVisitor visitor, Block block)
 {
     visitor.VisitDefault(block);
 }
Exemple #30
0
 public virtual ParserContext CreateParserRun(LookaheadTextReader input, ParserBase codeParser, MarkupParser markupParser, ParserVisitor listener)
 {
     return(new ParserContext(input, codeParser, markupParser, SelectActiveParser(codeParser, markupParser), listener));
 }
Exemple #31
0
 /// <summary>
 /// Invokes the corresponding <see cref="ParserVisitor{TInput}"/> visit method.
 /// </summary>
 public abstract void Accept(ParserVisitor <TInput> visitor);
	public virtual void  process(InternalContextAdapter context, ParserVisitor visitor) {}}
 public virtual Task CreateParseTask(TextReader input,
                                     ParserVisitor consumer)
 {
     return new Task(() =>
     {
         try
         {
             Parse(input, consumer);
         }
         catch (OperationCanceledException)
         {
             return; // Just return if we're cancelled.
         }
     });
 }
Exemple #34
0
 public override void Accept(ParserVisitor visitor, Span span)
 {
     visitor.VisitStatementSpan(this, span);
 }
Exemple #35
0
 public void Accept(ParserVisitor visitor)
 {
     _parser.Accept(visitor);
 }
Exemple #36
0
 public override void Accept(ParserVisitor visitor)
 {
     visitor.VisitBlock(this);
 }
Exemple #37
0
 /// <summary>Accept the visitor. *
 /// </summary>
 public override Object jjtAccept(ParserVisitor visitor, Object data)
 {
     return(visitor.visit(this, data));
 }
Exemple #38
0
	/// <summary>Accept the visitor. *
	/// </summary>
	public virtual System.Object jjtAccept(ParserVisitor visitor, System.Object data) {
	    return visitor.visit(this, data);
	}
Exemple #39
0
 /// <summary>
 /// Accepts a parser visitor, calling the appropriate visit method and passing in this instance
 /// </summary>
 /// <param name="visitor">The visitor to accept</param>
 public abstract void Accept(ParserVisitor visitor);
Exemple #40
0
        /// <summary>
        /// This method parses the output of the .p procedure that exports the database info
        /// and fills _dataBases
        /// It then updates the parser with the new info
        /// </summary>
        private void Read(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }
            _dataBases.Clear();
            _sequences.Clear();

            var            defaultToken = new TokenEos(null, 0, 0, 0, 0);
            ParsedDataBase currentDb    = null;
            ParsedTable    currentTable = null;

            Utils.ForEachLine(filePath, null, (i, items) => {
                var splitted = items.Split('\t');
                switch (items[0])
                {
                case 'H':
                    // base
                    //#H|<Dump date ISO 8601>|<Dump time>|<Logical DB name>|<Physical DB name>|<Progress version>
                    if (splitted.Length != 6)
                    {
                        return;
                    }
                    currentDb = new ParsedDataBase(
                        splitted[3],
                        splitted[4],
                        splitted[5],
                        new List <ParsedTable>(),
                        null);
                    _dataBases.Add(currentDb);
                    break;

                case 'S':
                    if (splitted.Length != 3 || currentDb == null)
                    {
                        return;
                    }
                    _sequences.Add(new ParsedSequence {
                        SeqName = splitted[1],
                        DbName  = currentDb.Name
                    });
                    break;

                case 'T':
                    // table
                    //#T|<Table name>|<Table ID>|<Table CRC>|<Dump name>|<Description>|<Hidden? 0/1>|<Frozen? 0/1>|<Table type>
                    if (splitted.Length != 9 || currentDb == null)
                    {
                        return;
                    }
                    ParsedTableType tblType;
                    if (!Enum.TryParse(splitted[8].Trim(), true, out tblType))
                    {
                        tblType = ParsedTableType.T;
                    }
                    currentTable = new ParsedTable(
                        splitted[1],
                        defaultToken,
                        tblType,
                        splitted[2],
                        splitted[3],
                        splitted[4],
                        splitted[5],
                        null,
                        new List <ParsedField>(),
                        new List <ParsedIndex>(),
                        new List <ParsedTrigger>(),
                        null,
                        splitted[6].Equals("1"),
                        splitted[7].Equals("1")
                        );
                    currentDb.Tables.Add(currentTable);
                    break;

                case 'X':
                    // trigger
                    //#X|<Parent table>|<Event>|<Proc name>|<Trigger CRC>
                    if (splitted.Length != 5 || currentTable == null)
                    {
                        return;
                    }
                    currentTable.Triggers.Add(new ParsedTrigger(
                                                  splitted[2],
                                                  splitted[3]));
                    break;

                case 'I':
                    // index
                    //#I|<Parent table>|<Index name>|<Primary? 0/1>|<Unique? 0/1>|<Index CRC>|<Fileds separated with %>
                    if (splitted.Length != 7 || currentTable == null)
                    {
                        return;
                    }
                    var flag = splitted[3].Equals("1") ? ParsedIndexFlag.Primary : ParsedIndexFlag.None;
                    if (splitted[4].Equals("1"))
                    {
                        flag = flag | ParsedIndexFlag.Unique;
                    }
                    currentTable.Indexes.Add(new ParsedIndex(
                                                 splitted[2],
                                                 flag,
                                                 splitted[6].Split('%').ToList()));
                    break;

                case 'F':
                    // field
                    //#F|<Parent table>|<Field name>|<Type>|<Format>|<Order #>|<Mandatory? 0/1>|<Extent? 0/x>|<Part of index? 0/1>|<Part of PK? 0/1>|<Initial value>|<Desription>
                    if (splitted.Length != 12 || currentTable == null)
                    {
                        return;
                    }
                    var flags = splitted[6].Equals("1") ? ParseFlag.Mandatory : 0;
                    if (splitted[8].Equals("1"))
                    {
                        flags = flags | ParseFlag.Index;
                    }
                    if (splitted[9].Equals("1"))
                    {
                        flags = flags | ParseFlag.Primary;
                    }
                    var curField = new ParsedField(
                        splitted[2],
                        splitted[3],
                        splitted[4],
                        int.Parse(splitted[5]),
                        flags,
                        splitted[10],
                        splitted[11],
                        ParsedAsLike.None);
                    curField.Extent        = int.Parse(splitted[7]);
                    curField.PrimitiveType = ParserVisitor.ConvertStringToParsedPrimitiveType(curField.TempPrimitiveType);
                    currentTable.Fields.Add(curField);
                    break;
                }
            });

            // copy the databases for each aliases
            foreach (var aliasCreation in GetAliasesList.Trim().Trim(';').Split(';'))
            {
                var splitted = aliasCreation.Split(',');
                if (splitted.Length == 2)
                {
                    if (!string.IsNullOrWhiteSpace(splitted[0]) && !string.IsNullOrWhiteSpace(splitted[1]))
                    {
                        var foundDb = FindDatabaseByName(splitted[1].Trim());
                        if (foundDb != null)
                        {
                            _dataBases.Add(new ParsedDataBase(
                                               splitted[0].Trim(),
                                               foundDb.PhysicalName,
                                               foundDb.ProgressVersion,
                                               foundDb.Tables,
                                               foundDb.Name));
                        }
                    }
                }
            }

            // sort all fields by primary then by name
            foreach (var dataBase in _dataBases)
            {
                foreach (var table in dataBase.Tables)
                {
                    table.Fields.Sort((x, y) => {
                        var compare = y.Flags.HasFlag(ParseFlag.Primary).CompareTo(x.Flags.HasFlag(ParseFlag.Primary));
                        if (compare != 0)
                        {
                            return(compare);
                        }
                        return(string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase));
                    });
                }
            }
        }