eric6/ThirdParty/Pygments/pygments/lexers/inferno.py

changeset 6942
2602857055c5
parent 6651
e8f3b5568b21
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.inferno
4 ~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for Inferno os and all the related stuff.
7
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 import re
13
14 from pygments.lexer import RegexLexer, include, bygroups, default
15 from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \
16 Name, String, Number
17
18 __all__ = ['LimboLexer']
19
20
21 class LimboLexer(RegexLexer):
22 """
23 Lexer for `Limbo programming language <http://www.vitanuova.com/inferno/limbo.html>`_
24
25 TODO:
26 - maybe implement better var declaration highlighting
27 - some simple syntax error highlighting
28
29 .. versionadded:: 2.0
30 """
31 name = 'Limbo'
32 aliases = ['limbo']
33 filenames = ['*.b']
34 mimetypes = ['text/limbo']
35
36 tokens = {
37 'whitespace': [
38 (r'^(\s*)([a-zA-Z_]\w*:(\s*)\n)',
39 bygroups(Text, Name.Label)),
40 (r'\n', Text),
41 (r'\s+', Text),
42 (r'#(\n|(.|\n)*?[^\\]\n)', Comment.Single),
43 ],
44 'string': [
45 (r'"', String, '#pop'),
46 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|'
47 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape),
48 (r'[^\\"\n]+', String), # all other characters
49 (r'\\', String), # stray backslash
50 ],
51 'statements': [
52 (r'"', String, 'string'),
53 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
54 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
55 (r'(\d+\.\d*|\.\d+|\d+[fF])', Number.Float),
56 (r'16r[0-9a-fA-F]+', Number.Hex),
57 (r'8r[0-7]+', Number.Oct),
58 (r'((([1-3]\d)|([2-9]))r)?(\d+)', Number.Integer),
59 (r'[()\[\],.]', Punctuation),
60 (r'[~!%^&*+=|?:<>/-]|(->)|(<-)|(=>)|(::)', Operator),
61 (r'(alt|break|case|continue|cyclic|do|else|exit'
62 r'for|hd|if|implement|import|include|len|load|or'
63 r'pick|return|spawn|tagof|tl|to|while)\b', Keyword),
64 (r'(byte|int|big|real|string|array|chan|list|adt'
65 r'|fn|ref|of|module|self|type)\b', Keyword.Type),
66 (r'(con|iota|nil)\b', Keyword.Constant),
67 (r'[a-zA-Z_]\w*', Name),
68 ],
69 'statement' : [
70 include('whitespace'),
71 include('statements'),
72 ('[{}]', Punctuation),
73 (';', Punctuation, '#pop'),
74 ],
75 'root': [
76 include('whitespace'),
77 default('statement'),
78 ],
79 }
80
81 def analyse_text(text):
82 # Any limbo module implements something
83 if re.search(r'^implement \w+;', text, re.MULTILINE):
84 return 0.7
85
86 # TODO:
87 # - Make lexers for:
88 # - asm sources
89 # - man pages
90 # - mkfiles
91 # - module definitions
92 # - namespace definitions
93 # - shell scripts
94 # - maybe keyfiles and fonts
95 # they all seem to be quite similar to their equivalents
96 # from unix world, so there should not be a lot of problems

eric ide

mercurial