Skip to content

Commit

Permalink
add back in tests from old tabry (and fix indent on multi-line strings)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbattaglia committed Sep 6, 2024
1 parent 45d28d2 commit dada7df
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
11 changes: 9 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
TODO before "public announcement"
* fish and nix support merged
* zsh support/testing
* go through TODOs
* get remaning example tests from ruby working
* go through TODOs and do important ones
* combining the three includes (sub, arg, flag) in the JSON format would be great
---
* put on cargo
* more examples / language reference in this repo.
* bump version number and add deb
* better instructions for installing (build from source, cargo, nix, deb)

-- very soon after
* flags like -abc -> -a, -b, -c

-- soon after
* tests to 80% coverage (goal 100% eventually)
* more TODOs from code
* documentation about using the tabry gem + "completion json" for speedy tab complteion, and in tabry
* set up github automated tests
* I think I need to use bytes instead of strings for reading argv

-- much later
* actually use argument names, titles, and descriptions -- probably a'help' thing? although I'm not sure of the use without a CLI library
* CLI library? compile to clap (requires types)? not sure of the future
8 changes: 7 additions & 1 deletion src/lang/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ fn make_arg(stmt: &parser::ArgStatement, name: Option<String>) -> types::TabryAr
eprintln!("ignoring title: {:?}", title_stmt.title);
}
}
parser::Statement::Desc(_desc_stmt) => {} // TODO (not supported in types module yet)
parser::Statement::Desc(desc_stmt) => {
if arg.description.is_some() {
// TODO errors for real, dedup with cmd
panic!("multiple desc statements found");
}
arg.description = Some(desc_stmt.desc);
}
_ => unreachable!("unhandled statement in compile_arg: {:?}", stmt_in_block),
}
}
Expand Down
30 changes: 29 additions & 1 deletion src/lang/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,37 @@ fn string_internals(i: &mut &str) -> PResult<String> {
.parse_next(i)
}

/// Multi-line strings in tabry can be indented for readability:
/// arg {
/// desc "
/// Hello
/// World
/// "
/// }
/// -> resulting string is "Hello\n World"
fn unindent(s: String) -> String {
if !(s.starts_with("\n ") || s.ends_with("\n\t")) {
return s;
}

let base_indent_chars = s[1..].chars().take_while(|c| c.is_whitespace()).count();

let lines = s.trim().lines();
let trimmed_lines = lines.map(|line| {
// min of base_indent_chars and actual indent on this line
let indent_here = line
.chars()
.take(base_indent_chars)
.take_while(|c| c.is_whitespace())
.count();
&line[indent_here..]
});
trimmed_lines.collect::<Vec<&str>>().join("\n")
}

fn string<'a>(i: &mut &'a str) -> PResult<Token<'a>> {
let s = delimited("\"", string_internals, "\"").parse_next(i)?;
Ok(Token::String(s))
Ok(Token::String(unindent(s)))
}

fn identifier_str<'a>(i: &mut &'a str) -> PResult<&'a str> {
Expand Down

0 comments on commit dada7df

Please sign in to comment.