gcodelexer.py 850 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.gcodelexer
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for the G Code Language.
  6. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer, bygroups
  10. from pygments.token import Comment, Name, Text, Keyword, Number
  11. __all__ = ['GcodeLexer']
  12. class GcodeLexer(RegexLexer):
  13. """
  14. For gcode source code.
  15. .. versionadded:: 2.9
  16. """
  17. name = 'g-code'
  18. aliases = ['gcode']
  19. filenames = ['*.gcode']
  20. tokens = {
  21. 'root': [
  22. (r';.*\n', Comment),
  23. (r'^[gmGM]\d{1,4}\s', Name.Builtin), # M or G commands
  24. (r'([^gGmM])([+-]?\d*[.]?\d+)', bygroups(Keyword, Number)),
  25. (r'\s', Text.Whitespace),
  26. (r'.*\n', Text),
  27. ]
  28. }