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

Include source position in the AST #346

Closed
wiiznokes opened this issue Mar 2, 2024 · 5 comments
Closed

Include source position in the AST #346

wiiznokes opened this issue Mar 2, 2024 · 5 comments
Labels
crate:fluent-syntax Issues related to fluent-syntax crate enhancement

Comments

@wiiznokes
Copy link

wiiznokes commented Mar 2, 2024

I'm creating a tool to check if there is more than two identifiers with the same name. How can i know where the error is in the file?

Idk what is the standard way of doing this, i'm thinking of providing a field pos: Option<usize>, inside the ast types, but i'm not sure.

wdyt?

@zbraniecki
Copy link
Collaborator

Ugh, I understand what you're trying to achieve but the architecture is particularly not suited for that. We do not associate AST with any textual representation, and binding AST to offsets would do just that.

If you were able to achieve adding that without inducing performance, memory penalty or increasing AST maintenance complexity, I'd be open to that, but I'm concerned it won't be easy to do.

For your particular purpose, you could extend the parser to handle optional visitor/inspect callback before inserting an entry to the AST, and check if it's an ID that already has been added.
I know it's not perfect, but parser is tied to source format, resulting AST is not.

@wiiznokes
Copy link
Author

For your particular purpose, you could extend the parser to handle optional visitor/inspect callback before inserting an entry to the AST, and check if it's an ID that already has been added.

while this could work, i'm also planning to do more verification like compare two files, so having to parse multiple times is not great.

I know it doesn't really fill the maintenance constraint but would a feature gate could be considered?

@zbraniecki
Copy link
Collaborator

Sure, I'd like to just ask for a good design that minimizes the maintenance burden. I don't want to have each edit to AST/parser be slowed down by source position considerations.

Maybe a trait that can be implemented on each node and parser #[cfg(...)]node.setPositionInSource(offset) ?

@wiiznokes
Copy link
Author

But how will the offset be stored ?

I was thinking of something like #[cfg(...)] pos: usize, and then when parsing, we just need to insert the position #[cfg(...)] pos: self.ptr

To be clear, if the ast is changed, the positions will not be in sync, and the serializer will not take the offset into account.

@alerque alerque added enhancement crate:fluent-syntax Issues related to fluent-syntax crate labels May 6, 2024
@alerque alerque changed the title fr: include the text position in the ast Include source position in the AST May 6, 2024
@alerque
Copy link
Collaborator

alerque commented May 7, 2024

This seems to be a duplicate of #270.

@alerque alerque closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:fluent-syntax Issues related to fluent-syntax crate enhancement
Projects
None yet
Development

No branches or pull requests

3 participants