-
Notifications
You must be signed in to change notification settings - Fork 136
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
Update classfile.ts for better parser #260
base: master
Are you sure you want to change the base?
Conversation
This is a more complete parser, that I tested that parse class files more completely.
Hi, thanks for extending the example. Can you fix the formatting errors?
Should automatically fix them. |
I'll do it in a bit, I wrote it in javascript though, I'll attempt to translate it to typescript if it is a better example. |
The updated code does not compile with the following errors:
|
@keichi Thanks a lot for the feedback, I did some changes (changed everything to const, fixed comments, fixed the ts errors), and tested with the following commands:
I get no warnings and works. But maybe I am running it wrong? |
ElementValue = ElementValue.choice("value", { | ||
tag: "tag", | ||
choices: { | ||
66: Parser.start().uint16be("const_value_index"), // byte ('B') | ||
67: Parser.start().uint16be("const_value_index"), // char ('C') | ||
68: Parser.start().uint16be("const_value_index"), // double ('D') | ||
70: Parser.start().uint16be("const_value_index"), // float ('F') | ||
73: Parser.start().uint16be("const_value_index"), // int ('I') | ||
74: Parser.start().uint16be("const_value_index"), // long ('J') | ||
83: Parser.start().uint16be("const_value_index"), // short ('S') | ||
90: Parser.start().uint16be("const_value_index"), // boolean ('Z') | ||
115: Parser.start().uint16be("const_value_index"), // String ('s') | ||
101: Parser.start() | ||
.uint16be("type_name_index") | ||
.uint16be("const_name_index"), // enum constant ('e') | ||
99: Parser.start().uint16be("class_info_index"), // class ('c') | ||
64: Parser.start().nest("annotation_value", { type: "annotation" }), // annotation ('@') | ||
91: Parser.start() // array ('[') | ||
.uint16be("num_values") | ||
.array("values", { type: "elementvalue", length: "num_values" }), | ||
}, | ||
}); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
CodeAttribute = CodeAttribute.useContextVars() | ||
.uint16be("max_stack") | ||
.uint16be("max_locals") | ||
.uint32be("code_length") | ||
.nest("code", { | ||
type: BytecodeParser, | ||
}) | ||
.uint16be("exception_table_length") | ||
.array("exception_table", { | ||
type: Parser.start() | ||
.uint16be("start_pc") | ||
.uint16be("end_pc") | ||
.uint16be("handler_pc") | ||
.uint16be("catch_type"), | ||
length: "exception_table_length", | ||
}) | ||
.uint16be("attributes_count") | ||
.array("attributes", { | ||
type: "attribute_info", | ||
length: "attributes_count", | ||
}); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About these two warnings, I used let instead of const, because parser is a bit recursive, and I needed to define the "head" first otherwise it wouldn't let me use it. Something like, parser is not defined yet, maybe you know better.
This is a more complete parser, that I tested that parse class files more completely.