summaryrefslogtreecommitdiff
path: root/pygments/lexers/functional.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-01-09 14:04:54 +0100
committerGeorg Brandl <georg@python.org>2013-01-09 14:04:54 +0100
commit9cc134d20b8505b6d472cca6872406dbecf5fda3 (patch)
tree773193024f85183f92d1ee4e32fe7a2b5ea70349 /pygments/lexers/functional.py
parent2867cf9479652aebd216e0c081e14bdc9aa4897b (diff)
parent0b03ce73a68bc794d4891b3cbbc581c7ccf3e03a (diff)
downloadpygments-9cc134d20b8505b6d472cca6872406dbecf5fda3.tar.gz
Merged in blackjack/pygments-main (pull request #88: CBM BASIC V2 and ca65 assembler)
Diffstat (limited to 'pygments/lexers/functional.py')
-rw-r--r--pygments/lexers/functional.py208
1 files changed, 205 insertions, 3 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index f77b918c..4947bf7d 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -5,7 +5,7 @@
Lexers for functional languages.
- :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -18,12 +18,13 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, \
__all__ = ['RacketLexer', 'SchemeLexer', 'CommonLispLexer', 'HaskellLexer',
'LiterateHaskellLexer', 'SMLLexer', 'OcamlLexer', 'ErlangLexer',
'ErlangShellLexer', 'OpaLexer', 'CoqLexer', 'NewLispLexer',
- 'ElixirLexer', 'ElixirConsoleLexer']
+ 'ElixirLexer', 'ElixirConsoleLexer', 'KokaLexer']
class RacketLexer(RegexLexer):
"""
- Lexer for Racket source code.
+ Lexer for `Racket <http://racket-lang.org/>`_ source code (formerly known as
+ PLT Scheme).
*New in Pygments 1.6.*
"""
@@ -2393,3 +2394,204 @@ class ElixirConsoleLexer(Lexer):
for item in do_insertions(insertions,
exlexer.get_tokens_unprocessed(curcode)):
yield item
+
+
+class KokaLexer(RegexLexer):
+ """
+ Lexer for the `Koka <http://research.microsoft.com/en-us/projects/koka/>`_
+ language.
+
+ *New in Pygments 1.6.*
+ """
+
+ name = 'Koka'
+ aliases = ['koka']
+ filenames = ['*.kk', '*.kki']
+ mimetypes = ['text/x-koka']
+
+ keywords = [
+ 'infix', 'infixr', 'infixl', 'prefix', 'postfix',
+ 'type', 'cotype', 'rectype', 'alias',
+ 'struct', 'con',
+ 'fun', 'function', 'val', 'var',
+ 'external',
+ 'if', 'then', 'else', 'elif', 'return', 'match',
+ 'private', 'public', 'private',
+ 'module', 'import', 'as',
+ 'include', 'inline',
+ 'rec',
+ 'try', 'yield', 'enum',
+ 'interface', 'instance',
+ ]
+
+ # keywords that are followed by a type
+ typeStartKeywords = [
+ 'type', 'cotype', 'rectype', 'alias', 'struct', 'enum',
+ ]
+
+ # keywords valid in a type
+ typekeywords = [
+ 'forall', 'exists', 'some', 'with',
+ ]
+
+ # builtin names and special names
+ builtin = [
+ 'for', 'while', 'repeat',
+ 'foreach', 'foreach-indexed',
+ 'error', 'catch', 'finally',
+ 'cs', 'js', 'file', 'ref', 'assigned',
+ ]
+
+ # symbols that can be in an operator
+ symbols = '[\$%&\*\+@!/\\\^~=\.:\-\?\|<>]+'
+
+ # symbol boundary: an operator keyword should not be followed by any of these
+ sboundary = '(?!'+symbols+')'
+
+ # name boundary: a keyword should not be followed by any of these
+ boundary = '(?![a-zA-Z0-9_\\-])'
+
+ # main lexer
+ tokens = {
+ 'root': [
+ include('whitespace'),
+
+ # go into type mode
+ (r'::?' + sboundary, Keyword.Type, 'type'),
+ (r'alias' + boundary, Keyword, 'alias-type'),
+ (r'struct' + boundary, Keyword, 'struct-type'),
+ (r'(%s)' % '|'.join(typeStartKeywords) + boundary, Keyword, 'type'),
+
+ # special sequences of tokens (we use ?: for non-capturing group as
+ # required by 'bygroups')
+ (r'(module)(\s*)((?:interface)?)(\s*)'
+ r'((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*'
+ r'[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)',
+ bygroups(Keyword, Text, Keyword, Text, Name.Namespace)),
+ (r'(import)(\s+)((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*[a-z]'
+ r'(?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)((?:as)?)'
+ r'((?:[A-Z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)?)',
+ bygroups(Keyword, Text, Name.Namespace, Text, Keyword,
+ Name.Namespace)),
+
+ # keywords
+ (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
+ (r'(%s)' % '|'.join(keywords) + boundary, Keyword),
+ (r'(%s)' % '|'.join(builtin) + boundary, Keyword.Pseudo),
+ (r'::|:=|\->|[=\.:]' + sboundary, Keyword),
+ (r'\-' + sboundary, Generic.Strong),
+
+ # names
+ (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
+ (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
+ (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Name),
+ (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Name.Variable),
+
+ # literal string
+ (r'@"', String.Double, 'litstring'),
+
+ # operators
+ (symbols, Operator),
+ (r'`', Operator),
+ (r'[\{\}\(\)\[\];,]', Punctuation),
+
+ # literals. No check for literal characters with len > 1
+ (r'[0-9]+\.[0-9]+([eE][\-\+]?[0-9]+)?', Number.Float),
+ (r'0[xX][0-9a-fA-F]+', Number.Hex),
+ (r'[0-9]+', Number.Integer),
+
+ (r"'", String.Char, 'char'),
+ (r'"', String.Double, 'string'),
+ ],
+
+ # type started by alias
+ 'alias-type': [
+ (r'=',Keyword),
+ include('type')
+ ],
+
+ # type started by struct
+ 'struct-type': [
+ (r'(?=\((?!,*\)))',Punctuation, '#pop'),
+ include('type')
+ ],
+
+ # type started by colon
+ 'type': [
+ (r'[\(\[<]', Keyword.Type, 'type-nested'),
+ include('type-content')
+ ],
+
+ # type nested in brackets: can contain parameters, comma etc.
+ 'type-nested': [
+ (r'[\)\]>]', Keyword.Type, '#pop'),
+ (r'[\(\[<]', Keyword.Type, 'type-nested'),
+ (r',', Keyword.Type),
+ (r'([a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)(:)(?!:)',
+ bygroups(Name.Variable,Text,Keyword.Type)), # parameter name
+ include('type-content')
+ ],
+
+ # shared contents of a type
+ 'type-content': [
+ include('whitespace'),
+
+ # keywords
+ (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
+ (r'(?=((%s)' % '|'.join(keywords) + boundary + '))',
+ Keyword, '#pop'), # need to match because names overlap...
+
+ # kinds
+ (r'[EPH]' + boundary, Keyword.Type),
+ (r'[*!]', Keyword.Type),
+
+ # type names
+ (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
+ (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
+ (r'[a-z][0-9]*(?![a-zA-Z_\-])', Keyword.Type), # Generic.Emph
+ (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type), # Generic.Emph
+ (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type),
+
+ # type keyword operators
+ (r'::|\->|[\.:|]', Keyword.Type),
+
+ #catchall
+ (r'', Text, '#pop')
+ ],
+
+ # comments and literals
+ 'whitespace': [
+ (r'\s+', Text),
+ (r'/\*', Comment.Multiline, 'comment'),
+ (r'//.*$', Comment.Single)
+ ],
+ 'comment': [
+ (r'[^/\*]+', Comment.Multiline),
+ (r'/\*', Comment.Multiline, '#push'),
+ (r'\*/', Comment.Multiline, '#pop'),
+ (r'[\*/]', Comment.Multiline),
+ ],
+ 'litstring': [
+ (r'[^"]+', String.Double),
+ (r'""', String.Escape),
+ (r'"', String.Double, '#pop'),
+ ],
+ 'string': [
+ (r'[^\\"\n]+', String.Double),
+ include('escape-sequence'),
+ (r'["\n]', String.Double, '#pop'),
+ ],
+ 'char': [
+ (r'[^\\\'\n]+', String.Char),
+ include('escape-sequence'),
+ (r'[\'\n]', String.Char, '#pop'),
+ ],
+ 'escape-sequence': [
+ (r'\\[abfnrtv0\\\"\'\?]', String.Escape),
+ (r'\\x[0-9a-fA-F]{2}', String.Escape),
+ (r'\\u[0-9a-fA-F]{4}', String.Escape),
+ # Yes, \U literals are 6 hex digits.
+ (r'\\U[0-9a-fA-F]{6}', String.Escape)
+ ]
+ }
+