diff options
Diffstat (limited to 'pygments/lexers/functional.py')
-rw-r--r-- | pygments/lexers/functional.py | 99 |
1 files changed, 96 insertions, 3 deletions
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py index 32e48eda..8bd4afff 100644 --- a/pygments/lexers/functional.py +++ b/pygments/lexers/functional.py @@ -21,7 +21,7 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, \ String, Number, Punctuation -__all__ = ['SchemeLexer', 'HaskellLexer'] +__all__ = ['SchemeLexer', 'HaskellLexer', 'OCamlLexer'] class SchemeLexer(RegexLexer): @@ -39,7 +39,7 @@ class SchemeLexer(RegexLexer): *New in Pygments 0.6.* """ name = 'Scheme' - aliases = ['scheme'] + aliases = ['scheme', 'scm'] filenames = ['*.scm'] mimetypes = ['text/x-scheme', 'application/x-scheme'] @@ -159,7 +159,7 @@ class HaskellLexer(RegexLexer): *New in Pygments 0.8.* """ name = 'Haskell' - aliases = ['haskell'] + aliases = ['haskell', 'hs'] filenames = ['*.hs'] reserved = ['case','class','data','default','deriving','do','else', @@ -199,6 +199,7 @@ class HaskellLexer(RegexLexer): (r'"', String, 'string'), # Special (r'\[\]', Keyword.Type), + (r'\(\)', Name.Builtin), (r'[][(),;`{}]', Punctuation), ], 'import': [ @@ -262,3 +263,95 @@ class HaskellLexer(RegexLexer): (r'\d+', String.Escape, '#pop'), ], } + + +class OcamlLexer(RegexLexer): + """ + For the OCaml language. + + *New in Pygments 0.7.* + """ + + name = 'OCaml' + aliases = ['ocaml'] + filenames = ['*.ml', '*.mli', '*.mll', '*.mly'] + mimetypes = ['text/x-ocaml'] + + keywords = [ + 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done', + 'downto', 'else', 'end', 'exception', 'external', 'false', + 'for', 'fun', 'function', 'functor', 'if', 'in', 'include', + 'inherit', 'initializer', 'lazy', 'let', 'match', 'method', + 'module', 'mutable', 'new', 'object', 'of', 'open', 'private', + 'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try', + 'type', 'val', 'virtual', 'when', 'while', 'with' + ] + keyopts = [ + '!=','#','&','&&','\(','\)','\*','\+',',','-', + '-\.','->','\.','\.\.',':','::',':=',':>',';',';;','<', + '<-','=','>','>]','>}','\?','\?\?','\[','\[<','\[>','\[\|', + ']','_','`','{','{<','\|','\|]','}','~' + ] + + operators = r'[!$%&*+\./:<=>?@^|~-]' + word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'or'] + prefix_syms = r'[!?~]' + infix_syms = r'[=<>@^|&+\*/$%-]' + primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array'] + + tokens = { + 'escape-sequence': [ + (r'\\[\"\'ntbr]', String.Escape), + (r'\\[0-9]{3}', String.Escape), + (r'\\x[0-9a-fA-F]{2}', String.Escape), + ], + 'root': [ + (r'\s+', Text), + (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo), + (r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)', + Name.Namespace, 'dotted'), + (r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class), + (r'\(\*', Comment, 'comment'), + (r'\b(%s)\b' % '|'.join(keywords), Keyword), + (r'(%s)' % '|'.join(keyopts), Operator), + (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator), + (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word), + (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type), + + (r"[^\W\d][\w']*", Name), + + (r'\d[\d_]*', Number.Integer), + (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex), + (r'0[oO][0-7][0-7_]*', Number.Oct), + (r'0[bB][01][01_]*', Number.Binary), + (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float), + + (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'", + String.Char), + (r"'.'", String.Char), + (r"'", Keyword), # a stray quote is another syntax element + + (r'"', String.Double, 'string'), + + (r'[~?][a-z][\w\']*:', Name.Variable), + ], + 'comment': [ + (r'[^(*)]', Comment), + (r'\(\*', Comment, '#push'), + (r'\*\)', Comment, '#pop'), + (r'[(*)]', Comment), + ], + 'string': [ + (r'[^\\"]', String.Double), + include('escape-sequence'), + (r'\\\n', String.Double), + (r'"', String.Double, '#pop'), + ], + 'dotted': [ + (r'\s+', Text), + (r'\.', Punctuation), + (r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace), + (r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'), + (r'[a-z][a-z0-9_\']*', Name, '#pop'), + ], + } |