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

Python, Construct: add missing imports of KaitaiStream #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ class PythonTranslator(provider: TypeProvider, importList: ImportList, config: R
}
s"${PythonCompiler.types2class(enumSpec.name, isExternal)}.$label"
}
override def doEnumById(enumSpec: EnumSpec, id: String): String =
override def doEnumById(enumSpec: EnumSpec, id: String): String = {
importList.add(s"from kaitaistruct import ${PythonCompiler.kstreamName}")

s"${PythonCompiler.kstreamName}.resolve_enum(${PythonCompiler.types2class(enumSpec.name, enumSpec.isExternal(provider.nowClass))}, $id)"
}

override def booleanOp(op: Ast.boolop) = op match {
case Ast.boolop.Or => "or"
Expand Down Expand Up @@ -103,16 +106,25 @@ class PythonTranslator(provider: TypeProvider, importList: ImportList, config: R

override def bytesLength(value: Ast.expr): String =
s"len(${translate(value)})"
override def bytesSubscript(container: Ast.expr, idx: Ast.expr): String =
override def bytesSubscript(container: Ast.expr, idx: Ast.expr): String = {
importList.add(s"from kaitaistruct import ${PythonCompiler.kstreamName}")

s"${PythonCompiler.kstreamName}.byte_array_index(${translate(container)}, ${translate(idx)})"
}
override def bytesFirst(a: Ast.expr): String =
bytesSubscript(a, Ast.expr.IntNum(0))
override def bytesLast(a: Ast.expr): String =
bytesSubscript(a, Ast.expr.IntNum(-1))
override def bytesMin(b: Ast.expr): String =
override def bytesMin(b: Ast.expr): String = {
importList.add(s"from kaitaistruct import ${PythonCompiler.kstreamName}")

s"${PythonCompiler.kstreamName}.byte_array_min(${translate(b)})"
override def bytesMax(b: Ast.expr): String =
}
override def bytesMax(b: Ast.expr): String = {
importList.add(s"from kaitaistruct import ${PythonCompiler.kstreamName}")

s"${PythonCompiler.kstreamName}.byte_array_max(${translate(b)})"
}


override def strLength(value: Ast.expr): String =
Expand Down
Loading