Inheritance: Antlr.Runtime.ParserRuleReturnScope
Exemple #1
0
    // $ANTLR start "variable"
    // D:\\lesscss.g:31:10: fragment variable : '@' IDENT ':' ( additiveExpression -> IDENT ^( EXPR additiveExpression ) | literal -> IDENT ^( LITERAL literal ) ) ';' ;
    public lesscssParser.variable_return variable() // throws RecognitionException [1]
    {   
        lesscssParser.variable_return retval = new lesscssParser.variable_return();
        retval.Start = input.LT(1);

        CommonTree root_0 = null;

        IToken char_literal2 = null;
        IToken IDENT3 = null;
        IToken char_literal4 = null;
        IToken char_literal7 = null;
        lesscssParser.additiveExpression_return additiveExpression5 = null;

        lesscssParser.literal_return literal6 = null;


        CommonTree char_literal2_tree=null;
        CommonTree IDENT3_tree=null;
        CommonTree char_literal4_tree=null;
        CommonTree char_literal7_tree=null;
        RewriteRuleTokenStream stream_IDENT = new RewriteRuleTokenStream(adaptor,"token IDENT");
        RewriteRuleTokenStream stream_30 = new RewriteRuleTokenStream(adaptor,"token 30");
        RewriteRuleTokenStream stream_32 = new RewriteRuleTokenStream(adaptor,"token 32");
        RewriteRuleTokenStream stream_31 = new RewriteRuleTokenStream(adaptor,"token 31");
        RewriteRuleSubtreeStream stream_additiveExpression = new RewriteRuleSubtreeStream(adaptor,"rule additiveExpression");
        RewriteRuleSubtreeStream stream_literal = new RewriteRuleSubtreeStream(adaptor,"rule literal");
        try 
    	{
            // D:\\lesscss.g:32:2: ( '@' IDENT ':' ( additiveExpression -> IDENT ^( EXPR additiveExpression ) | literal -> IDENT ^( LITERAL literal ) ) ';' )
            // D:\\lesscss.g:32:4: '@' IDENT ':' ( additiveExpression -> IDENT ^( EXPR additiveExpression ) | literal -> IDENT ^( LITERAL literal ) ) ';'
            {
            	char_literal2=(IToken)Match(input,30,FOLLOW_30_in_variable114);  
            	stream_30.Add(char_literal2);

            	IDENT3=(IToken)Match(input,IDENT,FOLLOW_IDENT_in_variable116);  
            	stream_IDENT.Add(IDENT3);

            	char_literal4=(IToken)Match(input,31,FOLLOW_31_in_variable118);  
            	stream_31.Add(char_literal4);

            	// D:\\lesscss.g:32:18: ( additiveExpression -> IDENT ^( EXPR additiveExpression ) | literal -> IDENT ^( LITERAL literal ) )
            	int alt2 = 2;
            	int LA2_0 = input.LA(1);

            	if ( (LA2_0 == NUM || LA2_0 == COLOR || LA2_0 == 30 || LA2_0 == 37) )
            	{
            	    alt2 = 1;
            	}
            	else if ( ((LA2_0 >= IDENT && LA2_0 <= STRING)) )
            	{
            	    alt2 = 2;
            	}
            	else 
            	{
            	    NoViableAltException nvae_d2s0 =
            	        new NoViableAltException("", 2, 0, input);

            	    throw nvae_d2s0;
            	}
            	switch (alt2) 
            	{
            	    case 1 :
            	        // D:\\lesscss.g:32:19: additiveExpression
            	        {
            	        	PushFollow(FOLLOW_additiveExpression_in_variable121);
            	        	additiveExpression5 = additiveExpression();
            	        	state.followingStackPointer--;

            	        	stream_additiveExpression.Add(additiveExpression5.Tree);


            	        	// AST REWRITE
            	        	// elements:          IDENT, additiveExpression
            	        	// token labels:      
            	        	// rule labels:       retval
            	        	// token list labels: 
            	        	// rule list labels:  
            	        	// wildcard labels: 
            	        	retval.Tree = root_0;
            	        	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);

            	        	root_0 = (CommonTree)adaptor.GetNilNode();
            	        	// 32:38: -> IDENT ^( EXPR additiveExpression )
            	        	{
            	        	    adaptor.AddChild(root_0, stream_IDENT.NextNode());
            	        	    // D:\\lesscss.g:32:47: ^( EXPR additiveExpression )
            	        	    {
            	        	    CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            	        	    root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(EXPR, "EXPR"), root_1);

            	        	    adaptor.AddChild(root_1, stream_additiveExpression.NextTree());

            	        	    adaptor.AddChild(root_0, root_1);
            	        	    }

            	        	}

            	        	retval.Tree = root_0;retval.Tree = root_0;
            	        }
            	        break;
            	    case 2 :
            	        // D:\\lesscss.g:32:76: literal
            	        {
            	        	PushFollow(FOLLOW_literal_in_variable135);
            	        	literal6 = literal();
            	        	state.followingStackPointer--;

            	        	stream_literal.Add(literal6.Tree);


            	        	// AST REWRITE
            	        	// elements:          literal, IDENT
            	        	// token labels:      
            	        	// rule labels:       retval
            	        	// token list labels: 
            	        	// rule list labels:  
            	        	// wildcard labels: 
            	        	retval.Tree = root_0;
            	        	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);

            	        	root_0 = (CommonTree)adaptor.GetNilNode();
            	        	// 32:84: -> IDENT ^( LITERAL literal )
            	        	{
            	        	    adaptor.AddChild(root_0, stream_IDENT.NextNode());
            	        	    // D:\\lesscss.g:32:93: ^( LITERAL literal )
            	        	    {
            	        	    CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            	        	    root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(LITERAL, "LITERAL"), root_1);

            	        	    adaptor.AddChild(root_1, stream_literal.NextTree());

            	        	    adaptor.AddChild(root_0, root_1);
            	        	    }

            	        	}

            	        	retval.Tree = root_0;retval.Tree = root_0;
            	        }
            	        break;

            	}

            	char_literal7=(IToken)Match(input,32,FOLLOW_32_in_variable148);  
            	stream_32.Add(char_literal7);


            }

            retval.Stop = input.LT(-1);

            	retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
    // $ANTLR start "variable"
    // D:\\development\\Less.Net\\lesscss.g:32:10: fragment variable : '@' IDENT ':' ( literal -> ^( VAR IDENT ^( LITERAL literal ) ) | expression -> ^( VAR IDENT expression ) ) ';' ;
    public lesscssParser.variable_return variable() // throws RecognitionException [1]
    {   
        lesscssParser.variable_return retval = new lesscssParser.variable_return();
        retval.Start = input.LT(1);

        CommonTree root_0 = null;

        IToken char_literal2 = null;
        IToken IDENT3 = null;
        IToken char_literal4 = null;
        IToken char_literal7 = null;
        lesscssParser.literal_return literal5 = default(lesscssParser.literal_return);

        lesscssParser.expression_return expression6 = default(lesscssParser.expression_return);


        CommonTree char_literal2_tree=null;
        CommonTree IDENT3_tree=null;
        CommonTree char_literal4_tree=null;
        CommonTree char_literal7_tree=null;
        RewriteRuleTokenStream stream_IDENT = new RewriteRuleTokenStream(adaptor,"token IDENT");
        RewriteRuleTokenStream stream_26 = new RewriteRuleTokenStream(adaptor,"token 26");
        RewriteRuleTokenStream stream_27 = new RewriteRuleTokenStream(adaptor,"token 27");
        RewriteRuleTokenStream stream_28 = new RewriteRuleTokenStream(adaptor,"token 28");
        RewriteRuleSubtreeStream stream_expression = new RewriteRuleSubtreeStream(adaptor,"rule expression");
        RewriteRuleSubtreeStream stream_literal = new RewriteRuleSubtreeStream(adaptor,"rule literal");
        try 
    	{
            // D:\\development\\Less.Net\\lesscss.g:33:2: ( '@' IDENT ':' ( literal -> ^( VAR IDENT ^( LITERAL literal ) ) | expression -> ^( VAR IDENT expression ) ) ';' )
            // D:\\development\\Less.Net\\lesscss.g:33:4: '@' IDENT ':' ( literal -> ^( VAR IDENT ^( LITERAL literal ) ) | expression -> ^( VAR IDENT expression ) ) ';'
            {
            	char_literal2=(IToken)Match(input,26,FOLLOW_26_in_variable118);  
            	stream_26.Add(char_literal2);

            	IDENT3=(IToken)Match(input,IDENT,FOLLOW_IDENT_in_variable120);  
            	stream_IDENT.Add(IDENT3);

            	char_literal4=(IToken)Match(input,27,FOLLOW_27_in_variable122);  
            	stream_27.Add(char_literal4);

            	// D:\\development\\Less.Net\\lesscss.g:33:18: ( literal -> ^( VAR IDENT ^( LITERAL literal ) ) | expression -> ^( VAR IDENT expression ) )
            	int alt2 = 2;
            	int LA2_0 = input.LA(1);

            	if ( ((LA2_0 >= IDENT && LA2_0 <= STRING)) )
            	{
            	    alt2 = 1;
            	}
            	else if ( (LA2_0 == COLOR || LA2_0 == NUM || LA2_0 == 26 || LA2_0 == 34) )
            	{
            	    alt2 = 2;
            	}
            	else 
            	{
            	    NoViableAltException nvae_d2s0 =
            	        new NoViableAltException("", 2, 0, input);

            	    throw nvae_d2s0;
            	}
            	switch (alt2) 
            	{
            	    case 1 :
            	        // D:\\development\\Less.Net\\lesscss.g:33:19: literal
            	        {
            	        	PushFollow(FOLLOW_literal_in_variable125);
            	        	literal5 = literal();
            	        	state.followingStackPointer--;

            	        	stream_literal.Add(literal5.Tree);


            	        	// AST REWRITE
            	        	// elements:          IDENT, literal
            	        	// token labels:      
            	        	// rule labels:       retval
            	        	// token list labels: 
            	        	// rule list labels:  
            	        	// wildcard labels: 
            	        	retval.Tree = root_0;
            	        	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);

            	        	root_0 = (CommonTree)adaptor.GetNilNode();
            	        	// 33:27: -> ^( VAR IDENT ^( LITERAL literal ) )
            	        	{
            	        	    // D:\\development\\Less.Net\\lesscss.g:33:30: ^( VAR IDENT ^( LITERAL literal ) )
            	        	    {
            	        	    CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            	        	    root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(VAR, "VAR"), root_1);

            	        	    adaptor.AddChild(root_1, stream_IDENT.NextNode());
            	        	    // D:\\development\\Less.Net\\lesscss.g:33:42: ^( LITERAL literal )
            	        	    {
            	        	    CommonTree root_2 = (CommonTree)adaptor.GetNilNode();
            	        	    root_2 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(LITERAL, "LITERAL"), root_2);

            	        	    adaptor.AddChild(root_2, stream_literal.NextTree());

            	        	    adaptor.AddChild(root_1, root_2);
            	        	    }

            	        	    adaptor.AddChild(root_0, root_1);
            	        	    }

            	        	}

            	        	retval.Tree = root_0;retval.Tree = root_0;
            	        }
            	        break;
            	    case 2 :
            	        // D:\\development\\Less.Net\\lesscss.g:33:64: expression
            	        {
            	        	PushFollow(FOLLOW_expression_in_variable143);
            	        	expression6 = expression();
            	        	state.followingStackPointer--;

            	        	stream_expression.Add(expression6.Tree);


            	        	// AST REWRITE
            	        	// elements:          IDENT, expression
            	        	// token labels:      
            	        	// rule labels:       retval
            	        	// token list labels: 
            	        	// rule list labels:  
            	        	// wildcard labels: 
            	        	retval.Tree = root_0;
            	        	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);

            	        	root_0 = (CommonTree)adaptor.GetNilNode();
            	        	// 33:75: -> ^( VAR IDENT expression )
            	        	{
            	        	    // D:\\development\\Less.Net\\lesscss.g:33:78: ^( VAR IDENT expression )
            	        	    {
            	        	    CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            	        	    root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(VAR, "VAR"), root_1);

            	        	    adaptor.AddChild(root_1, stream_IDENT.NextNode());
            	        	    adaptor.AddChild(root_1, stream_expression.NextTree());

            	        	    adaptor.AddChild(root_0, root_1);
            	        	    }

            	        	}

            	        	retval.Tree = root_0;retval.Tree = root_0;
            	        }
            	        break;

            	}

            	char_literal7=(IToken)Match(input,28,FOLLOW_28_in_variable156);  
            	stream_28.Add(char_literal7);


            }

            retval.Stop = input.LT(-1);

            	retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }