inferno.py 3.1 KB

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