コード例 #1
0
 public AphidMember(AphidObject aphidObject, string key, AphidObject value)
 {
     _aphidObject = aphidObject;
     _key         = key;
     _value       = value;
 }
コード例 #2
0
 private static AphidInterpreter GetSessionInterpreter(AphidObject session) => (AphidInterpreter)session[AphidName.Interpreter].Value;
コード例 #3
0
 private void SetupInterpreterScope(
     AphidInterpreter interpreter,
     string codeFile,
     HttpListenerContext context,
     AphidObject session) => SetupInterpreterScope(interpreter, interpreter.CurrentScope, codeFile, context, session);
コード例 #4
0
 public void OnBound(AphidObject source)
 {
 }
コード例 #5
0
 private static void CacheConfig(AphidObject session) => session[_configCacheTime] = AphidObject.Scalar(DateTime.Now);
コード例 #6
0
ファイル: AphidSerializer.cs プロジェクト: rajpaswan/aphid
        private void ObjToString(AphidObject obj, StringBuilder s, int indent)
        {
            if (obj == null)
            {
                s.Append("null");
            }
            else if (obj.Value != null)
            {
                if (obj.Value is bool ||
                    obj.Value is decimal)
                {
                    s.Append(obj.Value);
                }
                else if (obj.Value is string)
                {
                    s.Append(string.Format("'{0}'", Escape((string)obj.Value)));
                }
                else if (obj.Value is List <AphidObject> )
                {
                    var list = (List <AphidObject>)obj.Value;
                    s.Append("[\r\n");

                    foreach (var x in list)
                    {
                        s.Append(new string(' ', (indent + 1) * 4));
                        ObjToString(x, s, indent + 1);
                        s.Append(",\r\n");
                    }

                    s.AppendFormat("{0}]", new string(' ', indent * 4));
                }
                //else if (obj.Value is AphidFunction ||
                //    obj.Value is AphidInteropFunction)
                else
                {
                    s.AppendFormat("'`{0}`'", obj.Value.GetType().Name);
                }
                //else
                //{
                //    throw new InvalidOperationException();
                //}
            }
            else
            {
                s.Append("{\r\n");

                foreach (var kvp in obj)
                {
                    if (IgnoreFunctions &&
                        (kvp.Value.Value is AphidFunction ||
                         kvp.Value.Value is AphidInteropFunction))
                    {
                        continue;
                    }

                    s.AppendFormat(
                        "{0}{1}: ",
                        new string(' ', (indent + 1) * 4),
                        kvp.Key);

                    ObjToString(kvp.Value, s, indent + 1);
                    s.Append(",\r\n");
                }

                s.AppendFormat("{0}}}", new string(' ', indent * 4));
            }
        }
コード例 #7
0
 public void OnBinding(AphidObject source)
 {
 }
コード例 #8
0
ファイル: EnvironmentLibrary.cs プロジェクト: rajpaswan/aphid
        private static AphidObject Exec(AphidObject exeObj, AphidObject argsObj, AphidObject optionsObj)
        {
            string exe = (string)exeObj.Value, args = argsObj != null ? (string)argsObj.Value : null;

            var opt = optionsObj != null?
                      optionsObj.ConvertTo <ExecOptions>() :
                          new ExecOptions();

            var process = new Process()
            {
                StartInfo = new ProcessStartInfo(exe, args)
                {
                    RedirectStandardOutput = opt.RedirectOutput,
                    RedirectStandardError  = opt.RedirectOutput,
                    UseShellExecute        = !opt.RedirectOutput,
                }
            };

            var sb = new StringBuilder();

            DataReceivedEventHandler handler = (o, e) =>
            {
                lock (sb)
                {
                    sb.AppendLine(e.Data);
                }
            };

            if (opt.RedirectOutput)
            {
                process.OutputDataReceived += handler;
                process.ErrorDataReceived  += handler;
            }

            process.Start();

            if (opt.RedirectOutput)
            {
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
            }

            if (opt.RedirectOutput || opt.WaitForExit)
            {
                process.WaitForExit();

                var retVal = new AphidObject();
                retVal.Add("exitCode", new AphidObject((decimal)process.ExitCode));

                if (opt.RedirectOutput)
                {
                    retVal.Add("output", new AphidObject(sb.ToString()));
                }

                return(retVal);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
 public void SetInitialScope([PexAssumeUnderTest] AphidInterpreter target, AphidObject scope)
 {
     target.SetInitialScope(scope);
     // TODO: add assertions to method AphidInterpreterTest.SetInitialScope(AphidInterpreter, AphidObject)
 }
コード例 #10
0
ファイル: UdpLibrary.cs プロジェクト: rajpaswan/aphid
        public static AphidObject UdpSend(AphidObject clientObj, AphidObject datagramObj, AphidObject hostObj, AphidObject portObj)
        {
            var host    = (string)hostObj.Value;
            var address = GetIPV4Address(host);
            var port    = (decimal)portObj.Value;
            var ep      = new IPEndPoint(address, (int)port);
            var buffer  = AphidByteConverter.ToBytes(datagramObj);
            var client  = (UdpClient)clientObj.Value;

            client.Send(buffer, buffer.Length, ep);

            var datagram = new Datagram()
            {
                LocalPort  = ep.Port,
                RemotePort = (int)port,
                RemoteHost = host,
                Data       = buffer,
            };

            return(AphidObject.ConvertFrom(datagram));
        }
コード例 #11
0
 public static List <AphidObject> Members(AphidObject obj)
 {
     return(obj.Select(x => new AphidObject(x.Key)).ToList());
 }
コード例 #12
0
ファイル: AlxFile.cs プロジェクト: 5l1v3r1/Aphid
        public static string From(AphidObject retVal)
        {
            var llexFile = new LLexFile();

            retVal.Bind(llexFile);
            var tokenTable = new TokenTable {
                Ignore = llexFile.Ignore
            };
            var nameInfo = LLexNameInfo.Parse(llexFile.Name);

            var 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);
                    }
                    else if (token.TokenType != null)
                    {
                        tokenTable.AddCode("return {TokenType}." + token.TokenType + ";\r\n");
                    }
                    else
                    {
                        throw new NotImplementedException(
                                  "Token with no regex, code, or type not supported.");
                    }
                }

                foreach (var keyword in mode.Keywords ?? Array.Empty <string>())
                {
                    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)
            {
                IgnoreCase = llexFile.IgnoreCase
            };
            var lexer = generator.Generate();

            return(lexer
                   .Replace("{Lexer}", nameInfo.LexerName)
                   .Replace("{Token}", nameInfo.TokenName)
                   .Replace("{TokenType}", nameInfo.TokenTypeName)
                   .Replace("{LexerNamespace}", nameInfo.Namespace));
        }