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

command alias parsing breaks parse_or_exit #41

Open
nerditation opened this issue Apr 25, 2024 · 0 comments
Open

command alias parsing breaks parse_or_exit #41

nerditation opened this issue Apr 25, 2024 · 0 comments

Comments

@nerditation
Copy link

nerditation commented Apr 25, 2024

I have some utility using parse_or_exit for quick prototyping. after updating from 0.3.1 to 0.3.2, the macro fails to parse.

for example, the code and error message:

// error: invalid flags syntax, expected one of `optional`, `required`, `repeated`, got Some(Punct { ch: ':', spacing: Alone, span: #0 bytes(598..599) })
let flags = parse_or_exit! {
    required --name name: String
};

// this compiles, but the generated `Flags` type is empty:
let flags = parse_or_exit! {
    required --name
};

after some digging, I think it is due to all the Ident tokens (required, --name and name in the above example) are parsed and consumed as aliases by line 85:

fn cmd_impl(p: &mut Parser, anon: bool) -> Result<ast::Cmd> {
let name = if anon {
String::new()
} else {
p.expect_keyword("cmd")?;
cmd_name(p)?
};
let aliases = alias_names(p);

I made a local patch to put the alias parsing under the anon conditional guard, and it seems to have fixed the issue, as least for my simple use case:

	let (name, aliases) = if anon {
		(String::new(), vec![])
	} else {
		p.expect_keyword("cmd")?;
		(cmd_name(p)?, alias_names(p))
	};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant