~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/parser/text_java.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""
3
3
    MoinMoin - Java Source Parser
4
4
 
5
 
    DEPRECATED compatibility wrapper calling the highlight parser.
6
 
 
7
 
    This is to support (deprecated) existing syntax like:
8
 
    {{{#!java ...
9
 
    ...
10
 
    }}}
11
 
 
12
 
    It is equivalent to the new way to highlight code:
13
 
    {{{#!highlight java ...
14
 
    ...
15
 
    }}}
16
 
 
17
 
    @copyright: 2008 MoinMoin:ThomasWaldmann
 
5
    @copyright: 2002 Taesu Pyo <bigflood@hitel.net>
18
6
    @license: GNU GPL, see COPYING for details.
 
7
 
19
8
"""
20
9
 
21
 
from MoinMoin.parser.highlight import Parser as HighlightParser
22
 
from MoinMoin.parser.highlight import Dependencies
23
 
 
24
 
class Parser(HighlightParser):
25
 
    parsername = 'java'  # Lexer name pygments recognizes
26
 
    extensions = [] # this is only a compatibility wrapper, we have declared
27
 
                    # support for this extension in the HighlightParser, so
28
 
                    # moin will call that directly
29
 
 
 
10
from MoinMoin.parser._ParserBase import ParserBase
 
11
 
 
12
Dependencies = ['user'] # the "Toggle line numbers link" depends on user's language
 
13
 
 
14
class Parser(ParserBase):
 
15
 
 
16
    parsername = "ColorizedJava"
 
17
    extensions = ['.java']
 
18
    Dependencies = Dependencies
 
19
 
 
20
    def setupRules(self):
 
21
        ParserBase.setupRules(self)
 
22
 
 
23
        self.addRulePair("Comment", "/[*]", "[*]/")
 
24
        self.addRule("Comment", "//.*$")
 
25
        self.addRulePair("String", '"', r'$|[^\\](\\\\)*"')
 
26
        self.addRule("Char", r"'\\.'|'[^\\]'")
 
27
        self.addRule("Number", r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?")
 
28
        self.addRule("ID", "[a-zA-Z_][0-9a-zA-Z_]*")
 
29
        self.addRule("SPChar", r"[~!%^&*()+=|\[\]:;,.<>/?{}-]")
 
30
 
 
31
        reserved_words = ['class', 'interface', 'enum', 'import', 'package',
 
32
        'byte', 'int', 'long', 'float', 'double', 'char', 'short', 'void', 'boolean',
 
33
        'static', 'final', 'const', 'private', 'public', 'protected',
 
34
        'new', 'this', 'super', 'abstract', 'native', 'synchronized', 'transient', 'volatile', 'strictfp',
 
35
        'extends', 'implements', 'if', 'else', 'while', 'for', 'do', 'switch', 'case', 'default', 'instanceof',
 
36
        'try', 'catch', 'finally', 'throw', 'throws', 'return', 'continue', 'break']
 
37
 
 
38
        self.addReserved(reserved_words)
 
39
 
 
40
        constant_words = ['true', 'false', 'null']
 
41
 
 
42
        self.addConstant(constant_words)