コード例 #1
0
        public static CatFxnType Create(string sType)
        {
            if (sType.Length == 0)
            {
                return(null);
            }

            Peg.Parser p = new Peg.Parser(sType);
            try {
                if (!p.Parse(CatGrammar.FxnType()))
                {
                    throw new Exception("no additional information");
                }
            } catch (Exception e) {
                throw new Exception(sType + " is not a valid function type ", e);
            }

            Peg.PegAstNode ast = p.GetAst();
            if (ast.GetNumChildren() != 1)
            {
                throw new Exception("invalid number of children in abstract syntax tree");
            }
            AstFxnType node = new AstFxnType(ast.GetChild(0));
            CatFxnType ret  = new CatFxnType(node);

            return(ret);
        }
コード例 #2
0
ファイル: CatMetaData.cs プロジェクト: tangentforks/catlang
        public static CatMetaDataBlock Create(string s)
        {
            s = "{{\n" + s + "\n}}\n";
            Peg.Parser parser  = new Peg.Parser(s);
            bool       bResult = parser.Parse(CatGrammar.MetaDataBlock());

            if (!bResult)
            {
                throw new Exception("failed to parse meta-data block");
            }
            Peg.PegAstNode tree = parser.GetAst();
            if (tree.GetNumChildren() == 0)
            {
                return(null);
            }
            if (tree.GetNumChildren() != 1)
            {
                throw new Exception("invalid number of child nodes in meta-data block node");
            }
            AstMetaDataBlock node = new AstMetaDataBlock(tree.GetChild(0));
            CatMetaDataBlock ret  = new CatMetaDataBlock(node);

            return(ret);
        }