summaryrefslogtreecommitdiff
path: root/pygments/lexers/haskell.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/lexers/haskell.py')
-rw-r--r--pygments/lexers/haskell.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/pygments/lexers/haskell.py b/pygments/lexers/haskell.py
index 1a2f2217..d9eecaaf 100644
--- a/pygments/lexers/haskell.py
+++ b/pygments/lexers/haskell.py
@@ -5,19 +5,19 @@
Lexers for Haskell and related languages.
- :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \
- default, include
+ default, include, inherit
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Generic
from pygments import unistring as uni
-__all__ = ['HaskellLexer', 'IdrisLexer', 'AgdaLexer', 'CryptolLexer',
+__all__ = ['HaskellLexer', 'HspecLexer', 'IdrisLexer', 'AgdaLexer', 'CryptolLexer',
'LiterateHaskellLexer', 'LiterateIdrisLexer', 'LiterateAgdaLexer',
'LiterateCryptolLexer', 'KokaLexer']
@@ -72,11 +72,15 @@ class HaskellLexer(RegexLexer):
(r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators
(r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators
# Numbers
- (r'\d+[eE][+-]?\d+', Number.Float),
- (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float),
- (r'0[oO][0-7]+', Number.Oct),
- (r'0[xX][\da-fA-F]+', Number.Hex),
- (r'\d+', Number.Integer),
+ (r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*_*[pP][+-]?\d(_*\d)*', Number.Float),
+ (r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*\.[\da-fA-F](_*[\da-fA-F])*'
+ r'(_*[pP][+-]?\d(_*\d)*)?', Number.Float),
+ (r'\d(_*\d)*_*[eE][+-]?\d(_*\d)*', Number.Float),
+ (r'\d(_*\d)*\.\d(_*\d)*(_*[eE][+-]?\d(_*\d)*)?', Number.Float),
+ (r'0[bB]_*[01](_*[01])*', Number.Bin),
+ (r'0[oO]_*[0-7](_*[0-7])*', Number.Oct),
+ (r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*', Number.Hex),
+ (r'\d(_*\d)*', Number.Integer),
# Character/String Literals
(r"'", String.Char, 'character'),
(r'"', String, 'string'),
@@ -154,6 +158,28 @@ class HaskellLexer(RegexLexer):
}
+class HspecLexer(HaskellLexer):
+ """
+ A Haskell lexer with support for Hspec constructs.
+
+ .. versionadded:: 2.4.0
+ """
+
+ name = 'Hspec'
+ aliases = ['hspec']
+ filenames = []
+ mimetypes = []
+
+ tokens = {
+ 'root': [
+ (r'(it\s*)("[^"]*")', bygroups(Text, String.Doc)),
+ (r'(describe\s*)("[^"]*")', bygroups(Text, String.Doc)),
+ (r'(context\s*)("[^"]*")', bygroups(Text, String.Doc)),
+ inherit,
+ ],
+ }
+
+
class IdrisLexer(RegexLexer):
"""
A lexer for the dependently typed programming language Idris.
@@ -418,8 +444,8 @@ class CryptolLexer(RegexLexer):
(r'[A-Z]\w*', Keyword.Type),
(r'(_[\w\']+|[a-z][\w\']*)', Name.Function),
# TODO: these don't match the comments in docs, remove.
- #(r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single),
- #(r'{-', Comment.Multiline, 'comment'),
+ # (r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single),
+ # (r'{-', Comment.Multiline, 'comment'),
(r',', Punctuation),
(r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator),
# (HACK, but it makes sense to push two instances, believe me)
@@ -677,10 +703,10 @@ class KokaLexer(RegexLexer):
symbols = r'[$%&*+@!/\\^~=.:\-?|<>]+'
# symbol boundary: an operator keyword should not be followed by any of these
- sboundary = '(?!'+symbols+')'
+ sboundary = '(?!' + symbols + ')'
# name boundary: a keyword should not be followed by any of these
- boundary = '(?![\w/])'
+ boundary = r'(?![\w/])'
# koka token abstractions
tokenType = Name.Attribute