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 IonElement with annotation & meta from String #10

Open
Zhouenze opened this issue Jun 4, 2020 · 1 comment
Open

Create IonElement with annotation & meta from String #10

Zhouenze opened this issue Jun 4, 2020 · 1 comment

Comments

@Zhouenze
Copy link

Zhouenze commented Jun 4, 2020

Currently IonElement doesn't support creation from String that contain annotation & meta, it has to be created like this:

ionSexpOf(
  ionSymbolOf("sexp"),
  ionSexpOf(
    ionSymbolOf("data").withAnnotation(...).withMeta(...)))

Instead of above, something like this would be much simpler:
parseFromString("(sexp (annotation::data meta={line:1,column:23}))")

This ability is present for IonValue, it would be great if we could have the same for IonElement.

Thanks!

@popematt
Copy link
Contributor

It seems like there are two issues here. The first is that you would like a way to get an IonElement tree from a string, and the second is that you want to be able to serialize/deserialize the "metas".

Creating an IonElement tree from a string

This is already possible using the loadSingleElement function, found here. For example:

loadSingleElement("(sexp (annotation::data))")

This is the equivalent to calling IonSystem::singleValue(...) using ion-java to get an IonValue.

Deserializing Metas

The "metas" are not actually part of the Ion data format, and there is no support for metas in IonValue. To get the location metadata for IonElement, you can do this:

import com.amazon.ionelement.util.INCLUDE_LOCATION_META

// ...

loadSingleElement("(sexp (annotation::data))", INCLUDE_LOCATION_META)

That will include the actual location in the metas, so the symbol data will have metas with a location of line:1,column:8 (because the annotation:: starts at column 8).

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

No branches or pull requests

2 participants