mirror of
https://github.com/Instagram/LibCST.git
synced 2025-12-23 10:35:53 +00:00
Make parser package private
Now that this is imported from the top level, make it private.
This commit is contained in:
parent
1190dc8a2f
commit
3fb60b9706
33 changed files with 71 additions and 68 deletions
48
libcst/_parser/_python_parser.py
Normal file
48
libcst/_parser/_python_parser.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
from typing import Any, Iterable, Mapping, Sequence
|
||||
|
||||
from parso.pgen2.generator import Grammar
|
||||
from parso.python.token import TokenType
|
||||
|
||||
from libcst._parser._base_parser import BaseParser
|
||||
from libcst._parser._grammar import (
|
||||
get_nonterminal_conversions,
|
||||
get_terminal_conversions,
|
||||
)
|
||||
from libcst._parser._types.config import ParserConfig
|
||||
from libcst._parser._types.conversions import NonterminalConversion, TerminalConversion
|
||||
from libcst._parser._types.token import Token
|
||||
|
||||
|
||||
class PythonCSTParser(BaseParser[Token, TokenType, Any]):
|
||||
config: ParserConfig
|
||||
terminal_conversions: Mapping[str, TerminalConversion]
|
||||
nonterminal_conversions: Mapping[str, NonterminalConversion]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
tokens: Iterable[Token],
|
||||
config: ParserConfig,
|
||||
pgen_grammar: "Grammar[TokenType]",
|
||||
start_nonterminal: str = "file_input",
|
||||
) -> None:
|
||||
super().__init__(
|
||||
tokens=tokens,
|
||||
lines=config.lines,
|
||||
pgen_grammar=pgen_grammar,
|
||||
start_nonterminal=start_nonterminal,
|
||||
)
|
||||
self.config = config
|
||||
self.terminal_conversions = get_terminal_conversions()
|
||||
self.nonterminal_conversions = get_nonterminal_conversions()
|
||||
|
||||
def convert_nonterminal(self, nonterminal: str, children: Sequence[Any]) -> Any:
|
||||
return self.nonterminal_conversions[nonterminal](self.config, children)
|
||||
|
||||
def convert_terminal(self, token: Token) -> Any:
|
||||
return self.terminal_conversions[token.type.name](self.config, token)
|
||||
Loading…
Add table
Add a link
Reference in a new issue