1
###############################################################################
3
# Purpose: Generate Tags for Inno Setup Scripts #
4
# Author: Cody Precord <cprecord@editra.org> #
5
# Copyright: (c) 2008 Cody Precord <staff@editra.org> #
6
# License: wxWindows License #
7
###############################################################################
14
Generate a DocStruct object that captures the structure of a Inno Setup Script
15
Currently supports parsing of Sections, Function Definitions, Procedure
16
Definitions, and Global Define statements.
20
__author__ = "Cody Precord <cprecord@editra.org>"
21
__svnid__ = "$Id: innotags.py 52675 2008-03-22 03:34:38Z CJP $"
22
__revision__ = "$Revision: 52675 $"
24
#--------------------------------------------------------------------------#
29
#--------------------------------------------------------------------------#
31
def GenerateTags(buff):
32
"""Create a DocStruct object that represents an Inno Setup Script
33
@param buff: a file like buffer object (StringIO)
34
@todo: perhaps group functions, procedures within the Scope of a Section
38
rtags = taglib.DocStruct()
39
rtags.SetElementDescription('section', "Sections")
40
rtags.SetElementDescription('variable', "Defines")
41
rtags.SetElementDescription('function', "Function Definitions")
42
rtags.SetElementDescription('procedure', "Procedure Definitions")
43
rtags.SetElementPriority('section', 3)
44
rtags.SetElementPriority('function', 2)
45
rtags.SetElementPriority('procedure', 1)
47
for lnum, line in enumerate(buff):
50
# Skip comment and empty lines
51
if line.startswith(u";") or not line:
55
if line.startswith(u"["):
56
secend = line.find(u"]")
58
section = taglib.Section(line[1:secend], lnum)
59
rtags.AddElement('section', section)
60
elif parselib.IsToken(line, 0, u'function'):
61
name = parselib.GetFirstIdentifier(line[8:].strip())
63
rtags.AddFunction(taglib.Function(name, lnum))
64
elif parselib.IsToken(line, 0, u'procedure'):
65
name = parselib.GetFirstIdentifier(line[9:].strip())
67
rtags.AddElement('procedure',
68
taglib.Function(name, lnum, 'procedure'))
69
elif parselib.IsToken(line, 0, u'#define'):
70
name = parselib.GetFirstIdentifier(line[7:].strip())
72
rtags.AddVariable(taglib.Variable(name, lnum))
78
#-----------------------------------------------------------------------------#
80
if __name__ == '__main__':
83
fhandle = open(sys.argv[1])
86
tags = GenerateTags(StringIO.StringIO(txt))
88
for element in tags.GetElements():
89
print "\n%s:" % element.keys()[0]
90
for val in element.values()[0]:
91
print "%s [%d]" % (val.GetName(), val.GetLine())