Skip to content

Commit

Permalink
Better handling of sierra text. (#6950)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Dec 29, 2024
1 parent cc66986 commit 62add07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions crates/bin/sierra-compile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cairo_lang_sierra_to_casm::compiler::SierraToCasmConfig;
use cairo_lang_sierra_to_casm::metadata::calc_metadata;
use cairo_lang_utils::logging::init_logging;
use clap::Parser;
use indoc::indoc;
use indoc::formatdoc;

/// Compiles a Sierra file to CASM.
/// Exits with 0/1 if the compilation succeeds/fails.
Expand All @@ -25,11 +25,14 @@ fn main() -> anyhow::Result<()> {
let args = Args::parse();

let sierra_code = fs::read_to_string(args.file).with_context(|| "Could not read file!")?;
let Ok(program) = ProgramParser::new().parse(&sierra_code) else {
anyhow::bail!(indoc! {"
Failed to parse sierra program.
let program = match ProgramParser::new().parse(&sierra_code) {
Ok(program) => program,
Err(err) => {
anyhow::bail!(formatdoc! {"
Failed to parse sierra program with: `{err:?}`.
Note: StarkNet contracts should be compiled with `starknet-sierra-compile`."
})
})
}
};

let cairo_program = cairo_lang_sierra_to_casm::compiler::compile(
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-sierra/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ GenericTypeId: GenericTypeId = {

ConcreteTypeId: ConcreteTypeId = {
<id:ConcreteLabel> => ConcreteTypeId::from_string(id),
"@" <id:ConcreteLabel> => ConcreteTypeId::from_string(format!("@{id}")),
"@" <ty:ConcreteTypeId> => ConcreteTypeId::from_string(format!("@{ty}")),
"[" <id:UnsignedInt> "]" => ConcreteTypeId::new(id),
"[" <ty:ConcreteTypeId> ";" <count:UnsignedInt> "]" =>
ConcreteTypeId::from_string(format!("[{ty}; {count}]")),
Expand Down

0 comments on commit 62add07

Please sign in to comment.