Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/inferno.py: 93%

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.inferno 

3 ~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for Inferno os and all the related stuff. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, bygroups, default 

14from pygments.token import Punctuation, Comment, Operator, Keyword, \ 

15 Name, String, Number, Whitespace 

16 

17__all__ = ['LimboLexer'] 

18 

19 

20class LimboLexer(RegexLexer): 

21 """ 

22 Lexer for Limbo programming language 

23 

24 TODO: 

25 - maybe implement better var declaration highlighting 

26 - some simple syntax error highlighting 

27 

28 .. versionadded:: 2.0 

29 """ 

30 name = 'Limbo' 

31 url = 'http://www.vitanuova.com/inferno/limbo.html' 

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(Whitespace, Name.Label, Whitespace)), 

40 (r'\n', Whitespace), 

41 (r'\s+', Whitespace), 

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