public static PhpSyntaxTree ParseCode( string content, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, string fname) { if (fname == null) { throw ExceptionUtilities.ArgumentNull(nameof(fname)); } // TODO: new parser implementation based on Roslyn // TODO: file.IsScript ? scriptParseOptions : parseOptions var unit = new PhpSourceUnit( fname, SourceText.From(content, Encoding.UTF8), encoding: Encoding.UTF8); var result = new PhpSyntaxTree(unit); var errorSink = new ErrorSink(result); var factory = new NodesFactory(unit, parseOptions.Defines); // try { unit.Parse(factory, errorSink, features: GetLanguageFeatures(parseOptions), state: (parseOptions.Kind == SourceCodeKind.Regular) ? Lexer.LexicalStates.INITIAL : Lexer.LexicalStates.ST_IN_SCRIPTING); } finally { unit.Close(); } // result.Diagnostics = errorSink.Diagnostics; result.Lambdas = factory.Lambdas.AsImmutableSafe(); result.Types = factory.Types.AsImmutableSafe(); result.Functions = factory.Functions.AsImmutableSafe(); result.YieldNodes = factory.YieldNodes.AsImmutableSafe(); if (factory.Root != null) { result.Root = factory.Root; } else { // Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node var fullSpan = new Devsense.PHP.Text.Span(0, content.Length); result.Root = new GlobalCode(fullSpan, ImmutableArray <Statement> .Empty, unit); } // return(result); }
public static Diagnostic ParserDiagnostic(SyntaxTree tree, Devsense.PHP.Text.Span span, Devsense.PHP.Errors.ErrorInfo info, params string[] argsOpt) { ParserMessageProvider.Instance.RegisterError(info); return(ParserMessageProvider.Instance.CreateDiagnostic( info.Severity == Devsense.PHP.Errors.ErrorSeverity.WarningAsError, info.Id, new SourceLocation(tree, span.ToTextSpan()), argsOpt)); }
public static SyntaxTree ParseCode(Parser parser, Context context, string content_string, string filename) { if (filename == null) { throw new ArgumentNullException(nameof(filename)); } content_string = content_string.Replace("\r", "").Replace("else if", "elseif").Trim(); // TODO: new parser implementation based on Roslyn // TODO: file.IsScript ? scriptParseOptions : parseOptions var unit = new CodeSourceUnit( content_string, filename, Encoding.UTF8, Lexer.LexicalStates.INITIAL, LanguageFeatures.Php73Set | LanguageFeatures.ShortOpenTags ); var result = new SyntaxTree(unit); var errorSink = new PhpErrorSink(result); var factory = new NodesFactory(unit, context.Defines); // unit.Parse(factory, errorSink); // result.Diagnostics = errorSink.Diagnostics.Select(d => (IDiagnostic)d).ToImmutableArray(); result.Lambdas = factory.Lambdas.AsImmutableSafe(); result.Types = factory.Types.AsImmutableSafe(); result.Functions = factory.Functions.AsImmutableSafe(); result.YieldNodes = factory.YieldNodes.AsImmutableSafe(); if (factory.Root != null) { result.Root = factory.Root; } else { // Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node var fullSpan = new Devsense.PHP.Text.Span(0, unit.Code.Length); result.Root = new GlobalCode(fullSpan, ImmutableArray <Statement> .Empty, unit); } result.RootExpression = parser.Parse(result.Root); return(result); }
public static PhpSyntaxTree ParseCode( string content, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, string fname) { // TODO: new parser implementation based on Roslyn // TODO: file.IsScript ? scriptParseOptions : parseOptions var unit = new CodeSourceUnit( content, fname, Encoding.UTF8, (parseOptions.Kind == SourceCodeKind.Regular) ? Lexer.LexicalStates.INITIAL : Lexer.LexicalStates.ST_IN_SCRIPTING); var result = new PhpSyntaxTree(unit); var errorSink = new ErrorSink(result); var factory = new NodesFactory(unit); // unit.Parse(factory, errorSink); // result.Diagnostics = errorSink.Diagnostics; result.Lambdas = factory.Lambdas.AsImmutableSafe(); result.Types = factory.Types.AsImmutableSafe(); result.Functions = factory.Functions.AsImmutableSafe(); result.YieldNodes = factory.YieldNodes.AsImmutableSafe(); if (factory.Root != null) { result.Root = factory.Root; } else { // Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node var fullSpan = new Devsense.PHP.Text.Span(0, unit.Code.Length); result.Root = new GlobalCode(fullSpan, ImmutableArray <Statement> .Empty, unit); } // return(result); }
void Add(Devsense.PHP.Text.Span span, Devsense.PHP.Errors.ErrorInfo err, params string[] args) { _diagnostics.Add(DiagnosticBagExtensions.ParserDiagnostic(_routine, span, err, args)); }
public static Diagnostic ParserDiagnostic(SourceRoutineSymbol routine, Devsense.PHP.Text.Span span, Devsense.PHP.Errors.ErrorInfo info, params string[] argsOpt) { return(ParserDiagnostic(routine.ContainingFile.SyntaxTree, span, info, argsOpt)); }