Exemplo n.º 1
0
        public CatAstNode(PegAstNode node)
        {
            if (node.GetLabel() != null)
            {
                mLabel = (AstLabel)node.GetLabel();
            }
            else
            {
                mLabel = AstLabel.AstRoot;
            }

            msText = node.ToString();
        }
Exemplo n.º 2
0
        public RubyAstNode(PegAstNode node)
        {
            if (node.GetLabel() != null)
            {
                mLabel = (ASTNodeType)node.GetLabel();
            }
            else
            {
                mLabel = ASTNodeType.SELF;
            }

            mText = node.ToString();
        }
Exemplo n.º 3
0
        public AstDef(PegAstNode node)
            : base(node)
        {
            CheckLabel(AstLabel.Def);

            if (node.GetNumChildren() == 0)
            {
                throw new Exception("invalid function definition node");
            }

            AstName name = new AstName(node.GetChild(0));

            mName = name.ToString();

            int n = 1;

            // Look to see if a type is defined
            if ((node.GetNumChildren() >= 2) && (node.GetChild(1).GetLabel().Equals(AstLabel.FxnType)))
            {
                mType = new AstFxnType(node.GetChild(1));
                ++n;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                {
                    break;
                }

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Param))
                {
                    break;
                }

                mParams.Add(new AstParam(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.MetaDataBlock))
                {
                    break;
                }

                mpMetaData = new AstMetaDataBlock(child);
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);

                if (!child.GetLabel().Equals(AstLabel.Def))
                {
                    break;
                }

                mLocals.Add(new AstDef(child));
                n++;
            }

            while (n < node.GetNumChildren())
            {
                PegAstNode child = node.GetChild(n);
                CatAstNode expr  = Create(child);

                if (!(expr is AstExpr))
                {
                    throw new Exception("expected expression node");
                }

                mTerms.Add(expr as AstExpr);
                n++;
            }
        }
Exemplo n.º 4
0
        public static CatAstNode Create(PegAstNode node)
        {
            AstLabel label = (AstLabel)node.GetLabel();

            switch (label)
            {
            case AstLabel.AstRoot:
                return(new AstRoot(node));

            case AstLabel.Def:
                return(new AstDef(node));

            case AstLabel.Name:
                return(new AstName(node));

            case AstLabel.Param:
                return(new AstParam(node));

            case AstLabel.Lambda:
                return(new AstLambda(node));

            case AstLabel.Quote:
                return(new AstQuote(node));

            case AstLabel.Char:
                return(new AstChar(node));

            case AstLabel.String:
                return(new AstString(node));

            case AstLabel.Float:
                return(new AstFloat(node));

            case AstLabel.Int:
                return(new AstInt(node));

            case AstLabel.Bin:
                return(new AstBin(node));

            case AstLabel.Hex:
                return(new AstHex(node));

            case AstLabel.Stack:
                return(new AstStack(node));

            case AstLabel.FxnType:
                return(new AstFxnType(node));

            case AstLabel.TypeVar:
                return(new AstTypeVar(node));

            case AstLabel.TypeName:
                return(new AstSimpleType(node));

            case AstLabel.StackVar:
                return(new AstStackVar(node));

            case AstLabel.MacroRule:
                return(new AstMacro(node));

            case AstLabel.MacroProp:
                return(new AstMacro(node));

            case AstLabel.MacroPattern:
                return(new AstMacroPattern(node));

            case AstLabel.MacroQuote:
                return(new AstMacroQuote(node));

            case AstLabel.MacroTypeVar:
                return(new AstMacroTypeVar(node));

            case AstLabel.MacroStackVar:
                return(new AstMacroStackVar(node));

            case AstLabel.MacroName:
                return(new AstMacroName(node));

            case AstLabel.MetaDataContent:
                return(new AstMetaDataContent(node));

            case AstLabel.MetaDataLabel:
                return(new AstMetaDataLabel(node));

            case AstLabel.MetaDataBlock:
                return(new AstMetaDataBlock(node));

            default:
                throw new Exception("unrecognized node type in AST tree: " + label);
            }
        }
Exemplo n.º 5
0
        public static RubyAstNode Create(PegAstNode node)
        {
            ASTNodeType label = (ASTNodeType)node.GetLabel();

            if (node.GetLabel() != null)
            {
                return(new RubyTestAstNode(label, node.ToString()));
            }

            switch (label)
            {
            //case ASTNodeType.AstRoot:
            //	return new AstRoot ( node );
            //case ASTNodeType.Def:
            //	return new AstDef ( node );
            //case ASTNodeType.Name:
            //	return new AstName ( node );
            //case ASTNodeType.Param:
            //	return new AstParam ( node );
            //case ASTNodeType.Lambda:
            //	return new AstLambda ( node );
            //case ASTNodeType.Quote:
            //	return new AstQuote ( node );
            //case ASTNodeType.Char:
            //	return new AstChar ( node );
            //case ASTNodeType.String:
            //	return new AstString ( node );
            //case ASTNodeType.Float:
            //	return new AstFloat ( node );
            //case ASTNodeType.Int:
            //	return new AstInt ( node );
            //case ASTNodeType.Bin:
            //	return new AstBin ( node );
            //case ASTNodeType.Hex:
            //	return new AstHex ( node );
            //case ASTNodeType.Stack:
            //	return new AstStack ( node );
            //case ASTNodeType.FxnType:
            //	return new AstFxnType ( node );
            //case ASTNodeType.TypeVar:
            //	return new AstTypeVar ( node );
            //case ASTNodeType.TypeName:
            //	return new AstSimpleType ( node );
            //case ASTNodeType.StackVar:
            //	return new AstStackVar ( node );
            //case ASTNodeType.MacroRule:
            //	return new AstMacro ( node );
            //case ASTNodeType.MacroProp:
            //	return new AstMacro ( node );
            //case ASTNodeType.MacroPattern:
            //	return new AstMacroPattern ( node );
            //case ASTNodeType.MacroQuote:
            //	return new AstMacroQuote ( node );
            //case ASTNodeType.MacroTypeVar:
            //	return new AstMacroTypeVar ( node );
            //case ASTNodeType.MacroStackVar:
            //	return new AstMacroStackVar ( node );
            //case ASTNodeType.MacroName:
            //	return new AstMacroName ( node );
            //case ASTNodeType.MetaDataContent:
            //	return new AstMetaDataContent ( node );
            //case ASTNodeType.MetaDataLabel:
            //	return new AstMetaDataLabel ( node );
            //case ASTNodeType.MetaDataBlock:
            //	return new AstMetaDataBlock ( node );
            default:
                throw new Exception("unrecognized node type in AST tree: " + label);
            }
        }