-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
docparrstformatparser__define.pro
809 lines (709 loc) · 30.3 KB
/
docparrstformatparser__define.pro
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
809
; docformat = 'rst'
;+
; Handles parsing of the rst (restructured text) style comment blocks.
;-
;+
; Parse the lines from a tag; simply removes the tag and passes along the rest.
;
; :Returns:
; strarr
;
; :Params:
; lines : in, out, required, type=strarr
; lines of text to parse
;-
function docparrstformatparser::_parseTag, lines
compile_opt strictarr, hidden
mylines = lines
pos = stregex(lines[0], '^[[:space:]]*:[[:alpha:]_]+:[[:space:]]*', length=len)
mylines[0] = strmid(lines[0], pos + len)
while (strtrim(mylines[0], 2) eq '' && n_elements(mylines) gt 1L) do begin
mylines = mylines[1:*]
endwhile
return, mylines
end
;+
; Handles one tag in a file's comments.
;
; :Params:
; tag : in, required, type=string
; rst tag, i.e. returns, params, keywords, etc.
; lines : in, required, type=strarr
; lines of raw text for that tag
;
; :Keywords:
; file : in, required, type=object
; file tree object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::_handleFileTag, tag, lines, $
file=file, $
markup_parser=markupParser
compile_opt strictarr, hidden
case strlowcase(tag) of
'file_comments' : begin
file->setProperty, comments=markupParser->parse(self->_parseTag(lines), file=file)
end
'properties': begin
; there is no way to tell right now if this properties tag is allowed or
; not, must check later
; find number of spaces that properties' names are indented
l = 1L
nameIndent = -1L
while (l lt n_elements(lines) && nameIndent eq -1L) do begin
nameIndent = stregex(lines[l++], '[[:alnum:]_$]')
endwhile
; empty properties tag, so quit
if (nameIndent eq -1L) then break
; must indent property names
if (nameIndent lt 1) then begin
self.system->warning, 'invalid properties syntax'
return
endif
; find properties' names lines (ignore first line, first property starts
; on the line after :Properties:)
propLines = lines[1:*]
re = string(format='(%"^[ ]{%d}([[:alnum:]_$]+)")', nameIndent)
propertyNamesStart = stregex(propLines, re, $
/subexpr, length=propertyNamesLength)
propertyDefinitionLines = where(propertyNamesStart[1, *] ne -1L, nProperties)
; add each property
for p = 0L, nProperties - 1L do begin
propertyName = strmid(propLines[propertyDefinitionLines[p]], $
propertyNamesStart[1, propertyDefinitionLines[p]], $
propertyNamesLength[1, propertyDefinitionLines[p]])
property = self->_addToHeldProperties(propertyName)
; add property attributes: right now only TYPE=
propattrs = strmid(propLines[propertyDefinitionLines[p]], $
propertyNamesStart[1, propertyDefinitionLines[p]] $
+ propertyNamesLength[1, propertyDefinitionLines[p]])
eqpos = strpos(propattrs, '=')
if (eqpos ge 0L) then begin
attrnameTokens = strsplit(strmid(propattrs, 0, eqpos), /extract, count=nAttrnameTokens)
attrname = attrnameTokens[nAttrnameTokens - 1L]
if (strlowcase(attrname) ne 'type') then begin
self.system->warning, 'invalid property attribute: ' + attrname
endif else begin
proptype = strtrim(strmid(propattrs, eqpos + 1), 2)
property->setProperty, type=proptype
endelse
endif
propertyDefinitionEnd = p eq nProperties - 1L $
? n_elements(propLines) - 1L $
: propertyDefinitionLines[p + 1L] - 1L
if (propertyDefinitionLines[p] + 1 le propertyDefinitionEnd) then begin
comments = propLines[propertyDefinitionLines[p] + 1L:propertyDefinitionEnd]
property->setProperty, comments=markupParser->parse(comments, file=file)
endif
endfor
end
'hidden': file->setProperty, is_hidden=1B
'private': file->setProperty, is_private=1B
'examples': file->setProperty, examples=markupParser->parse(self->_parseTag(lines), file=file)
'author': file->setProperty, author=markupParser->parse(self->_parseTag(lines), file=file)
'copyright': file->setProperty, copyright=markupParser->parse(self->_parseTag(lines), file=file)
'history': file->setProperty, history=markupParser->parse(self->_parseTag(lines), file=file)
'version': file->setProperty, version=markupParser->parse(self->_parseTag(lines), file=file)
'abstract': file->setProperty, is_abstract=1B
'bugs': begin
self.system->createBugEntry, file
file->setProperty, bugs=markupParser->parse(self->_parseTag(lines), file=file)
end
'categories': begin
comments = self->_parseTag(lines)
categories = strtrim(strsplit(strjoin(comments), ',', /extract), 2)
for i = 0L, n_elements(categories) - 1L do begin
if (categories[i] ne '') then begin
file->addCategory, categories[i]
self.system->createCategoryEntry, categories[i], file
endif
endfor
end
'customer_id': file->setProperty, customer_id=markupParser->parse(self->_parseTag(lines), file=file)
'obsolete': begin
self.system->createObsoleteEntry, file
file->setProperty, is_obsolete=1B
end
'requires': begin
requires = self->_parseTag(lines)
; look for an IDL version
for i = 0L, n_elements(requires) - 1L do begin
version = stregex(lines[i], '[[:digit:].]+', /extract)
if (version ne '') then break
endfor
; if you have a real version then check in with system
if (version ne '') then begin
self.system->checkRequiredVersion, version, file
endif
file->setProperty, requires=markupParser->parse(requires, file=file)
end
'restrictions': file->setProperty, restrictions=markupParser->parse(self->_parseTag(lines), file=file)
'todo': begin
file->setProperty, todo=markupParser->parse(self->_parseTag(lines), file=file)
self.system->createTodoEntry, file
end
'uses': file->setProperty, uses=markupParser->parse(self->_parseTag(lines), file=file)
'fields': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
'post': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
'pre': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
'params': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
'keywords': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
'returns': begin
file->getProperty, basename=basename
msg = '(%"routine level tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
else: begin
file->getProperty, basename=basename
msg = '(%"unknown tag ''%s'' at file level in %s")'
self.system->warning, string(format=msg, tag, basename)
end
endcase
end
;+
; Handles one tag in a routine's comments.
;
; :Params:
; tag : in, required, type=string
; rst tag, i.e. returns, params, keywords, etc.
; lines : in, required, type=strarr
; lines of raw text for that tag
;
; :Keywords:
; routine : in, required, type=object
; routine tree object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::_handleRoutineTag, tag, lines, routine=routine, $
markup_parser=markupParser
compile_opt strictarr, hidden
routine->getProperty, file=file
case strlowcase(tag) of
'abstract': routine->setProperty, is_abstract=1B
'author': routine->setProperty, author=markupParser->parse(self->_parseTag(lines), file=file)
'bugs': begin
routine->setProperty, bugs=markupParser->parse(self->_parseTag(lines), file=file)
self.system->createBugEntry, routine
end
'categories': begin
comments = self->_parseTag(lines)
categories = strtrim(strsplit(strjoin(comments), ',', /extract), 2)
for i = 0L, n_elements(categories) - 1L do begin
if (categories[i] ne '') then begin
routine->addCategory, categories[i]
self.system->createCategoryEntry, categories[i], routine
endif
endfor
end
'copyright': routine->setProperty, copyright=markupParser->parse(self->_parseTag(lines), file=file)
'customer_id': routine->setProperty, customer_id=markupParser->parse(self->_parseTag(lines), file=file)
; handle description tag for ITT VIS Workbench integration
'description': routine->setProperty, comments=markupParser->parse(self->_parseTag(lines), file=file)
'examples': routine->setProperty, examples=markupParser->parse(self->_parseTag(lines), file=file)
'fields': begin
; fields are only allowed in routine named "classname__define"
routine->getProperty, file=file, name=name
classname = strmid(name, 0, strlen(name) - 8)
if (strlowcase(strmid(name, 7, /reverse_offset)) ne '__define') then begin
self.system->warning, 'field not allowed in non-class definition routine'
break
endif
; find number of spaces that fields' names are indented
l = 1L
nameIndent = -1L
while (l lt n_elements(lines) && nameIndent eq -1L) do begin
nameIndent = stregex(lines[l++], '[[:alnum:]_$]')
endwhile
; this is an empty fields tag, so quit
if (nameIndent eq -1L) then break
; must indent fields names
if (nameIndent lt 1) then begin
self.system->warning, 'invalid fields syntax'
return
endif
; find fields' names lines (ignore first line, first field starts
; on the line after :Fields:)
fieldLines = lines[1:*]
re = string(format='(%"^[ ]{%d}([[:alnum:]_$]+)")', nameIndent)
fieldNamesStart = stregex(fieldLines, re, $
/subexpr, length=fieldNamesLength)
fieldDefinitionLines = where(fieldNamesStart[1, *] ne -1L, nFields)
; get the class tree object
class = file->getClass(classname)
; add each field
for f = 0L, nFields - 1L do begin
fieldName = strmid(fieldLines[fieldDefinitionLines[f]], $
fieldNamesStart[1, fieldDefinitionLines[f]], $
fieldNamesLength[1, fieldDefinitionLines[f]])
field = class->addField(fieldName, /get_only)
fieldDefinitionEnd = f eq nFields - 1L $
? n_elements(fieldLines) - 1L $
: fieldDefinitionLines[f + 1L] - 1L
if (fieldDefinitionLines[f] + 1L le fieldDefinitionEnd) then begin
if (obj_valid(field)) then begin
comments = fieldLines[fieldDefinitionLines[f] + 1L:fieldDefinitionEnd]
field->setProperty, name=fieldName, comments=markupParser->parse(comments, file=file)
endif else begin
self.system->warning, 'invalid field ' + fieldName
endelse
endif
endfor
end
'file_comments': begin
routine->getProperty, file=file
file->setProperty, comments=markupParser->parse(self->_parseTag(lines), file=file)
end
'hidden': routine->setProperty, is_hidden=1
'hidden_file': begin
routine->getProperty, file=file
file->setProperty, is_hidden=1B
end
'history': routine->setProperty, history=markupParser->parse(self->_parseTag(lines), file=file)
'inherits': begin
routine->getProperty, name=name
msg = '(%"obsolete tag ''%s'' at routine level in %s")'
self.system->warning, string(format=msg, tag, name)
end
'keywords': self->_handleArgumentTag, lines, routine=routine, $
markup_parser=markupParser, /keyword
'obsolete': begin
routine->setProperty, is_obsolete=1B
self.system->createObsoleteEntry, routine
end
'params': self->_handleArgumentTag, lines, routine=routine, $
markup_parser=markupParser
'post': routine->setProperty, post=markupParser->parse(self->_parseTag(lines), file=file)
'pre': routine->setProperty, pre=markupParser->parse(self->_parseTag(lines), file=file)
'private': routine->setProperty, is_private=1B
'private_file': begin
routine->getProperty, file=file
file->setProperty, is_private=1B
end
'properties': begin
routine->getProperty, name=name
msg = '(%"properties tag at routine level in %s")'
self.system->warning, string(format=msg, tag, name)
end
'requires': begin
requires = self->_parseTag(lines)
; look for an IDL version
for i = 0L, n_elements(requires) - 1L do begin
version = stregex(lines[i], '[[:digit:].]+', /extract)
if (version ne '') then break
endfor
; if you have a real version then check in with system
if (version ne '') then begin
self.system->checkRequiredVersion, version, routine
endif
routine->setProperty, requires=markupParser->parse(requires, file=file)
end
'restrictions': routine->setProperty, restrictions=markupParser->parse(self->_parseTag(lines), file=file)
'returns': routine->setProperty, returns=markupParser->parse(self->_parseTag(lines), file=file)
'todo': begin
routine->setProperty, todo=markupParser->parse(self->_parseTag(lines), file=file)
self.system->createTodoEntry, routine
end
'uses': routine->setProperty, uses=markupParser->parse(self->_parseTag(lines), file=file)
'version': routine->setProperty, version=markupParser->parse(self->_parseTag(lines), file=file)
else: begin
routine->getProperty, name=name
msg = '(%"unknown tag ''%s'' at routine level in %s")'
self.system->warning, string(format=msg, tag, name)
end
endcase
end
;+
; Handles a tag with attributes (i.e. {} enclosed arguments like in param or
; keyword).
;
; :Params:
; lines : in, required, type=strarr
; lines of raw text for that tag
;
; :Keywords:
; routine : in, required, type=object
; routine tree object
; markup_parser : in, required, type=object
; markup parser object
; keyword : in, optional, type=boolean
; set to indicate the tag is a keyword
;-
pro docparrstformatparser::_handleArgumentTag, lines, $
routine=routine, $
markup_parser=markupParser, $
keyword=keyword
compile_opt strictarr, hidden
; find params/keywords
tag = keyword_set(keyword) ? 'keyword' : 'param'
; find number of spaces that properties' names are indented
l = 1L
nameIndent = -1L
while (l lt n_elements(lines) && nameIndent eq -1L) do begin
nameIndent = stregex(lines[l++], '[[:alnum:]_$]')
endwhile
; empty Params or Keywords tag, so quit
if (nameIndent eq -1L) then return
; must indent property names
if (nameIndent lt 1) then begin
self.system->warning, 'invalid ' + tag + 's syntax'
return
endif
; find properties' names lines (ignore first line, first property starts
; on the line after :Properties:)
paramLines = lines[1:*]
re = string(format='(%"^[ ]{%d}([[:alnum:]_$]+)")', nameIndent)
paramNamesStart = stregex(paramLines, re, $
/subexpr, length=paramNamesLength)
paramDefinitionLines = where(paramNamesStart[1, *] ne -1L, nParams)
routine->getProperty, name=routineName
; add each property
for p = 0L, nParams - 1L do begin
paramName = strmid(paramLines[paramDefinitionLines[p]], $
paramNamesStart[1, paramDefinitionLines[p]], $
paramNamesLength[1, paramDefinitionLines[p]])
param = keyword_set(keyword) $
? routine->getKeyword(paramName, found=found) $
: routine->getParameter(paramName, found=found)
if (~found) then begin
msg = string(format='(%"%s %s not found in %s")', tag, paramName, routineName)
self.system->warning, msg
continue
endif
headerLine = paramLines[paramDefinitionLines[p]]
colonPos = strpos(headerLine, ':')
if (colonPos ne -1L) then begin
attributes = strsplit(strmid(headerLine, colonPos + 1L), ',', $
/extract, escape='\')
; handle quoted attributes, like:
;
; vertices : in, type="fltarr(2, m, n)" lost text, required
;
; breaks down into:
;
; 0: in
; 1: type="fltarr(
; 2: m
; 3: n)" lost text
; 4: required
for a = 0L, n_elements(attributes) - 1L do begin
if (strmid(attributes[a], strpos(attributes[a], '=') + 1L, 1) eq '"') then begin
; add following attributes until closing quote or end of line
i = a + 1L
while (i lt n_elements(attributes)) do begin
t = attributes[i]
attributes[a] += ',' + t
attributes[i] = ''
if (strpos(t, '"') ne -1L) then break
i++
endwhile
; fix up attributes[a] by removing quotes
firstQuote = strpos(attributes[a], '"')
secondQuote = strpos(attributes[a], '"', firstQuote + 1L)
if (secondQuote eq -1L) then secondQuote = strlen(attributes[a])
valueLength = secondQuote - firstQuote - 1L
value = strmid(attributes[a], firstQuote + 1L, valueLength)
attributes[a] = strmid(attributes[a], 0, firstQuote) + value
endif
endfor
for a = 0L, n_elements(attributes) - 1L do begin
self->_handleAttribute, param, strtrim(attributes[a], 2), routine=routine
endfor
endif
paramDefinitionEnd = p eq nParams - 1L $
? n_elements(paramLines) - 1L $
: paramDefinitionLines[p + 1L] - 1L
if (paramDefinitionLines[p] + 1 le paramDefinitionEnd) then begin
comments = paramLines[paramDefinitionLines[p] + 1L:paramDefinitionEnd]
routine->getProperty, file=file
param->setProperty, comments=markupParser->parse(comments, file=file)
endif
endfor
end
;+
; Handle parameter/keyword attributes.
;
; :Params:
; param : in, required, type=object
; argument tree object
; attribute : in, required, type=string
; attribute name and, optionally, value i.e. "in" or "type=string"
;
; :Keywords:
; routine : in, required, type=object
; routine tree object
;-
pro docparrstformatparser::_handleAttribute, param, attribute, routine=routine
compile_opt strictarr, hidden
if (attribute eq '') then return
param->getProperty, name=paramName
routine->getProperty, name=routineName
result = strsplit(attribute, '=', /extract)
attributeName = strtrim(result[0], 2)
attributeValue = (n_elements(result) gt 1) ? result[1] : ''
case attributeName of
'in': param->setProperty, is_input=1
'out': param->setProperty, is_output=1
'optional': param->setProperty, is_optional=1
'required': param->setProperty, is_required=1
'private': param->setProperty, is_private=1
'hidden': param->setProperty, is_hidden=1
'obsolete': param->setProperty, is_obsolete=1
'type': param->setProperty, type=attributeValue
'default': param->setProperty, default_value=attributeValue
else: begin
self.system->warning, $
'unknown argument attribute "' + attributeName $
+ '" for argument ' + paramName + ' in ' + routineName
end
endcase
end
;+
; Handles parsing of a routine level comment block using rst syntax.
;
; :Params:
; lines : in, required, type=strarr
; all lines of the comment block
;
; :Keywords:
; routine : in, required, type=object
; routine tree object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::parseRoutineComments, lines, routine=routine, $
markup_parser=markupParser
compile_opt strictarr, hidden
; find tags enclosed by ":"s that are the first non-whitespace character on
; the line
tagLocations = where(stregex(lines, '^[[:space:]]*:[[:alpha:]_]+:') ne -1L, nTags)
; parse normal comments
tagsStart = nTags gt 0 ? tagLocations[0] : n_elements(lines)
if (tagsStart ne 0) then begin
routine->getProperty, file=file
comments = markupParser->parse(lines[0:tagsStart - 1L], file=file)
routine->setProperty, comments=comments
endif
; go through each tag
for t = 0L, nTags - 1L do begin
tagStart = tagLocations[t]
tagFull = stregex(lines[tagStart], ':[[:alpha:]_]+:', /extract)
tag = strmid(tagFull, 1, strlen(tagFull) - 2L)
tagEnd = t eq nTags - 1L $
? n_elements(lines) - 1L $
: tagLocations[t + 1L] - 1L
self->_handleRoutineTag, tag, lines[tagStart:tagEnd], $
routine=routine, markup_parser=markupParser
endfor
end
;+
; Handles parsing of a file level comment block using rst syntax.
;
; :Params:
; lines : in, required, type=strarr
; all lines of the comment block
;
; :Keywords:
; file : in, required, type=object
; file tree object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::parseFileComments, lines, file=file, $
markup_parser=markupParser
compile_opt strictarr, hidden
; find tags enclosed by ":"s that are the first non-whitespace character on
; the line
re = '^[[:space:]]*:[[:alpha:]_]+:'
tagLocations = where(stregex(lines, re) ne -1L, nTags)
; parse normal comments
tagsStart = nTags gt 0 ? tagLocations[0] : n_elements(lines)
if (tagsStart ne 0) then begin
comments = markupParser->parse(lines[0:tagsStart - 1L], file=file)
file->setProperty, comments=comments
endif
; go through each tag
for t = 0L, nTags - 1L do begin
tagStart = tagLocations[t]
tagFull = stregex(lines[tagStart], ':[[:alpha:]_]+:', /extract)
tag = strmid(tagFull, 1, strlen(tagFull) - 2L)
tagEnd = t eq nTags - 1L $
? n_elements(lines) - 1L $
: tagLocations[t + 1L] - 1L
self->_handleFileTag, tag, lines[tagStart:tagEnd], $
file=file, markup_parser=markupParser
endfor
end
;+
; Handles parsing of a comment block in the directory overview file using rst
; syntax.
;
; :Params:
; lines : in, required, type=strarr
; all lines of the comment block
;
; :Keywords:
; directory : in, required, type=object
; directory object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::parseDirOverviewComments, lines, directory=directory, $
markup_parser=markupParser
compile_opt strictarr, hidden
; find tags enclosed by ":"s that are the first non-whitespace character on
; the line
re = '^[[:space:]]*:[[:alpha:]_]+:'
tagLocations = where(stregex(lines, re) ne -1L, nTags)
; parse normal comments
tagsStart = nTags gt 0 ? tagLocations[0] : n_elements(lines)
if (tagsStart ne 0) then begin
comments = markupParser->parse(lines[0:tagsStart - 1L])
directory->setProperty, comments=comments
endif
; go through each tag
for t = 0L, nTags - 1L do begin
tagStart = tagLocations[t]
re = ':[[:alpha:]_]+:'
fullTag = stregex(lines[tagStart], re, /extract)
tag = strmid(fullTag, 1, strlen(fullTag) - 2L)
tagEnd = t eq nTags - 1L $
? n_elements(lines) - 1L $
: tagLocations[t + 1L] - 1L
tagLines = self->_parseTag(lines[tagStart:tagEnd])
case strlowcase(tag) of
'private': directory->setProperty, is_private=1B
'hidden': directory->setProperty, is_hidden=1B
'author': directory->setProperty, author=markupParser->parse(tagLines)
'copyright': directory->setProperty, copyright=markupParser->parse(tagLines)
'history': directory->setProperty, history=markupParser->parse(tagLines)
else: begin
directory->getProperty, location=location
self.system->warning, 'unknown tag "' + tag + '" in directory overview file for ' + location
end
endcase
endfor
end
;+
; Handles parsing of a comment block in the overview file using rst syntax.
;
; :Params:
; lines : in, required, type=strarr
; all lines of the comment block
;
; :Keywords:
; system : in, required, type=object
; system object
; markup_parser : in, required, type=object
; markup parser object
;-
pro docparrstformatparser::parseOverviewComments, lines, system=system, $
markup_parser=markupParser
compile_opt strictarr, hidden
; find tags enclosed by ":"s that are the first non-whitespace character on
; the line
re = '^[[:space:]]*:[[:alpha:]_]+:'
tagLocations = where(stregex(lines, re) ne -1L, nTags)
; parse normal comments
tagsStart = nTags gt 0 ? tagLocations[0] : n_elements(lines)
if (tagsStart ne 0) then begin
comments = markupParser->parse(lines[0:tagsStart - 1L])
system->setProperty, overview_comments=comments
endif
; go through each tag
for t = 0L, nTags - 1L do begin
tagStart = tagLocations[t]
re = ':[[:alpha:]_]+:'
fullTag = stregex(lines[tagStart], re, /extract)
tag = strmid(fullTag, 1, strlen(fullTag) - 2L)
tagEnd = t eq nTags - 1L $
? n_elements(lines) - 1L $
: tagLocations[t + 1L] - 1L
tagLines = self->_parseTag(lines[tagStart:tagEnd])
case strlowcase(tag) of
'author': system->setProperty, author=markupParser->parse(tagLines)
'copyright': system->setProperty, copyright=markupParser->parse(tagLines)
'history': system->setProperty, history=markupParser->parse(tagLines)
'version': system->setProperty, version=markupParser->parse(tagLines)
'dirs': begin
system->getProperty, directories=directories
; find number of spaces that directories' names are indented
l = 0L
nameIndent = -1L
while (l lt n_elements(tagLines) && nameIndent eq -1L) do begin
nameIndent = stregex(tagLines[l++], '[[:alnum:]_$./]')
endwhile
; must indent directories' names
if (nameIndent lt 1) then begin
self.system->warning, 'invalid directories syntax'
return
endif
; find directories' names lines (ignore first line, first directory
; starts on the line after :Dirs:)
dirLines = tagLines[0L:*]
re = string(format='(%"^[ ]{%d}([[:alnum:]._$\-\/]+)")', nameIndent)
dirNamesStart = stregex(dirLines, re, $
/subexpr, length=dirNamesLength)
dirDefinitionLines = where(dirNamesStart[1, *] ne -1L, nDirs)
; add each property
for d = 0L, nDirs - 1L do begin
dirName = strmid(dirLines[dirDefinitionLines[d]], $
dirNamesStart[1, dirDefinitionLines[d]], $
dirNamesLength[1, dirDefinitionLines[d]])
if (strmid(dirName, 0, /reverse_offset) ne path_sep()) then begin
dirName += path_sep()
endif
dd = 0L
done = 0B
while (dd lt directories->count() && ~done) do begin
dir = directories->get(position=dd)
dir->getProperty, location=location
if (dirName eq location) then begin
dirDefinitionEnd = d eq nDirs - 1L $
? n_elements(dirLines) - 1L $
: dirDefinitionLines[d + 1L] - 1L
if (dirDefinitionLines[d] + 1L le dirDefinitionEnd) then begin
comments = dirLines[dirDefinitionLines[d] + 1L:dirDefinitionEnd]
dir->setProperty, overview_comments=markupParser->parse(comments)
endif
done = 1B
endif
dd++
endwhile
endfor
end
else: begin
system->getProperty, overview=overview
system->warning, 'unknown tag "' + tag + '" in overview file ' + overview
end
endcase
endfor
end
;+
; Define instance variables.
;-
pro docparrstformatparser__define
compile_opt strictarr, hidden
define = { DOCparRstFormatParser, inherits DOCparFormatParser }
end