Skip to content

Commit

Permalink
Update myn to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte committed Feb 10, 2024
1 parent c529bf4 commit 9c4b87f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion onlyargs_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ license = "MIT"
proc-macro = true

[dependencies]
myn = "0.1"
myn = "0.2"
onlyargs = { version = "0.1", path = ".." }
26 changes: 20 additions & 6 deletions onlyargs_derive/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl ArgumentStruct {
input.parse_visibility()?;
input.expect_ident("struct")?;

let name = input.as_ident()?;
let name = input.try_ident()?;
let content = input.expect_group(Delimiter::Brace)?;
let fields = Argument::parse(content)?;

Expand All @@ -82,7 +82,10 @@ impl ArgumentStruct {
}
}

let doc = get_doc_comment(&attrs);
let doc = get_doc_comment(&attrs)
.into_iter()
.map(trim_with_indent)
.collect();

match input.next() {
None => Ok(Self {
Expand All @@ -105,7 +108,10 @@ impl Argument {
let attrs = input.parse_attributes()?;

// Parse attributes
let doc = get_doc_comment(&attrs);
let doc = get_doc_comment(&attrs)
.into_iter()
.map(trim_with_indent)
.collect();
let mut default = None;
let mut long = false;
let mut short = None;
Expand All @@ -116,12 +122,12 @@ impl Argument {
"default" => {
let mut stream = attr.tree.expect_group(Delimiter::Parenthesis)?;

default = Some(stream.as_lit()?);
default = Some(stream.try_lit()?);
}
"long" => long = true,
"short" => {
let mut stream = attr.tree.expect_group(Delimiter::Parenthesis)?;
let lit = stream.as_lit()?;
let lit = stream.try_lit()?;

short = Some(lit.as_char()?);
}
Expand All @@ -130,7 +136,7 @@ impl Argument {
}

input.parse_visibility()?;
let name = input.as_ident()?;
let name = input.try_ident()?;
input.expect_punct(':')?;
let (path, span) = input.parse_path()?;
let _ = input.expect_punct(',');
Expand Down Expand Up @@ -353,3 +359,11 @@ impl ArgType {
}
}
}

#[allow(clippy::needless_pass_by_value)]
fn trim_with_indent(line: String) -> String {
line.strip_prefix(' ')
.unwrap_or(&line)
.trim_end()
.to_string()
}

0 comments on commit 9c4b87f

Please sign in to comment.