aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/src/main.rs19
-rw-r--r--src/algo/walk.rs7
-rw-r--r--src/ast.rs8
-rw-r--r--src/lib.rs13
-rw-r--r--src/parser/grammar/expressions.rs2
-rw-r--r--src/parser/grammar/items/mod.rs1
-rw-r--r--src/parser/grammar/items/traits.rs1
-rw-r--r--src/parser/grammar/mod.rs7
-rw-r--r--src/parser/grammar/paths.rs8
-rw-r--r--src/parser/grammar/patterns.rs7
-rw-r--r--src/parser/grammar/type_args.rs2
-rw-r--r--src/utils.rs6
-rw-r--r--src/yellow/green.rs12
-rw-r--r--src/yellow/mod.rs2
-rw-r--r--src/yellow/red.rs5
-rw-r--r--src/yellow/syntax.rs12
-rw-r--r--tests/testutils/src/lib.rs2
-rw-r--r--tools/src/lib.rs11
-rw-r--r--tools/src/main.rs34
19 files changed, 94 insertions, 65 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index f87878137..546cbb66b 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -4,8 +4,8 @@ extern crate failure;
4extern crate libsyntax2; 4extern crate libsyntax2;
5extern crate tools; 5extern crate tools;
6 6
7use std::{fs, path::Path, io::Read};
8use clap::{App, Arg, SubCommand}; 7use clap::{App, Arg, SubCommand};
8use std::{fs, io::Read, path::Path};
9use tools::collect_tests; 9use tools::collect_tests;
10 10
11type Result<T> = ::std::result::Result<T, failure::Error>; 11type Result<T> = ::std::result::Result<T, failure::Error>;
@@ -15,8 +15,18 @@ fn main() -> Result<()> {
15 .setting(clap::AppSettings::SubcommandRequiredElseHelp) 15 .setting(clap::AppSettings::SubcommandRequiredElseHelp)
16 .subcommand( 16 .subcommand(
17 SubCommand::with_name("render-test") 17 SubCommand::with_name("render-test")
18 .arg(Arg::with_name("line").long("--line").required(true).takes_value(true)) 18 .arg(
19 .arg(Arg::with_name("file").long("--file").required(true).takes_value(true)) 19 Arg::with_name("line")
20 .long("--line")
21 .required(true)
22 .takes_value(true),
23 )
24 .arg(
25 Arg::with_name("file")
26 .long("--file")
27 .required(true)
28 .takes_value(true),
29 ),
20 ) 30 )
21 .subcommand(SubCommand::with_name("parse")) 31 .subcommand(SubCommand::with_name("parse"))
22 .get_matches(); 32 .get_matches();
@@ -24,7 +34,7 @@ fn main() -> Result<()> {
24 ("parse", _) => { 34 ("parse", _) => {
25 let tree = parse()?; 35 let tree = parse()?;
26 println!("{}", tree); 36 println!("{}", tree);
27 }, 37 }
28 ("render-test", Some(matches)) => { 38 ("render-test", Some(matches)) => {
29 let file = matches.value_of("file").unwrap(); 39 let file = matches.value_of("file").unwrap();
30 let file = Path::new(file); 40 let file = Path::new(file);
@@ -36,7 +46,6 @@ fn main() -> Result<()> {
36 _ => unreachable!(), 46 _ => unreachable!(),
37 } 47 }
38 Ok(()) 48 Ok(())
39
40} 49}
41 50
42fn parse() -> Result<String> { 51fn parse() -> Result<String> {
diff --git a/src/algo/walk.rs b/src/algo/walk.rs
index 86dd82cc9..c6d050251 100644
--- a/src/algo/walk.rs
+++ b/src/algo/walk.rs
@@ -1,6 +1,6 @@
1use SyntaxNodeRef; 1use SyntaxNodeRef;
2 2
3pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item=SyntaxNodeRef<'a>> { 3pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = SyntaxNodeRef<'a>> {
4 walk(root).filter_map(|event| match event { 4 walk(root).filter_map(|event| match event {
5 WalkEvent::Enter(node) => Some(node), 5 WalkEvent::Enter(node) => Some(node),
6 WalkEvent::Exit(_) => None, 6 WalkEvent::Exit(_) => None,
@@ -13,7 +13,7 @@ enum WalkEvent<'a> {
13 Exit(SyntaxNodeRef<'a>), 13 Exit(SyntaxNodeRef<'a>),
14} 14}
15 15
16fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item=WalkEvent<'a>> { 16fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = WalkEvent<'a>> {
17 let mut done = false; 17 let mut done = false;
18 ::itertools::unfold(WalkEvent::Enter(root), move |pos| { 18 ::itertools::unfold(WalkEvent::Enter(root), move |pos| {
19 if done { 19 if done {
@@ -35,7 +35,7 @@ fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item=WalkEvent<'a>> {
35 None => match node.parent() { 35 None => match node.parent() {
36 Some(node) => WalkEvent::Exit(node), 36 Some(node) => WalkEvent::Exit(node),
37 None => WalkEvent::Exit(node), 37 None => WalkEvent::Exit(node),
38 } 38 },
39 } 39 }
40 } 40 }
41 } 41 }
@@ -43,4 +43,3 @@ fn walk<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item=WalkEvent<'a>> {
43 Some(res) 43 Some(res)
44 }) 44 })
45} 45}
46
diff --git a/src/ast.rs b/src/ast.rs
index b513eb13e..48e1d23ac 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -1,14 +1,16 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use {SyntaxNode, TreeRoot, SyntaxRoot}; 2use {SyntaxNode, SyntaxRoot, TreeRoot};
3 3
4#[derive(Debug)] 4#[derive(Debug)]
5pub struct File<R: TreeRoot = Arc<SyntaxRoot>> { 5pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
6 syntax: SyntaxNode<R> 6 syntax: SyntaxNode<R>,
7} 7}
8 8
9impl File<Arc<SyntaxRoot>> { 9impl File<Arc<SyntaxRoot>> {
10 pub fn parse(text: &str) -> Self { 10 pub fn parse(text: &str) -> Self {
11 File { syntax: ::parse(text.to_owned()) } 11 File {
12 syntax: ::parse(text.to_owned()),
13 }
12 } 14 }
13} 15}
14 16
diff --git a/src/lib.rs b/src/lib.rs
index 9049beb29..953c9b860 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,25 +20,25 @@
20#![allow(missing_docs)] 20#![allow(missing_docs)]
21//#![warn(unreachable_pub)] // rust-lang/rust#47816 21//#![warn(unreachable_pub)] // rust-lang/rust#47816
22 22
23extern crate itertools;
23extern crate text_unit; 24extern crate text_unit;
24extern crate unicode_xid; 25extern crate unicode_xid;
25extern crate itertools;
26 26
27pub mod algo;
28pub mod ast;
27mod lexer; 29mod lexer;
28mod parser; 30mod parser;
29mod syntax_kinds; 31mod syntax_kinds;
30mod yellow;
31/// Utilities for simple uses of the parser. 32/// Utilities for simple uses of the parser.
32pub mod utils; 33pub mod utils;
33pub mod ast; 34mod yellow;
34pub mod algo;
35 35
36pub use { 36pub use {
37 ast::File,
37 lexer::{tokenize, Token}, 38 lexer::{tokenize, Token},
38 syntax_kinds::SyntaxKind, 39 syntax_kinds::SyntaxKind,
39 text_unit::{TextRange, TextUnit}, 40 text_unit::{TextRange, TextUnit},
40 yellow::{SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxRoot}, 41 yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot},
41 ast::File,
42}; 42};
43 43
44pub(crate) use yellow::SyntaxError; 44pub(crate) use yellow::SyntaxError;
@@ -47,4 +47,3 @@ pub fn parse(text: String) -> SyntaxNode {
47 let tokens = tokenize(&text); 47 let tokens = tokenize(&text);
48 parser::parse::<yellow::GreenBuilder>(text, &tokens) 48 parser::parse::<yellow::GreenBuilder>(text, &tokens)
49} 49}
50
diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs
index a6456c8d5..11bb3436b 100644
--- a/src/parser/grammar/expressions.rs
+++ b/src/parser/grammar/expressions.rs
@@ -39,7 +39,7 @@ pub(super) fn expr(p: &mut Parser) {
39fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> { 39fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> {
40 match p.current() { 40 match p.current() {
41 AMPERSAND => Some(ref_expr(p)), 41 AMPERSAND => Some(ref_expr(p)),
42 _ => atom_expr(p) 42 _ => atom_expr(p),
43 } 43 }
44} 44}
45 45
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index 0d9eccd2f..9147df87d 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -218,7 +218,6 @@ fn extern_block(p: &mut Parser) {
218 p.expect(R_CURLY); 218 p.expect(R_CURLY);
219} 219}
220 220
221
222fn fn_item(p: &mut Parser) { 221fn fn_item(p: &mut Parser) {
223 assert!(p.at(FN_KW)); 222 assert!(p.at(FN_KW));
224 p.bump(); 223 p.bump();
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs
index c7450b761..812cacfb7 100644
--- a/src/parser/grammar/items/traits.rs
+++ b/src/parser/grammar/items/traits.rs
@@ -8,7 +8,6 @@ pub(super) fn trait_item(p: &mut Parser) {
8 p.expect(R_CURLY); 8 p.expect(R_CURLY);
9} 9}
10 10
11
12// test impl_item 11// test impl_item
13// impl Foo {} 12// impl Foo {}
14pub(super) fn impl_item(p: &mut Parser) { 13pub(super) fn impl_item(p: &mut Parser) {
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs
index c2da775a2..498b45d44 100644
--- a/src/parser/grammar/mod.rs
+++ b/src/parser/grammar/mod.rs
@@ -26,12 +26,15 @@ mod expressions;
26mod items; 26mod items;
27mod paths; 27mod paths;
28mod patterns; 28mod patterns;
29mod type_params;
30mod type_args; 29mod type_args;
30mod type_params;
31mod types; 31mod types;
32 32
33use { 33use {
34 parser::{parser::{Parser, CompletedMarker}, token_set::TokenSet}, 34 parser::{
35 parser::{CompletedMarker, Parser},
36 token_set::TokenSet,
37 },
35 SyntaxKind::{self, *}, 38 SyntaxKind::{self, *},
36}; 39};
37 40
diff --git a/src/parser/grammar/paths.rs b/src/parser/grammar/paths.rs
index 69ed84665..6f66701ac 100644
--- a/src/parser/grammar/paths.rs
+++ b/src/parser/grammar/paths.rs
@@ -20,7 +20,11 @@ pub(super) fn expr_path(p: &mut Parser) {
20} 20}
21 21
22#[derive(Clone, Copy, Eq, PartialEq)] 22#[derive(Clone, Copy, Eq, PartialEq)]
23enum Mode { Use, Type, Expr } 23enum Mode {
24 Use,
25 Type,
26 Expr,
27}
24 28
25fn path(p: &mut Parser, mode: Mode) { 29fn path(p: &mut Parser, mode: Mode) {
26 if !is_path_start(p) { 30 if !is_path_start(p) {
@@ -55,7 +59,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
55 IDENT => { 59 IDENT => {
56 name_ref(p); 60 name_ref(p);
57 path_generic_args(p, mode); 61 path_generic_args(p, mode);
58 }, 62 }
59 SELF_KW | SUPER_KW => p.bump(), 63 SELF_KW | SUPER_KW => p.bump(),
60 _ => { 64 _ => {
61 p.error("expected identifier"); 65 p.error("expected identifier");
diff --git a/src/parser/grammar/patterns.rs b/src/parser/grammar/patterns.rs
index a5d13a124..7216807fd 100644
--- a/src/parser/grammar/patterns.rs
+++ b/src/parser/grammar/patterns.rs
@@ -43,11 +43,8 @@ fn ref_pat(p: &mut Parser) {
43// } 43// }
44fn bind_pat(p: &mut Parser) { 44fn bind_pat(p: &mut Parser) {
45 let m = p.start(); 45 let m = p.start();
46 if p.eat(REF_KW) { 46 p.eat(REF_KW);
47 p.eat(MUT_KW); 47 p.eat(MUT_KW);
48 } else {
49 p.eat(MUT_KW);
50 }
51 name(p); 48 name(p);
52 if p.eat(AT) { 49 if p.eat(AT) {
53 pattern(p); 50 pattern(p);
diff --git a/src/parser/grammar/type_args.rs b/src/parser/grammar/type_args.rs
index 20e75b4b0..adac73e7e 100644
--- a/src/parser/grammar/type_args.rs
+++ b/src/parser/grammar/type_args.rs
@@ -12,7 +12,7 @@ pub(super) fn list(p: &mut Parser, colon_colon_required: bool) {
12 m = p.start(); 12 m = p.start();
13 p.bump(); 13 p.bump();
14 } 14 }
15 _ => return 15 _ => return,
16 }; 16 };
17 17
18 while !p.at(EOF) && !p.at(R_ANGLE) { 18 while !p.at(EOF) && !p.at(R_ANGLE) {
diff --git a/src/utils.rs b/src/utils.rs
index 826a7d60b..f99d31b36 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -16,7 +16,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String {
16 errors: &mut BTreeSet<SyntaxError>, 16 errors: &mut BTreeSet<SyntaxError>,
17 ) { 17 ) {
18 buff.push_str(&String::from(" ").repeat(level)); 18 buff.push_str(&String::from(" ").repeat(level));
19 write!(buff, "{:?}\n", node).unwrap(); 19 writeln!(buff, "{:?}", node).unwrap();
20 let my_errors: Vec<_> = errors 20 let my_errors: Vec<_> = errors
21 .iter() 21 .iter()
22 .filter(|e| e.offset == node.range().start()) 22 .filter(|e| e.offset == node.range().start())
@@ -25,7 +25,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String {
25 for err in my_errors { 25 for err in my_errors {
26 errors.remove(&err); 26 errors.remove(&err);
27 buff.push_str(&String::from(" ").repeat(level)); 27 buff.push_str(&String::from(" ").repeat(level));
28 write!(buff, "err: `{}`\n", err.message).unwrap(); 28 writeln!(buff, "err: `{}`", err.message).unwrap();
29 } 29 }
30 30
31 for child in node.children() { 31 for child in node.children() {
@@ -40,7 +40,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String {
40 for err in my_errors { 40 for err in my_errors {
41 errors.remove(&err); 41 errors.remove(&err);
42 buff.push_str(&String::from(" ").repeat(level)); 42 buff.push_str(&String::from(" ").repeat(level));
43 write!(buff, "err: `{}`\n", err.message).unwrap(); 43 writeln!(buff, "err: `{}`", err.message).unwrap();
44 } 44 }
45 } 45 }
46} 46}
diff --git a/src/yellow/green.rs b/src/yellow/green.rs
index cda4e2167..8ddcc74b8 100644
--- a/src/yellow/green.rs
+++ b/src/yellow/green.rs
@@ -80,8 +80,14 @@ fn assert_send_sync() {
80 80
81#[derive(Clone, Debug)] 81#[derive(Clone, Debug)]
82pub(crate) enum GreenLeaf { 82pub(crate) enum GreenLeaf {
83 Whitespace { newlines: u8, spaces: u8 }, 83 Whitespace {
84 Token { kind: SyntaxKind, text: Option<Arc<str>> }, 84 newlines: u8,
85 spaces: u8,
86 },
87 Token {
88 kind: SyntaxKind,
89 text: Option<Arc<str>>,
90 },
85} 91}
86 92
87impl GreenLeaf { 93impl GreenLeaf {
@@ -121,7 +127,7 @@ impl GreenLeaf {
121 assert!(newlines <= N_NEWLINES && spaces <= N_SPACES); 127 assert!(newlines <= N_NEWLINES && spaces <= N_SPACES);
122 &WS[N_NEWLINES - newlines..N_NEWLINES + spaces] 128 &WS[N_NEWLINES - newlines..N_NEWLINES + spaces]
123 } 129 }
124 GreenLeaf::Token { kind, text, } => match text { 130 GreenLeaf::Token { kind, text } => match text {
125 None => kind.static_text().unwrap(), 131 None => kind.static_text().unwrap(),
126 Some(t) => t, 132 Some(t) => t,
127 }, 133 },
diff --git a/src/yellow/mod.rs b/src/yellow/mod.rs
index 0cc90adbd..f20be356d 100644
--- a/src/yellow/mod.rs
+++ b/src/yellow/mod.rs
@@ -8,5 +8,5 @@ pub(crate) use self::{
8 builder::GreenBuilder, 8 builder::GreenBuilder,
9 green::{GreenNode, GreenNodeBuilder}, 9 green::{GreenNode, GreenNodeBuilder},
10 red::RedNode, 10 red::RedNode,
11 syntax::{SyntaxError}, 11 syntax::SyntaxError,
12}; 12};
diff --git a/src/yellow/red.rs b/src/yellow/red.rs
index a30318c6e..c3d6c5f4f 100644
--- a/src/yellow/red.rs
+++ b/src/yellow/red.rs
@@ -36,7 +36,8 @@ impl RedNode {
36 36
37 fn new(green: GreenNode, parent: Option<ParentData>) -> RedNode { 37 fn new(green: GreenNode, parent: Option<ParentData>) -> RedNode {
38 let n_children = green.children().len(); 38 let n_children = green.children().len();
39 let children = (0..n_children).map(|_| None) 39 let children = (0..n_children)
40 .map(|_| None)
40 .collect::<Vec<_>>() 41 .collect::<Vec<_>>()
41 .into_boxed_slice(); 42 .into_boxed_slice();
42 RedNode { 43 RedNode {
@@ -63,7 +64,7 @@ impl RedNode {
63 64
64 pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> { 65 pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> {
65 if idx >= self.n_children() { 66 if idx >= self.n_children() {
66 return None 67 return None;
67 } 68 }
68 match &self.children.read().unwrap()[idx] { 69 match &self.children.read().unwrap()[idx] {
69 Some(child) => return Some(child.into()), 70 Some(child) => return Some(child.into()),
diff --git a/src/yellow/syntax.rs b/src/yellow/syntax.rs
index 41dcf3761..487a4ef1d 100644
--- a/src/yellow/syntax.rs
+++ b/src/yellow/syntax.rs
@@ -6,7 +6,7 @@ use {
6 TextRange, TextUnit, 6 TextRange, TextUnit,
7}; 7};
8 8
9pub trait TreeRoot: Deref<Target=SyntaxRoot> + Clone {} 9pub trait TreeRoot: Deref<Target = SyntaxRoot> + Clone {}
10 10
11impl TreeRoot for Arc<SyntaxRoot> {} 11impl TreeRoot for Arc<SyntaxRoot> {}
12 12
@@ -83,14 +83,12 @@ impl<R: TreeRoot> SyntaxNode<R> {
83 self.red().green().text() 83 self.red().green().text()
84 } 84 }
85 85
86 pub fn children<'a>(&'a self) -> impl Iterator<Item=SyntaxNode<R>> + 'a { 86 pub fn children<'a>(&'a self) -> impl Iterator<Item = SyntaxNode<R>> + 'a {
87 let red = self.red(); 87 let red = self.red();
88 let n_children = red.n_children(); 88 let n_children = red.n_children();
89 (0..n_children).map(move |i| { 89 (0..n_children).map(move |i| SyntaxNode {
90 SyntaxNode { 90 root: self.root.clone(),
91 root: self.root.clone(), 91 red: red.get_child(i).unwrap(),
92 red: red.get_child(i).unwrap(),
93 }
94 }) 92 })
95 } 93 }
96 94
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs
index 7c481156f..deeb707d3 100644
--- a/tests/testutils/src/lib.rs
+++ b/tests/testutils/src/lib.rs
@@ -2,7 +2,7 @@ extern crate difference;
2 2
3use std::{ 3use std::{
4 fs, 4 fs,
5 path::{Path, PathBuf} 5 path::{Path, PathBuf},
6}; 6};
7 7
8use difference::Changeset; 8use difference::Changeset;
diff --git a/tools/src/lib.rs b/tools/src/lib.rs
index 21a9468bc..5a7d846ff 100644
--- a/tools/src/lib.rs
+++ b/tools/src/lib.rs
@@ -1,7 +1,7 @@
1extern crate itertools; 1extern crate itertools;
2 2
3use std::hash;
4use itertools::Itertools; 3use itertools::Itertools;
4use std::hash;
5 5
6#[derive(Debug)] 6#[derive(Debug)]
7pub struct Test { 7pub struct Test {
@@ -28,18 +28,17 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
28 match block.next() { 28 match block.next() {
29 Some((idx, line)) if line.starts_with("test ") => { 29 Some((idx, line)) if line.starts_with("test ") => {
30 break (idx, line["test ".len()..].to_string()) 30 break (idx, line["test ".len()..].to_string())
31 }, 31 }
32 Some(_) => (), 32 Some(_) => (),
33 None => continue 'outer, 33 None => continue 'outer,
34 } 34 }
35 }; 35 };
36 let text: String = itertools::join( 36 let text: String = itertools::join(
37 block.map(|(_, line)| line) 37 block.map(|(_, line)| line).chain(::std::iter::once("")),
38 .chain(::std::iter::once("")), 38 "\n",
39 "\n"
40 ); 39 );
41 assert!(!text.trim().is_empty() && text.ends_with("\n")); 40 assert!(!text.trim().is_empty() && text.ends_with("\n"));
42 res.push((start_line, Test {name, text })) 41 res.push((start_line, Test { name, text }))
43 } 42 }
44 res 43 res
45} 44}
diff --git a/tools/src/main.rs b/tools/src/main.rs
index 3acb6e7ed..7c6c7a1aa 100644
--- a/tools/src/main.rs
+++ b/tools/src/main.rs
@@ -3,13 +3,17 @@ extern crate clap;
3extern crate failure; 3extern crate failure;
4extern crate ron; 4extern crate ron;
5extern crate tera; 5extern crate tera;
6extern crate walkdir;
7extern crate tools; 6extern crate tools;
7extern crate walkdir;
8#[macro_use] 8#[macro_use]
9extern crate commandspec; 9extern crate commandspec;
10 10
11use std::{collections::{HashMap}, fs, path::{Path, PathBuf}};
12use clap::{App, Arg, SubCommand}; 11use clap::{App, Arg, SubCommand};
12use std::{
13 collections::HashMap,
14 fs,
15 path::{Path, PathBuf},
16};
13use tools::{collect_tests, Test}; 17use tools::{collect_tests, Test};
14 18
15type Result<T> = ::std::result::Result<T, failure::Error>; 19type Result<T> = ::std::result::Result<T, failure::Error>;
@@ -71,7 +75,8 @@ fn get_kinds() -> Result<String> {
71 tera.add_raw_template("grammar", &template) 75 tera.add_raw_template("grammar", &template)
72 .map_err(|e| format_err!("template error: {:?}", e))?; 76 .map_err(|e| format_err!("template error: {:?}", e))?;
73 tera.register_global_function("concat", Box::new(concat)); 77 tera.register_global_function("concat", Box::new(concat));
74 let ret = tera.render("grammar", &grammar) 78 let ret = tera
79 .render("grammar", &grammar)
75 .map_err(|e| format_err!("template error: {:?}", e))?; 80 .map_err(|e| format_err!("template error: {:?}", e))?;
76 return Ok(ret); 81 return Ok(ret);
77 82
@@ -157,7 +162,10 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> {
157 file_name[5..file_name.len() - 3].to_string() 162 file_name[5..file_name.len() - 3].to_string()
158 }; 163 };
159 let text = fs::read_to_string(&path)?; 164 let text = fs::read_to_string(&path)?;
160 let test = Test { name: name.clone(), text }; 165 let test = Test {
166 name: name.clone(),
167 text,
168 };
161 match res.insert(name, (path, test)) { 169 match res.insert(name, (path, test)) {
162 Some(old) => println!("Duplicate test: {:?}", old), 170 Some(old) => println!("Duplicate test: {:?}", old),
163 None => (), 171 None => (),
@@ -167,17 +175,23 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> {
167} 175}
168 176
169fn install_code_extension() -> Result<()> { 177fn install_code_extension() -> Result<()> {
170 execute!(r" 178 execute!(
179 r"
171cd code 180cd code
172npm install 181npm install
173 ")?; 182 "
174 execute!(r" 183 )?;
184 execute!(
185 r"
175cd code 186cd code
176./node_modules/vsce/out/vsce package 187./node_modules/vsce/out/vsce package
177 ")?; 188 "
178 execute!(r" 189 )?;
190 execute!(
191 r"
179cd code 192cd code
180code --install-extension ./libsyntax-rust-0.0.1.vsix 193code --install-extension ./libsyntax-rust-0.0.1.vsix
181 ")?; 194 "
195 )?;
182 Ok(()) 196 Ok(())
183} 197}