~ubuntu-branches/ubuntu/lucid/editra/lucid-proposed

« back to all changes in this revision

Viewing changes to src/syntax/_inno.py

  • Committer: Bazaar Package Importer
  • Author(s): Alejandro Garrido Mota
  • Date: 2009-08-25 14:36:19 UTC
  • Revision ID: james.westby@ubuntu.com-20090825143619-7yqmn39iobkr80ro
Tags: upstream-0.5.15
ImportĀ upstreamĀ versionĀ 0.5.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############################################################################
 
2
# Name: inno.py                                                               #
 
3
# Purpose: Syntax configuration module 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
###############################################################################
 
8
 
 
9
"""
 
10
FILE: inno.py
 
11
AUTHOR: Cody Preord
 
12
@summary: Lexer configuration module for Inno Setup Scripts
 
13
 
 
14
"""
 
15
 
 
16
__author__ = "Cody Precord <cprecord@editra.org>"
 
17
__svnid__ = "$Id: _inno.py 62364 2009-10-11 01:02:12Z CJP $"
 
18
__revision__ = "$Revision: 62364 $"
 
19
 
 
20
#-----------------------------------------------------------------------------#
 
21
# Imports
 
22
import wx.stc as stc
 
23
import re
 
24
 
 
25
# Local Imports
 
26
import synglob
 
27
import syndata
 
28
 
 
29
#-----------------------------------------------------------------------------#
 
30
 
 
31
#---- Keyword Definitions ----#
 
32
SECTION_KW = (0, "code components custommessages dirs files icons ini "
 
33
                 "installdelete langoptions languages messages registry run "
 
34
                 "setup types tasks uninstalldelete uninstallrun _istool")
 
35
 
 
36
KEYWORDS = (1, "allowcancelduringinstall allownoicons allowrootdirectory "
 
37
            "allowuncpath alwaysrestart alwaysshowcomponentslist "
 
38
            "alwaysshowdironreadypage alwaysshowgrouponreadypage "
 
39
            "alwaysusepersonalgroup appcomments appcontact appcopyright "
 
40
            "appenddefaultdirname appenddefaultgroupname appid appmodifypath "
 
41
            "appmutex appname apppublisher apppublisherurl appreadmefile "
 
42
            "appsupporturl appupdatesurl appvername appversion "
 
43
            "architecturesallowed architecturesinstallin64bitmode backcolor "
 
44
            "backcolor2 backcolordirection backsolid changesassociations "
 
45
            "changesenvironment compression copyrightfontname "
 
46
            "copyrightfontsize createappdir createuninstallregkey "
 
47
            "defaultdirname defaultgroupname defaultuserinfoname "
 
48
            "defaultuserinfoorg defaultuserinfoserial dialogfontname "
 
49
            "dialogfontsize direxistswarning disabledirpage "
 
50
            "disablefinishedpage disableprogramgrouppage disablereadymemo "
 
51
            "disablereadypage disablestartupprompt diskclustersize "
 
52
            "diskslicesize diskspanning enablesdirdoesntexistwarning "
 
53
            "encryption extradiskspacerequired flatcomponentslist "
 
54
            "infoafterfile infobeforefile internalcompresslevel "
 
55
            "languagedetectionmethod languagecodepage languageid languagename "
 
56
            "licensefile mergeduplicatefiles minversion onlybelowversion "
 
57
            "outputbasefilename outputdir outputmanifestfile password "
 
58
            "privilegesrequired reservebytes restartifneededbyrun "
 
59
            "setupiconfile showcomponentsizes showlanguagedialog "
 
60
            "showtaskstreelines slicesperdisk solidcompression sourcedir "
 
61
            "timestamprounding timestampsinutc titlefontname titlefontsize "
 
62
            "touchdate touchtime uninstallable uninstalldisplayicon "
 
63
            "uninstalldisplayname uninstallfilesdir uninstalllogmode "
 
64
            "uninstallrestartcomputer updateuninstalllogappname "
 
65
            "usepreviousappdir usepreviousgroup useprevioussetuptype "
 
66
            "useprevioustasks useprevioususerinfo userinfopage usesetupldr "
 
67
            "versioninfocompany versioninfocopyright versioninfodescription "
 
68
            "versioninfotextversion versioninfoversion welcomefontname "
 
69
            "welcomefontsize windowshowcaption windowstartmaximized "
 
70
            "windowresizable windowvisible wizardimagebackcolor "
 
71
            "wizardimagefile wizardimagestretch wizardsmallimagefile")
 
72
 
 
73
PARAM_KW = (2, "afterinstall attribs beforeinstall check comment components "
 
74
               "copymode description destdir destname excludes "
 
75
               "extradiskspacerequired filename flags fontinstall "
 
76
               "groupdescription hotkey infoafterfile infobeforefile "
 
77
               "iconfilename iconindex key languages licensefile messagesfile "
 
78
               "minversion name onlybelowversion parameters permissions root "
 
79
               "runonceid section source statusmsg string subkey tasks type "
 
80
               "types valuedata valuename valuetype workingdir")
 
81
 
 
82
PREPROC_KW = (3, "append define dim else emit endif endsub error expr file for "
 
83
                 "if ifdef ifexist ifndef ifnexist include insert pragma sub "
 
84
                 "undef")
 
85
 
 
86
PASCAL_KW = (4, "begin break case const continue do downto else end except "
 
87
                "finally for function if of procedure repeat then to try until "
 
88
                "uses var while with")
 
89
 
 
90
USER_DEF = (5, "")
 
91
 
 
92
#---- End Keyword Definitions ----#
 
93
 
 
94
#---- Syntax Style Specs ----#
 
95
SYNTAX_ITEMS = [('STC_INNO_COMMENT', 'comment_style'),
 
96
                ('STC_INNO_COMMENT_PASCAL', 'comment_style'),
 
97
                ('STC_INNO_DEFAULT', 'default_style'),
 
98
                ('STC_INNO_IDENTIFIER', 'default_style'),
 
99
                ('STC_INNO_KEYWORD', 'keyword_style'),
 
100
                ('STC_INNO_KEYWORD_PASCAL', 'keyword4_style'),
 
101
                ('STC_INNO_KEYWORD_USER', 'default_style'),
 
102
                ('STC_INNO_PARAMETER', 'keyword2_style'),
 
103
                ('STC_INNO_PREPROC', 'pre_style'),
 
104
                ('STC_INNO_PREPROC_INLINE', 'pre_style'),
 
105
                ('STC_INNO_SECTION', 'scalar_style'),
 
106
                ('STC_INNO_STRING_DOUBLE', 'string_style'),
 
107
                ('STC_INNO_STRING_SINGLE', 'char_style')]
 
108
 
 
109
#---- Extra Properties ----#
 
110
FOLD = ("fold", "1")
 
111
FOLD_COMP = ("fold.compact", "1")
 
112
 
 
113
#-----------------------------------------------------------------------------#
 
114
 
 
115
class SyntaxData(syndata.SyntaxDataBase):
 
116
    """SyntaxData object for Inno Setup Scripts""" 
 
117
    def __init__(self, langid):
 
118
        syndata.SyntaxDataBase.__init__(self, langid)
 
119
 
 
120
        # Setup
 
121
        self.SetLexer(stc.STC_LEX_INNOSETUP)
 
122
        self.RegisterFeature(synglob.FEATURE_AUTOINDENT, AutoIndenter)
 
123
 
 
124
    def GetKeywords(self):
 
125
        """Returns Specified Keywords List """
 
126
        return [SECTION_KW, KEYWORDS, PARAM_KW, PREPROC_KW, PASCAL_KW]
 
127
 
 
128
    def GetSyntaxSpec(self):
 
129
        """Syntax Specifications """
 
130
        return SYNTAX_ITEMS
 
131
 
 
132
    def GetProperties(self):
 
133
        """Returns a list of Extra Properties to set """
 
134
        return [FOLD]
 
135
 
 
136
    def GetCommentPattern(self):
 
137
        """Returns a list of characters used to comment a block of code """
 
138
        # Note: Inno can also use pascal comments (i.e {})
 
139
        return [u';']
 
140
 
 
141
#-----------------------------------------------------------------------------#
 
142
 
 
143
def AutoIndenter(stc, pos, ichar):
 
144
    """Auto indent Inno Setup Scripts. uses \n the text buffer will
 
145
    handle any eol character formatting.
 
146
    @param stc: EditraStyledTextCtrl
 
147
    @param pos: current carat position
 
148
    @param ichar: Indentation character
 
149
    @return: string
 
150
 
 
151
    """
 
152
    rtxt = u''
 
153
    line = stc.GetCurrentLine()
 
154
    text = stc.GetTextRange(stc.PositionFromLine(line), pos)
 
155
 
 
156
    indent = stc.GetLineIndentation(line)
 
157
    if ichar == u"\t":
 
158
        tabw = stc.GetTabWidth()
 
159
    else:
 
160
        tabw = stc.GetIndent()
 
161
 
 
162
    i_space = indent / tabw
 
163
    ndent = u"\n" + ichar * i_space
 
164
    rtxt = ndent + ((indent - (tabw * i_space)) * u' ')
 
165
 
 
166
    if_pat = re.compile('if\s+.*\sthen')
 
167
    text = text.strip()
 
168
    if text == u'begin' or if_pat.match(text):
 
169
        rtxt += ichar
 
170
 
 
171
    return rtxt