From 4a900fd6815d3ea722b5e664aee9eac8bb9cb14f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Aug 2018 21:27:44 +0300 Subject: Split diagnostics --- src/ast/mod.rs | 6 +++++- src/lib.rs | 2 +- src/utils.rs | 4 ++-- src/yellow/builder.rs | 2 +- src/yellow/mod.rs | 3 +-- src/yellow/syntax.rs | 6 +++--- 6 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 317ed4f45..eeb7ae6f6 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -2,7 +2,7 @@ mod generated; use std::sync::Arc; use { - SyntaxNode, SyntaxRoot, TreeRoot, + SyntaxNode, SyntaxRoot, TreeRoot, SyntaxError, SyntaxKind::*, }; pub use self::generated::*; @@ -19,6 +19,10 @@ impl File> { } impl File { + pub fn errors(&self) -> Vec { + self.syntax().root.errors.clone() + } + pub fn functions<'a>(&'a self) -> impl Iterator> + 'a { self.syntax() .children() diff --git a/src/lib.rs b/src/lib.rs index d1e690bb2..ca33618a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ pub use { lexer::{tokenize, Token}, syntax_kinds::SyntaxKind, text_unit::{TextRange, TextUnit}, - yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot}, + yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError}, }; diff --git a/src/utils.rs b/src/utils.rs index a23a57423..1fbb872a5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -29,7 +29,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String { let off = node.range().end(); while err_pos < errors.len() && errors[err_pos].offset <= off { indent!(); - writeln!(buf, "err: `{}`", errors[err_pos].message).unwrap(); + writeln!(buf, "err: `{}`", errors[err_pos].msg).unwrap(); err_pos += 1; } } @@ -41,7 +41,7 @@ pub fn dump_tree(syntax: &SyntaxNode) -> String { assert_eq!(level, 0); for err in errors[err_pos..].iter() { - writeln!(buf, "err: `{}`", err.message).unwrap(); + writeln!(buf, "err: `{}`", err.msg).unwrap(); } return buf; diff --git a/src/yellow/builder.rs b/src/yellow/builder.rs index 878f3ba39..5e94e5055 100644 --- a/src/yellow/builder.rs +++ b/src/yellow/builder.rs @@ -51,7 +51,7 @@ impl<'a> Sink<'a> for GreenBuilder<'a> { fn error(&mut self, message: String) { self.errors.push(SyntaxError { - message, + msg: message, offset: self.pos, }) } diff --git a/src/yellow/mod.rs b/src/yellow/mod.rs index 1b5d4e4df..6129ecb99 100644 --- a/src/yellow/mod.rs +++ b/src/yellow/mod.rs @@ -3,10 +3,9 @@ mod green; mod red; mod syntax; -pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot}; +pub use self::syntax::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot, SyntaxError}; pub(crate) use self::{ builder::GreenBuilder, green::GreenNode, red::RedNode, - syntax::SyntaxError, }; diff --git a/src/yellow/syntax.rs b/src/yellow/syntax.rs index 07607ec2d..2ba9281fc 100644 --- a/src/yellow/syntax.rs +++ b/src/yellow/syntax.rs @@ -46,9 +46,9 @@ impl SyntaxRoot { } #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] -pub(crate) struct SyntaxError { - pub(crate) message: String, - pub(crate) offset: TextUnit, +pub struct SyntaxError { + pub msg: String, + pub offset: TextUnit, } impl SyntaxNode> { -- cgit v1.2.3