Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature: cmdline parser #10

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ whoami = "1.2.0" # Utils for fetching user data
rustyline = "9.0.0" # Read user input
tracing = "0.1.29" #
tracing-appender = "0.2.0" # Logging
peg = "0.7.0" # Parsing

[dependencies.mlua] # Lua interpreter
version = "0.6.6" #
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod core;
pub mod log; // TODO: rename this module
pub mod parser;
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! NeoSH command parser

pub mod structure;
52 changes: 52 additions & 0 deletions src/parser/structure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// Command is what user sends. Consists of [CommandUnit]
pub struct Command(Vec<CommandUnit>);

// TODO: Operator as an enum
/// Part of a [Command]. Can be either an [Instruction] or an Operator
pub enum CommandUnit {
Instruction(Instruction),
Operator(String),
}

/// Instruction is a something that is called with [InstructionUnit]
pub struct Instruction {
callable: String,
children: Vec<InstructionUnit>,
}

/// Either an argument or a [Flag]
pub enum InstructionUnit {
Arg(String),
Flag(Flag),
}

/// Flag parameters
///
/// name - what comes after `--` or `-`
/// value - what we pass to the flag
/// length - see [FlagLength]
/// storage - see [FlagStorage]
pub struct Flag {
name: String,
value: Option<String>,
length: FlagLength,
storage: FlagStorage,
}

/// Flag length type
///
/// Short - `-`
/// Long - `--`
pub enum FlagLength {
Short,
Long,
}

/// How flag storages it's value
// Inner - --a=b
// Outer - --a b
pub enum FlagStorage {
Inner,
Outer,
}