コード例 #1
0
        public ActionResult <TranspileResponse> Transpile([FromQuery] TargetLanguage target, [FromBody] TranspileRequest input)
        {
            var response = new TranspileResponse {
                Target = target
            };

            var program = Parser.ParseSylvreInput(input.Code);

            if (program.HasParseErrors)
            {
                response.HasErrors   = true;
                response.ErrorSource = TranspileResponseErrorSource.Parser;
                response.Errors      = program.ParseErrors;

                return(Ok(response));
            }

            var output = Transpiler.TranspileSylvreToTarget(program, target);

            if (output.HasTranspileErrors)
            {
                response.HasErrors   = true;
                response.ErrorSource = TranspileResponseErrorSource.Transpiler;
                response.Errors      = output.TranspileErrors;

                return(Ok(response));
            }

            response.TranspiledCode = output.TranspiledCode;
            return(Ok(response));
        }
コード例 #2
0
        public void Should_Output_Valid_JavaScript_Function_Return(string sylvreInput, string jsRegex)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            StringAssert.IsMatch(jsRegex, output.TranspiledCode);
        }
コード例 #3
0
ファイル: LoopBlockTests.cs プロジェクト: shahzaib-m/Sylvre
        public void Should_Output_Valid_For_Loop_Block(string sylvreInput, string regexToMatch)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            StringAssert.IsMatch(regexToMatch, output.TranspiledCode);
        }
コード例 #4
0
        public void Should_Not_Provide_Transpile_Errors(string sylvreInput)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsFalse(output.HasTranspileErrors);
        }
コード例 #5
0
        public void Should_Provide_Transpile_Error_When_Assigning_To_Sylvre()
        {
            string        sylvreInput = "\nSylvre = 25.21#";
            SylvreProgram program     = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsTrue(output.HasTranspileErrors);
        }
コード例 #6
0
        public void Should_Output_Valid_JavaScript_Unary_Decrement_Suffix()
        {
            string        sylvreInput = "var decrement#";
            string        jsRegex     = @"""use strict"";__var.*--[n ]*;";
            SylvreProgram program     = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            StringAssert.IsMatch(jsRegex, output.TranspiledCode);
        }
コード例 #7
0
ファイル: LoopBlockTests.cs プロジェクト: shahzaib-m/Sylvre
        public void Should_Output_Valid_While_Loop_Block()
        {
            string        sylvreInput = "loopwhile(FALSE) < >";
            SylvreProgram program     = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            StringAssert.IsMatch(@"""use strict"";while[\n ]*\(.*\)[\n ]*{[\n ]*}",
                                 output.TranspiledCode);
        }
コード例 #8
0
        public void Should_Append_Two_Underscores_If_FuncName_Is_Reserved_Keyword(string sylvreInput, string regexToMatch)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsFalse(output.HasTranspileErrors);

            StringAssert.IsMatch(regexToMatch, output.TranspiledCode);
        }
コード例 #9
0
        public void Should_Output_Valid_Else_Statement()
        {
            string        sylvreInput = "if (TRUE) <> else < >";
            SylvreProgram program     = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            StringAssert.IsMatch(@"""use strict"";.+else[\n ]*{[\n ]*}",
                                 output.TranspiledCode);
        }
コード例 #10
0
        public void Should_Output_Valid_ComplexVarReference_IndexRef(string sylvreInput,
                                                                     string regexToMatch)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsFalse(output.HasTranspileErrors);

            StringAssert.IsMatch(regexToMatch, output.TranspiledCode);
        }
コード例 #11
0
        public void Should_Give_Error_When_No_Member_Ref_After_Module_Ref(string sylvreInput)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsTrue(output.HasTranspileErrors);

            Assert.AreEqual("Missing a module member reference after module name.",
                            output.TranspileErrors.First().Message);
        }
コード例 #12
0
        public void Should_Give_Error_When_Index_Reference_After_Module_Ref(string sylvreInput)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsTrue(output.HasTranspileErrors);

            Assert.AreEqual("An index reference is not allowed after a module reference.",
                            output.TranspileErrors.First().Message);
        }
コード例 #13
0
        public void Should_Give_Error_When_Invalid_Module_Member_Ref_Is_Used(string sylvreInput)
        {
            SylvreProgram program = Parser.ParseSylvreInput(sylvreInput);

            Assert.IsFalse(program.HasParseErrors);

            TranspileOutputBase output = Transpiler.TranspileSylvreToTarget(
                program, TargetLanguage.Javascript);

            Assert.IsTrue(output.HasTranspileErrors);

            Assert.AreEqual("This Sylvre module member does not exist.",
                            output.TranspileErrors.First().Message);
        }