Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b9ec341
Update contributing.md
wdanilo Apr 8, 2020
ff64c11
Update contributing.md
wdanilo Apr 8, 2020
fdaa86f
Update contributing.md
wdanilo Apr 8, 2020
b1a5b34
Update contributing.md
wdanilo Apr 8, 2020
6517159
playing with simple cases, improving test harness
mwu-tow Apr 8, 2020
fadc178
[wip]
mwu-tow Apr 8, 2020
90d64eb
fixes
mwu-tow Apr 9, 2020
757ed2b
updates based on Ara's feedback and call with Wojciech
mwu-tow Apr 9, 2020
eb2b2a4
development
mwu-tow Apr 10, 2020
e3411a8
[wip]
mwu-tow Apr 10, 2020
31d0b1f
fixed nested block handling
mwu-tow Apr 10, 2020
68cdf2c
total refactoring
mwu-tow Apr 12, 2020
9175958
cleanups
mwu-tow Apr 14, 2020
9441a4c
cleanups & docs
mwu-tow Apr 14, 2020
84ecdbf
cleanups, fixes, tests
mwu-tow Apr 15, 2020
6d09cee
cleanups
mwu-tow Apr 15, 2020
c866db4
minor
mwu-tow Apr 15, 2020
853f608
ouch, it's tricky
mwu-tow Apr 15, 2020
87c1628
Fixed PageUp and PageDown (#340)
notdanilo Apr 15, 2020
3599f61
fixes in tests
mwu-tow Apr 15, 2020
1acb811
CR feedback
mwu-tow Apr 15, 2020
0403eec
todo note to refer to the spec, once it is available
mwu-tow Apr 15, 2020
1a874ea
Merge branch 'master' into wip/mwu/alias-analysis
mwu-tow Apr 15, 2020
9b1cc06
async sleep function (#357)
notdanilo Apr 15, 2020
d6b6b33
Merge remote-tracking branch 'remotes/origin/master' into wip/mwu/ali…
mwu-tow Apr 15, 2020
7224256
where went this
mwu-tow Apr 15, 2020
3d54632
CR feedback
mwu-tow Apr 15, 2020
0edfa08
i don't want this in my pr
mwu-tow Apr 15, 2020
5830edc
use impls! to reduce boilerplate
mwu-tow Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ debug = false
[profile.test]
opt-level = 0
lto = false
debug = false
debug = true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we set it to true? Have you checked why it was set to false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I need this to properly debug my test, it also provides line numbers in call stack when test is failing.

@wdanilo Can you comment why it was set to false? Is it still necessary?

96 changes: 57 additions & 39 deletions src/rust/ide/ast/impl/src/crumbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use crate::prelude::*;

use crate::known;
use crate::HasTokens;
use crate::Shape;
use crate::TokenConsumer;

use utils::fail::FallibleResult;

Expand Down Expand Up @@ -92,21 +94,21 @@ pub type Crumbs = Vec<Crumb>;
// === InvalidSuffix ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct InvalidSuffixCrumb;


// === TextLineFmt ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct TextLineFmtCrumb {pub segment_index:usize}


// === TextBlockFmt ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct TextBlockFmtCrumb {
pub text_line_index : usize,
pub segment_index : usize
Expand All @@ -116,7 +118,7 @@ pub struct TextBlockFmtCrumb {
// === TextUnclosed ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct TextUnclosedCrumb {
pub text_line_crumb : TextLineFmtCrumb
}
Expand All @@ -125,7 +127,7 @@ pub struct TextUnclosedCrumb {
// === Prefix ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum PrefixCrumb {
Func,
Arg
Expand All @@ -135,7 +137,7 @@ pub enum PrefixCrumb {
// === Infix ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum InfixCrumb {
LeftOperand,
Operator,
Expand All @@ -146,7 +148,7 @@ pub enum InfixCrumb {
// === SectionLeft ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum SectionLeftCrumb {
Arg,
Opr
Expand All @@ -156,7 +158,7 @@ pub enum SectionLeftCrumb {
// === SectionRight ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum SectionRightCrumb {
Opr,
Arg
Expand All @@ -166,21 +168,21 @@ pub enum SectionRightCrumb {
// === SectionSides ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct SectionSidesCrumb;


// === Module ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct ModuleCrumb {pub line_index:usize}


// === Block ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum BlockCrumb {
/// The first non-empty line in block.
HeadLine,
Expand All @@ -192,14 +194,14 @@ pub enum BlockCrumb {
// === Import ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct ImportCrumb {pub index:usize}


// === Mixfix ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum MixfixCrumb {
Name {index:usize},
Args {index:usize}
Expand All @@ -209,14 +211,14 @@ pub enum MixfixCrumb {
// === Group ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub struct GroupCrumb;


// === Def ===

#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
pub enum DefCrumb {
Name,
Args {index:usize},
Expand All @@ -239,6 +241,14 @@ macro_rules! from_crumb {
Crumb::$id(crumb.clone())
}
}

impl IntoIterator for $crumb_id {
type Item = Crumb;
type IntoIter = std::iter::Once<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
std::iter::once(Crumb::from(self))
}
}
}
}

Expand Down Expand Up @@ -271,14 +281,23 @@ macro_rules! impl_crumbs {
}

/// Crumb identifies location of child AST in an AST node. Allows for a single step AST traversal.
#[derive(Clone,Copy,Debug,PartialEq,Hash)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,Hash)]
#[allow(missing_docs)]
pub enum Crumb {
$($id($crumb_id),)*
}
}
}

impl IntoIterator for Crumb {
type Item = Crumb;
type IntoIter = std::iter::Once<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
std::iter::once(self)
}
}


impl_crumbs!{
(InvalidSuffix,InvalidSuffixCrumb),
(TextLineFmt ,TextLineFmtCrumb),
Expand Down Expand Up @@ -306,7 +325,7 @@ impl_crumbs!{
/// Interface for items that allow getting/setting stored Ast located by arbitrary `Crumb`.
pub trait Crumbable {
/// Specific `Crumb` type used by `Self` to locate child Asts.
type Crumb : Into<Crumb>;
type Crumb : Into<Crumb> + IntoIterator<Item=Crumb>;

/// Retrieves `Ast` under the crumb.
fn get(&self, crumb:&Self::Crumb) -> FallibleResult<&Ast>;
Expand Down Expand Up @@ -860,7 +879,7 @@ pub fn non_empty_line_indices<'a, T:'a>
// ===============

/// Item which location is identified by `Crumbs`.
#[derive(Clone,Debug,Shrinkwrap)]
#[derive(Clone,Debug,Shrinkwrap,PartialEq,Eq,Hash)]
pub struct Located<T> {
/// Crumbs from containing parent.
pub crumbs : Crumbs,
Expand All @@ -883,27 +902,32 @@ impl<T> Located<T> {
Located {crumbs,item}
}

/// Creates a new item in a root location (single crumb location).
pub fn new_direct_child(crumb:impl Into<Crumb>, item:T) -> Located<T> {
let crumbs = vec![crumb.into()];
Located {crumbs,item}
}

/// Uses given function to map over the item.
pub fn map<U>(self, f:impl FnOnce(T) -> U) -> Located<U> {
Located::new(self.crumbs, f(self.item))
}

/// Replaces the item, while pushing given crumbs on top of already present ones.
pub fn into_descendant<U>(self, crumbs:Crumbs, item:U) -> Located<U> {
/// Takes crumbs relative to self and item that will be wrapped.
pub fn descendant<Cs,U>(&self, crumbs:Cs, child:U) -> Located<U>
where Cs : IntoIterator<Item:Into<Crumb>>,{
let crumbs_so_far = self.crumbs.iter().copied();
let crumbs_to_add = crumbs.into_iter().map(|crumb| crumb.into());
let crumbs = crumbs_so_far.chain(crumbs_to_add);
Located::new(crumbs, child)
}

/// Maps into child, concatenating this crumbs and child crumbs.
pub fn into_descendant<U>(self, child:Located<U>) -> Located<U> {
let Located {crumbs,item} = child;
let mut ret = self.map(|_| item);
ret.crumbs.extend(crumbs);
ret
}
}

/// Maps into child, concatenating this crumbs and child crumbs.
pub fn push_descendant<U>(self, child:Located<U>) -> Located<U> {
self.into_descendant(child.crumbs,child.item)
impl<T:HasTokens> HasTokens for Located<T> {
fn feed_to(&self, consumer:&mut impl TokenConsumer) {
self.item.feed_to(consumer)
}
}

Expand Down Expand Up @@ -1425,17 +1449,11 @@ mod tests {
assert_eq!(item.item, "zero");
assert!(item.crumbs.is_empty());

let item = item.into_descendant(vec![Crumb::Infix(InfixCrumb::LeftOperand)], 1);
assert_eq!(item.item, 1);
let (crumb0,) = item.crumbs.iter().expect_tuple();
assert_eq!(crumb0,&Crumb::Infix(InfixCrumb::LeftOperand));

let child_item = Located::new_direct_child(InfixCrumb::Operator, "two");
let item = item.push_descendant(child_item);
let child_item = Located::new(InfixCrumb::Operator, "two");
let item = item.into_descendant(child_item);
assert_eq!(item.item, "two");
let (crumb0,crumb1) = item.crumbs.iter().expect_tuple();
assert_eq!(crumb0,&Crumb::Infix(InfixCrumb::LeftOperand));
assert_eq!(crumb1,&Crumb::Infix(InfixCrumb::Operator));
let (crumb0,) = item.crumbs.iter().expect_tuple();
assert_eq!(crumb0,&Crumb::Infix(InfixCrumb::Operator));

let item2 = item.clone().map(|item| item.len() );
assert_eq!(item2.item,3);
Expand Down
1 change: 1 addition & 0 deletions src/rust/ide/ast/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod prelude {

pub use crate::Ast;
pub use crate::traits::*;
pub use utils::option::*;
}

use crate::prelude::*;
Expand Down
Loading