Skip to content

Commit

Permalink
Implement AST transformer
Browse files Browse the repository at this point in the history
Summary:
Implement an eqWAlizer AST transformer in ELP, based on the AST visitor already implemented.

Add `preprocess` module implementing (for now) the default implementation of the transformer, which is called on every AST/stub going through ELP.

Reviewed By: RobinMorisset

Differential Revision: D60584098

fbshipit-source-id: 52f1a705e2c3616cc08921898276dc345dec9986
  • Loading branch information
VLanvin authored and facebook-github-bot committed Aug 20, 2024
1 parent ed89ea0 commit 16eef67
Show file tree
Hide file tree
Showing 4 changed files with 797 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/eqwalizer/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod convert;
pub mod convert_types;
pub mod db;
pub mod expand;
pub mod preprocess;
pub mod stub;
pub mod subst;
pub mod trans_valid;
Expand Down Expand Up @@ -205,7 +206,8 @@ pub fn from_bytes(bytes: &Vec<u8>) -> Result<AST, Error> {
if let Term::Tuple(res) = term {
if let [Term::Atom(ok), forms, _] = &res.elements[..] {
if ok.name == "ok" {
return Ok(convert::convert_forms(forms, false, false)?);
let converted_forms = convert::convert_forms(forms, false, false)?;
return Ok(preprocess::preprocess(converted_forms));
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions crates/eqwalizer/src/ast/preprocess.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under both the MIT license found in the
* LICENSE-MIT file in the root directory of this source tree and the Apache
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory
* of this source tree.
*/

use elp_types_db::eqwalizer::transformer::Transformer;
use elp_types_db::eqwalizer::AST;

struct Preprocessor {}

impl Transformer<()> for Preprocessor {}

pub(crate) fn preprocess(ast: AST) -> AST {
let mut preprocessor = Preprocessor {};
preprocessor.transform_ast(ast).unwrap()
}
1 change: 1 addition & 0 deletions crates/types_db/src/eqwalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod guard;
pub mod invalid_diagnostics;
pub mod pat;
pub mod tc_diagnostics;
pub mod transformer;
pub mod types;
pub mod visitor;

Expand Down
Loading

0 comments on commit 16eef67

Please sign in to comment.