~ubuntu-branches/ubuntu/trusty/highlighting-kate/trusty

« back to all changes in this revision

Viewing changes to .pc/Fix-source-encoding.patch/Text/Highlighting/Kate/Syntax/D.hs

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2010-03-06 23:03:27 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100306230327-nwnyp9k1knr9jk6z
Tags: 0.2.6.1-1
* New upstream release which incorporates our changes 
* Remove debian/patches/Fix-source-encoding.patch, fixed upstream 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{- This module was generated from data in the Kate syntax highlighting file d.xml, version 1.43,
2
 
   by  Aziz K�ksal (aziz.koeksal@gmail.com), Jari-Matti M�kel� (jmjm@iki.fi), Simon J Mackenzie (project.katedxml@smackoz.fastmail.fm) -}
3
 
 
4
 
module Text.Highlighting.Kate.Syntax.D ( highlight, parseExpression, syntaxName, syntaxExtensions ) where
5
 
import Text.Highlighting.Kate.Definitions
6
 
import Text.Highlighting.Kate.Common
7
 
import Text.ParserCombinators.Parsec
8
 
import Data.List (nub)
9
 
import Data.Map (fromList)
10
 
import Data.Maybe (fromMaybe)
11
 
 
12
 
syntaxName :: String
13
 
syntaxName = "D"
14
 
 
15
 
syntaxExtensions :: String
16
 
syntaxExtensions = "*.d;*.D;*.di;*.DI;"
17
 
 
18
 
highlight :: String -> Either String [SourceLine]
19
 
highlight input =
20
 
  case runParser parseSource startingState "source" input of
21
 
    Left err     -> Left $ show err
22
 
    Right result -> Right result
23
 
 
24
 
parseExpression :: GenParser Char SyntaxState LabeledSource
25
 
parseExpression = do
26
 
  st <- getState
27
 
  let oldLang = synStLanguage st
28
 
  setState $ st { synStLanguage = "D" }
29
 
  context <- currentContext <|> (pushContext "normal" >> currentContext)
30
 
  result <- parseRules context
31
 
  updateState $ \st -> st { synStLanguage = oldLang }
32
 
  return result
33
 
 
34
 
parseSource = do 
35
 
  lineContents <- lookAhead wholeLine
36
 
  updateState $ \st -> st { synStCurrentLine = lineContents }
37
 
  result <- manyTill parseSourceLine eof
38
 
  return $ map normalizeHighlighting result
39
 
 
40
 
startingState = SyntaxState {synStContexts = fromList [("D",["normal"])], synStLanguage = "D", synStCurrentLine = "", synStCharsParsedInLine = 0, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []}
41
 
 
42
 
parseSourceLine = manyTill parseExpressionInternal pEndLine
43
 
 
44
 
pEndLine = do
45
 
  newline <|> (eof >> return '\n')
46
 
  context <- currentContext
47
 
  case context of
48
 
    "normal" -> return ()
49
 
    "UnicodeShort" -> (popContext >> return ())
50
 
    "UnicodeLong" -> (popContext >> return ())
51
 
    "HTMLEntity" -> (popContext >> return ())
52
 
    "ModuleName" -> return ()
53
 
    "Deprecated" -> return ()
54
 
    "Linkage" -> (popContext >> return ())
55
 
    "Linkage2" -> (popContext >> return ())
56
 
    "Version" -> (popContext >> return ())
57
 
    "Version2" -> (popContext >> return ())
58
 
    "Pragmas" -> (popContext >> return ())
59
 
    "RawString" -> return ()
60
 
    "BQString" -> return ()
61
 
    "HexString" -> return ()
62
 
    "CharLiteral" -> (popContext >> return ())
63
 
    "String" -> return ()
64
 
    "CommentLine" -> (popContext >> return ())
65
 
    "CommentBlock" -> return ()
66
 
    "CommentNested" -> return ()
67
 
    _ -> return ()
68
 
  lineContents <- lookAhead wholeLine
69
 
  updateState $ \st -> st { synStCurrentLine = lineContents, synStCharsParsedInLine = 0 }
70
 
 
71
 
withAttribute attr txt = do
72
 
  if null txt
73
 
     then fail "Parser matched no text"
74
 
     else return ()
75
 
  let style = fromMaybe "" $ lookup attr styles
76
 
  st <- getState
77
 
  let oldCharsParsed = synStCharsParsedInLine st
78
 
  updateState $ \st -> st { synStCharsParsedInLine = oldCharsParsed + length txt } 
79
 
  return (nub [style, attr], txt)
80
 
 
81
 
styles = [("Normal Text","Normal"),("Keyword","Keyword"),("Type","DataType"),("Integer","DecVal"),("Binary","BaseN"),("Octal","BaseN"),("Hex","BaseN"),("Float","Float"),("LibrarySymbols","DataType"),("Deprecated","Comment"),("SpecialTokens","Normal"),("Module","Keyword"),("Module Name","Normal"),("Linkage","Keyword"),("Linkage Type","Normal"),("Debug","Keyword"),("Assert","Keyword"),("Version","Keyword"),("Version Type","Normal"),("Unit Test","Keyword"),("Pragma","Keyword"),("EscapeString","String"),("EscapeSequence","String"),("String","String"),("Char","Char"),("RawString","String"),("BQString","String"),("HexString","String"),("Comment","Comment"),("Error","Error")]
82
 
 
83
 
parseExpressionInternal = do
84
 
  context <- currentContext
85
 
  parseRules context <|> (pDefault >>= withAttribute (fromMaybe "" $ lookup context defaultAttributes))
86
 
 
87
 
defaultAttributes = [("normal","Normal Text"),("UnicodeShort","EscapeString"),("UnicodeLong","EscapeString"),("HTMLEntity","EscapeString"),("ModuleName","Module Name"),("Deprecated","Deprecated"),("Linkage","Linkage"),("Linkage2","Linkage"),("Version","Version"),("Version2","Version"),("Pragmas","Pragma"),("RawString","RawString"),("BQString","BQString"),("HexString","HexString"),("CharLiteral","Char"),("String","String"),("CommentLine","Comment"),("CommentBlock","Comment"),("CommentNested","Comment")]
88
 
 
89
 
parseRules "normal" = 
90
 
  do (attr, result) <- (((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["abstract","alias","align","asm","auto","body","break","case","cast","catch","class","const","continue","default","delegate","delete","do","else","enum","export","false","final","finally","for","foreach","foreach_reverse","function","goto","if","in","inout","interface","invariant","is","lazy","macro","mixin","new","null","out","override","package","private","protected","public","ref","return","scope","static","struct","super","switch","synchronized","template","this","throw","true","try","typedef","typeid","typeof","union","volatile","while","with"] >>= withAttribute "Keyword"))
91
 
                        <|>
92
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["module","import"] >>= withAttribute "Module") >>~ pushContext "ModuleName")
93
 
                        <|>
94
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["void","bool","byte","ubyte","short","ushort","int","uint","long","ulong","cent","ucent","float","double","real","ireal","ifloat","idouble","creal","cfloat","cdouble","char","wchar","dchar"] >>= withAttribute "Type"))
95
 
                        <|>
96
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["string","wstring","dstring","size_t","ptrdiff_t","hash_t","Error","Exception","Object","TypeInfo","ClassInfo"] >>= withAttribute "LibrarySymbols"))
97
 
                        <|>
98
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["extern"] >>= withAttribute "Linkage") >>~ pushContext "Linkage")
99
 
                        <|>
100
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["debug"] >>= withAttribute "Debug"))
101
 
                        <|>
102
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["assert"] >>= withAttribute "Assert"))
103
 
                        <|>
104
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["pragma"] >>= withAttribute "Pragma") >>~ pushContext "Pragmas")
105
 
                        <|>
106
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["version"] >>= withAttribute "Version") >>~ pushContext "Version")
107
 
                        <|>
108
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["unittest"] >>= withAttribute "Unit Test"))
109
 
                        <|>
110
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["__FILE__","__LINE__","__DATE__","__TIME__","__TIMESTAMP__","__VENDOR__","__VERSION__","__EOF__"] >>= withAttribute "SpecialTokens"))
111
 
                        <|>
112
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["deprecated"] >>= withAttribute "Deprecated") >>~ pushContext "Deprecated")
113
 
                        <|>
114
 
                        ((pDetect2Chars False 'r' '"' >>= withAttribute "RawString") >>~ pushContext "RawString")
115
 
                        <|>
116
 
                        ((pDetect2Chars False 'x' '"' >>= withAttribute "HexString") >>~ pushContext "HexString")
117
 
                        <|>
118
 
                        ((pDetectIdentifier >>= withAttribute "Normal Text"))
119
 
                        <|>
120
 
                        ((pHlCStringChar >>= withAttribute "EscapeString") >>~ (popContext >> return ()))
121
 
                        <|>
122
 
                        ((pDetect2Chars False '\\' 'u' >>= withAttribute "EscapeString") >>~ pushContext "UnicodeShort")
123
 
                        <|>
124
 
                        ((pDetect2Chars False '\\' 'U' >>= withAttribute "EscapeString") >>~ pushContext "UnicodeLong")
125
 
                        <|>
126
 
                        ((pDetect2Chars False '\\' '&' >>= withAttribute "EscapeString") >>~ pushContext "HTMLEntity")
127
 
                        <|>
128
 
                        ((pDetectChar False '\'' >>= withAttribute "Char") >>~ pushContext "CharLiteral")
129
 
                        <|>
130
 
                        ((pDetectChar False '"' >>= withAttribute "String") >>~ pushContext "String")
131
 
                        <|>
132
 
                        ((pDetectChar False '`' >>= withAttribute "BQString") >>~ pushContext "BQString")
133
 
                        <|>
134
 
                        ((pDetect2Chars False '/' '/' >>= withAttribute "Comment") >>~ pushContext "CommentLine")
135
 
                        <|>
136
 
                        ((pDetect2Chars False '/' '*' >>= withAttribute "Comment") >>~ pushContext "CommentBlock")
137
 
                        <|>
138
 
                        ((pDetect2Chars False '/' '+' >>= withAttribute "Comment") >>~ pushContext "CommentNested")
139
 
                        <|>
140
 
                        ((pDetectChar False '{' >>= withAttribute "Normal Text"))
141
 
                        <|>
142
 
                        ((pDetectChar False '}' >>= withAttribute "Normal Text"))
143
 
                        <|>
144
 
                        ((pString False "..." >>= withAttribute "Normal Text") >>~ (popContext >> return ()))
145
 
                        <|>
146
 
                        ((pDetect2Chars False '.' '.' >>= withAttribute "Normal Text"))
147
 
                        <|>
148
 
                        ((pRegExpr (compileRegex "0[xX][_a-fA-F\\d]*(\\.[_a-fA-F\\d]*)?[pP][-+]?[\\d]+[_\\d]*[fFL]?i?") >>= withAttribute "Float") >>~ (popContext >> return ()))
149
 
                        <|>
150
 
                        ((pRegExpr (compileRegex "[\\d][_\\d]*(\\.(?!\\.)[_\\d]*([eE][-+]?[\\d]+[_\\d]*)?[fFL]?i?|[eE][-+]?[\\d]+[_\\d]*[fFL]?i?|[fF]i?|[fFL]?i)") >>= withAttribute "Float") >>~ (popContext >> return ()))
151
 
                        <|>
152
 
                        ((pRegExpr (compileRegex "\\.[\\d][_\\d]*([eE][-+]?[\\d]+[_\\d]*)?[fFL]?i?") >>= withAttribute "Float") >>~ (popContext >> return ()))
153
 
                        <|>
154
 
                        ((pRegExpr (compileRegex "0[bB]_*[01][01_]*(L[uU]?|[uU]L?)?") >>= withAttribute "Binary") >>~ (popContext >> return ()))
155
 
                        <|>
156
 
                        ((pRegExpr (compileRegex "0_*[0-7][0-7_]*(L[uU]?|[uU]L?)?") >>= withAttribute "Octal") >>~ (popContext >> return ()))
157
 
                        <|>
158
 
                        ((pRegExpr (compileRegex "0[xX]_*[\\da-fA-F][\\da-fA-F_]*(L[uU]?|[uU]L?)?") >>= withAttribute "Hex") >>~ (popContext >> return ()))
159
 
                        <|>
160
 
                        ((pRegExpr (compileRegex "\\d+[\\d_]*(L[uU]?|[uU]L?)?") >>= withAttribute "Integer") >>~ (popContext >> return ()))
161
 
                        <|>
162
 
                        ((pString False "#line" >>= withAttribute "Pragma") >>~ (popContext >> return ())))
163
 
     return (attr, result)
164
 
 
165
 
parseRules "UnicodeShort" = 
166
 
  do (attr, result) <- ((pRegExpr (compileRegex "[\\da-fA-F]{4}") >>= withAttribute "EscapeString") >>~ (popContext >> return ()))
167
 
     return (attr, result)
168
 
 
169
 
parseRules "UnicodeLong" = 
170
 
  do (attr, result) <- ((pRegExpr (compileRegex "[\\da-fA-F]{8}") >>= withAttribute "EscapeString") >>~ (popContext >> return ()))
171
 
     return (attr, result)
172
 
 
173
 
parseRules "HTMLEntity" = 
174
 
  do (attr, result) <- (((pRegExpr (compileRegex "[a-zA-Z]\\w+;") >>= withAttribute "EscapeString") >>~ (popContext >> return ()))
175
 
                        <|>
176
 
                        ((popContext >> return ()) >> return ([], "")))
177
 
     return (attr, result)
178
 
 
179
 
parseRules "ModuleName" = 
180
 
  do (attr, result) <- (((pDetect2Chars False '/' '/' >>= withAttribute "Comment") >>~ pushContext "CommentLine")
181
 
                        <|>
182
 
                        ((pDetect2Chars False '/' '*' >>= withAttribute "Comment") >>~ pushContext "CommentBlock")
183
 
                        <|>
184
 
                        ((pDetect2Chars False '/' '+' >>= withAttribute "Comment") >>~ pushContext "CommentNested")
185
 
                        <|>
186
 
                        ((pRegExpr (compileRegex "[^\\s\\w.:,]") >>= withAttribute "Module Name") >>~ (popContext >> return ())))
187
 
     return (attr, result)
188
 
 
189
 
parseRules "Deprecated" = 
190
 
  do (attr, result) <- (((pDetect2Chars False '/' '/' >>= withAttribute "Comment") >>~ pushContext "CommentLine")
191
 
                        <|>
192
 
                        ((pDetect2Chars False '/' '*' >>= withAttribute "Comment") >>~ pushContext "CommentBlock")
193
 
                        <|>
194
 
                        ((pDetect2Chars False '/' '+' >>= withAttribute "Comment") >>~ pushContext "CommentNested")
195
 
                        <|>
196
 
                        ((pRegExpr (compileRegex "[;({=]") >>= withAttribute "Normal Text") >>~ (popContext >> return ())))
197
 
     return (attr, result)
198
 
 
199
 
parseRules "Linkage" = 
200
 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Linkage"))
201
 
                        <|>
202
 
                        ((pDetectChar False '(' >>= withAttribute "Normal Text") >>~ pushContext "Linkage2")
203
 
                        <|>
204
 
                        ((popContext >> return ()) >> return ([], "")))
205
 
     return (attr, result)
206
 
 
207
 
parseRules "Linkage2" = 
208
 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Linkage"))
209
 
                        <|>
210
 
                        ((pString False "C++" >>= withAttribute "Linkage Type") >>~ (popContext >> return ()))
211
 
                        <|>
212
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["C","D","Windows","Pascal","System"] >>= withAttribute "Linkage Type") >>~ (popContext >> return ()))
213
 
                        <|>
214
 
                        ((pRegExpr (compileRegex "[^)]+") >>= withAttribute "Error") >>~ (popContext >> return ()))
215
 
                        <|>
216
 
                        ((popContext >> return ()) >> return ([], "")))
217
 
     return (attr, result)
218
 
 
219
 
parseRules "Version" = 
220
 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Version"))
221
 
                        <|>
222
 
                        ((pDetectChar False '=' >>= withAttribute "Normal Text") >>~ pushContext "Version2")
223
 
                        <|>
224
 
                        ((pDetectChar False '(' >>= withAttribute "Normal Text") >>~ pushContext "Version2")
225
 
                        <|>
226
 
                        ((pDetectChar False ';' >>= withAttribute "Normal Text") >>~ (popContext >> return ()))
227
 
                        <|>
228
 
                        ((pDetectChar False ')' >>= withAttribute "Normal Text") >>~ (popContext >> return ()))
229
 
                        <|>
230
 
                        ((pRegExpr (compileRegex "[^\\n]+") >>= withAttribute "Error") >>~ (popContext >> return ()))
231
 
                        <|>
232
 
                        ((popContext >> return ()) >> return ([], "")))
233
 
     return (attr, result)
234
 
 
235
 
parseRules "Version2" = 
236
 
  do (attr, result) <- (((pDetectSpaces >>= withAttribute "Version"))
237
 
                        <|>
238
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["DigitalMars","X86","AMD64","Windows","Win32","Win64","linux","LittleEndian","BigEndian","D_InlineAsm","none"] >>= withAttribute "Version Type") >>~ (popContext >> return ()))
239
 
                        <|>
240
 
                        ((pDetectIdentifier >>= withAttribute "Normal Text") >>~ (popContext >> return ()))
241
 
                        <|>
242
 
                        ((pInt >>= withAttribute "Integer") >>~ (popContext >> return ()))
243
 
                        <|>
244
 
                        ((pRegExpr (compileRegex "[^);]+") >>= withAttribute "Error") >>~ (popContext >> return ()))
245
 
                        <|>
246
 
                        ((popContext >> return ()) >> return ([], "")))
247
 
     return (attr, result)
248
 
 
249
 
parseRules "Pragmas" = 
250
 
  do (attr, result) <- (((pDetectChar False '(' >>= withAttribute "Normal Text"))
251
 
                        <|>
252
 
                        ((pKeyword " \n\t.():!+,-<=>%&*/;?[]^{|}~\\" ["msg","lib"] >>= withAttribute "Version Type") >>~ (popContext >> return ()))
253
 
                        <|>
254
 
                        ((pDetectIdentifier >>= withAttribute "Normal Text") >>~ (popContext >> return ())))
255
 
     return (attr, result)
256
 
 
257
 
parseRules "RawString" = 
258
 
  do (attr, result) <- ((pDetectChar False '"' >>= withAttribute "RawString") >>~ (popContext >> return ()))
259
 
     return (attr, result)
260
 
 
261
 
parseRules "BQString" = 
262
 
  do (attr, result) <- ((pDetectChar False '`' >>= withAttribute "BQString") >>~ (popContext >> return ()))
263
 
     return (attr, result)
264
 
 
265
 
parseRules "HexString" = 
266
 
  do (attr, result) <- (((pDetectChar False '"' >>= withAttribute "HexString") >>~ (popContext >> return ()))
267
 
                        <|>
268
 
                        ((pRegExpr (compileRegex "[^\\sa-fA-F\\d\"]+") >>= withAttribute "Error")))
269
 
     return (attr, result)
270
 
 
271
 
parseRules "CharLiteral" = 
272
 
  do (attr, result) <- (((pHlCStringChar >>= withAttribute "EscapeSequence"))
273
 
                        <|>
274
 
                        ((pDetectChar False '\'' >>= withAttribute "Char") >>~ (popContext >> return ()))
275
 
                        <|>
276
 
                        ((pRegExpr (compileRegex "\\\\(u[\\da-fA-F]{4}|U[\\da-fA-F]{8}|&[a-zA-Z]\\w+;)") >>= withAttribute "EscapeSequence"))
277
 
                        <|>
278
 
                        ((pDetectChar False '\'' >>= withAttribute "Char") >>~ (popContext >> return ()))
279
 
                        <|>
280
 
                        ((pRegExpr (compileRegex ".'") >>= withAttribute "Char"))
281
 
                        <|>
282
 
                        ((popContext >> return ()) >> return ([], "")))
283
 
     return (attr, result)
284
 
 
285
 
parseRules "String" = 
286
 
  do (attr, result) <- (((pDetect2Chars False '\\' '"' >>= withAttribute "String"))
287
 
                        <|>
288
 
                        ((pDetectChar False '"' >>= withAttribute "String") >>~ (popContext >> return ()))
289
 
                        <|>
290
 
                        ((pHlCStringChar >>= withAttribute "EscapeSequence"))
291
 
                        <|>
292
 
                        ((pRegExpr (compileRegex "\\\\(u[\\da-fA-F]{4}|U[\\da-fA-F]{8}|&[a-zA-Z]\\w+;)") >>= withAttribute "EscapeSequence")))
293
 
     return (attr, result)
294
 
 
295
 
parseRules "CommentLine" = 
296
 
  pzero
297
 
 
298
 
parseRules "CommentBlock" = 
299
 
  do (attr, result) <- ((pDetect2Chars False '*' '/' >>= withAttribute "Comment") >>~ (popContext >> return ()))
300
 
     return (attr, result)
301
 
 
302
 
parseRules "CommentNested" = 
303
 
  do (attr, result) <- (((pDetect2Chars False '/' '+' >>= withAttribute "Comment") >>~ pushContext "CommentNested")
304
 
                        <|>
305
 
                        ((pDetect2Chars False '+' '/' >>= withAttribute "Comment") >>~ (popContext >> return ())))
306
 
     return (attr, result)
307
 
 
308
 
parseRules x = fail $ "Unknown context" ++ x