# -*- coding: iso-8859-1 -*-
"""
   MoinMoin - C# Source Parser

   Copyright (c) 2005 by Zoran Isailovski <nuspheratu-4moin@yahoo.de>
   All rights reserved.

   Based on parser cplusplus.py by Taesu Pyo, which was copyrighted as follows:
      cplusplus.py
      Copyright (c) 2002 by Taesu Pyo <bigflood@hitel.net>
      All rights reserved.
"""

from MoinMoin.util.ParserBase import ParserBase

Dependencies = []

class Parser(ParserBase):

    parsername = "ColorizedCSharp"
    extensions = ['.cs']
    Dependencies = []

    def setupRules(self):
        ParserBase.setupRules(self)

        self.addRulePair("Comment","/[*]","[*]/")
        self.addRule("Comment","//.*$")
        self.addRulePair("String",'L?"',r'$|[^\\](\\\\)*"')
        self.addRule("Char",r"'\\.'|'[^\\]'")
        self.addRule("Number",r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?")
        self.addRule("Preprc",r"^\s*#(.*\\\n)*(.*(?!\\))$")
        self.addRule("ID","[a-zA-Z_][0-9a-zA-Z_]*")
        self.addRule("SPChar",r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")

        self.addReserved(reserved_words)
        self.addConstant(constant_words)

        self.addWords(reserved_words2,'ResWord2')
        self.addWords(special_words,'Special')


######################################################################
## 
## Token Classifications
## 
######################################################################

reserved_words = '''\
abstract event new struct
as explicit null switch
base extern object this
bool false operator throw
break finally out true
byte fixed override try
case float params typeof
catch for private uint
char foreach protected ulong
checked goto public unchecked
class if readonly unsafe
const implicit ref ushort
continue in return using
decimal int sbyte virtual
default interface sealed volatile
delegate internal short void
do is sizeof while
double lock stackalloc
else long static
enum namespace string
'''.split()


reserved_words2 = 'object bool char byte short ushort int uint long ulong float double string'.split()
special_words = 'this base'.split()
constant_words = 'true false null'.split()

##reserved_words = [ word for word in reserved_words
##                   if word not in reserved_words2 + special_words + constant_words ]
