gcodelexer.py 826 B

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