forked from extern/nushell
improve subcommand parse
This commit is contained in:
parent
92f72b4103
commit
4deed7c836
@ -7,8 +7,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
let mut parser_state = Arc::new(ParserState::new());
|
let mut parser_state = Arc::new(ParserState::new());
|
||||||
let mut working_set = ParserWorkingSet::new(Some(parser_state.clone()));
|
let mut working_set = ParserWorkingSet::new(Some(parser_state.clone()));
|
||||||
|
|
||||||
// let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
||||||
// working_set.add_decl(sig.into());
|
working_set.add_decl(sig.into());
|
||||||
|
|
||||||
// let sig = Signature::build("bar")
|
// let sig = Signature::build("bar")
|
||||||
// .named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'))
|
// .named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'))
|
||||||
|
@ -643,17 +643,16 @@ impl ParserWorkingSet {
|
|||||||
// assume spans.len() > 0?
|
// assume spans.len() > 0?
|
||||||
let name = self.get_span_contents(spans[0]);
|
let name = self.get_span_contents(spans[0]);
|
||||||
|
|
||||||
if self.contains_decl_partial_match(name) {
|
if let Some(mut decl_id) = self.find_decl(name) {
|
||||||
// potentially subcommand
|
|
||||||
let mut name = name.to_vec();
|
let mut name = name.to_vec();
|
||||||
let mut pos = 1;
|
let mut pos = 1;
|
||||||
let mut decl_id = None;
|
|
||||||
while pos < spans.len() {
|
while pos < spans.len() {
|
||||||
|
// look to see if it's a subcommand
|
||||||
let mut new_name = name.to_vec();
|
let mut new_name = name.to_vec();
|
||||||
new_name.push(b' ');
|
new_name.push(b' ');
|
||||||
new_name.extend(self.get_span_contents(spans[pos]));
|
new_name.extend(self.get_span_contents(spans[pos]));
|
||||||
if let Some(did) = self.find_decl(&new_name) {
|
if let Some(did) = self.find_decl(&new_name) {
|
||||||
decl_id = Some(did);
|
decl_id = did;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -661,7 +660,6 @@ impl ParserWorkingSet {
|
|||||||
pos += 1;
|
pos += 1;
|
||||||
}
|
}
|
||||||
// parse internal command
|
// parse internal command
|
||||||
if let Some(decl_id) = decl_id {
|
|
||||||
let (call, span, err) = self.parse_internal_call(&spans[(pos - 1)..], decl_id);
|
let (call, span, err) = self.parse_internal_call(&spans[(pos - 1)..], decl_id);
|
||||||
(
|
(
|
||||||
Expression {
|
Expression {
|
||||||
@ -673,9 +671,6 @@ impl ParserWorkingSet {
|
|||||||
} else {
|
} else {
|
||||||
self.parse_external_call(spans)
|
self.parse_external_call(spans)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.parse_external_call(spans)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_int(&mut self, token: &str, span: Span) -> (Expression, Option<ParseError>) {
|
pub fn parse_int(&mut self, token: &str, span: Span) -> (Expression, Option<ParseError>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user