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

Access internal data of TokenVec #310

Closed
dalance opened this issue Mar 20, 2024 · 3 comments · Fixed by #311
Closed

Access internal data of TokenVec #310

dalance opened this issue Mar 20, 2024 · 3 comments · Fixed by #311
Assignees

Comments

@dalance
Copy link

dalance commented Mar 20, 2024

I want to handle expected_tokens of SyntaxError like below, but I can't access internal Vec of TokenVec.
Could you add any API to access the internal Vec?

match error.expected_tokens[0] {
    "TokenA" => "some kind of special message",
    ....
}
@jsinger67
Copy link
Owner

Sure, I will have a look at it soon.

@jsinger67 jsinger67 self-assigned this Mar 20, 2024
jsinger67 added a commit that referenced this issue Mar 20, 2024
@jsinger67
Copy link
Owner

Hi @dalance ,
I extended the implementation on TokenVec. It now provides a get method and an iter method.

/// A vector of tokens in a string representation
#[derive(Debug, Default)]
pub struct TokenVec(Vec<String>);

impl TokenVec {
    /// Pushes a token to the vector
    pub fn push(&mut self, token: String) {
        self.0.push(token);
    }

    /// Returns an iterator over the tokens
    pub fn iter(&self) -> std::slice::Iter<String> {
        self.0.iter()
    }

    /// Returns a token at the given index
    pub fn get(&self, index: usize) -> Option<&String> {
        self.0.get(index)
    }
}

The changes are on branch jsinger67/issue310 for now.
If you think that these changes are sufficient, I could prepare a new release of parol_runtime.

Br,
Jörg

@dalance
Copy link
Author

dalance commented Mar 21, 2024

Thanks! Looks good.

jsinger67 added a commit that referenced this issue Mar 21, 2024
Fixed issue [#310 Access internal data of TokenVec](#310)
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

Successfully merging a pull request may close this issue.

2 participants