summaryrefslogtreecommitdiff
path: root/giscanner/annotationpatterns.py
blob: a403005168587f5c06e1708283b8fc5a4a150df0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# -*- Mode: Python -*-
# GObject-Introspection - a framework for introspecting GObject libraries
# Copyright (C) 2012 Dieter Verfaillie <dieterv@optionexplicit.be>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#


'''
This module provides regular expression programs that can be used to identify
and extract useful information from different parts of GTK-Doc comment blocks.
These programs are built to:
 - match (or substitute) a single comment block line at a time;
 - support MULTILINE mode and should support (but remains untested)
   LOCALE and UNICODE modes.
'''


import re


# Program matching the start of a comment block.
#
# Results in 0 symbolic groups.
COMMENT_START_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    /                                        # 1 forward slash character
    \*{2}                                    # exactly 2 asterisk characters
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching the end of a comment block.
#
# Results in 0 symbolic groups.
COMMENT_END_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    \*+                                      # 1 or more asterisk characters
    /                                        # 1 forward slash character
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching the "*" at the beginning of every
# line inside a comment block.
#
# Results in 0 symbolic groups.
COMMENT_ASTERISK_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    \*                                       # 1 asterisk character
    [^\S\n\r]?                               # 0 or 1 whitespace characters
                                             #   Carefull: removing more would
                                             #   break embedded example program
                                             #   indentation
    ''',
    re.VERBOSE)

# Program matching an empty line.
#
# Results in 0 symbolic groups.
EMPTY_LINE_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or 1 whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching SECTION identifiers.
#
# Results in 2 symbolic groups:
#   - group 1 = colon
#   - group 2 = section_name
SECTION_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    SECTION                                  # SECTION
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<section_name>\w\S+)?                 # section name
    [^\S\n\r]*                               # 0 or more whitespace characters
    $
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching symbol (function, constant, struct and enum) identifiers.
#
# Results in 3 symbolic groups:
#   - group 1 = symbol_name
#   - group 2 = colon
#   - group 3 = annotations
SYMBOL_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<symbol_name>[\w-]*\w)                # symbol name
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching property identifiers.
#
# Results in 4 symbolic groups:
#   - group 1 = class_name
#   - group 2 = property_name
#   - group 3 = colon
#   - group 4 = annotations
PROPERTY_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<class_name>[\w]+)                    # class name
    [^\S\n\r]*                               # 0 or more whitespace characters
    :{1}                                     # required colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<property_name>[\w-]*\w)              # property name
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching signal identifiers.
#
# Results in 4 symbolic groups:
#   - group 1 = class_name
#   - group 2 = signal_name
#   - group 3 = colon
#   - group 4 = annotations
SIGNAL_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<class_name>[\w]+)                    # class name
    [^\S\n\r]*                               # 0 or more whitespace characters
    :{2}                                     # 2 required colons
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<signal_name>[\w-]*\w)                # signal name
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching parameters.
#
# Results in 4 symbolic groups:
#   - group 1 = parameter_name
#   - group 2 = annotations
#   - group 3 = colon
#   - group 4 = description
PARAMETER_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    @                                        # @ character
    (?P<parameter_name>[\w-]*\w|\.\.\.)      # parameter name
    [^\S\n\r]*                               # 0 or more whitespace characters
    :{1}                                     # required colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<description>.*?)                     # description
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching old style "Description:" tag.
#
# Results in 0 symbolic groups.
DESCRIPTION_TAG_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    Description:                             # 'Description:' literal
    ''',
    re.VERBOSE | re.MULTILINE)

# Program matching tags.
#
# Results in 4 symbolic groups:
#   - group 1 = tag_name
#   - group 2 = annotations
#   - group 3 = colon
#   - group 4 = description
TAG_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<tag_name>virtual|since|stability|
                 deprecated|returns|
                 return\ value|attributes|
                 rename\ to|type|
                 unref\ func|ref\ func|
                 set\ value\ func|
                 get\ value\ func|
                 transfer|value)             # tag name
    [^\S\n\r]*                               # 0 or more whitespace characters
    :{1}                                     # required colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    (?P<colon>:?)                            # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<description>.*?)                     # description
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE | re.IGNORECASE)

# Program matching multiline annotation continuations.
# This is used on multiline parameters and tags (but not on the first line) to
# generate warnings about invalid annotations spanning multiple lines.
#
# Results in 3 symbolic groups:
#   - group 2 = annotations
#   - group 3 = colon
#   - group 4 = description
MULTILINE_ANNOTATION_CONTINUATION_RE = re.compile(r'''
    ^                                        # start
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<annotations>(?:\(.*?\)[^\S\n\r]*)*)  # annotations
    (?P<colon>:)                             # colon
    [^\S\n\r]*                               # 0 or more whitespace characters
    (?P<description>.*?)                     # description
    [^\S\n\r]*                               # 0 or more whitespace characters
    $                                        # end
    ''',
    re.VERBOSE | re.MULTILINE)


if __name__ == '__main__':
    import unittest

    identifier_section_tests = [
        (SECTION_RE, 'TSIEOCN',
             None),
        (SECTION_RE, 'section',
             None),
        (SECTION_RE, 'section:',
             None),
        (SECTION_RE, 'section:test',
             None),
        (SECTION_RE, 'SECTION',
             {'colon': '',
              'section_name': None}),
        (SECTION_RE, 'SECTION  \t   ',
             {'colon': '',
              'section_name': None}),
        (SECTION_RE, '   \t  SECTION  \t   ',
             {'colon': '',
              'section_name': None}),
        (SECTION_RE, 'SECTION:   \t ',
             {'colon': ':',
              'section_name': None}),
        (SECTION_RE, 'SECTION   :   ',
             {'colon': ':',
              'section_name': None}),
        (SECTION_RE, '   SECTION : ',
             {'colon': ':',
              'section_name': None}),
        (SECTION_RE, 'SECTION:gtkwidget',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, 'SECTION:gtkwidget  ',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, '  SECTION:gtkwidget',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, '  SECTION:gtkwidget\t  ',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, 'SECTION:    gtkwidget   ',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, 'SECTION   :  gtkwidget',
             {'colon': ':',
              'section_name': 'gtkwidget'}),
        (SECTION_RE, 'SECTION    gtkwidget \f  ',
             {'colon': '',
              'section_name': 'gtkwidget'})]

    identifier_symbol_tests = [
        (SYMBOL_RE, 'GBaseFinalizeFunc:',
             {'colon': ':',
              'symbol_name': 'GBaseFinalizeFunc',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show  ',
             {'colon': '',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show',
             {'colon': '',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show  ',
             {'colon': '',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show:',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show :',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show:  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show :  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show:',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show :',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show:  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, '  gtk_widget_show :  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': ''}),
        (SYMBOL_RE, 'gtk_widget_show (skip)',
             {'colon': '',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, 'gtk_widget_show: (skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, 'gtk_widget_show : (skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, 'gtk_widget_show:  (skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, 'gtk_widget_show :  (skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, '  gtk_widget_show:(skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, '  gtk_widget_show :(skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, '  gtk_widget_show:  (skip)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)'}),
        (SYMBOL_RE, '  gtk_widget_show :  (skip)    \t    ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)    \t    '}),
        (SYMBOL_RE, '  gtk_widget_show  :  (skip)   \t    ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)   \t    '}),
        (SYMBOL_RE, 'gtk_widget_show:(skip)(test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)(test1)'}),
        (SYMBOL_RE, 'gtk_widget_show (skip)(test1)',
             {'colon': '',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)(test1)'}),
        (SYMBOL_RE, 'gtk_widget_show: (skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, 'gtk_widget_show : (skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, 'gtk_widget_show:  (skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, 'gtk_widget_show :  (skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, '  gtk_widget_show:(skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, '  gtk_widget_show :(skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, '  gtk_widget_show:  (skip) (test1)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)'}),
        (SYMBOL_RE, '  gtk_widget_show :  (skip) (test1)  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1)  '}),
        (SYMBOL_RE, 'gtk_widget_show: (skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, 'gtk_widget_show : (skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, 'gtk_widget_show:  (skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, 'gtk_widget_show :  (skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, '  gtk_widget_show:(skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, '  gtk_widget_show :(skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, '  gtk_widget_show:  (skip) (test1) (test-2)',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)'}),
        (SYMBOL_RE, '  gtk_widget_show :  (skip) (test1) (test-2)  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip) (test1) (test-2)  '}),
        (SYMBOL_RE, '  gtk_widget_show  :  (skip)  (test1)  (test-2)  ',
             {'colon': ':',
              'symbol_name': 'gtk_widget_show',
              'annotations': '(skip)  (test1)  (test-2)  '}),
        # constants
        (SYMBOL_RE, 'MY_CONSTANT:',
             {'colon': ':',
              'symbol_name': 'MY_CONSTANT',
              'annotations': ''}),
        # structs
        (SYMBOL_RE, 'FooWidget:',
             {'colon': ':',
              'symbol_name': 'FooWidget',
              'annotations': ''}),
        # enums
        (SYMBOL_RE, 'Something:',
             {'colon': ':',
              'symbol_name': 'Something',
              'annotations': ''})]

    identifier_property_tests = [
        # simple property name
        (PROPERTY_RE, 'GtkWidget:name (skip)',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': '',
              'annotations': '(skip)'}),
        (PROPERTY_RE, 'GtkWidget:name',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, ' GtkWidget :name',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget: name ',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, '  GtkWidget  :  name  ',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget:name:',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget:name:  ',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, '  GtkWidget:name:',
             {'class_name': 'GtkWidget',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Something:name:',
             {'class_name': 'Something',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Something:name:  ',
             {'class_name': 'Something',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, '  Something:name:',
             {'class_name': 'Something',
              'property_name': 'name',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Weird-thing:name:',
             None),
        (PROPERTY_RE, 'really-weird_thing:name:',
             None),
        (PROPERTY_RE, 'GWin32InputStream:handle:',
             {'class_name': 'GWin32InputStream',
              'property_name': 'handle',
              'colon': ':',
              'annotations': ''}),
        # property name that contains a dash
        (PROPERTY_RE, 'GtkWidget:double-buffered (skip)',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': '',
              'annotations': '(skip)'}),
        (PROPERTY_RE, 'GtkWidget:double-buffered',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, ' GtkWidget :double-buffered',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget: double-buffered ',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, '  GtkWidget  :  double-buffered  ',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': '',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget:double-buffered:',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'GtkWidget:double-buffered:  ',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, '  GtkWidget:double-buffered:',
             {'class_name': 'GtkWidget',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Something:double-buffered:',
             {'class_name': 'Something',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Something:double-buffered:  ',
             {'class_name': 'Something',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, '  Something:double-buffered:',
             {'class_name': 'Something',
              'property_name': 'double-buffered',
              'colon': ':',
              'annotations': ''}),
        (PROPERTY_RE, 'Weird-thing:double-buffered:',
             None),
        (PROPERTY_RE, 'really-weird_thing:double-buffered:',
             None),
        (PROPERTY_RE, ' GMemoryOutputStream:realloc-function: (skip)',
             {'class_name': 'GMemoryOutputStream',
              'property_name': 'realloc-function',
              'colon': ':',
              'annotations': '(skip)'})]

    identifier_signal_tests = [
        # simple property name
        (SIGNAL_RE, 'GtkWidget::changed: (skip)',
             {'class_name': 'GtkWidget',
              'signal_name': 'changed',
              'colon': ':',
              'annotations': '(skip)'}),
        (SIGNAL_RE, 'GtkWidget::changed:',
             {'class_name': 'GtkWidget',
              'signal_name': 'changed',
              'colon': ':',
              'annotations': ''}),
        (SIGNAL_RE, 'Something::changed:',
             {'class_name': 'Something',
              'signal_name': 'changed',
              'colon': ':',
              'annotations': ''}),
        (SIGNAL_RE, 'Weird-thing::changed:',
             None),
        (SIGNAL_RE, 'really-weird_thing::changed:',
             None),
        # property name that contains a dash
        (SIGNAL_RE, 'GtkWidget::hierarchy-changed: (skip)',
             {'class_name': 'GtkWidget',
              'signal_name': 'hierarchy-changed',
              'colon': ':',
              'annotations': '(skip)'}),
        (SIGNAL_RE, 'GtkWidget::hierarchy-changed:',
             {'class_name': 'GtkWidget',
              'signal_name': 'hierarchy-changed',
              'colon': ':',
              'annotations': ''}),
        (SIGNAL_RE, 'Something::hierarchy-changed:',
             {'class_name': 'Something',
              'signal_name': 'hierarchy-changed',
              'colon': ':',
              'annotations': ''}),
        (SIGNAL_RE, 'Weird-thing::hierarchy-changed:',
             None),
        (SIGNAL_RE, 'really-weird_thing::hierarchy-changed:',
             None)]

    parameter_tests = [
        (PARAMETER_RE, '@Short_description: Base class for all widgets  ',
             {'parameter_name': 'Short_description',
              'annotations': '',
              'colon': '',
              'description': 'Base class for all widgets'}),
        (PARAMETER_RE, '@...: the value of the first property, followed optionally by more',
             {'parameter_name': '...',
              'annotations': '',
              'colon': '',
              'description': 'the value of the first property, followed optionally by more'}),
        (PARAMETER_RE, '@widget: a #GtkWidget',
             {'parameter_name': 'widget',
              'annotations': '',
              'colon': '',
              'description': 'a #GtkWidget'}),
        (PARAMETER_RE, '@widget_pointer: (inout) (transfer none): '
                       'address of a variable that contains @widget',
             {'parameter_name': 'widget_pointer',
              'annotations': '(inout) (transfer none)',
              'colon': ':',
              'description': 'address of a variable that contains @widget'}),
        (PARAMETER_RE, '@weird_thing: (inout) (transfer none) (allow-none) (attribute) (destroy) '
                       '(foreign) (inout) (out) (transfer) (skip) (method): some weird @thing',
             {'parameter_name': 'weird_thing',
              'annotations': '(inout) (transfer none) (allow-none) (attribute) (destroy) '
                                '(foreign) (inout) (out) (transfer) (skip) (method)',
              'colon': ':',
              'description': 'some weird @thing'}),
        (PARAMETER_RE, '@data: a pointer to the element data. The data may be moved as elements '
                       'are added to the #GByteArray.',
             {'parameter_name': 'data',
              'annotations': '',
              'colon': '',
              'description': 'a pointer to the element data. The data may be moved as elements '
                                'are added to the #GByteArray.'}),
        (PARAMETER_RE, '@a: a #GSequenceIter',
             {'parameter_name': 'a',
              'annotations': '',
              'colon': '',
              'description': 'a #GSequenceIter'}),
        (PARAMETER_RE, '@keys: (array length=n_keys) (element-type GQuark) (allow-none):',
             {'parameter_name': 'keys',
              'annotations': '(array length=n_keys) (element-type GQuark) (allow-none)',
              'colon': ':',
              'description': ''})]

    tag_tests = [
        (TAG_RE, 'Since 3.0',
             None),
        (TAG_RE, 'Since: 3.0',
             {'tag_name': 'Since',
              'annotations': '',
              'colon': '',
              'description': '3.0'}),
        (TAG_RE, 'Attributes: (inout) (transfer none): some note about attributes',
             {'tag_name': 'Attributes',
              'annotations': '(inout) (transfer none)',
              'colon': ':',
              'description': 'some note about attributes'}),
        (TAG_RE, 'Rename to: something_else',
             {'tag_name': 'Rename to',
              'annotations': '',
              'colon': '',
              'description': 'something_else'}),
        (TAG_RE, '@Deprecated: Since 2.8, reference counting is done atomically',
             None),
        (TAG_RE, 'Returns %TRUE and does weird things',
             None),
        (TAG_RE, 'Returns: a #GtkWidget',
             {'tag_name': 'Returns',
              'annotations': '',
              'colon': '',
              'description': 'a #GtkWidget'}),
        (TAG_RE, 'Return value: (transfer none): The binary data that @text responds. '
                 'This pointer',
             {'tag_name': 'Return value',
              'annotations': '(transfer none)',
              'colon': ':',
              'description': 'The binary data that @text responds. This pointer'}),
        (TAG_RE, 'Return value: (transfer full) (array length=out_len) (element-type guint8):',
             {'tag_name': 'Return value',
              'annotations': '(transfer full) (array length=out_len) (element-type guint8)',
              'colon': ':',
              'description': ''}),
        (TAG_RE, 'Returns: A boolean value, but let me tell you a bit about this boolean.  It',
             {'tag_name': 'Returns',
              'annotations': '',
              'colon': '',
              'description': 'A boolean value, but let me tell you a bit about this boolean.  '
                             'It'}),
        (TAG_RE, 'Returns: (transfer container) (element-type GObject.ParamSpec): a',
             {'tag_name': 'Returns',
              'annotations': '(transfer container) (element-type GObject.ParamSpec)',
              'colon': ':',
              'description': 'a'}),
        (TAG_RE, 'Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) '
                 '(transfer full):',
             {'tag_name': 'Return value',
              'annotations': '(type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) '
                             '(transfer full)',
              'colon': ':',
              'description': ''})]


    def create_tests(cls, test_name, testcases):
        for (index, testcase) in enumerate(testcases):
            real_test_name = '%s_%03d' % (test_name, index)

            test_method = cls.__create_test__(testcase)
            test_method.__name__ = real_test_name
            setattr(cls, real_test_name, test_method)


    class TestProgram(unittest.TestCase):
        @classmethod
        def __create_test__(cls, testcase):
            def do_test(self):
                (program, text, expected) = testcase

                match = program.search(text)

                if expected is None:
                    msg = 'Program matched text but shouldn\'t:\n"%s"'
                    self.assertTrue(match is None, msg % (text))
                else:
                    msg = 'Program should match text but didn\'t:\n"%s"'
                    self.assertTrue(match is not None, msg % (text))

                    for key, value in expected.items():
                        msg = 'expected "%s" for "%s" but match returned "%s"'
                        msg = msg % (value, key, match.group(key))
                        self.assertEqual(match.group(key), value, msg)

            return do_test


    # Create tests from data
    create_tests(TestProgram, 'test_identifier_section', identifier_section_tests)
    create_tests(TestProgram, 'test_identifier_symbol', identifier_symbol_tests)
    create_tests(TestProgram, 'test_identifier_property', identifier_property_tests)
    create_tests(TestProgram, 'test_identifier_signal', identifier_signal_tests)
    create_tests(TestProgram, 'test_parameter', parameter_tests)
    create_tests(TestProgram, 'test_tag', tag_tests)

    # Run test suite
    unittest.main()