1
2 """
3 MoinMoin - SQL Source Parser
4
5 Uses the set of Oracle pl/sql reserved words:
6 http://www.stanford.edu/dept/itss/docs/oracle/9i/appdev.920/a96624/f_words.htm
7
8 @copyright: 2005 by Jim Clark <jimc AT accelrys DOT com>
9 @license: GNU GPL, see COPYING for details.
10 """
11
12 from MoinMoin.util.ParserBase import ParserBase
13
14 Dependencies = []
15
16 class Parser(ParserBase):
17
18 parsername = "ColorizedSQL"
19 extensions = ['.sql', '.pkb']
20 Dependencies = []
21
22 def __init__(self, raw, request, **kw):
23 ParserBase.__init__(self,raw,request,**kw)
24 self._ignore_case = 1
25
26 def setupRules(self):
27 ParserBase.setupRules(self)
28
29 self.addRulePair("Comment","/[*]","[*]/")
30 self.addRule("Comment","--.*$")
31 self.addRulePair("String","L?'",r"$|[^\\](\\\\)*'")
32 self.addRule("Number",r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?")
33 self.addRule("ID","[a-zA-Z_][0-9a-zA-Z_]*")
34 self.addRule("SPChar",r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")
35
36 reserved_words = ['all', 'alter', 'and', 'any', 'array', 'as', 'asc', 'at',
37 'authid', 'avg', 'begin', 'between', 'binary_integer', 'body',
38 'boolean', 'bulk', 'by', 'case', 'char', 'char_base', 'check',
39 'close', 'cluster', 'coalesce', 'collect', 'comment', 'commit',
40 'compress', 'connect', 'constant', 'create', 'current', 'currval',
41 'cursor', 'date', 'day', 'declare', 'decimal', 'default', 'delete',
42 'desc', 'distinct', 'do', 'drop', 'else', 'elsif', 'end', 'exception',
43 'exclusive', 'execute', 'exists', 'exit', 'extends', 'extract',
44 'false', 'fetch', 'float', 'for', 'forall', 'from', 'function', 'goto',
45 'group', 'having', 'heap', 'hour', 'if', 'immediate', 'in', 'index',
46 'indicator', 'insert', 'integer', 'interface', 'intersect', 'interval',
47 'into', 'is', 'isolation', 'java', 'level', 'like', 'limited', 'lock',
48 'long', 'loop', 'max', 'min', 'minus', 'minute', 'mlslabel', 'mod',
49 'mode', 'month', 'natural', 'naturaln', 'new', 'nextval', 'nocopy',
50 'not', 'nowait', 'null', 'nullif', 'number', 'number_base', 'ocirowid',
51 'of', 'on', 'opaque', 'open', 'operator', 'option', 'or', 'order',
52 'organization', 'others', 'out', 'package', 'partition', 'pctfree',
53 'pls_integer', 'positive', 'positiven', 'pragma', 'prior', 'private',
54 'procedure', 'public', 'raise', 'range', 'raw', 'real', 'record',
55 'ref', 'release', 'return', 'reverse', 'rollback', 'row', 'rowid',
56 'rownum', 'rowtype', 'savepoint', 'second', 'select', 'separate',
57 'set', 'share', 'smallint', 'space', 'sql', 'sqlcode', 'sqlerrm',
58 'start', 'stddev', 'subtype', 'successful', 'sum', 'synonym',
59 'sysdate', 'table', 'then', 'time', 'timestamp', 'timezone_region',
60 'timezone_abbr', 'timezone_minute', 'timezone_hour', 'to', 'trigger',
61 'true', 'type', 'uid', 'union', 'unique', 'update', 'use', 'user',
62 'validate', 'values', 'varchar', 'varchar2', 'variance', 'view',
63 'when', 'whenever', 'where', 'while', 'with', 'work', 'write', 'year',
64 'zone' ]
65
66 self.addReserved(reserved_words)