5 using AspectSharp.Lang.AST;
\r
11 class AspectLanguageParser extends Parser;
\r
15 exportVocab=aspectLanguage;
\r
16 defaultErrorHandler = true;
\r
27 INTERCEPTORS="interceptors";
\r
28 ADVICEINTERCEPTOR="advice";
\r
29 POINTCUT="pointcut";
\r
31 PROPERTY="property";
\r
32 PROPERTY_READ="propertyread";
\r
33 PROPERTY_WRITE="propertywrite";
\r
34 ASSIGNFROM="assignableFrom";
\r
35 CUSTOMMATCHER="customMatcher";
\r
36 EXCLUDES="excludes";
\r
37 INCLUDES="includes";
\r
40 protected StringBuilder sbuilder = new StringBuilder();
\r
42 protected LexicalInfo ToLexicalInfo(antlr.Token token)
\r
44 int line = token.getLine();
\r
45 int startColumn = token.getColumn();
\r
46 int endColumn = token.getColumn() + token.getText().Length;
\r
47 String filename = token.getFilename();
\r
48 return new LexicalInfo(filename, line, startColumn, endColumn);
\r
51 protected String methodAll(String s)
\r
60 start returns [EngineConfiguration conf]
\r
62 conf = new EngineConfiguration();
\r
64 (options { greedy=true;}: EOS!)*
\r
65 (import_directive[conf])*
\r
66 (interceptors_global[conf])*
\r
67 (mixins_global[conf])*
\r
73 import_directive[EngineConfiguration conf]
\r
76 String assemblyName;
\r
77 ImportDirective import = null;
\r
79 i:IMPORT! ns=identifier!
\r
81 import = new ImportDirective( ToLexicalInfo(i), ns );
\r
82 conf.Imports.Add(import);
\r
85 IN! assemblyName=identifier!
\r
87 import.AssemblyReference = new AssemblyReference( ToLexicalInfo(i), assemblyName);
\r
93 interceptors_global[EngineConfiguration conf] :
\r
94 INTERCEPTORS! keytypepair[conf.Interceptors]
\r
100 mixins_global[EngineConfiguration conf] :
\r
101 MIXINS! keytypepair[conf.Mixins]
\r
107 keytypepair [IDeclarationCollection collection] :
\r
110 (pairvalue[collection] (SEMI pairvalue[collection])*)
\r
116 pairvalue [IDeclarationCollection collection]
\r
118 DefinitionBase definition = null;
\r
120 keyToken:STRING_LITERAL! COLON
\r
122 String key = keyToken.getText();
\r
123 definition = collection.Add( key, ToLexicalInfo(keyToken) );
\r
125 type_name[definition]
\r
129 type_name_or_ref returns [TypeReference type]
\r
133 refTypeToken:STRING_LITERAL!
\r
135 type = new TypeReference();
\r
136 type.LinkRef = refTypeToken.getText();
\r
139 type=type_name_def!
\r
143 type_name[DefinitionBase definition]
\r
145 TypeReference tr = null;
\r
149 definition.TypeReference = tr;
\r
154 type_name_def returns [TypeReference type]
\r
156 type = new TypeReference();
\r
157 String typeToken = null;
\r
158 String assemblyToken = null;
\r
160 typeToken=identifier!
\r
162 type.TypeName = typeToken;
\r
165 i:IN! assemblyToken=identifier!
\r
167 type.AssemblyReference = new AssemblyReference( ToLexicalInfo(i), assemblyToken );
\r
173 aspects [EngineConfiguration conf]
\r
175 AspectDefinition aspect = null;
\r
176 TargetTypeDefinition target = null;
\r
177 TypeReference tr = null;
\r
179 a:ASPECT! aspectId:ID FOR!
\r
181 aspect = new AspectDefinition( ToLexicalInfo(a), aspectId.getText() );
\r
182 conf.Aspects.Add(aspect);
\r
187 target = new TargetTypeDefinition( tr );
\r
188 target.TargetStrategy = TargetStrategyEnum.SingleType;
\r
189 aspect.TargetType = target;
\r
194 target = new TargetTypeDefinition( );
\r
195 aspect.TargetType = target;
\r
196 String namespaceRegEx = null;
\r
199 ASSIGNFROM LCURLY! tr=type_name_def! RCURLY!
\r
201 target.TargetStrategy = TargetStrategyEnum.Assignable;
\r
202 target.AssignType = tr;
\r
205 CUSTOMMATCHER LCURLY! tr=type_name_def! RCURLY!
\r
207 target.TargetStrategy = TargetStrategyEnum.Custom;
\r
208 target.CustomMatcherType = tr;
\r
212 namespaceRegEx=identifier
\r
214 target.TargetStrategy = TargetStrategyEnum.Namespace;
\r
215 target.NamespaceRoot = namespaceRegEx;
\r
218 EXCLUDES LCURLY type_list[target.Excludes] RCURLY
\r
226 (pointcut[aspect])*
\r
232 type_list [TypeReferenceCollection types]
\r
234 TypeReference tr = null;
\r
241 SEMI! tr=type_name_def!
\r
249 include [AspectDefinition aspect]
\r
251 TypeReference tr = null;
\r
252 MixinDefinition md;
\r
256 md = new MixinDefinition( ToLexicalInfo(i) );
\r
258 tr=type_name_or_ref!
\r
260 md.TypeReference = tr;
\r
261 aspect.Mixins.Add( md );
\r
266 pointcut [AspectDefinition aspect]
\r
268 PointCutDefinition pointcut = null;
\r
269 PointCutFlags flags = PointCutFlags.Unspecified;
\r
271 p:POINTCUT! flags=pointcutflags
\r
273 pointcut = new PointCutDefinition( ToLexicalInfo(p), flags );
\r
274 aspect.PointCuts.Add( pointcut );
\r
276 pointcuttarget[pointcut]
\r
282 advices [PointCutDefinition pointcut] :
\r
283 (advice[pointcut])*
\r
287 advice [PointCutDefinition pointcut]
\r
289 TypeReference tr = null;
\r
290 InterceptorDefinition interDef = null;
\r
292 i:ADVICEINTERCEPTOR
\r
294 interDef = new InterceptorDefinition( ToLexicalInfo(i) );
\r
296 LCURLY tr=type_name_or_ref!
\r
298 interDef.TypeReference = tr;
\r
299 pointcut.Advices.Add( interDef );
\r
305 pointcutflags returns [PointCutFlags flags]
\r
307 flags = PointCutFlags.Unspecified;
\r
309 flags=pointcutflag[flags] (OR flags=pointcutflag[flags])?
\r
313 pointcutflag[PointCutFlags flags] returns [PointCutFlags retValue]
\r
318 { retValue |= PointCutFlags.Method; }
\r
321 { retValue |= PointCutFlags.Property; }
\r
324 { retValue |= PointCutFlags.PropertyRead; }
\r
327 { retValue |= PointCutFlags.PropertyWrite; }
\r
331 pointcuttarget [PointCutDefinition pointcut] :
\r
333 pointcutsignature[pointcut]
\r
339 pointcutsig1 [PointCutDefinition pointcut]
\r
342 MethodSignature ms = null;
\r
348 ms = AllMethodSignature.Instance;
\r
351 part1 = reg_ex[true]
\r
352 { ms = new MethodSignature(part1, methodAll("*")); }
\r
354 { pointcut.Method = pointcutsig2(part1, ms); }
\r
358 pointcutsig2 [String part1, MethodSignature ms] returns [MethodSignature ret]
\r
364 ALL { part2 = "*"; }
\r
365 ret = pointcutsig3[part1, part2, ms]
\r
368 pointcutarguments[ms]
\r
376 part2 = reg_ex[true]
\r
377 ret = pointcutsig3[part1, part2, ms]
\r
382 pointcutsig3 [String part1, String part2, MethodSignature ms] returns [MethodSignature ret]
\r
388 ALL { part3 = "*"; }
\r
389 { ms = new MethodSignature(part1, part2, methodAll(part3)); }
\r
393 { ms = new MethodSignature(part1, methodAll(part2)); }
\r
394 pointcutarguments[ms]
\r
399 { ms = new MethodSignature(part1, methodAll(part2)); }
\r
401 part3 = reg_ex[false]
\r
402 { ms = new MethodSignature(part1, part2, methodAll(part3)); }
\r
408 pointcutsig4 [MethodSignature ms]
\r
412 pointcutarguments[ms]
\r
421 pointcutsignature [PointCutDefinition pointcut]
\r
423 pointcutsig1[pointcut]
\r
428 pointcutarguments [MethodSignature ms] :
\r
429 (pointcutargument[ms] (COMMA pointcutargument[ms])*)?
\r
433 pointcutargument [MethodSignature ms]
\r
435 String argType = String.Empty;
\r
439 ms.AddArgumentType( "*" );
\r
442 argType=reg_ex[false]!
\r
444 ms.AddArgumentType( argType );
\r
449 identifier returns [String value]
\r
451 value = null; sbuilder.Length = 0;
\r
455 sbuilder.Append(id.getText());
\r
456 value = sbuilder.ToString();
\r
458 ( options { greedy = true; }:
\r
462 sbuilder.Append('.');
\r
463 sbuilder.Append(id2.getText());
\r
467 value = sbuilder.ToString();
\r
472 reg_ex [Boolean allowALL] returns [String value]
\r
474 value = null; sbuilder.Length = 0;
\r
479 sbuilder.Append(id.getText());
\r
480 value = sbuilder.ToString();
\r
482 ( options { greedy = true; }:
\r
485 { if (LA(1) == ALL) {
\r
489 throw new NoViableAltException(LT(1), getFilename());
\r
495 sbuilder.Append('.');
\r
499 sbuilder.Append('*');
\r
504 value = sbuilder.ToString();
\r