-
Notifications
You must be signed in to change notification settings - Fork 60
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
Extension for handling Yojson data with code positions #63
base: master
Are you sure you want to change the base?
Conversation
fix how to get position of string/stringlit
Hi! Thanks for looking into this. It seems that keeping track of locations would be useful to people who use yojson directly i.e. not from atdgen and don't have strict performance requirements. I imagine this fits the scenarios where json is used as a simple config file. Note that there's a bit of tension between achieving the best performance when working with large amounts of machine-generated json data and with human-written json which benefits from better error reporting. A thing I never particularly like about yojson is that we have already 3 modules to pick from ( Other than that, my concern is about the performance loss introduced by creating and discarding location objects. Did you run performance benchmarks? I haven't done that recently, but based on results I got in the past, it would be significantly faster (10% or more) to call |
This PR proposes an extension that enables us to handle Yojson data equipped with code positions the data come from. It adds
Yojson.SafePos
andYojson.position
for code positions,and thereby maintains backward compatibility with the latest version (i.e.
yojson
1.4.1). It probably be useful in situations like the following: where one expects the value corresponding to a certain name (such as"title"
) in objects to be a specific kind of data (such as string) but some data in a given (possibly handwritten) Yojson do not meet the expectation. In such case, one can report the code position where the unexpected data occur by usingYojson.SafePos
in order to ask for correction in an easy-to-understand manner.For an example of usage, see
examples/filtering_pos.ml
(which can be run by invoking the updatedrun-examples.sh
).