public static void ParseAndValidate(string text, LuaParseOptions options, params DiagnosticDescription[] expectedErrors) { var parsedTree = ParseWithRoundTripCheck(text, options: options); var actualErrors = parsedTree.GetDiagnostics(); actualErrors.Verify(expectedErrors); }
public SyntaxTree[] GetSyntaxTrees(LuaParseOptions parseOptions, string sourceFileName = "") { switch (Value) { case string source: return(new[] { LuaTestBase.Parse(source, filename: sourceFileName, parseOptions) }); case string[] sources: Debug.Assert(string.IsNullOrEmpty(sourceFileName)); return(LuaTestBase.Parse(parseOptions, sources)); case SyntaxTree tree: Debug.Assert(parseOptions == null); Debug.Assert(string.IsNullOrEmpty(sourceFileName)); return(new[] { tree }); case SyntaxTree[] trees: Debug.Assert(parseOptions == null); Debug.Assert(string.IsNullOrEmpty(sourceFileName)); return(trees); case LuaTestSource[] testSources: return(testSources.SelectMany(s => s.GetSyntaxTrees(parseOptions, sourceFileName)).ToArray()); case null: return(Array.Empty <SyntaxTree>()); default: throw new Exception($"Unexpected value: {Value}"); } }
protected LuaSyntaxNode UsingNode(string text, LuaParseOptions options, params DiagnosticDescription[] expectedErrors) { var node = ParseNode(text, options); UsingNode(text, node, expectedErrors); return(node); }
public static SyntaxTree[] Parse(LuaParseOptions options = null, params string[] sources) { if (sources == null || (sources.Length == 1 && null == sources[0])) { return(Array.Empty <SyntaxTree>()); } return(sources.Select(src => Parse(src, options: options)).ToArray()); }
public static SyntaxTree[] Parse(IEnumerable <string> sources, LuaParseOptions options = null) { if (sources == null || !sources.Any()) { return(Array.Empty <SyntaxTree>()); } return(Parse(options, sources.ToArray())); }
public static SyntaxTree ParseWithRoundTripCheck(string text, LuaParseOptions options = null) { var tree = Parse(text, options: options ?? LuaParseOptions.Default); var parsedText = tree.GetRoot(); // we validate the text roundtrips Assert.Equal(text, parsedText.ToFullString()); return(tree); }
public static ExpressionSyntax ParseExpressionWithRoundTripCheck( string text, LuaParseOptions options = null) { var node = ParseExpression(text, options: options ?? LuaParseOptions.Default); // we validate the text roundtrips Assert.Equal(text, node.ToFullString()); return(node); }
public static ExpressionSyntax ParseExpression( string text, LuaParseOptions options = null, Encoding encoding = null) { options ??= LuaParseOptions.Default; var stringText = SourceText.From(text, encoding ?? Encoding.UTF8); return((ExpressionSyntax)CheckSerializable(SyntaxFactory.ParseExpression(stringText, options))); }
public static SyntaxTree Parse(string text, string filename = "", LuaParseOptions options = null, Encoding encoding = null) { if (options is null) { options = LuaParseOptions.Default; } var stringText = SourceText.From(text, encoding ?? Encoding.UTF8); return(CheckSerializable(SyntaxFactory.ParseSyntaxTree(stringText, options, filename))); }
protected static Script ParseScript(LuaSyntaxOptions options, params string[] codes) { var parseOptions = new LuaParseOptions(options); var trees = new List <SyntaxTree>(); foreach (var code in codes) { var tree = ParseWithRoundTripCheck(code, parseOptions); tree.GetDiagnostics().Verify(); trees.Add(tree); } var script = new Script(ImmutableArray.CreateRange(trees)); return(script); }
internal static SyntaxNode GetSyntaxRoot(string expectedText, LuaParseOptions options = null) { return(SyntaxFactory.ParseCompilationUnit(expectedText, options: options)); }