1 unstable release
0.1.0 | Nov 7, 2022 |
---|
#113 in #dsl
23KB
535 lines
DSV Seeker
A small tool to run basic queries on DSV files.
Commands
"select" ("*" | (name ("," name)*))
The select
command keeps only the desired columns.
"where" name (("=" value) | ("like" pattern))
The where
command filters rows based on string equality or pattern matching of the value in the name
d column.
"enum" name
The enum
command outputs two columns, respectively the number of appearances of a value and the value itself.
This is similar in a way to running uniq -c
in Bash.
"sort" "num"? name ("asc" | "desc")
The sort
command sorts rows based on the name
d column.
"trim" ("*" | (name ("," name)*))
The trim
command removes heading and trailing whitespace from desired columns' values.
behead
The behead
command removes the first line, that usually being the headers.
How to add a new command
Commands are organized in isolated modules as much as possible.
Steps
- Add the grammar rule to the grammar.pest file:
- Create a new rule under the other commands' rules, right above the
command
rule. - Add that rule to the end of the
command
rule.
- Create a new rule under the other commands' rules, right above the
- Add your command to the
Command
enum insrc/ast.rs
. - Handle matching from the rule to a new
Command::[your_rule]
insrc/ast.rs::build_command
. - Create your command's file in
src/operators/
and add the new module tosrc/operators/mod.rs
. - Look at other commands to figure out how to write yours.
- Add the match case for your rule in
src/ast.rs::Ast::run_on
. - Add the command to this README and to the
src/main.rs::Cli
doc comment.
Dependencies
~6–8.5MB
~140K SLoC