Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/libcst/_parser/conversions/terminals.py: 59%

32 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# pyre-unsafe 

6 

7from typing import Any 

8 

9from libcst._nodes.expression import SimpleString 

10from libcst._parser.types.config import ParserConfig 

11from libcst._parser.types.partials import WithLeadingWhitespace 

12from libcst._parser.types.token import Token 

13from libcst._parser.whitespace_parser import ( 

14 parse_empty_lines, 

15 parse_trailing_whitespace, 

16) 

17 

18 

19def convert_NAME(config: ParserConfig, token: Token) -> Any: 

20 return token 

21 

22 

23def convert_NUMBER(config: ParserConfig, token: Token) -> Any: 

24 return token 

25 

26 

27def convert_STRING(config: ParserConfig, token: Token) -> Any: 

28 return WithLeadingWhitespace(SimpleString(token.string), token.whitespace_before) 

29 

30 

31def convert_OP(config: ParserConfig, token: Token) -> Any: 

32 return token 

33 

34 

35def convert_NEWLINE(config: ParserConfig, token: Token) -> Any: 

36 # A NEWLINE token is only emitted for semantic newlines, which means that this 

37 # corresponds to a TrailingWhitespace, since that's the only semantic 

38 # newline-containing node. 

39 

40 # N.B. Because this token is whitespace, and because the whitespace parser doesn't 

41 # try to prevent overflows, `token.whitespace_before` will end up overflowing into 

42 # the value of this newline token, so `parse_trailing_whitespace` will include 

43 # token.string's value. This is expected and desired behavior. 

44 return parse_trailing_whitespace(config, token.whitespace_before) 

45 

46 

47def convert_INDENT(config: ParserConfig, token: Token) -> Any: 

48 return token 

49 

50 

51def convert_DEDENT(config: ParserConfig, token: Token) -> Any: 

52 return token 

53 

54 

55def convert_ENDMARKER(config: ParserConfig, token: Token) -> Any: 

56 # Parse any and all empty lines with an indent similar to the header. That is, 

57 # indent of nothing and including all indents. In some cases, like when the 

58 # footer parser follows an indented suite, the state's indent can be wrong 

59 # due to the fact that it is shared with the _DEDENT node. We know that if 

60 # we're parsing the end of a file, we will have no indent. 

61 return parse_empty_lines( 

62 config, token.whitespace_before, override_absolute_indent="" 

63 ) 

64 

65 

66def convert_FSTRING_START(config: ParserConfig, token: Token) -> Any: 

67 return token 

68 

69 

70def convert_FSTRING_END(config: ParserConfig, token: Token) -> Any: 

71 return token 

72 

73 

74def convert_FSTRING_STRING(config: ParserConfig, token: Token) -> Any: 

75 return token 

76 

77 

78def convert_ASYNC(config: ParserConfig, token: Token) -> Any: 

79 return token 

80 

81 

82def convert_AWAIT(config: ParserConfig, token: Token) -> Any: 

83 return token