langs

various algorithms//utils for modifying bytes

ptcx.utils.langs.get_parser(lang)View on GitHub

tree_sitter.Parser based on lang

Parameters:

lang (str )

Return type:

Parser

ptcx.utils.langs.guess(path, content=None)View on GitHub

guesses the sourcetypes language based on the path and optionally file content

Parameters:
Return type:

str

ptcx.utils.langs.search_and_insert(text, pattern, insert_func)View on GitHub

finds match & replaces inserts string at first group in pattern.

Parameters:
  • text (bytes ) – text to insert into

  • patter – pattern including group to match

  • insert_func (Callable [[bytes ], Union [str , bytes ]]) – function with signature def insert(_content:bytes) -> str: to which the matched section is passed

  • pattern (Union [str , bytes ])

Return type:

bytes

ptcx.utils.langs.array_add(matched_text, to_add)View on GitHub

extend array inside string. Accepts json5, returns json (with indent_2 and newlines)

Parameters:
Return type:

bytes