2
26
Fork
You've already forked hevi
1

Add --parser arg #21

Merged
Reokodoku merged 7 commits from parser-option into master 2024年05月12日 11:35:01 +02:00
Reokodoku commented 2024年05月10日 23:08:50 +02:00 (Migrated from github.com)
Copy link

This commit adds --parser argument to specify which parser to use to read the file.

(削除) This is only an arg. There isn't any field in the config file to set a specific parser. (削除ここまで)

This commit adds `--parser` argument to specify which parser to use to read the file. ~This is only an arg. There isn't any field in the config file to set a specific parser.~
Arnau478 (Migrated from github.com) requested changes 2024年05月11日 23:05:26 +02:00
@ -35,0 +49,4 @@
list[pos]=split.next().?;
pos+=1;
}
break:vlist;
Arnau478 (Migrated from github.com) commented 2024年05月11日 16:35:17 +02:00
Copy link

The parser list should be comptime-generated

The parser list should be comptime-generated
@ -67,22 +88,32 @@ pub fn getOptions(args: argparse.ParseResult, stdout: std.fs.File) !DisplayOptio
for(root.ast.fields)|field|{
Arnau478 (Migrated from github.com) commented 2024年05月11日 16:44:22 +02:00
Copy link

Maybe it's just me, but I try to avoid OOM panics. I think panics should only be used in two scenarios:

  • Internal program crashes that shouldn't be possible in theory
  • When not in main's stack frame (rare), e.g. interrupt or syscall handler of some kind, code jumped to...

Running out of memory is definitely a state external to the program and should be handled gracefully.

Maybe it's just me, but I try to avoid OOM panics. I think panics should only be used in two scenarios: - Internal program crashes that shouldn't be possible in theory - When not in main's stack frame (rare), e.g. interrupt or syscall handler of some kind, code jumped to... Running out of memory is definitely a state external to the program and should be handled gracefully.
@ -1,19 +1,32 @@
conststd=@import("std");
Arnau478 (Migrated from github.com) commented 2024年05月11日 16:53:22 +02:00
Copy link

We should still run matches() and print an error if it's not an appropriate file when a parser is explicitly specified. Otherwise, garbage will be printed.

We should still run matches() and print an error if it's not an appropriate file when a parser is explicitly specified. Otherwise, garbage will be printed.
Arnau478 (Migrated from github.com) requested changes 2024年05月12日 10:02:06 +02:00
Arnau478 (Migrated from github.com) commented 2024年05月12日 10:01:58 +02:00
Copy link

This will panic. Could you add an else statement that prints an error?

This will panic. Could you add an else statement that prints an error?
Reokodoku (Migrated from github.com) reviewed 2024年05月12日 10:36:47 +02:00
Reokodoku (Migrated from github.com) commented 2024年05月12日 10:36:47 +02:00
Copy link

Is something like this okay? Maybe we can print it in red (if color support is enabled).

diff --git a/src/parser.zig b/src/parser.zig
index da609ba..b41498c 100644
--- a/src/parser.zig
+++ b/src/parser.zig
@@ -21,6 +21,9 @@ pub fn getColors(allocator: std.mem.Allocator, reader: std.io.AnyReader, options
 if (parser.matches(data)) {
 parser.getColors(colors, data);
 return colors;
+ } else {
+ std.debug.print("The specified parser doesn't match the file format!\n", .{});
+ std.process.exit(1);
 }
 }
 } else if (parser.matches(data)) {
Is something like this okay? Maybe we can print it in red (if color support is enabled). ```patch diff --git a/src/parser.zig b/src/parser.zig index da609ba..b41498c 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -21,6 +21,9 @@ pub fn getColors(allocator: std.mem.Allocator, reader: std.io.AnyReader, options if (parser.matches(data)) { parser.getColors(colors, data); return colors; + } else { + std.debug.print("The specified parser doesn't match the file format!\n", .{}); + std.process.exit(1); } } } else if (parser.matches(data)) { ```
Arnau478 (Migrated from github.com) reviewed 2024年05月12日 10:42:32 +02:00
Arnau478 (Migrated from github.com) commented 2024年05月12日 10:42:32 +02:00
Copy link

Yeah, just do that basic print. Maybe wirh an "Error:" prefix. I wanted to unify error reporting, but haven't done so yet. When I do I'll update it :)

Yeah, just do that basic print. Maybe wirh an "Error:" prefix. I wanted to unify error reporting, but haven't done so yet. When I do I'll update it :)
Arnau478 (Migrated from github.com) approved these changes 2024年05月12日 11:34:29 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
arnauc/hevi!21
Reference in a new issue
arnauc/hevi
No description provided.
Delete branch "parser-option"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?