inferno.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.inferno
  4. ~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for Inferno os and all the related stuff.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import RegexLexer, include, bygroups, default
  11. from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \
  12. Name, String, Number
  13. __all__ = ['LimboLexer']
  14. class LimboLexer(RegexLexer):
  15. """
  16. Lexer for `Limbo programming language <http://www.vitanuova.com/inferno/limbo.html>`_
  17. TODO:
  18. - maybe implement better var declaration highlighting
  19. - some simple syntax error highlighting
  20. .. versionadded:: 2.0
  21. """
  22. name = 'Limbo'
  23. aliases = ['limbo']
  24. filenames = ['*.b']
  25. mimetypes = ['text/limbo']
  26. tokens = {
  27. 'whitespace': [
  28. (r'^(\s*)([a-zA-Z_]\w*:(\s*)\n)',
  29. bygroups(Text, Name.Label)),
  30. (r'\n', Text),
  31. (r'\s+', Text),
  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