mirror of
https://github.com/Noratrieb/brash.git
synced 2026-01-14 21:55:02 +01:00
bash AST
This commit is contained in:
parent
36c7274ab0
commit
18b5d0b158
1 changed files with 90 additions and 0 deletions
90
src/parse.rs
90
src/parse.rs
|
|
@ -10,6 +10,96 @@ pub fn parse(filename: Arc<str>, src: &str) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Simplified conceptually:
|
||||||
|
COMMAND = PIPELINE
|
||||||
|
PIPELINE = LIST { "|" LIST }
|
||||||
|
LIST = COMPOUND { "&&" COMPOUND }
|
||||||
|
COMPOUND = ???
|
||||||
|
SIMPLECOMMAND = word { word }
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub struct SimpleCommand<'a> {
|
||||||
|
pub tokens: Vec<Token<'a>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum CompoundCommand<'a> {
|
||||||
|
Simple(SimpleCommand<'a>),
|
||||||
|
Until {
|
||||||
|
test: Command<'a>,
|
||||||
|
do_: Vec<Command<'a>>,
|
||||||
|
},
|
||||||
|
While {
|
||||||
|
test: Command<'a>,
|
||||||
|
do_: Vec<Command<'a>>,
|
||||||
|
},
|
||||||
|
For {
|
||||||
|
name: Token<'a>,
|
||||||
|
words: Vec<Token<'a>>,
|
||||||
|
do_: Vec<Command<'a>>,
|
||||||
|
},
|
||||||
|
ForArith,
|
||||||
|
If {
|
||||||
|
test: Command<'a>,
|
||||||
|
then: Vec<Command<'a>>,
|
||||||
|
elif: Vec<(Command<'a>, Vec<Command<'a>>)>,
|
||||||
|
else_: Vec<Command<'a>>,
|
||||||
|
},
|
||||||
|
Case,
|
||||||
|
Select,
|
||||||
|
/// `(( ))`
|
||||||
|
Arith,
|
||||||
|
/// `[[ ]]`
|
||||||
|
CondExpr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CommandList<'a> {
|
||||||
|
pub initial: SimpleCommand<'a>,
|
||||||
|
pub rest: Vec<(ListKind, SimpleCommand<'a>)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Pipeline<'a> {
|
||||||
|
pub time: bool,
|
||||||
|
/// !!!!
|
||||||
|
pub exclamation: bool,
|
||||||
|
pub initial: CommandList<'a>,
|
||||||
|
pub rest: Vec<(PipelineKind, CommandList<'a>)>,
|
||||||
|
pub terminator: Option<ListTerminator>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Command<'a> {
|
||||||
|
Single(Pipeline<'a>),
|
||||||
|
/// `()`
|
||||||
|
Subshell(Vec<Command<'a>>),
|
||||||
|
/// `{}`
|
||||||
|
Block(Vec<Command<'a>>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ListKind {
|
||||||
|
/// `;`
|
||||||
|
Chain,
|
||||||
|
/// `&``
|
||||||
|
Async,
|
||||||
|
/// `&&`
|
||||||
|
And,
|
||||||
|
/// `||`
|
||||||
|
Or,
|
||||||
|
Newline,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ListTerminator {
|
||||||
|
Chain,
|
||||||
|
Async,
|
||||||
|
Newline,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum PipelineKind {
|
||||||
|
/// `|`
|
||||||
|
Simple,
|
||||||
|
/// `|&`
|
||||||
|
All,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Span {
|
pub struct Span {
|
||||||
pub filename: Arc<str>,
|
pub filename: Arc<str>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue