Exemple #1
0
 public void InterpretFile01(
     [PexAssumeUnderTest] AphidInterpreter target,
     string filename,
     bool isTextDocument
     )
 {
     target.InterpretFile(filename, isTextDocument);
     // TODO: add assertions to method AphidInterpreterTest.InterpretFile01(AphidInterpreter, String, Boolean)
 }
        private static SelfTestAssembly[] LoadAssemblies()
        {
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(PathHelper.GetEntryPath("Tests.alx"));
            var retVal = interpreter.GetReturnValue();

            return(retVal.ConvertToArray <SelfTestAssembly>());
        }
Exemple #3
0
        public static string Interpret(string file)
        {
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(file);
            var retVal = interpreter.GetReturnValue();

            return(From(retVal));
        }
Exemple #4
0
        private static void LoadSettings()
        {
            WriteHeader("Loading release settings");
            var script = "PhpVH.alx";

            Cli.WriteLine("Executing ~Cyan~{0}~R~", script);
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(script);
            _currentRelease = interpreter.GetReturnValue().ConvertTo <Release>();
            var projects = _currentRelease.Projects;

            Cli.WriteLine();
        }
Exemple #5
0
        public static AphidObject Execute(string filename)
        {
            AphidObject obj;

            if (_executeCache.TryGetValue(filename, out obj))
            {
                return(obj);
            }

            var interpreter = new AphidInterpreter();

            Cli.WriteLine("Executing ~Cyan~{0}~R~", filename);
            interpreter.InterpretFile(filename);
            obj = interpreter.GetReturnValue();;
            _executeCache.Add(filename, obj);

            return(obj);
        }
        public CodeObject CreateCodeObject()
        {
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile("ParserRules.alx");
            var methods = interpreter
                          .GetReturnValue()
                          .ConvertTo <AphidParserRules>().BinaryOperatorExpressions
                          .Select(CreateBinOpParseFunction)
                          .ToArray();

            var t = CreateParserType(methods);

            var ns = new CodeNamespace("Components.Aphid.Parser");

            ns.Types.Add(t);

            return(ns);
        }
Exemple #7
0
        private void HandleConfigCaching(AphidObject session)
        {
            if (!session.TryGetValue(_configCacheTime, out var lastWriteObj))
            {
                session.Add(
                    _configCacheTime,
                    lastWriteObj = AphidObject.Scalar(DateTime.MinValue));
            }

            _ = (DateTime)lastWriteObj.Value;
            var config = GetConfigFile();

            //if (config.LastWriteTime == lastWrite)
            //{
            //    return;
            //}

            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(config.FullName);
            SetSessionInterpreter(session, interpreter);
            session[_configCacheTime].Value = config.LastWriteTime;
        }
Exemple #8
0
        public static string Interpret(string file)
        {
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(file);
            var retVal   = interpreter.GetReturnValue();
            var llexFile = new LLexFile();

            retVal.Bind(llexFile);
            var tokenTable = new TokenTable();

            tokenTable.Ignore = llexFile.Ignore;
            var nameInfo = LLexNameInfo.Parse(llexFile.Name);

            int z          = 0;
            var modeTable  = llexFile.Modes.ToDictionary(x => x.Mode, x => z++);
            var tokenTypes = new List <string>();

            foreach (var mode in llexFile.Modes)
            {
                tokenTable.SetMode(modeTable[mode.Mode]);
                foreach (var token in mode.Tokens)
                {
                    if (token.Regex != null)
                    {
                        var regexLexer = new RegexLexer(token.Regex);
                        var tokens     = regexLexer.GetTokens();
                        var parser     = new RegexParser(tokens.ToArray());
                        var ast        = parser.Parse();
                        var compiler   = new RegexCompiler(ast);
                        var strings    = compiler.ExpandRegex();

                        foreach (var l in strings)
                        {
                            if (token.Code != null)
                            {
                                tokenTable.AddLexemeCode(l, token.Code);
                                continue;
                            }

                            if (!tokenTypes.Contains(token.TokenType))
                            {
                                tokenTypes.Add(token.TokenType);
                            }

                            if (!string.IsNullOrEmpty(token.NewMode))
                            {
                                tokenTable.Add(l, token.TokenType, modeTable[token.NewMode]);
                            }
                            else
                            {
                                tokenTable.Add(l, token.TokenType);
                            }
                        }
                    }
                    else if (token.Code != null)
                    {
                        tokenTable.AddCode(token.Code);
                    }
                }

                foreach (var keyword in mode.Keywords)
                {
                    tokenTable.AddKeyword(keyword);
                    var t = keyword + "Keyword";
                    if (mode.KeywordTail != null)
                    {
                        tokenTable.AddLexemeCode(keyword, mode.KeywordTail.Replace("{Keyword}", t));
                    }
                    else
                    {
                        tokenTable.Add(keyword, t);
                    }
                }

                if (!string.IsNullOrEmpty(mode.KeywordDefault))
                {
                    var k = mode.Keywords
                            .SelectMany(x => Enumerable
                                        .Range(1, x.Length - 1)
                                        .Select(y => x.Remove(y))
                                        .ToArray())
                            .Distinct()
                            .ToArray();

                    foreach (var i in k)
                    {
                        if (tokenTable.Lists.Any(x => x.Value.Any(y => y.Lexeme == i)))
                        {
                            continue;
                        }
                        tokenTable.AddLexemeCode(i, mode.KeywordDefault);
                    }
                }
            }

            var generator = new LexerGenerator(tokenTable);
            var lexer     = generator.Generate();


            return(lexer
                   .Replace("{Lexer}", nameInfo.LexerName)
                   .Replace("{Token}", nameInfo.TokenName)
                   .Replace("{TokenType}", nameInfo.TokenTypeName)
                   .Replace("{LexerNamespace}", nameInfo.Namespace));
        }
Exemple #9
0
        static void Main(string[] args)
        {
            WriteHeader("Loading release settings");
            var script = "PhpVH.alx";

            Cli.WriteLine("Executing ~Cyan~{0}~R~", script);
            var interpreter = new AphidInterpreter();

            interpreter.InterpretFile(script);
            _currentRelease = interpreter.GetReturnValue().ConvertTo <Release>();
            var projects = _currentRelease.Projects;

            Cli.WriteLine();

            WriteHeader("Copying binaries");

            var outputDir = new DirectoryInfo(_currentRelease.Output)
                            .Combine(GetReleaseVersion(projects).ToString());

            if (outputDir.Exists)
            {
                Cli.WriteLine("Deleting ~Yellow~{0}~R~", outputDir.FullName);
                outputDir.Delete(true);
            }

            Cli.WriteLine();
            WriteProgressHeader("Copying");

            var progress = new CliProgressBar(projects.Length);

            progress.Write();

            projects
            .Iter(x =>
            {
                new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true);
                progress.Value++;
                progress.Write();
            });

            Cli.WriteLine();
            Cli.WriteLine();
            WriteHeader("Cleaning up");
            Cli.WriteLine("Searching...");
            var fsos = new List <FileSystemInfo>();

            if (_currentRelease.Cleanup.FilePatterns != null && _currentRelease.Cleanup.FilePatterns.Any())
            {
                fsos.AddRange(
                    outputDir
                    .GetFiles("*", SearchOption.AllDirectories)
                    .Where(x => _currentRelease.Cleanup.FilePatterns.Any(y => Regex.IsMatch(x.FullName, y))));
            }

            if (_currentRelease.Cleanup.Files != null && _currentRelease.Cleanup.Files.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Files.Select(x => new FileInfo(Path.Combine(outputDir.FullName, x))));
            }

            if (_currentRelease.Cleanup.Directories != null && _currentRelease.Cleanup.Directories.Any())
            {
                fsos.AddRange(_currentRelease.Cleanup.Directories.Select(x => outputDir.Combine(x)));
            }

            Cli.WriteLine("~Cyan~{0}~R~ files and directories found", fsos.Count);
            Cli.WriteLine();
            WriteProgressHeader("Deleting");

            progress = new CliProgressBar(fsos.Count);
            progress.Write();

            fsos.Iter(x =>
            {
                var dir = x as DirectoryInfo;

                if (dir != null)
                {
                    dir.Delete(true);
                }
                else
                {
                    x.Delete();
                }

                progress.Value++;
                progress.Write();
            });
        }
Exemple #10
0
        public int Generate(
            string wszInputFilePath,
            string bstrInputFileContents,
            string wszDefaultNamespace,
            IntPtr[] rgbOutputFileContents,
            out uint pcbOutput,
            IVsGeneratorProgress pGenerateProgress)
        {
            if (bstrInputFileContents == null)
            {
                throw new ArgumentException(bstrInputFileContents);
            }

            string csOut  = null;
            var    result = VSConstants.E_FAIL;

            try
            {
#if RELEASE
                if (AphidBuildInterop.Compile == null)
                {
                    var interpreter = new AphidInterpreter();

                    var interopScript = Path.Combine(
                        Path.GetDirectoryName(typeof(AphidExpression).Assembly.Location),
                        "AphidBuildInterop.alx");

                    interpreter.InterpretFile(interopScript);
                }
#else
                _interopScript.Refresh();

                if (_lastRun < _interopScript.LastWriteTime)
                {
                    _lastRun = DateTime.Now;
                    var interpreter = new AphidInterpreter();
                    interpreter.InterpretFile(_interopScript.FullName);
                }
#endif

                csOut = AphidBuildInterop.Compile(
                    wszInputFilePath,
                    bstrInputFileContents,
                    wszDefaultNamespace);

                result = VSConstants.S_OK;
            }
            catch (AphidParserException e)
            {
                if (e.UnexpectedToken.TokenType != default(AphidToken).TokenType)
                {
                    var pos = TokenHelper.GetIndexPosition(
                        bstrInputFileContents,
                        e.UnexpectedToken.Index);

                    pGenerateProgress.GeneratorError(
                        0,
                        0,
                        ParserErrorMessage.Create(bstrInputFileContents, e, false),
                        pos == null || pos.Item1 == -1 ? 0xffffffffu : (uint)pos.Item1,
                        pos == null || pos.Item2 == -1 ? 0xffffffffu : (uint)pos.Item2);
                }
                else
                {
                    WriteError(
                        pGenerateProgress,
                        bstrInputFileContents,
                        e,
                        e.Expression);
                }
            }
            catch (AphidLoadScriptException e)
            {
                WriteError(
                    pGenerateProgress,
                    bstrInputFileContents,
                    e,
                    e.CurrentExpression ?? e.CurrentStatement);
            }
            catch (AphidRuntimeException e)
            {
                WriteError(
                    pGenerateProgress,
                    bstrInputFileContents,
                    e,
                    e.CurrentExpression ?? e.CurrentStatement);
            }
            catch (Exception e)
            {
                WriteError(
                    pGenerateProgress,
                    bstrInputFileContents,
                    e);
            }

            var bytes = csOut?.GetBytes();

            if (bytes == null || bytes.Length == 0)
            {
                rgbOutputFileContents[0] = IntPtr.Zero;
                pcbOutput = 0;
            }
            else
            {
                rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length);
                Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length);
                pcbOutput = (uint)bytes.Length;
            }

            //pGenerateProgress.GeneratorError(

            return(result);
        }
Exemple #11
0
 public void InterpretFile([PexAssumeUnderTest] AphidInterpreter target, string filename)
 {
     target.InterpretFile(filename);
     // TODO: add assertions to method AphidInterpreterTest.InterpretFile(AphidInterpreter, String)
 }