# -*- coding: iso-8859-1 -*-
"""
	MoinMoin - Javascript Core 1.5 Source Parser
		(Modified from the original Java Source Parser)

	@version: 1.0.0
	@copyright: 2006 by Chun-Kwong Wong <chunkwong.wong@gmail.com>
	@license: GNU GPL
"""

from MoinMoin.util.ParserBase import ParserBase

Dependencies = []

class Parser(ParserBase):
	parsername = "ColorizedJavascript"
	extensions = ['.js']
	Dependencies = []

	def setupRules(self):
		ParserBase.setupRules(self)

		self.addRulePair("Comment", "/[*]", "[*]/")
		self.addRule("Comment", "//.*$")
		self.addRulePair("String", '"', 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("ID", "[a-zA-Z_][0-9a-zA-Z_]*")
		self.addRule("SPChar", r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")

		reserved_words = ['import', 'export',
			'function', 'return', 'Arguments',
			'if', 'else',
			'new', 'delete', 'this', 'with',
			'for', 'in', 'while', 'do',
			'switch', 'case',
			'default', 'break', 'continue',
			'try', 'catch', 'throw',
			'typeof', 'instanceof',
			'eval', 'void',
			'escape', 'unescape',
			'isNaN', 'isFinite',
			'decodeURI', 'decodeURIComponent',
			'encodeURI', 'encodeURIComponent',
			'parseFloat', 'parseInt']
		special_words = ['const', 'var', 'Number', 'String']
		constant_words = ['true', 'false',
			'null', 'undefined',
			'NaN', 'Infinity']

		self.addReserved(reserved_words)
		self.addConstant(constant_words)

		self.addWords(special_words, 'special')
