~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/syntax/_inno.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

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