MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / parse

Function parse

scratchattach/editor/code_translation/parse.py:21–30  ·  view source on GitHub ↗
(script: Union[str, bytes, SupportsRead[str], Path])

Source from the content-addressed store, hash-verified

19reconstructor = Reconstructor(lang)
20
21def parse(script: Union[str, bytes, SupportsRead[str], Path]) -> Tree:
22 if isinstance(script, Path):
23 script = script.read_text()
24 if isinstance(script, SupportsRead):
25 read_data = script.read()
26 assert isinstance(read_data, str)
27 script = read_data
28 if isinstance(script, bytes):
29 script = script.decode("utf-8")
30 return lang.parse(script)
31
32def unparse(tree: Tree) -> str:
33 return reconstructor.reconstruct(tree)

Callers 1

parse.pyFile · 0.85

Calls 2

decodeMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected