pddl.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """
  2. pygments.lexers.pddl
  3. ~~~~~~~~~~~~~~~~~~~~
  4. Lexer for the Planning Domain Definition Language.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, words, include
  9. from pygments.token import Punctuation, Keyword, Whitespace, Name, Comment, \
  10. Operator, Number
  11. __all__ = ['PddlLexer']
  12. class PddlLexer(RegexLexer):
  13. """
  14. A PDDL lexer.
  15. It should support up to PDDL 3.1.
  16. """
  17. name = 'PDDL'
  18. aliases = ['pddl']
  19. filenames = ['*.pddl']
  20. # there doesn't really seem to be a PDDL homepage.
  21. url = 'https://en.wikipedia.org/wiki/Planning_Domain_Definition_Language'
  22. version_added = '2.19'
  23. tokens = {
  24. 'root': [
  25. (r'\s+', Whitespace),
  26. (r';.*$', Comment.Singleline),
  27. include('keywords'),
  28. include('builtins'),
  29. (r'[()]', Punctuation),
  30. (r'[=/*+><-]', Operator),
  31. (r'[a-zA-Z][a-zA-Z0-9_-]*', Name),
  32. (r'\?[a-zA-Z][a-zA-Z0-9_-]*', Name.Variable),
  33. (r'[0-9]+\.[0-9]+', Number.Float),
  34. (r'[0-9]+', Number.Integer),
  35. ],
  36. 'keywords': [
  37. (words((
  38. ':requirements', ':types', ':constants',
  39. ':predicates', ':functions', ':action', ':agent',
  40. ':parameters', ':precondition', ':effect',
  41. ':durative-action', ':duration', ':condition',
  42. ':derived', ':domain', ':objects', ':init',
  43. ':goal', ':metric', ':length', ':serial', ':parallel',
  44. # the following are requirements
  45. ':strips', ':typing', ':negative-preconditions',
  46. ':disjunctive-preconditions', ':equality',
  47. ':existential-preconditions', ':universal-preconditions',
  48. ':conditional-effects', ':fluents', ':numeric-fluents',
  49. ':object-fluents', ':adl', ':durative-actions',
  50. ':continuous-effects', ':derived-predicates',
  51. ':time-intial-literals', ':preferences',
  52. ':constraints', ':action-costs', ':multi-agent',
  53. ':unfactored-privacy', ':factored-privacy',
  54. ':non-deterministic'
  55. ), suffix=r'\b'), Keyword)
  56. ],
  57. 'builtins': [
  58. (words((
  59. 'define', 'domain', 'object', 'either', 'and',
  60. 'forall', 'preference', 'imply', 'or', 'exists',
  61. 'not', 'when', 'assign', 'scale-up', 'scale-down',
  62. 'increase', 'decrease', 'at', 'over', 'start',
  63. 'end', 'all', 'problem', 'always', 'sometime',
  64. 'within', 'at-most-once', 'sometime-after',
  65. 'sometime-before', 'always-within', 'hold-during',
  66. 'hold-after', 'minimize', 'maximize',
  67. 'total-time', 'is-violated'), suffix=r'\b'),
  68. Name.Builtin)
  69. ]
  70. }