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

Using a regex parsed bytes value in &requires #1846

Closed
sethhall opened this issue Aug 28, 2024 · 2 comments · Fixed by #1878
Closed

Using a regex parsed bytes value in &requires #1846

sethhall opened this issue Aug 28, 2024 · 2 comments · Fixed by #1878
Assignees
Labels
Bug Something isn't working

Comments

@sethhall
Copy link
Member

I'm not sure if the title accurately represents what is going on here or not, but I have some examples of what works and what doesn't...

Using a regex parsed unit value to compare against regex group bytes in a &requires doesn't work...

module Test;

public type X = unit {
    b: /b/;
    x: /a(b+)c/ &requires=($1 == self.b);
};
printf 'babc' | HILTI_DEBUG=spicy spicy-driver test6.spicy
[error] terminating with uncaught exception of type hilti::rt::IndexError: vector index 1 out of range (test6.spicy:5:8-5:15)

But if the value we parse is parsed with a literal, that works fine...

module Test;

public type X = unit {
    b: b"b";
    x: /a(b+)c/ &requires=($1 == self.b);
};
printf 'babc' | HILTI_DEBUG=spicy spicy-driver test6.spicy

If we do the comparison in a field hook, it also works fine (it just seems to be broken in the &requires comparison)...

module Test;

public type X = unit {
    b: /b/;
    x: /a(b+)c/ {
        print ($1 == self.b);
    }
};
printf 'babc' | HILTI_DEBUG=spicy spicy-driver test6.spicy
True
@rsmmr rsmmr added the Bug Something isn't working label Aug 29, 2024
@rsmmr
Copy link
Member

rsmmr commented Aug 29, 2024

My initial take would be that this is a similar issue as #1842 (some parsing parsing state is available inside the hook, but not yet inside the field's attributes). However, it surprises me that it works with the literal, as that wouldn't make a difference then. Needs more investigation.

@rsmmr
Copy link
Member

rsmmr commented Sep 27, 2024

So turns out two things coming together: the main one is a bug with how we extract the data for capture groups. The second is that after regexp matching we aren't immediately trimming the data, whereas for bytes we do. The latter explains the difference for the two cases: the bug only manifests if the data isn't at the beginning of the stream.

@rsmmr rsmmr linked a pull request Sep 27, 2024 that will close this issue
@rsmmr rsmmr self-assigned this Sep 30, 2024
@rsmmr rsmmr closed this as completed in 5f14c36 Sep 30, 2024
rsmmr added a commit that referenced this issue Sep 30, 2024
* origin/topic/robin/gh-1846-regex-in-attr:
  Fix bug with captures groups.
  Add missing trim after matching a regular expression.
bbannier pushed a commit that referenced this issue Oct 1, 2024
* origin/topic/robin/gh-1846-regex-in-attr:
  Fix bug with captures groups.
  Add missing trim after matching a regular expression.

(cherry picked from commit 2b0eb03)
bbannier pushed a commit that referenced this issue Oct 1, 2024
When extracting the data matching capture groups we'd take it from the
beginning of the stream, not the beginning of the current view, even
though the latter is what we are matching against.

Closes #1846.

(cherry picked from commit 5f14c36)

# Conflicts:
#	spicy/toolchain/src/compiler/codegen/parsers/literals.cc
bbannier pushed a commit that referenced this issue Oct 2, 2024
When extracting the data matching capture groups we'd take it from the
beginning of the stream, not the beginning of the current view, even
though the latter is what we are matching against.

Closes #1846.

(cherry picked from commit 5f14c36)

# Conflicts:
#	spicy/toolchain/src/compiler/codegen/parsers/literals.cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants