Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions clarity/src/vm/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use stacks_common::types::StacksEpochId;
use self::definition_sorter::DefinitionSorter;
use self::errors::ParseResult;
use self::expression_identifier::ExpressionIdentifier;
#[cfg(not(feature = "devtools"))]
use self::parser::v1::parse as parse_v1;
use self::parser::v2::parse as parse_v2;
use self::stack_depth_checker::{StackDepthChecker, VaryStackDepthChecker};
Expand Down Expand Up @@ -58,12 +59,21 @@ pub fn parse(
/// Parse a program based on which epoch is active
fn parse_in_epoch(
source_code: &str,
epoch_id: StacksEpochId,
// the epoch_id argument can be removed as part of #3662 (removing parser v1)
#[allow(unused_variables)] epoch_id: StacksEpochId,
) -> ParseResult<Vec<PreSymbolicExpression>> {
if epoch_id >= StacksEpochId::Epoch21 {
#[cfg(feature = "devtools")]
{
parse_v2(source_code)
} else {
parse_v1(source_code)
}

#[cfg(not(feature = "devtools"))]
{
if epoch_id >= StacksEpochId::Epoch21 {
parse_v2(source_code)
} else {
parse_v1(source_code)
}
}
}

Expand Down Expand Up @@ -111,7 +121,8 @@ fn inner_build_ast<T: CostTracker>(
source_code: &str,
cost_track: &mut T,
clarity_version: ClarityVersion,
epoch: StacksEpochId,
// the epoch_id argument can be removed as part of #3662 (removing parser v1)
#[allow(unused_variables)] epoch: StacksEpochId,
error_early: bool,
) -> ParseResult<(ContractAST, Vec<Diagnostic>, bool)> {
let cost_err = match runtime_cost(
Expand All @@ -124,9 +135,18 @@ fn inner_build_ast<T: CostTracker>(
_ => None,
};

#[cfg(feature = "devtools")]
let (pre_expressions, mut diagnostics, mut success) = if error_early {
let exprs = parse_v2(source_code)?;
(exprs, Vec::new(), true)
} else {
parser::v2::parse_collect_diagnostics(source_code)
};

#[cfg(not(feature = "devtools"))]
let (pre_expressions, mut diagnostics, mut success) = if epoch >= StacksEpochId::Epoch21 {
if error_early {
let exprs = parser::v2::parse(source_code)?;
let exprs = parse_v2(source_code)?;
(exprs, Vec::new(), true)
} else {
parser::v2::parse_collect_diagnostics(source_code)
Expand Down