grammar dsl; options { backtrack=true; output=AST; } @header { package fr.lifl.stc.stan.dsl; import java.util.Vector; } @lexer::header { package fr.lifl.stc.stan.dsl; } @members { /* Result of parsing */ public PolicyManager policies = new PolicyManager(); } /* List of identifiers */ s returns [Vector id_list] : { $id_list = new Vector(); } id=IDENTIFIER { $id_list.add($id.text); } (COMMA! res=s { $id_list.addAll($res.id_list); } )* ; r_s : sources=s 'share with'^ targets=t { ShareWith cur_policy = new ShareWith(); for(String s : $sources.id_list) cur_policy.addSource(s); for(String s : $targets.t_list) cur_policy.addTarget(s); policies.addShareWith(cur_policy); } eol ; r_c : /* Instanciate policy and add source */ source=IDENTIFIER 'secret'^ target=s { Secret cur_policy = new Secret(); cur_policy.addSource($source.text); for(String s : $target.id_list) cur_policy.addTarget(s); policies.addSecret(cur_policy); } eol ; r_p : sources=s 'strict secret'^ { for(String s : $sources.id_list) policies.addStrictSecret(s); } eol ; t returns [Vector t_list] : { $t_list = new Vector(); } (res_cp=s { for(String s : $res_cp.id_list) $t_list.add(s); } |res_st=('Static'|'IO'|'Exception') { $t_list.add($res_st.text); } ) (COMMA! res_rec=t { $t_list.addAll($res_rec.t_list); } )* ; policy : (r_c|r_s|r_p)+ ; /* End of line rule */ eol : /* Add policy to list and reset current pointer */ EOL! { } ; COMMENT : '//' .* EOL! { skip(); } ; IDENTIFIER : LETTER (LETTER|'.'|'0'..'9')* ; COMMA : ',' ; EOL : ';' ; fragment LETTER : '$' | 'A'..'Z' | 'a'..'z' | '_' ; /* Skip whitespaces and linebreaks */ WS : (' '|'\t'|'\n')+ { skip(); } ;