* updated imports declaration

* parser bump, fixing the import regression

* this should be wasm test

* cleanups

* `in` is now treated as an operator

* one more fix

Original commit: 235ebdf38e
This commit is contained in:
Michał Wawrzyniec Urbańczyk 2020-07-20 17:35:43 +02:00 committed by GitHub
parent cbed8f08bf
commit eb17ad8352
8 changed files with 35 additions and 29 deletions

View File

@ -246,8 +246,15 @@ pub enum BlockCrumb {
// === Import ===
#[allow(missing_docs)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,PartialOrd,Ord,Hash)]
pub struct ImportCrumb {pub index:usize}
#[derive(Clone,Debug,PartialEq,Eq,PartialOrd,Ord,Hash)]
pub struct ImportCrumb(pub Box<Crumb>);
impl ImportCrumb {
#[allow(missing_docs)]
pub fn new(crumb:impl Into<Crumb>) -> Self {
Self(Box::new(crumb.into()))
}
}
// === Mixfix ===
@ -1046,20 +1053,17 @@ impl Crumbable for crate::Import<Ast> {
type Crumb = ImportCrumb;
fn get(&self, crumb:&Self::Crumb) -> FallibleResult<&Ast> {
self.path.get_or_err(crumb.index,"path").map_err(|err| err.into())
self.path.get(&crumb.0)
}
fn set(&self, crumb:&Self::Crumb, new_ast:Ast) -> FallibleResult<Self> {
let mut import = self.clone();
let path = import.path.get_mut_or_err(crumb.index,"path")?;
*path = new_ast;
import.path = self.path.set(&crumb.0,new_ast)?;
Ok(import)
}
fn iter_subcrumbs<'a>(&'a self) -> Box<dyn Iterator<Item = Self::Crumb> + 'a> {
let indices = self.path.iter().enumerate().map(|(indices,_)| indices);
let crumbs = indices.map(|path_index| ImportCrumb { index: path_index });
Box::new(crumbs)
Box::new(self.path.iter_subcrumbs().map(ImportCrumb::new))
}
}

View File

@ -754,7 +754,7 @@ pub enum MacroPatternMatchRaw<T> {
}
#[ast] pub struct Import<T> {
pub path: Vec<T> // Cons inside
pub path:T
}
#[ast] pub struct Mixfix<T> {

View File

@ -371,7 +371,7 @@ mod tests {
// === Import ===
fn make_import() -> Shape<Ast> {
Import {path : vec![]}.into()
Import {path : Ast::var("Target")}.into()
}
#[test]

View File

@ -25,7 +25,7 @@ use std::path::PathBuf;
const PARSER_PATH: &str = "./pkg/scala-parser.js";
/// Commit from `enso` repository that will be used to obtain parser from.
const PARSER_COMMIT: &str = "b105bc1f013f9c262102d8f59869c0a5617085d0";
const PARSER_COMMIT: &str = "157582b81edb1e02a91e7866fde7e0ae72d5570f";
/// Magic code that needs to be prepended to ScalaJS generated parser due to:
/// https://github.com/scala-js/scala-js/issues/3677/

View File

@ -27,7 +27,7 @@ fn import_utilities() {
assert!(ast_as_import_match(&ast).is_none());
};
expect_import("import");
// expect_import("import"); // TODO [mwu] https://github.com/enso-org/enso/issues/1016
expect_import("import Foo");
expect_import("import Foo.Bar");
expect_import("import Foo.Bar.Baz");

View File

@ -86,6 +86,7 @@ impl Fixture {
});
}
#[allow(dead_code)] // TODO [mwu] https://github.com/enso-org/enso/issues/1016
fn deserialize_unexpected(&mut self) {
let unexpected = "import";
let ast = self.parser.parse_line(unexpected).unwrap();
@ -396,7 +397,7 @@ impl Fixture {
self.blank_line_round_trip();
self.deserialize_metadata();
self.deserialize_unrecognized();
self.deserialize_unexpected();
//self.deserialize_unexpected(); // TODO [mwu] https://github.com/enso-org/enso/issues/1016
self.deserialize_invalid_quote();
self.deserialize_inline_block();
self.deserialize_blank();

View File

@ -1256,7 +1256,7 @@ main =
impl Case {
fn run(&self) {
let mut test = Fixture::set_up();
const MAIN_PREFIX:&str = "main = \n in = foo\n ";
const MAIN_PREFIX:&str = "main = \n var = foo\n ";
let main = format!("{}{}",MAIN_PREFIX,self.dest_node_expr);
let expected = format!("{}{}",MAIN_PREFIX,self.dest_node_expected);
let this = self.clone();
@ -1272,20 +1272,20 @@ main =
}
let cases = &
[ Case {dest_node_expr:"foo in" , dest_node_expected:"foo _" }
, Case {dest_node_expr:"foo in a" , dest_node_expected:"foo _ a" }
, Case {dest_node_expr:"foo a in" , dest_node_expected:"foo a" }
, Case {dest_node_expr:"in + a" , dest_node_expected:"_ + a" }
, Case {dest_node_expr:"a + in" , dest_node_expected:"a + _" }
, Case {dest_node_expr:"in + b + c" , dest_node_expected:"_ + b + c" }
, Case {dest_node_expr:"a + in + c" , dest_node_expected:"a + _ + c" }
, Case {dest_node_expr:"a + b + in" , dest_node_expected:"a + b" }
, Case {dest_node_expr:"in , a" , dest_node_expected:"_ , a" }
, Case {dest_node_expr:"a , in" , dest_node_expected:"a , _" }
, Case {dest_node_expr:"in , b , c" , dest_node_expected:"_ , b , c" }
, Case {dest_node_expr:"a , in , c" , dest_node_expected:"a , _ , c" }
, Case {dest_node_expr:"a , b , in" , dest_node_expected:"a , b" }
, Case {dest_node_expr:"f\n bar a in", dest_node_expected: "f\n bar a _"}
[ Case {dest_node_expr:"foo var" , dest_node_expected:"foo _" }
, Case {dest_node_expr:"foo var a" , dest_node_expected:"foo _ a" }
, Case {dest_node_expr:"foo a var" , dest_node_expected:"foo a" }
, Case {dest_node_expr:"var + a" , dest_node_expected:"_ + a" }
, Case {dest_node_expr:"a + var" , dest_node_expected:"a + _" }
, Case {dest_node_expr:"var + b + c" , dest_node_expected:"_ + b + c" }
, Case {dest_node_expr:"a + var + c" , dest_node_expected:"a + _ + c" }
, Case {dest_node_expr:"a + b + var" , dest_node_expected:"a + b" }
, Case {dest_node_expr:"var , a" , dest_node_expected:"_ , a" }
, Case {dest_node_expr:"a , var" , dest_node_expected:"a , _" }
, Case {dest_node_expr:"var , b , c" , dest_node_expected:"_ , b , c" }
, Case {dest_node_expr:"a , var , c" , dest_node_expected:"a , _ , c" }
, Case {dest_node_expr:"a , b , var" , dest_node_expected:"a , b" }
, Case {dest_node_expr:"f\n bar a var", dest_node_expected: "f\n bar a _"}
];
for case in cases {
case.run();

View File

@ -365,7 +365,8 @@ mod tests {
}
};
expect_imports("import", &[&[]]);
// TODO [mwu] waiting for fix https://github.com/enso-org/enso/issues/1016
// expect_imports("import", &[&[]]);
expect_imports("import Foo", &[&["Foo"]]);
expect_imports("import Foo.Bar", &[&["Foo","Bar"]]);
expect_imports("foo = bar\nimport Foo.Bar", &[&["Foo","Bar"]]);