Early work on tab completion
This commit is contained in:
@@ -71,7 +71,7 @@ impl<'a> Lexer<'a> {
|
||||
rule = TkRule::Ident
|
||||
|
||||
// If we are in a command right now, after this we are in arguments
|
||||
} else if self.is_command && rule != TkRule::Whitespace && !KEYWORDS.contains(&rule) {
|
||||
} else if self.is_command && !matches!(rule, TkRule::Comment | TkRule::Whitespace) && !KEYWORDS.contains(&rule) {
|
||||
self.is_command = false;
|
||||
}
|
||||
// If we see a separator like && or ;, we are now in a command again
|
||||
@@ -295,7 +295,7 @@ impl TkRule {
|
||||
}
|
||||
|
||||
tkrule_def!(Comment, |input: &str| {
|
||||
let mut chars = input.chars();
|
||||
let mut chars = input.chars().peekable();
|
||||
let mut len = 0;
|
||||
|
||||
if let Some('#') = chars.next() {
|
||||
@@ -304,6 +304,14 @@ tkrule_def!(Comment, |input: &str| {
|
||||
let chlen = ch.len_utf8();
|
||||
len += chlen;
|
||||
if ch == '\n' {
|
||||
while let Some(ch) = chars.peek() {
|
||||
if *ch == '\n' {
|
||||
len += 1;
|
||||
chars.next();
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -743,31 +751,53 @@ tkrule_def!(SQuote, |input: &str| {
|
||||
// Double quoted strings
|
||||
let mut chars = input.chars();
|
||||
let mut len = 0;
|
||||
let mut quoted = false;
|
||||
let mut quote_count = 0;
|
||||
|
||||
while let Some(ch) = chars.next() {
|
||||
match ch {
|
||||
'\\' => {
|
||||
chars.next();
|
||||
len += 2;
|
||||
len += 1;
|
||||
if let Some(ch) = chars.next() {
|
||||
let chlen = ch.len_utf8();
|
||||
len += chlen;
|
||||
}
|
||||
}
|
||||
'\'' if !quoted => {
|
||||
'\'' => {
|
||||
let chlen = ch.len_utf8();
|
||||
len += chlen;
|
||||
quoted = true;
|
||||
quote_count += 1;
|
||||
}
|
||||
'\'' if quoted => {
|
||||
' ' | '\t' | ';' | '\n' if quote_count % 2 == 0 => {
|
||||
if quote_count > 0 {
|
||||
if quote_count % 2 == 0 {
|
||||
return Some(len)
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
let chlen = ch.len_utf8();
|
||||
len += chlen;
|
||||
return Some(len)
|
||||
}
|
||||
_ if !quoted => {
|
||||
return None
|
||||
}
|
||||
_ => len += 1
|
||||
}
|
||||
}
|
||||
None
|
||||
match len {
|
||||
0 => None,
|
||||
_ => {
|
||||
if quote_count > 0 {
|
||||
if quote_count % 2 == 0 {
|
||||
return Some(len)
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tkrule_def!(DQuote, |input: &str| {
|
||||
|
||||
@@ -158,18 +158,18 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub fn parse(mut self) -> ShResult<SynTree> {
|
||||
log!(TRACE, "Starting parse");
|
||||
let mut lists = VecDeque::new();
|
||||
let mut lists = vec![];
|
||||
let token_slice = &*self.token_stream;
|
||||
// Get the Main rule
|
||||
if let Some(mut node) = Main::try_match(token_slice,self.shenv)? {
|
||||
// Extract the inner lists
|
||||
if let NdRule::Main { ref mut cmd_lists } = node.rule_mut() {
|
||||
while let Some(node) = cmd_lists.pop() {
|
||||
lists.bpush(node)
|
||||
lists.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
while let Some(node) = lists.bpop() {
|
||||
while let Some(node) = lists.pop() {
|
||||
// Push inner command lists to self.ast
|
||||
self.ast.push_node(node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user