We now canonicalize imported asts before inlining

This commit is contained in:
gluaxspeed 2021-07-22 12:40:12 -07:00
parent 63f82c9f68
commit 36aff9fbf8
3 changed files with 15 additions and 5 deletions

View File

@ -17,7 +17,7 @@
//! Errors encountered when attempting to convert to an asg from an ast.
use crate::Span;
use leo_ast::{FormattedError, LeoError};
use leo_ast::{AstError, FormattedError, LeoError};
use leo_parser::SyntaxError;
#[derive(Debug, Error)]
@ -28,6 +28,9 @@ pub enum AsgConvertError {
#[error("{}", _0)]
ImportError(FormattedError),
#[error("{}", _0)]
AstError(#[from] AstError),
#[error("{}", _0)]
InternalError(String),

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_asg::AsgConvertError;
use leo_ast::{FormattedError, Identifier, LeoError, Span};
use leo_ast::{AstError, FormattedError, Identifier, LeoError, Span};
use leo_parser::SyntaxError;
use std::{io, path::Path};
@ -26,6 +26,10 @@ pub enum ImportParserError {
#[error("{}", _0)]
SyntaxError(#[from] SyntaxError),
#[error("{}", _0)]
AstError(#[from] AstError),
#[error("{}", _0)]
AsgConvertError(#[from] AsgConvertError),
}
@ -37,6 +41,7 @@ impl Into<AsgConvertError> for ImportParserError {
match self {
ImportParserError::Error(x) => AsgConvertError::ImportError(x),
ImportParserError::SyntaxError(x) => x.into(),
ImportParserError::AstError(x) => AsgConvertError::AstError(x),
ImportParserError::AsgConvertError(x) => x,
}
}

View File

@ -54,8 +54,10 @@ impl<'a> ImportParser<'a> {
// Build the package abstract syntax tree.
let program_string =
&std::fs::read_to_string(&file_path).map_err(|x| ImportParserError::io_error(span, file_path_str, x))?;
let mut ast = leo_parser::parse(&file_path_str, &program_string)?;
ast.name = file_name;
Ok(ast)
let mut program = leo_parser::parse(&file_path_str, &program_string)?;
program.name = file_name;
let mut ast = leo_ast::Ast::new(program);
ast.canonicalize()?;
Ok(ast.into_repr())
}
}