📄 drl.g
字号:
: loc='activation-group' opt_eol name=STRING ';'? opt_eol { d = new AttributeDescr( "activation-group", getString( name ) ); d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); } ;agenda_group returns [AttributeDescr d] @init { d = null; } : loc='agenda-group' opt_eol name=STRING ';'? opt_eol { d = new AttributeDescr( "agenda-group", getString( name ) ); d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); } ; duration returns [AttributeDescr d] @init { d = null; } : loc='duration' opt_eol i=INT ';'? opt_eol { d = new AttributeDescr( "duration", i.getText() ); d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); } ; normal_lhs_block[AndDescr descrs] : ( d=lhs opt_eol { descrs.addDescr( d ); } )* opt_eol ; expander_lhs_block[AndDescr descrs] @init { String lhsBlock = null; String eol = System.getProperty( "line.separator" ); List constraints = null; } : (options{greedy=false;} : text=paren_chunk loc=EOL { //only expand non null if (text != null) { if (text.trim().startsWith("-")) { if (constraints == null) { constraints = new ArrayList(); } constraints.add(runWhenExpander( text, offset(loc.getLine()))); } else { if (constraints != null) { lhsBlock = applyConstraints(constraints, lhsBlock); constraints = null; } if (lhsBlock == null) { lhsBlock = runWhenExpander( text, offset(loc.getLine())); } else { lhsBlock = lhsBlock + eol + runWhenExpander( text, offset(loc.getLine())); } } text = null; } } (EOL)* )* { //flush out any constraints left handing before the RHS lhsBlock = applyConstraints(constraints, lhsBlock); if (lhsBlock != null) { reparseLhs(lhsBlock, descrs); } } ; lhs returns [PatternDescr d] @init { d=null; } : l=lhs_or { d = l; } ; lhs_column returns [PatternDescr d] @init { d=null; } : f=fact_binding { d = f; } | f=fact { d = f; } ; fact_binding returns [PatternDescr d] @init { d=null; boolean multi=false; } : id=ID opt_eol ':' opt_eol fe=fact_expression[id.getText()] { d=fe; } ; fact_expression[String id] returns [PatternDescr pd] @init { pd = null; boolean multi = false; } : '(' opt_eol fe=fact_expression[id]opt_eol ')' { pd=fe; } | f=fact opt_eol { ((ColumnDescr)f).setIdentifier( id ); pd = f; } ( ('or'|'||') opt_eol { if ( ! multi ) { PatternDescr first = pd; pd = new OrDescr(); ((OrDescr)pd).addDescr( first ); multi=true; } } f=fact { ((ColumnDescr)f).setIdentifier( id ); ((OrDescr)pd).addDescr( f ); } )* ; fact returns [PatternDescr d] @init { d=null; } : id=dotted_name { d = new ColumnDescr( id ); } opt_eol loc='(' { d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); }opt_eol ( c=constraints { for ( Iterator cIter = c.iterator() ; cIter.hasNext() ; ) { ((ColumnDescr)d).addDescr( (PatternDescr) cIter.next() ); } } )? opt_eol endLoc=')' opt_eol { d.setEndLocation( offset(endLoc.getLine()), endLoc.getCharPositionInLine() ); } ; constraints returns [List constraints] @init { constraints = new ArrayList(); } : opt_eol (constraint[constraints]|predicate[constraints]) ( opt_eol ',' opt_eol (constraint[constraints]|predicate[constraints]))* opt_eol ; constraint[List constraints] @init { PatternDescr d = null; } : opt_eol ( fb=ID opt_eol ':' opt_eol )? f=ID { if ( fb != null ) { //System.err.println( "fb: " + fb.getText() ); //System.err.println( " f: " + f.getText() ); d = new FieldBindingDescr( f.getText(), fb.getText() ); //System.err.println( "fbd: " + d ); d.setLocation( offset(f.getLine()), f.getCharPositionInLine() ); constraints.add( d ); } } opt_eol ( op=( '==' | '>' | '>=' | '<' | '<=' | '!=' | 'contains' | 'matches' | 'excludes' ) opt_eol ( bvc=ID { d = new BoundVariableDescr( f.getText(), op.getText(), bvc.getText() ); d.setLocation( offset(f.getLine()), f.getCharPositionInLine() ); constraints.add( d ); } | lc=enum_constraint { d = new LiteralDescr( f.getText(), op.getText(), lc, true ); d.setLocation( offset(f.getLine()), f.getCharPositionInLine() ); constraints.add( d ); } | lc=literal_constraint { d = new LiteralDescr( f.getText(), op.getText(), lc ); d.setLocation( offset(f.getLine()), f.getCharPositionInLine() ); constraints.add( d ); } | rvc=retval_constraint { d = new ReturnValueDescr( f.getText(), op.getText(), rvc ); d.setLocation( offset(f.getLine()), f.getCharPositionInLine() ); constraints.add( d ); } ) )? opt_eol ; literal_constraint returns [String text] @init { text = null; } : ( t=STRING { text = getString( t ); } //t.getText(); text=text.substring( 1, text.length() - 1 ); } | t=INT { text = t.getText(); } | t=FLOAT { text = t.getText(); } | t=BOOL { text = t.getText(); } | t='null' { text = null; } ) ; enum_constraint returns [String text] @init { text = null; } : (cls=ID '.' en=ID) { text = cls.getText() + "." + en.getText(); } ; retval_constraint returns [String text] @init { text = null; } : '(' c=paren_chunk ')' { text = c; } ;predicate[List constraints] : decl=ID ':' field=ID '->' '(' text=paren_chunk ')' { PredicateDescr d = new PredicateDescr(field.getText(), decl.getText(), text ); constraints.add( d ); } ; paren_chunk returns [String text] @init { text = null; } : ( options{greedy=false;} : '(' c=paren_chunk ')' { if ( c == null ) { c = ""; } if ( text == null ) { text = "( " + c + " )"; } else { text = text + " ( " + c + " )"; } } | any=. { if ( text == null ) { text = any.getText(); } else { text = text + " " + any.getText(); } } )* ; //NOTE: this is needed as there is a bug in antlr if you sometimes use the same sub rule in multiple placesparen_chunk2 returns [String text] @init { text = null; } : ( options{greedy=false;} : '(' c=paren_chunk2 ')' { if ( c == null ) { c = ""; } if ( text == null ) { text = "( " + c + " )"; } else { text = text + " ( " + c + " )"; } } | any=. { if ( text == null ) { text = any.getText(); } else { text = text + " " + any.getText(); } } )* ; curly_chunk returns [String text] @init { text = null; } : ( options{greedy=false;} : '{' c=curly_chunk '}' { //System.err.println( "chunk [" + c + "]" ); if ( c == null ) { c = ""; } if ( text == null ) { text = "{ " + c + " }"; } else { text = text + " { " + c + " }"; } } | any=. { //System.err.println( "any [" + any.getText() + "]" ); if ( text == null ) { text = any.getText(); } else { text = text + " " + any.getText(); } } )* ; lhs_or returns [PatternDescr d] @init{ d = null; } : { OrDescr or = null; } left=lhs_and {d = left; } ( ('or'|'||') opt_eol right=lhs_and { if ( or == null ) { or = new OrDescr(); or.addDescr( left ); d = or; } or.addDescr( right ); } )* ; lhs_and returns [PatternDescr d] @init{ d = null; } : { AndDescr and = null; } left=lhs_unary { d = left; } ( ('and'|'&&') opt_eol right=lhs_unary { if ( and == null ) { and = new AndDescr(); and.addDescr( left ); d = and; } and.addDescr( right ); } )* ; lhs_unary returns [PatternDescr d] @init { d = null; } : ( u=lhs_exist | u=lhs_not | u=lhs_eval | u=lhs_column | '(' opt_eol u=lhs opt_eol ')' ) { d = u; } ; lhs_exist returns [PatternDescr d] @init { d = null; } : loc='exists' ('(' column=lhs_column ')' | column=lhs_column) { d = new ExistsDescr( (ColumnDescr) column ); d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); } ; lhs_not returns [NotDescr d] @init { d = null; } : loc='not' ('(' column=lhs_column ')' | column=lhs_column) { d = new NotDescr( (ColumnDescr) column ); d.setLocation( offset(loc.getLine()), loc.getCharPositionInLine() ); } ;lhs_eval returns [PatternDescr d] @init { d = null; String text = ""; } : 'eval' loc='(' c=paren_chunk2 ')' { checkTrailingSemicolon( c, offset(loc.getLine()) ); d = new EvalDescr( c ); } ; dotted_name returns [String name] @init { name = null; } : id=ID { name=id.getText(); } ( '.' id=ID { name = name + "." + id.getText(); } )* ( '[' ']' { name = name + "[]";})* ; argument returns [String name] @init { name = null; } : id=ID { name=id.getText(); } ( '[' ']' { name = name + "[]";})* ; word returns [String word] @init{ word = null; } : id=ID { word=id.getText(); } | 'import' { word="import"; } | 'use' { word="use"; } | 'rule' { word="rule"; } | 'query' { word="query"; } | 'salience' { word="salience"; } | 'no-loop' { word="no-loop"; } | 'when' { word="when"; } | 'then' { word="then"; } | 'end' { word="end"; } | str=STRING { word=getString(str);} //str.getText(); word=word.substring( 1, word.length()-1 ); } ;MISC : '!' | '@' | '$' | '%' | '^' | '&' | '*' | '_' | '-' | '+' | '?' | '|' | ',' | '{' | '}' | '[' | ']' | '=' | '/' | '(' | ')' | '\'' | '\\' | '||' | '&&' | '<<<' | '++' | '--' | '>>>' | '==' | '+=' | '=+' | '-=' | '=-' |'*=' | '=*' | '/=' | '=/' | '>>=' ;WS : ( ' ' | '\t' | '\f' ) { channel=99; } ; EOL : ( ( '\r\n' )=> '\r\n' // Evil DOS | '\r' // Macintosh | '\n' // Unix (the right way) ) ; INT : ('-')?('0'..'9')+ ;FLOAT : ('-')?('0'..'9')+ '.' ('0'..'9')+ ; STRING : ('"' ( options{greedy=false;} : .)* '"' ) | ('\'' ( options{greedy=false;} : .)* '\'') ; BOOL : ('true'|'false') ; ID : ('a'..'z'|'A'..'Z'|'_'|'$' | '\u00c0'..'\u00ff')('a'..'z'|'A'..'Z'|'_'|'0'..'9' | '\u00c0'..'\u00ff')* ; SH_STYLE_SINGLE_LINE_COMMENT : '#' ( options{greedy=false;} : .)* EOL /* ('\r')? '\n' */ { channel=99; } ; C_STYLE_SINGLE_LINE_COMMENT : '//' ( options{greedy=false;} : .)* EOL // ('\r')? '\n' { channel=99; } ;MULTI_LINE_COMMENT : '/*' (options{greedy=false;} : .)* '*/' { channel=99; } ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -