// |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | SLL - Service Language Layer v1.1 | // | | // | DEPARTMENT: Siemens Germany CT SE 2 | // | AUTHORS: FXL Team | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| header { import java.util.List; import java.util.LinkedList; import java.util.ArrayList; import java.util.Stack; import java.util.Iterator; import java.util.StringTokenizer; import java.lang.String; import java.util.*; import antlr.ASTFactory; import antlr.collections.*; } // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | ______ | // | (_____ \ | // | _____) )____ ____ ___ _____ ____ | // | | ____(____ |/ ___)___) ___ |/ ___) | // | | | / ___ | | |___ | ____| | | // | |_| \_____|_| (___/|_____)_| | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| class SLLParser extends Parser; options { defaultErrorHandler = true; // don't generate error handlers for the parser k = 1; // look ahead 1 token exportVocab=SLL; // vokabulry name is SLL codeGenMakeSwitchThreshold = 2; // optimize code codeGenBitsetTestThreshold = 3; buildAST= true; // in general build the AST, I will add some nodes by myself } tokens { // SLL =========|=========|=========|=========|=========|=========|=========|=========|=========| NAMESPACES;PATH;ASSIGNMENT;INSERT;DELETE;REPLACE;DESTINATION;OPERATION;INIT;INVOKE;OPERATIONS; STATEMENT;PARALLEL;CONDITION;BLOCK;COUNT;CONTEXT_VARIABLE;EXPRESSION;MODIFIERS;PUBLIC;PRIVATE; PRINT;SERVICE;DEFINITION;INTERFACE;DESCRIPTION;INTERFACES;PARTNERS;PARTNER;RESOURCES;RESOURCE; CONTACTS;CONTACT;CATEGORY;SEMANTIC;NS_NAME;BINDING;KEY;PROPERTIES;PROPERTY;THROW;LANGUAGE; RESOLUTION;QUERY;SLEEP;EMPTY;LABEL;DURATION;BOOLEAN;CASE;DEFAULT;SWITCH;CASES;WHILE;DO;FOR; FOREACH;BREAK;CONTINUE;TRY;FINALLY;CATCH;CLAUSES;TRIGGER;EVENT;ACTION;MONITOR;TIMEOUT;LIFECYCLE; STOP;DEFAULT_OP;UNKNOWN_OP;TIMEOUTS;CATCHES;EVENTS;VARIABLES;TRIGGERS;MONITORS;CONTEXTS;CONTEXT; KEY_GENERATOR;KEYS;MASTER_KEY;CUSTOM_KEY;PATTERN;TERMINATE;BODY;THROWS;SYNCHRONIZED;SEQUENCE; STATEMENTS;PROPAGATION;INCLUDE;EXCLUDE;PROPAGATIONS;ASSIGNMENTS;GET;WITH;CORRELATION;CORRELATIONS; SET;SCOPE;SCOPES;SYNC;ACTIVATE;DEACTIVATE;SYNC_POINT;TRANSACTION;COMPENSATE;PREPARE;COMMIT;ABORT; INTO;STEPS;MOVE;RENAME;TO;RETRY;RETURNS;IMPORTS;WRAPPER;MAPPING;CLASS;IMPORT;ROLES;ROLE;ALLOW;DENY; IDENTITY;ISENCRYPTED;GET_REQUEST;TRANSFORM;LOG;SI;USI;SI_RP;USI_RP;SI_RQ;USI_RQ;UEN;EN;UEN_RQ;EN_RQ; UEN_RP;EN_RP;AU;UAU;AU_RQ;UAU_RQ;AU_RP;UAU_RP;ENDPOINT;TYPES;UPDATE;PRE_OP;POST_OP;EFFECTS_OP;PART;PARTS;SEMANTIC_OPERATION; // XQUERY ======|=========|=========|=========|=========|=========|=========|=========|=========| RELATIVE_PATH;NAMESPACE_NAME;LOCAL_NAME;STEP;AXIS;NODETEST;DESCENDANT_OR_SELF;UNORDERED; NAMESPACE;IDENTIFIER;MAINMODULE;LIBRARYMODULE;URI;PROLOG;DEFAULT_NAMESPACE;DEFAULT_FUNCTION_NAMESPACE; NAME;VARIABLE;IMPORT_MODULE_NAMESPACE;IMPORT_MODULE;TYPE;AT;MODULE;TARGET;LOCATION;PARAMETERS; RETURN;ATOMIC;EXPRESSIONS;OCCURRENCE;FLWOR;WHERE;VARIABLE_BINDING;ORDER_BY;EMPTY_LEAST;EMPTY_GREATEST; IN;POSITIONAL;ASSIGN;SATISFIES;QUANTIFIED;IF;THEN;ELSE;BEFORE;AFTER;ABSOLUTE_PATH;ABSOLUTE_DSLASH; PREDICATE;PREDICATES;PREFIX_WILDCARD;UNARY_MINUS;UNARY_PLUS;WILDCARD;PARENTHESIZED;ATTRIBUTE_ENCLOSED; EXPRESSION_ENCLOSED;VALUE;CONTENT;QNAME;FUNCTION;XPOINTER;XPOINTER_ID;ELEMENT;ATTRIBUTE;TEXT; V_EQ;V_NE;V_LT;V_LE;V_GT;V_GE;VERSION;PARAMETER;ATTRIBUTES;ML_COMMENT;SL_COMMENT; } { /* class that defines a data structure to store the declated Variables * used for checking if a variable was multiple defined or not defined at all */ class SLLBlock { public SLLBlock brother = null; protected SLLBlock father = null; public SLLBlock son = null; public String blockName = null; public Map declaredVariables = null; //no parameterless constructor allowed private SLLBlock(){declaredVariables = new TreeMap(); } public SLLBlock(SLLBlock father){ if(father != this) this.father = father; declaredVariables = new TreeMap(); } public SLLBlock(SLLBlock father, String name){ if(father != this) this.father = father; this.blockName = name; declaredVariables = new TreeMap(); } public String getBlockName() { return blockName; } public void setBrother(SLLBlock brother) { brother.father = this.father; if(this.brother == null){ this.brother = brother; }else{ this.brother.setBrother(brother); } } public void deleteSons(){ this.son = null; } public boolean isDeclaredVariable(String varName){ if(varName == null) return false; if(this.declaredVariables != null && this.declaredVariables.containsKey(varName)){ return true; }else{ if(this.father != null && this.father != this){ return this.father.isDeclaredVariable(varName); } return false; }//if } //return true on success false on error public boolean declareVariable( String varName, AST type) { //System.out.println("declareVariable "+varName); if(this.declaredVariables.containsKey(varName)){ return false; }else{ String value=null; if(type != null) value = type.toString(); this.declaredVariables.put(varName, value); return true; } } public void setSon(SLLBlock son) { son.father = this; if(this.son == null){ this.son = son; }else{ this.son.setBrother(son); } } public SLLBlock getFather(){ return this.father; } } protected SLLBlock declaredVariables = null; protected SLLBlock currentBlock = declaredVariables; protected ArrayList partners = new ArrayList(); //contains the names of all declared partners protected ArrayList namespaces = new ArrayList(); //contains the names of all declared namespaces private Object dummy = null; //contains returns values of rules that are not needed protected ArrayList exceptions= new ArrayList(2); protected boolean foundError= false; protected Stack globalStack= new Stack(); protected Stack elementStack= new Stack(); protected SLLLexer lexer; public SLLParser(SLLLexer lexer) { this((TokenStream) lexer); this.lexer= lexer; //reset the values declaredVariables = null; partners = new ArrayList(); namespaces = new ArrayList(); } public boolean foundErrors() { return foundError; } public String getErrorMessage() { StringBuffer buf= new StringBuffer(); for (Iterator i= exceptions.iterator(); i.hasNext();) { buf.append(((Exception) i.next()).toString()); buf.append('\n'); } return buf.toString(); } protected void handleException(Exception e) { //reset the values declaredVariables = null; partners = new ArrayList(); namespaces = new ArrayList(); foundError= true; exceptions.add(e); } public static AST getLastSibling(AST ast){ AST prev = null, curr=ast; prev = curr; if(curr == null) return null; while((curr=curr.getNextSibling())!= null) prev = curr; return prev; } protected boolean isTermStatement(AST stmt){ if(stmt == null) return false; if( stmt.getType() == RETURN || stmt.getType() == BREAK) { return true; }else{ return false; } } } // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | COMPILATION UNIT | // | This is the start rule for the parser (needed by fxl) | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| compilationUnit : ( sll_service_spec | /* nothing */ ) EOF! ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | SLL | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| // root element of the SLL sll_service_spec {currentBlock = new SLLBlock(null, "service");} : pre_service_block:sll_pre_service_block! sll_service[#pre_service_block] ; sll_service [AST definition] { String serviceName=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "service"! serviceName=ncnameOrKeyword! (interf:sll_interfaces! {definition.addChild(#interf);})? LCURLY! (description:sll_service_description[serviceName]!)? { //the syntax allows an optional description but the xmodel requires a obligatory description //besides the elements are reorderd -> tree starts with description nodes if(#description != null){ #description.setNextSibling(definition.getFirstChild()); definition.setFirstChild(#description); }else{ AST tmp = #(#[DESCRIPTION], #[NAME, serviceName]); tmp.setNextSibling(definition.getFirstChild()); definition.setFirstChild(tmp); } } body:sll_service_body RCURLY! (SEMICOLON!)? { AST service = #[SERVICE, "service"]; service.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_service"); #sll_service = #(service, #definition, #body); } ; sll_service_body { AST ast_ops = #(#[OPERATIONS]); AST ast_scopes = #(#[SCOPES]); } : cl:sll_global_clause! (prop:sll_propagations!)? ( op:sll_operation_decl! {ast_ops.addChild(#op);} | sc:sll_scope_decl! {ast_scopes.addChild(#sc);} )* { if (ast_ops.getNumberOfChildren() < 1) ast_ops = null; if (ast_scopes.getNumberOfChildren() < 1) ast_scopes = null; #sll_service_body = #(#[BODY], #cl, #prop, ast_ops, ast_scopes); } ; sll_scope_decl { int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); AST ast_ops = #(#[OPERATIONS]); AST ast_scopes = #(#[SCOPES]); } : "scope"! LCURLY! cl:sll_global_clause! ( (sll_modifiers | "operation") => op:sll_operation_decl! {ast_ops.addChild(#op);} | sc:sll_scope_decl! {ast_scopes.addChild(#sc);} )* RCURLY! { if (ast_ops.getNumberOfChildren() < 1) ast_ops = null; if (ast_scopes.getNumberOfChildren() < 1) ast_scopes = null; AST scope = #[SCOPE]; scope.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_scope_decl"); #sll_scope_decl = #(scope, #cl, ast_ops, ast_scopes); } ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== SLL_PROPAGATIONS ==========================================| sll_propagations {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : sll_propagation (sll_propagation)* { AST propagations = #[PROPAGATIONS]; propagations.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_propagations"); #sll_propagations = #(propagations, #sll_propagations); } ; sll_propagation { String partnerName=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : "propagate"! partnerName=sll_var_name {if(!partners.contains(partnerName)) throw new SemanticException("No partner or variable with the name "+partnerName+" declared!",getFilename(), LT(1).getLine(), LT(1).getColumn()); } ( SEMICOLON! | (sll_include | sll_exclude ) ) { AST propagation = #[PROPAGATION]; propagation.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_propagation"); #sll_propagation =#(propagation, #sll_propagation); } ; sll_include : n:"include"^ {#n.setType(INCLUDE);} sll_prop_op_decls ; sll_exclude : n:"exclude"^ {#n.setType(EXCLUDE);} sll_prop_op_decls ; sll_prop_op_decls : ( (LCURLY! (sll_op_sig_decl SEMICOLON!)+ RCURLY!) | (sll_op_sig_decl SEMICOLON!) ) {#sll_prop_op_decls = #(#[OPERATIONS], #sll_prop_op_decls);} ; sll_op_sig_decl {String name=null;} : name:sll_qName! LPAREN! (t:sll_type_list!)? RPAREN! (rt:returnType! {#rt.setType(RETURNS);} )? {#sll_op_sig_decl = #(#[OPERATION], #name, #t, #rt);} ; // |==================================== SLL_PROPAGATIONS ==========================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== SLL OPERATION DECLARATION =================================| sll_operation_decl {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : mod:sll_modifiers! "operation"! dummy=name:qName! LPAREN! (p:paramList!)? RPAREN! (rt:returnType! {#rt.setType(RETURNS);} )? (thr:sll_throws!)? LCURLY! (pre:sll_pre_op!) ? (sem_op:sll_semantic_operation_decl!) ? (opcl:sll_operation_clauses!)? (stmt:sll_statements!)? (post:sll_post_op!) ? (eff:sll_effects_op!) ? RCURLY! (SEMICOLON!)? { AST operation = #[OPERATION]; operation.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_operation_decl"); #sll_operation_decl = #(operation, #pre, #sem_op, #(#[QNAME], #name), #mod, #p, #rt, #thr, #opcl, #stmt, #post, #eff); } ; sll_semantic_operation_decl {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "semantic"! "operation"! LPAREN! (p:paramList!)? RPAREN! (rt:returnType! {#rt.setType(RETURNS);} )? // TODO: required??? --> (thr:sll_throws!)? LCURLY! (mapping:sll_semantic_mapping!) ? (pre:sll_pre_op!) ? (post:sll_post_op!) ? (eff:sll_effects_op!) ? RCURLY! (SEMICOLON!)? { AST operation = #[SEMANTIC_OPERATION]; operation.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_operation_decl"); #sll_semantic_operation_decl = #(operation, #mapping, #pre, #p, #rt, #thr, #post, #eff); } ; sll_pre_op {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "pre_conditions"! LCURLY! (elem:constructor!) ? RCURLY! (SEMICOLON!)? { AST pre_op = #[PRE_OP]; pre_op.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_pre_op"); #sll_pre_op = #(pre_op, #elem); } ; sll_semantic_mapping {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "mapping"! LCURLY! (elem:constructor!) ? RCURLY! (SEMICOLON!)? { AST mapping = #[MAPPING]; mapping.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_semantic_mapping"); #sll_semantic_mapping = #(mapping, #elem); } ; sll_post_op {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "post_conditions"! LCURLY! (elem:constructor!) ? RCURLY! (SEMICOLON!)? { AST post_op = #[POST_OP]; post_op.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_post_op"); #sll_post_op = #(post_op, #elem); } ; sll_effects_op {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "effects"! LCURLY! (elem:constructor!) ? RCURLY! (SEMICOLON!)? { AST post_op = #[EFFECTS_OP]; post_op.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_effects_op"); #sll_effects_op = #(post_op, #elem); } ; sll_operation_clauses { AST result = #(#[CLAUSES]); AST timeoutAST=null; AST catchAST=null; AST denyAST=null; AST allowAST=null; AST secAST= #(#[ROLES]); int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : ( ("timeout") => t:sll_timeout! { if(timeoutAST==null) timeoutAST = #(#[TIMEOUTS], #t); else timeoutAST.addChild(#t); } | ("catch") => c:sll_catch_stmt! { if(catchAST==null) catchAST = #(#[CATCHES], #c); else catchAST.addChild(#c); } | ( ("deny") => d:sll_deny! { if(denyAST==null){ denyAST = #(#[DENY], #d); }else{ denyAST.addChild(#d); } } ) | ( a:sll_allow! { if(allowAST==null){ allowAST = #(#[ALLOW], #a); }else{ allowAST.addChild(#a); } } ) )+ { result.addChild(timeoutAST); result.addChild(catchAST); if(denyAST != null){ secAST.addChild(denyAST); } if(allowAST != null){ secAST.addChild(allowAST); } if(secAST.getFirstChild() != null) result.addChild(secAST); if(result.getFirstChild() == null){ #sll_operation_clauses = null; }else{ result.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_operation_clauses"); #sll_operation_clauses = result; } } ; sll_modifiers : sll_modifier sll_sec_modifiers {#sll_modifiers = #([MODIFIERS, "MODIFIERS"], #sll_modifiers);} ; sll_modifier : (pr:"private" { #pr.setType(PRIVATE);#pr.setText("");} | pu:"public" { #pu.setType(PUBLIC);#pu.setText("");} )? (sy:"synchronized" { #sy.setType(SYNCHRONIZED);#sy.setText("");})? ; sll_throws : "throws"! sequenceType (COMMA! sequenceType)* {#sll_throws = #(#[THROWS], #sll_throws );} ; // |==================================== SLL OPERATION DECLARATION =================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| sll_global_clause //TODO in sll spec einfuegen, dass die reihenfolge in welcher die trigger angegeben werden, irrelevant ist, es werden erst alle triggers und anschliessend alle monitors ausgewertet { int default_op_cnt=0; int unknown_op_cnt = 0; AST secAST = null; AST ctxAST=null; AST allAST=null; AST denAST=null; AST triggerAST=null; AST monitorAST=null; AST timeoutAST=null; AST cAST=null; AST varsAST=#(#[VARIABLES]); AST lifecycleAST=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : ( default_op:sll_default_op! {default_op_cnt++; if(default_op_cnt > 2) throw new SemanticException("only one default operation can be specified",getFilename(), LT(1).getLine(), LT(1).getColumn()); } | unknown_op:sll_unknown_op! {unknown_op_cnt++; if(unknown_op_cnt > 2) throw new SemanticException("only one unknown operation can be specified",getFilename(), LT(1).getLine(), LT(1).getColumn()); } | lifecycle:sll_lifecycle! (SEMICOLON!)? {if(lifecycleAST == null) lifecycleAST = #lifecycle; else getLastSibling(lifecycleAST).setNextSibling(#lifecycle);} | trigger:sll_trigger! (SEMICOLON!)? {if(triggerAST == null) triggerAST = #trigger; else getLastSibling(triggerAST).setNextSibling(#trigger);} | monitor:sll_monitor! (SEMICOLON!)? {if(monitorAST == null) monitorAST = #monitor; else getLastSibling(monitorAST).setNextSibling(#monitor);} | timeout:sll_timeout! {if(timeoutAST == null) timeoutAST = #timeout; else getLastSibling(timeoutAST).setNextSibling(#timeout);} | c:sll_catch_stmt! (SEMICOLON!)? {if(cAST == null) cAST = #c; else getLastSibling(cAST).setNextSibling(#c);} | vars:sll_var_decl_stmt! SEMICOLON! {varsAST.addChild(#vars); } | ctx:sll_context_decl! {if(ctxAST == null) ctxAST = #ctx; else getLastSibling(ctxAST).setNextSibling(#ctx);} | all:sll_allow! { if(allAST == null) allAST = #(#[ALLOW], #(#[ROLES], #all) ); else allAST.getFirstChild().addChild(#all); } | den:sll_deny! { if(denAST == null) denAST = #(#[DENY], #(#[ROLES], #den) ); else denAST.getFirstChild().addChild(#den); } )* { if(allAST != null || denAST != null) secAST = #(#[ROLES], denAST, allAST); if(triggerAST != null) triggerAST = #(#[TRIGGERS], triggerAST); if(monitorAST != null) monitorAST = #(#[MONITORS], monitorAST); if(timeoutAST != null) timeoutAST = #(#[TIMEOUTS], timeoutAST); if(cAST != null) cAST = #(#[CATCHES], cAST); if(lifecycleAST != null) lifecycleAST = #(#[LIFECYCLE], lifecycleAST); if(varsAST.getFirstChild() == null) varsAST = null; if(ctxAST != null) ctxAST = #(#[CONTEXTS], ctxAST); //if no global clause was found return no node if (#den==null && #all==null && #default_op==null && #unknown_op==null && #lifecycle==null && #trigger==null && #monitor==null && #timeout==null && #c==null && #vars==null && #ctx==null){ #sll_global_clause = null; }else{ AST clauses = #[CLAUSES]; clauses.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_global_clause"); #sll_global_clause = #(clauses, triggerAST, monitorAST, timeoutAST, cAST, lifecycleAST, #default_op, #unknown_op, varsAST, ctxAST, secAST ); } } ; sll_allow : "allow"! (sll_role_list)? SEMICOLON! ; sll_deny : "deny"! (sll_role_list)? SEMICOLON! ; sll_role_list : sll_role (COMMA! sll_role)* ; sll_role { String ns=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : ns=qName { //parse the QName and check if a namespace including the roles has been declared String[] strarr = ns.split(":"); if(strarr != null && strarr.length>0){ if(! namespaces.contains(strarr[0])) throw new SemanticException("Namespace "+strarr[0]+" not declared!",getFilename(), LT(1).getLine(), LT(1).getColumn()); }//if } { AST role = #[ROLE]; role.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_role"); #sll_role = #(role, #(#[QNAME], #sll_role)); } ; sll_context_decl {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : n:"context"! {#n.setType(CONTEXT); } name:NCNAME! {#name.setType(NAME); } LCURLY! (c:sll_count_decl! SEMICOLON!)? m:sll_master_key_decl! (ck:sll_custom_key_decl!)? (cp:sll_context_pattern! SEMICOLON!)? (t:sll_timeout!)? (cr:sll_context_resources!)? (cpa:sll_context_partners!)? (cv:sll_ctx_var_decl_stmts[#name.getText()]!)? (ct:sll_triggers!)? (cm:sll_monitors!)? RCURLY! { #n.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_context_decl"); #sll_context_decl = #(#n, #name,#c,#m,#ck,#cp,#t,#cr,#cpa,#cv,#ct,#cm); } ; sll_ctx_assignment_exprs : sll_assignment_expr SEMICOLON! (sll_assignment_expr SEMICOLON!)* {#sll_ctx_assignment_exprs = #(#[ASSIGNMENTS], #sll_ctx_assignment_exprs);} ; sll_ctx_var_decl_stmts [String contextPrefix] //sll context needs own var decl stmt, because sll stmt vars mustn't //have a namespace qualifier!!! : sll_ctx_var_decl_stmt[contextPrefix] SEMICOLON! (sll_ctx_var_decl_stmt[contextPrefix] SEMICOLON!)* {#sll_ctx_var_decl_stmts = #(#[VARIABLES],#sll_ctx_var_decl_stmts);} ; sll_ctx_var_decl_stmt[String contextPrefix] options {defaultErrorHandler=false;} { AST temp=null; String varName=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : "var"! DOLLAR! name:NCNAME! { #name.setType(NAME); varName = contextPrefix+":"+#name.getText();} (t:typeDeclaration)? ( EQ! e:expr! { temp = #(#[ASSIGNMENT], #e) ; } )? { AST variable = #[VARIABLE]; variable.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_ctx_var_decl_stmt"); #sll_ctx_var_decl_stmt = #(variable, #t, #name, #temp ); if (currentBlock != null && !currentBlock.declareVariable(varName, #t)) System.out.println("Variable "+varName+" alredy declared!"); } ; sll_context_pattern : n:"pattern"^ {#n.setType(PATTERN);} ( "NEW"! {#n.setText("NEW");} | "KEYS_REQUIRED"! {#n.setText("KEYS_REQUIRED");} | "ALL_REQUIRED"! {#n.setText("ALL_REQUIRED");} | "KEYS_FORBIDDEN"! {#n.setText("KEYS_FORBIDDEN");} ) ; sll_triggers {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : sll_trigger (sll_trigger)* { AST triggers = #[TRIGGERS]; triggers.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_triggers"); #sll_triggers = #(triggers, #sll_triggers); } ; sll_monitors : sll_monitor (sll_monitor)* {#sll_monitors = #([MONITORS], #sll_monitors);} ; sll_var_decl_stmts : sll_var_decl_stmt SEMICOLON! (sll_var_decl_stmt SEMICOLON!)* {#sll_var_decl_stmts = #(#[VARIABLES],#sll_var_decl_stmts);} ; sll_context_resources : sll_resource SEMICOLON! (sll_resource SEMICOLON!)* {#sll_context_resources = #(#[RESOURCES], #sll_context_resources);} ; sll_context_partners : sll_partner (sll_partner )* {#sll_context_partners = #(#[PARTNERS], #sll_context_partners);} ; sll_count_decl : "count"! LPAREN! i:INTEGER_LITERAL {#i.setType(COUNT);} RPAREN! ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== MASTER AND CUSTOM KEYS=== =================================| sll_custom_key_decl : "custom"! ( (ck:sll_custom_key! (cnt1:sll_count_decl!)? SEMICOLON!) {#sll_custom_key_decl = #(#[CUSTOM_KEY], #cnt1, #(#[KEYS],#ck));} | (ckb:sll_custom_key_block! (cnt2:sll_count_decl! SEMICOLON!)?) {#sll_custom_key_decl = #(#[CUSTOM_KEY], #cnt2, #ckb);} ) ; sll_custom_key : "key"! DOLLAR! n:NCNAME! {#n.setType(NAME);} (t:typeDeclaration!)? (kg:sll_key_generator!)? {#sll_custom_key = #(#[KEY], #t, #n, #kg);} ; sll_custom_key_block : LCURLY! sll_custom_key SEMICOLON! (sll_custom_key SEMICOLON!)* RCURLY! {#sll_custom_key_block = #(#[KEYS], #sll_custom_key_block);} ; sll_master_key_decl : "master"! ( sll_master_key SEMICOLON! {#sll_master_key_decl = #(#[MASTER_KEY], #(#[KEYS], #sll_master_key_decl));} | sll_master_key_block {#sll_master_key_decl = #(#[MASTER_KEY], #sll_master_key_decl);} ) ; sll_master_key_block : LCURLY! sll_master_key SEMICOLON! (sll_master_key SEMICOLON!)* RCURLY! (SEMICOLON!)? {#sll_master_key_block = #(#[KEYS], #sll_master_key_block);} ; sll_master_key : "key"! ( "AUTO" {#sll_master_key = #(#[KEY], #sll_master_key);} | ( DOLLAR! n:NCNAME! {#n.setType(NAME);} (t:typeDeclaration!)? (kg:sll_key_generator!)? {#sll_master_key = #(#[KEY], #t, #n, #kg);} ) ) ; sll_key_generator : "generator"! expr {#sll_key_generator = #(#[KEY_GENERATOR], #sll_key_generator);} ; // |==================================== MASTER AND CUSTOM KEYS=== =================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| sll_timeout {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : n:"timeout"! {#n.setType(TIMEOUT);} (t:sll_timeout_type!)? d:sll_duration_expression! SEMICOLON! { AST timeout = #[TIMEOUT]; timeout.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_timeout"); #sll_timeout = #(timeout, #t, #d); } ; sll_timeout_type {String choice = null;} : ( "INVOKE" {choice = "INVOKE";} | "CONTEXT" {choice = "CONTEXT";} )! {#sll_timeout_type = #(#[TYPE, choice]);} ; sll_trigger {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "trigger"! LPAREN! exp:sll_bool_expr! RPAREN! stmt:sll_statement! { AST trigger = #[TRIGGER]; trigger.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_trigger"); #sll_trigger = #(trigger, #(#[EVENT], #exp), #(#[ACTION], #stmt) ); } ; sll_monitor {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "monitor"! LPAREN! dummy=name:sll_var_name! (COMMA! exp:sll_bool_expr!)? RPAREN! stmt:sll_statement! { AST monitor = #[MONITOR]; monitor.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_monitor"); if(#exp == null){ //no optional boolean expression was defined #sll_monitor = #(monitor, #name, #(#[ACTION], #stmt) ); }else{ #sll_monitor = #(monitor, #name, #(#[CONDITION], #exp), #(#[ACTION], #stmt) ); } } ; sll_lifecycle {String choice=null;int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "lifecycle"! "on"! ( ("INIT"! s1:sll_statement { AST init = #[INIT]; init.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_lifecycle"); #sll_lifecycle=#(init, #s1);} ) | ("STOP"! s2:sll_statement { AST stop = #[STOP]; stop.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_lifecycle"); #sll_lifecycle=#(stop, #s2);} ) ) ; sll_default_op {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "defaultoperation"! op:sll_op_sig_decl! SEMICOLON! { AST defaultOp = #[DEFAULT_OP]; defaultOp.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_default_op"); #sll_default_op = #(defaultOp, #op); } ; sll_unknown_op {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "unknownoperation"! op:sll_op_sig_decl! SEMICOLON! { AST unknownOp = #[UNKNOWN_OP]; unknownOp.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_unknown_op"); #sll_unknown_op = #(unknownOp, #op); } ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======================================== HELPERS ===============================================| sll_qName : dummy=name:qName {#sll_qName = #(#[QNAME], #sll_qName);} ; sll_path_expr {AST step = #(#[STEPS]); AST path = #(#[PATH]); } : dummy=name:sll_var_name! ( SLASH! sExp:stepExpr! {step.addChild(#sExp);} )* { if(step.getNumberOfChildren() < 1){ path = null; }else{ path.addChild(step); } #sll_path_expr = #(#sll_path_expr, #(#[VARIABLE], #name), path); } ; sll_type_list : sll_sequenceType (COMMA! sll_sequenceType )* {#sll_type_list = #(#[TYPES], #sll_type_list);} ; sll_sequenceType : sequenceType {#sll_sequenceType = #(#[TYPE], #sll_sequenceType);} ; sll_var_name returns [String varName] { varName = null; } : DOLLAR! varName=i:qName { #sll_var_name = #(#[QNAME], #i); } ; sll_label {String name=null;} : name=ncnameOrKeyword! { AST lbl = #(#[LABEL]); lbl.setText(name); #sll_label = lbl; } ; // |======================================== HELPERS ===============================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== SLL EXPRESSIONS ===========================================| sll_expression : (multipleVars EQ) => sll_assignment_expr | exprSingle //XQUERY expression ; sll_expressions : sll_expression ( COMMA! sll_expression )* { #sll_expressions = #(#[EXPRESSIONS], #sll_expressions); } ; //TODO check if the variable was declared before it is used !!! sll_assignment_expr : ( name:multipleVars EQ! e:exprSingle! ) { #sll_assignment_expr = #(#[ASSIGNMENT], #name, #e); } ; multipleVars : singleVar | varList ; varList : LPAREN! singleVar ( COMMA! singleVar )* RPAREN! { #varList = #(#[VARIABLES], #varList); } ; singleVar {String varName=null;} : varName=name:sll_var_name {if(!currentBlock.isDeclaredVariable(varName)) System.out.println("[WARNING] Variable "+varName+" not declared or not acessible!");} ; sll_bool_expr : e:exprSingle {#sll_bool_expr = #([BOOLEAN], #e);} ; sll_duration_expression : e:exprSingle {#sll_duration_expression = #([DURATION], #e);} ; // |==================================== SLL EXPRESSIONS ===========================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== SLL SECURITY ==============================================| sll_enc : "encrypted"^ {#sll_enc = #(#[EN]);} | "unencrypted"^ {#sll_enc = #(#[UEN]);} ; sll_enc_rp : "encrypted_rp"^ {#sll_enc_rp = #(#[EN_RP]);} | "unencrypted_rp"^ {#sll_enc_rp = #(#[UEN_RP]);} ; sll_enc_rq : "encrypted_rq"^ {#sll_enc_rq = #(#[EN_RQ]);} | "unencrypted_rq"^ {#sll_enc_rq = #(#[UEN_RQ]);} ; sll_sig : "signed"^ {#sll_sig = #(#[SI]);} | "unsigned"^ {#sll_sig = #(#[USI]);} ; sll_sig_rq : "signed_rq"^ {#sll_sig_rq = #(#[SI_RQ]);} | "unsigned_rq"^ {#sll_sig_rq = #(#[USI_RQ]);} ; sll_sig_rp : "signed_rp"^ {#sll_sig_rp = #(#[SI_RP]);} | "unsigned_rp"^ {#sll_sig_rp = #(#[USI_RP]);} ; sll_auth : "authenticated"^ {#sll_auth = #(#[AU]);} | "unauthenticated"^ {#sll_auth = #(#[UAU]);} ; sll_auth_rq : "authenticated_rq"^ {#sll_auth_rq = #(#[AU_RQ]);} | "unauthenticated_rq"^ {#sll_auth_rq = #(#[UAU_RQ]);} ; sll_auth_rp : "authenticated_rp"^ {#sll_auth_rp = #(#[AU_RP]);} | "unauthenticated_rp"^ {#sll_auth_rp = #(#[UAU_RP]);} ; //security stuff sll_param_modifiers { int enc_cnt = 0; int sig_cnt = 0; } : ( sll_enc {enc_cnt++;} | sll_sig {sig_cnt++;} )* { if(enc_cnt==0 && sig_cnt==0){ //user entered no security modifiers #sll_param_modifiers = null; }else{ #sll_param_modifiers = #(#[MODIFIERS], #sll_param_modifiers); }//if if(enc_cnt>1 || sig_cnt>1) //user entered multiple security modifiers throw new RecognitionException("Parameter or return type security modifiers can occur only once!", getFilename(), LT(1).getLine(), LT(1).getColumn()); } ; sll_sec_modifiers { //info rule check is done in semantic so that it is possible to order the modifiers any way boolean sll_auth = false; boolean sll_auth_rq = false; boolean sll_auth_rp = false; boolean sll_sig = false; boolean sll_sig_rq = false; boolean sll_sig_rp = false; boolean sll_enc = false; boolean sll_enc_rq = false; boolean sll_enc_rp = false; boolean multipleElement = false; } : ( ( sll_auth {if(!sll_auth) sll_auth=true; else multipleElement=true;} | sll_auth_rq {if(!sll_auth_rq) sll_auth_rq=true; else multipleElement=true;} | sll_auth_rp {if(!sll_auth_rp) sll_auth_rp=true; else multipleElement=true;} | sll_sig {if(!sll_sig) sll_sig=true; else multipleElement=true;} | sll_sig_rq {if(!sll_sig_rq) sll_sig_rq=true; else multipleElement=true;} | sll_sig_rp {if(!sll_sig_rp) sll_sig_rp=true; else multipleElement=true;} | sll_enc {if(!sll_enc) sll_enc=true; else multipleElement=true;} | sll_enc_rq {if(!sll_enc_rq) sll_enc_rq=true; else multipleElement=true;} | sll_enc_rp {if(!sll_enc_rp) sll_enc_rp=true; else multipleElement=true;} )* ) { //check if there didn't occur items that cannot be combinated if(multipleElement) throw new RecognitionException("Double or senseless occurence of operation security modifiers detected!", getFilename(), LT(1).getLine(), LT(1).getColumn()); if(sll_auth && (sll_auth_rq || sll_auth_rp)) throw new RecognitionException("(un)authenticated not possible in combination with (un)authenticated_rq/(un)authenticated_rp)!", getFilename(), LT(1).getLine(), LT(1).getColumn()); if(sll_sig && (sll_sig_rq || sll_sig_rp)) throw new RecognitionException("(un)signed not possible in combination with (un)signed_rq/(un)signed_rp)!", getFilename(), LT(1).getLine(), LT(1).getColumn()); if(sll_enc && (sll_enc_rq || sll_enc_rp)) throw new RecognitionException("(un)encrypted not possible in combination with (un)encrypted_rq/(un)encrypted_rp)!", getFilename(), LT(1).getLine(), LT(1).getColumn()); } ; // |==================================== SLL SECURITY ==============================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |==================================== SLL STATEMENTS ============================================| sll_statement : ("sequence") => sll_sequence_stmt | ("parallel") => sll_parallel_stmt | ("unordered") => sll_unordered_stmt | (SEMICOLON) => SEMICOLON! //SEMICOLON can be a statement -> so it is possible to set ; after blocks | ("get") => sll_get_ctx_binding_stmt SEMICOLON! | ("set") => sll_set_ctx_binding_stmt SEMICOLON! | ((sll_label COLON)| LCURLY) => sll_block_stmt | ("sleep") => sll_sleep_stmt SEMICOLON! | ("var") => sll_var_decl_stmt SEMICOLON! | ("empty") => sll_empty_stmt SEMICOLON! | ("while") => sll_while_stmt | ("do") => sll_do_while_stmt | ("if") => sll_if_stmt | ("switch") => sll_switch_stmt | ("for") => sll_for_stmt | ("break") => sll_break_stmt SEMICOLON! | ("continue") => sll_continue_stmt SEMICOLON! | ("return") => sll_return_stmt | ("throw") => sll_throw_stmt SEMICOLON! | ("try") => sll_try_catch_stmt | ("terminate") => sll_terminate_stmt SEMICOLON! | ("sync") => sll_sync_stmt | ("activate") => sll_activate_stmt SEMICOLON! | ("deactivate") => sll_deactivate_stmt SEMICOLON! | ("syncpoint") => sll_sync_point_stmt | ("transaction") => sll_transaction_stmt | ("prepare") => sll_prepare_stmt | ("commit") => sll_commit_stmt SEMICOLON! | ("abort") => sll_abort_stmt SEMICOLON! | ("insert" | "move" | "replace" | "delete" |"rename") => sll_data_manipulation_stmt SEMICOLON! | ("send_sync" | "send_async" ) => sll_invoke_stmt | ("wrapper") => sll_code_wrapper_stmt | ("identity" | "isEncrypted" | "print" | "getRequest" | "log" | "transform") => sll_build_in_func SEMICOLON! | sll_expression SEMICOLON! ; sll_sequence_stmt { SLLBlock tmp = new SLLBlock(currentBlock,"sequence"); currentBlock.setSon(tmp); currentBlock = tmp;} : "sequence"! LCURLY! sll_statements RCURLY! {#sll_sequence_stmt = #(#[SEQUENCE], #sll_sequence_stmt );} {if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); currentBlock.deleteSons(); }} ; sll_parallel_stmt { SLLBlock tmp = new SLLBlock(currentBlock); currentBlock.setSon(tmp); currentBlock = tmp; AST stmts = #(#[STATEMENTS]);} : "parallel"! LCURLY! stmt1:sll_statement! { stmts.addChild(#stmt1);} ( stmt2:sll_statement! { //no termination statements possible when parallel execution if(isTermStatement(#stmt2) || isTermStatement(#stmt1)) throw new SemanticException("Parallel executed statements don't allow termination statemtens like return, continue...", getFilename(), LT(1).getLine(), LT(1).getColumn()); stmts.addChild(#stmt2); } )+ RCURLY! {#sll_parallel_stmt = #(#[PARALLEL], stmts);} {if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); currentBlock.deleteSons(); }} ; sll_unordered_stmt { SLLBlock tmp = new SLLBlock(currentBlock,"unordered"); currentBlock.setSon(tmp); currentBlock = tmp;} : "unordered"! LCURLY! sll_statements RCURLY! {#sll_unordered_stmt = #(#[UNORDERED], #sll_unordered_stmt); } {if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); currentBlock.deleteSons(); }} ; sll_code_wrapper_stmt : "wrapper"! name:NCNAME! {#name.setType(NAME);} (LPAREN! (plist:paramList!)? RPAREN!)? (rt:returnType! {#rt.setType(RETURNS);} )? LCURLY! lang:sll_language_decl! (imp:sll_import_decl!)? (map:sll_mapping_decl!)? cdat:cdataSection! (SEMICOLON!)? RCURLY! {#sll_code_wrapper_stmt = #(#[WRAPPER], #name, #lang, #imp, #map, #plist, #rt, #cdat);} ; sll_partner_wrapper_decl : n:"wrapper"^ {#n.setType(WRAPPER);} LCURLY! sll_language_decl (sll_import_decl)? (sll_mapping_decl)? (sll_class_decl)? RCURLY! ; sll_class_decl : "class"! str:STRING_LITERAL {#str.setType(CLASS);} SEMICOLON! ; sll_mapping_decl : n:"mapping"^ {#n.setType(MAPPING);} ( name:NCNAME { #name.setType(NAMESPACE); String[] strarr = #name.getText().split(":"); if(strarr != null && strarr.length>0){ if(! namespaces.contains(strarr[0])) throw new SemanticException("Namespace "+strarr[0]+" not declared!",getFilename(), LT(1).getLine(), LT(1).getColumn()); }//if } | uri:STRING_LITERAL {#uri.setType(URI);} ) SEMICOLON! ; sll_import_decl : sll_import (sll_import)* {#sll_import_decl = #(#[IMPORTS], #sll_import_decl);} ; sll_import : n:"import"^ {#n.setType(IMPORT);} uri:STRING_LITERAL {#uri.setType(URI);} SEMICOLON! ; sll_language_decl : name:sll_language! {#name.setType(NAME);} SEMICOLON! (vers:sll_version! SEMICOLON!)? {#sll_language_decl = #(#[LANGUAGE], #name, #vers);} ; sll_data_manipulation_stmt : sll_insert_stmt | sll_move_stmt | sll_replace_stmt | sll_delete_stmt | sll_rename_stmt ; sll_insert_stmt {AST opt = null;} : "insert"! exp:sll_expression! ( "into"! {opt = #(#[INTO]);} | "before"! {opt = #(#[BEFORE]);} | "after"! {opt = #(#[AFTER]);} ) pathEx:sll_path_expr! {opt.addChild(#pathEx);} {#sll_insert_stmt = #(#[INSERT], #exp, opt );} ; sll_move_stmt {AST opt = null;} : "move"! pathExpr1:sll_path_expr! ( "into"! {opt = #(#[INTO]);} | "before"! {opt = #(#[BEFORE]);} | "after"! {opt = #(#[AFTER]);} ) pathExpr2:sll_path_expr! {opt.addChild(#pathExpr2);} { #sll_move_stmt = #(#[MOVE], #pathExpr1, opt); } ; sll_replace_stmt : "replace"! pathEx:sll_path_expr! "with"! exp:sll_expression! {#sll_replace_stmt = #(#[REPLACE], #pathEx, #(#[WITH], #exp) );} ; sll_delete_stmt : n:"delete"^ {#n.setType(DELETE);} sll_path_expr ; sll_rename_stmt : "rename"! pathEx:sll_path_expr! "to"! exp:sll_expression! {#sll_rename_stmt = #(#[RENAME], #pathEx, #(#[TO], #exp));} ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |=========================== SLL SERVICE INVOCATION STMTS =======================================| sll_invoke_timeout : n:"timeout"^ {#n.setType(TIMEOUT);} LPAREN! sll_duration_expression RPAREN! ; sll_invoke_retry : n:"retry"^ {#n.setType(RETRY);} LPAREN! ( sll_count_decl | sll_duration_expression ) (SEMICOLON! sll_sleep_stmt (SEMICOLON!)? )? RPAREN! ; sll_invoke_stmt {AST ast_type = #(#[TYPE]);} : ( "send_sync"! {ast_type.setText("SYNC");} | "send_async"! {ast_type.setText("ASYNC");} ) mod:sll_sec_modifiers! {if(#mod != null) #mod = #(#[MODIFIERS], #mod);} dest:sll_invoke_dest! ( LPAREN! (params:sll_expr_param_list)? RPAREN! ) ("with"! timeout_retry:sll_timeout_retry! )? {#sll_invoke_stmt = #(#[INVOKE], #mod, ast_type, #dest, #params, #timeout_retry);} ; sll_invoke_dest //check wether qName is variable name or partner name {AST uriVarPartner=null; AST op = null; String partnerName=null;} : ( uri:STRING_LITERAL! {#uri.setType(URI); uriVarPartner=#uri;} | partnerName=name:sll_var_name! { if(partners.contains(partnerName)){ uriVarPartner = #(#[PARTNER], #name); }else { //check if variable really exists!! if(currentBlock.isDeclaredVariable(partnerName)) uriVarPartner = #(#[VARIABLE], #name); else throw new SemanticException("No partner or variable with the name "+partnerName+" declared!",getFilename(), LT(1).getLine(), LT(1).getColumn()); }//if } ) ( COLON! COLON! ( dummy=varName:sll_var_name! {op = #(#[OPERATION], #varName);} | opName:NCNAME! {#opName.setType(NAME); op = #(#[OPERATION], #opName);} ) )? {#sll_invoke_dest = #(#[DESTINATION], uriVarPartner, op );} ; sll_timeout_retry : ((sll_invoke_timeout (COMMA! sll_invoke_retry)? ) | sll_invoke_retry) ; // |=========================== SLL SERVICE INVOCATION STMTS =======================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| sll_sync_point_stmt : "syncpoint"! LPAREN! dummy=name:sll_var_name! RPAREN! ( SEMICOLON! | ( LCURLY! "timeout"! exp:sll_duration_expression! SEMICOLON! (thr:sll_throw_stmt! SEMICOLON!)? RCURLY! ) ) { AST timeoutAST = null; if(#exp != null) timeoutAST = #(#[TIMEOUT], #exp); #sll_sync_point_stmt = #(#[SYNC_POINT], #name, timeoutAST, #thr ); } ; sll_activate_stmt : n:"activate"^ {#n.setType(ACTIVATE);} dummy=sll_var_name ; sll_deactivate_stmt : n:"deactivate"^ {#n.setType(DEACTIVATE);} dummy=sll_var_name ; sll_sync_stmt {String varName=null;} : n:"sync"^ {#n.setType(SYNC);} LPAREN! varName=sll_var_name {if(!currentBlock.isDeclaredVariable(varName)) System.out.println("[WARNING] Variable "+varName+" not declared or not acessible!");} RPAREN! sll_statement ; sll_transaction_stmt : "transaction"! dummy=n:qName! LPAREN! (param:paramList!)? RPAREN! ( stmts:sll_trans_inner_stmts! | SEMICOLON! ) {#sll_transaction_stmt = #(#[TRANSACTION], #(#[QNAME], #n), #param, #stmts);} ; sll_trans_inner_stmts : LCURLY! ( sll_statement (sll_compensate_stmt)? )+ RCURLY! ; sll_compensate_stmt : "compensate"! sll_statement {#sll_compensate_stmt = #(#[COMPENSATE], #sll_compensate_stmt);} ; sll_prepare_stmt : n:"prepare"^ {#n.setType(PREPARE);} sll_acid_stmt ; sll_acid_stmt //TODO - NOT IMPLEMENTED YET ! defined statements can be acid enabled statements //currently all statements can be acid enabled statements : sll_statement ; sll_commit_stmt : "commit"! dummy=n:qName! {#sll_commit_stmt = #(#[COMMIT], #(#[QNAME], #n));} ; sll_abort_stmt : "abort"! dummy=name:qName! ( LPAREN! (exp:sll_expr_param_list!)? RPAREN! )? {#sll_abort_stmt = #(#[ABORT], #(#[QNAME], #name), #exp);} ; sll_expr_param_list : sll_expr_param (COMMA! sll_expr_param)* {#sll_expr_param_list = #(#[PARAMETERS], #sll_expr_param_list);} ; sll_expr_param : sll_expression {#sll_expr_param = #(#[PARAMETER], #sll_expr_param);} ; sll_get_ctx_binding_stmt : n:"get"^ {#n.setType(GET);} name:NCNAME {#name.setType(CONTEXT);} (sll_get_ctx_correlations)? (sll_context_pattern)? ; sll_get_ctx_correlations : "correlation"! LPAREN! sll_get_correlation_content (COMMA! sll_get_correlation_content)* RPAREN! {#sll_get_ctx_correlations = #(#[CORRELATIONS], #sll_get_ctx_correlations);} ; sll_get_correlation_content : rpEx:sll_path_expr! "with"! dummy=kname:sll_var_name! { #sll_get_correlation_content = #(#[CORRELATION], #rpEx, #(#[WITH], #(#[KEY], #kname)) );} ; sll_set_ctx_binding_stmt : n:"set"^ {#n.setType(SET);} name:NCNAME {#name.setType(CONTEXT);} sll_set_ctx_correlations ; sll_set_ctx_correlations : "correlation"! LPAREN! sll_set_correlation_content (COMMA! sll_set_correlation_content)* RPAREN! {#sll_set_ctx_correlations = #(#[CORRELATIONS], #sll_set_ctx_correlations);} ; sll_set_correlation_content : dummy=kname:sll_var_name! "with"! rpEx:sll_path_expr! { #sll_set_correlation_content = #(#[CORRELATION], #(#[KEY], #kname), #(#[WITH], #rpEx ));} ; sll_terminate_stmt : n:"terminate"^ {#n.setType(TERMINATE);} ( name:NCNAME {#name.setType(NAME);} | "ALL" ) ; sll_try_catch_stmt : "try"! LCURLY! (sll_statements)? RCURLY! sll_catch_stmt (("finally") => sll_finally_stmt | /*nothing*/) {#sll_try_catch_stmt = #(#[TRY], #sll_try_catch_stmt);} ; sll_catch_stmt { int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : "catch"! LPAREN! dummy=name:sll_var_name (typeDeclaration)? RPAREN! LCURLY! (sll_statements)? RCURLY! { AST catchStmt = #[CATCH]; catchStmt.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_catch_stmt"); #sll_catch_stmt = #(catchStmt, #sll_catch_stmt); } ; sll_finally_stmt : "finally"! LCURLY! (sll_statements)? RCURLY! {#sll_finally_stmt = #(#[FINALLY], #sll_finally_stmt);} ; sll_throw_stmt : n:"throw"^ {#n.setType(THROW);} e:sll_expressions ; sll_return_stmt : "return"! (sll_expression)? SEMICOLON! {#sll_return_stmt = #(#[RETURN], #sll_return_stmt);} ; sll_continue_stmt : "continue"! (lbl:sll_label)? {#sll_continue_stmt = #(#[CONTINUE], #lbl);} ; sll_break_stmt : "break"! (lbl:sll_label)? {#sll_break_stmt = #(#[BREAK], #lbl);} ; sll_switch_stmt : "switch"! LPAREN! expr:sll_expression! RPAREN! LCURLY! cases:sll_switchStmtCases! (defcase:sll_default_switch_stmt!)? RCURLY! {#sll_switch_stmt = #(#[SWITCH], #expr, #cases, #defcase );} ; sll_switchStmtCases : sll_switchStmtCase (sll_switchStmtCase)* {#sll_switchStmtCases = #(#[CASES], #sll_switchStmtCases);} ; sll_switchStmtCase : "case"! LPAREN! expr:sll_expression! RPAREN! COLON! stmt:sll_statement! {#sll_switchStmtCase = #(#[CASE], #expr, #stmt);} ; sll_default_switch_stmt : "default"! COLON! stmt:sll_statement! {#sll_default_switch_stmt = #(#[DEFAULT], #stmt);} ; sll_if_stmt : "if"! LPAREN! sll_bool_expr RPAREN! sll_then_stmt ( options {warnWhenFollowAmbig = false;}: sll_else_stmt )? {#sll_if_stmt = #(#[IF], #sll_if_stmt);} ; sll_then_stmt : sll_statement {#sll_then_stmt = #(#[THEN], #sll_then_stmt);} ; sll_else_stmt : "else"! sll_statement {#sll_else_stmt = #(#[ELSE], #sll_else_stmt);} ; sll_do_while_stmt : "do"! stat:sll_statement! "while"! LPAREN! bool_expr:sll_bool_expr! RPAREN! {#sll_do_while_stmt = #(#[DO], #stat, #(#[WHILE], #bool_expr));} ; sll_block_stmt { SLLBlock tmp = new SLLBlock(currentBlock); currentBlock = tmp; } : (lbl:sll_label! COLON! {currentBlock.blockName = #lbl.getText();} )? LCURLY! (stmt:sll_statements! )? RCURLY! {#sll_block_stmt = #(#[BLOCK], #lbl, #stmt);} {if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); }} ; sll_statements { SLLBlock tmp = new SLLBlock(currentBlock); currentBlock = tmp; AST lastStmt=null; AST statementsAst=#(#[STATEMENTS]); AST pAst=null; boolean termStmtOccured=false; } : firstStmt:sll_statement! {lastStmt = #firstStmt;} ( stmt:sll_statement! { statementsAst.addChild(lastStmt); pAst=null; lastStmt=#stmt; if(termStmtOccured) throw new SemanticException("Unreachable Statement found!", getFilename(), LT(1).getLine(), LT(1).getColumn()); termStmtOccured = isTermStatement(#stmt); } | (DUNION! ustmt:sll_statement! { //no termination statements possible when parallel execution if(isTermStatement(#ustmt) || isTermStatement(#stmt)) throw new SemanticException("Parallel executed statements don't allow termination statemtens like return, continue...", getFilename(), LT(1).getLine(), LT(1).getColumn()); if(pAst == null){ pAst = #(#[PARALLEL], #(#[STATEMENTS])); }//if if(lastStmt.getType() == PARALLEL){ lastStmt.getFirstChild().addChild(#ustmt); }else{ pAst.getFirstChild().addChild(lastStmt); pAst.getFirstChild().addChild(#ustmt); lastStmt = pAst; }//if } ) )* { statementsAst.addChild(lastStmt); #sll_statements = statementsAst; if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); } } ; sll_sleep_stmt : "sleep"! LPAREN! dur:sll_duration_expression! RPAREN! {#sll_sleep_stmt = #([SLEEP], #dur);} ; sll_var_decl_stmt {AST temp=null; String varName=null;int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "var"! varName=name:sll_var_name! (t:typeDeclaration)? ( EQ! e:expr! { temp = #(#[ASSIGNMENT], #e); } )? { AST variable = #[VARIABLE]; variable.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_var_decl_stmt"); #sll_var_decl_stmt = #(variable, #t, #name, #temp ); if (currentBlock != null && !currentBlock.declareVariable(varName, #t)) System.out.println("[WARNING] Variable "+varName+" alredy declared!"); } ; sll_empty_stmt : "empty"! {#sll_empty_stmt = #(#[EMPTY]);} ; sll_while_stmt : "while"! LPAREN! bool_expr:sll_bool_expr! RPAREN! stat:sll_statement! {#sll_while_stmt = #(#[WHILE], #bool_expr, #stat);} ; sll_for_stmt { SLLBlock tmp = new SLLBlock(currentBlock); currentBlock = tmp; currentBlock.blockName = "for block"; } : "for"! LPAREN! (sll_var_decl_stmt | ((multipleVars EQ ) => sll_assignment_expr | sll_iterator_var ))? ( (COLON) => COLON! sll_in_expr | SEMICOLON! (sll_bool_expr)? SEMICOLON! (sll_update_expr)? ) RPAREN! sll_statement {#sll_for_stmt = #(#[FOR], #sll_for_stmt);} {if(currentBlock.getFather() != null){ currentBlock = currentBlock.getFather(); }} ; sll_update_expr : sll_expression {#sll_update_expr = #(#[UPDATE], #sll_update_expr);} ; sll_in_expr : sll_expression {#sll_in_expr = #(#[IN], #sll_in_expr);} ; sll_iterator_var : dummy=sll_var_name {#sll_iterator_var = #(#[EXPRESSION], #(#[VARIABLE], #sll_iterator_var));} ; // |==================================== SLL STATEMENTS ============================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // |================================= Build in Functions (part of statements) ======================| sll_build_in_func : ( sll_bif_identity | sll_bif_encrypted | sll_bif_print | sll_bif_getRequest | sll_bif_log | sll_bif_transform )//NOTE the parentheses are necessary, otherwise the functions are not sourrounded with the FUNCTION-Tag {#sll_build_in_func = #(#[FUNCTION], #sll_build_in_func);} ; sll_bif_identity : n:"identity"^ {#n.setType(IDENTITY);} LPAREN! (sll_qName | dummy=sll_var_name)? RPAREN! ; sll_bif_encrypted : n:"isEncrypted"^ {#n.setType(ISENCRYPTED);} LPAREN! (sll_qName | dummy=sll_var_name)? RPAREN! ; sll_bif_print : n:"print"^ {#n.setType(PRINT);} LPAREN! sll_expressions RPAREN! ; sll_bif_getRequest : n:"getRequest"^ {#n.setType(GET_REQUEST); #n.setText("");} LPAREN! RPAREN! ; sll_bif_log : n:"log"^ {#n.setType(LOG);} LPAREN! sll_expressions RPAREN! ; sll_bif_transform : n:"transform"^ {#n.setType(TRANSFORM);} LPAREN! sll_expression COMMA! dummy=sll_var_name RPAREN! ; // |================================= Build in Functions ===========================================| // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| sll_service_description [String serviceName] {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "description"! LCURLY! (vers:sll_version! SEMICOLON!)? (text:sll_text!)? (category:sll_category!)? (contacts:sll_contacts!)? (semantic:sll_semantic! (SEMICOLON!)? )? RCURLY! { AST desc = #[DESCRIPTION]; desc.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_service_description"); #sll_service_description = #(desc, #[NAME,serviceName], #vers, #text, #category, #contacts, #semantic); } ; sll_semantic {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "semantic"! LCURLY! elem:constructor! RCURLY! { AST semantic = #[SEMANTIC]; semantic.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_semantic"); #sll_semantic = #(semantic, #elem); } ; sll_contacts {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : sll_contact ( sll_contact )* { AST contacts = #[CONTACTS]; contacts.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_contacts"); #sll_contacts = #(contacts, #sll_contacts); } ; sll_contact { String name=null; int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn(); } : "contact"! a:STRING_LITERAL! {#a.setType(CONTACT);} SEMICOLON! { #a.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_contact"); #sll_contact = #a; } ; sll_version : "version"! (a:STRING_LITERAL {#a.setType(VERSION);} | d:DECIMAL_LITERAL {#d.setType(VERSION);}) ; sll_text : "text"! a:STRING_LITERAL {#a.setType(TEXT);} SEMICOLON! ; sll_category : "category"! a:STRING_LITERAL {#a.setType(CATEGORY);} SEMICOLON! ; sll_interfaces {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "implements"! i:sll_interface (COMMA! sll_interface)* { AST interfaces = #[INTERFACES]; interfaces.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_interfaces"); #sll_interfaces = #(interfaces, #sll_interfaces); } ; sll_interface {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : dummy=name:qName! { AST aInterface = #[INTERFACE]; aInterface.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_interface"); #sll_interface = #(aInterface, #(#[QNAME],#name)); } ; sll_pre_service_block { AST ns_ret = null; AST pt_ret = null; AST rs_ret = null; AST result_AST = astFactory.create(DEFINITION); AST ast_ns = astFactory.create(NAMESPACES); AST ast_rs = astFactory.create(RESOURCES); AST ast_pt = astFactory.create(PARTNERS);} : ( ns_ret:sll_namespace! {ast_ns.addChild(#ns_ret);} | pt_ret:sll_partner! {ast_pt.addChild(#pt_ret);} | rs_ret:sll_resource! SEMICOLON! {ast_rs.addChild(#rs_ret);} )* { //do the merging of the asts into one common ast if(ast_rs.getFirstChild() != null) result_AST.addChild(ast_rs); if(ast_pt.getFirstChild() != null) result_AST.addChild(ast_pt); if(ast_ns.getFirstChild() != null) result_AST.addChild(ast_ns); #sll_pre_service_block = result_AST; } ; sll_namespace {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : n:"namespace"! {#n.setType(NAMESPACE);} i:NCNAME! {#i.setType(NAME); namespaces.add(#i.getText());} EQ! l:STRING_LITERAL! {#l.setType(LOCATION);} SEMICOLON! { AST namespace = #[NAMESPACE]; namespace.setPartition(sColumn, sLine, LT(0).getColumn()+1, LT(0).getLine(), "sll_namespace"); #sll_namespace = #(namespace, #i, #l); } ; sll_partner {String partnerName=null;int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "partner"! partnerName=name:sll_var_name //name ( SEMICOLON! | (typ:sll_interface_type! (SEMICOLON!)? ) //port type or interface ) (EQ! binding:sll_partner_binding! SEMICOLON!)? { AST partner = #[PARTNER]; partner.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_partner"); #sll_partner = #(partner, #name, #typ, #binding); if (partners.contains(partnerName)) throw new SemanticException("Partner "+partnerName+" alredy defined!", getFilename(), LT(1).getLine(), LT(1).getColumn()); else partners.add(partnerName); } ; sll_interface_type {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : "as"! sll_partner_interface ( COMMA! sll_partner_interface )* { AST interfaces = #[INTERFACES]; interfaces.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_interface_type"); #sll_interface_type = #(interfaces, #sll_interface_type); } ; sll_partner_interface {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : dummy=name:qName! { AST aInterface = #[INTERFACE]; aInterface.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_partner_interface"); #sll_partner_interface = #(aInterface, #(#[QNAME],#name)); } ; sll_partner_binding : ( sll_endpoint | sll_query | sll_partner_wrapper_decl) {#sll_partner_binding = #([BINDING], #sll_partner_binding);} ; sll_endpoint : sll_expression {#sll_endpoint = #(#[ENDPOINT], #sll_endpoint);} ; sll_language : "language"! a:STRING_LITERAL {#a.setType(LANGUAGE);} ; sll_query : "query"! dummy=name:sll_var_name! lang: sll_language! (vers: sll_version!)? (res:sll_query_resolution!)? { //if no resoluion was set use AUTO as default if(#res == null) #res = #[RESOLUTION, "AUTO"]; } (LCURLY! //allows to specify optional properties (prop:sll_properties!)? (semexpr:sll_semantic!)? //and obligatory sememantic actions RCURLY!)? {#sll_query = #([QUERY], #name, #lang, #vers, #res, #prop, #semexpr);} ; sll_query_resolution {String choice = null;} : res:"resolution"! ( "ONCE" {choice = "ONCE";} | "FAILS" {choice = "FAILS";} | "ALWAYS" {choice = "ALWAYS";} | "AUTO" {choice = "AUTO";} | "MANUAL" {choice = "MANUAL";} | "ALL" {choice = "ALL";} )! {#sll_query_resolution = #(#[RESOLUTION, choice]);} ; sll_resource {int sLine=LT(1).getLine(); int sColumn=LT(1).getColumn();} : n:"resource"! dummy=name:sll_var_name! EQ! exp:sll_expression! (LCURLY! prop:sll_properties! RCURLY!)? (thrw:sll_throw_stmt!)? { AST resource = #[RESOURCE]; resource.setPartition(sColumn, sLine, LT(1).getColumn(), LT(1).getLine(), "sll_resource"); #sll_resource = #(resource, #name, #(#[BINDING], #([LOCATION], #exp), #prop ), #thrw ); } ; sll_properties : sll_property ( sll_property ) * {#sll_properties = #(#[PROPERTIES], #sll_properties);} ; sll_property : ("property"!)? ( (key:STRING_LITERAL {#key.setType(KEY);}) | (name:NCNAME { #name.setType(KEY); }) ) EQ! val:STRING_LITERAL {#val.setType(VALUE);} SEMICOLON! {#sll_property = #(#[PROPERTY], #sll_property);} ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | XQUERY | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| xpointer : "xpointer"^ LPAREN! ex:expr RPAREN! { #xpointer= #(#[XPOINTER, "xpointer"], #ex); } | nc:NCNAME { #xpointer= #(#[XPOINTER_ID, "id"], #nc); } ; xpath : ( module )? EOF ; exception catch [RecognitionException e] { handleException(e); } module : ( "module" "namespace" ) => libraryModule | mainModule; mainModule : p:prolog! q:queryBody! { #mainModule = #(#[MAINMODULE], #p, #q); } ; libraryModule: m:moduleDecl! p:prolog! { #libraryModule = #(#[LIBRARYMODULE], #m, #p); } ; moduleDecl: "module"! "namespace"! prefix:NCNAME EQ! uri:STRING_LITERAL {#uri.setType(URI);} SEMICOLON! { #moduleDecl = #(#[MODULE], #(#[NAME, prefix.getText()]), uri); } ; prolog : ( ( "xquery" "version" ) => version SEMICOLON! )? ( (( ( "declare" "namespace" ) => nd:namespaceDecl | ( "declare" "default" ) => dnd:defaultNamespaceDecl | ( "declare" "function" ) => fd:functionDecl | ( "declare" "variable" ) => varDecl ) | moduleImport) SEMICOLON! )* {#prolog = #([PROLOG], #prolog);} ; version : "xquery"! k:"version" s:STRING_LITERAL! { #k.setText(#s.getText()); } ; namespaceDecl : "declare"! "namespace"! n:NCNAME { n_AST.setType(NAME); } EQ! u:STRING_LITERAL { u_AST.setType(URI);} {#namespaceDecl = #([NAMESPACE], #namespaceDecl );} ; defaultNamespaceDecl : "declare"! "default"! ( "element"! "namespace"! defu:STRING_LITERAL^ { #defu.setType(DEFAULT_NAMESPACE); } | "function"! "namespace"! deff:STRING_LITERAL^ { #deff.setType(DEFAULT_FUNCTION_NAMESPACE); } ) ; varDecl { String varName= null; } : "declare"! "variable"! DOLLAR! varName=v:qName! //{ #v.setType(IDENTIFIER); } ( typeDeclaration )? LCURLY! ex:expr! RCURLY! { #varDecl= #(#[VARIABLE], #varDecl, #(#[IDENTIFIER], #v), #(#[VALUE], #ex) ); } ; moduleImport : i:"import"! "module"! (( "namespace"! n:NCNAME! { #n.setType(IDENTIFIER); } EQ! s1:STRING_LITERAL! { #s1.setType(TARGET); } { #moduleImport= #(#[IMPORT_MODULE_NAMESPACE], #n, #s1, #moduleImport ); } ) | ( s2:STRING_LITERAL! { #s2.setType(TARGET); } { #moduleImport= #(#[IMPORT_MODULE], #s2, #moduleImport ); } ) ) ( "at"! s3:STRING_LITERAL { #s3.setType(LOCATION); } )? ; functionDecl { String fName; } : "declare"! "function"! fName=name:qName! LPAREN! ( paramList )? RPAREN! ( returnType )? functionBody { #functionDecl= #(#[FUNCTION], #(#[IDENTIFIER], #name), #functionDecl); } ; functionBody : LCURLY! e:expr RCURLY! ; returnType : ( "as"! s:singlePart { #s.setType(RETURN); } ) | ( "returns"! p:partList { #p.setType(RETURN); } ) ; singlePart { String name; } : m:sll_param_modifiers! ( name=n:sll_var_name! "as"! )? t:sequenceType! { #singlePart= #( #[PART], #m, #n, #t); } ; partList : LPAREN! singlePart ( COMMA! singlePart )* RPAREN! { #partList = #(#[PARTS], #partList); } ; paramList : param ( COMMA! param )* { #paramList = #(#[PARAMETERS], #paramList); } ; param : m:sll_param_modifiers! dummy=name:sll_var_name ( t:typeDeclaration! )? { #param= #( #[PARAMETER], #m, #t, #name); } ; typeDeclaration : a:"as"^ { #a.setType(TYPE); } sequenceType ; sequenceType : ( "empty" LPAREN ) => "empty"^ LPAREN! RPAREN! | itemType ( occurrenceIndicator )? ; occurrenceIndicator : QUESTION { #occurrenceIndicator = #(#[OCCURRENCE, "question"]); } | STAR { #occurrenceIndicator = #(#[OCCURRENCE, "star"]); } | PLUS { #occurrenceIndicator = #(#[OCCURRENCE, "plus"]); } ; itemType : ( "item" LPAREN ) => "item"^ LPAREN! RPAREN! | ( . LPAREN ) => kindTest | atomicType ; singleType : atomicType (QUESTION)? ; atomicType { String name= null; } : name=q:qName { #atomicType= #(#[ATOMIC], #q); } ; queryBody : expr ; expr : exprSingle ( COMMA! exprSingle )* { #expr = #(#[EXPRESSIONS], #expr); } ; exprSingle : ( ( ( "for" | "let" ) DOLLAR ) => flworExpr | ( ( "some" | "every" ) DOLLAR ) => quantifiedExpr | ( "if" LPAREN ) => ifExpr | ("send_sync" | "send_async" ) => sll_invoke_stmt | orExpr ) { #exprSingle = #(#[EXPRESSION], #exprSingle); } ; flworExpr : ( forClause | letClause )+ ( whereClause )? ( orderByClause )? "return" ! e:exprSingle! { #flworExpr= #(#[FLWOR], #flworExpr, #(#[RETURN], #e) ); } ; whereClause : "where"! e:expr! { #whereClause = #(#[WHERE], #e); } ; forClause : "for"^ inVarBinding ( COMMA! inVarBinding )* ; letClause : "let"^ letVarBinding ( COMMA! letVarBinding )* ; inVarBinding { String varName; } : DOLLAR! varName=q:qName! ( typeDeclaration )? ( positionalVar )? "in"! e:exprSingle! { #inVarBinding= #(#[VARIABLE_BINDING], #(#[IDENTIFIER], #q), #inVarBinding, #(#[IN], #e)); } ; positionalVar { String varName; } : "at"! DOLLAR! varName=q:qName! { #positionalVar= #(#[POSITIONAL], #(#[IDENTIFIER], #q)); } ; letVarBinding { String varName; } : DOLLAR! varName=q:qName! ( typeDeclaration )? COLON! EQ! e:exprSingle! { #letVarBinding= #(#[VARIABLE_BINDING], #(#[IDENTIFIER], #q), #letVarBinding, #(#[ASSIGN], #e) ); } ; orderByClause : "order"! "by"! orderSpecList { #orderByClause= #([ORDER_BY], #orderByClause); } ; orderSpecList : orderSpec ( COMMA! orderSpec )* ; orderSpec : exprSingle orderModifier ; orderModifier : ( "ascending"^ | "descending"^ )? ("empty"! ( g:"greatest"{ #g.setType(EMPTY_GREATEST); #g.setText("");} | l:"least"{ #l.setType(EMPTY_LEAST); #l.setText("");} ) )? ; quantifiedExpr: ( "some" | "every" ) quantifiedInVarBinding ( COMMA! quantifiedInVarBinding )* "satisfies"! e:exprSingle! { #quantifiedExpr = #(#[QUANTIFIED], #quantifiedExpr, #(#[SATISFIES], #e)); } ; quantifiedInVarBinding { String varName; }: DOLLAR! varName=q:qName! ( typeDeclaration )? "in"! e:exprSingle! { #quantifiedInVarBinding = #(#[VARIABLE_BINDING],#(#[IDENTIFIER], #q), #quantifiedInVarBinding, #(#[IN], #e)); } ; ifExpr : "if"^ LPAREN! e:expr! RPAREN! "then"! t:exprSingle! "else"! el:exprSingle! { #ifExpr = #(#[IF], #e, #(#[THEN], #t), #(#[ELSE], #el)); } ; orExpr : andExpr ( "or"^ andExpr )* ; andExpr : instanceOf ( "and"^ instanceOf )* ; instanceOf : treatAs ("instance"^ "of"! sequenceType)? ; treatAs : castableAs ("treat"^ "as"! sequenceType)? ; castableAs : castExpr ("castable"^ "as"! singleType)? ; castExpr : comparisonExpr ( "cast"^ "as"! singleType )? ; comparisonExpr : rangeExpr ( ( LT LT ) => LT! LT! rangeExpr { #comparisonExpr = #(#[BEFORE], #comparisonExpr); } | ( GT GT ) => GT! GT! rangeExpr { #comparisonExpr = #(#[AFTER], #comparisonExpr); } | ( ( a:"eq"^{#a.setType(V_EQ);} | b:"ne"^{#b.setType(V_NE);} | c:"lt"^{#c.setType(V_LT);} | d:"le"^{#d.setType(V_LE);} | f:"gt"^{#f.setType(V_GT);} | g:"ge"^{#g.setType(V_GE);} ) rangeExpr ) | ( ( EQ^ | NEQ^ | GT^ | GTEQ^ | LT^ | LTEQ^ ) rangeExpr ) | ( ( "is"^ | "isnot"^ ) rangeExpr ) | ( ( ANDEQ^ | OREQ^ ) rangeExpr ) )? ; rangeExpr : additiveExpr ( "to"^ additiveExpr )? ; additiveExpr : multiplicativeExpr ( ( PLUS^ | MINUS^ ) multiplicativeExpr )* ; multiplicativeExpr : unaryExpr ( ( STAR^ | "div"^ | "idiv"^ | "mod"^ ) unaryExpr )* ; unaryExpr : // TODO: XPath 2.0 allows an arbitrary number of +/-, // we restrict it to one MINUS expr:unionExpr { #unaryExpr= #(#[UNARY_MINUS], #expr); } | PLUS expr2:unionExpr { #unaryExpr= #(#[UNARY_PLUS], #expr2); } | unionExpr ; unionExpr : intersectExceptExpr ( ( u:"union"^{#u.setType(UNION);} | UNION^ ) intersectExceptExpr )* ; intersectExceptExpr : pathExpr ( ( "intersect"^ | "except"^ ) pathExpr )* ; pathExpr { boolean created=false; boolean temp;} : temp=rp:relativePathExpr | ( SLASH relativePathExpr) => SLASH! created=relPath:relativePathExpr { if (created) { #relPath.setType(ABSOLUTE_PATH); } else{ #pathExpr=#([ABSOLUTE_PATH], #relPath); } } | SLASH! { #pathExpr= #[ABSOLUTE_PATH]; } | DSLASH! created=relPath2:relativePathExpr { if (created) { #relPath2.setType(ABSOLUTE_DSLASH); } else { #pathExpr=#([ABSOLUTE_DSLASH], #relPath2); } } ; relativePathExpr returns [boolean created] { created=false;AST tempAST = null; AST sTemp=null;} : first:stepExpr! ( ( SLASH! s1:stepExpr! { if (!created) { created=true; #tempAST = astFactory.create(RELATIVE_PATH); #tempAST.addChild(#first); #relativePathExpr = #(#relativePathExpr, #tempAST); } #tempAST.addChild(#s1); } | d:DSLASH! s:stepExpr! { if (!created) { created=true; #tempAST = astFactory.create(RELATIVE_PATH); #tempAST.addChild(#first); #relativePathExpr = #(#relativePathExpr, #tempAST); } #sTemp = s_AST.getFirstChild(); #tempAST.addChild(#(#[STEP], #(#[AXIS], #(#[DESCENDANT_OR_SELF,""])), #(#[NODETEST], astFactory.dupTree(#sTemp)), astFactory.dupTree(#sTemp.getNextSibling()) )); } ) )* { if (!created) { #relativePathExpr = #first; } } ; stepExpr : ( ( "text" | "node" | "element" ) LPAREN ) => axisStep | ( DOLLAR | ( qName LPAREN ) | SELF | LPAREN | literal | XML_COMMENT | CDATA | LT ) => filterStep | axisStep ; axisStep : f:forwardOrReverseStep! p:predicates! { #axisStep= #(#[STEP], #f, #(#[PREDICATES],#p) ); } ; predicates : ( predicate )* ; predicate : LPPAREN! predExpr:expr RPPAREN! { #predicate= #(#[PREDICATE], #predExpr); } ; forwardOrReverseStep : ( forwardAxisSpecifier COLON ) => f:forwardAxis! n:nodeTest! { #forwardOrReverseStep = #(#forwardOrReverseStep, #f, #(#[NODETEST], #n)); } | ( reverseAxisSpecifier COLON ) => f2:reverseAxis! n2:nodeTest! { #forwardOrReverseStep = #(#forwardOrReverseStep, #f2, #(#[NODETEST], #n2)); } | abbrevStep ; abbrevStep : ( ( a:AT! n:nodeTest! { #abbrevStep = #(#[AT], #n); } ) | nodeTest ) | p:PARENT{#p.setText("");} ; forwardAxis : f:forwardAxisSpecifier! COLON! COLON! { #forwardAxis = #(#[AXIS], #f); } ; forwardAxisSpecifier : c:"child" { #c.setText("");} | s:"self" { #s.setText("");} | a:"attribute" { #a.setText("");} | d1:"descendant" { #d1.setText("");} | d:"descendant-or-self" { #d.setText("");#d.setType(DESCENDANT_OR_SELF); } | f:"following-sibling" { #f.setText("");} ; reverseAxis : r:reverseAxisSpecifier! COLON! COLON! { #reverseAxis = #(#[AXIS], #r); } ; reverseAxisSpecifier : pa:"parent" { #pa.setText("");} | a:"ancestor" { #a.setText("");} | as:"ancestor-or-self" { #as.setText("");} | pr:"preceding-sibling" { #pr.setText("");} ; nodeTest : ( . LPAREN ) => kindTest | nameTest { #nodeTest = #(#[NODETEST], nodeTest); } ; nameTest { String name= null; } : ( ( NCNAME COLON STAR ) | STAR ) => wildcard | name=q:qName { #nameTest= #(#[IDENTIFIER], #q); } ; wildcard : // *:localname ( STAR COLON ) => STAR! COLON! nc1:NCNAME { #wildcard= #(#[PREFIX_WILDCARD], #nc1); } // prefix:* | nc2:NCNAME COLON! STAR! { #wildcard= #(#[WILDCARD], #nc2); } // * | STAR { // make this distinct from multiplication #wildcard= #[WILDCARD]; } ; filterStep : primaryExpr predicates ; primaryExpr { String varName= null; } : functionCall | contextItemExpr | parenthesizedExpr | DOLLAR! varName=q:qName { #primaryExpr= #(#[VARIABLE], #(#[IDENTIFIER], #q)); } | constructor | literal ; literal : STRING_LITERAL^ | numericLiteral ; numericLiteral : DOUBLE_LITERAL^ | DECIMAL_LITERAL^ | INTEGER_LITERAL^ ; parenthesizedExpr : LPAREN! ( e:expr )? RPAREN! { #parenthesizedExpr= #(#[PARENTHESIZED], #e); } ; functionCall { String fnName= null; } : fnName=q:qName! LPAREN! { #functionCall= #(#[FUNCTION], #(#[IDENTIFIER], #q)); } ( params:functionParameters! { #functionCall= #(#[FUNCTION], #(#[IDENTIFIER], #q), #(#[PARAMETERS], #params)); } )? RPAREN! ; functionParameters : functionParameter ( COMMA! functionParameter )* ; functionParameter : e:exprSingle! {#functionParameter = #(#[PARAMETER], #e);} ; contextItemExpr : s:SELF^ { #s.setText("");}; kindTest : textTest | anyKindTest | elementTest | attributeTest | commentTest | piTest | documentTest ; textTest : "text"^ LPAREN! RPAREN! ; anyKindTest : "node"^ LPAREN! RPAREN! ; elementTest : "element"^ LPAREN! RPAREN! ; attributeTest : "attribute"^ LPAREN! RPAREN! ; commentTest : "comment"^ LPAREN! RPAREN! ; piTest : "processing-instruction"^ LPAREN! RPAREN! ; documentTest : "document-node"^ LPAREN! RPAREN! ; qName returns [String name] { name= null; String name2; } : ( ncnameOrKeyword COLON ncnameOrKeyword ) => name=ncnameOrKeyword! COLON! name2=ncnameOrKeyword! { #qName = #(#qName, #(#[NAMESPACE_NAME, name]), #(#[LOCAL_NAME, name2])); } { name= name + ':' + name2; } | name=ncnameOrKeyword { #qName = #(#[LOCAL_NAME, name]); } ; constructor : elementConstructor | xmlComment | xmlPI | cdataSection ; elementConstructor {String name= null;} : ( LT qName ~( GT | SLASH ) ) => elementWithAttributes | elementWithoutAttributes ; elementWithoutAttributes { String name= null; } : LT name=q:qName! ( ( SLASH! GT! { //lexer.wsExplicit= false; if (!elementStack.isEmpty()) lexer.inElementContent= true; #elementWithoutAttributes= #(#[ELEMENT], #(#[NAME], #q)); } ) | ( GT! { elementStack.push(name); lexer.inElementContent= true; } content:mixedElementContent! END_TAG_START! name=qName! GT! { if (elementStack.isEmpty()) throw new RecognitionException("found wrong closing tag: " + name); String prev= (String) elementStack.pop(); if (!prev.equals(name)) throw new RecognitionException("found closing tag: " + name + "; expected: " + prev); #elementWithoutAttributes= #(#[ELEMENT], #(#[NAME], #q), #content); if (!elementStack.isEmpty()) { lexer.inElementContent= true; //lexer.wsExplicit= false; } } ) ) ; elementWithAttributes { String name= null; } : LT! name=q:qName! attrs:attributeList ( ( SLASH! GT! { if (!elementStack.isEmpty()) lexer.inElementContent= true; //lexer.wsExplicit= false; #elementWithAttributes= #(#[ELEMENT], #(#[NAME], #q), #attrs); } ) | ( GT! { elementStack.push(name); lexer.inElementContent= true; //lexer.wsExplicit= false; } content:mixedElementContent! END_TAG_START! name=qName! GT! { if (elementStack.isEmpty()) throw new RecognitionException("found closing tag without opening tag: " + name); String prev= (String) elementStack.pop(); if (!prev.equals(name)) throw new RecognitionException("found closing tag: " + name + "; expected: " + prev); #elementWithAttributes= #(#[ELEMENT], #(#[NAME],#q), #attrs, #content); if (!elementStack.isEmpty()) { lexer.inElementContent= true; //lexer.wsExplicit= false; } } ) ) ; attributeList : ( attributeDef )+ {#attributeList = #(#[ATTRIBUTES], #attributeList);} ; attributeDef { String name= null; lexer.parseStringLiterals= false; } : name=q:qName! EQ! QUOT! { lexer.inAttributeContent= true; } value:attributeValue { lexer.inAttributeContent= false; } QUOT! { lexer.parseStringLiterals= true; } { #attributeDef= #(#[ATTRIBUTE], #(#[NAME], #q), #value); } ; attributeValue : ( ATTRIBUTE_CONTENT | attributeEnclosedExpr )+ { #attributeValue = #(#[VALUE], #attributeValue); } ; mixedElementContent : ( elementContent )* { #mixedElementContent = #([CONTENT], #mixedElementContent); } ; elementContent : elementConstructor | ( content:ELEMENT_CONTENT! { #elementContent = #[TEXT, content.getText() ];} ) | xmlComment | cdataSection | xmlPI | enclosedExpr ; xmlComment : XML_COMMENT XML_COMMENT_END! ; cdataSection: CDATA CDATA_END! ; xmlPI : XML_PI XML_PI_END! ; enclosedExpr : LCURLY! { globalStack.push(elementStack); elementStack= new Stack(); lexer.inElementContent= false; } e:expr! RCURLY! { elementStack= (Stack) globalStack.pop(); lexer.inElementContent= true; } {#enclosedExpr = #(#[EXPRESSION_ENCLOSED], #e); } ; attributeEnclosedExpr : LCURLY! {lexer.inAttributeContent= false;} e:expr! RCURLY! {lexer.inAttributeContent= true;} {#attributeEnclosedExpr = #(#[ATTRIBUTE_ENCLOSED], #e); } ; /* All of the literals used in this grammar can also be * part of a valid QName. We thus have to test for each * of them below. */ ncnameOrKeyword returns [String name] { name= null; } : n1:NCNAME { name= n1.getText(); } | name=reserved_XQUERY_Keywords | name=reserved_SLL_Keywords | name=reserved_BOTH_Keywords ; ncnameOr_XQUERYexclusive_Keyword returns [String name] { name= null; } : n1:NCNAME { name= n1.getText(); } | name=reserved_XQUERY_Keywords ; reserved_BOTH_Keywords returns [String name] { name= null; } : "else" { name = "else"; } | "if" { name = "if"; } | "default" { name = "default"; } | "for" { name = "for"; } | "namespace" { name = "namespace"; } | "as" { name = "as"; } | "let" { name= "let"; } | "element" { name = "element"; } | "version" { name = "version";} ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | XQUERY KEYWORDS | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| reserved_XQUERY_Keywords returns [String name] { name= null; } : "div" { name= "div"; } | "mod" { name= "mod"; } | "text" { name= "text"; } | "node" { name= "node"; } | "or" { name= "or"; } | "and" { name= "and"; } | "child" { name= "child"; } | "parent" { name= "parent"; } | "self" { name= "self"; } | "attribute" { name= "attribute"; } | "comment" { name= "comment"; } | "document" { name= "document"; } | "collection" { name= "collection"; } | "ancestor" { name= "ancestor"; } | "descendant" { name= "descendant"; } | "descendant-or-self" { name= "descendant-or-self"; } | "ancestor-or-self" { name= "ancestor-or-self"; } | "preceding-sibling" { name= "preceding-sibling"; } | "following-sibling" { name= "following-sibling"; } | "item" { name= "item"; } | "empty" { name= "empty"; } | XQUERY { name= "xquery"; } | "variable" { name= "variable"; } | "then" { name= "then"; } | "function" { name= "function"; } | "union" { name = "union"; } | "intersect" { name = "intersect"; } | "except" { name = "except"; } | "order" { name = "order"; } | "by" { name = "by"; } | "some" { name = "some"; } | "every" { name = "every"; } | "module" { name = "module"; } | //"import" { name = "import"; } //| "at" { name = "at"; } | "treat" { name = "treat"; } | "instanceof" { name = "instanceof"; } | "to" { name = "to"; } | "eq" { name = "eq"; } | "ne" { name = "ne"; } | "lt" { name = "lt"; } | "le" { name = "le"; } | "gt" { name = "gt"; } | "ge" { name = "ge"; } | "is" { name = "is"; } | "isnot" { name = "isnot"; } ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | | // | SLL KEYWORDS | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| reserved_SLL_Keywords returns [String name] { name= null; } : "processing-instruction" { name = "processing-instruction"; } | "where" { name = "where"; } | "authenticated" { name = "authenticated"; } | "defaultoperation" { name = "defaultoperation"; } | //"wrapper" { name = "wrapper"; } //| "after" { name = "after"; } | //"declare" { name = "declare"; } //| "operation" { name = "operation"; } | "requirednew" { name = "requirednew"; } | "unauthenticated" { name = "unauthenticated"; } | "send_sync" { name = "send_sync"; } | "STOP" { name = "STOP"; } | "var" { name = "var"; } | "continue" { name = "continue"; } | "unauthenticated_rp" { name = "unauthenticated_rp"; } | "FAILS" { name = "FAILS"; } | "sideeffects" { name = "sideeffects"; } | //"with" { name = "with"; } //| //"unsigned" { name = "unsigned"; } //| "error" { name = "error"; } | //"post_semantic" { name = "post_semantic"; } //| "unauthenticated_rq" { name = "unauthenticated_rq"; } | "commit" { name = "commit"; } | "propagate" { name = "propagate"; } | "getRequest" { name = "getRequest"; } | "never" { name = "never"; } | "trigger" { name = "trigger"; } | "castable" { name = "castable"; } | "input" { name = "input"; } | "retry" { name = "retry"; } | "init" { name = "init"; } | "close" { name = "close"; } | "update" { name = "update"; } | "case" { name = "case"; } | "least" { name = "least"; } | "partner" { name = "partner"; } | "postcondition" { name = "postcondition"; } | "required" { name = "required"; } | "activate" { name = "activate"; } | "into" { name = "into"; } | "delete" { name = "delete"; } | "supports" { name = "supports"; } | "on" { name = "on"; } | "nothing" { name = "nothing"; } | "KEYS_FORBIDDEN" { name = "KEYS_FORBIDDEN"; } | "encrypted_rq" { name = "encrypted_rq"; } | "isEncrypted" { name = "isEncrypted"; } | "monitor" { name = "monitor"; } | "MANUAL" { name = "MANUAL"; } | "log" { name = "log"; } | "invariant" { name = "invariant"; } | "correlation" { name = "correlation"; } | //"unencrypted" { name = "unencrypted"; } //| "throws" { name = "throws"; } | "sleep" { name = "sleep"; } | "move" { name = "move"; } | "in" { name = "in"; } | "unknownoperation" { name = "unknownoperation"; } | "throw" { name = "throw"; } | "exclude" { name = "exclude"; } | "class" { name = "class"; } | "sync" { name = "sync"; } | "greatest" { name = "greatest"; } | "language" { name = "language"; } | //"encrypted" { name = "encrypted"; } //| "contact" { name = "contact"; } | "mapping" { name = "mapping"; } | "implements" { name = "implements"; } | "do" { name = "do"; } | "event" { name = "event"; } | "authenticated_rp" { name = "authenticated_rp"; } | "conversationtimeout" { name = "conversationtimeout"; } | "private" { name = "private"; } | "pattern" { name = "pattern"; } | "idiv" { name = "idiv"; } | "history" { name = "history"; } | "transform" { name = "transform"; } | "descending" { name = "descending"; } | "unencrypted_rp" { name = "unencrypted_rp"; } | //"INVOKE" { name = "INVOKE"; } //| "before" { name = "before"; } | "prepare" { name = "prepare"; } | "scope" { name = "scope"; } | "halt" { name = "halt"; } | "conditions" { name = "conditions"; } | "abort" { name = "abort"; } | "category" { name = "category"; } | //"deny" { name = "deny"; } //| //"allow" { name = "allow"; } //| "maximum" { name = "maximum"; } | "terminate" { name = "terminate"; } | "instance" { name = "instance"; } | "label" { name = "label"; } | //"count" { name = "count"; } //| "generator" { name = "generator"; } | "authenticated_rq" { name = "authenticated_rq"; } | "ALWAYS" { name = "ALWAYS"; } | "switch" { name = "switch"; } | "unsigned_rp" { name = "unsigned_rp"; } | "ONCE" { name = "ONCE"; } | "of" { name = "of"; } | "no" { name = "no"; } | //"timeout" { name = "timeout"; } //| //"catch" { name = "catch"; } //| "semantic" { name = "semantic"; } | //"order" { name = "order"; } //| "resource" { name = "resource"; } | "cast" { name = "cast"; } | "notsupported" { name = "notsupported"; } | "return" { name = "return"; } | "wait" { name = "wait"; } | "unencrypted_rq" { name = "unencrypted_rq"; } | "conversationpattern" { name = "conversationpattern"; } | "unordered" { name = "unordered"; } | "resolution" { name = "resolution"; } | "NEW" { name = "NEW"; } | "KEYS_REQUIRED" { name = "KEYS_REQUIRED"; } | //"query" { name = "query"; } //| "send_async" { name = "send_async"; } | "context" { name = "context"; } | "unsigned_rq" { name = "unsigned_rq"; } | "lifecycle" { name = "lifecycle"; } | "replace" { name = "replace"; } | "syncpoint" { name = "syncpoint"; } | "change" { name = "change"; } | "AUTO" { name = "AUTO"; } | "set" { name = "set"; } | "ALL" { name = "ALL"; } | "custom" { name = "custom"; } | "parallel" { name = "parallel"; } | "include" { name = "include"; } | //"CONTEXT" { name = "CONTEXT"; } //| "sequence" { name = "sequence"; } | "INIT" { name = "INIT"; } | //"compensate" { name = "compensate"; } //| "break" { name = "break"; } | "satisfies" { name = "satisfies"; } | "property" { name = "property"; } | //"invoke" { name = "invoke"; } //| "select" { name = "select"; } | "encrypted_rp" { name = "encrypted_rp"; } | "xpointer" { name = "xpointer"; } | "synchronized" { name = "synchronized"; } | "print" { name = "print"; } | "deactivate" { name = "deactivate"; } | "transaction" { name = "transaction"; } | "identity" { name = "identity"; } | "get" { name = "get"; } | "rename" { name = "rename"; } | "service" { name = "service"; } | "signed_rp" { name = "signed_rp"; } | "public" { name = "public"; } | "finally" { name = "finally"; } | "mandatory" { name = "mandatory"; } | "insert" { name = "insert"; } | "try" { name = "try"; } | "precondition" { name = "precondition"; } | "ascending" { name = "ascending"; } | "while" { name = "while"; } | "signed_rq" { name = "signed_rq"; } | "document-node" { name = "document-node"; } | "ALL_REQUIRED" { name = "ALL_REQUIRED"; } | "key" { name = "key"; } | //"pre_semantic" { name = "pre_semantic"; } //| //"signed" { name = "signed"; } //| "description" { name = "description"; } | "master" { name = "master"; } | "returns" { name = "returns"; } ; // |======1=========2=========3=========4=========5=========6=========7=========8=========9=========| // | _ | // | | | | // | | | _____ _ _ _____ ____ | // | | | | ___ ( \ / ) ___ |/ ___) | // | | |_____| ____|) X (| ____| | | // | |_______)_____|_/ \_)_____)_| | // | | // |======|=========|=========|=========|=========|=========|=========|=========|=========|=========| class SLLLexer extends Lexer; options { k = 3; testLiterals = false; charVocabulary = '\u0003'..'\uffff'; codeGenBitsetTestThreshold = 30; } { protected boolean wsExplicit= false; protected boolean parseStringLiterals= true; protected boolean inElementContent= false; protected boolean inAttributeContent= false; protected boolean inComment= false; protected boolean inXMLComment= false; protected boolean inCDATASection= false; } protected XL_OR : "<>"; protected SLASH : '/' ; protected DSLASH : '/' '/' ; protected COLON : ':' ; protected COMMA : ',' ; protected SEMICOLON : ';' ; protected STAR : '*' ; protected QUESTION : '?' ; protected DQUESTION : "??" ; protected PLUS : '+' ; protected MINUS : '-' ; protected LPPAREN : '[' ; protected RPPAREN : ']' ; protected LPAREN : '(' ; protected RPAREN : ')' ; protected SELF : '.' ; protected PARENT : ".." ; protected UNION : '|' ; protected AT : '@' ; protected DOLLAR : '$' ; protected ANDEQ : "&=" ; protected OREQ : "|=" ; protected EQ : '=' ; protected NEQ : "!=" ; protected GT : '>' ; protected GTEQ : ">=" ; protected QUOT : '"' ; protected LTEQ : "<=" ; protected LT : '<' ; protected END_TAG_START : "" ; protected CDATA_END: "]]>"; protected XML_PI_START : "" ; // Single-line comments protected SL_COMMENT : { LA(1)=='/' && LA(2)=='/' }? "//" (~('\n'|'\r'){char c=LA(1);if(c==(char)-1){break;};})* ('\n'{newline();}|'\r'('\n'{newline();})?) ; // multiple-line comments protected ML_COMMENT : { LA(1)=='/' && LA(2)=='*' }? "/*" ( options { generateAmbigWarnings=false; } : { LA(2)!='/' }? '*' | '\r' '\n' {newline();} | '\r' {newline();} | '\n' {newline();} | ~('*'|'\n'|'\r') {char c=LA(1);if(c==(char)-1){break;};} )* "*/" //{$setType(Token.SKIP);} ; protected LETTER : ( BASECHAR | IDEOGRAPHIC ) ; protected DIGITS : ( DIGIT )+ ; protected HEX_DIGITS : ( '0'..'9' | 'a'..'f' | 'A'..'F' )+ ; protected NMSTART : ( LETTER | '_' ) ; protected NMCHAR : ( LETTER | DIGIT | '.' | '-' | '_' | COMBINING_CHAR | EXTENDER ) ; protected NCNAME options { testLiterals=true; } : NMSTART ( NMCHAR )* ; protected WS : ( ' ' | '\t' | '\n' {newline();} | '\r' )+ ; protected SSEND : "-------"; protected INTEGER_LITERAL : { !(inElementContent || inAttributeContent) }? DIGITS ; protected DECIMAL_LITERAL : { !(inElementContent || inAttributeContent) }? ( '.' DIGITS ) | ( DIGITS '.' ) => DIGITS '.' ( DIGITS )? ; protected DOUBLE_LITERAL : { !(inElementContent || inAttributeContent) }? ( ( '.' DIGITS ) | ( DIGITS ( '.' ( DIGIT )* )? ) ) ( 'e' | 'E' ) ( '+' | '-' )? DIGITS ; protected PREDEFINED_ENTITY_REF : '&' ( "lt" | "gt" | "amp" | "quot" | "apos" ) ';' ; protected CHAR_REF : '&' '#' ( DIGITS | ( 'x' HEX_DIGITS ) ) ';' ; protected STRING_LITERAL options { testLiterals = false; } : '"'! ( PREDEFINED_ENTITY_REF | CHAR_REF | ( '"'! '"' ) | ~ ( '"' | '&' ) )* '"'! | '\''! ( PREDEFINED_ENTITY_REF | CHAR_REF | ( '\''! '\'' ) | ~ ( '\'' | '&' ) )* '\''! ; protected ATTRIBUTE_CONTENT options { testLiterals=false; } : ( '\t' | '\r' | '\n' {newline();} | '\u0020' | '\u0021' | '\u0023'..'\u003b' | '\u003d'..'\u007a' | '\u007c' | '\u007e'..'\uFFFD' )+ ; protected ELEMENT_CONTENT options { testLiterals=false; } : ( '\t' | '\r' | '\n'{newline();} | '\u0020'..'\u003b' | '\u003d'..'\u007a' | '\u007c' | '\u007e'..'\uFFFD' )+ ; protected XML_COMMENT options { testLiterals=false; } : "