Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create universal parser #143

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Create universal parser #143

wants to merge 33 commits into from

Conversation

istride
Copy link
Contributor

@istride istride commented Sep 17, 2024

Introduces a "universal" parser that is intended to convert between spreadsheets and JSON and be useful as a basis for any application-specific purpose (e.g. ParentText/ChatbotBuilder, AppBuilder).

A concerted effort has been made to preserve the existing conversion behaviour of the current ParentText-specific parser, for backwards-compatibility. A major exception has been made for templates, which are no longer interpreted during the conversion, just copied verbatim. An overview of the conversion behaviour can be found in docs/notation.md.

The universal parser does not use Pydantic models during conversion. Instead, the parser opportunistically converts strings to the JSON types. For example, if a string can be converted to a number it will be; if not the parser will fall back to different conversion methods until one works, or none of them work and the string is just passed through. A method for directing the conversion process is considered out of scope.

Metadata is stored within the JSON, in a top-level property with key _idems, to direct the conversion back to sheets. Currently, only the original table headers are stored as metadata, to preserve their order and layout.

Two CLI sub-commands have been added:

  • sheets-to-uni: converts a spreadsheet to nested ("universal") JSON
  • uni-to-sheets: reverse operation back to spreadsheet; currently limited to ODS output

Examples:

rpft sheets-to-uni 1hcH8pFdiHZN0UvZgyv3Zht9ARBTx-VXhNBI2o8L7fHU T_content.json
rpft uni-to-sheets T_content.json T_content.ods

Supporting other output formats is considered out of scope for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant