Commits

Tim Hatch committed 6df2be7 Merge

Merged in chochos/pygments-main (pull request #86)

Comments (0)

Files changed (2)

pygments/lexers/jvm.py

         ],
     }
 
+class CeylonLexer(RegexLexer):
+    """
+    For `Ceylon <http://ceylon-lang.org/>`_ source code.
+    """
+
+    name = 'Ceylon'
+    aliases = ['ceylon']
+    filenames = ['*.ceylon']
+    mimetypes = ['text/x-ceylon']
+
+    flags = re.MULTILINE | re.DOTALL
+
+    #: optional Comment or Whitespace
+    _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
+
+    tokens = {
+        'root': [
+            # method names
+            (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
+             r'([a-zA-Z_][a-zA-Z0-9_]*)'                    # method name
+             r'(\s*)(\()',                                  # signature start
+             bygroups(using(this), Name.Function, Text, Operator)),
+            (r'[^\S\n]+', Text),
+            (r'//.*?\n', Comment.Single),
+            (r'/\*.*?\*/', Comment.Multiline),
+            (r'(variable|shared|abstract|doc|by|formal|actual)', Name.Decorator),
+            (r'(break|case|catch|continue|default|else|finally|for|in|variable|'
+             r'if|return|switch|this|throw|try|while|is|exists|nonempty|then|outer)\b',
+             Keyword),
+            (r'(abstracts|extends|satisfies|adapts|'
+             r'super|given|of|out|assign|'
+             r'transient|volatile)\b', Keyword.Declaration),
+            (r'(function|value|void)\b',
+             Keyword.Type),
+            (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
+            (r'(true|false|null)\b', Keyword.Constant),
+            (r'(class|interface|object)(\s+)', bygroups(Keyword.Declaration, Text), 'class'),
+            (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
+            (r'"(\\\\|\\"|[^"])*"', String),
+            (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Quoted),
+            (r"`\\.`|`[^\\]`|`\\u[0-9a-f]{4}`", String.Char),
+            (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+            (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
+            (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+            (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
+            (r'\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
+            (r'\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', Number.Float),
+            (r'[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
+            (r'[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', Number.Float),
+            (r'0x[0-9a-f]+', Number.Hex),
+            (r'\d{1,3}(_\d{3})+[kMGTP]?', Number.Integer),
+            (r'[0-9]+[kMGTP]?', Number.Integer),
+            (r'\n', Text)
+        ],
+        'class': [
+            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
+        ],
+        'import': [
+            (r'[a-zA-Z0-9_.]+\w+ \{([a-zA-Z,]+|\.\.\.)\}', Name.Namespace, '#pop')
+        ],
+    }
 
 class KotlinLexer(RegexLexer):
     """

tests/examplefiles/example.ceylon

+doc "A top-level function,
+     with multi-line documentation."
+void topLevel(String? a, Integer b=5, String... seqs) {
+    function nested(String s) {
+        print(s[1..2]);
+        return true;
+    }
+    for (s in seqs.filter((String x) x.size > 2)) {
+        nested(s);
+    }
+    value uppers = seqs.sequence[].uppercased;
+    String|Nothing z = a;
+    Sequence<Integer> ints = { 1, 2, 3, 4, 5 };
+}
+
+shared class Example<Element>(name, element) satisfies Comparable<Example<Element>>
+        given Element satisfies Comparable<Element> {
+    shared String name;
+    shared Element element;
+
+    shared actual Comparison compare(Example<Element> other) {
+        return element <=> other.element;
+    }
+
+    shared actual String string {
+        return "Example with " + element.string;
+    }
+}
+
+Example<Integer> instance = Example {
+    name = "Named args call";
+    element = 5;
+};