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
« 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
7from typing import Any
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)
19def convert_NAME(config: ParserConfig, token: Token) -> Any:
20 return token
23def convert_NUMBER(config: ParserConfig, token: Token) -> Any:
24 return token
27def convert_STRING(config: ParserConfig, token: Token) -> Any:
28 return WithLeadingWhitespace(SimpleString(token.string), token.whitespace_before)
31def convert_OP(config: ParserConfig, token: Token) -> Any:
32 return token
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.
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)
47def convert_INDENT(config: ParserConfig, token: Token) -> Any:
48 return token
51def convert_DEDENT(config: ParserConfig, token: Token) -> Any:
52 return token
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 )
66def convert_FSTRING_START(config: ParserConfig, token: Token) -> Any:
67 return token
70def convert_FSTRING_END(config: ParserConfig, token: Token) -> Any:
71 return token
74def convert_FSTRING_STRING(config: ParserConfig, token: Token) -> Any:
75 return token
78def convert_ASYNC(config: ParserConfig, token: Token) -> Any:
79 return token
82def convert_AWAIT(config: ParserConfig, token: Token) -> Any:
83 return token