Cleanup for upcoming release

This commit is contained in:
Jonathan Turner
2019-07-17 07:10:25 +12:00
parent 3d28b50a53
commit 2ed46046bd
29 changed files with 139 additions and 570 deletions

View File

@ -154,8 +154,6 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
command("ls", Box::new(ls::ls)),
command("sysinfo", Box::new(sysinfo::sysinfo)),
command("cd", Box::new(cd::cd)),
command("view", Box::new(view::view)),
// command("skip", skip::Skip),
command("first", Box::new(first::first)),
command("size", Box::new(size::size)),
command("from-ini", Box::new(from_ini::from_ini)),
@ -182,7 +180,6 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
Arc::new(Where),
Arc::new(Config),
Arc::new(SkipWhile),
Arc::new(Enter),
]);
context.add_sinks(vec![
@ -220,22 +217,18 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
continue;
}
let (obj, cwd) = {
let cwd = {
let env = context.env.lock().unwrap();
let last = env.back().unwrap();
(last.obj().clone(), last.path().display().to_string())
};
let readline = match obj.item {
Value::Filesystem => rl.readline(&format!(
"{}{}> ",
cwd,
match current_branch() {
Some(s) => format!("({})", s),
None => "".to_string(),
}
)),
_ => rl.readline(&format!("{}{}> ", obj.type_name(), cwd)),
env.path().display().to_string()
};
let readline = rl.readline(&format!(
"{}{}> ",
cwd,
match current_branch() {
Some(s) => format!("({})", s),
None => "".to_string(),
}
));
match process_line(readline, &mut context).await {
LineResult::Success(line) => {

View File

@ -8,7 +8,6 @@ crate mod classified;
crate mod clip;
crate mod command;
crate mod config;
crate mod enter;
crate mod exit;
crate mod first;
crate mod from_ini;
@ -37,13 +36,11 @@ crate mod to_json;
crate mod to_toml;
crate mod to_yaml;
crate mod trim;
crate mod view;
crate mod vtable;
crate mod where_;
crate use command::command;
crate use config::Config;
crate use enter::Enter;
crate use open::Open;
crate use skip_while::SkipWhile;
crate use where_::Where;

View File

@ -1,85 +1,52 @@
use crate::errors::ShellError;
use crate::prelude::*;
use std::env;
use std::path::PathBuf;
pub fn cd(args: CommandArgs) -> Result<OutputStream, ShellError> {
let env = args.env.lock().unwrap();
let latest = env.back().unwrap();
let obj = &latest.obj;
let cwd = env.path().to_path_buf();
match obj.item() {
Value::Filesystem => {
let cwd = latest.path().to_path_buf();
let path = match args.nth(0) {
None => match dirs::home_dir() {
Some(o) => o,
_ => {
return Err(ShellError::maybe_labeled_error(
"Can not change to home directory",
"can not go to home",
args.name_span,
))
}
},
Some(v) => {
let target = v.as_string()?;
match dunce::canonicalize(cwd.join(target).as_path()) {
Ok(p) => p,
Err(_) => {
return Err(ShellError::labeled_error(
"Can not change to directory",
"directory not found",
v.span.clone(),
));
}
}
}
};
let mut stream = VecDeque::new();
match env::set_current_dir(&path) {
Ok(_) => {}
let path = match args.nth(0) {
None => match dirs::home_dir() {
Some(o) => o,
_ => {
return Err(ShellError::maybe_labeled_error(
"Can not change to home directory",
"can not go to home",
args.name_span,
))
}
},
Some(v) => {
let target = v.as_string()?;
match dunce::canonicalize(cwd.join(target).as_path()) {
Ok(p) => p,
Err(_) => {
if args.len() > 0 {
return Err(ShellError::labeled_error(
"Can not change to directory",
"directory not found",
args.nth(0).unwrap().span.clone(),
));
} else {
return Err(ShellError::string("Can not change to directory"));
}
return Err(ShellError::labeled_error(
"Can not change to directory",
"directory not found",
v.span.clone(),
));
}
}
stream.push_back(ReturnSuccess::change_cwd(path));
Ok(stream.into())
}
_ => {
let mut stream = VecDeque::new();
match args.nth(0) {
None => {
stream.push_back(ReturnSuccess::change_cwd(PathBuf::from("/")));
}
Some(v) => {
let mut cwd = latest.path().to_path_buf();
let target = v.as_string()?.clone();
match target {
x if x == ".." => {
cwd.pop();
}
_ => match target.chars().nth(0) {
Some(x) if x == '/' => cwd = PathBuf::from(target),
_ => {
cwd.push(target);
}
},
}
stream.push_back(ReturnSuccess::change_cwd(cwd));
}
};
Ok(stream.into())
};
let mut stream = VecDeque::new();
match env::set_current_dir(&path) {
Ok(_) => {}
Err(_) => {
if args.len() > 0 {
return Err(ShellError::labeled_error(
"Can not change to directory",
"directory not found",
args.nth(0).unwrap().span.clone(),
));
} else {
return Err(ShellError::string("Can not change to directory"));
}
}
}
stream.push_back(ReturnSuccess::change_cwd(path));
Ok(stream.into())
}

View File

@ -6,7 +6,6 @@ use futures::stream::StreamExt;
use futures_codec::{Decoder, Encoder, Framed};
use log::{log_enabled, trace};
use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::sync::Arc;
use subprocess::Exec;
@ -145,30 +144,9 @@ impl InternalCommand {
match item? {
ReturnSuccess::Action(action) => match action {
CommandAction::ChangePath(path) => {
context.env.lock().unwrap().back_mut().map(|x| {
x.path = path;
x
});
context.env.lock().unwrap().path = path;
}
CommandAction::Enter(obj) => {
let new_env = Environment {
obj: obj,
path: PathBuf::from("/"),
};
context.env.lock().unwrap().push_back(new_env);
}
CommandAction::Exit => match context.env.lock().unwrap().pop_back() {
Some(Environment {
obj:
Spanned {
item: Value::Filesystem,
..
},
..
}) => std::process::exit(0),
None => std::process::exit(-1),
_ => {}
},
CommandAction::Exit => std::process::exit(0),
},
ReturnSuccess::Value(v) => {
@ -306,7 +284,7 @@ impl ExternalCommand {
process = Exec::shell(new_arg_string);
}
process = process.cwd(context.env.lock().unwrap().front().unwrap().path());
process = process.cwd(context.env.lock().unwrap().path());
let mut process = match stream_next {
StreamNext::Last => process,

View File

@ -13,7 +13,7 @@ use std::path::PathBuf;
#[get = "crate"]
pub struct CommandArgs {
pub host: Arc<Mutex<dyn Host + Send>>,
pub env: Arc<Mutex<VecDeque<Environment>>>,
pub env: Arc<Mutex<Environment>>,
pub name_span: Option<Span>,
pub args: Args,
pub input: InputStream,
@ -40,6 +40,7 @@ impl CommandArgs {
self.args.get(name)
}
#[allow(unused)]
pub fn has(&self, name: &str) -> bool {
self.args.has(name)
}
@ -55,7 +56,6 @@ pub struct SinkCommandArgs {
#[derive(Debug, Serialize, Deserialize)]
pub enum CommandAction {
ChangePath(PathBuf),
Enter(Spanned<Value>),
Exit,
}

View File

@ -1,105 +0,0 @@
use crate::commands::command::CommandAction;
use crate::commands::open::{fetch, parse_as_value};
use crate::errors::ShellError;
use crate::object::{Primitive, Value};
use crate::parser::registry::{CommandConfig, PositionalType};
use crate::prelude::*;
use std::path::PathBuf;
pub struct Enter;
impl Command for Enter {
fn config(&self) -> CommandConfig {
CommandConfig {
name: self.name().to_string(),
positional: vec![PositionalType::mandatory_block("path")],
rest_positional: false,
is_filter: false,
is_sink: false,
named: indexmap::IndexMap::new(),
}
}
fn name(&self) -> &str {
"enter"
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
enter(args)
}
}
pub fn enter(args: CommandArgs) -> Result<OutputStream, ShellError> {
if args.len() == 0 {
return Err(ShellError::maybe_labeled_error(
"open requires a path or url",
"missing path",
args.name_span,
));
}
let span = args.name_span;
let cwd = args
.env()
.lock()
.unwrap()
.front()
.unwrap()
.path()
.to_path_buf();
let full_path = PathBuf::from(cwd);
let (file_extension, contents, contents_span) = match &args.expect_nth(0)?.item {
Value::Primitive(Primitive::String(s)) => fetch(&full_path, s, args.expect_nth(0)?.span)?,
_ => {
return Err(ShellError::labeled_error(
"Expected string value for filename",
"expected filename",
args.expect_nth(0)?.span,
));
}
};
let mut stream = VecDeque::new();
let file_extension = if args.has("raw") {
None
} else if args.has("json") {
Some("json".to_string())
} else if args.has("xml") {
Some("xml".to_string())
} else if args.has("ini") {
Some("ini".to_string())
} else if args.has("yaml") {
Some("yaml".to_string())
} else if args.has("toml") {
Some("toml".to_string())
} else {
if let Some(ref named_args) = args.args.named {
for named in named_args.iter() {
return Err(ShellError::labeled_error(
"Unknown flag for enter",
"unknown flag",
named.1.span.clone(),
));
}
file_extension
} else {
file_extension
}
};
match contents {
Value::Primitive(Primitive::String(string)) => {
stream.push_back(Ok(ReturnSuccess::Action(CommandAction::Enter(
parse_as_value(file_extension, string, contents_span, span)?,
))));
}
other => stream.push_back(ReturnSuccess::value(other.spanned(contents_span))),
};
Ok(stream.into())
}

View File

@ -2,13 +2,11 @@ use crate::errors::ShellError;
use crate::object::{dir_entry_dict, Primitive, Value};
use crate::parser::Spanned;
use crate::prelude::*;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
pub fn ls(args: CommandArgs) -> Result<OutputStream, ShellError> {
let env = args.env.lock().unwrap();
let path = env.back().unwrap().path.to_path_buf();
let obj = &env.back().unwrap().obj;
let path = env.path.to_path_buf();
let mut full_path = PathBuf::from(path);
match &args.nth(0) {
Some(Spanned {
@ -18,126 +16,32 @@ pub fn ls(args: CommandArgs) -> Result<OutputStream, ShellError> {
_ => {}
}
match obj.item {
Value::Filesystem => {
let entries = std::fs::read_dir(&full_path);
let entries = std::fs::read_dir(&full_path);
let entries = match entries {
Err(e) => {
if let Some(s) = args.nth(0) {
return Err(ShellError::labeled_error(
e.to_string(),
e.to_string(),
s.span,
));
} else {
return Err(ShellError::maybe_labeled_error(
e.to_string(),
e.to_string(),
args.name_span,
));
}
}
Ok(o) => o,
};
let mut shell_entries = VecDeque::new();
for entry in entries {
let value = dir_entry_dict(&entry?, args.name_span)?;
shell_entries.push_back(ReturnSuccess::value(value))
let entries = match entries {
Err(e) => {
if let Some(s) = args.nth(0) {
return Err(ShellError::labeled_error(
e.to_string(),
e.to_string(),
s.span,
));
} else {
return Err(ShellError::maybe_labeled_error(
e.to_string(),
e.to_string(),
args.name_span,
));
}
Ok(shell_entries.to_output_stream())
}
_ => {
let mut entries = VecDeque::new();
let mut viewed = obj;
let sep_string = std::path::MAIN_SEPARATOR.to_string();
let sep = OsStr::new(&sep_string);
for p in full_path.iter() {
//let p = p.to_string_lossy();
match p {
x if x == sep => {}
step => {
let tmp = step.to_string_lossy();
let split_tmp = tmp.split('[');
let mut first = true;
Ok(o) => o,
};
for s in split_tmp {
if !first {
match s.find(']') {
Some(finish) => {
let idx = s[0..finish].parse::<usize>();
match idx {
Ok(idx) => match viewed.get_data_by_index(idx) {
Some(v) => {
viewed = v;
}
_ => {
return Err(ShellError::maybe_labeled_error(
"Given incorrect index",
format!("path given bad index: {}", idx),
args.name_span,
))
}
},
_ => {
return Err(ShellError::maybe_labeled_error(
"Given incorrect index",
format!(
"path index not a number: {}",
&s[0..finish]
),
args.name_span,
))
}
}
}
_ => {
return Err(ShellError::maybe_labeled_error(
"Index not closed",
format!("path missing closing ']'"),
if args.len() > 0 {
Some(args.nth(0).unwrap().span)
} else {
args.name_span
},
))
}
}
} else {
match viewed.get_data_by_key(s) {
Some(v) => {
viewed = v;
}
_ => {
return Err(ShellError::maybe_labeled_error(
"Could not find key",
format!("could not find: {}", s),
args.name_span,
))
}
}
first = false;
}
}
}
}
}
match viewed {
Spanned {
item: Value::List(l),
..
} => {
for item in l {
entries.push_back(ReturnSuccess::value(item.clone()));
}
}
x => {
entries.push_back(ReturnSuccess::value(x.clone()));
}
}
Ok(entries.to_output_stream())
}
let mut shell_entries = VecDeque::new();
for entry in entries {
let value = dir_entry_dict(&entry?, args.name_span)?;
shell_entries.push_back(ReturnSuccess::value(value))
}
Ok(shell_entries.to_output_stream())
}

View File

@ -14,8 +14,6 @@ command! {
.env
.lock()
.unwrap()
.front()
.unwrap()
.path()
.to_path_buf();
@ -39,29 +37,8 @@ command! {
let file_extension = if raw.is_present() {
None
} else if args.has("json") {
Some("json".to_string())
} else if args.has("xml") {
Some("xml".to_string())
} else if args.has("ini") {
Some("ini".to_string())
} else if args.has("yaml") {
Some("yaml".to_string())
} else if args.has("toml") {
Some("toml".to_string())
} else {
if let Some(ref named_args) = args.args.named {
for named in named_args.iter() {
return Err(ShellError::labeled_error(
"Unknown flag for open",
"unknown flag",
named.1.span.clone(),
));
}
file_extension
} else {
file_extension
}
file_extension
};
match contents {

View File

@ -21,15 +21,7 @@ pub fn save(args: SinkCommandArgs) -> Result<(), ShellError> {
Some(p) => p,
};
let cwd = args
.ctx
.env
.lock()
.unwrap()
.front()
.unwrap()
.path()
.to_path_buf();
let cwd = args.ctx.env.lock().unwrap().path().to_path_buf();
let mut full_path = PathBuf::from(cwd);
match &(positional[0].item) {
Value::Primitive(Primitive::String(s)) => full_path.push(Path::new(s)),

View File

@ -1,42 +1,23 @@
use crate::errors::ShellError;
use crate::object::{SpannedDictBuilder, Value};
use crate::prelude::*;
use std::fs::File;
use std::io::prelude::*;
pub fn size(args: CommandArgs) -> Result<OutputStream, ShellError> {
if args.len() == 0 {
return Err(ShellError::maybe_labeled_error(
"Size requires a filepath",
"needs path",
args.name_span,
));
}
let cwd = args
.env
.lock()
.unwrap()
.front()
.unwrap()
.path()
.to_path_buf();
let mut contents = String::new();
let mut list: VecDeque<ReturnValue> = VecDeque::new();
for spanned_name in args.positional_iter() {
let name = spanned_name.as_string()?;
let path = cwd.join(&name);
let mut file = File::open(path)?;
file.read_to_string(&mut contents)?;
list.push_back(count(&name, &contents, spanned_name).into());
contents.clear();
}
Ok(list.to_output_stream())
let input = args.input;
Ok(input
.values
.map(move |v| match v.item {
Value::Primitive(Primitive::String(s)) => ReturnSuccess::value(count(&s, v.span)),
_ => Err(ShellError::maybe_labeled_error(
"Expected string values from pipeline",
"expects strings from pipeline",
Some(v.span),
)),
})
.to_output_stream())
}
fn count(name: &str, contents: &str, span: impl Into<Span>) -> Spanned<Value> {
fn count(contents: &str, span: impl Into<Span>) -> Spanned<Value> {
let mut lines: i64 = 0;
let mut words: i64 = 0;
let mut chars: i64 = 0;
@ -62,7 +43,8 @@ fn count(name: &str, contents: &str, span: impl Into<Span>) -> Spanned<Value> {
}
let mut dict = SpannedDictBuilder::new(span);
dict.insert("name", Value::string(name));
//TODO: add back in name when we have it in the span
//dict.insert("name", Value::string(name));
dict.insert("lines", Value::int(lines));
dict.insert("words", Value::int(words));
dict.insert("chars", Value::int(chars));

View File

@ -3,8 +3,6 @@ use crate::object::{Primitive, SpannedDictBuilder, Value};
use crate::prelude::*;
use log::trace;
// TODO: "Amount remaining" wrapper
pub fn split_column(args: CommandArgs) -> Result<OutputStream, ShellError> {
let positional: Vec<_> = args.positional_iter().cloned().collect();
let span = args.name_span;

View File

@ -4,8 +4,6 @@ use crate::parser::Spanned;
use crate::prelude::*;
use log::trace;
// TODO: "Amount remaining" wrapper
pub fn split_row(args: CommandArgs) -> Result<OutputStream, ShellError> {
let positional: Vec<Spanned<Value>> = args.positional_iter().cloned().collect();
let span = args.name_span;

View File

@ -19,7 +19,6 @@ pub fn value_to_json_value(v: &Value) -> serde_json::Value {
Value::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_json::Value::String(s.display().to_string()),
Value::Filesystem => serde_json::Value::Null,
Value::List(l) => {
serde_json::Value::Array(l.iter().map(|x| value_to_json_value(x)).collect())
}

View File

@ -15,7 +15,6 @@ pub fn value_to_toml_value(v: &Value) -> toml::Value {
Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => toml::Value::String(s.display().to_string()),
Value::Filesystem => toml::Value::String("<Filesystem>".to_string()),
Value::List(l) => toml::Value::Array(l.iter().map(|x| value_to_toml_value(x)).collect()),
Value::Block(_) => toml::Value::String("<Block>".to_string()),
Value::Binary(b) => {

View File

@ -19,7 +19,6 @@ pub fn value_to_yaml_value(v: &Value) -> serde_yaml::Value {
Value::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()),
Value::Filesystem => serde_yaml::Value::Null,
Value::List(l) => {
serde_yaml::Value::Sequence(l.iter().map(|x| value_to_yaml_value(x)).collect())
}

View File

@ -1,50 +0,0 @@
use crate::errors::ShellError;
use crate::prelude::*;
use prettyprint::PrettyPrinter;
pub fn view(args: CommandArgs) -> Result<OutputStream, ShellError> {
if args.len() == 0 {
return Err(ShellError::maybe_labeled_error(
"View requires a filename",
"needs parameter",
args.name_span,
));
}
let target = match args.expect_nth(0)?.as_string() {
Ok(s) => s.clone(),
Err(e) => {
if let Some(span) = args.name_span {
return Err(ShellError::labeled_error(
"Expected a string",
"not a filename",
span,
));
} else {
return Err(e);
}
}
};
let cwd = args
.env
.lock()
.unwrap()
.front()
.unwrap()
.path()
.to_path_buf();
let printer = PrettyPrinter::default()
.line_numbers(false)
.header(false)
.grid(false)
.build()
.map_err(|e| ShellError::string(e))?;
let file = cwd.join(&target);
let _ = printer.file(file.display().to_string());
Ok(OutputStream::empty())
}

View File

@ -14,18 +14,16 @@ pub struct Context {
commands: IndexMap<String, Arc<dyn Command>>,
sinks: IndexMap<String, Arc<dyn Sink>>,
crate host: Arc<Mutex<dyn Host + Send>>,
crate env: Arc<Mutex<VecDeque<Environment>>>,
crate env: Arc<Mutex<Environment>>,
}
impl Context {
crate fn basic() -> Result<Context, Box<dyn Error>> {
let mut env = VecDeque::new();
env.push_back(Environment::basic()?);
Ok(Context {
commands: indexmap::IndexMap::new(),
sinks: indexmap::IndexMap::new(),
host: Arc::new(Mutex::new(crate::env::host::BasicHost)),
env: Arc::new(Mutex::new(env)),
env: Arc::new(Mutex::new(Environment::basic()?)),
})
}

View File

@ -1,10 +1,7 @@
use crate::object::base::Value;
use crate::prelude::*;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct Environment {
crate obj: Spanned<Value>,
crate path: PathBuf,
}
@ -12,17 +9,10 @@ impl Environment {
pub fn basic() -> Result<Environment, std::io::Error> {
let path = std::env::current_dir()?;
Ok(Environment {
obj: Value::Filesystem.spanned_unknown(),
path,
})
Ok(Environment { path })
}
pub fn path(&self) -> &Path {
self.path.as_path()
}
pub fn obj(&self) -> &Spanned<Value> {
&self.obj
}
}

View File

@ -98,7 +98,7 @@ impl ShellError {
}
crate fn parse_error(
error: nom::Err<(nom_locate::LocatedSpan<&str>, nom::error::ErrorKind)>,
error: nom::Err<(nom5_locate::LocatedSpan<&str>, nom::error::ErrorKind)>,
) -> ShellError {
use language_reporting::*;

View File

@ -40,11 +40,6 @@ impl RenderView for GenericView<'value> {
host.stdout("<Binary>");
Ok(())
}
Value::Filesystem => {
host.stdout("<filesystem>");
Ok(())
}
}
}
}

View File

@ -185,7 +185,6 @@ pub enum Value {
List(Vec<Spanned<Value>>),
#[allow(unused)]
Block(Block),
Filesystem,
}
pub fn debug_list(values: &'a Vec<Spanned<Value>>) -> ValuesDebug<'a> {
@ -215,7 +214,6 @@ impl fmt::Debug for ValueDebug<'a> {
Value::Object(o) => o.debug(f),
Value::List(l) => debug_list(l).fmt(f),
Value::Block(_) => write!(f, "[[block]]"),
Value::Filesystem => write!(f, "[[filesystem]]"),
Value::Binary(_) => write!(f, "[[binary]]"),
}
}
@ -300,7 +298,6 @@ impl Value {
Value::Object(_) => format!("object"),
Value::List(_) => format!("list"),
Value::Block(_) => format!("block"),
Value::Filesystem => format!("filesystem"),
Value::Binary(_) => format!("binary"),
}
}
@ -316,7 +313,6 @@ impl Value {
.collect(),
Value::Block(_) => vec![],
Value::List(_) => vec![],
Value::Filesystem => vec![],
Value::Binary(_) => vec![],
}
}
@ -343,6 +339,7 @@ impl Value {
}
}
#[allow(unused)]
crate fn get_data_by_index(&'a self, idx: usize) -> Option<&Spanned<Value>> {
match self {
Value::List(l) => l.iter().nth(idx),
@ -353,7 +350,6 @@ impl Value {
pub fn get_data(&'a self, desc: &String) -> MaybeOwned<'a, Value> {
match self {
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
p @ Value::Filesystem => MaybeOwned::Borrowed(p),
Value::Object(o) => o.get_data(desc),
Value::Block(_) => MaybeOwned::Owned(Value::nothing()),
Value::List(_) => MaybeOwned::Owned(Value::nothing()),
@ -372,7 +368,6 @@ impl Value {
),
Value::Object(_) => format!("[object Object]"),
Value::List(_) => format!("[list List]"),
Value::Filesystem => format!("<filesystem>"),
Value::Binary(_) => format!("<binary>"),
}
}

View File

@ -16,7 +16,7 @@ use log::trace;
use nom::dbg;
use nom::*;
use nom::{AsBytes, FindSubstring, IResult, InputLength, InputTake, Slice};
use nom_locate::{position, LocatedSpan};
use nom5_locate::{position, LocatedSpan};
use std::fmt::Debug;
use std::str::FromStr;

View File

@ -99,8 +99,8 @@ impl From<&Span> for Span {
}
}
impl From<nom_locate::LocatedSpan<&str>> for Span {
fn from(input: nom_locate::LocatedSpan<&str>) -> Span {
impl From<nom5_locate::LocatedSpan<&str>> for Span {
fn from(input: nom5_locate::LocatedSpan<&str>) -> Span {
Span {
start: input.offset,
end: input.offset + input.fragment.len(),
@ -108,8 +108,8 @@ impl From<nom_locate::LocatedSpan<&str>> for Span {
}
}
impl<T> From<(nom_locate::LocatedSpan<T>, nom_locate::LocatedSpan<T>)> for Span {
fn from(input: (nom_locate::LocatedSpan<T>, nom_locate::LocatedSpan<T>)) -> Span {
impl<T> From<(nom5_locate::LocatedSpan<T>, nom5_locate::LocatedSpan<T>)> for Span {
fn from(input: (nom5_locate::LocatedSpan<T>, nom5_locate::LocatedSpan<T>)) -> Span {
Span {
start: input.0.offset,
end: input.1.offset,

View File

@ -32,6 +32,10 @@ impl PositionalType {
PositionalType::Mandatory(name.to_string(), SyntaxType::Any)
}
pub fn mandatory_block(name: &str) -> PositionalType {
PositionalType::Mandatory(name.to_string(), SyntaxType::Block)
}
pub fn optional(name: &str, ty: SyntaxType) -> PositionalType {
PositionalType::Optional(name.to_string(), ty)
}
@ -40,10 +44,6 @@ impl PositionalType {
PositionalType::Optional(name.to_string(), SyntaxType::Any)
}
pub fn mandatory_block(name: &str) -> PositionalType {
PositionalType::Mandatory(name.to_string(), SyntaxType::Block)
}
#[allow(unused)]
crate fn to_coerce_hint(&self) -> Option<SyntaxType> {
match self {

View File

@ -31,7 +31,6 @@ impl TreeView {
}
}
Value::Block(_) => {}
Value::Filesystem => {}
Value::Binary(_) => {}
}
}

View File

@ -46,6 +46,7 @@ pub struct OutputStream {
}
impl OutputStream {
#[allow(unused)]
pub fn empty() -> OutputStream {
let v: VecDeque<ReturnValue> = VecDeque::new();
v.into()