A real parser (lalrpop)

This commit is contained in:
Yehuda Katz
2019-05-25 23:54:41 -07:00
parent cd92f579c9
commit b74daa2e60
24 changed files with 2599 additions and 216 deletions

View File

@ -1,9 +1,13 @@
use crate::prelude::*;
use derive_new::new;
use rustyline::completion::Completer;
use rustyline::completion::{self, FilenameCompleter};
use rustyline::line_buffer::LineBuffer;
#[derive(new)]
crate struct NuCompleter {
pub file_completer: FilenameCompleter,
pub commands: indexmap::IndexMap<String, Arc<dyn Command>>,
}
impl Completer for NuCompleter {
@ -15,10 +19,7 @@ impl Completer for NuCompleter {
pos: usize,
context: &rustyline::Context,
) -> rustyline::Result<(usize, Vec<completion::Pair>)> {
let commands = [
"ps", "ls", "cd", "view", "skip", "take", "select", "reject", "to-array", "where",
"sort-by",
];
let commands: Vec<String> = self.commands.keys().cloned().collect();
let mut completions = self.file_completer.complete(line, pos, context)?.1;

View File

@ -1,5 +1,6 @@
use crate::shell::completer::NuCompleter;
use crate::prelude::*;
use rustyline::completion::{self, Completer, FilenameCompleter};
use rustyline::error::ReadlineError;
use rustyline::highlight::{Highlighter, MatchingBracketHighlighter};
@ -13,10 +14,11 @@ crate struct Helper {
}
impl Helper {
crate fn new() -> Helper {
crate fn new(commands: indexmap::IndexMap<String, Arc<dyn Command>>) -> Helper {
Helper {
completer: NuCompleter {
file_completer: FilenameCompleter::new(),
commands,
},
highlighter: MatchingBracketHighlighter::new(),
hinter: HistoryHinter {},