-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add s-expression parser to lib/util #381
Conversation
lib/util/Sexpr.v3
Outdated
case EmptySexp; | ||
} | ||
|
||
class SexpParser extends TextReader { |
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.
Because this is a parser that might be fed very large files, having position information for errors is really useful. Given that I think it makes sense that this parser take either an error generator object or has a mutable field for a callback on errors, that includes location information.
Then the parser can return a default value for the ADT (atom of an empty string) if it fails.
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.
Does it make sense to just exploit the underlying TextReader's error fields?
def readAtom() -> SExpr {
skipWhitespace();
def atom_end = star_rel(1, atomChar);
if (atom_end == -1) {
fail("Expected atom");
return SExpr.Atom("");
}
def tok = readToken(atom_end - pos);
skipWhitespace();
return SExpr.Atom(tok.image);
}
lib/util/Sexpr.v3
Outdated
@@ -0,0 +1,75 @@ | |||
type Sexp { | |||
case Atom(data: string); | |||
case List(elts: Range<Sexp>); // usually Cons |
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.
How about a list for the elements? Also, I think I'd prefer elems
or elements
as the field name.
lib/util/Sexpr.v3
Outdated
@@ -0,0 +1,75 @@ | |||
type Sexp { |
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.
Maybe SExpr
as a name?
I don't remember if you thought this should be added to util, but: