blob: de5a1cacf8dbd449c9fa8cc243677c7f917e0686 [file] [log] [blame]
edisonn@google.com07f01472013-06-13 17:24:54 +00001#!/usr/local/bin/python
2# coding: utf-8
3
4import sys
5import re
6
7# TODO(edisonn): put processed part of file in a new file
8# put unprocessed part, in a new file, so we see what we miss
9# keep blank lines, and generate a version without the blank lines
10
11#TODO (edisonn): deal manually with
12# TABLE 7.11 Restrictions on the entries in a soft-mask image dictionary
13#KEY RESTRICTION
14
15
16
17lines = 0
18table = ''
19tableHeaderFound = False
20tableLine = 0
21tableRow = 0
22columnWidth = []
edisonn@google.com45327112013-06-13 20:02:29 +000023columnValues = None
edisonn@google.com07f01472013-06-13 17:24:54 +000024mustFollowTableHeader = False
edisonn@google.com45327112013-06-13 20:02:29 +000025emitedDitionaryName = ''
edisonn@google.com07f01472013-06-13 17:24:54 +000026
27knownTypes = {
28'(any)',
29unicode('undefined', 'utf8'),
30'(undefined)',
31'(various)',
32'array',
33'or',
34'boolean',
35'date',
36'dictionary',
37'function',
38'integer',
39unicode('file', 'utf8'),
40'file',
41unicode('specification', 'utf8'),
42'specification',
43'name',
44'tree',
45'number',
46'rectangle',
47'stream',
48'string',
49'text',
50',',
51' '
52}
53
edisonn@google.com45327112013-06-13 20:02:29 +000054tableToClassName = {
55'TABLE 3.4': ['StreamDictionariesCommon', 'Entries common to all stream dictionaries'],
56'TABLE 3.7': ['LzwdecodeAndFlatedecodeFiltersOptionalParameters', 'Optional parameters for LZWDecode and FlateDecode filters'],
57'TABLE 3.9': ['CcittfaxdecodeFilterOptionalParameters', 'Optional parameters for the CCITTFaxDecode filter'],
58'TABLE 3.10': ['Jbig2DecodeFilterOptionalParameters', 'Optional parameter for the JBIG2Decode filter'],
59'TABLE 3.11': ['DctdecodeFilterOptionalParameters', 'Optional parameter for the DCTDecode filter'],
60'TABLE 3.12': ['FileTrailerDictionary', 'Entries in the file trailer dictionary'],
61'TABLE 3.13': ['EncryptionDictionariesCommon', 'Entries common to all encryption dictionaries'],
62'TABLE 3.14': ['DictionaryEntriesForTheStandardSecurityHandler', 'Additional encryption dictionary entries for the standard security handler'],
63'TABLE 3.16': ['CatalogDictionary', 'Entries in the catalog dictionary'],
64'TABLE 3.17': ['PageTreeNodeDictionary', 'Required entries in a page tree node'],
65'TABLE 3.18': ['PageObjectDictionary', 'Entries in a page object'],
66'TABLE 3.19': ['NameDictionary', 'Entries in the name dictionary'],
67'TABLE 3.21': ['ResourceDictionary', 'Entries in a resource dictionary'],
68'TABLE 3.23': ['NameTreeNodeDictionary', 'Entries in a name tree node dictionary'],
69'TABLE 3.25': ['NumberTreeNodeDictionary', 'Entries in a number tree node dictionary'],
70'TABLE 3.26': ['FunctionDictionariesCommon', 'Entries common to all function dictionaries'],
71'TABLE 3.27': ['SpecificToAType0FunctionDictionary', 'Additional entries specific to a type 0 function dictionary'],
72'TABLE 3.28': ['SpecificToAType2FunctionDictionary', 'Additional entries specific to a type 2 function dictionary'],
73'TABLE 3.29': ['SpecificToAType3FunctionDictionary', 'Additional entries specific to a type 3 function dictionary'],
74'TABLE 3.32': ['FileSpecificationDictionary', 'Entries in a file specification dictionary'],
75'TABLE 3.33': ['EmbeddedFileStreamDictionary', 'Additional entries in an embedded file stream dictionary'],
76'TABLE 3.35': ['MacOsFileInformationDictionary', 'Entries in a Mac OS file information dictionary'],
77'TABLE 4.13': ['CalgrayColorSpaceDictionary', 'Entries in a CalGray color space dictionary'],
78'TABLE 4.14': ['CalrgbColorSpaceDictionary', 'Entries in a CalRGB color space dictionary'],
79'TABLE 4.15': ['LabColorSpaceDictionary', 'Entries in a Lab color space dictionary'],
80'TABLE 4.16': ['SpecificToAnIccProfileStreamDictionary', 'Additional entries specific to an ICC profile stream dictionary'],
81'TABLE 4.20': ['DevicenColorSpaceAttributesDictionary', 'Entry in a DeviceN color space attributes dictionary'],
82'TABLE 4.22': ['SpecificToAType1PatternDictionary', 'Additional entries specific to a type 1 pattern dictionary'],
83'TABLE 4.23': ['Type2PatternDictionary', 'Entries in a type 2 pattern dictionary'],
84'TABLE 4.25': ['ShadingDictionariesCommon', 'Entries common to all shading dictionaries'],
85'TABLE 4.26': ['SpecificToAType1ShadingDictionary', 'Additional entries specific to a type 1 shading dictionary'],
86'TABLE 4.27': ['SpecificToAType2ShadingDictionary', 'Additional entries specific to a type 2 shading dictionary'],
87'TABLE 4.28': ['SpecificToAType3ShadingDictionary', 'Additional entries specific to a type 3 shading dictionary'],
88'TABLE 4.29': ['SpecificToAType4ShadingDictionary', 'Additional entries specific to a type 4 shading dictionary'],
89'TABLE 4.30': ['SpecificToAType5ShadingDictionary', 'Additional entries specific to a type 5 shading dictionary'],
90'TABLE 4.31': ['SpecificToAType6ShadingDictionary', 'Additional entries specific to a type 6 shading dictionary'],
91'TABLE 4.35': ['SpecificToAnImageDictionary', 'Additional entries specific to an image dictionary'],
92'TABLE 4.37': ['AlternateImageDictionary', 'Entries in an alternate image dictionary'],
93'TABLE 4.41': ['SpecificToAType1FormDictionary', 'Additional entries specific to a type 1 form dictionary'],
94'TABLE 4.42': ['GroupAttributesDictionariesCommon', 'Entries common to all group attributes dictionaries'],
95'TABLE 4.43': ['ReferenceDictionary', 'Entries in a reference dictionary'],
96'TABLE 4.44': ['SpecificToAPostscriptXobjectDictionary', 'Additional entries specific to a PostScript XObject dictionary'],
97'TABLE 5.8': ['Type1FontDictionary', 'Entries in a Type 1 font dictionary'],
98'TABLE 5.9': ['Type3FontDictionary', 'Entries in a Type 3 font dictionary'],
99'TABLE 5.11': ['EncodingDictionary', 'Entries in an encoding dictionary'],
100'TABLE 5.12': ['CidsysteminfoDictionary', 'Entries in a CIDSystemInfo dictionary'],
101'TABLE 5.13': ['CidfontDictionary', 'Entries in a CIDFont dictionary'],
102'TABLE 5.16': ['CmapDictionary', 'Additional entries in a CMap dictionary'],
103'TABLE 5.17': ['Type0FontDictionary', 'Entries in a Type 0 font dictionary'],
104'TABLE 5.18': ['FontDescriptorsCommon', 'Entries common to all font descriptors'],
105'TABLE 5.20': ['DescriptorEntriesForCidfonts', 'Additional font descriptor entries for CIDFonts'],
106'TABLE 5.23': ['EmbeddedFontStreamDictionary', 'Additional entries in an embedded font stream dictionary'],
107'TABLE 6.3': ['Type1HalftoneDictionary', 'Entries in a type 1 halftone dictionary'],
108'TABLE 6.4': ['SpecificToAType6HalftoneDictionary', 'Additional entries specific to a type 6 halftone dictionary'],
109'TABLE 6.5': ['SpecificToAType10HalftoneDictionary', 'Additional entries specific to a type 10 halftone dictionary'],
110'TABLE 6.6': ['SpecificToAType16HalftoneDictionary', 'Additional entries specific to a type 16 halftone dictionary'],
111'TABLE 6.7': ['Type5HalftoneDictionary', 'Entries in a type 5 halftone dictionary'],
112'TABLE 7.10': ['Soft-MaskDictionary', 'Entries in a soft-mask dictionary'],
113'TABLE 7.12': ['Soft-MaskImageDictionary', 'Additional entry in a soft-mask image dictionary'],
114'TABLE 7.13': ['SpecificToATransparencyGroupAttributesDictionary', 'Additional entries specific to a transparency group attributes dictionary'],
115'TABLE 8.1': ['ViewerPreferencesDictionary', 'Entries in a viewer preferences dictionary'],
116'TABLE 8.3': ['OutlineDictionary', 'Entries in the outline dictionary'],
117'TABLE 8.6': ['PageLabelDictionary', 'Entries in a page label dictionary'],
118'TABLE 8.7': ['ThreadDictionary', 'Entries in a thread dictionary'],
119'TABLE 8.9': ['TransitionDictionary', 'Entries in a transition dictionary'],
120'TABLE 8.10': ['AnnotationDictionariesCommon', 'Entries common to all annotation dictionaries'],
121'TABLE 8.12': ['BorderStyleDictionary', 'Entries in a border style dictionary'],
122'TABLE 8.13': ['AppearanceDictionary', 'Entries in an appearance dictionary'],
123'TABLE 8.15': ['SpecificToATextAnnotation', 'Additional entries specific to a text annotation'],
124'TABLE 8.16': ['SpecificToALinkAnnotation', 'Additional entries specific to a link annotation'],
125'TABLE 8.17': ['SpecificToAFreeTextAnnotation', 'Additional entries specific to a free text annotation'],
126'TABLE 8.18': ['SpecificToALineAnnotation', 'Additional entries specific to a line annotation'],
127'TABLE 8.20': ['SpecificToASquareOrCircleAnnotation', 'Additional entries specific to a square or circle annotation'],
128'TABLE 8.21': ['SpecificToMarkupAnnotations', 'Additional entries specific to markup annotations'],
129'TABLE 8.22': ['SpecificToARubberStampAnnotation', 'Additional entries specific to a rubber stamp annotation'],
130'TABLE 8.23': ['SpecificToAnInkAnnotation', 'Additional entries specific to an ink annotation'],
131'TABLE 8.24': ['SpecificToAPop-UpAnnotation', 'Additional entries specific to a pop-up annotation'],
132'TABLE 8.26': ['SpecificToASoundAnnotation', 'Additional entries specific to a sound annotation'],
133'TABLE 8.27': ['SpecificToAMovieAnnotation', 'Additional entries specific to a movie annotation'],
134'TABLE 8.28': ['SpecificToAWidgetAnnotation', 'Additional entries specific to a widget annotation'],
135'TABLE 8.29': ['ActionDictionariesCommon', 'Entries common to all action dictionaries'],
136'TABLE 8.30': ['Annotation’SAdditional-ActionsDictionary', 'Entries in an annotation’s additional-actions dictionary'],
137'TABLE 8.35': ['SpecificToAGo-ToAction', 'Additional entries specific to a go-to action'],
138'TABLE 8.36': ['SpecificToARemoteGo-ToAction', 'Additional entries specific to a remote go-to action'],
139'TABLE 8.37': ['SpecificToALaunchAction', 'Additional entries specific to a launch action'],
140'TABLE 8.39': ['SpecificToAThreadAction', 'Additional entries specific to a thread action'],
141'TABLE 8.40': ['SpecificToAUriAction', 'Additional entries specific to a URI action'],
142'TABLE 8.41': ['UriDictionary', 'Entry in a URI dictionary'],
143'TABLE 8.42': ['SpecificToASoundAction', 'Additional entries specific to a sound action'],
144'TABLE 8.43': ['SpecificToAMovieAction', 'Additional entries specific to a movie action'],
145'TABLE 8.44': ['SpecificToAHideAction', 'Additional entries specific to a hide action'],
146'TABLE 8.46': ['SpecificToNamedActions', 'Additional entries specific to named actions'],
147'TABLE 8.47': ['InteractiveFormDictionary', 'Entries in the interactive form dictionary'],
148'TABLE 8.49': ['FieldDictionariesCommon', 'Entries common to all field dictionaries'],
149'TABLE 8.51': ['CommonToAllFieldsContainingVariableText', 'Additional entries common to all fields containing variable text'],
150'TABLE 8.52': ['AppearanceCharacteristicsDictionary', 'Entries in an appearance characteristics dictionary'],
151'TABLE 8.54': ['SpecificToACheckboxField', 'Additional entry specific to a checkbox field'],
152'TABLE 8.55': ['SpecificToARadioButtonField', 'Additional entry specific to a radio button field'],
153'TABLE 8.57': ['SpecificToATextField', 'Additional entry specific to a text field'],
154'TABLE 8.59': ['SpecificToAChoiceField', 'Additional entries specific to a choice field'],
155'TABLE 8.60': ['SignatureDictionary', 'Entries in a signature dictionary'],
156'TABLE 8.61': ['SpecificToASubmit-FormAction', 'Additional entries specific to a submit-form action'],
157'TABLE 8.63': ['SpecificToAReset-FormAction', 'Additional entries specific to a reset-form action'],
158'TABLE 8.65': ['SpecificToAnImport-DataAction', 'Additional entries specific to an import-data action'],
159'TABLE 8.66': ['SpecificToAJavascriptAction', 'Additional entries specific to a JavaScript action'],
160'TABLE 8.67': ['FdfTrailerDictionary', 'Entry in the FDF trailer dictionary'],
161'TABLE 8.68': ['FdfCatalogDictionary', 'Entries in the FDF catalog dictionary'],
162'TABLE 8.70': ['EmbeddedFileStreamDictionary', 'Additional entry in an embedded file stream dictionary for an encrypted FDF file'],
163'TABLE 8.71': ['JavascriptDictionary', 'Entries in the JavaScript dictionary'],
164'TABLE 8.72': ['FdfFieldDictionary', 'Entries in an FDF field dictionary'],
165'TABLE 8.73': ['IconFitDictionary', 'Entries in an icon fit dictionary'],
166'TABLE 8.74': ['FdfPageDictionary', 'Entries in an FDF page dictionary'],
167'TABLE 8.75': ['FdfTemplateDictionary', 'Entries in an FDF template dictionary'],
168'TABLE 8.76': ['FdfNamedPageReferenceDictionary', 'Entries in an FDF named page reference dictionary'],
169'TABLE 8.77': ['ForAnnotationDictionariesInAnFdfFile', 'Additional entry for annotation dictionaries in an FDF file'],
170'TABLE 8.78': ['SpecificToASoundObject', 'Additional entries specific to a sound object'],
171'TABLE 8.79': ['MovieDictionary', 'Entries in a movie dictionary'],
172'TABLE 9.2': ['DocumentInformationDictionary', 'Entries in the document information dictionary'],
173'TABLE 9.3': ['MetadataStreamDictionary', 'Additional entries in a metadata stream dictionary'],
174'TABLE 9.4': ['ForComponentsHavingMetadata', 'Additional entry for components having metadata'],
175'TABLE 9.6': ['Page-PieceDictionary', 'Entries in a page-piece dictionary'],
176'TABLE 9.7': ['ApplicationDataDictionary', 'Entries in an application data dictionary'],
177'TABLE 9.9': ['StructureTreeRootDictionary', 'Entries in the structure tree root'],
178'TABLE 9.11': ['Marked-ContentReferenceDictionary', 'Entries in a marked-content reference dictionary'],
179'TABLE 9.12': ['ObjectReferenceDictionary', 'Entries in an object reference dictionary'],
180'TABLE 9.13': ['EntriesForStructureElementAccess', 'Additional dictionary entries for structure element access'],
181'TABLE 9.14': ['AttributeObjectsCommon', 'Entry common to all attribute objects'],
182'TABLE 9.15': ['MarkInformationDictionary', 'Entry in the mark information dictionary'],
183'TABLE 9.16': ['ArtifactsDictionary', 'Property list entries for artifacts'],
184'TABLE 9.27': ['StandardStructureTypesCommon', 'Standard layout attributes common to all standard structure types'],
185'TABLE 9.28': ['LayoutAttributesSpecificToBlock-LevelStructureElements', 'Additional standard layout attributes specific to block-level structure elements'],
186'TABLE 9.29': ['LayoutAttributesSpecificToInline-LevelStructureElementsDictionary', 'Standard layout attributes specific to inline-level structure elements'],
187'TABLE 9.30': ['ListAttributeDictionary', 'Standard list attribute'],
188'TABLE 9.31': ['TableAttributesDictionary', 'Standard table attributes'],
189'TABLE 9.32': ['WebCaptureInformationDictionary', 'Entries in the Web Capture information dictionary'],
190'TABLE 9.33': ['WebCaptureContentSetsCommon', 'Entries common to all Web Capture content sets'],
191'TABLE 9.35': ['SpecificToAWebCaptureImageSet', 'Additional entries specific to a Web Capture image set'],
192'TABLE 9.36': ['SourceInformationDictionary', 'Entries in a source information dictionary'],
193'TABLE 9.37': ['UrlAliasDictionary', 'Entries in a URL alias dictionary'],
194'TABLE 9.38': ['WebCaptureCommandDictionary', 'Entries in a Web Capture command dictionary'],
195'TABLE 9.40': ['WebCaptureCommandSettingsDictionary', 'Entries in a Web Capture command settings dictionary'],
196'TABLE 9.41': ['BoxColorInformationDictionary', 'Entries in a box color information dictionary'],
197'TABLE 9.43': ['SpecificToAPrinter’SMarkAnnotation', 'Additional entries specific to a printer’s mark annotation'],
198'TABLE 9.44': ['SpecificToAPrinter’SMarkFormDictionary', 'Additional entries specific to a printer’s mark form dictionary'],
199'TABLE 9.45': ['SeparationDictionary', 'Entries in a separation dictionary'],
200'TABLE 9.46': ['Pdf/XOutputIntentDictionary', 'Entries in a PDF/X output intent dictionary'],
201'TABLE 9.47': ['SpecificToATrapNetworkAnnotation', 'Additional entries specific to a trap network annotation'],
202'TABLE 9.48': ['SpecificToATrapNetworkAppearanceStream', 'Additional entries specific to a trap network appearance stream'],
203'TABLE 9.49': ['OpiVersionDictionary', 'Entry in an OPI version dictionary'],
204}
205
206
edisonn@google.com07f01472013-06-13 17:24:54 +0000207def acceptType(val):
208 global knownTypes
209
210 ret = val
211
212 for item in knownTypes:
213 ret = ret.replace(item, '')
214
215 return ret == ''
216
217
218def inTable():
219 global tableHeaderFound
220 return tableHeaderFound
221
222def tableDescriptionFound(desc):
223 global table
224 table = desc.strip()
225
226def tableHasHeader():
227 global table
228 global tableHeaderFound
229
230 tableHeaderFound = True
231 #print table
232
233
234def commitRow():
235 global columnValues
edisonn@google.com45327112013-06-13 20:02:29 +0000236 global emitedDitionaryName
237 global table
238 global tableToClassName
239
240 if columnValues == None:
241 return
242
edisonn@google.com07f01472013-06-13 17:24:54 +0000243 #print columnValues
244
245 lastClosed = columnValues[2].find(')')
246 if lastClosed < 0:
247 print 'ERRRRRRRRRRRRRRROR'
248 print columnValues
249 return
250
251 spec = columnValues[2][:lastClosed + 1]
252 spec = spec.replace('(', ';')
253 spec = spec.replace(')', ';')
254 spec = spec.strip(';')
255
256 specs = spec.split(';')
257
258 # clearly required, but it can be required with conditions. don't handle this ones here, but manually
259 required = specs[0] == 'Required'
260
261 inheritable = False
262 version = ''
263 for s in specs:
264 if s.strip() == 'inheritable' or s.strip() == 'Inheritable':
265 inheritable = True
266 elif re.match('^PDF [0-9]*[\.[0-9]*]*', s.strip()):
267 version = s.strip()
268 elif s != 'Required':
269 required = False
270
edisonn@google.com45327112013-06-13 20:02:29 +0000271 #print spec
272 #print specs
273 #print required
274 #print inheritable
275 #print version
276 #print columnValues
277
278 columnValues = [columnValues[0].replace(unicode('fi', 'utf8'), 'fi'), columnValues[1].replace(unicode('fi', 'utf8'), 'fi'), columnValues[2].replace(unicode('fi', 'utf8'), 'fi')]
279
280 if emitedDitionaryName == '':
281 table = table.replace(unicode('fi', 'utf8'), 'fi')
282
283
284 #print table
285 emitedDitionaryName = 'foo'
286 e = re.search('[Entries|Entry] in [a-z]* (.* dictionary)', table)
287 a = re.search('Additional [a-z]* in a[n]? (.* dictionary)', table)
288 s = re.search('Additional [a-z]* (.*)', table)
289 c = re.search('[Entries|Entry] common to all (.*)', table)
290 o1 = re.search('Optional parameter[s]? for the (.*)', table)
291 o2 = re.search('Optional parameter[s]? for (.*)', table)
292 t = re.search('.*ntries in [a-z]* (.*)', table)
293
294 r = re.search('Property list entries for (.*)', table)
295 st = re.search('Standard (.*)', table)
296
297 if e:
298 emitedDitionaryName = e.group(1).title().replace(' ', '')
299 #print emitedDitionaryName
300 elif a:
301 emitedDitionaryName = a.group(1).title().replace(' ', '')
302 #print emitedDitionaryName
303 elif s:
304 emitedDitionaryName = s.group(1).title().replace(' ', '')
305 #print emitedDitionaryName
306 elif c:
307 emitedDitionaryName = c.group(1).title().replace(' ', '') + 'Common'
308 #print emitedDitionaryName
309 elif o1:
310 emitedDitionaryName = o1.group(1).title().replace(' ', '') + 'OptionalParameters'
311 #print emitedDitionaryName
312 elif o2:
313 emitedDitionaryName = o2.group(1).title().replace(' ', '') + 'OptionalParameters'
314 #print emitedDitionaryName
315 elif t:
316 emitedDitionaryName = t.group(1).title().replace(' ', '') + 'Dictionary'
317 #print emitedDitionaryName
318 elif r:
319 emitedDitionaryName = r.group(1).title().replace(' ', '') + 'Dictionary'
320 #print emitedDitionaryName
321 elif st:
322 emitedDitionaryName = st.group(1).title().replace(' ', '') + 'Dictionary'
323 #print emitedDitionaryName
324 #else:
325 #print table
326
327 tableKey = re.search('(TABLE [0-9].[0-9][0-9]?)', table).group(1)
328 #print tableKey
329 #print('\'' + tableKey + '\': [\'' + emitedDitionaryName + '\', \'' + table[len(tableKey) + 1:] + '\'],')
330
331 emitedDitionaryName = tableToClassName[tableKey][0]
332 comment = tableToClassName[tableKey][1]
333
334 print(' all.addClass(\'' + emitedDitionaryName + '\', \'Dictionary\', \'' + comment + '\')\\')
335
336 if required:
337 print(' .required(\'NULL\')\\')
338 else:
339 print(' .optional()\\')
340
341 print(' .field(\'' + columnValues[0] + '\')\\')
342 print(' .name(\'' + columnValues[0] + '\')\\')
343 print(' .type(\'' + columnValues[1] + '\')\\')
344 print(' .comment(\'' + columnValues[2] + '\')\\')
345 print(' .done().done()\\')
346
347
348 columnValues = None
edisonn@google.com07f01472013-06-13 17:24:54 +0000349
350def newRow(first, second, third):
351 global columnValues
352 columnValues = [first.rstrip(), second.rstrip(), third.rstrip()]
353
354def appendRow(second, third):
355 global columnValues
356 if second.rstrip() != '':
357 columnValues[1] = columnValues[1] + ' ' + second.rstrip()
358 if third.rstrip() != '':
359 columnValues[2] = columnValues[2] + ' ' + third.rstrip()
360
361def rebaseTable(line):
362 global knownTypes
363 global columnWidth
364
365 words = line.split()
366
367 if len(words) < 3:
368 return False
369
370 i = 1
371 while i < len(words) - 1 and words[i] in knownTypes:
372 i = i + 1
373
374 if words[i].startswith('(Optional') or words[i].startswith('(Required'):
375 commitRow()
376
377 columnWidth[0] = line.find(words[1])
378
379 if words[i].startswith('(Optional'):
380 columnWidth[1] = line.find('(Optional') - columnWidth[0]
381 if words[i].startswith('(Required'):
382 columnWidth[1] = line.find('(Required') - columnWidth[0]
383 return True
384
385 return False
386
387
388def stopTable():
389 global tableHeaderFound
edisonn@google.com45327112013-06-13 20:02:29 +0000390 global emitedDitionaryName
edisonn@google.com07f01472013-06-13 17:24:54 +0000391 commitRow()
392 tableHeaderFound = False
edisonn@google.com45327112013-06-13 20:02:29 +0000393 emitedDitionaryName = ''
394 print(' .done()')
395 print
edisonn@google.com07f01472013-06-13 17:24:54 +0000396
397
398def killTable():
399 return
400
401def processLine(line):
402 global lines
403 global tableLine
404 global tableRow
405 global columnWidth
406 global columnValues
407 global mustFollowTableHeader
408
409 lines = lines + 1
410
411 line = unicode(line, 'utf8')
412
413 striped = line.rstrip()
414
415 words = line.split()
416 if len(words) == 0:
417 return
418
419 if words[0] == 'TABLE':
420 tableDescriptionFound(striped)
421 mustFollowTableHeader = True
422 return
423
424 if mustFollowTableHeader:
425 mustFollowTableHeader = False
426 if len(words) != 3:
427 killTable()
428
429 # TODO(edisonn): support for generic table!
430 if words[0] != 'KEY' or words[1] != 'TYPE' or words[2] != 'VALUE':
431 killTable()
432 return
433
434 tableHasHeader()
435 columnWidth = [0, 0, 0]
436 columnWidth[0] = striped.index('TYPE')
437 columnWidth[1] = striped.index('VALUE') - striped.index('TYPE')
438 columnWidth[2] = 0
439 return
440
441 if inTable():
442 tableLine = tableLine + 1
443 first = striped[0 : columnWidth[0]]
444 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]]
445 third = striped[columnWidth[0] + columnWidth[1] :]
446
447 if tableLine == 1:
448 if third[0] != '(':
449 killTable()
450 return
451
452 newRow(first, second, third)
453 return
454
455 if rebaseTable(striped):
456 first = striped[0 : columnWidth[0]]
457 second = striped[columnWidth[0] : columnWidth[0] + columnWidth[1]]
458 third = striped[columnWidth[0] + columnWidth[1] :]
459
460 first = first.rstrip()
461 second = second.rstrip()
462 third = third.rstrip()
463
464 if first == '' and second == '' and third != '':
465 appendRow(second, third)
466 return
467
468 if len(first.split()) > 1:
469 stopTable()
470 return
471
472 if first != '' and first[0] == ' ':
473 stopTable()
474 return
475
476 if first != '' and second != '' and third == '':
477 stopTable()
478 return
479
480 if first == '' and second != '' and second[0] != ' ':
481 if acceptType(second):
482 appendRow(second, third)
483 else:
484 stopTable()
485 return
486
487 if first != '' and second != '' and third[0] != '(':
488 stopTable()
489 return
490
491 if first == '' and second != '' and second[0] == ' ':
492 stopTable()
493 return
494
495 if first != '' and second != '' and third[0] == '(':
496 commitRow()
497 newRow(first, second, third)
498 return
499
500
501def generateDef():
502 global lines
503 for line in sys.stdin:
504 processLine(line)
edisonn@google.com45327112013-06-13 20:02:29 +0000505 #print lines
edisonn@google.com07f01472013-06-13 17:24:54 +0000506
507if '__main__' == __name__:
508 sys.exit(generateDef())