-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,243 @@ | |||
type JsonValue { | |||
case String(v: string); | |||
case Number(v: int); // TODO: float |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
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!