Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand parser support and highlight supported grammar. #2

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/s0_lexer/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub enum Token {
Identifier(String),

#[regex("\"[ _0-9a-zA-Z]*\"", quoted_string_callback)]
Description(String),
String(String),

#[regex("[1-9][0-9]*", |lex| lex.slice().parse::<i64>().unwrap(), priority=3)]
UnsignedInteger(i64),
Expand Down
94 changes: 71 additions & 23 deletions src/s1_parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,53 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct StoredDefinition {
pub classes: Vec<ClassDefinition>,
pub within: Option<Name>,
pub model_md5: String,
pub rumoca_git_hash: String,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[allow(clippy::vec_box)]
pub struct ComponentDeclaration {
pub declaration: Declaration,
pub condition_attribute: Option<Box<Expression>>,
pub description: Description,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[allow(clippy::vec_box)]
pub struct ComponentDeclaration1 {
pub declaration: Declaration,
pub description: Description,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ClassPrefixes {
pub is_partial: bool,
pub class_type: ClassType,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ClassSpecifier {
pub name: String,
pub class: String,
pub connection: Connection,
pub variability: Variability,
pub causality: Causality,
pub array_subscripts: Vec<Subscript>,
pub modification: Option<Modification>,
pub description: Vec<String>,
pub composition: Vec<CompositionPart>,
pub name_end: String,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct ClassDefinition {
pub name: String,
pub description: String,
pub class_type: ClassType,
pub partial: bool,
pub encapsulated: bool,
pub compositions: Vec<Composition>,
pub is_encapsulated: bool,
pub is_final: bool,
pub class_prefixes: ClassPrefixes,
pub class_specifier: ClassSpecifier,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Composition {
pub enum CompositionPart {
ElementList {
visibility: Visibility,
elements: Vec<ComponentDeclaration>,
elements: Vec<Element>,
},
EquationSection {
initial: bool,
Expand All @@ -45,6 +61,16 @@ pub enum Composition {
},
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Element {
ComponentClause {
type_prefix: TypePrefix,
type_specifier: TypeSpecifier,
array_subscripts: Option<Vec<Subscript>>,
components: Vec<ComponentDeclaration>,
},
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Causality {
None,
Expand Down Expand Up @@ -88,12 +114,17 @@ pub enum Statement {
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[allow(clippy::vec_box)]
pub struct ComponentReference {
pub struct RefPart {
pub name: String,
pub array_subscripts: Vec<Subscript>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ComponentReference {
pub local: bool,
pub parts: Vec<RefPart>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Equation {
Der {
Expand Down Expand Up @@ -242,6 +273,12 @@ pub enum Expression {
},
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Description {
pub strings: Vec<String>,
pub annotation: Vec<Argument>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Modification {
pub expression: Box<Expression>,
Expand All @@ -250,18 +287,18 @@ pub struct Modification {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Declaration {
pub name: String,
pub array_subscripts: Vec<Subscript>,
pub array_subscripts: Option<Vec<Subscript>>,
pub modification: Option<Modification>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Argument {
Modificaion {
Modification {
name: Name,
each: bool,
is_final: bool,
modification: Option<Modification>,
description: String,
description: Description,
},
Replaceable,
Redeclaration,
Expand All @@ -275,11 +312,23 @@ pub struct TypePrefix {
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ComponentClause {
pub type_prefix: TypePrefix,
pub struct Component {
pub connection: Connection,
pub variability: Variability,
pub causality: Causality,
pub type_specifier: TypeSpecifier,
pub name: String,
pub array_subscripts: Vec<Subscript>,
pub components: Vec<ComponentDeclaration>,
pub modification: Option<Modification>,
pub condition_attribute: Option<Box<Expression>>,
pub description: Description,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ComponentClause1 {
pub type_prefix: TypePrefix,
pub type_specifier: TypeSpecifier,
pub component_declaration1: ComponentDeclaration1,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -328,7 +377,6 @@ mod tests {

// class ball
let class_ball = ClassDefinition {
name: String::from("Ball"),
..Default::default()
};
def.classes.push(class_ball);
Expand Down
Loading
Loading