45 | (?P<Method> |
45 | (?P<Method> |
46 ^ |
46 ^ |
47 (?P<MethodIndent> [ \t]* ) |
47 (?P<MethodIndent> [ \t]* ) |
48 def [ \t]+ |
48 def [ \t]+ |
49 (?: |
49 (?: |
50 (?P<MethodName2> [a-zA-Z0-9_]+ (?: \. | :: ) [a-zA-Z_] [a-zA-Z0-9_?!=]* ) |
50 (?P<MethodName2> [a-zA-Z0-9_]+ (?: \. | :: ) |
|
51 [a-zA-Z_] [a-zA-Z0-9_?!=]* ) |
51 | |
52 | |
52 (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_?!=]* ) |
53 (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_?!=]* ) |
53 | |
54 | |
54 (?P<MethodName3> [^( \t]{1,3} ) |
55 (?P<MethodName3> [^( \t]{1,3} ) |
55 ) |
56 ) |
98 ^ |
99 ^ |
99 (?P<AccessControlIndent> [ \t]* ) |
100 (?P<AccessControlIndent> [ \t]* ) |
100 (?: |
101 (?: |
101 (?P<AccessControlType> private | public | protected ) [^_] |
102 (?P<AccessControlType> private | public | protected ) [^_] |
102 | |
103 | |
103 (?P<AccessControlType2> private_class_method | public_class_method ) |
104 (?P<AccessControlType2> |
|
105 private_class_method | public_class_method ) |
104 ) |
106 ) |
105 \(? |
107 \(? |
106 [ \t]* |
108 [ \t]* |
107 (?P<AccessControlList> (?: : [a-zA-Z0-9_]+ , \s* )* (?: : [a-zA-Z0-9_]+ )+ )? |
109 (?P<AccessControlList> (?: : [a-zA-Z0-9_]+ , \s* )* |
|
110 (?: : [a-zA-Z0-9_]+ )+ )? |
108 [ \t]* |
111 [ \t]* |
109 \)? |
112 \)? |
110 ) |
113 ) |
111 |
114 |
112 | (?P<Attribute> |
115 | (?P<Attribute> |
121 (?P<AttrIndent> [ \t]* ) |
124 (?P<AttrIndent> [ \t]* ) |
122 attr |
125 attr |
123 (?P<AttrType> (?: _accessor | _reader | _writer ) )? |
126 (?P<AttrType> (?: _accessor | _reader | _writer ) )? |
124 \(? |
127 \(? |
125 [ \t]* |
128 [ \t]* |
126 (?P<AttrList> (?: : [a-zA-Z0-9_]+ , \s* )* (?: : [a-zA-Z0-9_]+ | true | false )+ ) |
129 (?P<AttrList> (?: : [a-zA-Z0-9_]+ , \s* )* |
|
130 (?: : [a-zA-Z0-9_]+ | true | false )+ ) |
127 [ \t]* |
131 [ \t]* |
128 \)? |
132 \)? |
129 ) |
133 ) |
130 |
134 |
131 | (?P<Begin> |
135 | (?P<Begin> |
132 ^ |
136 ^ |
133 [ \t]* |
137 [ \t]* |
134 (?: def | if | unless | case | while | until | for | begin ) \b [^_] |
138 (?: def | if | unless | case | while | until | for | begin ) |
|
139 \b [^_] |
135 | |
140 | |
136 [ \t]* do [ \t]* (?: \| .*? \| )? [ \t]* $ |
141 [ \t]* do [ \t]* (?: \| .*? \| )? [ \t]* $ |
137 ) |
142 ) |
138 |
143 |
139 | (?P<BeginEnd> |
144 | (?P<BeginEnd> |
205 |
210 |
206 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
211 class Function(ClbrBaseClasses.Function, VisibilityMixin): |
207 """ |
212 """ |
208 Class to represent a Ruby function. |
213 Class to represent a Ruby function. |
209 """ |
214 """ |
210 def __init__(self, module, name, file, lineno, signature='', separator=','): |
215 def __init__(self, module, name, file, lineno, signature='', |
|
216 separator=','): |
211 """ |
217 """ |
212 Constructor |
218 Constructor |
213 |
219 |
214 @param module name of the module containing this function |
220 @param module name of the module containing this function |
215 @param name name of this function |
221 @param name name of this function |
317 acstack[-1][1] >= thisindent: |
323 acstack[-1][1] >= thisindent: |
318 del acstack[-1] |
324 del acstack[-1] |
319 if classstack: |
325 if classstack: |
320 # it's a class/module method |
326 # it's a class/module method |
321 cur_class = classstack[-1][0] |
327 cur_class = classstack[-1][0] |
322 if isinstance(cur_class, Class) or isinstance(cur_class, Module): |
328 if isinstance(cur_class, Class) or \ |
|
329 isinstance(cur_class, Module): |
323 # it's a method |
330 # it's a method |
324 f = Function(None, meth_name, |
331 f = Function(None, meth_name, |
325 file, lineno, meth_sig) |
332 file, lineno, meth_sig) |
326 cur_class._addmethod(meth_name, f) |
333 cur_class._addmethod(meth_name, f) |
327 else: |
334 else: |
340 # it's a function |
347 # it's a function |
341 f = Function(module, meth_name, |
348 f = Function(module, meth_name, |
342 file, lineno, meth_sig) |
349 file, lineno, meth_sig) |
343 if meth_name in dict_counts: |
350 if meth_name in dict_counts: |
344 dict_counts[meth_name] += 1 |
351 dict_counts[meth_name] += 1 |
345 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) |
352 meth_name = "{0}_{1:d}".format( |
|
353 meth_name, dict_counts[meth_name]) |
346 else: |
354 else: |
347 dict_counts[meth_name] = 0 |
355 dict_counts[meth_name] = 0 |
348 dict[meth_name] = f |
356 dict[meth_name] = f |
349 if not classstack: |
357 if not classstack: |
350 if lastGlobalEntry: |
358 if lastGlobalEntry: |
406 cur_obj = cur_class |
414 cur_obj = cur_class |
407 classstack.append((cur_class, thisindent)) |
415 classstack.append((cur_class, thisindent)) |
408 while acstack and \ |
416 while acstack and \ |
409 acstack[-1][1] >= thisindent: |
417 acstack[-1][1] >= thisindent: |
410 del acstack[-1] |
418 del acstack[-1] |
411 acstack.append(["public", thisindent]) # default access control is 'public' |
419 acstack.append(["public", thisindent]) # default access control |
|
420 # is 'public' |
412 |
421 |
413 elif m.start("Module") >= 0: |
422 elif m.start("Module") >= 0: |
414 # we found a module definition |
423 # we found a module definition |
415 thisindent = indent |
424 thisindent = indent |
416 indent += 1 |
425 indent += 1 |
446 cur_obj = cur_class |
455 cur_obj = cur_class |
447 classstack.append((cur_class, thisindent)) |
456 classstack.append((cur_class, thisindent)) |
448 while acstack and \ |
457 while acstack and \ |
449 acstack[-1][1] >= thisindent: |
458 acstack[-1][1] >= thisindent: |
450 del acstack[-1] |
459 del acstack[-1] |
451 acstack.append(["public", thisindent]) # default access control is 'public' |
460 acstack.append(["public", thisindent]) # default access control |
|
461 # is 'public' |
452 |
462 |
453 elif m.start("AccessControl") >= 0: |
463 elif m.start("AccessControl") >= 0: |
454 aclist = m.group("AccessControlList") |
464 aclist = m.group("AccessControlList") |
455 if aclist is None: |
465 if aclist is None: |
456 index = -1 |
466 index = -1 |
471 parent = classstack[index][0] |
481 parent = classstack[index][0] |
472 actype = m.group("AccessControlType") or \ |
482 actype = m.group("AccessControlType") or \ |
473 m.group("AccessControlType2").split('_')[0] |
483 m.group("AccessControlType2").split('_')[0] |
474 actype = actype.lower() |
484 actype = actype.lower() |
475 for name in aclist.split(","): |
485 for name in aclist.split(","): |
476 name = name.strip()[1:] # get rid of leading ':' |
486 name = name.strip()[1:] # get rid of leading ':' |
477 acmeth = parent._getmethod(name) |
487 acmeth = parent._getmethod(name) |
478 if acmeth is None: |
488 if acmeth is None: |
479 continue |
489 continue |
480 if actype == "private": |
490 if actype == "private": |
481 acmeth.setPrivate() |
491 acmeth.setPrivate() |
493 index = -1 |
503 index = -1 |
494 while index >= -len(classstack): |
504 while index >= -len(classstack): |
495 if classstack[index][0] is not None and \ |
505 if classstack[index][0] is not None and \ |
496 not isinstance(classstack[index][0], Function) and \ |
506 not isinstance(classstack[index][0], Function) and \ |
497 not classstack[index][1] >= indent: |
507 not classstack[index][1] >= indent: |
498 attr = Attribute(module, m.group("AttributeName"), file, lineno) |
508 attr = Attribute( |
|
509 module, m.group("AttributeName"), file, lineno) |
499 classstack[index][0]._addattribute(attr) |
510 classstack[index][0]._addattribute(attr) |
500 break |
511 break |
501 else: |
512 else: |
502 index -= 1 |
513 index -= 1 |
503 if lastGlobalEntry: |
514 if lastGlobalEntry: |
527 attr.setPublic() |
538 attr.setPublic() |
528 parent._addattribute(attr) |
539 parent._addattribute(attr) |
529 else: |
540 else: |
530 access = m.group("AttrType") |
541 access = m.group("AttrType") |
531 for name in m.group("AttrList").split(","): |
542 for name in m.group("AttrList").split(","): |
532 name = name.strip()[1:] # get rid of leading ':' |
543 name = name.strip()[1:] # get rid of leading ':' |
533 attr = parent._getattribute("@" + name) or \ |
544 attr = parent._getattribute("@" + name) or \ |
534 parent._getattribute("@@" + name) or \ |
545 parent._getattribute("@@" + name) or \ |
535 Attribute(module, "@" + name, file, lineno) |
546 Attribute(module, "@" + name, file, lineno) |
536 if access == "_accessor": |
547 if access == "_accessor": |
537 attr.setPublic() |
548 attr.setPublic() |
567 # a coding statement |
578 # a coding statement |
568 coding = m.group("Coding") |
579 coding = m.group("Coding") |
569 lineno = lineno + src.count('\n', last_lineno_pos, start) |
580 lineno = lineno + src.count('\n', last_lineno_pos, start) |
570 last_lineno_pos = start |
581 last_lineno_pos = start |
571 if "@@Coding@@" not in dict: |
582 if "@@Coding@@" not in dict: |
572 dict["@@Coding@@"] = ClbrBaseClasses.Coding(module, file, lineno, coding) |
583 dict["@@Coding@@"] = ClbrBaseClasses.Coding( |
|
584 module, file, lineno, coding) |
573 |
585 |
574 else: |
586 else: |
575 assert 0, "regexp _getnext found something unexpected" |
587 assert 0, "regexp _getnext found something unexpected" |
576 |
588 |
577 return dict |
589 return dict |