Coverage for phml\nodes\node.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-08 16:33 -0600

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING, Optional 

4 

5if TYPE_CHECKING: 

6 from .position import Position 

7 

8 

9class Node: # pylint: disable=too-few-public-methods 

10 """All node values can be expressed in JSON as: string, number, 

11 object, array, true, false, or null. This means that the syntax tree should 

12 be able to be converted to and from JSON and produce the same tree. 

13 For example, in JavaScript, a tree can be passed through JSON.parse(JSON.phml(tree)) 

14 and result in the same tree. 

15 """ 

16 

17 position: Position 

18 """The location of a node in a source document. 

19 The value of the position field implements the Position interface. 

20 The position field must not be present if a node is generated. 

21 """ 

22 

23 def __init__( 

24 self, 

25 position: Optional[Position] = None, 

26 ): 

27 self.position = position 

28 

29 @property 

30 def type(self) -> str: 

31 """Non-empty string representing the variant of a node. 

32 This field can be used to determine the type a node implements.""" 

33 return self.__class__.__name__.lower()