/// <summary> /// Creates source unit and parses given <paramref name="code"/>. /// </summary> /// <param name="code">Source code to be parsed.</param> /// <param name="filePath">Source file used for error reporting.</param> /// <param name="factory">Nodes factory and error sink.</param> /// <param name="errors">Error sink. Can be <c>null</c>.</param> /// <param name="recovery">Error recovery. Can be <c>null</c>.</param> /// <param name="features">Optional. Language features.</param> /// <param name="initialState"> /// Optional. Initial parser state. /// This allows e.g. to parse PHP code without encapsulating the code into opening and closing tags.</param> /// <returns>New <see cref="CodeSourceUnit"/> object.</returns> public static SourceUnit /*!*/ ParseCode(string code, string filePath, INodesFactory <LangElement, Span> factory = null, Errors.IErrorSink <Span> errors = null, Errors.IErrorRecovery recovery = null, LanguageFeatures features = LanguageFeatures.Basic, Lexer.LexicalStates initialState = Lexer.LexicalStates.INITIAL) { var unit = new CodeSourceUnit(code, filePath, Encoding.UTF8, initialState, features); if (factory == null) { factory = new BasicNodesFactory(unit); } if (errors == null) { errors = (factory as Errors.IErrorSink <Span>) ?? new EmptyErrorSink <Span>(); } //var lexer = new Lexer(new StringReader(code), Encoding.UTF8, errors, features, 0, initialState); unit.Parse(factory, errors, recovery); unit.Close(); // return(unit); }
public override void Parse(INodesFactory <LangElement, Span> factory, Errors.IErrorSink <Span> errors) { using (var source = new StringReader(this.Code)) { var lexer = new Lexer(source, Encoding.UTF8, errors, features, 0, initialState); ast = new Parser().Parse(lexer, factory, this.features, errors); } }
public override void Parse(INodesFactory <LangElement, Span> factory, IErrorSink <Span> errors, IErrorRecovery recovery = null) { using (var source = new StringReader(this.Code)) { _lexer = new CollectionLexer(source, errors); ast = new Parser().Parse(_lexer, factory, _features, errors, recovery); } }
public LangElement Parse( ITokenProvider <SemanticValueType, Span> lexer, INodesFactory <LangElement, Span> astFactory, LanguageFeatures language, IErrorSink <Span> errors = null, IErrorRecovery errorRecovery = null, int positionShift = 0) { if (lexer == null) { throw new ArgumentNullException(nameof(lexer)); } if (astFactory == null) { throw new ArgumentNullException(nameof(astFactory)); } // initialization: _languageFeatures = language; if (errorRecovery != null) { _lexer = new BufferedLexer(new CompliantLexer(lexer)); } else { _lexer = new CompliantLexer(lexer); } _astFactory = astFactory; _errors = errors ?? new EmptyErrorSink <Span>(); _errorRecovery = errorRecovery ?? new EmptyErrorRecovery(); //InitializeFields(); _currentScope = new Scope(0); base.Scanner = _lexer; bool accept = base.Parse(); LangElement result = _astRoot; // clean and let GC collect unused AST and other stuff: //ClearFields(); return(result); }
/// <summary> /// Merges DOC comments into the list of statements. /// </summary> /// <param name="extent">Span of code block containing <paramref name="stmts"/>.</param> /// <param name="stmts">List of statements to be merged with overlapping DOC comments.</param> /// <param name="factory">Factory used to create PHPDoc statements.</param> public void Merge(Text.Span extent, IList <LangElement> /*!*/ stmts, INodesFactory <LangElement, Span> factory) { Debug.Assert(extent.IsValid); Debug.Assert(stmts != null); if (_span.OverlapsWith(extent)) { var list = _doclist; int insertAt = 0; int count = 0; DocInfo doc; int indexFrom = FindFirstIn(list, extent); for (var index = indexFrom; index < list.Count && (doc = list[index]).Extent.OverlapsWith(extent); index++) { // skip stmts fully above {doc} while (insertAt < stmts.Count && doc.IsBelowOrNull(stmts[insertAt])) { insertAt++; } // insert {doc} into {stmts} if (insertAt == stmts.Count || doc.IsAbove(stmts[insertAt])) { stmts.Insert(insertAt, factory.PHPDoc(doc.PhpDoc.Span, doc.PhpDoc)); insertAt++; } // count++; } // if (count != 0) { list.RemoveRange(indexFrom, count); this.UpdateSpan(); } } }
public LangElement Parse( ITokenProvider <SemanticValueType, Span> lexer, INodesFactory <LangElement, Span> astFactory, LanguageFeatures language, IErrorSink <Span> errors = null, IErrorRecovery errorRecovery = null, int positionShift = 0) { if (lexer == null) { throw new ArgumentNullException(nameof(lexer)); } // initialization: _languageFeatures = language; _lexer = new CompliantLexer(lexer, language); _astFactory = astFactory ?? throw new ArgumentNullException(nameof(astFactory)); _errors = errors ?? new EmptyErrorSink <Span>(); if (errorRecovery != null) { _lexer = new BufferedLexer(_lexer); _errorRecovery = errorRecovery; } else { _errorRecovery = EmptyErrorRecovery.Instance; } //InitializeFields(); _currentScope = new Scope(0); base.Scanner = _lexer; bool accept = base.Parse(); // return(_astRoot); }
public XpandCriteriaToTreeProcessor(INodesFactory nodesFactory, IList <CriteriaOperator> skippedHolder) : base(nodesFactory, skippedHolder) { }
public override void Parse(INodesFactory <LangElement, Span> factory, IErrorSink <Span> errors, IErrorRecovery recovery = null) { Parse((NodesFactory)factory, errors, recovery, LanguageFeatures.Basic, Lexer.LexicalStates.INITIAL); }
public XpandCriteriaToTreeProcessor(INodesFactory nodesFactory, IList<CriteriaOperator> skippedHolder) : base(nodesFactory, skippedHolder){ }
public abstract void Parse(INodesFactory <LangElement, Span> factory, Errors.IErrorSink <Span> errors, Errors.IErrorRecovery recovery = null);
public abstract void Parse(INodesFactory <LangElement, Span> factory, Errors.IErrorSink <Span> errors);