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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1""" 

2 pygments.lexers.inferno 

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

4 

5 Lexers for Inferno os and all the related stuff. 

6 

7 :copyright: Copyright 2006-2025 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 name = 'Limbo' 

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

30 aliases = ['limbo'] 

31 filenames = ['*.b'] 

32 mimetypes = ['text/limbo'] 

33 version_added = '2.0' 

34 

35 tokens = { 

36 'whitespace': [ 

37 (r'^(\s*)([a-zA-Z_]\w*:)(\s*\n)', 

38 bygroups(Whitespace, Name.Label, Whitespace)), 

39 (r'\n', Whitespace), 

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

41 (r'#(\n|(.|\n)*?[^\\]\n)', Comment.Single), 

42 ], 

43 'string': [ 

44 (r'"', String, '#pop'), 

45 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' 

46 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), 

47 (r'[^\\"\n]+', String), # all other characters 

48 (r'\\', String), # stray backslash 

49 ], 

50 'statements': [ 

51 (r'"', String, 'string'), 

52 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 

53 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), 

54 (r'(\d+\.\d*|\.\d+|\d+[fF])', Number.Float), 

55 (r'16r[0-9a-fA-F]+', Number.Hex), 

56 (r'8r[0-7]+', Number.Oct), 

57 (r'((([1-3]\d)|([2-9]))r)?(\d+)', Number.Integer), 

58 (r'[()\[\],.]', Punctuation), 

59 (r'[~!%^&*+=|?:<>/-]|(->)|(<-)|(=>)|(::)', Operator), 

60 (r'(alt|break|case|continue|cyclic|do|else|exit' 

61 r'for|hd|if|implement|import|include|len|load|or' 

62 r'pick|return|spawn|tagof|tl|to|while)\b', Keyword), 

63 (r'(byte|int|big|real|string|array|chan|list|adt' 

64 r'|fn|ref|of|module|self|type)\b', Keyword.Type), 

65 (r'(con|iota|nil)\b', Keyword.Constant), 

66 (r'[a-zA-Z_]\w*', Name), 

67 ], 

68 'statement' : [ 

69 include('whitespace'), 

70 include('statements'), 

71 ('[{}]', Punctuation), 

72 (';', Punctuation, '#pop'), 

73 ], 

74 'root': [ 

75 include('whitespace'), 

76 default('statement'), 

77 ], 

78 } 

79 

80 def analyse_text(text): 

81 # Any limbo module implements something 

82 if re.search(r'^implement \w+;', text, re.MULTILINE): 

83 return 0.7 

84 

85# TODO: 

86# - Make lexers for: 

87# - asm sources 

88# - man pages 

89# - mkfiles 

90# - module definitions 

91# - namespace definitions 

92# - shell scripts 

93# - maybe keyfiles and fonts 

94# they all seem to be quite similar to their equivalents 

95# from unix world, so there should not be a lot of problems