inferno.py 3.0 KB

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