Skip to content

Commit

Permalink
Issue#7 numeric (#131)
Browse files Browse the repository at this point in the history
* adding drop possibility

* Add functionality drop type

* adding part of string as attribute

* adding string attr

* added grouped_parts

* added Quickfixes to add Type as attribute

* quickfix cardinality and attribute in one string

* fix Quickfix text

* quickfix endless while and error text

* added documentation

* drop constraint feature

* fixed drop function

* Adding default value for types

* adding sum() conversion

* adding enroll sum() feature

* fixing spelling and doku

* adding conversion for avg function

---------

Co-authored-by: Thilo Brugger <thilo.brugger@uni-ulm.de>
Co-authored-by: Chico Sundermann <chico.sundermann@uni-ulm.de>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent 11dd29c commit 6b3952d
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 24 deletions.
14 changes: 9 additions & 5 deletions uvls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ dashmap = "5.4.0"
tower-lsp = "0.19.0"
tokio = { version = "1", features = ["full"] }
ropey = "1.5.0"
flexi_logger = { version = "0.24", features = ["async", "specfile", "compress"] }
flexi_logger = { version = "0.24", features = [
"async",
"specfile",
"compress",
] }
log = "0.4"
lazy_static = "1.4.0"
parking_lot = "0.12.1"
Expand All @@ -29,17 +33,17 @@ stacker = "0.1.15"
strsim = "0.10.0"
min-max-heap = "1.3.0"
compact_str = "0.6.1"
ustr = {version = "0.9.0",features = ["serialization"]}
ustr = { version = "0.9.0", features = ["serialization"] }
pathfinding = "3.0.14"
log-panics = {version = "2.1.0", features=["with-backtrace"]}
log-panics = { version = "2.1.0", features = ["with-backtrace"] }
tokio-util = "0.7.4"
serde_json = "1.0"
walkdir = "2"
hashbrown = "0.14.3"
tree-sitter-uvl = {path="../tree-sitter-uvl"}
tree-sitter-json = {git="https://github.com/tree-sitter/tree-sitter-json", rev = "c5a9a9af069de3fe0ef5fa2fa001b6a2e44d75b2"}
hashbrown = "0.13.2"
regex = "1"
axum = {version = "0.6.6", features = ["ws"]}
axum = { version = "0.6.6", features = ["ws"] }
dioxus = { version = "*" }
dioxus-liveview = { version = "*", features = ["axum"] }
serde = "1.0.152"
Expand Down
46 changes: 33 additions & 13 deletions uvls/src/core/ast/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ fn opt_function_args(state: &mut VisitorState) -> Option<Vec<Path>> {
})
}

fn check_langlvls(state: &mut VisitorState, searched_lang_lvl: LanguageLevel) {
fn check_langlvls(state: &mut VisitorState, searched_lang_lvl: LanguageLevel, is_constraint: bool) {
if state.ast.includes.is_empty() {
// no includes means, that implicitly everything is included
return ();
Expand Down Expand Up @@ -690,14 +690,25 @@ fn check_langlvls(state: &mut VisitorState, searched_lang_lvl: LanguageLevel) {
LanguageLevelType::Any,
),
} {
state.push_error_with_type(
10,
format!(
"Operation does not correspond includes. Please include {:?}",
searched_lang_lvl
),
ErrorType::WrongLanguageLevel,
)
if is_constraint {
state.push_error_with_type(
10,
format!(
"Operation does not correspond includes. Please include {:?} or convert to the included language level.",
searched_lang_lvl
),
ErrorType::WrongLanguageLevelConstraint,
)
} else {
state.push_error_with_type(
10,
format!(
"Operation does not correspond includes. Please include {:?} or convert to the included language level.",
searched_lang_lvl
),
ErrorType::WrongLanguageLevel,
)
}
}
}

Expand Down Expand Up @@ -789,7 +800,7 @@ fn opt_numeric(state: &mut VisitorState) -> Option<ExprDecl> {
state.goto_field("lhs");
let lhs = opt_numeric(state)?;
state.goto_field("op");
check_langlvls(state, LanguageLevel::Arithmetic(vec![]));
check_langlvls(state, LanguageLevel::Arithmetic(vec![]), false);
state.goto_field("rhs");
let rhs = opt_numeric(state)?;
Some(Expr::Binary {
Expand All @@ -813,13 +824,15 @@ fn opt_numeric(state: &mut VisitorState) -> Option<ExprDecl> {
check_langlvls(
state,
LanguageLevel::Arithmetic(vec![LanguageLevelArithmetic::Aggregate]),
true,
);
opt_aggregate(state)
}
"len" => {
check_langlvls(
state,
LanguageLevel::Type(vec![LanguageLevelType::StringConstraints]),
true,
);
if state.child_by_name("tail").is_some() {
state.push_error(10, "tailing comma not allowed");
Expand All @@ -843,6 +856,7 @@ fn opt_numeric(state: &mut VisitorState) -> Option<ExprDecl> {
check_langlvls(
state,
LanguageLevel::Type(vec![LanguageLevelType::NumericConstraints]),
true,
);
opt_integer(state)
}
Expand Down Expand Up @@ -878,6 +892,8 @@ fn opt_equation(node: Node) -> Option<EquationOP> {
}

fn opt_constraint(state: &mut VisitorState) -> Option<ConstraintDecl> {
info!("first ---------sind in op-constraint");

let span = state.node().byte_range();
state.goto_named();
match state.kind() {
Expand All @@ -904,7 +920,8 @@ fn opt_constraint(state: &mut VisitorState) -> Option<ConstraintDecl> {
state.goto_field("lhs");
let lhs = opt_constraint(state)?;
state.goto_field("op");
check_langlvls(state, LanguageLevel::Boolean(vec![]));
info!("sind in op-constraint logic");
check_langlvls(state, LanguageLevel::Boolean(vec![]), true);
state.goto_field("rhs");
let rhs = opt_constraint(state)?;
Some(Constraint::Logic {
Expand All @@ -916,7 +933,8 @@ fn opt_constraint(state: &mut VisitorState) -> Option<ConstraintDecl> {
state.goto_field("lhs");
let lhs = opt_numeric(state)?;
state.goto_field("op");
check_langlvls(state, LanguageLevel::Arithmetic(vec![]));
info!("sind in op-constraint equation");
check_langlvls(state, LanguageLevel::Arithmetic(vec![]), true);
state.goto_field("rhs");
let rhs = opt_numeric(state)?;
Some(Constraint::Equation {
Expand Down Expand Up @@ -1080,6 +1098,7 @@ fn visit_feature(
check_langlvls(
state,
LanguageLevel::Arithmetic(vec![LanguageLevelArithmetic::FeatureCardinality]),
false,
);
opt_cardinality(n, state)
})
Expand Down Expand Up @@ -1191,7 +1210,7 @@ fn visit_blk_decl(state: &mut VisitorState, parent: Symbol, duplicate: &bool) {
visit_feature(state, parent, name, Type::Bool, *duplicate);
}
"typed_feature" => {
check_langlvls(state, LanguageLevel::Type(vec![]));
check_langlvls(state, LanguageLevel::Type(vec![]), false);
let (name, ty) = visit_children(state, |state| {
state.goto_field("type");
let ty = match &*state.slice_raw(state.node().byte_range()) {
Expand Down Expand Up @@ -1235,6 +1254,7 @@ fn visit_blk_decl(state: &mut VisitorState, parent: Symbol, duplicate: &bool) {
check_langlvls(
state,
LanguageLevel::Boolean(vec![LanguageLevelBoolean::GroupCardinality]),
false,
);
let card = opt_cardinality(state.node(), state).unwrap_or(Cardinality::Fixed);
visit_group(state, parent, GroupMode::Cardinality(card), duplicate);
Expand Down
2 changes: 2 additions & 0 deletions uvls/src/core/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ pub enum ErrorType {
AddIndentation,
StartsWithNumber,
WrongLanguageLevel,
WrongLanguageLevelConstraint,
}

impl ErrorType {
pub fn from_u32(value: u32) -> ErrorType {
match value {
6 => ErrorType::WrongLanguageLevelConstraint,
5 => ErrorType::WrongLanguageLevel,
4 => ErrorType::StartsWithNumber,
3 => ErrorType::AddIndentation,
Expand Down
23 changes: 23 additions & 0 deletions uvls/src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ pub fn byte_offset(pos: &Position, source: &Rope) -> usize {
source.char_to_byte(char_offset(pos, source))
}

pub fn byte_to_line_col(byte: usize, source: &Rope) -> Position {
let mut line = 0;
let mut col = 0;

for (index, ch) in source.chars().enumerate() {
if index == byte {
break;
}

if ch == '\n' {
line += 1;
col = 0;
} else {
col += 1;
}
}

Position {
line,
character: col,
}
}

pub fn containing_blk(mut node: Node) -> Option<Node> {
node = node.parent()?;
while node.kind() != "blk" {
Expand Down
Loading

0 comments on commit 6b3952d

Please sign in to comment.