gcodelexer.py 874 B

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. pygments.lexers.gcodelexer
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for the G Code Language.
  5. :copyright: Copyright 2006-2024 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. """
  15. name = 'g-code'
  16. aliases = ['gcode']
  17. filenames = ['*.gcode']
  18. url = 'https://en.wikipedia.org/wiki/G-code'
  19. version_added = '2.9'
  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. }