⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actiontranslatorlexer.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
              			st.setAttribute("attr", scope.getAttribute(y.getText()));              			st.setAttribute("expr", translateAction(expr.getText()));              		}              		else { // must be return value              			st = template("returnSetAttributeRef");              			st.setAttribute("ruleDescriptor", enclosingRule);              			st.setAttribute("attr", scope.getAttribute(y.getText()));              			st.setAttribute("expr", translateAction(expr.getText()));              		}              		            }            }            if ( backtracking==1 ) {                      if ( token==null && ruleNestingLevel==1 ) {                          emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);                      }                                  }    }        finally {            ruleNestingLevel--;        }    }    // $ANTLR end SET_ENCLOSING_RULE_SCOPE_ATTR    // $ANTLR start ENCLOSING_RULE_SCOPE_ATTR    public void mENCLOSING_RULE_SCOPE_ATTR() throws RecognitionException {        try {            ruleNestingLevel++;            int _type = ENCLOSING_RULE_SCOPE_ATTR;            int _start = getCharIndex();            int _line = getLine();            int _charPosition = getCharPositionInLine();            int _channel = Token.DEFAULT_CHANNEL;            // ActionTranslator.g:246:4: ( '$' x= ID '.' y= ID {...}?)            // ActionTranslator.g:246:4: '$' x= ID '.' y= ID {...}?            {            match('$'); if (failed) return ;            int xStart = getCharIndex();            mID(); if (failed) return ;            Token x = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, xStart, getCharIndex()-1);            match('.'); if (failed) return ;            int yStart = getCharIndex();            mID(); if (failed) return ;            Token y = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, yStart, getCharIndex()-1);            if ( !(enclosingRule!=null &&            	                         x.getText().equals(enclosingRule.name) &&            	                         enclosingRule.getLocalAttributeScope(y.getText())!=null) ) {                if (backtracking>0) {failed=true; return ;}                throw new FailedPredicateException(input, "ENCLOSING_RULE_SCOPE_ATTR", "enclosingRule!=null &&\n\t                         $x.text.equals(enclosingRule.name) &&\n\t                         enclosingRule.getLocalAttributeScope($y.text)!=null");            }            if ( backtracking==1 ) {              		StringTemplate st = null;              		AttributeScope scope = enclosingRule.getLocalAttributeScope(y.getText());              		if ( scope.isPredefinedRuleScope ) {              			st = template("rulePropertyRef_"+y.getText());              			grammar.referenceRuleLabelPredefinedAttribute(x.getText());              			st.setAttribute("scope", x.getText());              			st.setAttribute("attr", y.getText());              		}              	    else if ( scope.isPredefinedLexerRuleScope ) {              	    	// perhaps not the most precise error message to use, but...              			ErrorManager.grammarError(ErrorManager.MSG_RULE_HAS_NO_ARGS,              									  grammar,              									  actionToken,              									  x.getText());              	    }              		else if ( scope.isParameterScope ) {              			st = template("parameterAttributeRef");              			st.setAttribute("attr", scope.getAttribute(y.getText()));              		}              		else { // must be return value              			st = template("returnAttributeRef");              			st.setAttribute("ruleDescriptor", enclosingRule);              			st.setAttribute("attr", scope.getAttribute(y.getText()));              		}              		            }            }            if ( backtracking==1 ) {                      if ( token==null && ruleNestingLevel==1 ) {                          emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);                      }                                  }    }        finally {            ruleNestingLevel--;        }    }    // $ANTLR end ENCLOSING_RULE_SCOPE_ATTR    // $ANTLR start SET_TOKEN_SCOPE_ATTR    public void mSET_TOKEN_SCOPE_ATTR() throws RecognitionException {        try {            ruleNestingLevel++;            int _type = SET_TOKEN_SCOPE_ATTR;            int _start = getCharIndex();            int _line = getLine();            int _charPosition = getCharPositionInLine();            int _channel = Token.DEFAULT_CHANNEL;            // ActionTranslator.g:280:4: ( '$' x= ID '.' y= ID ( WS )? '=' {...}?)            // ActionTranslator.g:280:4: '$' x= ID '.' y= ID ( WS )? '=' {...}?            {            match('$'); if (failed) return ;            int xStart = getCharIndex();            mID(); if (failed) return ;            Token x = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, xStart, getCharIndex()-1);            match('.'); if (failed) return ;            int yStart = getCharIndex();            mID(); if (failed) return ;            Token y = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, yStart, getCharIndex()-1);            // ActionTranslator.g:280:22: ( WS )?            int alt2=2;            int LA2_0 = input.LA(1);            if ( ((LA2_0>='\t' && LA2_0<='\n')||LA2_0==' ') ) {                alt2=1;            }            switch (alt2) {                case 1 :                    // ActionTranslator.g:280:22: WS                    {                    mWS(); if (failed) return ;                    }                    break;            }            match('='); if (failed) return ;            if ( !(enclosingRule!=null && input.LA(1)!='=' &&            	                         (enclosingRule.getTokenLabel(x.getText())!=null||            	                          isTokenRefInAlt(x.getText())) &&            	                         AttributeScope.tokenScope.getAttribute(y.getText())!=null) ) {                if (backtracking>0) {failed=true; return ;}                throw new FailedPredicateException(input, "SET_TOKEN_SCOPE_ATTR", "enclosingRule!=null && input.LA(1)!='=' &&\n\t                         (enclosingRule.getTokenLabel($x.text)!=null||\n\t                          isTokenRefInAlt($x.text)) &&\n\t                         AttributeScope.tokenScope.getAttribute($y.text)!=null");            }            if ( backtracking==1 ) {              		ErrorManager.grammarError(ErrorManager.MSG_WRITE_TO_READONLY_ATTR,              								  grammar,              								  actionToken,              								  x.getText(),              								  y.getText());              		            }            }            if ( backtracking==1 ) {                      if ( token==null && ruleNestingLevel==1 ) {                          emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);                      }                                  }    }        finally {            ruleNestingLevel--;        }    }    // $ANTLR end SET_TOKEN_SCOPE_ATTR    // $ANTLR start TOKEN_SCOPE_ATTR    public void mTOKEN_SCOPE_ATTR() throws RecognitionException {        try {            ruleNestingLevel++;            int _type = TOKEN_SCOPE_ATTR;            int _start = getCharIndex();            int _line = getLine();            int _charPosition = getCharPositionInLine();            int _channel = Token.DEFAULT_CHANNEL;            // ActionTranslator.g:299:4: ( '$' x= ID '.' y= ID {...}?)            // ActionTranslator.g:299:4: '$' x= ID '.' y= ID {...}?            {            match('$'); if (failed) return ;            int xStart = getCharIndex();            mID(); if (failed) return ;            Token x = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, xStart, getCharIndex()-1);            match('.'); if (failed) return ;            int yStart = getCharIndex();            mID(); if (failed) return ;            Token y = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, yStart, getCharIndex()-1);            if ( !(enclosingRule!=null &&            	                         (enclosingRule.getTokenLabel(x.getText())!=null||            	                          isTokenRefInAlt(x.getText())) &&            	                         AttributeScope.tokenScope.getAttribute(y.getText())!=null &&            	                         (grammar.type!=Grammar.LEXER ||            	                         getElementLabel(x.getText()).elementRef.token.getType()==ANTLRParser.TOKEN_REF ||            	                         getElementLabel(x.getText()).elementRef.token.getType()==ANTLRParser.STRING_LITERAL)) ) {                if (backtracking>0) {failed=true; return ;}                throw new FailedPredicateException(input, "TOKEN_SCOPE_ATTR", "enclosingRule!=null &&\n\t                         (enclosingRule.getTokenLabel($x.text)!=null||\n\t                          isTokenRefInAlt($x.text)) &&\n\t                         AttributeScope.tokenScope.getAttribute($y.text)!=null &&\n\t                         (grammar.type!=Grammar.LEXER ||\n\t                         getElementLabel($x.text).elementRef.token.getType()==ANTLRParser.TOKEN_REF ||\n\t                         getElementLabel($x.text).elementRef.token.getType()==ANTLRParser.STRING_LITERAL)");            }            if ( backtracking==1 ) {              		String label = x.getText();              		if ( enclosingRule.getTokenLabel(x.getText())==null ) {              			// $tokenref.attr  gotta get old label or compute new one              			checkElementRefUniqueness(x.getText(), true);              			label = enclosingRule.getElementLabel(x.getText(), outerAltNum, generator);              			if ( label==null ) {              				ErrorManager.grammarError(ErrorManager.MSG_FORWARD_ELEMENT_REF,              										  grammar,              										  actionToken,              										  "$"+x.getText()+"."+y.getText());              				label = x.getText();              			}              		}              		StringTemplate st = template("tokenLabelPropertyRef_"+y.getText());              		st.setAttribute("scope", label);              		st.setAttribute("attr", AttributeScope.tokenScope.getAttribute(y.getText()));              		            }            }            if ( backtracking==1 ) {                      if ( token==null && ruleNestingLevel==1 ) {                          emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);                      }                                  }    }        finally {            ruleNestingLevel--;        }    }    // $ANTLR end TOKEN_SCOPE_ATTR    // $ANTLR start SET_RULE_SCOPE_ATTR    public void mSET_RULE_SCOPE_ATTR() throws RecognitionException {        try {            ruleNestingLevel++;            int _type = SET_RULE_SCOPE_ATTR;            int _start = getCharIndex();            int _line = getLine();            int _charPosition = getCharPositionInLine();            int _channel = Token.DEFAULT_CHANNEL;            Grammar.LabelElementPair pair=null;            String refdRuleName=null;            // ActionTranslator.g:337:4: ( '$' x= ID '.' y= ID ( WS )? '=' {...}?{...}?)            // ActionTranslator.g:337:4: '$' x= ID '.' y= ID ( WS )? '=' {...}?{...}?            {            match('$'); if (failed) return ;            int xStart = getCharIndex();            mID(); if (failed) return ;            Token x = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, xStart, getCharIndex()-1);            match('.'); if (failed) return ;            int yStart = getCharIndex();            mID(); if (failed) return ;            Token y = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, yStart, getCharIndex()-1);            // ActionTranslator.g:337:22: ( WS )?            int alt3=2;            int LA3_0 = input.LA(1);            if ( ((LA3_0>='\t' && LA3_0<='\n')||LA3_0==' ') ) {                alt3=1;            }            switch (alt3) {                case 1 :                    // ActionTranslator.g:337:22: WS                    {                    mWS(); if (failed) return ;                    }                    break;            }            match('='); if (failed) return ;            if ( !(enclosingRule!=null && input.LA(1)!='=') ) {                if (backtracking>0) {failed=true; return ;}                throw new FailedPredicateException(input, "SET_RULE_SCOPE_ATTR", "enclosingRule!=null && input.LA(1)!='='");            }            if ( backtracking==1 ) {              		pair = enclosingRule.getRuleLabel(x.getText());              		refdRuleName = x.getText();              		if ( pair!=null ) {              			refdRuleName = pair.referencedRuleName;              		}              		            }            if ( !((enclosingRule.getRuleLabel(x.getText())!=null || isRuleRefInAlt(x.getText())) &&            	      getRuleLabelAttribute(enclosingRule.getRuleLabel(x.getText())!=null?enclosingRule.getRuleLabel(x.getText()).referencedRuleName:x.getText(),y.getText())!=null) ) {                if (backtracking>0) {failed=true; return ;}                throw new FailedPredicateException(input, "SET_RULE_SCOPE_ATTR", "(enclosingRule.getRuleLabel($x.text)!=null || isRuleRefInAlt($x.text)) &&\n\t      getRuleLabelAttribute(enclosingRule.getRuleLabel($x.text)!=null?enclosingRule.getRuleLabel($x.text).referencedRuleName:$x.text,$y.text)!=null");            }            if ( backtracking==1 ) {              		ErrorManager.grammarError(ErrorManager.MSG_WRITE_TO_READONLY_ATTR,              								  grammar,              								  actionToken,              								  x.getText(),              								  y.getText());              		            }            }            if ( backtracking==1 ) {                      if ( token==null && ruleNestingLevel==1 ) {                          emit(_type,_line,_charPosition,_channel,_start,getCharIndex()-1);                      }                                  }    }        finally {            ruleNestingLevel--;        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -