/// <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 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);