Example #1
0
        public override bool VisitFirstMemberAccess([NotNull] sphereScript99Parser.FirstMemberAccessContext context)
        {
            if (context.customMemberAccess()?.chainedMemberAccess() != null)
            {
                parentTranspiler.Visit(context.customMemberAccess()?.chainedMemberAccess());
            }
            else if (context.genericNativeMemberAccess()?.nativeMemberAccess()?.chainedMemberAccess() != null)
            {
                parentTranspiler.Visit(context.genericNativeMemberAccess()?.nativeMemberAccess()?.chainedMemberAccess());
            }

            return(true);
        }
        public override bool VisitDialogSection([NotNull] sphereScript99Parser.DialogSectionContext context)
        {
            if (context.dialogPosition() != null)
            {
                parentTranspiler.Visit(context.dialogPosition());
                return(true);
            }

            var statements = context.codeBlock()?.statement();

            if (statements != null)
            {
                foreach (var statement in statements)
                {
                    if (statement.call()?.firstMemberAccess() != null && VisitFirstMemberAccess(statement.call().firstMemberAccess()))
                    {
                        return(true);
                    }
                    if (statement.assignment() != null && VisitAssignment(statement.assignment()))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool VisitFirstMemberAccess([NotNull] sphereScript99Parser.FirstMemberAccessContext context)
        {
            var name = firstMemberAccessNameVisitor.Visit(context);

            IParseTree[] arguments = firstMemberAccessArgumentsVisitor.Visit(context);

            if (IsSpecialFunction(name))
            {
                builder.EnsureEvalCall("eval", () =>
                {
                    builder.Append(name);

                    builder.Append('(');
                    if (name.Equals("strmatch", StringComparison.OrdinalIgnoreCase))
                    {
                        builder.StartSpecialFunctionArguments();
                        transpiler.Visit(arguments[1]);
                        builder.Append(',');
                        transpiler.Visit(arguments[0]);
                        builder.EndSpecialFunctionArguments();
                    }
                    else
                    {
                        if (name.Equals("strcmpi", StringComparison.OrdinalIgnoreCase) ||
                            name.Equals("strcmp", StringComparison.OrdinalIgnoreCase))
                        {
                            builder.StartSpecialFunctionArguments();
                            QuoteIntrinsicArgument(arguments[0]);
                            builder.Append(',');
                            QuoteIntrinsicArgument(arguments[1]);
                            builder.EndSpecialFunctionArguments();
                        }
                        else
                        {
                            UnquoteIntrinsicArgument(arguments[0]);
                        }
                    }
                    builder.Append(')');
                });

                return(true);
            }

            return(false);
        }
        private void TranspileScripts()
        {
            foreach (var file in compilation.CompiledFiles)
            {
                var outputFileName  = GetOutputFileName(file.FileName);
                var outputDirectory = Path.GetDirectoryName(outputFileName);
                if (!Directory.Exists(outputDirectory))
                {
                    Directory.CreateDirectory(outputDirectory);
                }

                Console.WriteLine($"Transpiling to {outputFileName}");
                var transpiler = new Sphere56TranspilerVisitor(compilation.DefinitionRepository);
                transpiler.Visit(file.ParsedTree);
                File.WriteAllText(outputFileName, transpiler.Output);
            }
        }
Example #5
0
        public void Transpile(TranspileOptions options)
        {
            if (File.Exists(options.InputPath))
            {
                ParseFile(options.InputPath);
            }
            else if (Directory.Exists(options.InputPath))
            {
                ParseDirectory(options.InputPath);
            }
            else
            {
                throw new CommandLineException($"Cannot find {options.InputPath}");
            }

            if (compilation.CompilationErrors.Any())
            {
                foreach (var error in compilation.CompilationErrors)
                {
                    if (!string.IsNullOrEmpty(error.FileName))
                    {
                        Console.WriteLine(error.FileName);
                    }
                    Console.WriteLine(error.Message);
                }
            }
            else
            {
                var fileNameHandler = new TranspileCommandFileNameHandler(options);
                foreach (var file in compilation.CompiledFiles)
                {
                    var outputFileName  = fileNameHandler.GetOututFileNameFromInput(file.FileName);
                    var outputDirectory = Path.GetDirectoryName(outputFileName);
                    if (!Directory.Exists(outputDirectory))
                    {
                        Directory.CreateDirectory(outputDirectory);
                    }

                    Console.WriteLine($"Transpiling to {outputFileName}");
                    var transpiler = new Sphere56TranspilerVisitor(compilation.DefinitionRepository);
                    transpiler.Visit(file.ParsedTree);
                    File.WriteAllText(outputFileName, transpiler.Output);
                }
            }
        }
        public override bool VisitNonEscapedMacro([NotNull] sphereScript99Parser.NonEscapedMacroContext context)
        {
            transpiler.Visit(context.macroBody());

            return(true);
        }
Example #7
0
 public override bool VisitPropertyList([NotNull] sphereScript99Parser.PropertyListContext context)
 {
     return(parentVisitor.Visit(context));
 }
Example #8
0
        public override bool VisitMacro([NotNull] sphereScript99Parser.MacroContext context)
        {
            parentTranspiler.Visit(context);

            return(true);
        }
        public override bool VisitCustomMemberAccess([NotNull] sphereScript99Parser.CustomMemberAccessContext context)
        {
            parentTranspiler.Visit(context.memberName());

            return(true);
        }
        public override bool VisitChainedMemberAccess([NotNull] sphereScript99Parser.ChainedMemberAccessContext context)
        {
            transpiler.Visit(context.memberAccess());

            return(true);
        }
        public override bool VisitGenericNativeMemberAccess([NotNull] sphereScript99Parser.GenericNativeMemberAccessContext context)
        {
            parentTranspiler.Visit(context);

            return(true);
        }
Example #12
0
 public override bool VisitEvalExpression([NotNull] sphereScript99Parser.EvalExpressionContext context)
 {
     return(parentTranspiler.Visit(context));
 }