Пример #1
0
        public static void ParseAndValidate(string text, LuaParseOptions options, params DiagnosticDescription[] expectedErrors)
        {
            var parsedTree   = ParseWithRoundTripCheck(text, options: options);
            var actualErrors = parsedTree.GetDiagnostics();

            actualErrors.Verify(expectedErrors);
        }
Пример #2
0
        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}");
            }
        }
Пример #3
0
        protected LuaSyntaxNode UsingNode(string text, LuaParseOptions options, params DiagnosticDescription[] expectedErrors)
        {
            var node = ParseNode(text, options);

            UsingNode(text, node, expectedErrors);
            return(node);
        }
Пример #4
0
        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());
        }
Пример #5
0
        public static SyntaxTree[] Parse(IEnumerable <string> sources, LuaParseOptions options = null)
        {
            if (sources == null || !sources.Any())
            {
                return(Array.Empty <SyntaxTree>());
            }

            return(Parse(options, sources.ToArray()));
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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)));
        }
Пример #9
0
        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)));
        }
Пример #10
0
        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);
        }
Пример #11
0
 internal static SyntaxNode GetSyntaxRoot(string expectedText, LuaParseOptions options = null)
 {
     return(SyntaxFactory.ParseCompilationUnit(expectedText, options: options));
 }