Ejemplo n.º 1
0
        public static (Language lang, Cons ast) GenerateAst(string text)
        {
            Tokenizer tokenizer = new Tokenizer(text: text,
                                                seperators: new char[] { ' ', '\n' },
                                                singles: new char[] { '(', ')', '[', ']' },
                                                whiteList: new Tokenizer.SelfExistentToken('"', '"'));

            tokenizer.CleanUpTokens();
            _tokens = Cons.FromArray(tokenizer.Tokens);
            if (_tokens.car as string == "#lang")
            {
                string lang = (_tokens.cdr as Cons).car as string;
                _tokens = (_tokens.cdr as Cons).cdr as Cons;
                if (lang == "SuckerML")
                {
                    // 调用 SuckerML 解释器
                    return(Language.SuckerML, GenerateAst());
                }
                else if (lang == "SuckerScript")
                {
                    // 调用 SuckerScript 解释器
                    return(Language.SuckerScript, GenerateAst());
                }
                else
                {
                    throw new FormatException($"语言指示符不存在:#lang {lang}");
                }
            }
            else
            {
                throw new FormatException("缺失语言指示符 #lang");
            }
        }
Ejemplo n.º 2
0
        public static Cons GenerateAst(string text)
        {
            Tokenizer tokenizer = new Tokenizer(text, new char[] { ' ', '\n' }, new char[] { '(', ')', '[', ']' });

            tokenizer.CleanUpTokens();
            _tokens = Cons.FromArray(tokenizer.Tokens);
            if (_tokens.car as string == "#lang")
            {
                string lang = (_tokens.cdr as Cons).car as string;
                _tokens = (_tokens.cdr as Cons).cdr as Cons;
                if (lang == "SuckerML")
                {
                    // 调用 SuckerML 解释器
                    return(GenerateAst());
                }
                else if (lang == "SuckerScript")
                {
                    // 调用 SuckerScript 解释器
                    return(GenerateAst());
                }
                else
                {
                    throw new FormatException($"语言指示符不存在:{lang}");
                }
            }
            else
            {
                throw new FormatException("缺失语言指示符 #lang");
            }
        }
Ejemplo n.º 3
0
        internal IronSchemeLanguageProvider(ScriptDomainManager x)
            : base(x)
        {
            ScriptDomainManager.Options.DynamicStackTraceSupport = false;

            Runtime.Closure.ConsFromArray     = Runtime.Cons.FromArray;
            Runtime.Closure.ConsStarFromArray = delegate(object[] args) { return(Builtins.ToImproper(Cons.FromArray(args))); };
            Runtime.Closure.Unspecified       = Builtins.Unspecified;
            Runtime.Closure.ArrayFromCons     = Builtins.ListToVector;

            Initialize();

            // only register when done
            x.RegisterLanguageProvider("IronScheme", "IronScheme.Hosting.IronSchemeLanguageProvider", ".sps", ".ss", ".sls");
        }