mirror of
https://github.com/nushell/nushell
synced 2025-01-15 06:34:15 +00:00
Rename origin to anchor
This commit is contained in:
parent
d52e087453
commit
caed87c125
18 changed files with 111 additions and 111 deletions
|
@ -58,7 +58,7 @@ pub fn autoview(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if is_single_origined_text_value(&input) {
|
} else if is_single_anchored_text_value(&input) {
|
||||||
let text = context.get_command("textview");
|
let text = context.get_command("textview");
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let result = text.run(raw.with_input(input), &context.commands, false);
|
let result = text.run(raw.with_input(input), &context.commands, false);
|
||||||
|
@ -111,17 +111,17 @@ fn is_single_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_single_origined_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
fn is_single_anchored_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
||||||
if input.len() != 1 {
|
if input.len() != 1 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Tagged {
|
if let Tagged {
|
||||||
item: Value::Primitive(Primitive::String(_)),
|
item: Value::Primitive(Primitive::String(_)),
|
||||||
tag: Tag { origin, .. },
|
tag: Tag { anchor, .. },
|
||||||
} = input[0]
|
} = input[0]
|
||||||
{
|
{
|
||||||
origin != uuid::Uuid::nil()
|
anchor != uuid::Uuid::nil()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,10 @@ impl PerItemCommand for Enter {
|
||||||
)
|
)
|
||||||
.await.unwrap();
|
.await.unwrap();
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
span_source,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,10 @@ fn run(
|
||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
span_source,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ pub async fn fetch(
|
||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -173,7 +173,7 @@ pub async fn fetch(
|
||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -190,7 +190,7 @@ pub async fn fetch(
|
||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
|
@ -206,7 +206,7 @@ pub async fn fetch(
|
||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -223,7 +223,7 @@ pub async fn fetch(
|
||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
|
@ -239,7 +239,7 @@ pub async fn fetch(
|
||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -266,7 +266,7 @@ pub async fn fetch(
|
||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
|
@ -276,7 +276,7 @@ pub async fn fetch(
|
||||||
Value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
|
Value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -287,7 +287,7 @@ pub async fn fetch(
|
||||||
Value::string(format!("No content type found")),
|
Value::string(format!("No content type found")),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -77,10 +77,10 @@ fn run(
|
||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
span_source,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ pub async fn fetch(
|
||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -166,7 +166,7 @@ pub async fn fetch(
|
||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -175,7 +175,7 @@ pub async fn fetch(
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -186,7 +186,7 @@ pub async fn fetch(
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
))
|
))
|
||||||
|
@ -204,7 +204,7 @@ pub async fn fetch(
|
||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -213,7 +213,7 @@ pub async fn fetch(
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
@ -224,7 +224,7 @@ pub async fn fetch(
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
))
|
))
|
||||||
|
@ -235,7 +235,7 @@ pub async fn fetch(
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
SpanSource::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -85,10 +85,10 @@ fn run(
|
||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
span_source,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,10 +133,10 @@ fn save(
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
let input: Vec<Tagged<Value>> = input.values.collect().await;
|
let input: Vec<Tagged<Value>> = input.values.collect().await;
|
||||||
if path.is_none() {
|
if path.is_none() {
|
||||||
// If there is no filename, check the metadata for the origin filename
|
// If there is no filename, check the metadata for the anchor filename
|
||||||
if input.len() > 0 {
|
if input.len() > 0 {
|
||||||
let origin = input[0].origin();
|
let anchor = input[0].anchor();
|
||||||
match source_map.get(&origin) {
|
match source_map.get(&anchor) {
|
||||||
Some(path) => match path {
|
Some(path) => match path {
|
||||||
SpanSource::File(file) => {
|
SpanSource::File(file) => {
|
||||||
full_path.push(Path::new(file));
|
full_path.push(Path::new(file));
|
||||||
|
|
|
@ -35,19 +35,19 @@ fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
.map(move |v| {
|
.map(move |v| {
|
||||||
let mut tags = TaggedDictBuilder::new(v.tag());
|
let mut tags = TaggedDictBuilder::new(v.tag());
|
||||||
{
|
{
|
||||||
let origin = v.origin();
|
let anchor = v.anchor();
|
||||||
let span = v.tag().span;
|
let span = v.tag().span;
|
||||||
let mut dict = TaggedDictBuilder::new(v.tag());
|
let mut dict = TaggedDictBuilder::new(v.tag());
|
||||||
dict.insert("start", Value::int(span.start as i64));
|
dict.insert("start", Value::int(span.start as i64));
|
||||||
dict.insert("end", Value::int(span.end as i64));
|
dict.insert("end", Value::int(span.end as i64));
|
||||||
tags.insert_tagged("span", dict.into_tagged_value());
|
tags.insert_tagged("span", dict.into_tagged_value());
|
||||||
|
|
||||||
match source_map.get(&origin) {
|
match source_map.get(&anchor) {
|
||||||
Some(SpanSource::File(source)) => {
|
Some(SpanSource::File(source)) => {
|
||||||
tags.insert("origin", Value::string(source));
|
tags.insert("anchor", Value::string(source));
|
||||||
}
|
}
|
||||||
Some(SpanSource::Url(source)) => {
|
Some(SpanSource::Url(source)) => {
|
||||||
tags.insert("origin", Value::string(source));
|
tags.insert("anchor", Value::string(source));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub trait TaggedItem: Sized {
|
||||||
self,
|
self,
|
||||||
Tag {
|
Tag {
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,12 @@ impl<T> Tagged<T> {
|
||||||
self.tag.span
|
self.tag.span
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin(&self) -> uuid::Uuid {
|
pub fn anchor(&self) -> uuid::Uuid {
|
||||||
self.tag.origin
|
self.tag.anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin_name(&self, source_map: &SourceMap) -> Option<String> {
|
pub fn anchor_name(&self, source_map: &SourceMap) -> Option<String> {
|
||||||
match source_map.get(&self.tag.origin) {
|
match source_map.get(&self.tag.anchor) {
|
||||||
Some(SpanSource::File(file)) => Some(file.clone()),
|
Some(SpanSource::File(file)) => Some(file.clone()),
|
||||||
Some(SpanSource::Url(url)) => Some(url.clone()),
|
Some(SpanSource::Url(url)) => Some(url.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -167,14 +167,14 @@ impl From<&std::ops::Range<usize>> for Span {
|
||||||
Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Hash, Getters,
|
Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Hash, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub origin: Uuid,
|
pub anchor: Uuid,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Span> for Tag {
|
impl From<Span> for Tag {
|
||||||
fn from(span: Span) -> Self {
|
fn from(span: Span) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,25 +183,25 @@ impl From<Span> for Tag {
|
||||||
impl From<&Span> for Tag {
|
impl From<&Span> for Tag {
|
||||||
fn from(span: &Span) -> Self {
|
fn from(span: &Span) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span: *span,
|
span: *span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(usize, usize, Uuid)> for Tag {
|
impl From<(usize, usize, Uuid)> for Tag {
|
||||||
fn from((start, end, origin): (usize, usize, Uuid)) -> Self {
|
fn from((start, end, anchor): (usize, usize, Uuid)) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin,
|
anchor,
|
||||||
span: Span { start, end },
|
span: Span { start, end },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(usize, usize, Option<Uuid>)> for Tag {
|
impl From<(usize, usize, Option<Uuid>)> for Tag {
|
||||||
fn from((start, end, origin): (usize, usize, Option<Uuid>)) -> Self {
|
fn from((start, end, anchor): (usize, usize, Option<Uuid>)) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: if let Some(uuid) = origin {
|
anchor: if let Some(uuid) = anchor {
|
||||||
uuid
|
uuid
|
||||||
} else {
|
} else {
|
||||||
uuid::Uuid::nil()
|
uuid::Uuid::nil()
|
||||||
|
@ -214,7 +214,7 @@ impl From<(usize, usize, Option<Uuid>)> for Tag {
|
||||||
impl From<nom_locate::LocatedSpanEx<&str, Uuid>> for Tag {
|
impl From<nom_locate::LocatedSpanEx<&str, Uuid>> for Tag {
|
||||||
fn from(input: nom_locate::LocatedSpanEx<&str, Uuid>) -> Tag {
|
fn from(input: nom_locate::LocatedSpanEx<&str, Uuid>) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: input.extra,
|
anchor: input.extra,
|
||||||
span: Span {
|
span: Span {
|
||||||
start: input.offset,
|
start: input.offset,
|
||||||
end: input.offset + input.fragment.len(),
|
end: input.offset + input.fragment.len(),
|
||||||
|
@ -236,23 +236,23 @@ impl From<&Tag> for Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
pub fn unknown_origin(span: Span) -> Tag {
|
pub fn unknown_anchor(span: Span) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknown_span(origin: Uuid) -> Tag {
|
pub fn unknown_span(anchor: Uuid) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin,
|
anchor,
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknown() -> Tag {
|
pub fn unknown() -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,8 +260,8 @@ impl Tag {
|
||||||
pub fn until(&self, other: impl Into<Tag>) -> Tag {
|
pub fn until(&self, other: impl Into<Tag>) -> Tag {
|
||||||
let other = other.into();
|
let other = other.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.origin == other.origin,
|
self.anchor == other.anchor,
|
||||||
"Can only merge two tags with the same origin"
|
"Can only merge two tags with the same anchor"
|
||||||
);
|
);
|
||||||
|
|
||||||
Tag {
|
Tag {
|
||||||
|
@ -269,7 +269,7 @@ impl Tag {
|
||||||
start: self.span.start,
|
start: self.span.start,
|
||||||
end: other.span.end,
|
end: other.span.end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ impl language_reporting::ReportingSpan for Tag {
|
||||||
start,
|
start,
|
||||||
end: self.span.end,
|
end: self.span.end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ impl language_reporting::ReportingSpan for Tag {
|
||||||
start: self.span.start,
|
start: self.span.start,
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,10 @@ pub(crate) use parse::unit::Unit;
|
||||||
pub(crate) use parse_command::parse_command;
|
pub(crate) use parse_command::parse_command;
|
||||||
pub(crate) use registry::CommandRegistry;
|
pub(crate) use registry::CommandRegistry;
|
||||||
|
|
||||||
pub fn parse(input: &str, origin: uuid::Uuid) -> Result<TokenNode, ShellError> {
|
pub fn parse(input: &str, anchor: uuid::Uuid) -> Result<TokenNode, ShellError> {
|
||||||
let _ = pretty_env_logger::try_init();
|
let _ = pretty_env_logger::try_init();
|
||||||
|
|
||||||
match pipeline(nom_input(input, origin)) {
|
match pipeline(nom_input(input, anchor)) {
|
||||||
Ok((_rest, val)) => Ok(val),
|
Ok((_rest, val)) => Ok(val),
|
||||||
Err(err) => Err(ShellError::parse_error(err)),
|
Err(err) => Err(ShellError::parse_error(err)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl language_reporting::ReportingFiles for Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_id(&self, tag: Self::Span) -> Self::FileId {
|
fn file_id(&self, tag: Self::Span) -> Self::FileId {
|
||||||
tag.origin
|
tag.anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_name(&self, _file: Self::FileId) -> FileName {
|
fn file_name(&self, _file: Self::FileId) -> FileName {
|
||||||
|
|
|
@ -26,8 +26,8 @@ use uuid::Uuid;
|
||||||
|
|
||||||
pub type NomSpan<'a> = LocatedSpanEx<&'a str, Uuid>;
|
pub type NomSpan<'a> = LocatedSpanEx<&'a str, Uuid>;
|
||||||
|
|
||||||
pub fn nom_input(s: &str, origin: Uuid) -> NomSpan<'_> {
|
pub fn nom_input(s: &str, anchor: Uuid) -> NomSpan<'_> {
|
||||||
LocatedSpanEx::new_extra(s, origin)
|
LocatedSpanEx::new_extra(s, anchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! operator {
|
macro_rules! operator {
|
||||||
|
@ -149,7 +149,7 @@ impl Into<Number> for BigDecimal {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_number(input: NomSpan) -> IResult<NomSpan, Tagged<RawNumber>> {
|
pub fn raw_number(input: NomSpan) -> IResult<NomSpan, Tagged<RawNumber>> {
|
||||||
let original = input;
|
let anchoral = input;
|
||||||
let start = input.offset;
|
let start = input.offset;
|
||||||
trace_step(input, "raw_decimal", move |input| {
|
trace_step(input, "raw_decimal", move |input| {
|
||||||
let (input, neg) = opt(tag("-"))(input)?;
|
let (input, neg) = opt(tag("-"))(input)?;
|
||||||
|
@ -1308,7 +1308,7 @@ mod tests {
|
||||||
right: usize,
|
right: usize,
|
||||||
) -> TokenNode {
|
) -> TokenNode {
|
||||||
let node = DelimitedNode::new(*delimiter, children);
|
let node = DelimitedNode::new(*delimiter, children);
|
||||||
let spanned = node.tagged((left, right, delimiter.tag.origin));
|
let spanned = node.tagged((left, right, delimiter.tag.anchor));
|
||||||
TokenNode::Delimited(spanned)
|
TokenNode::Delimited(spanned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1319,7 +1319,7 @@ mod tests {
|
||||||
Box::new(head),
|
Box::new(head),
|
||||||
tail.into_iter().map(TokenNode::Token).collect(),
|
tail.into_iter().map(TokenNode::Token).collect(),
|
||||||
);
|
);
|
||||||
let spanned = node.tagged((left, right, tag.origin));
|
let spanned = node.tagged((left, right, tag.anchor));
|
||||||
TokenNode::Path(spanned)
|
TokenNode::Path(spanned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,15 @@ pub struct TokenTreeBuilder {
|
||||||
#[new(default)]
|
#[new(default)]
|
||||||
output: String,
|
output: String,
|
||||||
|
|
||||||
origin: Uuid,
|
anchor: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CurriedToken = Box<dyn FnOnce(&mut TokenTreeBuilder) -> TokenNode + 'static>;
|
pub type CurriedToken = Box<dyn FnOnce(&mut TokenTreeBuilder) -> TokenNode + 'static>;
|
||||||
pub type CurriedCall = Box<dyn FnOnce(&mut TokenTreeBuilder) -> Tagged<CallNode> + 'static>;
|
pub type CurriedCall = Box<dyn FnOnce(&mut TokenTreeBuilder) -> Tagged<CallNode> + 'static>;
|
||||||
|
|
||||||
impl TokenTreeBuilder {
|
impl TokenTreeBuilder {
|
||||||
pub fn build(origin: Uuid, block: impl FnOnce(&mut Self) -> TokenNode) -> (TokenNode, String) {
|
pub fn build(anchor: Uuid, block: impl FnOnce(&mut Self) -> TokenNode) -> (TokenNode, String) {
|
||||||
let mut builder = TokenTreeBuilder::new(origin);
|
let mut builder = TokenTreeBuilder::new(anchor);
|
||||||
let node = block(&mut builder);
|
let node = block(&mut builder);
|
||||||
(node, builder.output)
|
(node, builder.output)
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_pipeline((out, None), (start, end, b.origin))
|
TokenTreeBuilder::tagged_pipeline((out, None), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_op(input, (start, end, b.origin))
|
TokenTreeBuilder::tagged_op(input, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ impl TokenTreeBuilder {
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_string(
|
TokenTreeBuilder::tagged_string(
|
||||||
(inner_start, inner_end, b.origin),
|
(inner_start, inner_end, b.anchor),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_bare((start, end, b.origin))
|
TokenTreeBuilder::tagged_bare((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_pattern((start, end, b.origin))
|
TokenTreeBuilder::tagged_pattern((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_external_word((start, end, b.origin))
|
TokenTreeBuilder::tagged_external_word((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ impl TokenTreeBuilder {
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_number(
|
TokenTreeBuilder::tagged_number(
|
||||||
RawNumber::Int((start, end, b.origin).into()),
|
RawNumber::Int((start, end, b.anchor).into()),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ impl TokenTreeBuilder {
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_number(
|
TokenTreeBuilder::tagged_number(
|
||||||
RawNumber::Decimal((start, end, b.origin).into()),
|
RawNumber::Decimal((start, end, b.anchor).into()),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -214,8 +214,8 @@ impl TokenTreeBuilder {
|
||||||
b.pos = end_unit;
|
b.pos = end_unit;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_size(
|
TokenTreeBuilder::tagged_size(
|
||||||
(RawNumber::Int((start_int, end_int, b.origin).into()), unit),
|
(RawNumber::Int((start_int, end_int, b.anchor).into()), unit),
|
||||||
(start_int, end_unit, b.origin),
|
(start_int, end_unit, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_path((head, output), (start, end, b.origin))
|
TokenTreeBuilder::tagged_path((head, output), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, _) = b.consume("$");
|
let (start, _) = b.consume("$");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_var((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_var((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, _) = b.consume("--");
|
let (start, _) = b.consume("--");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_flag((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_flag((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ impl TokenTreeBuilder {
|
||||||
let (start, _) = b.consume("-");
|
let (start, _) = b.consume("-");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_shorthand((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_shorthand((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
Box::new(move |b| {
|
Box::new(move |b| {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
TokenTreeBuilder::tagged_member((start, end, b.origin))
|
TokenTreeBuilder::tagged_member((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_call(nodes, (start, end, b.origin))
|
TokenTreeBuilder::tagged_call(nodes, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let (_, end) = b.consume(")");
|
let (_, end) = b.consume(")");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_parens(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_parens(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let (_, end) = b.consume("]");
|
let (_, end) = b.consume("]");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_square(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_square(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
let (_, end) = b.consume(" }");
|
let (_, end) = b.consume(" }");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_brace(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_brace(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ impl TokenTreeBuilder {
|
||||||
pub fn sp() -> CurriedToken {
|
pub fn sp() -> CurriedToken {
|
||||||
Box::new(|b| {
|
Box::new(|b| {
|
||||||
let (start, end) = b.consume(" ");
|
let (start, end) = b.consume(" ");
|
||||||
TokenNode::Whitespace(Tag::from((start, end, b.origin)))
|
TokenNode::Whitespace(Tag::from((start, end, b.anchor)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ impl TokenTreeBuilder {
|
||||||
|
|
||||||
Box::new(move |b| {
|
Box::new(move |b| {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
TokenTreeBuilder::tagged_ws((start, end, b.origin))
|
TokenTreeBuilder::tagged_ws((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,6 +425,6 @@ impl TokenTreeBuilder {
|
||||||
let start = self.pos;
|
let start = self.pos;
|
||||||
self.pos += input.len();
|
self.pos += input.len();
|
||||||
self.output.push_str(input);
|
self.output.push_str(input);
|
||||||
(start, self.pos, self.origin).into()
|
(start, self.pos, self.anchor).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ impl Plugin for BinaryView {
|
||||||
|
|
||||||
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {
|
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {
|
||||||
for v in input {
|
for v in input {
|
||||||
let value_origin = v.origin();
|
let value_anchor = v.anchor();
|
||||||
match v.item {
|
match v.item {
|
||||||
Value::Primitive(Primitive::Binary(b)) => {
|
Value::Primitive(Primitive::Binary(b)) => {
|
||||||
let source = call_info.source_map.get(&value_origin);
|
let source = call_info.source_map.get(&value_anchor);
|
||||||
let _ = view_binary(&b, source, call_info.args.has("lores"));
|
let _ = view_binary(&b, source, call_info.args.has("lores"));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -186,15 +186,15 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CallStub {
|
struct CallStub {
|
||||||
origin: uuid::Uuid,
|
anchor: uuid::Uuid,
|
||||||
positionals: Vec<Tagged<Value>>,
|
positionals: Vec<Tagged<Value>>,
|
||||||
flags: IndexMap<String, Tagged<Value>>,
|
flags: IndexMap<String, Tagged<Value>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallStub {
|
impl CallStub {
|
||||||
fn new(origin: uuid::Uuid) -> CallStub {
|
fn new(anchor: uuid::Uuid) -> CallStub {
|
||||||
CallStub {
|
CallStub {
|
||||||
origin,
|
anchor,
|
||||||
positionals: vec![],
|
positionals: vec![],
|
||||||
flags: indexmap::IndexMap::new(),
|
flags: indexmap::IndexMap::new(),
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ mod tests {
|
||||||
|
|
||||||
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
||||||
self.positionals
|
self.positionals
|
||||||
.push(Value::string(name.to_string()).tagged(Tag::unknown_span(self.origin)));
|
.push(Value::string(name.to_string()).tagged(Tag::unknown_span(self.anchor)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ mod tests {
|
||||||
CallInfo {
|
CallInfo {
|
||||||
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
||||||
source_map: SourceMap::new(),
|
source_map: SourceMap::new(),
|
||||||
name_tag: Tag::unknown_span(self.origin),
|
name_tag: Tag::unknown_span(self.anchor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ mod tests {
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
struct CallStub {
|
struct CallStub {
|
||||||
origin: uuid::Uuid,
|
anchor: uuid::Uuid,
|
||||||
positionals: Vec<Tagged<Value>>,
|
positionals: Vec<Tagged<Value>>,
|
||||||
flags: IndexMap<String, Tagged<Value>>,
|
flags: IndexMap<String, Tagged<Value>>,
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ mod tests {
|
||||||
impl CallStub {
|
impl CallStub {
|
||||||
fn new() -> CallStub {
|
fn new() -> CallStub {
|
||||||
CallStub {
|
CallStub {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
positionals: vec![],
|
positionals: vec![],
|
||||||
flags: indexmap::IndexMap::new(),
|
flags: indexmap::IndexMap::new(),
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ mod tests {
|
||||||
CallInfo {
|
CallInfo {
|
||||||
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
||||||
source_map: SourceMap::new(),
|
source_map: SourceMap::new(),
|
||||||
name_tag: Tag::unknown_span(self.origin),
|
name_tag: Tag::unknown_span(self.anchor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,10 +216,10 @@ fn scroll_view(s: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
||||||
let value_origin = value.origin();
|
let value_anchor = value.anchor();
|
||||||
match value.item {
|
match value.item {
|
||||||
Value::Primitive(Primitive::String(ref s)) => {
|
Value::Primitive(Primitive::String(ref s)) => {
|
||||||
let source = source_map.get(&value_origin);
|
let source = source_map.get(&value_anchor);
|
||||||
|
|
||||||
if let Some(source) = source {
|
if let Some(source) = source {
|
||||||
let extension: Option<String> = match source {
|
let extension: Option<String> = match source {
|
||||||
|
|
|
@ -99,10 +99,10 @@ impl HelpShell {
|
||||||
|
|
||||||
impl Shell for HelpShell {
|
impl Shell for HelpShell {
|
||||||
fn name(&self, source_map: &SourceMap) -> String {
|
fn name(&self, source_map: &SourceMap) -> String {
|
||||||
let origin_name = self.value.origin_name(source_map);
|
let anchor_name = self.value.anchor_name(source_map);
|
||||||
format!(
|
format!(
|
||||||
"{}",
|
"{}",
|
||||||
match origin_name {
|
match anchor_name {
|
||||||
Some(x) => format!("{{{}}}", x),
|
Some(x) => format!("{{{}}}", x),
|
||||||
None => format!("<{}>", self.value.item.type_name(),),
|
None => format!("<{}>", self.value.item.type_name(),),
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,10 +73,10 @@ impl ValueShell {
|
||||||
|
|
||||||
impl Shell for ValueShell {
|
impl Shell for ValueShell {
|
||||||
fn name(&self, source_map: &SourceMap) -> String {
|
fn name(&self, source_map: &SourceMap) -> String {
|
||||||
let origin_name = self.value.origin_name(source_map);
|
let anchor_name = self.value.anchor_name(source_map);
|
||||||
format!(
|
format!(
|
||||||
"{}",
|
"{}",
|
||||||
match origin_name {
|
match anchor_name {
|
||||||
Some(x) => format!("{{{}}}", x),
|
Some(x) => format!("{{{}}}", x),
|
||||||
None => format!("<{}>", self.value.item.type_name(),),
|
None => format!("<{}>", self.value.item.type_name(),),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue