1 package h
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Hy = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Hy",
12 Aliases: []string{"hylang"},
13 Filenames: []string{"*.hy"},
14 MimeTypes: []string{"text/x-hy", "application/x-hy"},
15 },
16 hyRules,
17 ))
18
19 func hyRules() Rules {
20 return Rules{
21 "root": {
22 {`;.*$`, CommentSingle, nil},
23 {`[,\s]+`, Text, nil},
24 {`-?\d+\.\d+`, LiteralNumberFloat, nil},
25 {`-?\d+`, LiteralNumberInteger, nil},
26 {`0[0-7]+j?`, LiteralNumberOct, nil},
27 {`0[xX][a-fA-F0-9]+`, LiteralNumberHex, nil},
28 {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
29 {`'(?!#)[\w!$%*+<=>?/.#-]+`, LiteralStringSymbol, nil},
30 {`\\(.|[a-z]+)`, LiteralStringChar, nil},
31 {`^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringDoc), nil},
32 {`^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')`, ByGroups(Text, LiteralStringDoc), nil},
33 {`::?(?!#)[\w!$%*+<=>?/.#-]+`, LiteralStringSymbol, nil},
34 {"~@|[`\\'#^~&@]", Operator, nil},
35 Include("py-keywords"),
36 Include("py-builtins"),
37 {Words(``, ` `, `cond`, `for`, `->`, `->>`, `car`, `cdr`, `first`, `rest`, `let`, `when`, `unless`, `import`, `do`, `progn`, `get`, `slice`, `assoc`, `with-decorator`, `,`, `list_comp`, `kwapply`, `~`, `is`, `in`, `is-not`, `not-in`, `quasiquote`, `unquote`, `unquote-splice`, `quote`, `|`, `<<=`, `>>=`, `foreach`, `while`, `eval-and-compile`, `eval-when-compile`), Keyword, nil},
38 {Words(``, ` `, `def`, `defn`, `defun`, `defmacro`, `defclass`, `lambda`, `fn`, `setv`), KeywordDeclaration, nil},
39 {Words(``, ` `, `cycle`, `dec`, `distinct`, `drop`, `even?`, `filter`, `inc`, `instance?`, `iterable?`, `iterate`, `iterator?`, `neg?`, `none?`, `nth`, `numeric?`, `odd?`, `pos?`, `remove`, `repeat`, `repeatedly`, `take`, `take_nth`, `take_while`, `zero?`), NameBuiltin, nil},
40 {`(?<=\()(?!#)[\w!$%*+<=>?/.#-]+`, NameFunction, nil},
41 {`(?!#)[\w!$%*+<=>?/.#-]+`, NameVariable, nil},
42 {`(\[|\])`, Punctuation, nil},
43 {`(\{|\})`, Punctuation, nil},
44 {`(\(|\))`, Punctuation, nil},
45 },
46 "py-keywords": {
47 {Words(``, `\b`, `assert`, `break`, `continue`, `del`, `elif`, `else`, `except`, `exec`, `finally`, `for`, `global`, `if`, `lambda`, `pass`, `print`, `raise`, `return`, `try`, `while`, `yield`, `yield from`, `as`, `with`), Keyword, nil},
48 },
49 "py-builtins": {
50 {Words(`(?<!\.)`, `\b`, `__import__`, `abs`, `all`, `any`, `apply`, `basestring`, `bin`, `bool`, `buffer`, `bytearray`, `bytes`, `callable`, `chr`, `classmethod`, `cmp`, `coerce`, `compile`, `complex`, `delattr`, `dict`, `dir`, `divmod`, `enumerate`, `eval`, `execfile`, `exit`, `file`, `filter`, `float`, `frozenset`, `getattr`, `globals`, `hasattr`, `hash`, `hex`, `id`, `input`, `int`, `intern`, `isinstance`, `issubclass`, `iter`, `len`, `list`, `locals`, `long`, `map`, `max`, `min`, `next`, `object`, `oct`, `open`, `ord`, `pow`, `property`, `range`, `raw_input`, `reduce`, `reload`, `repr`, `reversed`, `round`, `set`, `setattr`, `slice`, `sorted`, `staticmethod`, `str`, `sum`, `super`, `tuple`, `type`, `unichr`, `unicode`, `vars`, `xrange`, `zip`), NameBuiltin, nil},
51 {`(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|cls)\b`, NameBuiltinPseudo, nil},
52 {Words(`(?<!\.)`, `\b`, `ArithmeticError`, `AssertionError`, `AttributeError`, `BaseException`, `DeprecationWarning`, `EOFError`, `EnvironmentError`, `Exception`, `FloatingPointError`, `FutureWarning`, `GeneratorExit`, `IOError`, `ImportError`, `ImportWarning`, `IndentationError`, `IndexError`, `KeyError`, `KeyboardInterrupt`, `LookupError`, `MemoryError`, `NameError`, `NotImplemented`, `NotImplementedError`, `OSError`, `OverflowError`, `OverflowWarning`, `PendingDeprecationWarning`, `ReferenceError`, `RuntimeError`, `RuntimeWarning`, `StandardError`, `StopIteration`, `SyntaxError`, `SyntaxWarning`, `SystemError`, `SystemExit`, `TabError`, `TypeError`, `UnboundLocalError`, `UnicodeDecodeError`, `UnicodeEncodeError`, `UnicodeError`, `UnicodeTranslateError`, `UnicodeWarning`, `UserWarning`, `ValueError`, `VMSError`, `Warning`, `WindowsError`, `ZeroDivisionError`), NameException, nil},
53 },
54 }
55 }
56
View as plain text