-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add repeat-until last element check #183
Add repeat-until last element check #183
Conversation
shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala
Outdated
Show resolved
Hide resolved
I just realized that it isn't enough to just initialize the repeat-until: _io.eof or _.block_type == block_type::end_of_file
repeat-until: _io.pos == _io.size - 8
repeat-until: _io.pos + _.size > header.size.value or _.is_invalid
repeat-until: _.type == "IEND" or _io.eof Accessing methods of the So we need to mock the This means that we can't just let _write() to immediately call When I think about the consequences of trying to manage checking such an Of course, we could give up |
Why do you only check the last element? (For performance, of course.) |
I reuse ConsistencyError for throwing if the last element of array doesn't satisfy repeat-until condition, but I'm not sure what should be present in the error message. Maybe it should throw a special type of Exception deriving from ConsistencyError, but I don't know.
c29835c
to
72ca925
Compare
Yes, thanks for pointing it out. I'll follow with that after I merge this PR. |
I need to access
typeProvider
property of LanguageCompiler from trait GenericChecks, so I made it public withval
.I reuse ConsistencyError for throwing if the last element of array doesn't satisfy repeat-until condition, but I'm not sure what should be present in the error message. Maybe it should throw a special type of Exception deriving from ConsistencyError, but I don't know.
I also add methods
blockScopeHeader
andblockScopeFooter
, because in case there are multiple seq fields with repeat-until, I need to redeclare_it
variable, every time with a different type. Java doesn't allow redeclaring variables in the same scope, so I wrap each check in its own.For example, these are the generated repeat-until checks in the test format repeat_until_complex: