Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/libcst/_parser/types/py_whitespace_state.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:43 +0000

1# Copyright (c) Meta Platforms, Inc. and affiliates. 

2# 

3# This source code is licensed under the MIT license found in the 

4# LICENSE file in the root directory of this source tree. 

5 

6from dataclasses import dataclass 

7 

8from libcst._add_slots import add_slots 

9 

10 

11@add_slots 

12@dataclass(frozen=False) 

13class WhitespaceState: 

14 """ 

15 A frequently mutated store of the whitespace parser's current state. This object 

16 must be cloned prior to speculative parsing. 

17 

18 This is in contrast to the `config` object each whitespace parser function takes, 

19 which is frozen and never mutated. 

20 

21 Whitespace parsing works by mutating this state object. By encapsulating saving, and 

22 re-using state objects inside the top-level python parser, the whitespace parser is 

23 able to be reentrant. One 'convert' function can consume part of the whitespace, and 

24 another 'convert' function can consume the rest, depending on who owns what 

25 whitespace. 

26 

27 This is similar to the approach you might take to parse nested languages (e.g. 

28 JavaScript inside of HTML). We're treating whitespace as a separate language and 

29 grammar from the rest of Python's grammar. 

30 """ 

31 

32 line: int # one-indexed (to match parso's behavior) 

33 column: int # zero-indexed (to match parso's behavior) 

34 # What to look for when executing `_parse_indent`. 

35 absolute_indent: str 

36 is_parenthesized: bool