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

[lib] JSON format parsing & representation #292

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

linxuanm
Copy link
Contributor

This PR introduces a lib file for JSON parsing and handling. This was from my language server project, and I thought maybe it could be useful to refractor this out and have it in the stdlib.

This is a draft; I'll add tests for this tomorrow!

@@ -0,0 +1,243 @@
type JsonValue {
case String(v: string);
case Number(v: int); // TODO: float
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be double, in fact.

lib/util/Json.v3 Outdated
}

def parse_number() -> JsonValue {
var res = Ints.parseDecimal(source, pc);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do this properly, it should also support floating point numbers. The logic for that is in the NumberParser in aeneas/src/vst/. We should probably extract some of that logic into another utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the entirety of NumberParser can be moved to a util file under lib/util?

lib/util/Json.v3 Outdated
def NO_ERR = ParseError(JsonError.None, "", -1);
def ERR_RET = JsonValue.Null;

class JsonParser {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use an underlying TextReader, which will keep track of line number information.

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.

2 participants