📄 ruby.stg
字号:
look_ahead_<decisionNumber>_<stateNumber> = <LA(1)> <endif> s = -1 <edges> return s if s >= 0 >>/** Just like a fixed DFA edge, test the lookahead and indicate what * state to jump to next if successful. Again, this is for special * states. */cyclicDFAEdge(labelExpr, targetStateNumber, edgeNumber, predicates)::=<<return s = <targetStateNumber> if (<labelExpr>) <if(predicates)>&& (<predicates>)<endif><\n>>>/** An edge pointing at end-of-token; essentially matches any char; * always jump to the target. */eotDFAEdge(targetStateNumber,edgeNumber, predicates)::=<<s = <targetStateNumber><\n>>>// D F A E X P R E S S I O N SandPredicates(left,right)::= "(<left> && <right>)"orPredicates(operands)::=<<(<operands; separator=" || ">)>>notPredicate(pred)::= "!(<evalPredicate(...)>)"evalPredicate(pred,description)::= "(<pred>)"evalSynPredicate(pred,description)::= "<pred>()"/** * It's not really clear that decisionNumber and stateNumber are available here */lookaheadTest(atom,k,atomAsInt)::=<<<if(LEXER)>look_ahead<decisionNumber>_<stateNumber> == <atom><else>look_ahead<decisionNumber>_<stateNumber> == :<atom><endif>>>/** Sometimes a lookahead test cannot assume that LA(k) is in a temp variable * somewhere. Must ask for the lookahead directly. */isolatedLookaheadTest(atom,k,atomAsInt) ::=<<<if(LEXER)><LA(k)> == <atom><else><LA(k)> == :<atom><endif>>>/** * It's not really clear that decisionNumber and stateNumber are available here */lookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt)::=<<<if(LEXER)>(look_ahead<decisionNumber>_<stateNumber> \>= <lower> && look_ahead<decisionNumber>_<stateNumber> \<= <upper>)<else>(TOKENS[look_ahead<decisionNumber>_<stateNumber>] \>= <lowerAsInt> && TOKENS[look_ahead<decisionNumber>_<stateNumber>] \<= <upperAsInt>)<endif>>>isolatedLookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt) ::=<<<if(LEXER)>(<LA(k)> \>= <lower> && <LA(k)> \<= <upper>)<else>(TOKENS[<LA(k)>] \>= <lowerAsInt> && TOKENS[<LA(k)>] \<= <upperAsInt>)<endif>>>setTest(ranges) ::=<<<ranges; separator=" || ">>>// A T T R I B U T E SparameterAttributeRef(attr)::=<< raise "parameterAttributeRef not implemented">>parameterSetAttributeRef(attr,expr) ::=<< raise "parameterSetAttributeRef not implemented">>scopeAttributeRef(scope,attr,index,negIndex)::=<< raise "scopeAttributeRef not implemented">>scopeSetAttributeRef(scope,attr,expr,index,negIndex) ::=<< raise "scopeSetAttributeRef not implemented">>/** $x is either global scope or x is rule with dynamic scope; refers * to stack itself not top of stack. This is useful for predicates * like {$function.size()>0 && $function::name.equals("foo")}? */isolatedDynamicScopeRef(scope)::=<< raise "isolatedDynamicScopeRef not implemented">>/** reference an attribute of rule; might only have single return value */ruleLabelRef(referencedRule,scope,attr)::=<< raise "ruleLabelRef not implemented">>returnAttributeRef(ruleDescriptor,attr)::=<< raise "returnAttributeRef not implemented">>returnSetAttributeRef(ruleDescriptor,attr,expr) ::=<< raise "returnSetAttributeRef not implemented">>/** How to translate $tokenLabel */tokenLabelRef(label)::= "_<label>"/** ids+=ID {$ids} or e+=expr {$e} */listLabelRef(label)::= "list_<label>"// not sure the next are the right approach; and they are evaluated early;// they cannot see TREE_PARSER or PARSER attributes for example. :(tokenLabelPropertyRef_text(scope,attr)::= "_<scope>.text"tokenLabelPropertyRef_type(scope,attr)::= "_<scope>.token_type"tokenLabelPropertyRef_line(scope,attr)::= "_<scope>.line"tokenLabelPropertyRef_pos(scope,attr) ::= "_<scope>.pos"tokenLabelPropertyRef_channel(scope,attr)::= "_<scope>.channel"tokenLabelPropertyRef_index(scope,attr)::= "_<scope>.index"tokenLabelPropertyRef_tree(scope,attr)::= << raise "tokenLabelPropertyRef_tree not implemented" >>ruleLabelPropertyRef_start(scope,attr)::=<< raise "ruleLabelPropertyRef_start not implemented">>ruleLabelPropertyRef_stop(scope,attr)::=<< raise "ruleLabelPropertyRef_stop not implemented">>ruleLabelPropertyRef_tree(scope,attr)::=<< raise "ruleLabelPropertyRef_tree not implemented">>ruleLabelPropertyRef_text(scope,attr)::=<< raise "ruleLabelPropertyRef_text not implemented">>ruleLabelPropertyRef_st(scope,attr)::=<< raise "ruleLabelPropertyRef_st not implemented">>/** Isolated $RULE ref ok in lexer as it's a Token */lexerRuleLabel(label)::=<< raise "lexerRuleLabel not implemented">>lexerRuleLabelPropertyRef_type(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_type not implemented">>lexerRuleLabelPropertyRef_line(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_line not implemented">>lexerRuleLabelPropertyRef_pos(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_pos not implemented">>lexerRuleLabelPropertyRef_channel(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_channel not implemented">>lexerRuleLabelPropertyRef_index(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_index not implemented">>lexerRuleLabelPropertyRef_text(scope,attr)::=<< raise "lexerRuleLabelPropertyRef_text not implemented">>lexerRulePropertyRef_text(scope,attr) ::= << raise "lexerRulePropertyRef_text not implemented">>lexerRulePropertyRef_type(scope,attr) ::= << raise "lexerRulePropertyRef_type not implemented">>lexerRulePropertyRef_line(scope,attr) ::= << raise "lexerRulePropertyRef_line not implemented">>lexerRulePropertyRef_pos(scope,attr) ::= << raise "lexerRulePropertyRef_pos not implemented">>lexerRulePropertyRef_index(scope,attr) ::= << raise "lexerRulePropertyRef_index not implemented">>lexerRulePropertyRef_channel(scope,attr) ::= << raise "lexerRulePropertyRef_channel not implemented">>lexerRulePropertyRef_start(scope,attr) ::= << raise "lexerRulePropertyRef_start not implemented">>lexerRulePropertyRef_stop(scope,attr) ::= << raise "lexerRulePropertyRef_stop not implemented">>ruleSetPropertyRef_tree(scope,attr,expr) ::= << raise "ruleSetPropertyRef_tree not implemented">>ruleSetPropertyRef_st(scope,attr,expr) ::= << raise "ruleSetPropertyRef_st not implemented">>// Somebody may ref $template or $tree or $stop within a rule:rulePropertyRef_start(scope,attr)::=<< raise "rulePropertyRef_start not implemented">>rulePropertyRef_stop(scope,attr)::=<< raise "rulePropertyRef_stop not implemented">>rulePropertyRef_tree(scope,attr)::=<< raise "rulePropertyRef_tree not implemented">>rulePropertyRef_text(scope,attr)::=<< raise "rulePropertyRef_text not implemented">>rulePropertyRef_st(scope,attr)::=<< raise "rulePropertyRef_st not implemented">>/** How to execute an action *//** TODO: add syntactic predicate & bactracking gates **/execAction(action)::=<<<action>>>// M I S C (properties, etc...)codeFileExtension()::=".rb"true()::= "true"false()::= "false"///////////// --------------------------- private templates --------------------------------bitset()::=<< raise "bitset not implemented">>element() ::= "<it.el>"plainBlock(decls, alts, description) ::=<<<decls><alts>>>switchBlock(description, decisionNumber, maxAlt, alts, decls, decision) ::=<<# <description>alt<decisionNumber> = <maxAlt><decls><decision>case alt<decisionNumber> <alts:switchCase(); separator="\n">end>>switchCase() ::=<<when <i> <it>>>LA(k) ::=<<<if(LEXER)>@input.look_ahead(<k>)<else>look_ahead(<k>)<endif>>>synpred(name) ::= <<def <name> start = @input.mark() @backtracking += 1 <name>_fragment() @backtracking -= 1 success = !@failed @input.rewind(start) @failed = false return successend>>parameterScope(scope) ::= <<<scope.attributes:{<it.decl>}; separator=", ">>>dfaClass() ::= <<<if(cyclicDFAs)> class DFA def initialize(eot, eof, min, max, accept, special, transition) @eot = eot @eof = eof @min = min @max = max @accept = accept @special = special @transition = transition end def predict(parser, input) mark = input.mark() s = 0 # we always start at s0 begin loop do special_state = @special[s] if special_state >= 0 s = parser.special_state_transition(special_state) input.consume() next end if @accept[s] >= 1 return @accept[s] end # look for a normal char transition c = input.look_ahead(1).to_i if c != :EOF && c >= @min[s] && c \<= @max[s] next_state = @transition[s][c - @min[s]] # move to next state if next_state \< 0 # was in range but not a normal transition # must check EOT, which is like the else clause. # eot[s]>=0 indicates that an EOT edge goes to another # state. if @eot[s] >= 0 # EOT Transition to accept state? s = @eot[s] input.consume() next end raise "No viable alt" end s = next_state input.consume() next end if @eot[s] >= 0 # EOT Transition? s = @eot[s] input.consume() next end if c == :EOF && @eof[s] >= 0 # EOF Transition to accept state? return @accept[@eof[s]] end # not in range and not EOF/EOT, must be invalid symbol raise "No viable alt" end ensure input.rewind(mark) end end end <endif>>>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -