-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One can now define bitfield "constants" for parsing by providing integer expressions with fields: type Foo = unit { x: bitfield(8) { a: 0..3 = 2; b: 4..7; c: 7 = 1; }; This will first parse the bitfield as usual and then enforce that the two bit ranges that are coming with expressions (i.e., `a` and `c`) indeed containing the expected values. If they don't, that's a parse error. We also support using such bitfield constants for look-ahead parsing: type Foo = unit { x: uint8[]; y: bitfield(8) { a: 0..3 = 4; b: 4..7; }; }; This will parse uint8s until a value is discovered that has its bits set as defined by the bitfield constant. (We use the term "constant" loosely here: only the bits with values are actually enforced to be constant, all others are parsed as usual.) TODO: - Test use for synchronization. - Add documentation. Closes #1467.
- Loading branch information
Showing
10 changed files
with
130 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. | ||
[$x=[1, 2, 3], $y=(4, 8), $z=5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. | ||
(2, 8, 1) | ||
[error] terminating with uncaught exception of type spicy::rt::ParseError: unexpected value for bitfield element 'a' (<...>/ctor.spicy:10:6-14:4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. | ||
[error] <...>/width-fail.spicy:9:8-12:6: upper limit is beyond the width of the bitfield | ||
[error] <...>/width-fail.spicy:9:8-12:6: lower limit needs to be lower than upper limit | ||
[error] <...>/width-fail.spicy:10:9: upper limit is beyond the width of the bitfield | ||
[error] <...>/width-fail.spicy:11:9: lower limit needs to be lower than upper limit | ||
[error] spicyc: aborting after errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @TEST-EXEC: printf '\001\002\003\204\005' | spicy-driver %INPUT >>output | ||
# @TEST-EXEC: btest-diff output | ||
# | ||
# @TEST-DOC: Check look-ahead vector parsing with bitfield constant as terminator. | ||
|
||
module Test; | ||
|
||
public type Foo = unit { | ||
x: uint8[]; | ||
y: bitfield(8) { | ||
a: 0..3 = 4; | ||
b: 4..7; | ||
}; | ||
z: uint8; | ||
|
||
on %done { print self; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @TEST-EXEC: printf '\x82' | spicy-driver %INPUT >>output 2>&1 | ||
# @TEST-EXEC-FAIL: printf '\200' | spicy-driver %INPUT >>output 2>&1 | ||
# @TEST-EXEC: btest-diff output | ||
# | ||
# @TEST-DOC: Check bitfield constant parsing. | ||
|
||
module Test; | ||
|
||
public type Foo = unit { | ||
x: bitfield(8) { | ||
a: 0..3 = 2; | ||
b: 4..7; | ||
c: 7 = 1; | ||
}; | ||
|
||
on %done { print self.x; } | ||
}; |