Convert span's start to line number + col

This requires to make line numbers a first-class citizen in the module
  hierarchy but it is fortunately not _too involved_.
This commit is contained in:
KtorZ
2024-01-18 12:44:20 +01:00
parent e67d5863a1
commit 59c784778e
13 changed files with 165 additions and 26 deletions

View File

@@ -20,6 +20,7 @@ use crate::{
},
builtins::{bool, data, function, int, list, string, void},
expr::TypedExpr,
line_numbers::{LineColumn, LineNumbers},
tipo::{PatternConstructor, TypeVar, ValueConstructor, ValueConstructorVariant},
};
@@ -1775,9 +1776,9 @@ pub fn extract_constant(term: &Term<Name>) -> Option<Rc<UplcConstant>> {
pub fn get_src_code_by_span(
module_name: &String,
span: &Span,
module_src: &IndexMap<String, String>,
module_src: &IndexMap<String, (String, LineNumbers)>,
) -> String {
let src = module_src
let (src, _) = module_src
.get(module_name)
.unwrap_or_else(|| panic!("Missing module {module_name}"));
@@ -1786,6 +1787,20 @@ pub fn get_src_code_by_span(
.to_string()
}
pub fn get_line_columns_by_span(
module_name: &String,
span: &Span,
module_src: &IndexMap<String, (String, LineNumbers)>,
) -> LineColumn {
let (_, lines) = module_src
.get(module_name)
.unwrap_or_else(|| panic!("Missing module {module_name}"));
lines
.line_and_column_number(span.start)
.expect("Out of bounds span")
}
pub fn air_holds_msg(air: &Air) -> bool {
match air {
Air::AssertConstr { .. } | Air::AssertBool { .. } | Air::FieldsEmpty | Air::ListEmpty => {