diff --git a/lark/grammar.py b/lark/grammar.py index 3aa8e3ab..0c72a6f5 100644 --- a/lark/grammar.py +++ b/lark/grammar.py @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, ClassVar, Sequence +from typing import Any, Dict, Optional, Tuple, ClassVar, Sequence from .utils import Serialize @@ -57,6 +57,11 @@ class NonTerminal(Symbol): is_term: ClassVar[bool] = False + def serialize(self, memo=None) -> Dict[str, Any]: + # TODO this is here because self.name can be a Token instance. + # remove this function when the issue is fixed. (backwards-incompatible) + return {'name': str(self.name), '__type__': 'NonTerminal'} + class RuleOptions(Serialize): __serialize_fields__ = 'keep_all_tokens', 'expand1', 'priority', 'template_source', 'empty_indices'