Attachment 'csharp.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - C# Source Parser
4
5 Copyright (c) 2005 by Zoran Isailovski <nuspheratu-4moin@yahoo.de>
6 All rights reserved.
7
8 Based on parser cplusplus.py by Taesu Pyo, which was copyrighted as follows:
9 cplusplus.py
10 Copyright (c) 2002 by Taesu Pyo <bigflood@hitel.net>
11 All rights reserved.
12 """
13
14 from MoinMoin.util.ParserBase import ParserBase
15
16 Dependencies = []
17
18 class Parser(ParserBase):
19
20 parsername = "ColorizedCSharp"
21 extensions = ['.cs']
22 Dependencies = []
23
24 def setupRules(self):
25 ParserBase.setupRules(self)
26
27 self.addRulePair("Comment","/[*]","[*]/")
28 self.addRule("Comment","//.*$")
29 self.addRulePair("String",'L?"',r'$|[^\\](\\\\)*"')
30 self.addRule("Char",r"'\\.'|'[^\\]'")
31 self.addRule("Number",r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?")
32 self.addRule("Preprc",r"^\s*#(.*\\\n)*(.*(?!\\))$")
33 self.addRule("ID","[a-zA-Z_][0-9a-zA-Z_]*")
34 self.addRule("SPChar",r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")
35
36 self.addReserved(reserved_words)
37 self.addConstant(constant_words)
38
39 self.addWords(reserved_words2,'ResWord2')
40 self.addWords(special_words,'Special')
41
42
43 ######################################################################
44 ##
45 ## Token Classifications
46 ##
47 ######################################################################
48
49 reserved_words = '''\
50 abstract event new struct
51 as explicit null switch
52 base extern object this
53 bool false operator throw
54 break finally out true
55 byte fixed override try
56 case float params typeof
57 catch for private uint
58 char foreach protected ulong
59 checked goto public unchecked
60 class if readonly unsafe
61 const implicit ref ushort
62 continue in return using
63 decimal int sbyte virtual
64 default interface sealed volatile
65 delegate internal short void
66 do is sizeof while
67 double lock stackalloc
68 else long static
69 enum namespace string
70 '''.split()
71
72
73 reserved_words2 = 'object bool char byte short ushort int uint long ulong float double string'.split()
74 special_words = 'this base'.split()
75 constant_words = 'true false null'.split()
76
77 ##reserved_words = [ word for word in reserved_words
78 ## if word not in reserved_words2 + special_words + constant_words ]
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.