From 26cc2890d67b9e1fd318cdb279aea554a29f9955 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sat, 30 Dec 2023 16:53:55 +0100 Subject: [PATCH 01/67] Initialize cargo package --- .gitignore | 6 ++++++ Cargo.toml | 8 ++++++++ src/lib.rs | 14 ++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index a06e6d4..48cd419 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,9 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + + +# Added by cargo + +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..95675b9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mofmt" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7d12d9a --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} From 32f7cbff63b40a12250751642a05f3d610abe808 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sat, 30 Dec 2023 16:54:32 +0100 Subject: [PATCH 02/67] Add moparse as a dependency --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 95675b9..2abc3e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +moparse = "0.1.1-rc1" From d76aaac22fcdb3a1b480105930a58d219a3babb5 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sat, 30 Dec 2023 19:48:10 +0100 Subject: [PATCH 03/67] Partially reproduce formatting logic in Rust --- src/formatting.rs | 372 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 15 +- 2 files changed, 373 insertions(+), 14 deletions(-) create mode 100644 src/formatting.rs diff --git a/src/formatting.rs b/src/formatting.rs new file mode 100644 index 0000000..be3b05e --- /dev/null +++ b/src/formatting.rs @@ -0,0 +1,372 @@ +use moparse::{SyntaxEvent, SyntaxKind, Terminal, Token, TokenCollection, TokenKind}; + +enum Marker { + Token(usize), + Comment(usize), + Space, + Indent, + Dedent, + Ignore, + Blank, + Break, + Wrap, +} + +struct Formatter<'a> { + tokens: &'a TokenCollection, + events: &'a Vec, + markers: Vec, + token: usize, + comment: usize, + prev_token: TokenKind, + prev_line: usize, + brackets: usize, + groups: Vec, + rules: Vec, + wraps: Vec, +} + +const NO_SPACE_AFTER: [TokenKind; 6] = [ + TokenKind::LParen, + TokenKind::Dot, + TokenKind::LBracket, + TokenKind::LCurly, + TokenKind::Semi, + TokenKind::Colon, +]; +const NO_SPACE_BEFORE: [TokenKind; 6] = [ + TokenKind::RParen, + TokenKind::RBracket, + TokenKind::RCurly, + TokenKind::Semi, + TokenKind::Comma, + TokenKind::Colon, +]; +const NO_BREAK_BEFORE: [TokenKind; 4] = [ + TokenKind::End, + TokenKind::Else, + TokenKind::Elif, + TokenKind::Elwhen, +]; + +impl<'a> Formatter<'a> { + fn new(tokens: &'a TokenCollection, events: &'a Vec) -> Self { + Formatter { + tokens, + events, + markers: Vec::new(), + token: 0, + comment: 0, + prev_token: TokenKind::EOF, + prev_line: 1, + brackets: 0, + groups: Vec::new(), + rules: Vec::new(), + wraps: Vec::new(), + } + } + + /// Handle comments and separate them if needed. + fn handle_comments(&mut self, comments: Vec<&Token>, current_line: usize) { + let mut line = self.prev_line; + let mut diff = comments[0].end.line - line; + if diff == 0 { + // TODO: Handle inline comments + (); + } + for comment in comments { + diff = comment.start.line - line; + if diff == 0 { + self.markers.push(Marker::Space); + } else if diff == 1 { + self.markers.push(Marker::Break); + } else { + if self.prev_token == TokenKind::Semi { + self.markers.push(Marker::Blank); + } + } + self.markers.push(Marker::Comment(comment.idx)); + line = comment.end.line; + } + diff = current_line - line; + if self.prev_line == 1 { + self.markers.push(Marker::Break); + } else if diff == 1 { + self.markers.push(Marker::Break); + } else if diff > 1 { + self.markers.push(Marker::Blank); + } + } + + /// Insert line break or space + fn break_or_space(&mut self) { + match self.groups.last() { + Some(b) => { + if *b { + self.markers.push(Marker::Break); + } else { + if !NO_SPACE_AFTER.contains(&self.prev_token) { + self.markers.push(Marker::Space); + } + } + } + None => { + if !NO_SPACE_AFTER.contains(&self.prev_token) { + self.markers.push(Marker::Space); + } + } + } + } + + fn enter_group(&mut self) { + self.groups.push(false); + // TODO + } + + fn wrap_expression(&mut self) { + // TODO + } + + fn walk_events(&mut self) { + for idx in 0..self.events.len() { + match &self.events[idx] { + SyntaxEvent::Advance(t) => { + match t { + Terminal::Token(i) => { + let tok = self.tokens.get_token(*i).unwrap(); + let kind = tok.typ; + let comments = preceding_comments(self.tokens, tok.idx); + if self.prev_token == TokenKind::Semi { + if self.brackets == 0 { + self.markers.push(Marker::Break); + } else { + self.markers.push(Marker::Space); + } + if comments.is_none() { + if tok.start.line - self.prev_line > 1 + && !NO_BREAK_BEFORE.contains(&kind) + { + self.markers.push(Marker::Blank); + } + } + } + + if comments.is_some() { + self.handle_comments(comments.unwrap(), tok.start.line); + } + + // Special cases + match kind { + TokenKind::LBracket => { + self.brackets += 1; + if self.prev_token != TokenKind::Ident + && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } + TokenKind::RBracket => self.brackets -= 1, + TokenKind::For => self.break_or_space(), + TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { + // Handle conditional expression context + if *self.rules.last().unwrap() == SyntaxKind::Expression { + self.break_or_space(); + } else if [ + SyntaxKind::IfEquation, + SyntaxKind::IfStatement, + SyntaxKind::WhenEquation, + SyntaxKind::WhenStatement, + ] + .contains(self.rules.last().unwrap()) + { + self.markers.push(Marker::Break); + } + } + TokenKind::If => { + // Handle conditional expressions + if *self.groups.last().unwrap() + && [TokenKind::Equal, TokenKind::Assign] + .contains(&self.prev_token) + { + self.markers.push(Marker::Indent); + self.break_or_space(); + } + } + TokenKind::Dot => { + // Only first dot in type specifiers etc. can be preceded with a space + if ![TokenKind::Ident, TokenKind::LBracket] + .contains(&self.prev_token) + && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } + TokenKind::Protected | TokenKind::Public => { + self.markers.push(Marker::Blank) + } + TokenKind::External => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } + _ => { + if !NO_SPACE_BEFORE.contains(&kind) + && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } + } + + self.markers.push(Marker::Token(tok.idx)); + + match kind { + TokenKind::Annotation => self.markers.push(Marker::Space), + TokenKind::Then | TokenKind::Else | TokenKind::Loop => { + if [ + SyntaxKind::IfEquation, + SyntaxKind::IfStatement, + SyntaxKind::WhenEquation, + SyntaxKind::WhenStatement, + SyntaxKind::WhileStatement, + SyntaxKind::ForEquation, + SyntaxKind::ForStatement, + ] + .contains(self.rules.last().unwrap()) + { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Break); + } + } + TokenKind::Equation | TokenKind::Algorithm => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } + _ => (), + } + + self.prev_token = kind; + self.prev_line = tok.start.line; + } + _ => (), + } + } + SyntaxEvent::Enter { typ, tok, exit } => { + match typ { + SyntaxKind::DescriptionString + | SyntaxKind::AnnotationClause + | SyntaxKind::ConstrainingClause => { + self.markers.push(Marker::Indent); + // Handle class annotations + if *typ == SyntaxKind::AnnotationClause + && *self.rules.last().unwrap() == SyntaxKind::Composition + { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } + } + SyntaxKind::Equation | SyntaxKind::Statement => { + if [SyntaxKind::IfEquation, SyntaxKind::IfStatement] + .contains(self.rules.last().unwrap()) + { + self.markers.push(Marker::Indent); + } + } + SyntaxKind::EnumerationLiteral => self.markers.push(Marker::Break), + // TODO: external function call + SyntaxKind::ElementList => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } + SyntaxKind::EnumList => self.markers.push(Marker::Indent), + // TODO: end clause + SyntaxKind::EquationSection | SyntaxKind::AlgorithmSection => { + self.markers.push(Marker::Blank) + } + SyntaxKind::Primary => { + // Handle matrix or array + if [TokenKind::LBracket, TokenKind::LCurly] + .contains(&self.tokens.get_token(*tok).unwrap().typ) + { + self.enter_group(); + } + } + SyntaxKind::FunctionCallArgs + | SyntaxKind::ClassOrInheritanceModification + | SyntaxKind::ClassModification + | SyntaxKind::ArraySubscripts => { + self.enter_group(); + self.markers.push(Marker::Ignore); + } + SyntaxKind::ExpressionList => { + self.break_or_space(); + self.enter_group(); + } + SyntaxKind::FunctionArgument => { + // do not break if it is part of named arg + if self.prev_token != TokenKind::Equal { + self.break_or_space(); + } + } + SyntaxKind::Subscript + | SyntaxKind::NamedArgument + | SyntaxKind::Argument + | SyntaxKind::InheritanceModification => { + self.break_or_space(); + } + SyntaxKind::MulOperator + | SyntaxKind::AddOperator + | SyntaxKind::RelationalOperator => { + self.wrap_expression(); + } + SyntaxKind::Expression => { + if [SyntaxKind::ExpressionList, SyntaxKind::ArrayArguments] + .contains(&self.rules[self.rules.len() - 2]) + { + self.break_or_space(); + // Handle conditional expression + } else if self.tokens.get_token(*tok).unwrap().typ == TokenKind::If { + self.enter_group(); + // Handle conditional parts in conditional expression + } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) + && *self.rules.last().unwrap() == SyntaxKind::Expression + { + self.markers.push(Marker::Indent); + self.break_or_space(); + } + self.wraps.push(false); + } + _ => (), + } + self.rules.push(*typ); + } + _ => (), + } + } + } +} + +/// Return comments that precedes the token of the given index +fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> { + // Check if the current token is not a first one + if i == 0 { + return None; + } + let mut rest = i - 1; + let mut comments = Vec::new(); + while rest >= 0 { + let prev_item = tokens.get_item(rest).unwrap(); + rest -= 1; + if [TokenKind::LineComment, TokenKind::BlockComment].contains(&prev_item.typ) { + comments.push(prev_item); + } else { + break; + } + } + if comments.len() == 0 { + None + } else { + comments.reverse(); + Some(comments) + } +} diff --git a/src/lib.rs b/src/lib.rs index 7d12d9a..75a1e98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +mod formatting; From aaec28a7ff406e08a00c32738c3c55fc411d1cf7 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 1 Jan 2024 19:55:07 +0100 Subject: [PATCH 04/67] Create functions for handling groups and wrapped expressions --- src/formatting.rs | 403 +++++++++++++++++++++++++++++++--------------- 1 file changed, 269 insertions(+), 134 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index be3b05e..17eee2d 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -48,6 +48,26 @@ const NO_BREAK_BEFORE: [TokenKind; 4] = [ TokenKind::Elif, TokenKind::Elwhen, ]; +const OPERATORS: [TokenKind; 18] = [ + TokenKind::Plus, + TokenKind::DotPlus, + TokenKind::Minus, + TokenKind::DotMinus, + TokenKind::Star, + TokenKind::DotStar, + TokenKind::Slash, + TokenKind::DotSlash, + TokenKind::Flex, + TokenKind::DotFlex, + TokenKind::And, + TokenKind::Or, + TokenKind::Gre, + TokenKind::Geq, + TokenKind::Les, + TokenKind::Leq, + TokenKind::Eq, + TokenKind::Neq, +]; impl<'a> Formatter<'a> { fn new(tokens: &'a TokenCollection, events: &'a Vec) -> Self { @@ -118,138 +138,229 @@ impl<'a> Formatter<'a> { } } - fn enter_group(&mut self) { - self.groups.push(false); - // TODO + fn enter_group(&mut self, typ: SyntaxKind, start: usize, exit: usize) { + // Check if group was multiline + let end; + match self.events[exit] { + SyntaxEvent::Exit { tok, .. } => { + end = tok; + } + _ => unreachable!(), + } + let first_tok = self.tokens.get_token(start).unwrap(); + let last_tok = self.tokens.get_token(end).unwrap(); + if first_tok.start.line > last_tok.end.line { + // Handle conditional expression + if first_tok.typ == TokenKind::If + && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) + { + self.markers.push(Marker::Indent); + // Handle matrix row + } else if typ == SyntaxKind::ExpressionList { + if !*self.groups.last().unwrap() { + self.markers.push(Marker::Indent); + } + } else { + self.markers.push(Marker::Indent); + } + self.groups.push(true); + } else { + self.groups.push(false); + } } - fn wrap_expression(&mut self) { - // TODO + fn exit_group(&mut self, typ: SyntaxKind, enter: usize) { + let group_broken = self.groups.pop().unwrap(); + let start; + match self.events[enter] { + SyntaxEvent::Enter { tok, .. } => { + start = tok; + } + _ => unreachable!(), + } + if group_broken { + // Handle conditional expression + if self.tokens.get_token(start).unwrap().typ == TokenKind::If + && [TokenKind::Equal, TokenKind::Assign] + .contains(&self.tokens.get_token(start - 1).unwrap().typ) + { + self.markers.push(Marker::Dedent); + // Handle matrix row + } else if typ == SyntaxKind::ExpressionList { + if !*self.groups.last().unwrap() { + self.markers.push(Marker::Dedent); + } + } else { + self.markers.push(Marker::Dedent); + } + } } - fn walk_events(&mut self) { - for idx in 0..self.events.len() { - match &self.events[idx] { - SyntaxEvent::Advance(t) => { - match t { - Terminal::Token(i) => { - let tok = self.tokens.get_token(*i).unwrap(); - let kind = tok.typ; - let comments = preceding_comments(self.tokens, tok.idx); - if self.prev_token == TokenKind::Semi { - if self.brackets == 0 { - self.markers.push(Marker::Break); - } else { - self.markers.push(Marker::Space); - } - if comments.is_none() { - if tok.start.line - self.prev_line > 1 - && !NO_BREAK_BEFORE.contains(&kind) - { - self.markers.push(Marker::Blank); - } - } - } + /// Place the line break at the i-th token + fn wrap_expression(&mut self, i: usize) { + let next_tok = self.tokens.get_token(i + 1).unwrap(); + // Check if there was a line break around the wrap point + if next_tok.start.line > self.prev_line { + // Consider only binary operators + if [ + TokenKind::RBracket, + TokenKind::RParen, + TokenKind::RCurly, + TokenKind::Ident, + TokenKind::String, + TokenKind::Uint, + TokenKind::Ureal, + TokenKind::True, + TokenKind::False, + TokenKind::End, + ] + .contains(&self.prev_token) + { + // Only indent if this is a first wrap + let wrapped = self.wraps.last_mut().unwrap(); + if !*wrapped { + self.markers.push(Marker::Indent); + *wrapped = true; + } + self.markers.push(Marker::Wrap); + } + } + } - if comments.is_some() { - self.handle_comments(comments.unwrap(), tok.start.line); - } + fn handle_token(&mut self, i: usize) { + let tok = self.tokens.get_item(i).unwrap(); + let kind = tok.typ; + let comments = preceding_comments(self.tokens, tok.idx); + if self.prev_token == TokenKind::Semi { + if self.brackets == 0 { + self.markers.push(Marker::Break); + } else { + self.markers.push(Marker::Space); + } + if comments.is_none() { + if tok.start.line - self.prev_line > 1 && !NO_BREAK_BEFORE.contains(&kind) { + self.markers.push(Marker::Blank); + } + } + } - // Special cases - match kind { - TokenKind::LBracket => { - self.brackets += 1; - if self.prev_token != TokenKind::Ident - && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - TokenKind::RBracket => self.brackets -= 1, - TokenKind::For => self.break_or_space(), - TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { - // Handle conditional expression context - if *self.rules.last().unwrap() == SyntaxKind::Expression { - self.break_or_space(); - } else if [ - SyntaxKind::IfEquation, - SyntaxKind::IfStatement, - SyntaxKind::WhenEquation, - SyntaxKind::WhenStatement, - ] - .contains(self.rules.last().unwrap()) - { - self.markers.push(Marker::Break); - } - } - TokenKind::If => { - // Handle conditional expressions - if *self.groups.last().unwrap() - && [TokenKind::Equal, TokenKind::Assign] - .contains(&self.prev_token) - { - self.markers.push(Marker::Indent); - self.break_or_space(); - } - } - TokenKind::Dot => { - // Only first dot in type specifiers etc. can be preceded with a space - if ![TokenKind::Ident, TokenKind::LBracket] - .contains(&self.prev_token) - && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - TokenKind::Protected | TokenKind::Public => { - self.markers.push(Marker::Blank) - } - TokenKind::External => { - self.markers.push(Marker::Indent); - self.markers.push(Marker::Blank); - } - _ => { - if !NO_SPACE_BEFORE.contains(&kind) - && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - } + // Handle comments + if comments.is_some() { + self.handle_comments(comments.unwrap(), tok.start.line); + } - self.markers.push(Marker::Token(tok.idx)); + match kind { + TokenKind::LBracket => { + self.brackets += 1; + if self.prev_token != TokenKind::Ident && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } + TokenKind::RBracket => self.brackets -= 1, + TokenKind::For => self.break_or_space(), + TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { + // Handle conditional expression context + if *self.rules.last().unwrap() == SyntaxKind::Expression { + self.break_or_space(); + } else if [ + SyntaxKind::IfEquation, + SyntaxKind::IfStatement, + SyntaxKind::WhenEquation, + SyntaxKind::WhenStatement, + ] + .contains(self.rules.last().unwrap()) + { + self.markers.push(Marker::Break); + } + } + TokenKind::If => { + // Handle conditional expressions + if *self.groups.last().unwrap() + && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) + { + self.markers.push(Marker::Indent); + self.break_or_space(); + } + } + TokenKind::Dot => { + // Only first dot in type specifiers etc. can be preceded with a space + if ![TokenKind::Ident, TokenKind::LBracket].contains(&self.prev_token) + && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } + TokenKind::Protected | TokenKind::Public => self.markers.push(Marker::Blank), + TokenKind::External => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } + TokenKind::Plus + | TokenKind::DotPlus + | TokenKind::Minus + | TokenKind::DotMinus + | TokenKind::Star + | TokenKind::DotStar + | TokenKind::Slash + | TokenKind::DotSlash + | TokenKind::Flex + | TokenKind::DotFlex + | TokenKind::And + | TokenKind::Or + | TokenKind::Gre + | TokenKind::Geq + | TokenKind::Les + | TokenKind::Leq + | TokenKind::Eq + | TokenKind::Neq => { + self.wrap_expression(i); + } + _ => { + if !NO_SPACE_BEFORE.contains(&kind) && !NO_SPACE_AFTER.contains(&self.prev_token) { + self.markers.push(Marker::Space); + } + } + } - match kind { - TokenKind::Annotation => self.markers.push(Marker::Space), - TokenKind::Then | TokenKind::Else | TokenKind::Loop => { - if [ - SyntaxKind::IfEquation, - SyntaxKind::IfStatement, - SyntaxKind::WhenEquation, - SyntaxKind::WhenStatement, - SyntaxKind::WhileStatement, - SyntaxKind::ForEquation, - SyntaxKind::ForStatement, - ] - .contains(self.rules.last().unwrap()) - { - self.markers.push(Marker::Indent); - self.markers.push(Marker::Break); - } - } - TokenKind::Equation | TokenKind::Algorithm => { - self.markers.push(Marker::Indent); - self.markers.push(Marker::Blank); - } - _ => (), - } + self.markers.push(Marker::Token(tok.idx)); - self.prev_token = kind; - self.prev_line = tok.start.line; - } - _ => (), - } + match kind { + TokenKind::Annotation => self.markers.push(Marker::Space), + TokenKind::Then | TokenKind::Else | TokenKind::Loop => { + if [ + SyntaxKind::IfEquation, + SyntaxKind::IfStatement, + SyntaxKind::WhenEquation, + SyntaxKind::WhenStatement, + SyntaxKind::WhileStatement, + SyntaxKind::ForEquation, + SyntaxKind::ForStatement, + ] + .contains(self.rules.last().unwrap()) + { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Break); } + } + TokenKind::Equation | TokenKind::Algorithm => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } + _ => (), + } + + self.prev_token = kind; + self.prev_line = tok.start.line; + } + + fn walk_events(&mut self) { + for idx in 0..self.events.len() { + match &self.events[idx] { + SyntaxEvent::Advance(t) => match t { + Terminal::Token(i) => self.handle_token(*i), + _ => (), + }, SyntaxEvent::Enter { typ, tok, exit } => { match typ { SyntaxKind::DescriptionString @@ -288,19 +399,19 @@ impl<'a> Formatter<'a> { if [TokenKind::LBracket, TokenKind::LCurly] .contains(&self.tokens.get_token(*tok).unwrap().typ) { - self.enter_group(); + self.enter_group(*typ, *tok, *exit); } } SyntaxKind::FunctionCallArgs | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts => { - self.enter_group(); + self.enter_group(*typ, *tok, *exit); self.markers.push(Marker::Ignore); } SyntaxKind::ExpressionList => { self.break_or_space(); - self.enter_group(); + self.enter_group(*typ, *tok, *exit); } SyntaxKind::FunctionArgument => { // do not break if it is part of named arg @@ -314,19 +425,14 @@ impl<'a> Formatter<'a> { | SyntaxKind::InheritanceModification => { self.break_or_space(); } - SyntaxKind::MulOperator - | SyntaxKind::AddOperator - | SyntaxKind::RelationalOperator => { - self.wrap_expression(); - } SyntaxKind::Expression => { if [SyntaxKind::ExpressionList, SyntaxKind::ArrayArguments] - .contains(&self.rules[self.rules.len() - 2]) + .contains(&self.rules[self.rules.len() - 1]) { self.break_or_space(); // Handle conditional expression } else if self.tokens.get_token(*tok).unwrap().typ == TokenKind::If { - self.enter_group(); + self.enter_group(*typ, *tok, *exit); // Handle conditional parts in conditional expression } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) && *self.rules.last().unwrap() == SyntaxKind::Expression @@ -340,7 +446,36 @@ impl<'a> Formatter<'a> { } self.rules.push(*typ); } - _ => (), + SyntaxEvent::Exit { typ, tok, enter } => { + match typ { + // TODO: Conditional equations, conditional statements, external element, equation list, statement list, conditional expression, conditional branch + SyntaxKind::DescriptionString + | SyntaxKind::AnnotationClause + | SyntaxKind::ConstrainingClause + | SyntaxKind::ElementList + | SyntaxKind::EnumList => self.markers.push(Marker::Dedent), + SyntaxKind::Primary => { + // Handle matrix or array + if [TokenKind::RBracket, TokenKind::RCurly] + .contains(&self.tokens.get_token(*tok).unwrap().typ) + { + self.exit_group(*typ, *enter); + } + } + SyntaxKind::FunctionCallArgs + | SyntaxKind::ClassOrInheritanceModification + | SyntaxKind::ClassModification + | SyntaxKind::ArraySubscripts + | SyntaxKind::ExpressionList => self.exit_group(*typ, *enter), + SyntaxKind::Expression => { + let wrapped = self.wraps.pop().unwrap(); + if wrapped { + self.markers.push(Marker::Dedent); + } + } + _ => (), + } + } } } } @@ -354,7 +489,7 @@ fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> } let mut rest = i - 1; let mut comments = Vec::new(); - while rest >= 0 { + loop { let prev_item = tokens.get_item(rest).unwrap(); rest -= 1; if [TokenKind::LineComment, TokenKind::BlockComment].contains(&prev_item.typ) { From db2641f248d6a980c12ebb12837ad5161b41ec27 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 2 Jan 2024 16:40:48 +0100 Subject: [PATCH 05/67] Update parser version --- Cargo.toml | 2 +- src/formatting.rs | 74 +++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2abc3e8..b43866d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.1-rc1" +moparse = "0.1.1" diff --git a/src/formatting.rs b/src/formatting.rs index 17eee2d..8db12b1 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,4 +1,4 @@ -use moparse::{SyntaxEvent, SyntaxKind, Terminal, Token, TokenCollection, TokenKind}; +use moparse::{Payload, SyntaxEvent, SyntaxKind, Terminal, Token, TokenCollection, TokenKind}; enum Marker { Token(usize), @@ -138,17 +138,10 @@ impl<'a> Formatter<'a> { } } - fn enter_group(&mut self, typ: SyntaxKind, start: usize, exit: usize) { + fn enter_group(&mut self, enter: &Payload, exit: &Payload) { // Check if group was multiline - let end; - match self.events[exit] { - SyntaxEvent::Exit { tok, .. } => { - end = tok; - } - _ => unreachable!(), - } - let first_tok = self.tokens.get_token(start).unwrap(); - let last_tok = self.tokens.get_token(end).unwrap(); + let first_tok = self.tokens.get_token(enter.tok).unwrap(); + let last_tok = self.tokens.get_token(exit.tok).unwrap(); if first_tok.start.line > last_tok.end.line { // Handle conditional expression if first_tok.typ == TokenKind::If @@ -156,7 +149,7 @@ impl<'a> Formatter<'a> { { self.markers.push(Marker::Indent); // Handle matrix row - } else if typ == SyntaxKind::ExpressionList { + } else if enter.typ == SyntaxKind::ExpressionList { if !*self.groups.last().unwrap() { self.markers.push(Marker::Indent); } @@ -169,24 +162,17 @@ impl<'a> Formatter<'a> { } } - fn exit_group(&mut self, typ: SyntaxKind, enter: usize) { + fn exit_group(&mut self, enter: &Payload, exit: &Payload) { let group_broken = self.groups.pop().unwrap(); - let start; - match self.events[enter] { - SyntaxEvent::Enter { tok, .. } => { - start = tok; - } - _ => unreachable!(), - } if group_broken { // Handle conditional expression - if self.tokens.get_token(start).unwrap().typ == TokenKind::If + if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If && [TokenKind::Equal, TokenKind::Assign] - .contains(&self.tokens.get_token(start - 1).unwrap().typ) + .contains(&self.tokens.get_token(enter.tok - 1).unwrap().typ) { self.markers.push(Marker::Dedent); // Handle matrix row - } else if typ == SyntaxKind::ExpressionList { + } else if exit.typ == SyntaxKind::ExpressionList { if !*self.groups.last().unwrap() { self.markers.push(Marker::Dedent); } @@ -361,14 +347,19 @@ impl<'a> Formatter<'a> { Terminal::Token(i) => self.handle_token(*i), _ => (), }, - SyntaxEvent::Enter { typ, tok, exit } => { - match typ { + SyntaxEvent::Enter(p_start) => { + let p_end; + match &self.events[p_start.pair] { + SyntaxEvent::Exit(exit) => p_end = exit, + _ => unreachable!(), + } + match p_start.typ { SyntaxKind::DescriptionString | SyntaxKind::AnnotationClause | SyntaxKind::ConstrainingClause => { self.markers.push(Marker::Indent); // Handle class annotations - if *typ == SyntaxKind::AnnotationClause + if p_start.typ == SyntaxKind::AnnotationClause && *self.rules.last().unwrap() == SyntaxKind::Composition { self.markers.push(Marker::Blank); @@ -397,21 +388,21 @@ impl<'a> Formatter<'a> { SyntaxKind::Primary => { // Handle matrix or array if [TokenKind::LBracket, TokenKind::LCurly] - .contains(&self.tokens.get_token(*tok).unwrap().typ) + .contains(&self.tokens.get_token(p_start.tok).unwrap().typ) { - self.enter_group(*typ, *tok, *exit); + self.enter_group(p_start, p_end); } } SyntaxKind::FunctionCallArgs | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts => { - self.enter_group(*typ, *tok, *exit); + self.enter_group(p_start, p_end); self.markers.push(Marker::Ignore); } SyntaxKind::ExpressionList => { self.break_or_space(); - self.enter_group(*typ, *tok, *exit); + self.enter_group(p_start, p_end); } SyntaxKind::FunctionArgument => { // do not break if it is part of named arg @@ -431,8 +422,10 @@ impl<'a> Formatter<'a> { { self.break_or_space(); // Handle conditional expression - } else if self.tokens.get_token(*tok).unwrap().typ == TokenKind::If { - self.enter_group(*typ, *tok, *exit); + } else if self.tokens.get_token(p_start.tok).unwrap().typ + == TokenKind::If + { + self.enter_group(p_start, p_end); // Handle conditional parts in conditional expression } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) && *self.rules.last().unwrap() == SyntaxKind::Expression @@ -444,10 +437,15 @@ impl<'a> Formatter<'a> { } _ => (), } - self.rules.push(*typ); + self.rules.push(p_start.typ); } - SyntaxEvent::Exit { typ, tok, enter } => { - match typ { + SyntaxEvent::Exit(p_end) => { + let p_start; + match &self.events[p_end.pair] { + SyntaxEvent::Enter(enter) => p_start = enter, + _ => unreachable!(), + } + match p_end.typ { // TODO: Conditional equations, conditional statements, external element, equation list, statement list, conditional expression, conditional branch SyntaxKind::DescriptionString | SyntaxKind::AnnotationClause @@ -457,16 +455,16 @@ impl<'a> Formatter<'a> { SyntaxKind::Primary => { // Handle matrix or array if [TokenKind::RBracket, TokenKind::RCurly] - .contains(&self.tokens.get_token(*tok).unwrap().typ) + .contains(&self.tokens.get_token(p_end.tok).unwrap().typ) { - self.exit_group(*typ, *enter); + self.exit_group(p_start, p_end); } } SyntaxKind::FunctionCallArgs | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts - | SyntaxKind::ExpressionList => self.exit_group(*typ, *enter), + | SyntaxKind::ExpressionList => self.exit_group(p_start, p_end), SyntaxKind::Expression => { let wrapped = self.wraps.pop().unwrap(); if wrapped { From 23c57f4fc5ce360e787ba6047d1477ac251ad6b2 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 2 Jan 2024 17:53:39 +0100 Subject: [PATCH 06/67] Finish initial version of event walker --- src/formatting.rs | 156 +++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 91 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 8db12b1..30c45cd 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -16,8 +16,6 @@ struct Formatter<'a> { tokens: &'a TokenCollection, events: &'a Vec, markers: Vec, - token: usize, - comment: usize, prev_token: TokenKind, prev_line: usize, brackets: usize, @@ -48,26 +46,6 @@ const NO_BREAK_BEFORE: [TokenKind; 4] = [ TokenKind::Elif, TokenKind::Elwhen, ]; -const OPERATORS: [TokenKind; 18] = [ - TokenKind::Plus, - TokenKind::DotPlus, - TokenKind::Minus, - TokenKind::DotMinus, - TokenKind::Star, - TokenKind::DotStar, - TokenKind::Slash, - TokenKind::DotSlash, - TokenKind::Flex, - TokenKind::DotFlex, - TokenKind::And, - TokenKind::Or, - TokenKind::Gre, - TokenKind::Geq, - TokenKind::Les, - TokenKind::Leq, - TokenKind::Eq, - TokenKind::Neq, -]; impl<'a> Formatter<'a> { fn new(tokens: &'a TokenCollection, events: &'a Vec) -> Self { @@ -75,8 +53,6 @@ impl<'a> Formatter<'a> { tokens, events, markers: Vec::new(), - token: 0, - comment: 0, prev_token: TokenKind::EOF, prev_line: 1, brackets: 0, @@ -138,18 +114,16 @@ impl<'a> Formatter<'a> { } } - fn enter_group(&mut self, enter: &Payload, exit: &Payload) { - // Check if group was multiline - let first_tok = self.tokens.get_token(enter.tok).unwrap(); - let last_tok = self.tokens.get_token(exit.tok).unwrap(); - if first_tok.start.line > last_tok.end.line { + fn enter_group(&mut self, typ: SyntaxKind, first: &Token, last: &Token) { + // Mark the group as broken if group was multiline + if first.start.line > last.end.line { // Handle conditional expression - if first_tok.typ == TokenKind::If + if first.typ == TokenKind::If && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) { self.markers.push(Marker::Indent); // Handle matrix row - } else if enter.typ == SyntaxKind::ExpressionList { + } else if typ == SyntaxKind::ExpressionList { if !*self.groups.last().unwrap() { self.markers.push(Marker::Indent); } @@ -216,6 +190,7 @@ impl<'a> Formatter<'a> { fn handle_token(&mut self, i: usize) { let tok = self.tokens.get_item(i).unwrap(); let kind = tok.typ; + let parent = *self.rules.last().unwrap(); let comments = preceding_comments(self.tokens, tok.idx); if self.prev_token == TokenKind::Semi { if self.brackets == 0 { @@ -245,9 +220,17 @@ impl<'a> Formatter<'a> { } TokenKind::RBracket => self.brackets -= 1, TokenKind::For => self.break_or_space(), + TokenKind::End => { + // Handle end clause in class specifiers + if parent == SyntaxKind::LongClassSpecifier { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Space); + } + } TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { // Handle conditional expression context - if *self.rules.last().unwrap() == SyntaxKind::Expression { + if parent == SyntaxKind::Expression { self.break_or_space(); } else if [ SyntaxKind::IfEquation, @@ -255,7 +238,7 @@ impl<'a> Formatter<'a> { SyntaxKind::WhenEquation, SyntaxKind::WhenStatement, ] - .contains(self.rules.last().unwrap()) + .contains(&parent) { self.markers.push(Marker::Break); } @@ -323,14 +306,12 @@ impl<'a> Formatter<'a> { SyntaxKind::ForEquation, SyntaxKind::ForStatement, ] - .contains(self.rules.last().unwrap()) + .contains(&parent) { - self.markers.push(Marker::Indent); self.markers.push(Marker::Break); } } TokenKind::Equation | TokenKind::Algorithm => { - self.markers.push(Marker::Indent); self.markers.push(Marker::Blank); } _ => (), @@ -347,88 +328,69 @@ impl<'a> Formatter<'a> { Terminal::Token(i) => self.handle_token(*i), _ => (), }, - SyntaxEvent::Enter(p_start) => { - let p_end; - match &self.events[p_start.pair] { - SyntaxEvent::Exit(exit) => p_end = exit, - _ => unreachable!(), - } - match p_start.typ { + SyntaxEvent::Enter(p) => { + let first = self.tokens.get_token(p.tok).unwrap(); + let last = self.events[p.pair].get_token(self.tokens); + let parent = self.rules.last().unwrap(); + match p.typ { SyntaxKind::DescriptionString | SyntaxKind::AnnotationClause - | SyntaxKind::ConstrainingClause => { + | SyntaxKind::ConstrainingClause + | SyntaxKind::EnumerationLiteral => { self.markers.push(Marker::Indent); // Handle class annotations - if p_start.typ == SyntaxKind::AnnotationClause - && *self.rules.last().unwrap() == SyntaxKind::Composition + if p.typ == SyntaxKind::AnnotationClause + && *parent == SyntaxKind::Composition { self.markers.push(Marker::Blank); } else { self.markers.push(Marker::Break); } } - SyntaxKind::Equation | SyntaxKind::Statement => { - if [SyntaxKind::IfEquation, SyntaxKind::IfStatement] - .contains(self.rules.last().unwrap()) - { - self.markers.push(Marker::Indent); - } - } - SyntaxKind::EnumerationLiteral => self.markers.push(Marker::Break), - // TODO: external function call - SyntaxKind::ElementList => { + SyntaxKind::Equation | SyntaxKind::Statement | SyntaxKind::Element => { self.markers.push(Marker::Indent); - self.markers.push(Marker::Blank); } - SyntaxKind::EnumList => self.markers.push(Marker::Indent), - // TODO: end clause - SyntaxKind::EquationSection | SyntaxKind::AlgorithmSection => { - self.markers.push(Marker::Blank) + SyntaxKind::ElementList + | SyntaxKind::EquationSection + | SyntaxKind::AlgorithmSection => { + self.markers.push(Marker::Blank); } SyntaxKind::Primary => { // Handle matrix or array - if [TokenKind::LBracket, TokenKind::LCurly] - .contains(&self.tokens.get_token(p_start.tok).unwrap().typ) - { - self.enter_group(p_start, p_end); + if [TokenKind::LBracket, TokenKind::LCurly].contains(&first.typ) { + self.enter_group(p.typ, first, last); } } SyntaxKind::FunctionCallArgs | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts => { - self.enter_group(p_start, p_end); - self.markers.push(Marker::Ignore); + self.enter_group(p.typ, first, last); + // self.markers.push(Marker::Ignore); } SyntaxKind::ExpressionList => { self.break_or_space(); - self.enter_group(p_start, p_end); - } - SyntaxKind::FunctionArgument => { - // do not break if it is part of named arg - if self.prev_token != TokenKind::Equal { - self.break_or_space(); - } + self.enter_group(p.typ, first, last); } SyntaxKind::Subscript | SyntaxKind::NamedArgument | SyntaxKind::Argument - | SyntaxKind::InheritanceModification => { + | SyntaxKind::InheritanceModification + | SyntaxKind::FunctionArgumentsNonFirst + | SyntaxKind::FunctionArguments + | SyntaxKind::ArrayArguments + | SyntaxKind::ArrayArgumentsNonFirst => { self.break_or_space(); } SyntaxKind::Expression => { - if [SyntaxKind::ExpressionList, SyntaxKind::ArrayArguments] - .contains(&self.rules[self.rules.len() - 1]) - { + if *parent == SyntaxKind::ExpressionList { self.break_or_space(); // Handle conditional expression - } else if self.tokens.get_token(p_start.tok).unwrap().typ - == TokenKind::If - { - self.enter_group(p_start, p_end); + } else if first.typ == TokenKind::If { + self.enter_group(p.typ, first, last); // Handle conditional parts in conditional expression } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) - && *self.rules.last().unwrap() == SyntaxKind::Expression + && *parent == SyntaxKind::Expression { self.markers.push(Marker::Indent); self.break_or_space(); @@ -437,26 +399,29 @@ impl<'a> Formatter<'a> { } _ => (), } - self.rules.push(p_start.typ); + self.rules.push(p.typ); } SyntaxEvent::Exit(p_end) => { + let typ = self.rules.pop().unwrap(); let p_start; match &self.events[p_end.pair] { SyntaxEvent::Enter(enter) => p_start = enter, _ => unreachable!(), } - match p_end.typ { - // TODO: Conditional equations, conditional statements, external element, equation list, statement list, conditional expression, conditional branch + let first = self.tokens.get_token(p_start.tok).unwrap(); + let last = self.tokens.get_token(p_end.tok).unwrap(); + match typ { + // TODO: external element SyntaxKind::DescriptionString | SyntaxKind::AnnotationClause | SyntaxKind::ConstrainingClause - | SyntaxKind::ElementList - | SyntaxKind::EnumList => self.markers.push(Marker::Dedent), + | SyntaxKind::Equation + | SyntaxKind::Statement + | SyntaxKind::Element + | SyntaxKind::EnumerationLiteral => self.markers.push(Marker::Dedent), SyntaxKind::Primary => { // Handle matrix or array - if [TokenKind::RBracket, TokenKind::RCurly] - .contains(&self.tokens.get_token(p_end.tok).unwrap().typ) - { + if [TokenKind::RBracket, TokenKind::RCurly].contains(&last.typ) { self.exit_group(p_start, p_end); } } @@ -466,6 +431,15 @@ impl<'a> Formatter<'a> { | SyntaxKind::ArraySubscripts | SyntaxKind::ExpressionList => self.exit_group(p_start, p_end), SyntaxKind::Expression => { + // Handle conditional expression + if first.typ == TokenKind::If { + self.exit_group(p_start, p_end); + // Handle conditional part of the expression + } else if [TokenKind::Then, TokenKind::Else].contains(&first.typ) + && *self.rules.last().unwrap() == SyntaxKind::Expression + { + self.markers.push(Marker::Dedent); + } let wrapped = self.wraps.pop().unwrap(); if wrapped { self.markers.push(Marker::Dedent); From ebb6046e25b1cfe43633d0f42f1ed57bfd77dbe6 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 2 Jan 2024 18:25:34 +0100 Subject: [PATCH 07/67] Recreate markers collector --- src/formatting.rs | 16 +++------------ src/lib.rs | 1 + src/markers.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/markers.rs diff --git a/src/formatting.rs b/src/formatting.rs index 30c45cd..542bc8c 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,21 +1,11 @@ use moparse::{Payload, SyntaxEvent, SyntaxKind, Terminal, Token, TokenCollection, TokenKind}; +use crate::markers::{Marker, MarkerCollector}; -enum Marker { - Token(usize), - Comment(usize), - Space, - Indent, - Dedent, - Ignore, - Blank, - Break, - Wrap, -} struct Formatter<'a> { tokens: &'a TokenCollection, events: &'a Vec, - markers: Vec, + markers: MarkerCollector, prev_token: TokenKind, prev_line: usize, brackets: usize, @@ -52,7 +42,7 @@ impl<'a> Formatter<'a> { Formatter { tokens, events, - markers: Vec::new(), + markers: MarkerCollector::new(), prev_token: TokenKind::EOF, prev_line: 1, brackets: 0, diff --git a/src/lib.rs b/src/lib.rs index 75a1e98..63121e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,2 @@ mod formatting; +mod markers; diff --git a/src/markers.rs b/src/markers.rs new file mode 100644 index 0000000..6bef406 --- /dev/null +++ b/src/markers.rs @@ -0,0 +1,51 @@ + +#[derive(PartialEq, PartialOrd)] +pub enum Marker { + Token(usize), + Comment(usize), + Space, + Indent, + Dedent, + Ignore, + Blank, + Break, + Wrap, +} + +pub struct MarkerCollector { + markers: Vec, +} + +impl MarkerCollector { + + pub fn new() -> Self { + MarkerCollector { markers: Vec::new() } + } + + pub fn push(&mut self, m: Marker) { + match m { + Marker::Space => { + if self.markers.len() == 0 { + return; + } else if [Marker::Ignore, Marker::Space, Marker::Indent, Marker::Dedent].contains(&self.markers.last().unwrap()) { + return; + } + } + Marker::Blank => { + // Remove preceding break + if *self.markers.last().unwrap() >= Marker::Blank { + self.markers.pop(); + } + } + Marker::Break => { + // Do not add unnecessary breaks + if *self.markers.last().unwrap() >= Marker::Blank { + return; + } + } + _ => (), + } + self.markers.push(m); + } + +} From 1418440585911f0482e6134d2d3402171044bcb3 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 2 Jan 2024 18:58:20 +0100 Subject: [PATCH 08/67] Recreate the code printer --- src/lib.rs | 1 + src/printing.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/printing.rs diff --git a/src/lib.rs b/src/lib.rs index 63121e3..6b2defd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,3 @@ mod formatting; mod markers; +mod printing; diff --git a/src/printing.rs b/src/printing.rs new file mode 100644 index 0000000..1960314 --- /dev/null +++ b/src/printing.rs @@ -0,0 +1,53 @@ +use moparse::TokenCollection; + +use crate::markers::Marker; + + +pub struct Printer<'a> { + indent: usize, + tokens: &'a TokenCollection, + markers: &'a Vec, + formatted: String, +} + +impl<'a> Printer<'a> { + + pub fn new(tokens: &'a TokenCollection, markers: &'a Vec) -> Self { + Printer { indent: 0, tokens, markers, formatted: String::new() } + } + + fn print_marker(&mut self, m: &Marker) -> String { + const INDENT: &str = " "; + match m { + Marker::Space => String::from(" "), + Marker::Ignore => String::new(), + Marker::Indent => { + self.indent += 1; + String::new() + } + Marker::Dedent => { + self.indent -= 1; + String::new() + } + Marker::Token(i) | Marker::Comment(i) => self.tokens.get_item(*i).unwrap().text.clone(), + _ => { + let mut out = String::from("\n");; + if m == &Marker::Blank { + out += "\n"; + } + for i in 1..self.indent { + out += INDENT + } + out + } + } + + } + + pub fn pretty_print(&mut self) { + for marker in self.markers { + let s = self.print_marker(marker); + self.formatted += s.as_str(); + } + } +} From 48d6ba7a6ed31f8bcc9623cbb3e28fb8d403a114 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Wed, 3 Jan 2024 16:53:17 +0100 Subject: [PATCH 09/67] Make pretty-print function public --- src/formatting.rs | 2 +- src/lib.rs | 2 ++ src/printing.rs | 35 ++++++++++++++++------------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 542bc8c..8fcf192 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,4 +1,4 @@ -use moparse::{Payload, SyntaxEvent, SyntaxKind, Terminal, Token, TokenCollection, TokenKind}; +use moparse::*; use crate::markers::{Marker, MarkerCollector}; diff --git a/src/lib.rs b/src/lib.rs index 6b2defd..85b13d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +pub use self::printing::pretty_print; + mod formatting; mod markers; mod printing; diff --git a/src/printing.rs b/src/printing.rs index 1960314..5560838 100644 --- a/src/printing.rs +++ b/src/printing.rs @@ -2,21 +2,26 @@ use moparse::TokenCollection; use crate::markers::Marker; +pub fn pretty_print(tokens: &TokenCollection, markers: &Vec) -> String { + let mut printer = Printer::new(); + let mut formatted = String::new(); + for marker in markers { + let s = printer.print_marker(marker, tokens); + formatted += s.as_str(); + } + formatted +} -pub struct Printer<'a> { +struct Printer { indent: usize, - tokens: &'a TokenCollection, - markers: &'a Vec, - formatted: String, } -impl<'a> Printer<'a> { - - pub fn new(tokens: &'a TokenCollection, markers: &'a Vec) -> Self { - Printer { indent: 0, tokens, markers, formatted: String::new() } +impl Printer { + fn new() -> Self { + Printer { indent: 0 } } - fn print_marker(&mut self, m: &Marker) -> String { + fn print_marker(&mut self, m: &Marker, tokens: &TokenCollection) -> String { const INDENT: &str = " "; match m { Marker::Space => String::from(" "), @@ -29,9 +34,9 @@ impl<'a> Printer<'a> { self.indent -= 1; String::new() } - Marker::Token(i) | Marker::Comment(i) => self.tokens.get_item(*i).unwrap().text.clone(), + Marker::Token(i) | Marker::Comment(i) => tokens.get_item(*i).unwrap().text.clone(), _ => { - let mut out = String::from("\n");; + let mut out = String::from("\n"); if m == &Marker::Blank { out += "\n"; } @@ -41,13 +46,5 @@ impl<'a> Printer<'a> { out } } - - } - - pub fn pretty_print(&mut self) { - for marker in self.markers { - let s = self.print_marker(marker); - self.formatted += s.as_str(); - } } } From 632a6886c8774f0b278cba461414e853cc8dd40a Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Wed, 3 Jan 2024 19:33:42 +0100 Subject: [PATCH 10/67] More progress on reaching desired output 1. Fix the issue with duplicated comments 2. Fix the issue with formatting of conditional expressions --- Cargo.toml | 2 +- src/formatting.rs | 54 +++++++++++++++++++++++++---------------------- src/lib.rs | 1 + src/main.rs | 16 ++++++++++++++ src/markers.rs | 13 +++++------- src/printing.rs | 4 ++-- 6 files changed, 54 insertions(+), 36 deletions(-) create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index b43866d..c401390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.1" +moparse = "0.1.2-rc1" diff --git a/src/formatting.rs b/src/formatting.rs index 8fcf192..956f198 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,6 +1,11 @@ -use moparse::*; use crate::markers::{Marker, MarkerCollector}; +use moparse::*; +pub fn format(tokens: &TokenCollection, events: &Vec) -> Vec { + let mut fmt = Formatter::new(tokens, events); + fmt.walk_events(); + fmt.markers.markers +} struct Formatter<'a> { tokens: &'a TokenCollection, @@ -46,9 +51,9 @@ impl<'a> Formatter<'a> { prev_token: TokenKind::EOF, prev_line: 1, brackets: 0, - groups: Vec::new(), - rules: Vec::new(), - wraps: Vec::new(), + groups: vec![false], + rules: vec![SyntaxKind::StoredDefinition], + wraps: vec![false], } } @@ -106,7 +111,7 @@ impl<'a> Formatter<'a> { fn enter_group(&mut self, typ: SyntaxKind, first: &Token, last: &Token) { // Mark the group as broken if group was multiline - if first.start.line > last.end.line { + if first.start.line < last.end.line { // Handle conditional expression if first.typ == TokenKind::If && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) @@ -178,11 +183,12 @@ impl<'a> Formatter<'a> { } fn handle_token(&mut self, i: usize) { - let tok = self.tokens.get_item(i).unwrap(); + let tok = self.tokens.get_token(i).unwrap(); let kind = tok.typ; let parent = *self.rules.last().unwrap(); let comments = preceding_comments(self.tokens, tok.idx); if self.prev_token == TokenKind::Semi { + // Handle matrix rows if self.brackets == 0 { self.markers.push(Marker::Break); } else { @@ -233,15 +239,6 @@ impl<'a> Formatter<'a> { self.markers.push(Marker::Break); } } - TokenKind::If => { - // Handle conditional expressions - if *self.groups.last().unwrap() - && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) - { - self.markers.push(Marker::Indent); - self.break_or_space(); - } - } TokenKind::Dot => { // Only first dot in type specifiers etc. can be preceded with a space if ![TokenKind::Ident, TokenKind::LBracket].contains(&self.prev_token) @@ -324,23 +321,27 @@ impl<'a> Formatter<'a> { let parent = self.rules.last().unwrap(); match p.typ { SyntaxKind::DescriptionString - | SyntaxKind::AnnotationClause | SyntaxKind::ConstrainingClause | SyntaxKind::EnumerationLiteral => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Break); + } + SyntaxKind::AnnotationClause => { self.markers.push(Marker::Indent); // Handle class annotations - if p.typ == SyntaxKind::AnnotationClause - && *parent == SyntaxKind::Composition - { + if *parent == SyntaxKind::Composition { self.markers.push(Marker::Blank); } else { self.markers.push(Marker::Break); } } - SyntaxKind::Equation | SyntaxKind::Statement | SyntaxKind::Element => { + SyntaxKind::Equation | SyntaxKind::Statement => { self.markers.push(Marker::Indent); } - SyntaxKind::ElementList + SyntaxKind::ElementList => { + self.markers.push(Marker::Indent); + self.markers.push(Marker::Blank); + } | SyntaxKind::EquationSection | SyntaxKind::AlgorithmSection => { self.markers.push(Marker::Blank); @@ -356,7 +357,7 @@ impl<'a> Formatter<'a> { | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts => { self.enter_group(p.typ, first, last); - // self.markers.push(Marker::Ignore); + self.markers.push(Marker::Ignore); } SyntaxKind::ExpressionList => { self.break_or_space(); @@ -378,6 +379,7 @@ impl<'a> Formatter<'a> { // Handle conditional expression } else if first.typ == TokenKind::If { self.enter_group(p.typ, first, last); + self.break_or_space(); // Handle conditional parts in conditional expression } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) && *parent == SyntaxKind::Expression @@ -407,11 +409,11 @@ impl<'a> Formatter<'a> { | SyntaxKind::ConstrainingClause | SyntaxKind::Equation | SyntaxKind::Statement - | SyntaxKind::Element + | SyntaxKind::ElementList | SyntaxKind::EnumerationLiteral => self.markers.push(Marker::Dedent), SyntaxKind::Primary => { // Handle matrix or array - if [TokenKind::RBracket, TokenKind::RCurly].contains(&last.typ) { + if [TokenKind::LBracket, TokenKind::LCurly].contains(&first.typ) { self.exit_group(p_start, p_end); } } @@ -425,7 +427,7 @@ impl<'a> Formatter<'a> { if first.typ == TokenKind::If { self.exit_group(p_start, p_end); // Handle conditional part of the expression - } else if [TokenKind::Then, TokenKind::Else].contains(&first.typ) + } else if [TokenKind::Then, TokenKind::Else].contains(&self.tokens.get_token(p_start.tok-1).unwrap().typ) && *self.rules.last().unwrap() == SyntaxKind::Expression { self.markers.push(Marker::Dedent); @@ -467,3 +469,5 @@ fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> Some(comments) } } + +mod test {} diff --git a/src/lib.rs b/src/lib.rs index 85b13d0..9e51a80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub use self::printing::pretty_print; +pub use self::formatting::format; mod formatting; mod markers; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..006fa7f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,16 @@ +use moparse::{parse, lex, SyntaxKind}; +use mofmt::{pretty_print, format}; +use std::fs; +use std::env; + +fn main() { + let args: Vec = env::args().collect(); + let file_path = &args[1]; + let contents = fs::read_to_string(file_path) + .expect("error"); + let tokens = lex(&contents); + let events = parse(&tokens, SyntaxKind::StoredDefinition); + let markers = format(&tokens, &events); + let output = pretty_print(&tokens, &markers); + println!("{}", output); +} diff --git a/src/markers.rs b/src/markers.rs index 6bef406..b2f57c6 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -1,4 +1,3 @@ - #[derive(PartialEq, PartialOrd)] pub enum Marker { Token(usize), @@ -13,21 +12,20 @@ pub enum Marker { } pub struct MarkerCollector { - markers: Vec, + pub markers: Vec, } impl MarkerCollector { - pub fn new() -> Self { - MarkerCollector { markers: Vec::new() } + MarkerCollector { + markers: Vec::new(), + } } pub fn push(&mut self, m: Marker) { match m { Marker::Space => { - if self.markers.len() == 0 { - return; - } else if [Marker::Ignore, Marker::Space, Marker::Indent, Marker::Dedent].contains(&self.markers.last().unwrap()) { + if self.markers.len() == 0 || *self.markers.last().unwrap() >= Marker::Space { return; } } @@ -47,5 +45,4 @@ impl MarkerCollector { } self.markers.push(m); } - } diff --git a/src/printing.rs b/src/printing.rs index 5560838..d5ff5a4 100644 --- a/src/printing.rs +++ b/src/printing.rs @@ -24,7 +24,7 @@ impl Printer { fn print_marker(&mut self, m: &Marker, tokens: &TokenCollection) -> String { const INDENT: &str = " "; match m { - Marker::Space => String::from(" "), + Marker::Space => String::from(" "), Marker::Ignore => String::new(), Marker::Indent => { self.indent += 1; @@ -40,7 +40,7 @@ impl Printer { if m == &Marker::Blank { out += "\n"; } - for i in 1..self.indent { + for i in 0..self.indent { out += INDENT } out From ed3d8ac62a44a5f42166efdafb9ef9d0aaf9d5c2 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 4 Jan 2024 17:52:54 +0100 Subject: [PATCH 11/67] Use newer parser version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c401390..c044628 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.2-rc1" +moparse = "0.1.2-rc2" From 7f147f8a636d10c5e01520a475621b34ffb83efe Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 4 Jan 2024 17:53:33 +0100 Subject: [PATCH 12/67] Reproduce rest of the formatting style Needs tests --- src/formatting.rs | 83 +++++++++++++++++++++++++++++------------------ src/markers.rs | 24 +++++++++++++- 2 files changed, 74 insertions(+), 33 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 956f198..20ef802 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -19,13 +19,14 @@ struct Formatter<'a> { wraps: Vec, } -const NO_SPACE_AFTER: [TokenKind; 6] = [ +const NO_SPACE_AFTER: [TokenKind; 7] = [ TokenKind::LParen, TokenKind::Dot, TokenKind::LBracket, TokenKind::LCurly, TokenKind::Semi, TokenKind::Colon, + TokenKind::Connect, ]; const NO_SPACE_BEFORE: [TokenKind; 6] = [ TokenKind::RParen, @@ -60,10 +61,11 @@ impl<'a> Formatter<'a> { /// Handle comments and separate them if needed. fn handle_comments(&mut self, comments: Vec<&Token>, current_line: usize) { let mut line = self.prev_line; - let mut diff = comments[0].end.line - line; + let mut diff = comments[0].start.line - line; + let mut tail = Vec::new(); if diff == 0 { - // TODO: Handle inline comments - (); + // Handle inline comments + tail = self.markers.cache_tail(); } for comment in comments { diff = comment.start.line - line; @@ -77,12 +79,15 @@ impl<'a> Formatter<'a> { } } self.markers.push(Marker::Comment(comment.idx)); - line = comment.end.line; + line = comment.start.line; } diff = current_line - line; if self.prev_line == 1 { self.markers.push(Marker::Break); - } else if diff == 1 { + } else if tail.len() > 0 { + self.markers.append(&mut tail); + } + else if diff == 1 { self.markers.push(Marker::Break); } else if diff > 1 { self.markers.push(Marker::Blank); @@ -113,10 +118,10 @@ impl<'a> Formatter<'a> { // Mark the group as broken if group was multiline if first.start.line < last.end.line { // Handle conditional expression - if first.typ == TokenKind::If - && [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) - { - self.markers.push(Marker::Indent); + if first.typ == TokenKind::If { + if [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) { + self.markers.push(Marker::Indent); + } // Handle matrix row } else if typ == SyntaxKind::ExpressionList { if !*self.groups.last().unwrap() { @@ -135,11 +140,12 @@ impl<'a> Formatter<'a> { let group_broken = self.groups.pop().unwrap(); if group_broken { // Handle conditional expression - if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If - && [TokenKind::Equal, TokenKind::Assign] + if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If { + if [TokenKind::Equal, TokenKind::Assign] .contains(&self.tokens.get_token(enter.tok - 1).unwrap().typ) - { - self.markers.push(Marker::Dedent); + { + self.markers.push(Marker::Dedent); + } // Handle matrix row } else if exit.typ == SyntaxKind::ExpressionList { if !*self.groups.last().unwrap() { @@ -179,6 +185,10 @@ impl<'a> Formatter<'a> { } self.markers.push(Marker::Wrap); } + } else { + if !NO_SPACE_AFTER.contains(&self.prev_token) { + self.markers.push(Marker::Space); + } } } @@ -241,7 +251,7 @@ impl<'a> Formatter<'a> { } TokenKind::Dot => { // Only first dot in type specifiers etc. can be preceded with a space - if ![TokenKind::Ident, TokenKind::LBracket].contains(&self.prev_token) + if ![TokenKind::Ident, TokenKind::RBracket].contains(&self.prev_token) && !NO_SPACE_AFTER.contains(&self.prev_token) { self.markers.push(Marker::Space); @@ -283,24 +293,28 @@ impl<'a> Formatter<'a> { match kind { TokenKind::Annotation => self.markers.push(Marker::Space), - TokenKind::Then | TokenKind::Else | TokenKind::Loop => { - if [ - SyntaxKind::IfEquation, - SyntaxKind::IfStatement, - SyntaxKind::WhenEquation, - SyntaxKind::WhenStatement, - SyntaxKind::WhileStatement, - SyntaxKind::ForEquation, - SyntaxKind::ForStatement, + TokenKind::Equation | TokenKind::Algorithm => { + self.markers.push(Marker::Blank); + } + TokenKind::Plus | TokenKind::DotPlus | TokenKind::Minus | TokenKind::DotMinus => { + // Do not add next space if unary operator + if ![ + TokenKind::RBracket, + TokenKind::RParen, + TokenKind::RCurly, + TokenKind::Ident, + TokenKind::String, + TokenKind::Uint, + TokenKind::Ureal, + TokenKind::True, + TokenKind::False, + TokenKind::End, ] - .contains(&parent) + .contains(&self.prev_token) { - self.markers.push(Marker::Break); + self.markers.push(Marker::Ignore); } } - TokenKind::Equation | TokenKind::Algorithm => { - self.markers.push(Marker::Blank); - } _ => (), } @@ -337,13 +351,17 @@ impl<'a> Formatter<'a> { } SyntaxKind::Equation | SyntaxKind::Statement => { self.markers.push(Marker::Indent); + if [TokenKind::Loop, TokenKind::Then, TokenKind::Else] + .contains(&self.prev_token) + { + self.markers.push(Marker::Break); + } } SyntaxKind::ElementList => { self.markers.push(Marker::Indent); self.markers.push(Marker::Blank); } - | SyntaxKind::EquationSection - | SyntaxKind::AlgorithmSection => { + SyntaxKind::EquationSection | SyntaxKind::AlgorithmSection => { self.markers.push(Marker::Blank); } SyntaxKind::Primary => { @@ -427,7 +445,8 @@ impl<'a> Formatter<'a> { if first.typ == TokenKind::If { self.exit_group(p_start, p_end); // Handle conditional part of the expression - } else if [TokenKind::Then, TokenKind::Else].contains(&self.tokens.get_token(p_start.tok-1).unwrap().typ) + } else if [TokenKind::Then, TokenKind::Else] + .contains(&self.tokens.get_token(p_start.tok - 1).unwrap().typ) && *self.rules.last().unwrap() == SyntaxKind::Expression { self.markers.push(Marker::Dedent); diff --git a/src/markers.rs b/src/markers.rs index b2f57c6..1a41f4d 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -2,9 +2,9 @@ pub enum Marker { Token(usize), Comment(usize), - Space, Indent, Dedent, + Space, Ignore, Blank, Break, @@ -45,4 +45,26 @@ impl MarkerCollector { } self.markers.push(m); } + + pub fn cache_tail(&mut self) -> Vec { + let mut tail = Vec::new(); + loop { + let last = self.markers.last(); + if last.is_none() { + break; + } + if *last.unwrap() < Marker::Indent { + break; + } + if *last.unwrap() != Marker::Space { + tail.push(self.markers.pop().unwrap()); + } + } + tail.reverse(); + tail + } + + pub fn append(&mut self, markers: &mut Vec) { + self.markers.append(markers); + } } From 1b1d1ea54b8a5e7094779e29ca3e78c2317518d1 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 4 Jan 2024 17:58:37 +0100 Subject: [PATCH 13/67] Remove Python remnants --- .pre-commit-config.yaml | 10 - .pre-commit-hooks.yaml | 4 +- grammar/Modelica.g4 | 619 - grammar/ModelicaLexer.g4 | 154 - mofmt/__init__.py | 1 - mofmt/__main__.py | 3 - mofmt/collecting/__init__.py | 1 - mofmt/collecting/collector.py | 134 - mofmt/io/__init__.py | 5 - mofmt/io/io.py | 40 - mofmt/mofmt.py | 54 - mofmt/parsing/__init__.py | 5 - mofmt/parsing/generated/Modelica.interp | 310 - mofmt/parsing/generated/Modelica.py | 17744 ----------------- mofmt/parsing/generated/Modelica.tokens | 179 - mofmt/parsing/generated/ModelicaLexer.interp | 309 - mofmt/parsing/generated/ModelicaLexer.py | 7224 ------- mofmt/parsing/generated/ModelicaLexer.tokens | 179 - mofmt/parsing/generated/ModelicaListener.py | 943 - mofmt/parsing/generated/__init__.py | 5 - mofmt/parsing/parser.py | 412 - mofmt/parsing/parsing.py | 62 - mofmt/printing/__init__.py | 5 - mofmt/printing/printing.py | 63 - poetry.lock | 560 - pyproject.toml | 65 - scripts/__init__.py | 1 - scripts/generate_parser.py | 24 - tests/__init__.py | 0 tests/functional/__init__.py | 0 tests/functional/test_mofmt.py | 102 - tests/style/__init__.py | 0 tests/style/conftest.py | 21 - tests/style/test_style.py | 48 - tests/unit/__init__.py | 0 tests/unit/test_collector.py | 85 - tox.ini | 38 - 37 files changed, 2 insertions(+), 29407 deletions(-) delete mode 100644 grammar/Modelica.g4 delete mode 100644 grammar/ModelicaLexer.g4 delete mode 100644 mofmt/__init__.py delete mode 100644 mofmt/__main__.py delete mode 100644 mofmt/collecting/__init__.py delete mode 100644 mofmt/collecting/collector.py delete mode 100644 mofmt/io/__init__.py delete mode 100644 mofmt/io/io.py delete mode 100644 mofmt/mofmt.py delete mode 100644 mofmt/parsing/__init__.py delete mode 100644 mofmt/parsing/generated/Modelica.interp delete mode 100644 mofmt/parsing/generated/Modelica.py delete mode 100644 mofmt/parsing/generated/Modelica.tokens delete mode 100644 mofmt/parsing/generated/ModelicaLexer.interp delete mode 100644 mofmt/parsing/generated/ModelicaLexer.py delete mode 100644 mofmt/parsing/generated/ModelicaLexer.tokens delete mode 100644 mofmt/parsing/generated/ModelicaListener.py delete mode 100644 mofmt/parsing/generated/__init__.py delete mode 100644 mofmt/parsing/parser.py delete mode 100644 mofmt/parsing/parsing.py delete mode 100644 mofmt/printing/__init__.py delete mode 100644 mofmt/printing/printing.py delete mode 100644 poetry.lock delete mode 100644 pyproject.toml delete mode 100644 scripts/__init__.py delete mode 100644 scripts/generate_parser.py delete mode 100644 tests/__init__.py delete mode 100644 tests/functional/__init__.py delete mode 100644 tests/functional/test_mofmt.py delete mode 100644 tests/style/__init__.py delete mode 100644 tests/style/conftest.py delete mode 100644 tests/style/test_style.py delete mode 100644 tests/unit/__init__.py delete mode 100644 tests/unit/test_collector.py delete mode 100644 tox.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2836380..25c84cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,13 +5,3 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - -- repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 618e90e..4228215 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -2,5 +2,5 @@ name: mofmt description: Make your Modelica code pretty entry: mofmt - language: python - files: '.*\.mo$' \ No newline at end of file + language: rust + files: '.*\.mo$' diff --git a/grammar/Modelica.g4 b/grammar/Modelica.g4 deleted file mode 100644 index 68c80fa..0000000 --- a/grammar/Modelica.g4 +++ /dev/null @@ -1,619 +0,0 @@ -// This is ANTLR-4 file defining Modelica language parser rules -// Grammar files were defined based on the Modelica Specification -// See: https://specification.modelica.org/master/modelica-concrete-syntax.html -// There are some modifications, mostly few new "wrapper" rules, that -// were introduced to simplify some logic in mofmt. Such rules were -// marked with proper comments. - -// Grammar file created by Eryk Mroczek - -parser grammar Modelica; -options { tokenVocab=ModelicaLexer; } - -stored_definition - : (WITHIN name? SEMICOLON)? (FINAL? class_definition SEMICOLON)* - ; - -class_definition - : ENCAPSULATED? class_prefixes class_specifier - ; - -class_prefixes - : PARTIAL? - ( - CLASS - | MODEL - | OPERATOR? RECORD - | BLOCK - | EXPANDABLE? CONNECTOR - | TYPE - | PACKAGE - | (PURE | IMPURE)? OPERATOR? FUNCTION - | OPERATOR - ) - ; - -class_specifier - : long_class_specifier - | short_class_specifier - | der_class_specifier - ; - -long_class_specifier - : IDENT description_string composition end_clause - | EXTENDS IDENT class_modification? description_string composition end_clause - ; - -// not present in spec -end_clause - : END IDENT - ; - -short_class_specifier - : IDENT EQUAL base_prefix type_specifier array_subscripts? class_modification? description - | IDENT EQUAL ENUMERATION enumerations description - ; - -der_class_specifier - : IDENT EQUAL DER LPAREN type_specifier COMMA IDENT (COMMA IDENT)* RPAREN description - ; - -base_prefix - : (INPUT | OUTPUT)? - ; - -// not present in spec -enumerations - : LPAREN ( enum_list? | COLON ) RPAREN - ; - -enum_list - : enumeration_literal (COMMA enumeration_literal)* - ; - -enumeration_literal - : IDENT description - ; - -composition - : initial_element_list - ( - public_element_list - | protected_element_list - | equation_section - | algorithm_section - )* - external_element? - class_annotation? - ; - -// not present in spec -class_annotation - : ANNOTATION class_modification SEMICOLON - ; - -// not present in spec -external_element - : (EXTERNAL language_specification? external_function_call? - annotation? SEMICOLON) - ; - -language_specification - : STRING - ; - -external_function_call - : (component_reference EQUAL)? IDENT external_function_args - ; - -// not present in spec -external_function_args - : LPAREN expression_list? RPAREN - ; - -// not present in spec -initial_element_list - : element_list - ; - -// not present in spec -public_element_list - : PUBLIC element_list - ; - -// not present in spec -protected_element_list - : PROTECTED element_list - ; - -element_list - : (element SEMICOLON)* - ; - -element - : import_clause - | extends_clause - | declaration_clause - ; - -import_clause - : IMPORT - ( - IDENT EQUAL name - | name (DOTSTAR | (DOT LCURLY import_list RCURLY))? - ) - description - ; - - import_list - : IDENT (COMMA IDENT)* - ; - -// not present in spec -declaration_clause - : REDECLARE? FINAL? INNER? OUTER? REPLACEABLE? - (class_definition | component_clause) (constraining_clause description)? - ; - -extends_clause - : EXTENDS type_specifier class_or_inheritance_modification? annotation? - ; - -constraining_clause - : CONSTRAINEDBY type_specifier class_modification? - ; - -class_or_inheritance_modification - : LPAREN argument_or_inheritance_modification_list? RPAREN - ; - -argument_or_inheritance_modification_list - : (argument | inheritance_modification) (COMMA (argument | inheritance_modification))* - ; - -inheritance_modification - : BREAK (connect_equation | IDENT) - ; - -component_clause - : type_prefix type_specifier array_subscripts? component_list - ; - -type_prefix - : (FLOW | STREAM)? - (DISCRETE | PARAMETER | CONSTANT)? - (INPUT | OUTPUT)? - ; - -component_list - : component_declaration (COMMA component_declaration)* - ; - -component_declaration - : declaration (IF expression)? description - ; - -declaration - : IDENT array_subscripts? modification? - ; - -modification - : class_modification (EQUAL modification_expression)? - | EQUAL modification_expression - | ASSIGN modification_expression - ; - -modification_expression - : expression - | BREAK - ; - -class_modification - : LPAREN argument_list? RPAREN - ; - -argument_list - : argument (COMMA argument)* - ; - -argument - : element_modification_or_replaceable - | element_redeclaration - ; - -element_modification_or_replaceable - : EACH? FINAL? (element_modification | element_replaceable) - ; - -element_modification - : name modification? description_string - ; - -element_redeclaration - : REDECLARE EACH? FINAL? - ( - short_definition - | short_component_clause - | element_replaceable - ) - ; - -element_replaceable - : REPLACEABLE - ( - short_definition - | short_component_clause - ) - constraining_clause? - ; - -// originally called component-clause1 in spec -short_component_clause - : type_prefix type_specifier short_component_declaration - ; - -// originally called component-declaration1 in spec -short_component_declaration - : declaration description - ; - -// originally called short-class-definition in spec -short_definition - : class_prefixes short_class_specifier - ; - -equation_section - : INITIAL? EQUATION equation_list - ; - -algorithm_section - : INITIAL? ALGORITHM statement_list - ; - -// not present in spec -equation_list - : (equation SEMICOLON)* - ; - -// not present in spec -statement_list - : (statement SEMICOLON)* - ; - -equation - : ( - simple_expression EQUAL expression - | if_equation - | for_equation - | connect_equation - | when_equation - | component_reference function_call_args - ) - description - ; - -statement - : ( - component_reference (ASSIGN expression | function_call_args) - | LPAREN output_expression_list RPAREN ASSIGN component_reference function_call_args - | BREAK - | RETURN - | if_statement - | for_statement - | while_statement - | when_statement - ) - description - ; - -if_equation - : if_branch - conditional_equations - ( - elseif_branch - conditional_equations - )* - ( - else_branch - conditional_equations - )? - END IF - ; - -// not present in spec -conditional_equations - : (equation SEMICOLON)* - ; - -if_statement - : if_branch - conditional_statements - ( - elseif_branch - conditional_statements - )* - ( - else_branch - conditional_statements - )? - END IF - ; - -// not present in spec -if_branch - : IF expression THEN - ; - -// not present in spec -elseif_branch - : ELSEIF expression THEN - ; - -// not present in spec -else_branch - : ELSE - ; - -// not present in spec -conditional_statements - : (statement SEMICOLON)* - ; - -for_equation - : FOR for_indices LOOP - conditional_equations - END FOR - ; - -for_statement - : FOR for_indices LOOP - conditional_statements - END FOR - ; - -for_indices - : for_index (COMMA for_index)* - ; - -for_index - : - IDENT (IN expression)? - ; - -while_statement - : WHILE expression LOOP - conditional_statements - END WHILE - ; - -when_equation - : when_branch - conditional_equations - ( - elsewhen_branch - conditional_equations - )* - END WHEN - ; - -when_statement - : when_branch - conditional_statements - ( - elsewhen_branch - conditional_statements - )* - END WHEN - ; - -// not present in spec -when_branch - : WHEN expression THEN - ; - -// not present in spec -elsewhen_branch - : ELSEWHEN expression THEN - ; - -connect_equation - : CONNECT connected_components - ; - -// not present in spec -connected_components - : LPAREN component_reference COMMA component_reference RPAREN - ; - -expression - : simple_expression | if_expression - ; - -// not present in spec -if_expression - : if_eval conditional_expression - (elseif_eval conditional_expression)* - else_eval conditional_expression - ; - -// not present in spec -if_eval - : IF expression THEN - ; - -// not present in spec -elseif_eval - : ELSEIF expression THEN - ; - -// not present in spec -else_eval - : ELSE - ; - -// not present in spec -conditional_expression - : expression - ; - -simple_expression - : logical_expression (COLON logical_expression (COLON logical_expression)?)? - ; - -logical_expression - : logical_term (or_operator logical_term)* - ; - -// not present in spec -or_operator - : OR - ; - -logical_term - : logical_factor (and_operator logical_factor)* - ; - -// not present in spec -and_operator - : AND - ; - -logical_factor - : NOT? relation - ; - -relation - : arithmetic_expression (relational_operator arithmetic_expression)? - ; - -relational_operator - : GRE | GEQ - | LES | LEQ - | NEQ | EEQ - ; - -arithmetic_expression - : term (add_operator term)* - ; - -// not present in spec -unary_expression - : add_operator unary_operand - ; - -// not present in spec -unary_operand - : primary - ; - -add_operator - : PLUS | MINUS - | DOTPLUS | DOTMINUS - ; - -term - : factor (mul_operator factor)* - ; - -mul_operator - : STAR | SLASH - | DOTSTAR | DOTSLASH - ; - -factor - : primary (exp_operator primary)? - ; - -exp_operator - : FLEX | DOTFLEX - ; - - -primary - : UNUM - | STRING - | BOOL - | unary_expression - | (component_reference | DER | INITIAL | PURE) function_call_args - | component_reference - | LPAREN output_expression_list RPAREN - | LBRACK expression_list (SEMICOLON expression_list)* RBRACK - | LCURLY array_arguments RCURLY - | END - ; - -type_specifier - : DOT? IDENT (DOT IDENT)* ; - -name - : IDENT (DOT IDENT)* - ; - -component_reference - : DOT? IDENT array_subscripts? (DOT IDENT array_subscripts?)* - ; - -function_call_args - : LPAREN function_arguments? RPAREN - ; - -function_arguments - : expression FOR for_indices - | function_argument (COMMA function_argument)* (COMMA named_arguments)? - | named_arguments - ; - -named_arguments - : named_argument (COMMA named_argument)* - ; - -named_argument - : IDENT EQUAL function_argument - ; - -function_argument - : function_partial_application - | expression - ; - -function_partial_application - : FUNCTION type_specifier LPAREN named_arguments? RPAREN - ; - -output_expression_list - : expression? (COMMA expression?)* - ; - -expression_list - : expression (COMMA expression)* - ; - -array_arguments - : expression ((COMMA expression)* | FOR for_indices) - ; - -array_subscripts - : LBRACK subscript (COMMA subscript)* RBRACK - ; - -subscript - : COLON | expression - ; - -description - : description_string annotation? - ; - - -description_string - : (STRING (cat_operator STRING)*)? - ; - -// not present in spec -cat_operator - : PLUS - ; - -annotation - : ANNOTATION class_modification - ; diff --git a/grammar/ModelicaLexer.g4 b/grammar/ModelicaLexer.g4 deleted file mode 100644 index 555a943..0000000 --- a/grammar/ModelicaLexer.g4 +++ /dev/null @@ -1,154 +0,0 @@ -// This is ANTLR-4 file defining Modelica language tokens -// Grammar files were defined based on the Modelica Specification -// See: https://specification.modelica.org/master/modelica-concrete-syntax.html - -// Grammar defined by Eryk Mroczek - -lexer grammar ModelicaLexer; - -channels { - WHITESPACE, - COMMENTS -} - -// Whitespace tokens -WS : [ \r\n\t] + -> channel (WHITESPACE) ; - -// Misc tokens -DQUOTE : '"' ; -COMMA : ',' ; -DOT : '.' ; -SEMICOLON : ';' ; -COLON : ':' ; - -// Parentheses tokens -LPAREN : '(' ; -RPAREN : ')' ; -LCURLY : '{' ; -RCURLY : '}' ; -LBRACK : '[' ; -RBRACK : ']' ; - -// Operator tokens -EQUAL : '=' ; -ASSIGN : ':=' ; - -PLUS : '+' ; -MINUS : '-' ; -STAR : '*' ; -SLASH : '/' ; -FLEX : '^' ; -DOTPLUS : '.+' ; -DOTMINUS : '.-' ; -DOTSTAR : '.*' ; -DOTSLASH : './' ; -DOTFLEX : '.^' ; - -GRE : '>' ; -GEQ : '>=' ; -LES : '<' ; -LEQ : '<=' ; -NEQ : '<>' ; -EEQ : '==' ; - -NOT : 'not' ; -AND : 'and' ; -OR : 'or' ; - -// Control flow tokens -IN : 'in' ; -FOR : 'for' ; -IF : 'if' ; -ELSE : 'else' ; -ELSEIF : 'elseif' ; -THEN : 'then' ; -WHEN : 'when' ; -ELSEWHEN : 'elsewhen' ; -WHILE : 'while' ; -LOOP : 'loop' ; -BREAK : 'break' ; -RETURN : 'return' ; - -// Class tokens -PARTIAL : 'partial' ; -OPERATOR : 'operator' ; -EXPANDABLE : 'expandable' ; -CLASS : 'class' ; -MODEL : 'model' ; -FUNCTION : 'function' ; -RECORD : 'record' ; -TYPE : 'type' ; -BLOCK : 'block' ; -CONNECTOR : 'connector' ; -PACKAGE : 'package' ; -PURE : 'pure' ; -IMPURE : 'impure' ; - -// Keyword tokens -END : 'end' ; -DER : 'der' ; -CONNECT : 'connect' ; -INITIAL : 'initial' ; -EQUATION : 'equation' ; -ALGORITHM : 'algorithm' ; -WITHIN : 'within' ; -FINAL : 'final' ; -ENCAPSULATED : 'encapsulated' ; -EXTENDS : 'extends' ; -IMPORT : 'import' ; -ENUMERATION : 'enumeration' ; -INPUT : 'input' ; -OUTPUT : 'output' ; -PUBLIC : 'public' ; -PROTECTED : 'protected' ; -REDECLARE : 'redeclare' ; -INNER : 'inner' ; -OUTER : 'outer' ; -REPLACEABLE : 'replaceable' ; -CONSTRAINEDBY : 'constrainedby' ; -FLOW : 'flow' ; -STREAM : 'stream' ; -DISCRETE : 'discrete' ; -PARAMETER : 'parameter' ; -CONSTANT : 'constant' ; -EACH : 'each' ; -ANNOTATION : 'annotation' ; -EXTERNAL : 'external' ; - -// Comment tokens -BLOCK_COMMENT : '/*' .*? '*/' -> channel (COMMENTS) ; -LINE_COMMENT : '//' ~[\r\n]* -> channel (COMMENTS) ; - -// Fragment tokens -fragment S_ESCAPE : '\\' ('\'' | '"' | '?' | '\\' | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v') ; -fragment DIGIT : [0-9] ; -fragment NONDIGIT : [a-zA-Z_] ; -fragment Q_CHAR - : NONDIGIT - | DIGIT - | '!' | '#' | '$' | '%' | '&' - | '(' | ')' - | '*' | '+' | ',' | '-' | '.' | '/' - | ':' | ';' - | '<' | '>' | '=' - | '?' | '@' - | '[' | ']' - | '^' - | '{' | '}' - | '|' | '~' - | '"' - | ' ' - ; -fragment Q_IDENT : '\'' (Q_CHAR | S_ESCAPE)* '\'' ; -fragment S_CHAR : ~ ["\\] ; - -fragment E : 'e' | 'E' ; -fragment UINT : DIGIT+ ; -fragment UREAL : UINT (DOT (UINT)?)? (E (PLUS | MINUS)? UINT)? ; - -// Literal tokens -STRING : DQUOTE ( S_CHAR | S_ESCAPE )* DQUOTE ; -UNUM : UREAL | UINT ; -BOOL : 'true' | 'false' ; - -IDENT : NONDIGIT (DIGIT | NONDIGIT)* | Q_IDENT ; diff --git a/mofmt/__init__.py b/mofmt/__init__.py deleted file mode 100644 index a8d4557..0000000 --- a/mofmt/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.3.5" diff --git a/mofmt/__main__.py b/mofmt/__main__.py deleted file mode 100644 index d11c9aa..0000000 --- a/mofmt/__main__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .mofmt import main - -main() diff --git a/mofmt/collecting/__init__.py b/mofmt/collecting/__init__.py deleted file mode 100644 index adaab06..0000000 --- a/mofmt/collecting/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Module related to collecting markers that are used in printing""" diff --git a/mofmt/collecting/collector.py b/mofmt/collecting/collector.py deleted file mode 100644 index cf19ba9..0000000 --- a/mofmt/collecting/collector.py +++ /dev/null @@ -1,134 +0,0 @@ -"""Classes used for collecting printing markers""" - -import json - - -class Marker: - """ - Represents single printing marker (token, space, newline etc.). - - Attributes - ---------- - typ : int - Type of marker. - val : str - String value of marker. Used for printing. - rep : str - String representation. Mostly for debugging purposes. - """ - - # Integers indicate type - TOKEN = 0 - COMMENT = 1 - SPACE = 2 - INDENT = 3 - DEDENT = 4 - IGNORE = 5 - BLANK = 6 - BREAK = 7 - WRAPPOINT = 8 - - __slots__ = ("typ", "val", "rep") - - def __init__(self, typ: int, val: str, rep: str) -> None: - self.typ = typ - self.val = val - self.rep = rep - - def __repr__(self) -> str: - return self.rep - - def __str__(self) -> str: - return self.val - - -class Collector: - """Represents collector that gathers formatting markers""" - - __slots__ = ("markers", "wrapped") - - def __init__(self) -> None: - self.markers: list[Marker] = [] - - def add_marker(self, marker: Marker) -> None: - """Add marker""" - self.markers.append(marker) - - def add_token(self, val: str) -> None: - """Add a token marker""" - self.add_marker(Marker(Marker.TOKEN, val, val)) - - def add_comment(self, val: str) -> None: - """Add a comment marker""" - self.add_marker(Marker(Marker.COMMENT, val, val)) - - def cache_tail(self) -> list[Marker]: - """Return last few markers that are not tokens or comments""" - tail = [] - while len(self.markers) > 0: - if self.markers[-1].typ <= Marker.COMMENT: - break - last = self.markers.pop() - if last.typ != Marker.SPACE: - tail.append(last) - tail.reverse() - return tail - - def append(self, markers: list[Marker]) -> None: - """Append cached markers""" - self.markers.extend(markers) - - def add_space(self) -> None: - """Add a space marker""" - if len(self.markers) == 0: - return - if self.markers[-1].typ >= Marker.IGNORE: - return - if self.markers[-1].typ == Marker.SPACE: - return - if ( - self.markers[-1].typ in {Marker.INDENT, Marker.DEDENT} - and self.markers[-2].typ >= Marker.BLANK - ): - return - self.add_marker(Marker(Marker.SPACE, " ", "SPACE")) - - def add_ignore(self) -> None: - """Add a ignore space marker""" - self.add_marker(Marker(Marker.IGNORE, "", "IGNORE")) - - def add_blank(self) -> None: - """Add a blank marker""" - if self.markers[-1].typ >= Marker.BLANK: - self.markers.pop() - self.add_marker(Marker(Marker.BLANK, "\n\n", "BLANK")) - - def add_break(self) -> None: - """Add a hard break marker""" - if self.markers[-1].typ >= Marker.BLANK: - return - self.add_marker(Marker(Marker.BREAK, "\n", "BREAK")) - - def add_wrappoint(self) -> None: - """Add a soft break marker""" - self.add_marker(Marker(Marker.WRAPPOINT, "\n", "WRAP")) - - def add_indent(self) -> None: - """Increase indentation before next marker""" - self.add_marker(Marker(Marker.INDENT, "", "INDENT")) - - def add_dedent(self) -> None: - """Decrease indentation before next marker""" - if self.markers[-1].typ == Marker.INDENT: - self.markers.pop() - else: - self.add_marker(Marker(Marker.DEDENT, "", "DEDENT")) - - def __repr__(self) -> str: - return [n.rep for n in self.markers].__repr__() - - def __str__(self) -> str: - return json.dumps( - self.__repr__(), - indent=2, - ) diff --git a/mofmt/io/__init__.py b/mofmt/io/__init__.py deleted file mode 100644 index 805ee09..0000000 --- a/mofmt/io/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""File IO module""" - -__all__ = ["get_files_from_dir", "read_file", "write_file"] - -from .io import get_files_from_dir, read_file, write_file diff --git a/mofmt/io/io.py b/mofmt/io/io.py deleted file mode 100644 index 07f49e9..0000000 --- a/mofmt/io/io.py +++ /dev/null @@ -1,40 +0,0 @@ -"""Helper functions for file IO""" - -from pathlib import Path - - -class NotModelicaFileError(Exception): - """Custom exception raised when specified file is not a valid Modelica""" - - def __init__(self, file: Path) -> None: - self.message = f"{file} is not a valid Modelica file" - super().__init__(self.message) - - -def get_files_from_dir(directory: Path) -> list[Path]: - """Return list of Modelica files inside directory""" - return list(directory.rglob("*.mo")) - - -def read_file(path: Path) -> str: - """Return file contents""" - - if not path.is_file(): - raise FileNotFoundError(f"file {path} not found") - if path.suffix != ".mo": - raise NotModelicaFileError(path) - try: - with path.open("r", encoding="utf-8") as file: - contents = file.read() - except UnicodeDecodeError as exc: - raise UnicodeError(f"{path} is not a valid text file") from exc - return contents - - -def write_file(path: Path, code: str) -> None: - """Write code string to a file""" - try: - with path.open("w", encoding="utf-8") as file: - file.write(code) - except PermissionError as exc: - raise PermissionError(f"Couldn't write to {path}") from exc diff --git a/mofmt/mofmt.py b/mofmt/mofmt.py deleted file mode 100644 index 50f65e7..0000000 --- a/mofmt/mofmt.py +++ /dev/null @@ -1,54 +0,0 @@ -import sys -from itertools import chain -from pathlib import Path - -from mofmt import __version__ -from mofmt.io import get_files_from_dir, read_file, write_file -from mofmt.parsing import parse_source -from mofmt.printing import Printer - -HELP_MSG = """ -mofmt: Modelica code formatter - -Usage: mofmt SRC ... - -Options: --h, --help: display this message and exit --v, --version: display a version number and exit -""" - - -def main() -> None: - if len(sys.argv) < 2: - raise SystemExit(HELP_MSG) - else: - if sys.argv[1] in ("-h", "--help"): - raise SystemExit(HELP_MSG) - elif sys.argv[1] in ("-v", "--version"): - raise SystemExit(f"mofmt, {__version__}") - format_files(sys.argv) - - -def format_files(args: list[str]) -> None: - """Format files specified in argument list""" - paths = [Path(arg) for arg in args[1:]] - modelica_files = list( - chain.from_iterable( - (get_files_from_dir(p) if p.is_dir() else [p] for p in paths) - ) - ) - for file in modelica_files: - contents = read_file(file) - parsed = parse_source(file, contents) - if parsed: - fmt = Printer(parsed).pretty_print() - write_file(file, fmt) - else: - print( - f"errors met while parsing {file}. Formatter will not modify it", - file=sys.stderr, - ) - - -if __name__ == "__main__": - main() diff --git a/mofmt/parsing/__init__.py b/mofmt/parsing/__init__.py deleted file mode 100644 index b6398fd..0000000 --- a/mofmt/parsing/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Module related to parsing Modelica source""" - -__all__ = ["parse_source"] - -from .parsing import parse_source diff --git a/mofmt/parsing/generated/Modelica.interp b/mofmt/parsing/generated/Modelica.interp deleted file mode 100644 index 4a556f8..0000000 --- a/mofmt/parsing/generated/Modelica.interp +++ /dev/null @@ -1,310 +0,0 @@ -token literal names: -null -null -'"' -',' -'.' -';' -':' -'(' -')' -'{' -'}' -'[' -']' -'=' -':=' -'+' -'-' -'*' -'/' -'^' -'.+' -'.-' -'.*' -'./' -'.^' -'>' -'>=' -'<' -'<=' -'<>' -'==' -'not' -'and' -'or' -'in' -'for' -'if' -'else' -'elseif' -'then' -'when' -'elsewhen' -'while' -'loop' -'break' -'return' -'partial' -'operator' -'expandable' -'class' -'model' -'function' -'record' -'type' -'block' -'connector' -'package' -'pure' -'impure' -'end' -'der' -'connect' -'initial' -'equation' -'algorithm' -'within' -'final' -'encapsulated' -'extends' -'import' -'enumeration' -'input' -'output' -'public' -'protected' -'redeclare' -'inner' -'outer' -'replaceable' -'constrainedby' -'flow' -'stream' -'discrete' -'parameter' -'constant' -'each' -'annotation' -'external' -null -null -null -null -null -null - -token symbolic names: -null -WS -DQUOTE -COMMA -DOT -SEMICOLON -COLON -LPAREN -RPAREN -LCURLY -RCURLY -LBRACK -RBRACK -EQUAL -ASSIGN -PLUS -MINUS -STAR -SLASH -FLEX -DOTPLUS -DOTMINUS -DOTSTAR -DOTSLASH -DOTFLEX -GRE -GEQ -LES -LEQ -NEQ -EEQ -NOT -AND -OR -IN -FOR -IF -ELSE -ELSEIF -THEN -WHEN -ELSEWHEN -WHILE -LOOP -BREAK -RETURN -PARTIAL -OPERATOR -EXPANDABLE -CLASS -MODEL -FUNCTION -RECORD -TYPE -BLOCK -CONNECTOR -PACKAGE -PURE -IMPURE -END -DER -CONNECT -INITIAL -EQUATION -ALGORITHM -WITHIN -FINAL -ENCAPSULATED -EXTENDS -IMPORT -ENUMERATION -INPUT -OUTPUT -PUBLIC -PROTECTED -REDECLARE -INNER -OUTER -REPLACEABLE -CONSTRAINEDBY -FLOW -STREAM -DISCRETE -PARAMETER -CONSTANT -EACH -ANNOTATION -EXTERNAL -BLOCK_COMMENT -LINE_COMMENT -STRING -UNUM -BOOL -IDENT - -rule names: -stored_definition -class_definition -class_prefixes -class_specifier -long_class_specifier -end_clause -short_class_specifier -der_class_specifier -base_prefix -enumerations -enum_list -enumeration_literal -composition -class_annotation -external_element -language_specification -external_function_call -external_function_args -initial_element_list -public_element_list -protected_element_list -element_list -element -import_clause -import_list -declaration_clause -extends_clause -constraining_clause -class_or_inheritance_modification -argument_or_inheritance_modification_list -inheritance_modification -component_clause -type_prefix -component_list -component_declaration -declaration -modification -modification_expression -class_modification -argument_list -argument -element_modification_or_replaceable -element_modification -element_redeclaration -element_replaceable -short_component_clause -short_component_declaration -short_definition -equation_section -algorithm_section -equation_list -statement_list -equation -statement -if_equation -conditional_equations -if_statement -if_branch -elseif_branch -else_branch -conditional_statements -for_equation -for_statement -for_indices -for_index -while_statement -when_equation -when_statement -when_branch -elsewhen_branch -connect_equation -connected_components -expression -if_expression -if_eval -elseif_eval -else_eval -conditional_expression -simple_expression -logical_expression -or_operator -logical_term -and_operator -logical_factor -relation -relational_operator -arithmetic_expression -unary_expression -unary_operand -add_operator -term -mul_operator -factor -exp_operator -primary -type_specifier -name -component_reference -function_call_args -function_arguments -named_arguments -named_argument -function_argument -function_partial_application -output_expression_list -expression_list -array_arguments -array_subscripts -subscript -description -description_string -cat_operator -annotation - - -atn: -[4, 1, 93, 1133, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 2, 62, 7, 62, 2, 63, 7, 63, 2, 64, 7, 64, 2, 65, 7, 65, 2, 66, 7, 66, 2, 67, 7, 67, 2, 68, 7, 68, 2, 69, 7, 69, 2, 70, 7, 70, 2, 71, 7, 71, 2, 72, 7, 72, 2, 73, 7, 73, 2, 74, 7, 74, 2, 75, 7, 75, 2, 76, 7, 76, 2, 77, 7, 77, 2, 78, 7, 78, 2, 79, 7, 79, 2, 80, 7, 80, 2, 81, 7, 81, 2, 82, 7, 82, 2, 83, 7, 83, 2, 84, 7, 84, 2, 85, 7, 85, 2, 86, 7, 86, 2, 87, 7, 87, 2, 88, 7, 88, 2, 89, 7, 89, 2, 90, 7, 90, 2, 91, 7, 91, 2, 92, 7, 92, 2, 93, 7, 93, 2, 94, 7, 94, 2, 95, 7, 95, 2, 96, 7, 96, 2, 97, 7, 97, 2, 98, 7, 98, 2, 99, 7, 99, 2, 100, 7, 100, 2, 101, 7, 101, 2, 102, 7, 102, 2, 103, 7, 103, 2, 104, 7, 104, 2, 105, 7, 105, 2, 106, 7, 106, 2, 107, 7, 107, 2, 108, 7, 108, 2, 109, 7, 109, 2, 110, 7, 110, 2, 111, 7, 111, 2, 112, 7, 112, 1, 0, 1, 0, 3, 0, 229, 8, 0, 1, 0, 3, 0, 232, 8, 0, 1, 0, 3, 0, 235, 8, 0, 1, 0, 1, 0, 1, 0, 5, 0, 240, 8, 0, 10, 0, 12, 0, 243, 9, 0, 1, 1, 3, 1, 246, 8, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 252, 8, 2, 1, 2, 1, 2, 1, 2, 3, 2, 257, 8, 2, 1, 2, 1, 2, 1, 2, 3, 2, 262, 8, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 268, 8, 2, 1, 2, 3, 2, 271, 8, 2, 1, 2, 1, 2, 3, 2, 275, 8, 2, 1, 3, 1, 3, 1, 3, 3, 3, 280, 8, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 290, 8, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 296, 8, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 306, 8, 6, 1, 6, 3, 6, 309, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 319, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 330, 8, 7, 10, 7, 12, 7, 333, 9, 7, 1, 7, 1, 7, 1, 7, 1, 8, 3, 8, 339, 8, 8, 1, 9, 1, 9, 3, 9, 343, 8, 9, 1, 9, 3, 9, 346, 8, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 5, 10, 353, 8, 10, 10, 10, 12, 10, 356, 9, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 5, 12, 366, 8, 12, 10, 12, 12, 12, 369, 9, 12, 1, 12, 3, 12, 372, 8, 12, 1, 12, 3, 12, 375, 8, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 3, 14, 383, 8, 14, 1, 14, 3, 14, 386, 8, 14, 1, 14, 3, 14, 389, 8, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 3, 16, 398, 8, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 3, 17, 405, 8, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 5, 21, 420, 8, 21, 10, 21, 12, 21, 423, 9, 21, 1, 22, 1, 22, 1, 22, 3, 22, 428, 8, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 3, 23, 441, 8, 23, 3, 23, 443, 8, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, 5, 24, 450, 8, 24, 10, 24, 12, 24, 453, 9, 24, 1, 25, 3, 25, 456, 8, 25, 1, 25, 3, 25, 459, 8, 25, 1, 25, 3, 25, 462, 8, 25, 1, 25, 3, 25, 465, 8, 25, 1, 25, 3, 25, 468, 8, 25, 1, 25, 1, 25, 3, 25, 472, 8, 25, 1, 25, 1, 25, 1, 25, 3, 25, 477, 8, 25, 1, 26, 1, 26, 1, 26, 3, 26, 482, 8, 26, 1, 26, 3, 26, 485, 8, 26, 1, 27, 1, 27, 1, 27, 3, 27, 490, 8, 27, 1, 28, 1, 28, 3, 28, 494, 8, 28, 1, 28, 1, 28, 1, 29, 1, 29, 3, 29, 500, 8, 29, 1, 29, 1, 29, 1, 29, 3, 29, 505, 8, 29, 5, 29, 507, 8, 29, 10, 29, 12, 29, 510, 9, 29, 1, 30, 1, 30, 1, 30, 3, 30, 515, 8, 30, 1, 31, 1, 31, 1, 31, 3, 31, 520, 8, 31, 1, 31, 1, 31, 1, 32, 3, 32, 525, 8, 32, 1, 32, 3, 32, 528, 8, 32, 1, 32, 3, 32, 531, 8, 32, 1, 33, 1, 33, 1, 33, 5, 33, 536, 8, 33, 10, 33, 12, 33, 539, 9, 33, 1, 34, 1, 34, 1, 34, 3, 34, 544, 8, 34, 1, 34, 1, 34, 1, 35, 1, 35, 3, 35, 550, 8, 35, 1, 35, 3, 35, 553, 8, 35, 1, 36, 1, 36, 1, 36, 3, 36, 558, 8, 36, 1, 36, 1, 36, 1, 36, 1, 36, 3, 36, 564, 8, 36, 1, 37, 1, 37, 3, 37, 568, 8, 37, 1, 38, 1, 38, 3, 38, 572, 8, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 5, 39, 579, 8, 39, 10, 39, 12, 39, 582, 9, 39, 1, 40, 1, 40, 3, 40, 586, 8, 40, 1, 41, 3, 41, 589, 8, 41, 1, 41, 3, 41, 592, 8, 41, 1, 41, 1, 41, 3, 41, 596, 8, 41, 1, 42, 1, 42, 3, 42, 600, 8, 42, 1, 42, 1, 42, 1, 43, 1, 43, 3, 43, 606, 8, 43, 1, 43, 3, 43, 609, 8, 43, 1, 43, 1, 43, 1, 43, 3, 43, 614, 8, 43, 1, 44, 1, 44, 1, 44, 3, 44, 619, 8, 44, 1, 44, 3, 44, 622, 8, 44, 1, 45, 1, 45, 1, 45, 1, 45, 1, 46, 1, 46, 1, 46, 1, 47, 1, 47, 1, 47, 1, 48, 3, 48, 635, 8, 48, 1, 48, 1, 48, 1, 48, 1, 49, 3, 49, 641, 8, 49, 1, 49, 1, 49, 1, 49, 1, 50, 1, 50, 1, 50, 5, 50, 649, 8, 50, 10, 50, 12, 50, 652, 9, 50, 1, 51, 1, 51, 1, 51, 5, 51, 657, 8, 51, 10, 51, 12, 51, 660, 9, 51, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 3, 52, 673, 8, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 3, 53, 681, 8, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 3, 53, 696, 8, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 5, 54, 705, 8, 54, 10, 54, 12, 54, 708, 9, 54, 1, 54, 1, 54, 1, 54, 3, 54, 713, 8, 54, 1, 54, 1, 54, 1, 54, 1, 55, 1, 55, 1, 55, 5, 55, 721, 8, 55, 10, 55, 12, 55, 724, 9, 55, 1, 56, 1, 56, 1, 56, 1, 56, 1, 56, 5, 56, 731, 8, 56, 10, 56, 12, 56, 734, 9, 56, 1, 56, 1, 56, 1, 56, 3, 56, 739, 8, 56, 1, 56, 1, 56, 1, 56, 1, 57, 1, 57, 1, 57, 1, 57, 1, 58, 1, 58, 1, 58, 1, 58, 1, 59, 1, 59, 1, 60, 1, 60, 1, 60, 5, 60, 757, 8, 60, 10, 60, 12, 60, 760, 9, 60, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 63, 1, 63, 1, 63, 5, 63, 779, 8, 63, 10, 63, 12, 63, 782, 9, 63, 1, 64, 1, 64, 1, 64, 3, 64, 787, 8, 64, 1, 65, 1, 65, 1, 65, 1, 65, 1, 65, 1, 65, 1, 65, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 5, 66, 801, 8, 66, 10, 66, 12, 66, 804, 9, 66, 1, 66, 1, 66, 1, 66, 1, 67, 1, 67, 1, 67, 1, 67, 1, 67, 5, 67, 814, 8, 67, 10, 67, 12, 67, 817, 9, 67, 1, 67, 1, 67, 1, 67, 1, 68, 1, 68, 1, 68, 1, 68, 1, 69, 1, 69, 1, 69, 1, 69, 1, 70, 1, 70, 1, 70, 1, 71, 1, 71, 1, 71, 1, 71, 1, 71, 1, 71, 1, 72, 1, 72, 3, 72, 841, 8, 72, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 5, 73, 848, 8, 73, 10, 73, 12, 73, 851, 9, 73, 1, 73, 1, 73, 1, 73, 1, 74, 1, 74, 1, 74, 1, 74, 1, 75, 1, 75, 1, 75, 1, 75, 1, 76, 1, 76, 1, 77, 1, 77, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 3, 78, 873, 8, 78, 3, 78, 875, 8, 78, 1, 79, 1, 79, 1, 79, 1, 79, 5, 79, 881, 8, 79, 10, 79, 12, 79, 884, 9, 79, 1, 80, 1, 80, 1, 81, 1, 81, 1, 81, 1, 81, 5, 81, 892, 8, 81, 10, 81, 12, 81, 895, 9, 81, 1, 82, 1, 82, 1, 83, 3, 83, 900, 8, 83, 1, 83, 1, 83, 1, 84, 1, 84, 1, 84, 1, 84, 3, 84, 908, 8, 84, 1, 85, 1, 85, 1, 86, 1, 86, 1, 86, 1, 86, 5, 86, 916, 8, 86, 10, 86, 12, 86, 919, 9, 86, 1, 87, 1, 87, 1, 87, 1, 88, 1, 88, 1, 89, 1, 89, 1, 90, 1, 90, 1, 90, 1, 90, 5, 90, 932, 8, 90, 10, 90, 12, 90, 935, 9, 90, 1, 91, 1, 91, 1, 92, 1, 92, 1, 92, 1, 92, 3, 92, 943, 8, 92, 1, 93, 1, 93, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 3, 94, 955, 8, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 5, 94, 967, 8, 94, 10, 94, 12, 94, 970, 9, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 1, 94, 3, 94, 979, 8, 94, 1, 95, 3, 95, 982, 8, 95, 1, 95, 1, 95, 1, 95, 5, 95, 987, 8, 95, 10, 95, 12, 95, 990, 9, 95, 1, 96, 1, 96, 1, 96, 5, 96, 995, 8, 96, 10, 96, 12, 96, 998, 9, 96, 1, 97, 3, 97, 1001, 8, 97, 1, 97, 1, 97, 3, 97, 1005, 8, 97, 1, 97, 1, 97, 1, 97, 3, 97, 1010, 8, 97, 5, 97, 1012, 8, 97, 10, 97, 12, 97, 1015, 9, 97, 1, 98, 1, 98, 3, 98, 1019, 8, 98, 1, 98, 1, 98, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 1, 99, 5, 99, 1030, 8, 99, 10, 99, 12, 99, 1033, 9, 99, 1, 99, 1, 99, 3, 99, 1037, 8, 99, 1, 99, 3, 99, 1040, 8, 99, 1, 100, 1, 100, 1, 100, 5, 100, 1045, 8, 100, 10, 100, 12, 100, 1048, 9, 100, 1, 101, 1, 101, 1, 101, 1, 101, 1, 102, 1, 102, 3, 102, 1056, 8, 102, 1, 103, 1, 103, 1, 103, 1, 103, 3, 103, 1062, 8, 103, 1, 103, 1, 103, 1, 104, 3, 104, 1067, 8, 104, 1, 104, 1, 104, 3, 104, 1071, 8, 104, 5, 104, 1073, 8, 104, 10, 104, 12, 104, 1076, 9, 104, 1, 105, 1, 105, 1, 105, 5, 105, 1081, 8, 105, 10, 105, 12, 105, 1084, 9, 105, 1, 106, 1, 106, 1, 106, 5, 106, 1089, 8, 106, 10, 106, 12, 106, 1092, 9, 106, 1, 106, 1, 106, 3, 106, 1096, 8, 106, 1, 107, 1, 107, 1, 107, 1, 107, 5, 107, 1102, 8, 107, 10, 107, 12, 107, 1105, 9, 107, 1, 107, 1, 107, 1, 108, 1, 108, 3, 108, 1111, 8, 108, 1, 109, 1, 109, 3, 109, 1115, 8, 109, 1, 110, 1, 110, 1, 110, 1, 110, 5, 110, 1121, 8, 110, 10, 110, 12, 110, 1124, 9, 110, 3, 110, 1126, 8, 110, 1, 111, 1, 111, 1, 112, 1, 112, 1, 112, 1, 112, 0, 0, 113, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 0, 8, 1, 0, 57, 58, 1, 0, 71, 72, 1, 0, 80, 81, 1, 0, 82, 84, 1, 0, 25, 30, 2, 0, 15, 16, 20, 21, 2, 0, 17, 18, 22, 23, 2, 0, 19, 19, 24, 24, 1184, 0, 231, 1, 0, 0, 0, 2, 245, 1, 0, 0, 0, 4, 251, 1, 0, 0, 0, 6, 279, 1, 0, 0, 0, 8, 295, 1, 0, 0, 0, 10, 297, 1, 0, 0, 0, 12, 318, 1, 0, 0, 0, 14, 320, 1, 0, 0, 0, 16, 338, 1, 0, 0, 0, 18, 340, 1, 0, 0, 0, 20, 349, 1, 0, 0, 0, 22, 357, 1, 0, 0, 0, 24, 360, 1, 0, 0, 0, 26, 376, 1, 0, 0, 0, 28, 380, 1, 0, 0, 0, 30, 392, 1, 0, 0, 0, 32, 397, 1, 0, 0, 0, 34, 402, 1, 0, 0, 0, 36, 408, 1, 0, 0, 0, 38, 410, 1, 0, 0, 0, 40, 413, 1, 0, 0, 0, 42, 421, 1, 0, 0, 0, 44, 427, 1, 0, 0, 0, 46, 429, 1, 0, 0, 0, 48, 446, 1, 0, 0, 0, 50, 455, 1, 0, 0, 0, 52, 478, 1, 0, 0, 0, 54, 486, 1, 0, 0, 0, 56, 491, 1, 0, 0, 0, 58, 499, 1, 0, 0, 0, 60, 511, 1, 0, 0, 0, 62, 516, 1, 0, 0, 0, 64, 524, 1, 0, 0, 0, 66, 532, 1, 0, 0, 0, 68, 540, 1, 0, 0, 0, 70, 547, 1, 0, 0, 0, 72, 563, 1, 0, 0, 0, 74, 567, 1, 0, 0, 0, 76, 569, 1, 0, 0, 0, 78, 575, 1, 0, 0, 0, 80, 585, 1, 0, 0, 0, 82, 588, 1, 0, 0, 0, 84, 597, 1, 0, 0, 0, 86, 603, 1, 0, 0, 0, 88, 615, 1, 0, 0, 0, 90, 623, 1, 0, 0, 0, 92, 627, 1, 0, 0, 0, 94, 630, 1, 0, 0, 0, 96, 634, 1, 0, 0, 0, 98, 640, 1, 0, 0, 0, 100, 650, 1, 0, 0, 0, 102, 658, 1, 0, 0, 0, 104, 672, 1, 0, 0, 0, 106, 695, 1, 0, 0, 0, 108, 699, 1, 0, 0, 0, 110, 722, 1, 0, 0, 0, 112, 725, 1, 0, 0, 0, 114, 743, 1, 0, 0, 0, 116, 747, 1, 0, 0, 0, 118, 751, 1, 0, 0, 0, 120, 758, 1, 0, 0, 0, 122, 761, 1, 0, 0, 0, 124, 768, 1, 0, 0, 0, 126, 775, 1, 0, 0, 0, 128, 783, 1, 0, 0, 0, 130, 788, 1, 0, 0, 0, 132, 795, 1, 0, 0, 0, 134, 808, 1, 0, 0, 0, 136, 821, 1, 0, 0, 0, 138, 825, 1, 0, 0, 0, 140, 829, 1, 0, 0, 0, 142, 832, 1, 0, 0, 0, 144, 840, 1, 0, 0, 0, 146, 842, 1, 0, 0, 0, 148, 855, 1, 0, 0, 0, 150, 859, 1, 0, 0, 0, 152, 863, 1, 0, 0, 0, 154, 865, 1, 0, 0, 0, 156, 867, 1, 0, 0, 0, 158, 876, 1, 0, 0, 0, 160, 885, 1, 0, 0, 0, 162, 887, 1, 0, 0, 0, 164, 896, 1, 0, 0, 0, 166, 899, 1, 0, 0, 0, 168, 903, 1, 0, 0, 0, 170, 909, 1, 0, 0, 0, 172, 911, 1, 0, 0, 0, 174, 920, 1, 0, 0, 0, 176, 923, 1, 0, 0, 0, 178, 925, 1, 0, 0, 0, 180, 927, 1, 0, 0, 0, 182, 936, 1, 0, 0, 0, 184, 938, 1, 0, 0, 0, 186, 944, 1, 0, 0, 0, 188, 978, 1, 0, 0, 0, 190, 981, 1, 0, 0, 0, 192, 991, 1, 0, 0, 0, 194, 1000, 1, 0, 0, 0, 196, 1016, 1, 0, 0, 0, 198, 1039, 1, 0, 0, 0, 200, 1041, 1, 0, 0, 0, 202, 1049, 1, 0, 0, 0, 204, 1055, 1, 0, 0, 0, 206, 1057, 1, 0, 0, 0, 208, 1066, 1, 0, 0, 0, 210, 1077, 1, 0, 0, 0, 212, 1085, 1, 0, 0, 0, 214, 1097, 1, 0, 0, 0, 216, 1110, 1, 0, 0, 0, 218, 1112, 1, 0, 0, 0, 220, 1125, 1, 0, 0, 0, 222, 1127, 1, 0, 0, 0, 224, 1129, 1, 0, 0, 0, 226, 228, 5, 65, 0, 0, 227, 229, 3, 192, 96, 0, 228, 227, 1, 0, 0, 0, 228, 229, 1, 0, 0, 0, 229, 230, 1, 0, 0, 0, 230, 232, 5, 5, 0, 0, 231, 226, 1, 0, 0, 0, 231, 232, 1, 0, 0, 0, 232, 241, 1, 0, 0, 0, 233, 235, 5, 66, 0, 0, 234, 233, 1, 0, 0, 0, 234, 235, 1, 0, 0, 0, 235, 236, 1, 0, 0, 0, 236, 237, 3, 2, 1, 0, 237, 238, 5, 5, 0, 0, 238, 240, 1, 0, 0, 0, 239, 234, 1, 0, 0, 0, 240, 243, 1, 0, 0, 0, 241, 239, 1, 0, 0, 0, 241, 242, 1, 0, 0, 0, 242, 1, 1, 0, 0, 0, 243, 241, 1, 0, 0, 0, 244, 246, 5, 67, 0, 0, 245, 244, 1, 0, 0, 0, 245, 246, 1, 0, 0, 0, 246, 247, 1, 0, 0, 0, 247, 248, 3, 4, 2, 0, 248, 249, 3, 6, 3, 0, 249, 3, 1, 0, 0, 0, 250, 252, 5, 46, 0, 0, 251, 250, 1, 0, 0, 0, 251, 252, 1, 0, 0, 0, 252, 274, 1, 0, 0, 0, 253, 275, 5, 49, 0, 0, 254, 275, 5, 50, 0, 0, 255, 257, 5, 47, 0, 0, 256, 255, 1, 0, 0, 0, 256, 257, 1, 0, 0, 0, 257, 258, 1, 0, 0, 0, 258, 275, 5, 52, 0, 0, 259, 275, 5, 54, 0, 0, 260, 262, 5, 48, 0, 0, 261, 260, 1, 0, 0, 0, 261, 262, 1, 0, 0, 0, 262, 263, 1, 0, 0, 0, 263, 275, 5, 55, 0, 0, 264, 275, 5, 53, 0, 0, 265, 275, 5, 56, 0, 0, 266, 268, 7, 0, 0, 0, 267, 266, 1, 0, 0, 0, 267, 268, 1, 0, 0, 0, 268, 270, 1, 0, 0, 0, 269, 271, 5, 47, 0, 0, 270, 269, 1, 0, 0, 0, 270, 271, 1, 0, 0, 0, 271, 272, 1, 0, 0, 0, 272, 275, 5, 51, 0, 0, 273, 275, 5, 47, 0, 0, 274, 253, 1, 0, 0, 0, 274, 254, 1, 0, 0, 0, 274, 256, 1, 0, 0, 0, 274, 259, 1, 0, 0, 0, 274, 261, 1, 0, 0, 0, 274, 264, 1, 0, 0, 0, 274, 265, 1, 0, 0, 0, 274, 267, 1, 0, 0, 0, 274, 273, 1, 0, 0, 0, 275, 5, 1, 0, 0, 0, 276, 280, 3, 8, 4, 0, 277, 280, 3, 12, 6, 0, 278, 280, 3, 14, 7, 0, 279, 276, 1, 0, 0, 0, 279, 277, 1, 0, 0, 0, 279, 278, 1, 0, 0, 0, 280, 7, 1, 0, 0, 0, 281, 282, 5, 93, 0, 0, 282, 283, 3, 220, 110, 0, 283, 284, 3, 24, 12, 0, 284, 285, 3, 10, 5, 0, 285, 296, 1, 0, 0, 0, 286, 287, 5, 68, 0, 0, 287, 289, 5, 93, 0, 0, 288, 290, 3, 76, 38, 0, 289, 288, 1, 0, 0, 0, 289, 290, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 292, 3, 220, 110, 0, 292, 293, 3, 24, 12, 0, 293, 294, 3, 10, 5, 0, 294, 296, 1, 0, 0, 0, 295, 281, 1, 0, 0, 0, 295, 286, 1, 0, 0, 0, 296, 9, 1, 0, 0, 0, 297, 298, 5, 59, 0, 0, 298, 299, 5, 93, 0, 0, 299, 11, 1, 0, 0, 0, 300, 301, 5, 93, 0, 0, 301, 302, 5, 13, 0, 0, 302, 303, 3, 16, 8, 0, 303, 305, 3, 190, 95, 0, 304, 306, 3, 214, 107, 0, 305, 304, 1, 0, 0, 0, 305, 306, 1, 0, 0, 0, 306, 308, 1, 0, 0, 0, 307, 309, 3, 76, 38, 0, 308, 307, 1, 0, 0, 0, 308, 309, 1, 0, 0, 0, 309, 310, 1, 0, 0, 0, 310, 311, 3, 218, 109, 0, 311, 319, 1, 0, 0, 0, 312, 313, 5, 93, 0, 0, 313, 314, 5, 13, 0, 0, 314, 315, 5, 70, 0, 0, 315, 316, 3, 18, 9, 0, 316, 317, 3, 218, 109, 0, 317, 319, 1, 0, 0, 0, 318, 300, 1, 0, 0, 0, 318, 312, 1, 0, 0, 0, 319, 13, 1, 0, 0, 0, 320, 321, 5, 93, 0, 0, 321, 322, 5, 13, 0, 0, 322, 323, 5, 60, 0, 0, 323, 324, 5, 7, 0, 0, 324, 325, 3, 190, 95, 0, 325, 326, 5, 3, 0, 0, 326, 331, 5, 93, 0, 0, 327, 328, 5, 3, 0, 0, 328, 330, 5, 93, 0, 0, 329, 327, 1, 0, 0, 0, 330, 333, 1, 0, 0, 0, 331, 329, 1, 0, 0, 0, 331, 332, 1, 0, 0, 0, 332, 334, 1, 0, 0, 0, 333, 331, 1, 0, 0, 0, 334, 335, 5, 8, 0, 0, 335, 336, 3, 218, 109, 0, 336, 15, 1, 0, 0, 0, 337, 339, 7, 1, 0, 0, 338, 337, 1, 0, 0, 0, 338, 339, 1, 0, 0, 0, 339, 17, 1, 0, 0, 0, 340, 345, 5, 7, 0, 0, 341, 343, 3, 20, 10, 0, 342, 341, 1, 0, 0, 0, 342, 343, 1, 0, 0, 0, 343, 346, 1, 0, 0, 0, 344, 346, 5, 6, 0, 0, 345, 342, 1, 0, 0, 0, 345, 344, 1, 0, 0, 0, 346, 347, 1, 0, 0, 0, 347, 348, 5, 8, 0, 0, 348, 19, 1, 0, 0, 0, 349, 354, 3, 22, 11, 0, 350, 351, 5, 3, 0, 0, 351, 353, 3, 22, 11, 0, 352, 350, 1, 0, 0, 0, 353, 356, 1, 0, 0, 0, 354, 352, 1, 0, 0, 0, 354, 355, 1, 0, 0, 0, 355, 21, 1, 0, 0, 0, 356, 354, 1, 0, 0, 0, 357, 358, 5, 93, 0, 0, 358, 359, 3, 218, 109, 0, 359, 23, 1, 0, 0, 0, 360, 367, 3, 36, 18, 0, 361, 366, 3, 38, 19, 0, 362, 366, 3, 40, 20, 0, 363, 366, 3, 96, 48, 0, 364, 366, 3, 98, 49, 0, 365, 361, 1, 0, 0, 0, 365, 362, 1, 0, 0, 0, 365, 363, 1, 0, 0, 0, 365, 364, 1, 0, 0, 0, 366, 369, 1, 0, 0, 0, 367, 365, 1, 0, 0, 0, 367, 368, 1, 0, 0, 0, 368, 371, 1, 0, 0, 0, 369, 367, 1, 0, 0, 0, 370, 372, 3, 28, 14, 0, 371, 370, 1, 0, 0, 0, 371, 372, 1, 0, 0, 0, 372, 374, 1, 0, 0, 0, 373, 375, 3, 26, 13, 0, 374, 373, 1, 0, 0, 0, 374, 375, 1, 0, 0, 0, 375, 25, 1, 0, 0, 0, 376, 377, 5, 86, 0, 0, 377, 378, 3, 76, 38, 0, 378, 379, 5, 5, 0, 0, 379, 27, 1, 0, 0, 0, 380, 382, 5, 87, 0, 0, 381, 383, 3, 30, 15, 0, 382, 381, 1, 0, 0, 0, 382, 383, 1, 0, 0, 0, 383, 385, 1, 0, 0, 0, 384, 386, 3, 32, 16, 0, 385, 384, 1, 0, 0, 0, 385, 386, 1, 0, 0, 0, 386, 388, 1, 0, 0, 0, 387, 389, 3, 224, 112, 0, 388, 387, 1, 0, 0, 0, 388, 389, 1, 0, 0, 0, 389, 390, 1, 0, 0, 0, 390, 391, 5, 5, 0, 0, 391, 29, 1, 0, 0, 0, 392, 393, 5, 90, 0, 0, 393, 31, 1, 0, 0, 0, 394, 395, 3, 194, 97, 0, 395, 396, 5, 13, 0, 0, 396, 398, 1, 0, 0, 0, 397, 394, 1, 0, 0, 0, 397, 398, 1, 0, 0, 0, 398, 399, 1, 0, 0, 0, 399, 400, 5, 93, 0, 0, 400, 401, 3, 34, 17, 0, 401, 33, 1, 0, 0, 0, 402, 404, 5, 7, 0, 0, 403, 405, 3, 210, 105, 0, 404, 403, 1, 0, 0, 0, 404, 405, 1, 0, 0, 0, 405, 406, 1, 0, 0, 0, 406, 407, 5, 8, 0, 0, 407, 35, 1, 0, 0, 0, 408, 409, 3, 42, 21, 0, 409, 37, 1, 0, 0, 0, 410, 411, 5, 73, 0, 0, 411, 412, 3, 42, 21, 0, 412, 39, 1, 0, 0, 0, 413, 414, 5, 74, 0, 0, 414, 415, 3, 42, 21, 0, 415, 41, 1, 0, 0, 0, 416, 417, 3, 44, 22, 0, 417, 418, 5, 5, 0, 0, 418, 420, 1, 0, 0, 0, 419, 416, 1, 0, 0, 0, 420, 423, 1, 0, 0, 0, 421, 419, 1, 0, 0, 0, 421, 422, 1, 0, 0, 0, 422, 43, 1, 0, 0, 0, 423, 421, 1, 0, 0, 0, 424, 428, 3, 46, 23, 0, 425, 428, 3, 52, 26, 0, 426, 428, 3, 50, 25, 0, 427, 424, 1, 0, 0, 0, 427, 425, 1, 0, 0, 0, 427, 426, 1, 0, 0, 0, 428, 45, 1, 0, 0, 0, 429, 442, 5, 69, 0, 0, 430, 431, 5, 93, 0, 0, 431, 432, 5, 13, 0, 0, 432, 443, 3, 192, 96, 0, 433, 440, 3, 192, 96, 0, 434, 441, 5, 22, 0, 0, 435, 436, 5, 4, 0, 0, 436, 437, 5, 9, 0, 0, 437, 438, 3, 48, 24, 0, 438, 439, 5, 10, 0, 0, 439, 441, 1, 0, 0, 0, 440, 434, 1, 0, 0, 0, 440, 435, 1, 0, 0, 0, 440, 441, 1, 0, 0, 0, 441, 443, 1, 0, 0, 0, 442, 430, 1, 0, 0, 0, 442, 433, 1, 0, 0, 0, 443, 444, 1, 0, 0, 0, 444, 445, 3, 218, 109, 0, 445, 47, 1, 0, 0, 0, 446, 451, 5, 93, 0, 0, 447, 448, 5, 3, 0, 0, 448, 450, 5, 93, 0, 0, 449, 447, 1, 0, 0, 0, 450, 453, 1, 0, 0, 0, 451, 449, 1, 0, 0, 0, 451, 452, 1, 0, 0, 0, 452, 49, 1, 0, 0, 0, 453, 451, 1, 0, 0, 0, 454, 456, 5, 75, 0, 0, 455, 454, 1, 0, 0, 0, 455, 456, 1, 0, 0, 0, 456, 458, 1, 0, 0, 0, 457, 459, 5, 66, 0, 0, 458, 457, 1, 0, 0, 0, 458, 459, 1, 0, 0, 0, 459, 461, 1, 0, 0, 0, 460, 462, 5, 76, 0, 0, 461, 460, 1, 0, 0, 0, 461, 462, 1, 0, 0, 0, 462, 464, 1, 0, 0, 0, 463, 465, 5, 77, 0, 0, 464, 463, 1, 0, 0, 0, 464, 465, 1, 0, 0, 0, 465, 467, 1, 0, 0, 0, 466, 468, 5, 78, 0, 0, 467, 466, 1, 0, 0, 0, 467, 468, 1, 0, 0, 0, 468, 471, 1, 0, 0, 0, 469, 472, 3, 2, 1, 0, 470, 472, 3, 62, 31, 0, 471, 469, 1, 0, 0, 0, 471, 470, 1, 0, 0, 0, 472, 476, 1, 0, 0, 0, 473, 474, 3, 54, 27, 0, 474, 475, 3, 218, 109, 0, 475, 477, 1, 0, 0, 0, 476, 473, 1, 0, 0, 0, 476, 477, 1, 0, 0, 0, 477, 51, 1, 0, 0, 0, 478, 479, 5, 68, 0, 0, 479, 481, 3, 190, 95, 0, 480, 482, 3, 56, 28, 0, 481, 480, 1, 0, 0, 0, 481, 482, 1, 0, 0, 0, 482, 484, 1, 0, 0, 0, 483, 485, 3, 224, 112, 0, 484, 483, 1, 0, 0, 0, 484, 485, 1, 0, 0, 0, 485, 53, 1, 0, 0, 0, 486, 487, 5, 79, 0, 0, 487, 489, 3, 190, 95, 0, 488, 490, 3, 76, 38, 0, 489, 488, 1, 0, 0, 0, 489, 490, 1, 0, 0, 0, 490, 55, 1, 0, 0, 0, 491, 493, 5, 7, 0, 0, 492, 494, 3, 58, 29, 0, 493, 492, 1, 0, 0, 0, 493, 494, 1, 0, 0, 0, 494, 495, 1, 0, 0, 0, 495, 496, 5, 8, 0, 0, 496, 57, 1, 0, 0, 0, 497, 500, 3, 80, 40, 0, 498, 500, 3, 60, 30, 0, 499, 497, 1, 0, 0, 0, 499, 498, 1, 0, 0, 0, 500, 508, 1, 0, 0, 0, 501, 504, 5, 3, 0, 0, 502, 505, 3, 80, 40, 0, 503, 505, 3, 60, 30, 0, 504, 502, 1, 0, 0, 0, 504, 503, 1, 0, 0, 0, 505, 507, 1, 0, 0, 0, 506, 501, 1, 0, 0, 0, 507, 510, 1, 0, 0, 0, 508, 506, 1, 0, 0, 0, 508, 509, 1, 0, 0, 0, 509, 59, 1, 0, 0, 0, 510, 508, 1, 0, 0, 0, 511, 514, 5, 44, 0, 0, 512, 515, 3, 140, 70, 0, 513, 515, 5, 93, 0, 0, 514, 512, 1, 0, 0, 0, 514, 513, 1, 0, 0, 0, 515, 61, 1, 0, 0, 0, 516, 517, 3, 64, 32, 0, 517, 519, 3, 190, 95, 0, 518, 520, 3, 214, 107, 0, 519, 518, 1, 0, 0, 0, 519, 520, 1, 0, 0, 0, 520, 521, 1, 0, 0, 0, 521, 522, 3, 66, 33, 0, 522, 63, 1, 0, 0, 0, 523, 525, 7, 2, 0, 0, 524, 523, 1, 0, 0, 0, 524, 525, 1, 0, 0, 0, 525, 527, 1, 0, 0, 0, 526, 528, 7, 3, 0, 0, 527, 526, 1, 0, 0, 0, 527, 528, 1, 0, 0, 0, 528, 530, 1, 0, 0, 0, 529, 531, 7, 1, 0, 0, 530, 529, 1, 0, 0, 0, 530, 531, 1, 0, 0, 0, 531, 65, 1, 0, 0, 0, 532, 537, 3, 68, 34, 0, 533, 534, 5, 3, 0, 0, 534, 536, 3, 68, 34, 0, 535, 533, 1, 0, 0, 0, 536, 539, 1, 0, 0, 0, 537, 535, 1, 0, 0, 0, 537, 538, 1, 0, 0, 0, 538, 67, 1, 0, 0, 0, 539, 537, 1, 0, 0, 0, 540, 543, 3, 70, 35, 0, 541, 542, 5, 36, 0, 0, 542, 544, 3, 144, 72, 0, 543, 541, 1, 0, 0, 0, 543, 544, 1, 0, 0, 0, 544, 545, 1, 0, 0, 0, 545, 546, 3, 218, 109, 0, 546, 69, 1, 0, 0, 0, 547, 549, 5, 93, 0, 0, 548, 550, 3, 214, 107, 0, 549, 548, 1, 0, 0, 0, 549, 550, 1, 0, 0, 0, 550, 552, 1, 0, 0, 0, 551, 553, 3, 72, 36, 0, 552, 551, 1, 0, 0, 0, 552, 553, 1, 0, 0, 0, 553, 71, 1, 0, 0, 0, 554, 557, 3, 76, 38, 0, 555, 556, 5, 13, 0, 0, 556, 558, 3, 74, 37, 0, 557, 555, 1, 0, 0, 0, 557, 558, 1, 0, 0, 0, 558, 564, 1, 0, 0, 0, 559, 560, 5, 13, 0, 0, 560, 564, 3, 74, 37, 0, 561, 562, 5, 14, 0, 0, 562, 564, 3, 74, 37, 0, 563, 554, 1, 0, 0, 0, 563, 559, 1, 0, 0, 0, 563, 561, 1, 0, 0, 0, 564, 73, 1, 0, 0, 0, 565, 568, 3, 144, 72, 0, 566, 568, 5, 44, 0, 0, 567, 565, 1, 0, 0, 0, 567, 566, 1, 0, 0, 0, 568, 75, 1, 0, 0, 0, 569, 571, 5, 7, 0, 0, 570, 572, 3, 78, 39, 0, 571, 570, 1, 0, 0, 0, 571, 572, 1, 0, 0, 0, 572, 573, 1, 0, 0, 0, 573, 574, 5, 8, 0, 0, 574, 77, 1, 0, 0, 0, 575, 580, 3, 80, 40, 0, 576, 577, 5, 3, 0, 0, 577, 579, 3, 80, 40, 0, 578, 576, 1, 0, 0, 0, 579, 582, 1, 0, 0, 0, 580, 578, 1, 0, 0, 0, 580, 581, 1, 0, 0, 0, 581, 79, 1, 0, 0, 0, 582, 580, 1, 0, 0, 0, 583, 586, 3, 82, 41, 0, 584, 586, 3, 86, 43, 0, 585, 583, 1, 0, 0, 0, 585, 584, 1, 0, 0, 0, 586, 81, 1, 0, 0, 0, 587, 589, 5, 85, 0, 0, 588, 587, 1, 0, 0, 0, 588, 589, 1, 0, 0, 0, 589, 591, 1, 0, 0, 0, 590, 592, 5, 66, 0, 0, 591, 590, 1, 0, 0, 0, 591, 592, 1, 0, 0, 0, 592, 595, 1, 0, 0, 0, 593, 596, 3, 84, 42, 0, 594, 596, 3, 88, 44, 0, 595, 593, 1, 0, 0, 0, 595, 594, 1, 0, 0, 0, 596, 83, 1, 0, 0, 0, 597, 599, 3, 192, 96, 0, 598, 600, 3, 72, 36, 0, 599, 598, 1, 0, 0, 0, 599, 600, 1, 0, 0, 0, 600, 601, 1, 0, 0, 0, 601, 602, 3, 220, 110, 0, 602, 85, 1, 0, 0, 0, 603, 605, 5, 75, 0, 0, 604, 606, 5, 85, 0, 0, 605, 604, 1, 0, 0, 0, 605, 606, 1, 0, 0, 0, 606, 608, 1, 0, 0, 0, 607, 609, 5, 66, 0, 0, 608, 607, 1, 0, 0, 0, 608, 609, 1, 0, 0, 0, 609, 613, 1, 0, 0, 0, 610, 614, 3, 94, 47, 0, 611, 614, 3, 90, 45, 0, 612, 614, 3, 88, 44, 0, 613, 610, 1, 0, 0, 0, 613, 611, 1, 0, 0, 0, 613, 612, 1, 0, 0, 0, 614, 87, 1, 0, 0, 0, 615, 618, 5, 78, 0, 0, 616, 619, 3, 94, 47, 0, 617, 619, 3, 90, 45, 0, 618, 616, 1, 0, 0, 0, 618, 617, 1, 0, 0, 0, 619, 621, 1, 0, 0, 0, 620, 622, 3, 54, 27, 0, 621, 620, 1, 0, 0, 0, 621, 622, 1, 0, 0, 0, 622, 89, 1, 0, 0, 0, 623, 624, 3, 64, 32, 0, 624, 625, 3, 190, 95, 0, 625, 626, 3, 92, 46, 0, 626, 91, 1, 0, 0, 0, 627, 628, 3, 70, 35, 0, 628, 629, 3, 218, 109, 0, 629, 93, 1, 0, 0, 0, 630, 631, 3, 4, 2, 0, 631, 632, 3, 12, 6, 0, 632, 95, 1, 0, 0, 0, 633, 635, 5, 62, 0, 0, 634, 633, 1, 0, 0, 0, 634, 635, 1, 0, 0, 0, 635, 636, 1, 0, 0, 0, 636, 637, 5, 63, 0, 0, 637, 638, 3, 100, 50, 0, 638, 97, 1, 0, 0, 0, 639, 641, 5, 62, 0, 0, 640, 639, 1, 0, 0, 0, 640, 641, 1, 0, 0, 0, 641, 642, 1, 0, 0, 0, 642, 643, 5, 64, 0, 0, 643, 644, 3, 102, 51, 0, 644, 99, 1, 0, 0, 0, 645, 646, 3, 104, 52, 0, 646, 647, 5, 5, 0, 0, 647, 649, 1, 0, 0, 0, 648, 645, 1, 0, 0, 0, 649, 652, 1, 0, 0, 0, 650, 648, 1, 0, 0, 0, 650, 651, 1, 0, 0, 0, 651, 101, 1, 0, 0, 0, 652, 650, 1, 0, 0, 0, 653, 654, 3, 106, 53, 0, 654, 655, 5, 5, 0, 0, 655, 657, 1, 0, 0, 0, 656, 653, 1, 0, 0, 0, 657, 660, 1, 0, 0, 0, 658, 656, 1, 0, 0, 0, 658, 659, 1, 0, 0, 0, 659, 103, 1, 0, 0, 0, 660, 658, 1, 0, 0, 0, 661, 662, 3, 156, 78, 0, 662, 663, 5, 13, 0, 0, 663, 664, 3, 144, 72, 0, 664, 673, 1, 0, 0, 0, 665, 673, 3, 108, 54, 0, 666, 673, 3, 122, 61, 0, 667, 673, 3, 140, 70, 0, 668, 673, 3, 132, 66, 0, 669, 670, 3, 194, 97, 0, 670, 671, 3, 196, 98, 0, 671, 673, 1, 0, 0, 0, 672, 661, 1, 0, 0, 0, 672, 665, 1, 0, 0, 0, 672, 666, 1, 0, 0, 0, 672, 667, 1, 0, 0, 0, 672, 668, 1, 0, 0, 0, 672, 669, 1, 0, 0, 0, 673, 674, 1, 0, 0, 0, 674, 675, 3, 218, 109, 0, 675, 105, 1, 0, 0, 0, 676, 680, 3, 194, 97, 0, 677, 678, 5, 14, 0, 0, 678, 681, 3, 144, 72, 0, 679, 681, 3, 196, 98, 0, 680, 677, 1, 0, 0, 0, 680, 679, 1, 0, 0, 0, 681, 696, 1, 0, 0, 0, 682, 683, 5, 7, 0, 0, 683, 684, 3, 208, 104, 0, 684, 685, 5, 8, 0, 0, 685, 686, 5, 14, 0, 0, 686, 687, 3, 194, 97, 0, 687, 688, 3, 196, 98, 0, 688, 696, 1, 0, 0, 0, 689, 696, 5, 44, 0, 0, 690, 696, 5, 45, 0, 0, 691, 696, 3, 112, 56, 0, 692, 696, 3, 124, 62, 0, 693, 696, 3, 130, 65, 0, 694, 696, 3, 134, 67, 0, 695, 676, 1, 0, 0, 0, 695, 682, 1, 0, 0, 0, 695, 689, 1, 0, 0, 0, 695, 690, 1, 0, 0, 0, 695, 691, 1, 0, 0, 0, 695, 692, 1, 0, 0, 0, 695, 693, 1, 0, 0, 0, 695, 694, 1, 0, 0, 0, 696, 697, 1, 0, 0, 0, 697, 698, 3, 218, 109, 0, 698, 107, 1, 0, 0, 0, 699, 700, 3, 114, 57, 0, 700, 706, 3, 110, 55, 0, 701, 702, 3, 116, 58, 0, 702, 703, 3, 110, 55, 0, 703, 705, 1, 0, 0, 0, 704, 701, 1, 0, 0, 0, 705, 708, 1, 0, 0, 0, 706, 704, 1, 0, 0, 0, 706, 707, 1, 0, 0, 0, 707, 712, 1, 0, 0, 0, 708, 706, 1, 0, 0, 0, 709, 710, 3, 118, 59, 0, 710, 711, 3, 110, 55, 0, 711, 713, 1, 0, 0, 0, 712, 709, 1, 0, 0, 0, 712, 713, 1, 0, 0, 0, 713, 714, 1, 0, 0, 0, 714, 715, 5, 59, 0, 0, 715, 716, 5, 36, 0, 0, 716, 109, 1, 0, 0, 0, 717, 718, 3, 104, 52, 0, 718, 719, 5, 5, 0, 0, 719, 721, 1, 0, 0, 0, 720, 717, 1, 0, 0, 0, 721, 724, 1, 0, 0, 0, 722, 720, 1, 0, 0, 0, 722, 723, 1, 0, 0, 0, 723, 111, 1, 0, 0, 0, 724, 722, 1, 0, 0, 0, 725, 726, 3, 114, 57, 0, 726, 732, 3, 120, 60, 0, 727, 728, 3, 116, 58, 0, 728, 729, 3, 120, 60, 0, 729, 731, 1, 0, 0, 0, 730, 727, 1, 0, 0, 0, 731, 734, 1, 0, 0, 0, 732, 730, 1, 0, 0, 0, 732, 733, 1, 0, 0, 0, 733, 738, 1, 0, 0, 0, 734, 732, 1, 0, 0, 0, 735, 736, 3, 118, 59, 0, 736, 737, 3, 120, 60, 0, 737, 739, 1, 0, 0, 0, 738, 735, 1, 0, 0, 0, 738, 739, 1, 0, 0, 0, 739, 740, 1, 0, 0, 0, 740, 741, 5, 59, 0, 0, 741, 742, 5, 36, 0, 0, 742, 113, 1, 0, 0, 0, 743, 744, 5, 36, 0, 0, 744, 745, 3, 144, 72, 0, 745, 746, 5, 39, 0, 0, 746, 115, 1, 0, 0, 0, 747, 748, 5, 38, 0, 0, 748, 749, 3, 144, 72, 0, 749, 750, 5, 39, 0, 0, 750, 117, 1, 0, 0, 0, 751, 752, 5, 37, 0, 0, 752, 119, 1, 0, 0, 0, 753, 754, 3, 106, 53, 0, 754, 755, 5, 5, 0, 0, 755, 757, 1, 0, 0, 0, 756, 753, 1, 0, 0, 0, 757, 760, 1, 0, 0, 0, 758, 756, 1, 0, 0, 0, 758, 759, 1, 0, 0, 0, 759, 121, 1, 0, 0, 0, 760, 758, 1, 0, 0, 0, 761, 762, 5, 35, 0, 0, 762, 763, 3, 126, 63, 0, 763, 764, 5, 43, 0, 0, 764, 765, 3, 110, 55, 0, 765, 766, 5, 59, 0, 0, 766, 767, 5, 35, 0, 0, 767, 123, 1, 0, 0, 0, 768, 769, 5, 35, 0, 0, 769, 770, 3, 126, 63, 0, 770, 771, 5, 43, 0, 0, 771, 772, 3, 120, 60, 0, 772, 773, 5, 59, 0, 0, 773, 774, 5, 35, 0, 0, 774, 125, 1, 0, 0, 0, 775, 780, 3, 128, 64, 0, 776, 777, 5, 3, 0, 0, 777, 779, 3, 128, 64, 0, 778, 776, 1, 0, 0, 0, 779, 782, 1, 0, 0, 0, 780, 778, 1, 0, 0, 0, 780, 781, 1, 0, 0, 0, 781, 127, 1, 0, 0, 0, 782, 780, 1, 0, 0, 0, 783, 786, 5, 93, 0, 0, 784, 785, 5, 34, 0, 0, 785, 787, 3, 144, 72, 0, 786, 784, 1, 0, 0, 0, 786, 787, 1, 0, 0, 0, 787, 129, 1, 0, 0, 0, 788, 789, 5, 42, 0, 0, 789, 790, 3, 144, 72, 0, 790, 791, 5, 43, 0, 0, 791, 792, 3, 120, 60, 0, 792, 793, 5, 59, 0, 0, 793, 794, 5, 42, 0, 0, 794, 131, 1, 0, 0, 0, 795, 796, 3, 136, 68, 0, 796, 802, 3, 110, 55, 0, 797, 798, 3, 138, 69, 0, 798, 799, 3, 110, 55, 0, 799, 801, 1, 0, 0, 0, 800, 797, 1, 0, 0, 0, 801, 804, 1, 0, 0, 0, 802, 800, 1, 0, 0, 0, 802, 803, 1, 0, 0, 0, 803, 805, 1, 0, 0, 0, 804, 802, 1, 0, 0, 0, 805, 806, 5, 59, 0, 0, 806, 807, 5, 40, 0, 0, 807, 133, 1, 0, 0, 0, 808, 809, 3, 136, 68, 0, 809, 815, 3, 120, 60, 0, 810, 811, 3, 138, 69, 0, 811, 812, 3, 120, 60, 0, 812, 814, 1, 0, 0, 0, 813, 810, 1, 0, 0, 0, 814, 817, 1, 0, 0, 0, 815, 813, 1, 0, 0, 0, 815, 816, 1, 0, 0, 0, 816, 818, 1, 0, 0, 0, 817, 815, 1, 0, 0, 0, 818, 819, 5, 59, 0, 0, 819, 820, 5, 40, 0, 0, 820, 135, 1, 0, 0, 0, 821, 822, 5, 40, 0, 0, 822, 823, 3, 144, 72, 0, 823, 824, 5, 39, 0, 0, 824, 137, 1, 0, 0, 0, 825, 826, 5, 41, 0, 0, 826, 827, 3, 144, 72, 0, 827, 828, 5, 39, 0, 0, 828, 139, 1, 0, 0, 0, 829, 830, 5, 61, 0, 0, 830, 831, 3, 142, 71, 0, 831, 141, 1, 0, 0, 0, 832, 833, 5, 7, 0, 0, 833, 834, 3, 194, 97, 0, 834, 835, 5, 3, 0, 0, 835, 836, 3, 194, 97, 0, 836, 837, 5, 8, 0, 0, 837, 143, 1, 0, 0, 0, 838, 841, 3, 156, 78, 0, 839, 841, 3, 146, 73, 0, 840, 838, 1, 0, 0, 0, 840, 839, 1, 0, 0, 0, 841, 145, 1, 0, 0, 0, 842, 843, 3, 148, 74, 0, 843, 849, 3, 154, 77, 0, 844, 845, 3, 150, 75, 0, 845, 846, 3, 154, 77, 0, 846, 848, 1, 0, 0, 0, 847, 844, 1, 0, 0, 0, 848, 851, 1, 0, 0, 0, 849, 847, 1, 0, 0, 0, 849, 850, 1, 0, 0, 0, 850, 852, 1, 0, 0, 0, 851, 849, 1, 0, 0, 0, 852, 853, 3, 152, 76, 0, 853, 854, 3, 154, 77, 0, 854, 147, 1, 0, 0, 0, 855, 856, 5, 36, 0, 0, 856, 857, 3, 144, 72, 0, 857, 858, 5, 39, 0, 0, 858, 149, 1, 0, 0, 0, 859, 860, 5, 38, 0, 0, 860, 861, 3, 144, 72, 0, 861, 862, 5, 39, 0, 0, 862, 151, 1, 0, 0, 0, 863, 864, 5, 37, 0, 0, 864, 153, 1, 0, 0, 0, 865, 866, 3, 144, 72, 0, 866, 155, 1, 0, 0, 0, 867, 874, 3, 158, 79, 0, 868, 869, 5, 6, 0, 0, 869, 872, 3, 158, 79, 0, 870, 871, 5, 6, 0, 0, 871, 873, 3, 158, 79, 0, 872, 870, 1, 0, 0, 0, 872, 873, 1, 0, 0, 0, 873, 875, 1, 0, 0, 0, 874, 868, 1, 0, 0, 0, 874, 875, 1, 0, 0, 0, 875, 157, 1, 0, 0, 0, 876, 882, 3, 162, 81, 0, 877, 878, 3, 160, 80, 0, 878, 879, 3, 162, 81, 0, 879, 881, 1, 0, 0, 0, 880, 877, 1, 0, 0, 0, 881, 884, 1, 0, 0, 0, 882, 880, 1, 0, 0, 0, 882, 883, 1, 0, 0, 0, 883, 159, 1, 0, 0, 0, 884, 882, 1, 0, 0, 0, 885, 886, 5, 33, 0, 0, 886, 161, 1, 0, 0, 0, 887, 893, 3, 166, 83, 0, 888, 889, 3, 164, 82, 0, 889, 890, 3, 166, 83, 0, 890, 892, 1, 0, 0, 0, 891, 888, 1, 0, 0, 0, 892, 895, 1, 0, 0, 0, 893, 891, 1, 0, 0, 0, 893, 894, 1, 0, 0, 0, 894, 163, 1, 0, 0, 0, 895, 893, 1, 0, 0, 0, 896, 897, 5, 32, 0, 0, 897, 165, 1, 0, 0, 0, 898, 900, 5, 31, 0, 0, 899, 898, 1, 0, 0, 0, 899, 900, 1, 0, 0, 0, 900, 901, 1, 0, 0, 0, 901, 902, 3, 168, 84, 0, 902, 167, 1, 0, 0, 0, 903, 907, 3, 172, 86, 0, 904, 905, 3, 170, 85, 0, 905, 906, 3, 172, 86, 0, 906, 908, 1, 0, 0, 0, 907, 904, 1, 0, 0, 0, 907, 908, 1, 0, 0, 0, 908, 169, 1, 0, 0, 0, 909, 910, 7, 4, 0, 0, 910, 171, 1, 0, 0, 0, 911, 917, 3, 180, 90, 0, 912, 913, 3, 178, 89, 0, 913, 914, 3, 180, 90, 0, 914, 916, 1, 0, 0, 0, 915, 912, 1, 0, 0, 0, 916, 919, 1, 0, 0, 0, 917, 915, 1, 0, 0, 0, 917, 918, 1, 0, 0, 0, 918, 173, 1, 0, 0, 0, 919, 917, 1, 0, 0, 0, 920, 921, 3, 178, 89, 0, 921, 922, 3, 176, 88, 0, 922, 175, 1, 0, 0, 0, 923, 924, 3, 188, 94, 0, 924, 177, 1, 0, 0, 0, 925, 926, 7, 5, 0, 0, 926, 179, 1, 0, 0, 0, 927, 933, 3, 184, 92, 0, 928, 929, 3, 182, 91, 0, 929, 930, 3, 184, 92, 0, 930, 932, 1, 0, 0, 0, 931, 928, 1, 0, 0, 0, 932, 935, 1, 0, 0, 0, 933, 931, 1, 0, 0, 0, 933, 934, 1, 0, 0, 0, 934, 181, 1, 0, 0, 0, 935, 933, 1, 0, 0, 0, 936, 937, 7, 6, 0, 0, 937, 183, 1, 0, 0, 0, 938, 942, 3, 188, 94, 0, 939, 940, 3, 186, 93, 0, 940, 941, 3, 188, 94, 0, 941, 943, 1, 0, 0, 0, 942, 939, 1, 0, 0, 0, 942, 943, 1, 0, 0, 0, 943, 185, 1, 0, 0, 0, 944, 945, 7, 7, 0, 0, 945, 187, 1, 0, 0, 0, 946, 979, 5, 91, 0, 0, 947, 979, 5, 90, 0, 0, 948, 979, 5, 92, 0, 0, 949, 979, 3, 174, 87, 0, 950, 955, 3, 194, 97, 0, 951, 955, 5, 60, 0, 0, 952, 955, 5, 62, 0, 0, 953, 955, 5, 57, 0, 0, 954, 950, 1, 0, 0, 0, 954, 951, 1, 0, 0, 0, 954, 952, 1, 0, 0, 0, 954, 953, 1, 0, 0, 0, 955, 956, 1, 0, 0, 0, 956, 979, 3, 196, 98, 0, 957, 979, 3, 194, 97, 0, 958, 959, 5, 7, 0, 0, 959, 960, 3, 208, 104, 0, 960, 961, 5, 8, 0, 0, 961, 979, 1, 0, 0, 0, 962, 963, 5, 11, 0, 0, 963, 968, 3, 210, 105, 0, 964, 965, 5, 5, 0, 0, 965, 967, 3, 210, 105, 0, 966, 964, 1, 0, 0, 0, 967, 970, 1, 0, 0, 0, 968, 966, 1, 0, 0, 0, 968, 969, 1, 0, 0, 0, 969, 971, 1, 0, 0, 0, 970, 968, 1, 0, 0, 0, 971, 972, 5, 12, 0, 0, 972, 979, 1, 0, 0, 0, 973, 974, 5, 9, 0, 0, 974, 975, 3, 212, 106, 0, 975, 976, 5, 10, 0, 0, 976, 979, 1, 0, 0, 0, 977, 979, 5, 59, 0, 0, 978, 946, 1, 0, 0, 0, 978, 947, 1, 0, 0, 0, 978, 948, 1, 0, 0, 0, 978, 949, 1, 0, 0, 0, 978, 954, 1, 0, 0, 0, 978, 957, 1, 0, 0, 0, 978, 958, 1, 0, 0, 0, 978, 962, 1, 0, 0, 0, 978, 973, 1, 0, 0, 0, 978, 977, 1, 0, 0, 0, 979, 189, 1, 0, 0, 0, 980, 982, 5, 4, 0, 0, 981, 980, 1, 0, 0, 0, 981, 982, 1, 0, 0, 0, 982, 983, 1, 0, 0, 0, 983, 988, 5, 93, 0, 0, 984, 985, 5, 4, 0, 0, 985, 987, 5, 93, 0, 0, 986, 984, 1, 0, 0, 0, 987, 990, 1, 0, 0, 0, 988, 986, 1, 0, 0, 0, 988, 989, 1, 0, 0, 0, 989, 191, 1, 0, 0, 0, 990, 988, 1, 0, 0, 0, 991, 996, 5, 93, 0, 0, 992, 993, 5, 4, 0, 0, 993, 995, 5, 93, 0, 0, 994, 992, 1, 0, 0, 0, 995, 998, 1, 0, 0, 0, 996, 994, 1, 0, 0, 0, 996, 997, 1, 0, 0, 0, 997, 193, 1, 0, 0, 0, 998, 996, 1, 0, 0, 0, 999, 1001, 5, 4, 0, 0, 1000, 999, 1, 0, 0, 0, 1000, 1001, 1, 0, 0, 0, 1001, 1002, 1, 0, 0, 0, 1002, 1004, 5, 93, 0, 0, 1003, 1005, 3, 214, 107, 0, 1004, 1003, 1, 0, 0, 0, 1004, 1005, 1, 0, 0, 0, 1005, 1013, 1, 0, 0, 0, 1006, 1007, 5, 4, 0, 0, 1007, 1009, 5, 93, 0, 0, 1008, 1010, 3, 214, 107, 0, 1009, 1008, 1, 0, 0, 0, 1009, 1010, 1, 0, 0, 0, 1010, 1012, 1, 0, 0, 0, 1011, 1006, 1, 0, 0, 0, 1012, 1015, 1, 0, 0, 0, 1013, 1011, 1, 0, 0, 0, 1013, 1014, 1, 0, 0, 0, 1014, 195, 1, 0, 0, 0, 1015, 1013, 1, 0, 0, 0, 1016, 1018, 5, 7, 0, 0, 1017, 1019, 3, 198, 99, 0, 1018, 1017, 1, 0, 0, 0, 1018, 1019, 1, 0, 0, 0, 1019, 1020, 1, 0, 0, 0, 1020, 1021, 5, 8, 0, 0, 1021, 197, 1, 0, 0, 0, 1022, 1023, 3, 144, 72, 0, 1023, 1024, 5, 35, 0, 0, 1024, 1025, 3, 126, 63, 0, 1025, 1040, 1, 0, 0, 0, 1026, 1031, 3, 204, 102, 0, 1027, 1028, 5, 3, 0, 0, 1028, 1030, 3, 204, 102, 0, 1029, 1027, 1, 0, 0, 0, 1030, 1033, 1, 0, 0, 0, 1031, 1029, 1, 0, 0, 0, 1031, 1032, 1, 0, 0, 0, 1032, 1036, 1, 0, 0, 0, 1033, 1031, 1, 0, 0, 0, 1034, 1035, 5, 3, 0, 0, 1035, 1037, 3, 200, 100, 0, 1036, 1034, 1, 0, 0, 0, 1036, 1037, 1, 0, 0, 0, 1037, 1040, 1, 0, 0, 0, 1038, 1040, 3, 200, 100, 0, 1039, 1022, 1, 0, 0, 0, 1039, 1026, 1, 0, 0, 0, 1039, 1038, 1, 0, 0, 0, 1040, 199, 1, 0, 0, 0, 1041, 1046, 3, 202, 101, 0, 1042, 1043, 5, 3, 0, 0, 1043, 1045, 3, 202, 101, 0, 1044, 1042, 1, 0, 0, 0, 1045, 1048, 1, 0, 0, 0, 1046, 1044, 1, 0, 0, 0, 1046, 1047, 1, 0, 0, 0, 1047, 201, 1, 0, 0, 0, 1048, 1046, 1, 0, 0, 0, 1049, 1050, 5, 93, 0, 0, 1050, 1051, 5, 13, 0, 0, 1051, 1052, 3, 204, 102, 0, 1052, 203, 1, 0, 0, 0, 1053, 1056, 3, 206, 103, 0, 1054, 1056, 3, 144, 72, 0, 1055, 1053, 1, 0, 0, 0, 1055, 1054, 1, 0, 0, 0, 1056, 205, 1, 0, 0, 0, 1057, 1058, 5, 51, 0, 0, 1058, 1059, 3, 190, 95, 0, 1059, 1061, 5, 7, 0, 0, 1060, 1062, 3, 200, 100, 0, 1061, 1060, 1, 0, 0, 0, 1061, 1062, 1, 0, 0, 0, 1062, 1063, 1, 0, 0, 0, 1063, 1064, 5, 8, 0, 0, 1064, 207, 1, 0, 0, 0, 1065, 1067, 3, 144, 72, 0, 1066, 1065, 1, 0, 0, 0, 1066, 1067, 1, 0, 0, 0, 1067, 1074, 1, 0, 0, 0, 1068, 1070, 5, 3, 0, 0, 1069, 1071, 3, 144, 72, 0, 1070, 1069, 1, 0, 0, 0, 1070, 1071, 1, 0, 0, 0, 1071, 1073, 1, 0, 0, 0, 1072, 1068, 1, 0, 0, 0, 1073, 1076, 1, 0, 0, 0, 1074, 1072, 1, 0, 0, 0, 1074, 1075, 1, 0, 0, 0, 1075, 209, 1, 0, 0, 0, 1076, 1074, 1, 0, 0, 0, 1077, 1082, 3, 144, 72, 0, 1078, 1079, 5, 3, 0, 0, 1079, 1081, 3, 144, 72, 0, 1080, 1078, 1, 0, 0, 0, 1081, 1084, 1, 0, 0, 0, 1082, 1080, 1, 0, 0, 0, 1082, 1083, 1, 0, 0, 0, 1083, 211, 1, 0, 0, 0, 1084, 1082, 1, 0, 0, 0, 1085, 1095, 3, 144, 72, 0, 1086, 1087, 5, 3, 0, 0, 1087, 1089, 3, 144, 72, 0, 1088, 1086, 1, 0, 0, 0, 1089, 1092, 1, 0, 0, 0, 1090, 1088, 1, 0, 0, 0, 1090, 1091, 1, 0, 0, 0, 1091, 1096, 1, 0, 0, 0, 1092, 1090, 1, 0, 0, 0, 1093, 1094, 5, 35, 0, 0, 1094, 1096, 3, 126, 63, 0, 1095, 1090, 1, 0, 0, 0, 1095, 1093, 1, 0, 0, 0, 1096, 213, 1, 0, 0, 0, 1097, 1098, 5, 11, 0, 0, 1098, 1103, 3, 216, 108, 0, 1099, 1100, 5, 3, 0, 0, 1100, 1102, 3, 216, 108, 0, 1101, 1099, 1, 0, 0, 0, 1102, 1105, 1, 0, 0, 0, 1103, 1101, 1, 0, 0, 0, 1103, 1104, 1, 0, 0, 0, 1104, 1106, 1, 0, 0, 0, 1105, 1103, 1, 0, 0, 0, 1106, 1107, 5, 12, 0, 0, 1107, 215, 1, 0, 0, 0, 1108, 1111, 5, 6, 0, 0, 1109, 1111, 3, 144, 72, 0, 1110, 1108, 1, 0, 0, 0, 1110, 1109, 1, 0, 0, 0, 1111, 217, 1, 0, 0, 0, 1112, 1114, 3, 220, 110, 0, 1113, 1115, 3, 224, 112, 0, 1114, 1113, 1, 0, 0, 0, 1114, 1115, 1, 0, 0, 0, 1115, 219, 1, 0, 0, 0, 1116, 1122, 5, 90, 0, 0, 1117, 1118, 3, 222, 111, 0, 1118, 1119, 5, 90, 0, 0, 1119, 1121, 1, 0, 0, 0, 1120, 1117, 1, 0, 0, 0, 1121, 1124, 1, 0, 0, 0, 1122, 1120, 1, 0, 0, 0, 1122, 1123, 1, 0, 0, 0, 1123, 1126, 1, 0, 0, 0, 1124, 1122, 1, 0, 0, 0, 1125, 1116, 1, 0, 0, 0, 1125, 1126, 1, 0, 0, 0, 1126, 221, 1, 0, 0, 0, 1127, 1128, 5, 15, 0, 0, 1128, 223, 1, 0, 0, 0, 1129, 1130, 5, 86, 0, 0, 1130, 1131, 3, 76, 38, 0, 1131, 225, 1, 0, 0, 0, 130, 228, 231, 234, 241, 245, 251, 256, 261, 267, 270, 274, 279, 289, 295, 305, 308, 318, 331, 338, 342, 345, 354, 365, 367, 371, 374, 382, 385, 388, 397, 404, 421, 427, 440, 442, 451, 455, 458, 461, 464, 467, 471, 476, 481, 484, 489, 493, 499, 504, 508, 514, 519, 524, 527, 530, 537, 543, 549, 552, 557, 563, 567, 571, 580, 585, 588, 591, 595, 599, 605, 608, 613, 618, 621, 634, 640, 650, 658, 672, 680, 695, 706, 712, 722, 732, 738, 758, 780, 786, 802, 815, 840, 849, 872, 874, 882, 893, 899, 907, 917, 933, 942, 954, 968, 978, 981, 988, 996, 1000, 1004, 1009, 1013, 1018, 1031, 1036, 1039, 1046, 1055, 1061, 1066, 1070, 1074, 1082, 1090, 1095, 1103, 1110, 1114, 1122, 1125] diff --git a/mofmt/parsing/generated/Modelica.py b/mofmt/parsing/generated/Modelica.py deleted file mode 100644 index cbd1f2c..0000000 --- a/mofmt/parsing/generated/Modelica.py +++ /dev/null @@ -1,17744 +0,0 @@ -# Generated from grammar/Modelica.g4 by ANTLR 4.13.0 -# encoding: utf-8 -import sys -from io import StringIO - -from antlr4 import * - -if sys.version_info[1] > 5: - from typing import TextIO -else: - from typing.io import TextIO - - -def serializedATN(): - return [ - 4, - 1, - 93, - 1133, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 2, - 7, - 7, - 7, - 2, - 8, - 7, - 8, - 2, - 9, - 7, - 9, - 2, - 10, - 7, - 10, - 2, - 11, - 7, - 11, - 2, - 12, - 7, - 12, - 2, - 13, - 7, - 13, - 2, - 14, - 7, - 14, - 2, - 15, - 7, - 15, - 2, - 16, - 7, - 16, - 2, - 17, - 7, - 17, - 2, - 18, - 7, - 18, - 2, - 19, - 7, - 19, - 2, - 20, - 7, - 20, - 2, - 21, - 7, - 21, - 2, - 22, - 7, - 22, - 2, - 23, - 7, - 23, - 2, - 24, - 7, - 24, - 2, - 25, - 7, - 25, - 2, - 26, - 7, - 26, - 2, - 27, - 7, - 27, - 2, - 28, - 7, - 28, - 2, - 29, - 7, - 29, - 2, - 30, - 7, - 30, - 2, - 31, - 7, - 31, - 2, - 32, - 7, - 32, - 2, - 33, - 7, - 33, - 2, - 34, - 7, - 34, - 2, - 35, - 7, - 35, - 2, - 36, - 7, - 36, - 2, - 37, - 7, - 37, - 2, - 38, - 7, - 38, - 2, - 39, - 7, - 39, - 2, - 40, - 7, - 40, - 2, - 41, - 7, - 41, - 2, - 42, - 7, - 42, - 2, - 43, - 7, - 43, - 2, - 44, - 7, - 44, - 2, - 45, - 7, - 45, - 2, - 46, - 7, - 46, - 2, - 47, - 7, - 47, - 2, - 48, - 7, - 48, - 2, - 49, - 7, - 49, - 2, - 50, - 7, - 50, - 2, - 51, - 7, - 51, - 2, - 52, - 7, - 52, - 2, - 53, - 7, - 53, - 2, - 54, - 7, - 54, - 2, - 55, - 7, - 55, - 2, - 56, - 7, - 56, - 2, - 57, - 7, - 57, - 2, - 58, - 7, - 58, - 2, - 59, - 7, - 59, - 2, - 60, - 7, - 60, - 2, - 61, - 7, - 61, - 2, - 62, - 7, - 62, - 2, - 63, - 7, - 63, - 2, - 64, - 7, - 64, - 2, - 65, - 7, - 65, - 2, - 66, - 7, - 66, - 2, - 67, - 7, - 67, - 2, - 68, - 7, - 68, - 2, - 69, - 7, - 69, - 2, - 70, - 7, - 70, - 2, - 71, - 7, - 71, - 2, - 72, - 7, - 72, - 2, - 73, - 7, - 73, - 2, - 74, - 7, - 74, - 2, - 75, - 7, - 75, - 2, - 76, - 7, - 76, - 2, - 77, - 7, - 77, - 2, - 78, - 7, - 78, - 2, - 79, - 7, - 79, - 2, - 80, - 7, - 80, - 2, - 81, - 7, - 81, - 2, - 82, - 7, - 82, - 2, - 83, - 7, - 83, - 2, - 84, - 7, - 84, - 2, - 85, - 7, - 85, - 2, - 86, - 7, - 86, - 2, - 87, - 7, - 87, - 2, - 88, - 7, - 88, - 2, - 89, - 7, - 89, - 2, - 90, - 7, - 90, - 2, - 91, - 7, - 91, - 2, - 92, - 7, - 92, - 2, - 93, - 7, - 93, - 2, - 94, - 7, - 94, - 2, - 95, - 7, - 95, - 2, - 96, - 7, - 96, - 2, - 97, - 7, - 97, - 2, - 98, - 7, - 98, - 2, - 99, - 7, - 99, - 2, - 100, - 7, - 100, - 2, - 101, - 7, - 101, - 2, - 102, - 7, - 102, - 2, - 103, - 7, - 103, - 2, - 104, - 7, - 104, - 2, - 105, - 7, - 105, - 2, - 106, - 7, - 106, - 2, - 107, - 7, - 107, - 2, - 108, - 7, - 108, - 2, - 109, - 7, - 109, - 2, - 110, - 7, - 110, - 2, - 111, - 7, - 111, - 2, - 112, - 7, - 112, - 1, - 0, - 1, - 0, - 3, - 0, - 229, - 8, - 0, - 1, - 0, - 3, - 0, - 232, - 8, - 0, - 1, - 0, - 3, - 0, - 235, - 8, - 0, - 1, - 0, - 1, - 0, - 1, - 0, - 5, - 0, - 240, - 8, - 0, - 10, - 0, - 12, - 0, - 243, - 9, - 0, - 1, - 1, - 3, - 1, - 246, - 8, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 2, - 3, - 2, - 252, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 257, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 262, - 8, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 268, - 8, - 2, - 1, - 2, - 3, - 2, - 271, - 8, - 2, - 1, - 2, - 1, - 2, - 3, - 2, - 275, - 8, - 2, - 1, - 3, - 1, - 3, - 1, - 3, - 3, - 3, - 280, - 8, - 3, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 3, - 4, - 290, - 8, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 1, - 4, - 3, - 4, - 296, - 8, - 4, - 1, - 5, - 1, - 5, - 1, - 5, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 3, - 6, - 306, - 8, - 6, - 1, - 6, - 3, - 6, - 309, - 8, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 1, - 6, - 3, - 6, - 319, - 8, - 6, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 5, - 7, - 330, - 8, - 7, - 10, - 7, - 12, - 7, - 333, - 9, - 7, - 1, - 7, - 1, - 7, - 1, - 7, - 1, - 8, - 3, - 8, - 339, - 8, - 8, - 1, - 9, - 1, - 9, - 3, - 9, - 343, - 8, - 9, - 1, - 9, - 3, - 9, - 346, - 8, - 9, - 1, - 9, - 1, - 9, - 1, - 10, - 1, - 10, - 1, - 10, - 5, - 10, - 353, - 8, - 10, - 10, - 10, - 12, - 10, - 356, - 9, - 10, - 1, - 11, - 1, - 11, - 1, - 11, - 1, - 12, - 1, - 12, - 1, - 12, - 1, - 12, - 1, - 12, - 5, - 12, - 366, - 8, - 12, - 10, - 12, - 12, - 12, - 369, - 9, - 12, - 1, - 12, - 3, - 12, - 372, - 8, - 12, - 1, - 12, - 3, - 12, - 375, - 8, - 12, - 1, - 13, - 1, - 13, - 1, - 13, - 1, - 13, - 1, - 14, - 1, - 14, - 3, - 14, - 383, - 8, - 14, - 1, - 14, - 3, - 14, - 386, - 8, - 14, - 1, - 14, - 3, - 14, - 389, - 8, - 14, - 1, - 14, - 1, - 14, - 1, - 15, - 1, - 15, - 1, - 16, - 1, - 16, - 1, - 16, - 3, - 16, - 398, - 8, - 16, - 1, - 16, - 1, - 16, - 1, - 16, - 1, - 17, - 1, - 17, - 3, - 17, - 405, - 8, - 17, - 1, - 17, - 1, - 17, - 1, - 18, - 1, - 18, - 1, - 19, - 1, - 19, - 1, - 19, - 1, - 20, - 1, - 20, - 1, - 20, - 1, - 21, - 1, - 21, - 1, - 21, - 5, - 21, - 420, - 8, - 21, - 10, - 21, - 12, - 21, - 423, - 9, - 21, - 1, - 22, - 1, - 22, - 1, - 22, - 3, - 22, - 428, - 8, - 22, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 23, - 3, - 23, - 441, - 8, - 23, - 3, - 23, - 443, - 8, - 23, - 1, - 23, - 1, - 23, - 1, - 24, - 1, - 24, - 1, - 24, - 5, - 24, - 450, - 8, - 24, - 10, - 24, - 12, - 24, - 453, - 9, - 24, - 1, - 25, - 3, - 25, - 456, - 8, - 25, - 1, - 25, - 3, - 25, - 459, - 8, - 25, - 1, - 25, - 3, - 25, - 462, - 8, - 25, - 1, - 25, - 3, - 25, - 465, - 8, - 25, - 1, - 25, - 3, - 25, - 468, - 8, - 25, - 1, - 25, - 1, - 25, - 3, - 25, - 472, - 8, - 25, - 1, - 25, - 1, - 25, - 1, - 25, - 3, - 25, - 477, - 8, - 25, - 1, - 26, - 1, - 26, - 1, - 26, - 3, - 26, - 482, - 8, - 26, - 1, - 26, - 3, - 26, - 485, - 8, - 26, - 1, - 27, - 1, - 27, - 1, - 27, - 3, - 27, - 490, - 8, - 27, - 1, - 28, - 1, - 28, - 3, - 28, - 494, - 8, - 28, - 1, - 28, - 1, - 28, - 1, - 29, - 1, - 29, - 3, - 29, - 500, - 8, - 29, - 1, - 29, - 1, - 29, - 1, - 29, - 3, - 29, - 505, - 8, - 29, - 5, - 29, - 507, - 8, - 29, - 10, - 29, - 12, - 29, - 510, - 9, - 29, - 1, - 30, - 1, - 30, - 1, - 30, - 3, - 30, - 515, - 8, - 30, - 1, - 31, - 1, - 31, - 1, - 31, - 3, - 31, - 520, - 8, - 31, - 1, - 31, - 1, - 31, - 1, - 32, - 3, - 32, - 525, - 8, - 32, - 1, - 32, - 3, - 32, - 528, - 8, - 32, - 1, - 32, - 3, - 32, - 531, - 8, - 32, - 1, - 33, - 1, - 33, - 1, - 33, - 5, - 33, - 536, - 8, - 33, - 10, - 33, - 12, - 33, - 539, - 9, - 33, - 1, - 34, - 1, - 34, - 1, - 34, - 3, - 34, - 544, - 8, - 34, - 1, - 34, - 1, - 34, - 1, - 35, - 1, - 35, - 3, - 35, - 550, - 8, - 35, - 1, - 35, - 3, - 35, - 553, - 8, - 35, - 1, - 36, - 1, - 36, - 1, - 36, - 3, - 36, - 558, - 8, - 36, - 1, - 36, - 1, - 36, - 1, - 36, - 1, - 36, - 3, - 36, - 564, - 8, - 36, - 1, - 37, - 1, - 37, - 3, - 37, - 568, - 8, - 37, - 1, - 38, - 1, - 38, - 3, - 38, - 572, - 8, - 38, - 1, - 38, - 1, - 38, - 1, - 39, - 1, - 39, - 1, - 39, - 5, - 39, - 579, - 8, - 39, - 10, - 39, - 12, - 39, - 582, - 9, - 39, - 1, - 40, - 1, - 40, - 3, - 40, - 586, - 8, - 40, - 1, - 41, - 3, - 41, - 589, - 8, - 41, - 1, - 41, - 3, - 41, - 592, - 8, - 41, - 1, - 41, - 1, - 41, - 3, - 41, - 596, - 8, - 41, - 1, - 42, - 1, - 42, - 3, - 42, - 600, - 8, - 42, - 1, - 42, - 1, - 42, - 1, - 43, - 1, - 43, - 3, - 43, - 606, - 8, - 43, - 1, - 43, - 3, - 43, - 609, - 8, - 43, - 1, - 43, - 1, - 43, - 1, - 43, - 3, - 43, - 614, - 8, - 43, - 1, - 44, - 1, - 44, - 1, - 44, - 3, - 44, - 619, - 8, - 44, - 1, - 44, - 3, - 44, - 622, - 8, - 44, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 48, - 3, - 48, - 635, - 8, - 48, - 1, - 48, - 1, - 48, - 1, - 48, - 1, - 49, - 3, - 49, - 641, - 8, - 49, - 1, - 49, - 1, - 49, - 1, - 49, - 1, - 50, - 1, - 50, - 1, - 50, - 5, - 50, - 649, - 8, - 50, - 10, - 50, - 12, - 50, - 652, - 9, - 50, - 1, - 51, - 1, - 51, - 1, - 51, - 5, - 51, - 657, - 8, - 51, - 10, - 51, - 12, - 51, - 660, - 9, - 51, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 3, - 52, - 673, - 8, - 52, - 1, - 52, - 1, - 52, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 3, - 53, - 681, - 8, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 3, - 53, - 696, - 8, - 53, - 1, - 53, - 1, - 53, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 5, - 54, - 705, - 8, - 54, - 10, - 54, - 12, - 54, - 708, - 9, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 3, - 54, - 713, - 8, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 55, - 1, - 55, - 1, - 55, - 5, - 55, - 721, - 8, - 55, - 10, - 55, - 12, - 55, - 724, - 9, - 55, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 5, - 56, - 731, - 8, - 56, - 10, - 56, - 12, - 56, - 734, - 9, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 3, - 56, - 739, - 8, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 58, - 1, - 58, - 1, - 58, - 1, - 58, - 1, - 59, - 1, - 59, - 1, - 60, - 1, - 60, - 1, - 60, - 5, - 60, - 757, - 8, - 60, - 10, - 60, - 12, - 60, - 760, - 9, - 60, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 63, - 1, - 63, - 1, - 63, - 5, - 63, - 779, - 8, - 63, - 10, - 63, - 12, - 63, - 782, - 9, - 63, - 1, - 64, - 1, - 64, - 1, - 64, - 3, - 64, - 787, - 8, - 64, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 5, - 66, - 801, - 8, - 66, - 10, - 66, - 12, - 66, - 804, - 9, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 5, - 67, - 814, - 8, - 67, - 10, - 67, - 12, - 67, - 817, - 9, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 70, - 1, - 70, - 1, - 70, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 72, - 1, - 72, - 3, - 72, - 841, - 8, - 72, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 5, - 73, - 848, - 8, - 73, - 10, - 73, - 12, - 73, - 851, - 9, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 76, - 1, - 76, - 1, - 77, - 1, - 77, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 3, - 78, - 873, - 8, - 78, - 3, - 78, - 875, - 8, - 78, - 1, - 79, - 1, - 79, - 1, - 79, - 1, - 79, - 5, - 79, - 881, - 8, - 79, - 10, - 79, - 12, - 79, - 884, - 9, - 79, - 1, - 80, - 1, - 80, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 5, - 81, - 892, - 8, - 81, - 10, - 81, - 12, - 81, - 895, - 9, - 81, - 1, - 82, - 1, - 82, - 1, - 83, - 3, - 83, - 900, - 8, - 83, - 1, - 83, - 1, - 83, - 1, - 84, - 1, - 84, - 1, - 84, - 1, - 84, - 3, - 84, - 908, - 8, - 84, - 1, - 85, - 1, - 85, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 5, - 86, - 916, - 8, - 86, - 10, - 86, - 12, - 86, - 919, - 9, - 86, - 1, - 87, - 1, - 87, - 1, - 87, - 1, - 88, - 1, - 88, - 1, - 89, - 1, - 89, - 1, - 90, - 1, - 90, - 1, - 90, - 1, - 90, - 5, - 90, - 932, - 8, - 90, - 10, - 90, - 12, - 90, - 935, - 9, - 90, - 1, - 91, - 1, - 91, - 1, - 92, - 1, - 92, - 1, - 92, - 1, - 92, - 3, - 92, - 943, - 8, - 92, - 1, - 93, - 1, - 93, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 3, - 94, - 955, - 8, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 5, - 94, - 967, - 8, - 94, - 10, - 94, - 12, - 94, - 970, - 9, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 1, - 94, - 3, - 94, - 979, - 8, - 94, - 1, - 95, - 3, - 95, - 982, - 8, - 95, - 1, - 95, - 1, - 95, - 1, - 95, - 5, - 95, - 987, - 8, - 95, - 10, - 95, - 12, - 95, - 990, - 9, - 95, - 1, - 96, - 1, - 96, - 1, - 96, - 5, - 96, - 995, - 8, - 96, - 10, - 96, - 12, - 96, - 998, - 9, - 96, - 1, - 97, - 3, - 97, - 1001, - 8, - 97, - 1, - 97, - 1, - 97, - 3, - 97, - 1005, - 8, - 97, - 1, - 97, - 1, - 97, - 1, - 97, - 3, - 97, - 1010, - 8, - 97, - 5, - 97, - 1012, - 8, - 97, - 10, - 97, - 12, - 97, - 1015, - 9, - 97, - 1, - 98, - 1, - 98, - 3, - 98, - 1019, - 8, - 98, - 1, - 98, - 1, - 98, - 1, - 99, - 1, - 99, - 1, - 99, - 1, - 99, - 1, - 99, - 1, - 99, - 1, - 99, - 5, - 99, - 1030, - 8, - 99, - 10, - 99, - 12, - 99, - 1033, - 9, - 99, - 1, - 99, - 1, - 99, - 3, - 99, - 1037, - 8, - 99, - 1, - 99, - 3, - 99, - 1040, - 8, - 99, - 1, - 100, - 1, - 100, - 1, - 100, - 5, - 100, - 1045, - 8, - 100, - 10, - 100, - 12, - 100, - 1048, - 9, - 100, - 1, - 101, - 1, - 101, - 1, - 101, - 1, - 101, - 1, - 102, - 1, - 102, - 3, - 102, - 1056, - 8, - 102, - 1, - 103, - 1, - 103, - 1, - 103, - 1, - 103, - 3, - 103, - 1062, - 8, - 103, - 1, - 103, - 1, - 103, - 1, - 104, - 3, - 104, - 1067, - 8, - 104, - 1, - 104, - 1, - 104, - 3, - 104, - 1071, - 8, - 104, - 5, - 104, - 1073, - 8, - 104, - 10, - 104, - 12, - 104, - 1076, - 9, - 104, - 1, - 105, - 1, - 105, - 1, - 105, - 5, - 105, - 1081, - 8, - 105, - 10, - 105, - 12, - 105, - 1084, - 9, - 105, - 1, - 106, - 1, - 106, - 1, - 106, - 5, - 106, - 1089, - 8, - 106, - 10, - 106, - 12, - 106, - 1092, - 9, - 106, - 1, - 106, - 1, - 106, - 3, - 106, - 1096, - 8, - 106, - 1, - 107, - 1, - 107, - 1, - 107, - 1, - 107, - 5, - 107, - 1102, - 8, - 107, - 10, - 107, - 12, - 107, - 1105, - 9, - 107, - 1, - 107, - 1, - 107, - 1, - 108, - 1, - 108, - 3, - 108, - 1111, - 8, - 108, - 1, - 109, - 1, - 109, - 3, - 109, - 1115, - 8, - 109, - 1, - 110, - 1, - 110, - 1, - 110, - 1, - 110, - 5, - 110, - 1121, - 8, - 110, - 10, - 110, - 12, - 110, - 1124, - 9, - 110, - 3, - 110, - 1126, - 8, - 110, - 1, - 111, - 1, - 111, - 1, - 112, - 1, - 112, - 1, - 112, - 1, - 112, - 0, - 0, - 113, - 0, - 2, - 4, - 6, - 8, - 10, - 12, - 14, - 16, - 18, - 20, - 22, - 24, - 26, - 28, - 30, - 32, - 34, - 36, - 38, - 40, - 42, - 44, - 46, - 48, - 50, - 52, - 54, - 56, - 58, - 60, - 62, - 64, - 66, - 68, - 70, - 72, - 74, - 76, - 78, - 80, - 82, - 84, - 86, - 88, - 90, - 92, - 94, - 96, - 98, - 100, - 102, - 104, - 106, - 108, - 110, - 112, - 114, - 116, - 118, - 120, - 122, - 124, - 126, - 128, - 130, - 132, - 134, - 136, - 138, - 140, - 142, - 144, - 146, - 148, - 150, - 152, - 154, - 156, - 158, - 160, - 162, - 164, - 166, - 168, - 170, - 172, - 174, - 176, - 178, - 180, - 182, - 184, - 186, - 188, - 190, - 192, - 194, - 196, - 198, - 200, - 202, - 204, - 206, - 208, - 210, - 212, - 214, - 216, - 218, - 220, - 222, - 224, - 0, - 8, - 1, - 0, - 57, - 58, - 1, - 0, - 71, - 72, - 1, - 0, - 80, - 81, - 1, - 0, - 82, - 84, - 1, - 0, - 25, - 30, - 2, - 0, - 15, - 16, - 20, - 21, - 2, - 0, - 17, - 18, - 22, - 23, - 2, - 0, - 19, - 19, - 24, - 24, - 1184, - 0, - 231, - 1, - 0, - 0, - 0, - 2, - 245, - 1, - 0, - 0, - 0, - 4, - 251, - 1, - 0, - 0, - 0, - 6, - 279, - 1, - 0, - 0, - 0, - 8, - 295, - 1, - 0, - 0, - 0, - 10, - 297, - 1, - 0, - 0, - 0, - 12, - 318, - 1, - 0, - 0, - 0, - 14, - 320, - 1, - 0, - 0, - 0, - 16, - 338, - 1, - 0, - 0, - 0, - 18, - 340, - 1, - 0, - 0, - 0, - 20, - 349, - 1, - 0, - 0, - 0, - 22, - 357, - 1, - 0, - 0, - 0, - 24, - 360, - 1, - 0, - 0, - 0, - 26, - 376, - 1, - 0, - 0, - 0, - 28, - 380, - 1, - 0, - 0, - 0, - 30, - 392, - 1, - 0, - 0, - 0, - 32, - 397, - 1, - 0, - 0, - 0, - 34, - 402, - 1, - 0, - 0, - 0, - 36, - 408, - 1, - 0, - 0, - 0, - 38, - 410, - 1, - 0, - 0, - 0, - 40, - 413, - 1, - 0, - 0, - 0, - 42, - 421, - 1, - 0, - 0, - 0, - 44, - 427, - 1, - 0, - 0, - 0, - 46, - 429, - 1, - 0, - 0, - 0, - 48, - 446, - 1, - 0, - 0, - 0, - 50, - 455, - 1, - 0, - 0, - 0, - 52, - 478, - 1, - 0, - 0, - 0, - 54, - 486, - 1, - 0, - 0, - 0, - 56, - 491, - 1, - 0, - 0, - 0, - 58, - 499, - 1, - 0, - 0, - 0, - 60, - 511, - 1, - 0, - 0, - 0, - 62, - 516, - 1, - 0, - 0, - 0, - 64, - 524, - 1, - 0, - 0, - 0, - 66, - 532, - 1, - 0, - 0, - 0, - 68, - 540, - 1, - 0, - 0, - 0, - 70, - 547, - 1, - 0, - 0, - 0, - 72, - 563, - 1, - 0, - 0, - 0, - 74, - 567, - 1, - 0, - 0, - 0, - 76, - 569, - 1, - 0, - 0, - 0, - 78, - 575, - 1, - 0, - 0, - 0, - 80, - 585, - 1, - 0, - 0, - 0, - 82, - 588, - 1, - 0, - 0, - 0, - 84, - 597, - 1, - 0, - 0, - 0, - 86, - 603, - 1, - 0, - 0, - 0, - 88, - 615, - 1, - 0, - 0, - 0, - 90, - 623, - 1, - 0, - 0, - 0, - 92, - 627, - 1, - 0, - 0, - 0, - 94, - 630, - 1, - 0, - 0, - 0, - 96, - 634, - 1, - 0, - 0, - 0, - 98, - 640, - 1, - 0, - 0, - 0, - 100, - 650, - 1, - 0, - 0, - 0, - 102, - 658, - 1, - 0, - 0, - 0, - 104, - 672, - 1, - 0, - 0, - 0, - 106, - 695, - 1, - 0, - 0, - 0, - 108, - 699, - 1, - 0, - 0, - 0, - 110, - 722, - 1, - 0, - 0, - 0, - 112, - 725, - 1, - 0, - 0, - 0, - 114, - 743, - 1, - 0, - 0, - 0, - 116, - 747, - 1, - 0, - 0, - 0, - 118, - 751, - 1, - 0, - 0, - 0, - 120, - 758, - 1, - 0, - 0, - 0, - 122, - 761, - 1, - 0, - 0, - 0, - 124, - 768, - 1, - 0, - 0, - 0, - 126, - 775, - 1, - 0, - 0, - 0, - 128, - 783, - 1, - 0, - 0, - 0, - 130, - 788, - 1, - 0, - 0, - 0, - 132, - 795, - 1, - 0, - 0, - 0, - 134, - 808, - 1, - 0, - 0, - 0, - 136, - 821, - 1, - 0, - 0, - 0, - 138, - 825, - 1, - 0, - 0, - 0, - 140, - 829, - 1, - 0, - 0, - 0, - 142, - 832, - 1, - 0, - 0, - 0, - 144, - 840, - 1, - 0, - 0, - 0, - 146, - 842, - 1, - 0, - 0, - 0, - 148, - 855, - 1, - 0, - 0, - 0, - 150, - 859, - 1, - 0, - 0, - 0, - 152, - 863, - 1, - 0, - 0, - 0, - 154, - 865, - 1, - 0, - 0, - 0, - 156, - 867, - 1, - 0, - 0, - 0, - 158, - 876, - 1, - 0, - 0, - 0, - 160, - 885, - 1, - 0, - 0, - 0, - 162, - 887, - 1, - 0, - 0, - 0, - 164, - 896, - 1, - 0, - 0, - 0, - 166, - 899, - 1, - 0, - 0, - 0, - 168, - 903, - 1, - 0, - 0, - 0, - 170, - 909, - 1, - 0, - 0, - 0, - 172, - 911, - 1, - 0, - 0, - 0, - 174, - 920, - 1, - 0, - 0, - 0, - 176, - 923, - 1, - 0, - 0, - 0, - 178, - 925, - 1, - 0, - 0, - 0, - 180, - 927, - 1, - 0, - 0, - 0, - 182, - 936, - 1, - 0, - 0, - 0, - 184, - 938, - 1, - 0, - 0, - 0, - 186, - 944, - 1, - 0, - 0, - 0, - 188, - 978, - 1, - 0, - 0, - 0, - 190, - 981, - 1, - 0, - 0, - 0, - 192, - 991, - 1, - 0, - 0, - 0, - 194, - 1000, - 1, - 0, - 0, - 0, - 196, - 1016, - 1, - 0, - 0, - 0, - 198, - 1039, - 1, - 0, - 0, - 0, - 200, - 1041, - 1, - 0, - 0, - 0, - 202, - 1049, - 1, - 0, - 0, - 0, - 204, - 1055, - 1, - 0, - 0, - 0, - 206, - 1057, - 1, - 0, - 0, - 0, - 208, - 1066, - 1, - 0, - 0, - 0, - 210, - 1077, - 1, - 0, - 0, - 0, - 212, - 1085, - 1, - 0, - 0, - 0, - 214, - 1097, - 1, - 0, - 0, - 0, - 216, - 1110, - 1, - 0, - 0, - 0, - 218, - 1112, - 1, - 0, - 0, - 0, - 220, - 1125, - 1, - 0, - 0, - 0, - 222, - 1127, - 1, - 0, - 0, - 0, - 224, - 1129, - 1, - 0, - 0, - 0, - 226, - 228, - 5, - 65, - 0, - 0, - 227, - 229, - 3, - 192, - 96, - 0, - 228, - 227, - 1, - 0, - 0, - 0, - 228, - 229, - 1, - 0, - 0, - 0, - 229, - 230, - 1, - 0, - 0, - 0, - 230, - 232, - 5, - 5, - 0, - 0, - 231, - 226, - 1, - 0, - 0, - 0, - 231, - 232, - 1, - 0, - 0, - 0, - 232, - 241, - 1, - 0, - 0, - 0, - 233, - 235, - 5, - 66, - 0, - 0, - 234, - 233, - 1, - 0, - 0, - 0, - 234, - 235, - 1, - 0, - 0, - 0, - 235, - 236, - 1, - 0, - 0, - 0, - 236, - 237, - 3, - 2, - 1, - 0, - 237, - 238, - 5, - 5, - 0, - 0, - 238, - 240, - 1, - 0, - 0, - 0, - 239, - 234, - 1, - 0, - 0, - 0, - 240, - 243, - 1, - 0, - 0, - 0, - 241, - 239, - 1, - 0, - 0, - 0, - 241, - 242, - 1, - 0, - 0, - 0, - 242, - 1, - 1, - 0, - 0, - 0, - 243, - 241, - 1, - 0, - 0, - 0, - 244, - 246, - 5, - 67, - 0, - 0, - 245, - 244, - 1, - 0, - 0, - 0, - 245, - 246, - 1, - 0, - 0, - 0, - 246, - 247, - 1, - 0, - 0, - 0, - 247, - 248, - 3, - 4, - 2, - 0, - 248, - 249, - 3, - 6, - 3, - 0, - 249, - 3, - 1, - 0, - 0, - 0, - 250, - 252, - 5, - 46, - 0, - 0, - 251, - 250, - 1, - 0, - 0, - 0, - 251, - 252, - 1, - 0, - 0, - 0, - 252, - 274, - 1, - 0, - 0, - 0, - 253, - 275, - 5, - 49, - 0, - 0, - 254, - 275, - 5, - 50, - 0, - 0, - 255, - 257, - 5, - 47, - 0, - 0, - 256, - 255, - 1, - 0, - 0, - 0, - 256, - 257, - 1, - 0, - 0, - 0, - 257, - 258, - 1, - 0, - 0, - 0, - 258, - 275, - 5, - 52, - 0, - 0, - 259, - 275, - 5, - 54, - 0, - 0, - 260, - 262, - 5, - 48, - 0, - 0, - 261, - 260, - 1, - 0, - 0, - 0, - 261, - 262, - 1, - 0, - 0, - 0, - 262, - 263, - 1, - 0, - 0, - 0, - 263, - 275, - 5, - 55, - 0, - 0, - 264, - 275, - 5, - 53, - 0, - 0, - 265, - 275, - 5, - 56, - 0, - 0, - 266, - 268, - 7, - 0, - 0, - 0, - 267, - 266, - 1, - 0, - 0, - 0, - 267, - 268, - 1, - 0, - 0, - 0, - 268, - 270, - 1, - 0, - 0, - 0, - 269, - 271, - 5, - 47, - 0, - 0, - 270, - 269, - 1, - 0, - 0, - 0, - 270, - 271, - 1, - 0, - 0, - 0, - 271, - 272, - 1, - 0, - 0, - 0, - 272, - 275, - 5, - 51, - 0, - 0, - 273, - 275, - 5, - 47, - 0, - 0, - 274, - 253, - 1, - 0, - 0, - 0, - 274, - 254, - 1, - 0, - 0, - 0, - 274, - 256, - 1, - 0, - 0, - 0, - 274, - 259, - 1, - 0, - 0, - 0, - 274, - 261, - 1, - 0, - 0, - 0, - 274, - 264, - 1, - 0, - 0, - 0, - 274, - 265, - 1, - 0, - 0, - 0, - 274, - 267, - 1, - 0, - 0, - 0, - 274, - 273, - 1, - 0, - 0, - 0, - 275, - 5, - 1, - 0, - 0, - 0, - 276, - 280, - 3, - 8, - 4, - 0, - 277, - 280, - 3, - 12, - 6, - 0, - 278, - 280, - 3, - 14, - 7, - 0, - 279, - 276, - 1, - 0, - 0, - 0, - 279, - 277, - 1, - 0, - 0, - 0, - 279, - 278, - 1, - 0, - 0, - 0, - 280, - 7, - 1, - 0, - 0, - 0, - 281, - 282, - 5, - 93, - 0, - 0, - 282, - 283, - 3, - 220, - 110, - 0, - 283, - 284, - 3, - 24, - 12, - 0, - 284, - 285, - 3, - 10, - 5, - 0, - 285, - 296, - 1, - 0, - 0, - 0, - 286, - 287, - 5, - 68, - 0, - 0, - 287, - 289, - 5, - 93, - 0, - 0, - 288, - 290, - 3, - 76, - 38, - 0, - 289, - 288, - 1, - 0, - 0, - 0, - 289, - 290, - 1, - 0, - 0, - 0, - 290, - 291, - 1, - 0, - 0, - 0, - 291, - 292, - 3, - 220, - 110, - 0, - 292, - 293, - 3, - 24, - 12, - 0, - 293, - 294, - 3, - 10, - 5, - 0, - 294, - 296, - 1, - 0, - 0, - 0, - 295, - 281, - 1, - 0, - 0, - 0, - 295, - 286, - 1, - 0, - 0, - 0, - 296, - 9, - 1, - 0, - 0, - 0, - 297, - 298, - 5, - 59, - 0, - 0, - 298, - 299, - 5, - 93, - 0, - 0, - 299, - 11, - 1, - 0, - 0, - 0, - 300, - 301, - 5, - 93, - 0, - 0, - 301, - 302, - 5, - 13, - 0, - 0, - 302, - 303, - 3, - 16, - 8, - 0, - 303, - 305, - 3, - 190, - 95, - 0, - 304, - 306, - 3, - 214, - 107, - 0, - 305, - 304, - 1, - 0, - 0, - 0, - 305, - 306, - 1, - 0, - 0, - 0, - 306, - 308, - 1, - 0, - 0, - 0, - 307, - 309, - 3, - 76, - 38, - 0, - 308, - 307, - 1, - 0, - 0, - 0, - 308, - 309, - 1, - 0, - 0, - 0, - 309, - 310, - 1, - 0, - 0, - 0, - 310, - 311, - 3, - 218, - 109, - 0, - 311, - 319, - 1, - 0, - 0, - 0, - 312, - 313, - 5, - 93, - 0, - 0, - 313, - 314, - 5, - 13, - 0, - 0, - 314, - 315, - 5, - 70, - 0, - 0, - 315, - 316, - 3, - 18, - 9, - 0, - 316, - 317, - 3, - 218, - 109, - 0, - 317, - 319, - 1, - 0, - 0, - 0, - 318, - 300, - 1, - 0, - 0, - 0, - 318, - 312, - 1, - 0, - 0, - 0, - 319, - 13, - 1, - 0, - 0, - 0, - 320, - 321, - 5, - 93, - 0, - 0, - 321, - 322, - 5, - 13, - 0, - 0, - 322, - 323, - 5, - 60, - 0, - 0, - 323, - 324, - 5, - 7, - 0, - 0, - 324, - 325, - 3, - 190, - 95, - 0, - 325, - 326, - 5, - 3, - 0, - 0, - 326, - 331, - 5, - 93, - 0, - 0, - 327, - 328, - 5, - 3, - 0, - 0, - 328, - 330, - 5, - 93, - 0, - 0, - 329, - 327, - 1, - 0, - 0, - 0, - 330, - 333, - 1, - 0, - 0, - 0, - 331, - 329, - 1, - 0, - 0, - 0, - 331, - 332, - 1, - 0, - 0, - 0, - 332, - 334, - 1, - 0, - 0, - 0, - 333, - 331, - 1, - 0, - 0, - 0, - 334, - 335, - 5, - 8, - 0, - 0, - 335, - 336, - 3, - 218, - 109, - 0, - 336, - 15, - 1, - 0, - 0, - 0, - 337, - 339, - 7, - 1, - 0, - 0, - 338, - 337, - 1, - 0, - 0, - 0, - 338, - 339, - 1, - 0, - 0, - 0, - 339, - 17, - 1, - 0, - 0, - 0, - 340, - 345, - 5, - 7, - 0, - 0, - 341, - 343, - 3, - 20, - 10, - 0, - 342, - 341, - 1, - 0, - 0, - 0, - 342, - 343, - 1, - 0, - 0, - 0, - 343, - 346, - 1, - 0, - 0, - 0, - 344, - 346, - 5, - 6, - 0, - 0, - 345, - 342, - 1, - 0, - 0, - 0, - 345, - 344, - 1, - 0, - 0, - 0, - 346, - 347, - 1, - 0, - 0, - 0, - 347, - 348, - 5, - 8, - 0, - 0, - 348, - 19, - 1, - 0, - 0, - 0, - 349, - 354, - 3, - 22, - 11, - 0, - 350, - 351, - 5, - 3, - 0, - 0, - 351, - 353, - 3, - 22, - 11, - 0, - 352, - 350, - 1, - 0, - 0, - 0, - 353, - 356, - 1, - 0, - 0, - 0, - 354, - 352, - 1, - 0, - 0, - 0, - 354, - 355, - 1, - 0, - 0, - 0, - 355, - 21, - 1, - 0, - 0, - 0, - 356, - 354, - 1, - 0, - 0, - 0, - 357, - 358, - 5, - 93, - 0, - 0, - 358, - 359, - 3, - 218, - 109, - 0, - 359, - 23, - 1, - 0, - 0, - 0, - 360, - 367, - 3, - 36, - 18, - 0, - 361, - 366, - 3, - 38, - 19, - 0, - 362, - 366, - 3, - 40, - 20, - 0, - 363, - 366, - 3, - 96, - 48, - 0, - 364, - 366, - 3, - 98, - 49, - 0, - 365, - 361, - 1, - 0, - 0, - 0, - 365, - 362, - 1, - 0, - 0, - 0, - 365, - 363, - 1, - 0, - 0, - 0, - 365, - 364, - 1, - 0, - 0, - 0, - 366, - 369, - 1, - 0, - 0, - 0, - 367, - 365, - 1, - 0, - 0, - 0, - 367, - 368, - 1, - 0, - 0, - 0, - 368, - 371, - 1, - 0, - 0, - 0, - 369, - 367, - 1, - 0, - 0, - 0, - 370, - 372, - 3, - 28, - 14, - 0, - 371, - 370, - 1, - 0, - 0, - 0, - 371, - 372, - 1, - 0, - 0, - 0, - 372, - 374, - 1, - 0, - 0, - 0, - 373, - 375, - 3, - 26, - 13, - 0, - 374, - 373, - 1, - 0, - 0, - 0, - 374, - 375, - 1, - 0, - 0, - 0, - 375, - 25, - 1, - 0, - 0, - 0, - 376, - 377, - 5, - 86, - 0, - 0, - 377, - 378, - 3, - 76, - 38, - 0, - 378, - 379, - 5, - 5, - 0, - 0, - 379, - 27, - 1, - 0, - 0, - 0, - 380, - 382, - 5, - 87, - 0, - 0, - 381, - 383, - 3, - 30, - 15, - 0, - 382, - 381, - 1, - 0, - 0, - 0, - 382, - 383, - 1, - 0, - 0, - 0, - 383, - 385, - 1, - 0, - 0, - 0, - 384, - 386, - 3, - 32, - 16, - 0, - 385, - 384, - 1, - 0, - 0, - 0, - 385, - 386, - 1, - 0, - 0, - 0, - 386, - 388, - 1, - 0, - 0, - 0, - 387, - 389, - 3, - 224, - 112, - 0, - 388, - 387, - 1, - 0, - 0, - 0, - 388, - 389, - 1, - 0, - 0, - 0, - 389, - 390, - 1, - 0, - 0, - 0, - 390, - 391, - 5, - 5, - 0, - 0, - 391, - 29, - 1, - 0, - 0, - 0, - 392, - 393, - 5, - 90, - 0, - 0, - 393, - 31, - 1, - 0, - 0, - 0, - 394, - 395, - 3, - 194, - 97, - 0, - 395, - 396, - 5, - 13, - 0, - 0, - 396, - 398, - 1, - 0, - 0, - 0, - 397, - 394, - 1, - 0, - 0, - 0, - 397, - 398, - 1, - 0, - 0, - 0, - 398, - 399, - 1, - 0, - 0, - 0, - 399, - 400, - 5, - 93, - 0, - 0, - 400, - 401, - 3, - 34, - 17, - 0, - 401, - 33, - 1, - 0, - 0, - 0, - 402, - 404, - 5, - 7, - 0, - 0, - 403, - 405, - 3, - 210, - 105, - 0, - 404, - 403, - 1, - 0, - 0, - 0, - 404, - 405, - 1, - 0, - 0, - 0, - 405, - 406, - 1, - 0, - 0, - 0, - 406, - 407, - 5, - 8, - 0, - 0, - 407, - 35, - 1, - 0, - 0, - 0, - 408, - 409, - 3, - 42, - 21, - 0, - 409, - 37, - 1, - 0, - 0, - 0, - 410, - 411, - 5, - 73, - 0, - 0, - 411, - 412, - 3, - 42, - 21, - 0, - 412, - 39, - 1, - 0, - 0, - 0, - 413, - 414, - 5, - 74, - 0, - 0, - 414, - 415, - 3, - 42, - 21, - 0, - 415, - 41, - 1, - 0, - 0, - 0, - 416, - 417, - 3, - 44, - 22, - 0, - 417, - 418, - 5, - 5, - 0, - 0, - 418, - 420, - 1, - 0, - 0, - 0, - 419, - 416, - 1, - 0, - 0, - 0, - 420, - 423, - 1, - 0, - 0, - 0, - 421, - 419, - 1, - 0, - 0, - 0, - 421, - 422, - 1, - 0, - 0, - 0, - 422, - 43, - 1, - 0, - 0, - 0, - 423, - 421, - 1, - 0, - 0, - 0, - 424, - 428, - 3, - 46, - 23, - 0, - 425, - 428, - 3, - 52, - 26, - 0, - 426, - 428, - 3, - 50, - 25, - 0, - 427, - 424, - 1, - 0, - 0, - 0, - 427, - 425, - 1, - 0, - 0, - 0, - 427, - 426, - 1, - 0, - 0, - 0, - 428, - 45, - 1, - 0, - 0, - 0, - 429, - 442, - 5, - 69, - 0, - 0, - 430, - 431, - 5, - 93, - 0, - 0, - 431, - 432, - 5, - 13, - 0, - 0, - 432, - 443, - 3, - 192, - 96, - 0, - 433, - 440, - 3, - 192, - 96, - 0, - 434, - 441, - 5, - 22, - 0, - 0, - 435, - 436, - 5, - 4, - 0, - 0, - 436, - 437, - 5, - 9, - 0, - 0, - 437, - 438, - 3, - 48, - 24, - 0, - 438, - 439, - 5, - 10, - 0, - 0, - 439, - 441, - 1, - 0, - 0, - 0, - 440, - 434, - 1, - 0, - 0, - 0, - 440, - 435, - 1, - 0, - 0, - 0, - 440, - 441, - 1, - 0, - 0, - 0, - 441, - 443, - 1, - 0, - 0, - 0, - 442, - 430, - 1, - 0, - 0, - 0, - 442, - 433, - 1, - 0, - 0, - 0, - 443, - 444, - 1, - 0, - 0, - 0, - 444, - 445, - 3, - 218, - 109, - 0, - 445, - 47, - 1, - 0, - 0, - 0, - 446, - 451, - 5, - 93, - 0, - 0, - 447, - 448, - 5, - 3, - 0, - 0, - 448, - 450, - 5, - 93, - 0, - 0, - 449, - 447, - 1, - 0, - 0, - 0, - 450, - 453, - 1, - 0, - 0, - 0, - 451, - 449, - 1, - 0, - 0, - 0, - 451, - 452, - 1, - 0, - 0, - 0, - 452, - 49, - 1, - 0, - 0, - 0, - 453, - 451, - 1, - 0, - 0, - 0, - 454, - 456, - 5, - 75, - 0, - 0, - 455, - 454, - 1, - 0, - 0, - 0, - 455, - 456, - 1, - 0, - 0, - 0, - 456, - 458, - 1, - 0, - 0, - 0, - 457, - 459, - 5, - 66, - 0, - 0, - 458, - 457, - 1, - 0, - 0, - 0, - 458, - 459, - 1, - 0, - 0, - 0, - 459, - 461, - 1, - 0, - 0, - 0, - 460, - 462, - 5, - 76, - 0, - 0, - 461, - 460, - 1, - 0, - 0, - 0, - 461, - 462, - 1, - 0, - 0, - 0, - 462, - 464, - 1, - 0, - 0, - 0, - 463, - 465, - 5, - 77, - 0, - 0, - 464, - 463, - 1, - 0, - 0, - 0, - 464, - 465, - 1, - 0, - 0, - 0, - 465, - 467, - 1, - 0, - 0, - 0, - 466, - 468, - 5, - 78, - 0, - 0, - 467, - 466, - 1, - 0, - 0, - 0, - 467, - 468, - 1, - 0, - 0, - 0, - 468, - 471, - 1, - 0, - 0, - 0, - 469, - 472, - 3, - 2, - 1, - 0, - 470, - 472, - 3, - 62, - 31, - 0, - 471, - 469, - 1, - 0, - 0, - 0, - 471, - 470, - 1, - 0, - 0, - 0, - 472, - 476, - 1, - 0, - 0, - 0, - 473, - 474, - 3, - 54, - 27, - 0, - 474, - 475, - 3, - 218, - 109, - 0, - 475, - 477, - 1, - 0, - 0, - 0, - 476, - 473, - 1, - 0, - 0, - 0, - 476, - 477, - 1, - 0, - 0, - 0, - 477, - 51, - 1, - 0, - 0, - 0, - 478, - 479, - 5, - 68, - 0, - 0, - 479, - 481, - 3, - 190, - 95, - 0, - 480, - 482, - 3, - 56, - 28, - 0, - 481, - 480, - 1, - 0, - 0, - 0, - 481, - 482, - 1, - 0, - 0, - 0, - 482, - 484, - 1, - 0, - 0, - 0, - 483, - 485, - 3, - 224, - 112, - 0, - 484, - 483, - 1, - 0, - 0, - 0, - 484, - 485, - 1, - 0, - 0, - 0, - 485, - 53, - 1, - 0, - 0, - 0, - 486, - 487, - 5, - 79, - 0, - 0, - 487, - 489, - 3, - 190, - 95, - 0, - 488, - 490, - 3, - 76, - 38, - 0, - 489, - 488, - 1, - 0, - 0, - 0, - 489, - 490, - 1, - 0, - 0, - 0, - 490, - 55, - 1, - 0, - 0, - 0, - 491, - 493, - 5, - 7, - 0, - 0, - 492, - 494, - 3, - 58, - 29, - 0, - 493, - 492, - 1, - 0, - 0, - 0, - 493, - 494, - 1, - 0, - 0, - 0, - 494, - 495, - 1, - 0, - 0, - 0, - 495, - 496, - 5, - 8, - 0, - 0, - 496, - 57, - 1, - 0, - 0, - 0, - 497, - 500, - 3, - 80, - 40, - 0, - 498, - 500, - 3, - 60, - 30, - 0, - 499, - 497, - 1, - 0, - 0, - 0, - 499, - 498, - 1, - 0, - 0, - 0, - 500, - 508, - 1, - 0, - 0, - 0, - 501, - 504, - 5, - 3, - 0, - 0, - 502, - 505, - 3, - 80, - 40, - 0, - 503, - 505, - 3, - 60, - 30, - 0, - 504, - 502, - 1, - 0, - 0, - 0, - 504, - 503, - 1, - 0, - 0, - 0, - 505, - 507, - 1, - 0, - 0, - 0, - 506, - 501, - 1, - 0, - 0, - 0, - 507, - 510, - 1, - 0, - 0, - 0, - 508, - 506, - 1, - 0, - 0, - 0, - 508, - 509, - 1, - 0, - 0, - 0, - 509, - 59, - 1, - 0, - 0, - 0, - 510, - 508, - 1, - 0, - 0, - 0, - 511, - 514, - 5, - 44, - 0, - 0, - 512, - 515, - 3, - 140, - 70, - 0, - 513, - 515, - 5, - 93, - 0, - 0, - 514, - 512, - 1, - 0, - 0, - 0, - 514, - 513, - 1, - 0, - 0, - 0, - 515, - 61, - 1, - 0, - 0, - 0, - 516, - 517, - 3, - 64, - 32, - 0, - 517, - 519, - 3, - 190, - 95, - 0, - 518, - 520, - 3, - 214, - 107, - 0, - 519, - 518, - 1, - 0, - 0, - 0, - 519, - 520, - 1, - 0, - 0, - 0, - 520, - 521, - 1, - 0, - 0, - 0, - 521, - 522, - 3, - 66, - 33, - 0, - 522, - 63, - 1, - 0, - 0, - 0, - 523, - 525, - 7, - 2, - 0, - 0, - 524, - 523, - 1, - 0, - 0, - 0, - 524, - 525, - 1, - 0, - 0, - 0, - 525, - 527, - 1, - 0, - 0, - 0, - 526, - 528, - 7, - 3, - 0, - 0, - 527, - 526, - 1, - 0, - 0, - 0, - 527, - 528, - 1, - 0, - 0, - 0, - 528, - 530, - 1, - 0, - 0, - 0, - 529, - 531, - 7, - 1, - 0, - 0, - 530, - 529, - 1, - 0, - 0, - 0, - 530, - 531, - 1, - 0, - 0, - 0, - 531, - 65, - 1, - 0, - 0, - 0, - 532, - 537, - 3, - 68, - 34, - 0, - 533, - 534, - 5, - 3, - 0, - 0, - 534, - 536, - 3, - 68, - 34, - 0, - 535, - 533, - 1, - 0, - 0, - 0, - 536, - 539, - 1, - 0, - 0, - 0, - 537, - 535, - 1, - 0, - 0, - 0, - 537, - 538, - 1, - 0, - 0, - 0, - 538, - 67, - 1, - 0, - 0, - 0, - 539, - 537, - 1, - 0, - 0, - 0, - 540, - 543, - 3, - 70, - 35, - 0, - 541, - 542, - 5, - 36, - 0, - 0, - 542, - 544, - 3, - 144, - 72, - 0, - 543, - 541, - 1, - 0, - 0, - 0, - 543, - 544, - 1, - 0, - 0, - 0, - 544, - 545, - 1, - 0, - 0, - 0, - 545, - 546, - 3, - 218, - 109, - 0, - 546, - 69, - 1, - 0, - 0, - 0, - 547, - 549, - 5, - 93, - 0, - 0, - 548, - 550, - 3, - 214, - 107, - 0, - 549, - 548, - 1, - 0, - 0, - 0, - 549, - 550, - 1, - 0, - 0, - 0, - 550, - 552, - 1, - 0, - 0, - 0, - 551, - 553, - 3, - 72, - 36, - 0, - 552, - 551, - 1, - 0, - 0, - 0, - 552, - 553, - 1, - 0, - 0, - 0, - 553, - 71, - 1, - 0, - 0, - 0, - 554, - 557, - 3, - 76, - 38, - 0, - 555, - 556, - 5, - 13, - 0, - 0, - 556, - 558, - 3, - 74, - 37, - 0, - 557, - 555, - 1, - 0, - 0, - 0, - 557, - 558, - 1, - 0, - 0, - 0, - 558, - 564, - 1, - 0, - 0, - 0, - 559, - 560, - 5, - 13, - 0, - 0, - 560, - 564, - 3, - 74, - 37, - 0, - 561, - 562, - 5, - 14, - 0, - 0, - 562, - 564, - 3, - 74, - 37, - 0, - 563, - 554, - 1, - 0, - 0, - 0, - 563, - 559, - 1, - 0, - 0, - 0, - 563, - 561, - 1, - 0, - 0, - 0, - 564, - 73, - 1, - 0, - 0, - 0, - 565, - 568, - 3, - 144, - 72, - 0, - 566, - 568, - 5, - 44, - 0, - 0, - 567, - 565, - 1, - 0, - 0, - 0, - 567, - 566, - 1, - 0, - 0, - 0, - 568, - 75, - 1, - 0, - 0, - 0, - 569, - 571, - 5, - 7, - 0, - 0, - 570, - 572, - 3, - 78, - 39, - 0, - 571, - 570, - 1, - 0, - 0, - 0, - 571, - 572, - 1, - 0, - 0, - 0, - 572, - 573, - 1, - 0, - 0, - 0, - 573, - 574, - 5, - 8, - 0, - 0, - 574, - 77, - 1, - 0, - 0, - 0, - 575, - 580, - 3, - 80, - 40, - 0, - 576, - 577, - 5, - 3, - 0, - 0, - 577, - 579, - 3, - 80, - 40, - 0, - 578, - 576, - 1, - 0, - 0, - 0, - 579, - 582, - 1, - 0, - 0, - 0, - 580, - 578, - 1, - 0, - 0, - 0, - 580, - 581, - 1, - 0, - 0, - 0, - 581, - 79, - 1, - 0, - 0, - 0, - 582, - 580, - 1, - 0, - 0, - 0, - 583, - 586, - 3, - 82, - 41, - 0, - 584, - 586, - 3, - 86, - 43, - 0, - 585, - 583, - 1, - 0, - 0, - 0, - 585, - 584, - 1, - 0, - 0, - 0, - 586, - 81, - 1, - 0, - 0, - 0, - 587, - 589, - 5, - 85, - 0, - 0, - 588, - 587, - 1, - 0, - 0, - 0, - 588, - 589, - 1, - 0, - 0, - 0, - 589, - 591, - 1, - 0, - 0, - 0, - 590, - 592, - 5, - 66, - 0, - 0, - 591, - 590, - 1, - 0, - 0, - 0, - 591, - 592, - 1, - 0, - 0, - 0, - 592, - 595, - 1, - 0, - 0, - 0, - 593, - 596, - 3, - 84, - 42, - 0, - 594, - 596, - 3, - 88, - 44, - 0, - 595, - 593, - 1, - 0, - 0, - 0, - 595, - 594, - 1, - 0, - 0, - 0, - 596, - 83, - 1, - 0, - 0, - 0, - 597, - 599, - 3, - 192, - 96, - 0, - 598, - 600, - 3, - 72, - 36, - 0, - 599, - 598, - 1, - 0, - 0, - 0, - 599, - 600, - 1, - 0, - 0, - 0, - 600, - 601, - 1, - 0, - 0, - 0, - 601, - 602, - 3, - 220, - 110, - 0, - 602, - 85, - 1, - 0, - 0, - 0, - 603, - 605, - 5, - 75, - 0, - 0, - 604, - 606, - 5, - 85, - 0, - 0, - 605, - 604, - 1, - 0, - 0, - 0, - 605, - 606, - 1, - 0, - 0, - 0, - 606, - 608, - 1, - 0, - 0, - 0, - 607, - 609, - 5, - 66, - 0, - 0, - 608, - 607, - 1, - 0, - 0, - 0, - 608, - 609, - 1, - 0, - 0, - 0, - 609, - 613, - 1, - 0, - 0, - 0, - 610, - 614, - 3, - 94, - 47, - 0, - 611, - 614, - 3, - 90, - 45, - 0, - 612, - 614, - 3, - 88, - 44, - 0, - 613, - 610, - 1, - 0, - 0, - 0, - 613, - 611, - 1, - 0, - 0, - 0, - 613, - 612, - 1, - 0, - 0, - 0, - 614, - 87, - 1, - 0, - 0, - 0, - 615, - 618, - 5, - 78, - 0, - 0, - 616, - 619, - 3, - 94, - 47, - 0, - 617, - 619, - 3, - 90, - 45, - 0, - 618, - 616, - 1, - 0, - 0, - 0, - 618, - 617, - 1, - 0, - 0, - 0, - 619, - 621, - 1, - 0, - 0, - 0, - 620, - 622, - 3, - 54, - 27, - 0, - 621, - 620, - 1, - 0, - 0, - 0, - 621, - 622, - 1, - 0, - 0, - 0, - 622, - 89, - 1, - 0, - 0, - 0, - 623, - 624, - 3, - 64, - 32, - 0, - 624, - 625, - 3, - 190, - 95, - 0, - 625, - 626, - 3, - 92, - 46, - 0, - 626, - 91, - 1, - 0, - 0, - 0, - 627, - 628, - 3, - 70, - 35, - 0, - 628, - 629, - 3, - 218, - 109, - 0, - 629, - 93, - 1, - 0, - 0, - 0, - 630, - 631, - 3, - 4, - 2, - 0, - 631, - 632, - 3, - 12, - 6, - 0, - 632, - 95, - 1, - 0, - 0, - 0, - 633, - 635, - 5, - 62, - 0, - 0, - 634, - 633, - 1, - 0, - 0, - 0, - 634, - 635, - 1, - 0, - 0, - 0, - 635, - 636, - 1, - 0, - 0, - 0, - 636, - 637, - 5, - 63, - 0, - 0, - 637, - 638, - 3, - 100, - 50, - 0, - 638, - 97, - 1, - 0, - 0, - 0, - 639, - 641, - 5, - 62, - 0, - 0, - 640, - 639, - 1, - 0, - 0, - 0, - 640, - 641, - 1, - 0, - 0, - 0, - 641, - 642, - 1, - 0, - 0, - 0, - 642, - 643, - 5, - 64, - 0, - 0, - 643, - 644, - 3, - 102, - 51, - 0, - 644, - 99, - 1, - 0, - 0, - 0, - 645, - 646, - 3, - 104, - 52, - 0, - 646, - 647, - 5, - 5, - 0, - 0, - 647, - 649, - 1, - 0, - 0, - 0, - 648, - 645, - 1, - 0, - 0, - 0, - 649, - 652, - 1, - 0, - 0, - 0, - 650, - 648, - 1, - 0, - 0, - 0, - 650, - 651, - 1, - 0, - 0, - 0, - 651, - 101, - 1, - 0, - 0, - 0, - 652, - 650, - 1, - 0, - 0, - 0, - 653, - 654, - 3, - 106, - 53, - 0, - 654, - 655, - 5, - 5, - 0, - 0, - 655, - 657, - 1, - 0, - 0, - 0, - 656, - 653, - 1, - 0, - 0, - 0, - 657, - 660, - 1, - 0, - 0, - 0, - 658, - 656, - 1, - 0, - 0, - 0, - 658, - 659, - 1, - 0, - 0, - 0, - 659, - 103, - 1, - 0, - 0, - 0, - 660, - 658, - 1, - 0, - 0, - 0, - 661, - 662, - 3, - 156, - 78, - 0, - 662, - 663, - 5, - 13, - 0, - 0, - 663, - 664, - 3, - 144, - 72, - 0, - 664, - 673, - 1, - 0, - 0, - 0, - 665, - 673, - 3, - 108, - 54, - 0, - 666, - 673, - 3, - 122, - 61, - 0, - 667, - 673, - 3, - 140, - 70, - 0, - 668, - 673, - 3, - 132, - 66, - 0, - 669, - 670, - 3, - 194, - 97, - 0, - 670, - 671, - 3, - 196, - 98, - 0, - 671, - 673, - 1, - 0, - 0, - 0, - 672, - 661, - 1, - 0, - 0, - 0, - 672, - 665, - 1, - 0, - 0, - 0, - 672, - 666, - 1, - 0, - 0, - 0, - 672, - 667, - 1, - 0, - 0, - 0, - 672, - 668, - 1, - 0, - 0, - 0, - 672, - 669, - 1, - 0, - 0, - 0, - 673, - 674, - 1, - 0, - 0, - 0, - 674, - 675, - 3, - 218, - 109, - 0, - 675, - 105, - 1, - 0, - 0, - 0, - 676, - 680, - 3, - 194, - 97, - 0, - 677, - 678, - 5, - 14, - 0, - 0, - 678, - 681, - 3, - 144, - 72, - 0, - 679, - 681, - 3, - 196, - 98, - 0, - 680, - 677, - 1, - 0, - 0, - 0, - 680, - 679, - 1, - 0, - 0, - 0, - 681, - 696, - 1, - 0, - 0, - 0, - 682, - 683, - 5, - 7, - 0, - 0, - 683, - 684, - 3, - 208, - 104, - 0, - 684, - 685, - 5, - 8, - 0, - 0, - 685, - 686, - 5, - 14, - 0, - 0, - 686, - 687, - 3, - 194, - 97, - 0, - 687, - 688, - 3, - 196, - 98, - 0, - 688, - 696, - 1, - 0, - 0, - 0, - 689, - 696, - 5, - 44, - 0, - 0, - 690, - 696, - 5, - 45, - 0, - 0, - 691, - 696, - 3, - 112, - 56, - 0, - 692, - 696, - 3, - 124, - 62, - 0, - 693, - 696, - 3, - 130, - 65, - 0, - 694, - 696, - 3, - 134, - 67, - 0, - 695, - 676, - 1, - 0, - 0, - 0, - 695, - 682, - 1, - 0, - 0, - 0, - 695, - 689, - 1, - 0, - 0, - 0, - 695, - 690, - 1, - 0, - 0, - 0, - 695, - 691, - 1, - 0, - 0, - 0, - 695, - 692, - 1, - 0, - 0, - 0, - 695, - 693, - 1, - 0, - 0, - 0, - 695, - 694, - 1, - 0, - 0, - 0, - 696, - 697, - 1, - 0, - 0, - 0, - 697, - 698, - 3, - 218, - 109, - 0, - 698, - 107, - 1, - 0, - 0, - 0, - 699, - 700, - 3, - 114, - 57, - 0, - 700, - 706, - 3, - 110, - 55, - 0, - 701, - 702, - 3, - 116, - 58, - 0, - 702, - 703, - 3, - 110, - 55, - 0, - 703, - 705, - 1, - 0, - 0, - 0, - 704, - 701, - 1, - 0, - 0, - 0, - 705, - 708, - 1, - 0, - 0, - 0, - 706, - 704, - 1, - 0, - 0, - 0, - 706, - 707, - 1, - 0, - 0, - 0, - 707, - 712, - 1, - 0, - 0, - 0, - 708, - 706, - 1, - 0, - 0, - 0, - 709, - 710, - 3, - 118, - 59, - 0, - 710, - 711, - 3, - 110, - 55, - 0, - 711, - 713, - 1, - 0, - 0, - 0, - 712, - 709, - 1, - 0, - 0, - 0, - 712, - 713, - 1, - 0, - 0, - 0, - 713, - 714, - 1, - 0, - 0, - 0, - 714, - 715, - 5, - 59, - 0, - 0, - 715, - 716, - 5, - 36, - 0, - 0, - 716, - 109, - 1, - 0, - 0, - 0, - 717, - 718, - 3, - 104, - 52, - 0, - 718, - 719, - 5, - 5, - 0, - 0, - 719, - 721, - 1, - 0, - 0, - 0, - 720, - 717, - 1, - 0, - 0, - 0, - 721, - 724, - 1, - 0, - 0, - 0, - 722, - 720, - 1, - 0, - 0, - 0, - 722, - 723, - 1, - 0, - 0, - 0, - 723, - 111, - 1, - 0, - 0, - 0, - 724, - 722, - 1, - 0, - 0, - 0, - 725, - 726, - 3, - 114, - 57, - 0, - 726, - 732, - 3, - 120, - 60, - 0, - 727, - 728, - 3, - 116, - 58, - 0, - 728, - 729, - 3, - 120, - 60, - 0, - 729, - 731, - 1, - 0, - 0, - 0, - 730, - 727, - 1, - 0, - 0, - 0, - 731, - 734, - 1, - 0, - 0, - 0, - 732, - 730, - 1, - 0, - 0, - 0, - 732, - 733, - 1, - 0, - 0, - 0, - 733, - 738, - 1, - 0, - 0, - 0, - 734, - 732, - 1, - 0, - 0, - 0, - 735, - 736, - 3, - 118, - 59, - 0, - 736, - 737, - 3, - 120, - 60, - 0, - 737, - 739, - 1, - 0, - 0, - 0, - 738, - 735, - 1, - 0, - 0, - 0, - 738, - 739, - 1, - 0, - 0, - 0, - 739, - 740, - 1, - 0, - 0, - 0, - 740, - 741, - 5, - 59, - 0, - 0, - 741, - 742, - 5, - 36, - 0, - 0, - 742, - 113, - 1, - 0, - 0, - 0, - 743, - 744, - 5, - 36, - 0, - 0, - 744, - 745, - 3, - 144, - 72, - 0, - 745, - 746, - 5, - 39, - 0, - 0, - 746, - 115, - 1, - 0, - 0, - 0, - 747, - 748, - 5, - 38, - 0, - 0, - 748, - 749, - 3, - 144, - 72, - 0, - 749, - 750, - 5, - 39, - 0, - 0, - 750, - 117, - 1, - 0, - 0, - 0, - 751, - 752, - 5, - 37, - 0, - 0, - 752, - 119, - 1, - 0, - 0, - 0, - 753, - 754, - 3, - 106, - 53, - 0, - 754, - 755, - 5, - 5, - 0, - 0, - 755, - 757, - 1, - 0, - 0, - 0, - 756, - 753, - 1, - 0, - 0, - 0, - 757, - 760, - 1, - 0, - 0, - 0, - 758, - 756, - 1, - 0, - 0, - 0, - 758, - 759, - 1, - 0, - 0, - 0, - 759, - 121, - 1, - 0, - 0, - 0, - 760, - 758, - 1, - 0, - 0, - 0, - 761, - 762, - 5, - 35, - 0, - 0, - 762, - 763, - 3, - 126, - 63, - 0, - 763, - 764, - 5, - 43, - 0, - 0, - 764, - 765, - 3, - 110, - 55, - 0, - 765, - 766, - 5, - 59, - 0, - 0, - 766, - 767, - 5, - 35, - 0, - 0, - 767, - 123, - 1, - 0, - 0, - 0, - 768, - 769, - 5, - 35, - 0, - 0, - 769, - 770, - 3, - 126, - 63, - 0, - 770, - 771, - 5, - 43, - 0, - 0, - 771, - 772, - 3, - 120, - 60, - 0, - 772, - 773, - 5, - 59, - 0, - 0, - 773, - 774, - 5, - 35, - 0, - 0, - 774, - 125, - 1, - 0, - 0, - 0, - 775, - 780, - 3, - 128, - 64, - 0, - 776, - 777, - 5, - 3, - 0, - 0, - 777, - 779, - 3, - 128, - 64, - 0, - 778, - 776, - 1, - 0, - 0, - 0, - 779, - 782, - 1, - 0, - 0, - 0, - 780, - 778, - 1, - 0, - 0, - 0, - 780, - 781, - 1, - 0, - 0, - 0, - 781, - 127, - 1, - 0, - 0, - 0, - 782, - 780, - 1, - 0, - 0, - 0, - 783, - 786, - 5, - 93, - 0, - 0, - 784, - 785, - 5, - 34, - 0, - 0, - 785, - 787, - 3, - 144, - 72, - 0, - 786, - 784, - 1, - 0, - 0, - 0, - 786, - 787, - 1, - 0, - 0, - 0, - 787, - 129, - 1, - 0, - 0, - 0, - 788, - 789, - 5, - 42, - 0, - 0, - 789, - 790, - 3, - 144, - 72, - 0, - 790, - 791, - 5, - 43, - 0, - 0, - 791, - 792, - 3, - 120, - 60, - 0, - 792, - 793, - 5, - 59, - 0, - 0, - 793, - 794, - 5, - 42, - 0, - 0, - 794, - 131, - 1, - 0, - 0, - 0, - 795, - 796, - 3, - 136, - 68, - 0, - 796, - 802, - 3, - 110, - 55, - 0, - 797, - 798, - 3, - 138, - 69, - 0, - 798, - 799, - 3, - 110, - 55, - 0, - 799, - 801, - 1, - 0, - 0, - 0, - 800, - 797, - 1, - 0, - 0, - 0, - 801, - 804, - 1, - 0, - 0, - 0, - 802, - 800, - 1, - 0, - 0, - 0, - 802, - 803, - 1, - 0, - 0, - 0, - 803, - 805, - 1, - 0, - 0, - 0, - 804, - 802, - 1, - 0, - 0, - 0, - 805, - 806, - 5, - 59, - 0, - 0, - 806, - 807, - 5, - 40, - 0, - 0, - 807, - 133, - 1, - 0, - 0, - 0, - 808, - 809, - 3, - 136, - 68, - 0, - 809, - 815, - 3, - 120, - 60, - 0, - 810, - 811, - 3, - 138, - 69, - 0, - 811, - 812, - 3, - 120, - 60, - 0, - 812, - 814, - 1, - 0, - 0, - 0, - 813, - 810, - 1, - 0, - 0, - 0, - 814, - 817, - 1, - 0, - 0, - 0, - 815, - 813, - 1, - 0, - 0, - 0, - 815, - 816, - 1, - 0, - 0, - 0, - 816, - 818, - 1, - 0, - 0, - 0, - 817, - 815, - 1, - 0, - 0, - 0, - 818, - 819, - 5, - 59, - 0, - 0, - 819, - 820, - 5, - 40, - 0, - 0, - 820, - 135, - 1, - 0, - 0, - 0, - 821, - 822, - 5, - 40, - 0, - 0, - 822, - 823, - 3, - 144, - 72, - 0, - 823, - 824, - 5, - 39, - 0, - 0, - 824, - 137, - 1, - 0, - 0, - 0, - 825, - 826, - 5, - 41, - 0, - 0, - 826, - 827, - 3, - 144, - 72, - 0, - 827, - 828, - 5, - 39, - 0, - 0, - 828, - 139, - 1, - 0, - 0, - 0, - 829, - 830, - 5, - 61, - 0, - 0, - 830, - 831, - 3, - 142, - 71, - 0, - 831, - 141, - 1, - 0, - 0, - 0, - 832, - 833, - 5, - 7, - 0, - 0, - 833, - 834, - 3, - 194, - 97, - 0, - 834, - 835, - 5, - 3, - 0, - 0, - 835, - 836, - 3, - 194, - 97, - 0, - 836, - 837, - 5, - 8, - 0, - 0, - 837, - 143, - 1, - 0, - 0, - 0, - 838, - 841, - 3, - 156, - 78, - 0, - 839, - 841, - 3, - 146, - 73, - 0, - 840, - 838, - 1, - 0, - 0, - 0, - 840, - 839, - 1, - 0, - 0, - 0, - 841, - 145, - 1, - 0, - 0, - 0, - 842, - 843, - 3, - 148, - 74, - 0, - 843, - 849, - 3, - 154, - 77, - 0, - 844, - 845, - 3, - 150, - 75, - 0, - 845, - 846, - 3, - 154, - 77, - 0, - 846, - 848, - 1, - 0, - 0, - 0, - 847, - 844, - 1, - 0, - 0, - 0, - 848, - 851, - 1, - 0, - 0, - 0, - 849, - 847, - 1, - 0, - 0, - 0, - 849, - 850, - 1, - 0, - 0, - 0, - 850, - 852, - 1, - 0, - 0, - 0, - 851, - 849, - 1, - 0, - 0, - 0, - 852, - 853, - 3, - 152, - 76, - 0, - 853, - 854, - 3, - 154, - 77, - 0, - 854, - 147, - 1, - 0, - 0, - 0, - 855, - 856, - 5, - 36, - 0, - 0, - 856, - 857, - 3, - 144, - 72, - 0, - 857, - 858, - 5, - 39, - 0, - 0, - 858, - 149, - 1, - 0, - 0, - 0, - 859, - 860, - 5, - 38, - 0, - 0, - 860, - 861, - 3, - 144, - 72, - 0, - 861, - 862, - 5, - 39, - 0, - 0, - 862, - 151, - 1, - 0, - 0, - 0, - 863, - 864, - 5, - 37, - 0, - 0, - 864, - 153, - 1, - 0, - 0, - 0, - 865, - 866, - 3, - 144, - 72, - 0, - 866, - 155, - 1, - 0, - 0, - 0, - 867, - 874, - 3, - 158, - 79, - 0, - 868, - 869, - 5, - 6, - 0, - 0, - 869, - 872, - 3, - 158, - 79, - 0, - 870, - 871, - 5, - 6, - 0, - 0, - 871, - 873, - 3, - 158, - 79, - 0, - 872, - 870, - 1, - 0, - 0, - 0, - 872, - 873, - 1, - 0, - 0, - 0, - 873, - 875, - 1, - 0, - 0, - 0, - 874, - 868, - 1, - 0, - 0, - 0, - 874, - 875, - 1, - 0, - 0, - 0, - 875, - 157, - 1, - 0, - 0, - 0, - 876, - 882, - 3, - 162, - 81, - 0, - 877, - 878, - 3, - 160, - 80, - 0, - 878, - 879, - 3, - 162, - 81, - 0, - 879, - 881, - 1, - 0, - 0, - 0, - 880, - 877, - 1, - 0, - 0, - 0, - 881, - 884, - 1, - 0, - 0, - 0, - 882, - 880, - 1, - 0, - 0, - 0, - 882, - 883, - 1, - 0, - 0, - 0, - 883, - 159, - 1, - 0, - 0, - 0, - 884, - 882, - 1, - 0, - 0, - 0, - 885, - 886, - 5, - 33, - 0, - 0, - 886, - 161, - 1, - 0, - 0, - 0, - 887, - 893, - 3, - 166, - 83, - 0, - 888, - 889, - 3, - 164, - 82, - 0, - 889, - 890, - 3, - 166, - 83, - 0, - 890, - 892, - 1, - 0, - 0, - 0, - 891, - 888, - 1, - 0, - 0, - 0, - 892, - 895, - 1, - 0, - 0, - 0, - 893, - 891, - 1, - 0, - 0, - 0, - 893, - 894, - 1, - 0, - 0, - 0, - 894, - 163, - 1, - 0, - 0, - 0, - 895, - 893, - 1, - 0, - 0, - 0, - 896, - 897, - 5, - 32, - 0, - 0, - 897, - 165, - 1, - 0, - 0, - 0, - 898, - 900, - 5, - 31, - 0, - 0, - 899, - 898, - 1, - 0, - 0, - 0, - 899, - 900, - 1, - 0, - 0, - 0, - 900, - 901, - 1, - 0, - 0, - 0, - 901, - 902, - 3, - 168, - 84, - 0, - 902, - 167, - 1, - 0, - 0, - 0, - 903, - 907, - 3, - 172, - 86, - 0, - 904, - 905, - 3, - 170, - 85, - 0, - 905, - 906, - 3, - 172, - 86, - 0, - 906, - 908, - 1, - 0, - 0, - 0, - 907, - 904, - 1, - 0, - 0, - 0, - 907, - 908, - 1, - 0, - 0, - 0, - 908, - 169, - 1, - 0, - 0, - 0, - 909, - 910, - 7, - 4, - 0, - 0, - 910, - 171, - 1, - 0, - 0, - 0, - 911, - 917, - 3, - 180, - 90, - 0, - 912, - 913, - 3, - 178, - 89, - 0, - 913, - 914, - 3, - 180, - 90, - 0, - 914, - 916, - 1, - 0, - 0, - 0, - 915, - 912, - 1, - 0, - 0, - 0, - 916, - 919, - 1, - 0, - 0, - 0, - 917, - 915, - 1, - 0, - 0, - 0, - 917, - 918, - 1, - 0, - 0, - 0, - 918, - 173, - 1, - 0, - 0, - 0, - 919, - 917, - 1, - 0, - 0, - 0, - 920, - 921, - 3, - 178, - 89, - 0, - 921, - 922, - 3, - 176, - 88, - 0, - 922, - 175, - 1, - 0, - 0, - 0, - 923, - 924, - 3, - 188, - 94, - 0, - 924, - 177, - 1, - 0, - 0, - 0, - 925, - 926, - 7, - 5, - 0, - 0, - 926, - 179, - 1, - 0, - 0, - 0, - 927, - 933, - 3, - 184, - 92, - 0, - 928, - 929, - 3, - 182, - 91, - 0, - 929, - 930, - 3, - 184, - 92, - 0, - 930, - 932, - 1, - 0, - 0, - 0, - 931, - 928, - 1, - 0, - 0, - 0, - 932, - 935, - 1, - 0, - 0, - 0, - 933, - 931, - 1, - 0, - 0, - 0, - 933, - 934, - 1, - 0, - 0, - 0, - 934, - 181, - 1, - 0, - 0, - 0, - 935, - 933, - 1, - 0, - 0, - 0, - 936, - 937, - 7, - 6, - 0, - 0, - 937, - 183, - 1, - 0, - 0, - 0, - 938, - 942, - 3, - 188, - 94, - 0, - 939, - 940, - 3, - 186, - 93, - 0, - 940, - 941, - 3, - 188, - 94, - 0, - 941, - 943, - 1, - 0, - 0, - 0, - 942, - 939, - 1, - 0, - 0, - 0, - 942, - 943, - 1, - 0, - 0, - 0, - 943, - 185, - 1, - 0, - 0, - 0, - 944, - 945, - 7, - 7, - 0, - 0, - 945, - 187, - 1, - 0, - 0, - 0, - 946, - 979, - 5, - 91, - 0, - 0, - 947, - 979, - 5, - 90, - 0, - 0, - 948, - 979, - 5, - 92, - 0, - 0, - 949, - 979, - 3, - 174, - 87, - 0, - 950, - 955, - 3, - 194, - 97, - 0, - 951, - 955, - 5, - 60, - 0, - 0, - 952, - 955, - 5, - 62, - 0, - 0, - 953, - 955, - 5, - 57, - 0, - 0, - 954, - 950, - 1, - 0, - 0, - 0, - 954, - 951, - 1, - 0, - 0, - 0, - 954, - 952, - 1, - 0, - 0, - 0, - 954, - 953, - 1, - 0, - 0, - 0, - 955, - 956, - 1, - 0, - 0, - 0, - 956, - 979, - 3, - 196, - 98, - 0, - 957, - 979, - 3, - 194, - 97, - 0, - 958, - 959, - 5, - 7, - 0, - 0, - 959, - 960, - 3, - 208, - 104, - 0, - 960, - 961, - 5, - 8, - 0, - 0, - 961, - 979, - 1, - 0, - 0, - 0, - 962, - 963, - 5, - 11, - 0, - 0, - 963, - 968, - 3, - 210, - 105, - 0, - 964, - 965, - 5, - 5, - 0, - 0, - 965, - 967, - 3, - 210, - 105, - 0, - 966, - 964, - 1, - 0, - 0, - 0, - 967, - 970, - 1, - 0, - 0, - 0, - 968, - 966, - 1, - 0, - 0, - 0, - 968, - 969, - 1, - 0, - 0, - 0, - 969, - 971, - 1, - 0, - 0, - 0, - 970, - 968, - 1, - 0, - 0, - 0, - 971, - 972, - 5, - 12, - 0, - 0, - 972, - 979, - 1, - 0, - 0, - 0, - 973, - 974, - 5, - 9, - 0, - 0, - 974, - 975, - 3, - 212, - 106, - 0, - 975, - 976, - 5, - 10, - 0, - 0, - 976, - 979, - 1, - 0, - 0, - 0, - 977, - 979, - 5, - 59, - 0, - 0, - 978, - 946, - 1, - 0, - 0, - 0, - 978, - 947, - 1, - 0, - 0, - 0, - 978, - 948, - 1, - 0, - 0, - 0, - 978, - 949, - 1, - 0, - 0, - 0, - 978, - 954, - 1, - 0, - 0, - 0, - 978, - 957, - 1, - 0, - 0, - 0, - 978, - 958, - 1, - 0, - 0, - 0, - 978, - 962, - 1, - 0, - 0, - 0, - 978, - 973, - 1, - 0, - 0, - 0, - 978, - 977, - 1, - 0, - 0, - 0, - 979, - 189, - 1, - 0, - 0, - 0, - 980, - 982, - 5, - 4, - 0, - 0, - 981, - 980, - 1, - 0, - 0, - 0, - 981, - 982, - 1, - 0, - 0, - 0, - 982, - 983, - 1, - 0, - 0, - 0, - 983, - 988, - 5, - 93, - 0, - 0, - 984, - 985, - 5, - 4, - 0, - 0, - 985, - 987, - 5, - 93, - 0, - 0, - 986, - 984, - 1, - 0, - 0, - 0, - 987, - 990, - 1, - 0, - 0, - 0, - 988, - 986, - 1, - 0, - 0, - 0, - 988, - 989, - 1, - 0, - 0, - 0, - 989, - 191, - 1, - 0, - 0, - 0, - 990, - 988, - 1, - 0, - 0, - 0, - 991, - 996, - 5, - 93, - 0, - 0, - 992, - 993, - 5, - 4, - 0, - 0, - 993, - 995, - 5, - 93, - 0, - 0, - 994, - 992, - 1, - 0, - 0, - 0, - 995, - 998, - 1, - 0, - 0, - 0, - 996, - 994, - 1, - 0, - 0, - 0, - 996, - 997, - 1, - 0, - 0, - 0, - 997, - 193, - 1, - 0, - 0, - 0, - 998, - 996, - 1, - 0, - 0, - 0, - 999, - 1001, - 5, - 4, - 0, - 0, - 1000, - 999, - 1, - 0, - 0, - 0, - 1000, - 1001, - 1, - 0, - 0, - 0, - 1001, - 1002, - 1, - 0, - 0, - 0, - 1002, - 1004, - 5, - 93, - 0, - 0, - 1003, - 1005, - 3, - 214, - 107, - 0, - 1004, - 1003, - 1, - 0, - 0, - 0, - 1004, - 1005, - 1, - 0, - 0, - 0, - 1005, - 1013, - 1, - 0, - 0, - 0, - 1006, - 1007, - 5, - 4, - 0, - 0, - 1007, - 1009, - 5, - 93, - 0, - 0, - 1008, - 1010, - 3, - 214, - 107, - 0, - 1009, - 1008, - 1, - 0, - 0, - 0, - 1009, - 1010, - 1, - 0, - 0, - 0, - 1010, - 1012, - 1, - 0, - 0, - 0, - 1011, - 1006, - 1, - 0, - 0, - 0, - 1012, - 1015, - 1, - 0, - 0, - 0, - 1013, - 1011, - 1, - 0, - 0, - 0, - 1013, - 1014, - 1, - 0, - 0, - 0, - 1014, - 195, - 1, - 0, - 0, - 0, - 1015, - 1013, - 1, - 0, - 0, - 0, - 1016, - 1018, - 5, - 7, - 0, - 0, - 1017, - 1019, - 3, - 198, - 99, - 0, - 1018, - 1017, - 1, - 0, - 0, - 0, - 1018, - 1019, - 1, - 0, - 0, - 0, - 1019, - 1020, - 1, - 0, - 0, - 0, - 1020, - 1021, - 5, - 8, - 0, - 0, - 1021, - 197, - 1, - 0, - 0, - 0, - 1022, - 1023, - 3, - 144, - 72, - 0, - 1023, - 1024, - 5, - 35, - 0, - 0, - 1024, - 1025, - 3, - 126, - 63, - 0, - 1025, - 1040, - 1, - 0, - 0, - 0, - 1026, - 1031, - 3, - 204, - 102, - 0, - 1027, - 1028, - 5, - 3, - 0, - 0, - 1028, - 1030, - 3, - 204, - 102, - 0, - 1029, - 1027, - 1, - 0, - 0, - 0, - 1030, - 1033, - 1, - 0, - 0, - 0, - 1031, - 1029, - 1, - 0, - 0, - 0, - 1031, - 1032, - 1, - 0, - 0, - 0, - 1032, - 1036, - 1, - 0, - 0, - 0, - 1033, - 1031, - 1, - 0, - 0, - 0, - 1034, - 1035, - 5, - 3, - 0, - 0, - 1035, - 1037, - 3, - 200, - 100, - 0, - 1036, - 1034, - 1, - 0, - 0, - 0, - 1036, - 1037, - 1, - 0, - 0, - 0, - 1037, - 1040, - 1, - 0, - 0, - 0, - 1038, - 1040, - 3, - 200, - 100, - 0, - 1039, - 1022, - 1, - 0, - 0, - 0, - 1039, - 1026, - 1, - 0, - 0, - 0, - 1039, - 1038, - 1, - 0, - 0, - 0, - 1040, - 199, - 1, - 0, - 0, - 0, - 1041, - 1046, - 3, - 202, - 101, - 0, - 1042, - 1043, - 5, - 3, - 0, - 0, - 1043, - 1045, - 3, - 202, - 101, - 0, - 1044, - 1042, - 1, - 0, - 0, - 0, - 1045, - 1048, - 1, - 0, - 0, - 0, - 1046, - 1044, - 1, - 0, - 0, - 0, - 1046, - 1047, - 1, - 0, - 0, - 0, - 1047, - 201, - 1, - 0, - 0, - 0, - 1048, - 1046, - 1, - 0, - 0, - 0, - 1049, - 1050, - 5, - 93, - 0, - 0, - 1050, - 1051, - 5, - 13, - 0, - 0, - 1051, - 1052, - 3, - 204, - 102, - 0, - 1052, - 203, - 1, - 0, - 0, - 0, - 1053, - 1056, - 3, - 206, - 103, - 0, - 1054, - 1056, - 3, - 144, - 72, - 0, - 1055, - 1053, - 1, - 0, - 0, - 0, - 1055, - 1054, - 1, - 0, - 0, - 0, - 1056, - 205, - 1, - 0, - 0, - 0, - 1057, - 1058, - 5, - 51, - 0, - 0, - 1058, - 1059, - 3, - 190, - 95, - 0, - 1059, - 1061, - 5, - 7, - 0, - 0, - 1060, - 1062, - 3, - 200, - 100, - 0, - 1061, - 1060, - 1, - 0, - 0, - 0, - 1061, - 1062, - 1, - 0, - 0, - 0, - 1062, - 1063, - 1, - 0, - 0, - 0, - 1063, - 1064, - 5, - 8, - 0, - 0, - 1064, - 207, - 1, - 0, - 0, - 0, - 1065, - 1067, - 3, - 144, - 72, - 0, - 1066, - 1065, - 1, - 0, - 0, - 0, - 1066, - 1067, - 1, - 0, - 0, - 0, - 1067, - 1074, - 1, - 0, - 0, - 0, - 1068, - 1070, - 5, - 3, - 0, - 0, - 1069, - 1071, - 3, - 144, - 72, - 0, - 1070, - 1069, - 1, - 0, - 0, - 0, - 1070, - 1071, - 1, - 0, - 0, - 0, - 1071, - 1073, - 1, - 0, - 0, - 0, - 1072, - 1068, - 1, - 0, - 0, - 0, - 1073, - 1076, - 1, - 0, - 0, - 0, - 1074, - 1072, - 1, - 0, - 0, - 0, - 1074, - 1075, - 1, - 0, - 0, - 0, - 1075, - 209, - 1, - 0, - 0, - 0, - 1076, - 1074, - 1, - 0, - 0, - 0, - 1077, - 1082, - 3, - 144, - 72, - 0, - 1078, - 1079, - 5, - 3, - 0, - 0, - 1079, - 1081, - 3, - 144, - 72, - 0, - 1080, - 1078, - 1, - 0, - 0, - 0, - 1081, - 1084, - 1, - 0, - 0, - 0, - 1082, - 1080, - 1, - 0, - 0, - 0, - 1082, - 1083, - 1, - 0, - 0, - 0, - 1083, - 211, - 1, - 0, - 0, - 0, - 1084, - 1082, - 1, - 0, - 0, - 0, - 1085, - 1095, - 3, - 144, - 72, - 0, - 1086, - 1087, - 5, - 3, - 0, - 0, - 1087, - 1089, - 3, - 144, - 72, - 0, - 1088, - 1086, - 1, - 0, - 0, - 0, - 1089, - 1092, - 1, - 0, - 0, - 0, - 1090, - 1088, - 1, - 0, - 0, - 0, - 1090, - 1091, - 1, - 0, - 0, - 0, - 1091, - 1096, - 1, - 0, - 0, - 0, - 1092, - 1090, - 1, - 0, - 0, - 0, - 1093, - 1094, - 5, - 35, - 0, - 0, - 1094, - 1096, - 3, - 126, - 63, - 0, - 1095, - 1090, - 1, - 0, - 0, - 0, - 1095, - 1093, - 1, - 0, - 0, - 0, - 1096, - 213, - 1, - 0, - 0, - 0, - 1097, - 1098, - 5, - 11, - 0, - 0, - 1098, - 1103, - 3, - 216, - 108, - 0, - 1099, - 1100, - 5, - 3, - 0, - 0, - 1100, - 1102, - 3, - 216, - 108, - 0, - 1101, - 1099, - 1, - 0, - 0, - 0, - 1102, - 1105, - 1, - 0, - 0, - 0, - 1103, - 1101, - 1, - 0, - 0, - 0, - 1103, - 1104, - 1, - 0, - 0, - 0, - 1104, - 1106, - 1, - 0, - 0, - 0, - 1105, - 1103, - 1, - 0, - 0, - 0, - 1106, - 1107, - 5, - 12, - 0, - 0, - 1107, - 215, - 1, - 0, - 0, - 0, - 1108, - 1111, - 5, - 6, - 0, - 0, - 1109, - 1111, - 3, - 144, - 72, - 0, - 1110, - 1108, - 1, - 0, - 0, - 0, - 1110, - 1109, - 1, - 0, - 0, - 0, - 1111, - 217, - 1, - 0, - 0, - 0, - 1112, - 1114, - 3, - 220, - 110, - 0, - 1113, - 1115, - 3, - 224, - 112, - 0, - 1114, - 1113, - 1, - 0, - 0, - 0, - 1114, - 1115, - 1, - 0, - 0, - 0, - 1115, - 219, - 1, - 0, - 0, - 0, - 1116, - 1122, - 5, - 90, - 0, - 0, - 1117, - 1118, - 3, - 222, - 111, - 0, - 1118, - 1119, - 5, - 90, - 0, - 0, - 1119, - 1121, - 1, - 0, - 0, - 0, - 1120, - 1117, - 1, - 0, - 0, - 0, - 1121, - 1124, - 1, - 0, - 0, - 0, - 1122, - 1120, - 1, - 0, - 0, - 0, - 1122, - 1123, - 1, - 0, - 0, - 0, - 1123, - 1126, - 1, - 0, - 0, - 0, - 1124, - 1122, - 1, - 0, - 0, - 0, - 1125, - 1116, - 1, - 0, - 0, - 0, - 1125, - 1126, - 1, - 0, - 0, - 0, - 1126, - 221, - 1, - 0, - 0, - 0, - 1127, - 1128, - 5, - 15, - 0, - 0, - 1128, - 223, - 1, - 0, - 0, - 0, - 1129, - 1130, - 5, - 86, - 0, - 0, - 1130, - 1131, - 3, - 76, - 38, - 0, - 1131, - 225, - 1, - 0, - 0, - 0, - 130, - 228, - 231, - 234, - 241, - 245, - 251, - 256, - 261, - 267, - 270, - 274, - 279, - 289, - 295, - 305, - 308, - 318, - 331, - 338, - 342, - 345, - 354, - 365, - 367, - 371, - 374, - 382, - 385, - 388, - 397, - 404, - 421, - 427, - 440, - 442, - 451, - 455, - 458, - 461, - 464, - 467, - 471, - 476, - 481, - 484, - 489, - 493, - 499, - 504, - 508, - 514, - 519, - 524, - 527, - 530, - 537, - 543, - 549, - 552, - 557, - 563, - 567, - 571, - 580, - 585, - 588, - 591, - 595, - 599, - 605, - 608, - 613, - 618, - 621, - 634, - 640, - 650, - 658, - 672, - 680, - 695, - 706, - 712, - 722, - 732, - 738, - 758, - 780, - 786, - 802, - 815, - 840, - 849, - 872, - 874, - 882, - 893, - 899, - 907, - 917, - 933, - 942, - 954, - 968, - 978, - 981, - 988, - 996, - 1000, - 1004, - 1009, - 1013, - 1018, - 1031, - 1036, - 1039, - 1046, - 1055, - 1061, - 1066, - 1070, - 1074, - 1082, - 1090, - 1095, - 1103, - 1110, - 1114, - 1122, - 1125, - ] - - -class Modelica(Parser): - grammarFileName = "Modelica.g4" - - atn = ATNDeserializer().deserialize(serializedATN()) - - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] - - sharedContextCache = PredictionContextCache() - - literalNames = [ - "", - "", - "'\"'", - "','", - "'.'", - "';'", - "':'", - "'('", - "')'", - "'{'", - "'}'", - "'['", - "']'", - "'='", - "':='", - "'+'", - "'-'", - "'*'", - "'/'", - "'^'", - "'.+'", - "'.-'", - "'.*'", - "'./'", - "'.^'", - "'>'", - "'>='", - "'<'", - "'<='", - "'<>'", - "'=='", - "'not'", - "'and'", - "'or'", - "'in'", - "'for'", - "'if'", - "'else'", - "'elseif'", - "'then'", - "'when'", - "'elsewhen'", - "'while'", - "'loop'", - "'break'", - "'return'", - "'partial'", - "'operator'", - "'expandable'", - "'class'", - "'model'", - "'function'", - "'record'", - "'type'", - "'block'", - "'connector'", - "'package'", - "'pure'", - "'impure'", - "'end'", - "'der'", - "'connect'", - "'initial'", - "'equation'", - "'algorithm'", - "'within'", - "'final'", - "'encapsulated'", - "'extends'", - "'import'", - "'enumeration'", - "'input'", - "'output'", - "'public'", - "'protected'", - "'redeclare'", - "'inner'", - "'outer'", - "'replaceable'", - "'constrainedby'", - "'flow'", - "'stream'", - "'discrete'", - "'parameter'", - "'constant'", - "'each'", - "'annotation'", - "'external'", - ] - - symbolicNames = [ - "", - "WS", - "DQUOTE", - "COMMA", - "DOT", - "SEMICOLON", - "COLON", - "LPAREN", - "RPAREN", - "LCURLY", - "RCURLY", - "LBRACK", - "RBRACK", - "EQUAL", - "ASSIGN", - "PLUS", - "MINUS", - "STAR", - "SLASH", - "FLEX", - "DOTPLUS", - "DOTMINUS", - "DOTSTAR", - "DOTSLASH", - "DOTFLEX", - "GRE", - "GEQ", - "LES", - "LEQ", - "NEQ", - "EEQ", - "NOT", - "AND", - "OR", - "IN", - "FOR", - "IF", - "ELSE", - "ELSEIF", - "THEN", - "WHEN", - "ELSEWHEN", - "WHILE", - "LOOP", - "BREAK", - "RETURN", - "PARTIAL", - "OPERATOR", - "EXPANDABLE", - "CLASS", - "MODEL", - "FUNCTION", - "RECORD", - "TYPE", - "BLOCK", - "CONNECTOR", - "PACKAGE", - "PURE", - "IMPURE", - "END", - "DER", - "CONNECT", - "INITIAL", - "EQUATION", - "ALGORITHM", - "WITHIN", - "FINAL", - "ENCAPSULATED", - "EXTENDS", - "IMPORT", - "ENUMERATION", - "INPUT", - "OUTPUT", - "PUBLIC", - "PROTECTED", - "REDECLARE", - "INNER", - "OUTER", - "REPLACEABLE", - "CONSTRAINEDBY", - "FLOW", - "STREAM", - "DISCRETE", - "PARAMETER", - "CONSTANT", - "EACH", - "ANNOTATION", - "EXTERNAL", - "BLOCK_COMMENT", - "LINE_COMMENT", - "STRING", - "UNUM", - "BOOL", - "IDENT", - ] - - RULE_stored_definition = 0 - RULE_class_definition = 1 - RULE_class_prefixes = 2 - RULE_class_specifier = 3 - RULE_long_class_specifier = 4 - RULE_end_clause = 5 - RULE_short_class_specifier = 6 - RULE_der_class_specifier = 7 - RULE_base_prefix = 8 - RULE_enumerations = 9 - RULE_enum_list = 10 - RULE_enumeration_literal = 11 - RULE_composition = 12 - RULE_class_annotation = 13 - RULE_external_element = 14 - RULE_language_specification = 15 - RULE_external_function_call = 16 - RULE_external_function_args = 17 - RULE_initial_element_list = 18 - RULE_public_element_list = 19 - RULE_protected_element_list = 20 - RULE_element_list = 21 - RULE_element = 22 - RULE_import_clause = 23 - RULE_import_list = 24 - RULE_declaration_clause = 25 - RULE_extends_clause = 26 - RULE_constraining_clause = 27 - RULE_class_or_inheritance_modification = 28 - RULE_argument_or_inheritance_modification_list = 29 - RULE_inheritance_modification = 30 - RULE_component_clause = 31 - RULE_type_prefix = 32 - RULE_component_list = 33 - RULE_component_declaration = 34 - RULE_declaration = 35 - RULE_modification = 36 - RULE_modification_expression = 37 - RULE_class_modification = 38 - RULE_argument_list = 39 - RULE_argument = 40 - RULE_element_modification_or_replaceable = 41 - RULE_element_modification = 42 - RULE_element_redeclaration = 43 - RULE_element_replaceable = 44 - RULE_short_component_clause = 45 - RULE_short_component_declaration = 46 - RULE_short_definition = 47 - RULE_equation_section = 48 - RULE_algorithm_section = 49 - RULE_equation_list = 50 - RULE_statement_list = 51 - RULE_equation = 52 - RULE_statement = 53 - RULE_if_equation = 54 - RULE_conditional_equations = 55 - RULE_if_statement = 56 - RULE_if_branch = 57 - RULE_elseif_branch = 58 - RULE_else_branch = 59 - RULE_conditional_statements = 60 - RULE_for_equation = 61 - RULE_for_statement = 62 - RULE_for_indices = 63 - RULE_for_index = 64 - RULE_while_statement = 65 - RULE_when_equation = 66 - RULE_when_statement = 67 - RULE_when_branch = 68 - RULE_elsewhen_branch = 69 - RULE_connect_equation = 70 - RULE_connected_components = 71 - RULE_expression = 72 - RULE_if_expression = 73 - RULE_if_eval = 74 - RULE_elseif_eval = 75 - RULE_else_eval = 76 - RULE_conditional_expression = 77 - RULE_simple_expression = 78 - RULE_logical_expression = 79 - RULE_or_operator = 80 - RULE_logical_term = 81 - RULE_and_operator = 82 - RULE_logical_factor = 83 - RULE_relation = 84 - RULE_relational_operator = 85 - RULE_arithmetic_expression = 86 - RULE_unary_expression = 87 - RULE_unary_operand = 88 - RULE_add_operator = 89 - RULE_term = 90 - RULE_mul_operator = 91 - RULE_factor = 92 - RULE_exp_operator = 93 - RULE_primary = 94 - RULE_type_specifier = 95 - RULE_name = 96 - RULE_component_reference = 97 - RULE_function_call_args = 98 - RULE_function_arguments = 99 - RULE_named_arguments = 100 - RULE_named_argument = 101 - RULE_function_argument = 102 - RULE_function_partial_application = 103 - RULE_output_expression_list = 104 - RULE_expression_list = 105 - RULE_array_arguments = 106 - RULE_array_subscripts = 107 - RULE_subscript = 108 - RULE_description = 109 - RULE_description_string = 110 - RULE_cat_operator = 111 - RULE_annotation = 112 - - ruleNames = [ - "stored_definition", - "class_definition", - "class_prefixes", - "class_specifier", - "long_class_specifier", - "end_clause", - "short_class_specifier", - "der_class_specifier", - "base_prefix", - "enumerations", - "enum_list", - "enumeration_literal", - "composition", - "class_annotation", - "external_element", - "language_specification", - "external_function_call", - "external_function_args", - "initial_element_list", - "public_element_list", - "protected_element_list", - "element_list", - "element", - "import_clause", - "import_list", - "declaration_clause", - "extends_clause", - "constraining_clause", - "class_or_inheritance_modification", - "argument_or_inheritance_modification_list", - "inheritance_modification", - "component_clause", - "type_prefix", - "component_list", - "component_declaration", - "declaration", - "modification", - "modification_expression", - "class_modification", - "argument_list", - "argument", - "element_modification_or_replaceable", - "element_modification", - "element_redeclaration", - "element_replaceable", - "short_component_clause", - "short_component_declaration", - "short_definition", - "equation_section", - "algorithm_section", - "equation_list", - "statement_list", - "equation", - "statement", - "if_equation", - "conditional_equations", - "if_statement", - "if_branch", - "elseif_branch", - "else_branch", - "conditional_statements", - "for_equation", - "for_statement", - "for_indices", - "for_index", - "while_statement", - "when_equation", - "when_statement", - "when_branch", - "elsewhen_branch", - "connect_equation", - "connected_components", - "expression", - "if_expression", - "if_eval", - "elseif_eval", - "else_eval", - "conditional_expression", - "simple_expression", - "logical_expression", - "or_operator", - "logical_term", - "and_operator", - "logical_factor", - "relation", - "relational_operator", - "arithmetic_expression", - "unary_expression", - "unary_operand", - "add_operator", - "term", - "mul_operator", - "factor", - "exp_operator", - "primary", - "type_specifier", - "name", - "component_reference", - "function_call_args", - "function_arguments", - "named_arguments", - "named_argument", - "function_argument", - "function_partial_application", - "output_expression_list", - "expression_list", - "array_arguments", - "array_subscripts", - "subscript", - "description", - "description_string", - "cat_operator", - "annotation", - ] - - EOF = Token.EOF - WS = 1 - DQUOTE = 2 - COMMA = 3 - DOT = 4 - SEMICOLON = 5 - COLON = 6 - LPAREN = 7 - RPAREN = 8 - LCURLY = 9 - RCURLY = 10 - LBRACK = 11 - RBRACK = 12 - EQUAL = 13 - ASSIGN = 14 - PLUS = 15 - MINUS = 16 - STAR = 17 - SLASH = 18 - FLEX = 19 - DOTPLUS = 20 - DOTMINUS = 21 - DOTSTAR = 22 - DOTSLASH = 23 - DOTFLEX = 24 - GRE = 25 - GEQ = 26 - LES = 27 - LEQ = 28 - NEQ = 29 - EEQ = 30 - NOT = 31 - AND = 32 - OR = 33 - IN = 34 - FOR = 35 - IF = 36 - ELSE = 37 - ELSEIF = 38 - THEN = 39 - WHEN = 40 - ELSEWHEN = 41 - WHILE = 42 - LOOP = 43 - BREAK = 44 - RETURN = 45 - PARTIAL = 46 - OPERATOR = 47 - EXPANDABLE = 48 - CLASS = 49 - MODEL = 50 - FUNCTION = 51 - RECORD = 52 - TYPE = 53 - BLOCK = 54 - CONNECTOR = 55 - PACKAGE = 56 - PURE = 57 - IMPURE = 58 - END = 59 - DER = 60 - CONNECT = 61 - INITIAL = 62 - EQUATION = 63 - ALGORITHM = 64 - WITHIN = 65 - FINAL = 66 - ENCAPSULATED = 67 - EXTENDS = 68 - IMPORT = 69 - ENUMERATION = 70 - INPUT = 71 - OUTPUT = 72 - PUBLIC = 73 - PROTECTED = 74 - REDECLARE = 75 - INNER = 76 - OUTER = 77 - REPLACEABLE = 78 - CONSTRAINEDBY = 79 - FLOW = 80 - STREAM = 81 - DISCRETE = 82 - PARAMETER = 83 - CONSTANT = 84 - EACH = 85 - ANNOTATION = 86 - EXTERNAL = 87 - BLOCK_COMMENT = 88 - LINE_COMMENT = 89 - STRING = 90 - UNUM = 91 - BOOL = 92 - IDENT = 93 - - def __init__(self, input: TokenStream, output: TextIO = sys.stdout): - super().__init__(input, output) - self.checkVersion("4.13.0") - self._interp = ParserATNSimulator( - self, self.atn, self.decisionsToDFA, self.sharedContextCache - ) - self._predicates = None - - class Stored_definitionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def WITHIN(self): - return self.getToken(Modelica.WITHIN, 0) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def class_definition(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Class_definitionContext) - else: - return self.getTypedRuleContext(Modelica.Class_definitionContext, i) - - def name(self): - return self.getTypedRuleContext(Modelica.NameContext, 0) - - def FINAL(self, i: int = None): - if i is None: - return self.getTokens(Modelica.FINAL) - else: - return self.getToken(Modelica.FINAL, i) - - def getRuleIndex(self): - return Modelica.RULE_stored_definition - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterStored_definition"): - listener.enterStored_definition(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitStored_definition"): - listener.exitStored_definition(self) - - def stored_definition(self): - localctx = Modelica.Stored_definitionContext(self, self._ctx, self.state) - self.enterRule(localctx, 0, self.RULE_stored_definition) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 231 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 65: - self.state = 226 - self.match(Modelica.WITHIN) - self.state = 228 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 93: - self.state = 227 - self.name() - - self.state = 230 - self.match(Modelica.SEMICOLON) - - self.state = 241 - self._errHandler.sync(self) - _la = self._input.LA(1) - while (((_la - 46)) & ~0x3F) == 0 and ((1 << (_la - 46)) & 3153919) != 0: - self.state = 234 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 66: - self.state = 233 - self.match(Modelica.FINAL) - - self.state = 236 - self.class_definition() - self.state = 237 - self.match(Modelica.SEMICOLON) - self.state = 243 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_definitionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def class_prefixes(self): - return self.getTypedRuleContext(Modelica.Class_prefixesContext, 0) - - def class_specifier(self): - return self.getTypedRuleContext(Modelica.Class_specifierContext, 0) - - def ENCAPSULATED(self): - return self.getToken(Modelica.ENCAPSULATED, 0) - - def getRuleIndex(self): - return Modelica.RULE_class_definition - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_definition"): - listener.enterClass_definition(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_definition"): - listener.exitClass_definition(self) - - def class_definition(self): - localctx = Modelica.Class_definitionContext(self, self._ctx, self.state) - self.enterRule(localctx, 2, self.RULE_class_definition) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 245 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 67: - self.state = 244 - self.match(Modelica.ENCAPSULATED) - - self.state = 247 - self.class_prefixes() - self.state = 248 - self.class_specifier() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_prefixesContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def CLASS(self): - return self.getToken(Modelica.CLASS, 0) - - def MODEL(self): - return self.getToken(Modelica.MODEL, 0) - - def RECORD(self): - return self.getToken(Modelica.RECORD, 0) - - def BLOCK(self): - return self.getToken(Modelica.BLOCK, 0) - - def CONNECTOR(self): - return self.getToken(Modelica.CONNECTOR, 0) - - def TYPE(self): - return self.getToken(Modelica.TYPE, 0) - - def PACKAGE(self): - return self.getToken(Modelica.PACKAGE, 0) - - def FUNCTION(self): - return self.getToken(Modelica.FUNCTION, 0) - - def OPERATOR(self): - return self.getToken(Modelica.OPERATOR, 0) - - def PARTIAL(self): - return self.getToken(Modelica.PARTIAL, 0) - - def EXPANDABLE(self): - return self.getToken(Modelica.EXPANDABLE, 0) - - def PURE(self): - return self.getToken(Modelica.PURE, 0) - - def IMPURE(self): - return self.getToken(Modelica.IMPURE, 0) - - def getRuleIndex(self): - return Modelica.RULE_class_prefixes - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_prefixes"): - listener.enterClass_prefixes(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_prefixes"): - listener.exitClass_prefixes(self) - - def class_prefixes(self): - localctx = Modelica.Class_prefixesContext(self, self._ctx, self.state) - self.enterRule(localctx, 4, self.RULE_class_prefixes) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 251 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 46: - self.state = 250 - self.match(Modelica.PARTIAL) - - self.state = 274 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 10, self._ctx) - if la_ == 1: - self.state = 253 - self.match(Modelica.CLASS) - pass - - elif la_ == 2: - self.state = 254 - self.match(Modelica.MODEL) - pass - - elif la_ == 3: - self.state = 256 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 47: - self.state = 255 - self.match(Modelica.OPERATOR) - - self.state = 258 - self.match(Modelica.RECORD) - pass - - elif la_ == 4: - self.state = 259 - self.match(Modelica.BLOCK) - pass - - elif la_ == 5: - self.state = 261 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 48: - self.state = 260 - self.match(Modelica.EXPANDABLE) - - self.state = 263 - self.match(Modelica.CONNECTOR) - pass - - elif la_ == 6: - self.state = 264 - self.match(Modelica.TYPE) - pass - - elif la_ == 7: - self.state = 265 - self.match(Modelica.PACKAGE) - pass - - elif la_ == 8: - self.state = 267 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 57 or _la == 58: - self.state = 266 - _la = self._input.LA(1) - if not (_la == 57 or _la == 58): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - - self.state = 270 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 47: - self.state = 269 - self.match(Modelica.OPERATOR) - - self.state = 272 - self.match(Modelica.FUNCTION) - pass - - elif la_ == 9: - self.state = 273 - self.match(Modelica.OPERATOR) - pass - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_specifierContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def long_class_specifier(self): - return self.getTypedRuleContext(Modelica.Long_class_specifierContext, 0) - - def short_class_specifier(self): - return self.getTypedRuleContext(Modelica.Short_class_specifierContext, 0) - - def der_class_specifier(self): - return self.getTypedRuleContext(Modelica.Der_class_specifierContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_class_specifier - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_specifier"): - listener.enterClass_specifier(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_specifier"): - listener.exitClass_specifier(self) - - def class_specifier(self): - localctx = Modelica.Class_specifierContext(self, self._ctx, self.state) - self.enterRule(localctx, 6, self.RULE_class_specifier) - try: - self.state = 279 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 11, self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 276 - self.long_class_specifier() - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 277 - self.short_class_specifier() - pass - - elif la_ == 3: - self.enterOuterAlt(localctx, 3) - self.state = 278 - self.der_class_specifier() - pass - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Long_class_specifierContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def description_string(self): - return self.getTypedRuleContext(Modelica.Description_stringContext, 0) - - def composition(self): - return self.getTypedRuleContext(Modelica.CompositionContext, 0) - - def end_clause(self): - return self.getTypedRuleContext(Modelica.End_clauseContext, 0) - - def EXTENDS(self): - return self.getToken(Modelica.EXTENDS, 0) - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_long_class_specifier - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterLong_class_specifier"): - listener.enterLong_class_specifier(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitLong_class_specifier"): - listener.exitLong_class_specifier(self) - - def long_class_specifier(self): - localctx = Modelica.Long_class_specifierContext(self, self._ctx, self.state) - self.enterRule(localctx, 8, self.RULE_long_class_specifier) - self._la = 0 # Token type - try: - self.state = 295 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [93]: - self.enterOuterAlt(localctx, 1) - self.state = 281 - self.match(Modelica.IDENT) - self.state = 282 - self.description_string() - self.state = 283 - self.composition() - self.state = 284 - self.end_clause() - pass - elif token in [68]: - self.enterOuterAlt(localctx, 2) - self.state = 286 - self.match(Modelica.EXTENDS) - self.state = 287 - self.match(Modelica.IDENT) - self.state = 289 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 7: - self.state = 288 - self.class_modification() - - self.state = 291 - self.description_string() - self.state = 292 - self.composition() - self.state = 293 - self.end_clause() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class End_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def END(self): - return self.getToken(Modelica.END, 0) - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def getRuleIndex(self): - return Modelica.RULE_end_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEnd_clause"): - listener.enterEnd_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEnd_clause"): - listener.exitEnd_clause(self) - - def end_clause(self): - localctx = Modelica.End_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 10, self.RULE_end_clause) - try: - self.enterOuterAlt(localctx, 1) - self.state = 297 - self.match(Modelica.END) - self.state = 298 - self.match(Modelica.IDENT) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Short_class_specifierContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def base_prefix(self): - return self.getTypedRuleContext(Modelica.Base_prefixContext, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def array_subscripts(self): - return self.getTypedRuleContext(Modelica.Array_subscriptsContext, 0) - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def ENUMERATION(self): - return self.getToken(Modelica.ENUMERATION, 0) - - def enumerations(self): - return self.getTypedRuleContext(Modelica.EnumerationsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_short_class_specifier - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterShort_class_specifier"): - listener.enterShort_class_specifier(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitShort_class_specifier"): - listener.exitShort_class_specifier(self) - - def short_class_specifier(self): - localctx = Modelica.Short_class_specifierContext(self, self._ctx, self.state) - self.enterRule(localctx, 12, self.RULE_short_class_specifier) - self._la = 0 # Token type - try: - self.state = 318 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 16, self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 300 - self.match(Modelica.IDENT) - self.state = 301 - self.match(Modelica.EQUAL) - self.state = 302 - self.base_prefix() - self.state = 303 - self.type_specifier() - self.state = 305 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 11: - self.state = 304 - self.array_subscripts() - - self.state = 308 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 7: - self.state = 307 - self.class_modification() - - self.state = 310 - self.description() - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 312 - self.match(Modelica.IDENT) - self.state = 313 - self.match(Modelica.EQUAL) - self.state = 314 - self.match(Modelica.ENUMERATION) - self.state = 315 - self.enumerations() - self.state = 316 - self.description() - pass - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Der_class_specifierContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.IDENT) - else: - return self.getToken(Modelica.IDENT, i) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def DER(self): - return self.getToken(Modelica.DER, 0) - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_der_class_specifier - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterDer_class_specifier"): - listener.enterDer_class_specifier(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitDer_class_specifier"): - listener.exitDer_class_specifier(self) - - def der_class_specifier(self): - localctx = Modelica.Der_class_specifierContext(self, self._ctx, self.state) - self.enterRule(localctx, 14, self.RULE_der_class_specifier) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 320 - self.match(Modelica.IDENT) - self.state = 321 - self.match(Modelica.EQUAL) - self.state = 322 - self.match(Modelica.DER) - self.state = 323 - self.match(Modelica.LPAREN) - self.state = 324 - self.type_specifier() - self.state = 325 - self.match(Modelica.COMMA) - self.state = 326 - self.match(Modelica.IDENT) - self.state = 331 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 327 - self.match(Modelica.COMMA) - self.state = 328 - self.match(Modelica.IDENT) - self.state = 333 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 334 - self.match(Modelica.RPAREN) - self.state = 335 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Base_prefixContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def INPUT(self): - return self.getToken(Modelica.INPUT, 0) - - def OUTPUT(self): - return self.getToken(Modelica.OUTPUT, 0) - - def getRuleIndex(self): - return Modelica.RULE_base_prefix - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterBase_prefix"): - listener.enterBase_prefix(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitBase_prefix"): - listener.exitBase_prefix(self) - - def base_prefix(self): - localctx = Modelica.Base_prefixContext(self, self._ctx, self.state) - self.enterRule(localctx, 16, self.RULE_base_prefix) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 338 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 71 or _la == 72: - self.state = 337 - _la = self._input.LA(1) - if not (_la == 71 or _la == 72): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class EnumerationsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def COLON(self): - return self.getToken(Modelica.COLON, 0) - - def enum_list(self): - return self.getTypedRuleContext(Modelica.Enum_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_enumerations - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEnumerations"): - listener.enterEnumerations(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEnumerations"): - listener.exitEnumerations(self) - - def enumerations(self): - localctx = Modelica.EnumerationsContext(self, self._ctx, self.state) - self.enterRule(localctx, 18, self.RULE_enumerations) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 340 - self.match(Modelica.LPAREN) - self.state = 345 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [8, 93]: - self.state = 342 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 93: - self.state = 341 - self.enum_list() - - pass - elif token in [6]: - self.state = 344 - self.match(Modelica.COLON) - pass - else: - raise NoViableAltException(self) - - self.state = 347 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Enum_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def enumeration_literal(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Enumeration_literalContext) - else: - return self.getTypedRuleContext(Modelica.Enumeration_literalContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_enum_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEnum_list"): - listener.enterEnum_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEnum_list"): - listener.exitEnum_list(self) - - def enum_list(self): - localctx = Modelica.Enum_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 20, self.RULE_enum_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 349 - self.enumeration_literal() - self.state = 354 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 350 - self.match(Modelica.COMMA) - self.state = 351 - self.enumeration_literal() - self.state = 356 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Enumeration_literalContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_enumeration_literal - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEnumeration_literal"): - listener.enterEnumeration_literal(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEnumeration_literal"): - listener.exitEnumeration_literal(self) - - def enumeration_literal(self): - localctx = Modelica.Enumeration_literalContext(self, self._ctx, self.state) - self.enterRule(localctx, 22, self.RULE_enumeration_literal) - try: - self.enterOuterAlt(localctx, 1) - self.state = 357 - self.match(Modelica.IDENT) - self.state = 358 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class CompositionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def initial_element_list(self): - return self.getTypedRuleContext(Modelica.Initial_element_listContext, 0) - - def public_element_list(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Public_element_listContext) - else: - return self.getTypedRuleContext(Modelica.Public_element_listContext, i) - - def protected_element_list(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Protected_element_listContext) - else: - return self.getTypedRuleContext( - Modelica.Protected_element_listContext, i - ) - - def equation_section(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Equation_sectionContext) - else: - return self.getTypedRuleContext(Modelica.Equation_sectionContext, i) - - def algorithm_section(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Algorithm_sectionContext) - else: - return self.getTypedRuleContext(Modelica.Algorithm_sectionContext, i) - - def external_element(self): - return self.getTypedRuleContext(Modelica.External_elementContext, 0) - - def class_annotation(self): - return self.getTypedRuleContext(Modelica.Class_annotationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_composition - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterComposition"): - listener.enterComposition(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitComposition"): - listener.exitComposition(self) - - def composition(self): - localctx = Modelica.CompositionContext(self, self._ctx, self.state) - self.enterRule(localctx, 24, self.RULE_composition) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 360 - self.initial_element_list() - self.state = 367 - self._errHandler.sync(self) - _la = self._input.LA(1) - while (((_la - 62)) & ~0x3F) == 0 and ((1 << (_la - 62)) & 6151) != 0: - self.state = 365 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 22, self._ctx) - if la_ == 1: - self.state = 361 - self.public_element_list() - pass - - elif la_ == 2: - self.state = 362 - self.protected_element_list() - pass - - elif la_ == 3: - self.state = 363 - self.equation_section() - pass - - elif la_ == 4: - self.state = 364 - self.algorithm_section() - pass - - self.state = 369 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 371 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 87: - self.state = 370 - self.external_element() - - self.state = 374 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 86: - self.state = 373 - self.class_annotation() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_annotationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ANNOTATION(self): - return self.getToken(Modelica.ANNOTATION, 0) - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def SEMICOLON(self): - return self.getToken(Modelica.SEMICOLON, 0) - - def getRuleIndex(self): - return Modelica.RULE_class_annotation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_annotation"): - listener.enterClass_annotation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_annotation"): - listener.exitClass_annotation(self) - - def class_annotation(self): - localctx = Modelica.Class_annotationContext(self, self._ctx, self.state) - self.enterRule(localctx, 26, self.RULE_class_annotation) - try: - self.enterOuterAlt(localctx, 1) - self.state = 376 - self.match(Modelica.ANNOTATION) - self.state = 377 - self.class_modification() - self.state = 378 - self.match(Modelica.SEMICOLON) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class External_elementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def EXTERNAL(self): - return self.getToken(Modelica.EXTERNAL, 0) - - def SEMICOLON(self): - return self.getToken(Modelica.SEMICOLON, 0) - - def language_specification(self): - return self.getTypedRuleContext(Modelica.Language_specificationContext, 0) - - def external_function_call(self): - return self.getTypedRuleContext(Modelica.External_function_callContext, 0) - - def annotation(self): - return self.getTypedRuleContext(Modelica.AnnotationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_external_element - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExternal_element"): - listener.enterExternal_element(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExternal_element"): - listener.exitExternal_element(self) - - def external_element(self): - localctx = Modelica.External_elementContext(self, self._ctx, self.state) - self.enterRule(localctx, 28, self.RULE_external_element) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 380 - self.match(Modelica.EXTERNAL) - self.state = 382 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 90: - self.state = 381 - self.language_specification() - - self.state = 385 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 4 or _la == 93: - self.state = 384 - self.external_function_call() - - self.state = 388 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 86: - self.state = 387 - self.annotation() - - self.state = 390 - self.match(Modelica.SEMICOLON) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Language_specificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def STRING(self): - return self.getToken(Modelica.STRING, 0) - - def getRuleIndex(self): - return Modelica.RULE_language_specification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterLanguage_specification"): - listener.enterLanguage_specification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitLanguage_specification"): - listener.exitLanguage_specification(self) - - def language_specification(self): - localctx = Modelica.Language_specificationContext(self, self._ctx, self.state) - self.enterRule(localctx, 30, self.RULE_language_specification) - try: - self.enterOuterAlt(localctx, 1) - self.state = 392 - self.match(Modelica.STRING) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class External_function_callContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def external_function_args(self): - return self.getTypedRuleContext(Modelica.External_function_argsContext, 0) - - def component_reference(self): - return self.getTypedRuleContext(Modelica.Component_referenceContext, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def getRuleIndex(self): - return Modelica.RULE_external_function_call - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExternal_function_call"): - listener.enterExternal_function_call(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExternal_function_call"): - listener.exitExternal_function_call(self) - - def external_function_call(self): - localctx = Modelica.External_function_callContext(self, self._ctx, self.state) - self.enterRule(localctx, 32, self.RULE_external_function_call) - try: - self.enterOuterAlt(localctx, 1) - self.state = 397 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 29, self._ctx) - if la_ == 1: - self.state = 394 - self.component_reference() - self.state = 395 - self.match(Modelica.EQUAL) - - self.state = 399 - self.match(Modelica.IDENT) - self.state = 400 - self.external_function_args() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class External_function_argsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def expression_list(self): - return self.getTypedRuleContext(Modelica.Expression_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_external_function_args - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExternal_function_args"): - listener.enterExternal_function_args(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExternal_function_args"): - listener.exitExternal_function_args(self) - - def external_function_args(self): - localctx = Modelica.External_function_argsContext(self, self._ctx, self.state) - self.enterRule(localctx, 34, self.RULE_external_function_args) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 402 - self.match(Modelica.LPAREN) - self.state = 404 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la) & ~0x3F) == 0 and ((1 << _la) & 6485183534283721360) != 0) or ( - (((_la - 90)) & ~0x3F) == 0 and ((1 << (_la - 90)) & 15) != 0 - ): - self.state = 403 - self.expression_list() - - self.state = 406 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Initial_element_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def element_list(self): - return self.getTypedRuleContext(Modelica.Element_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_initial_element_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterInitial_element_list"): - listener.enterInitial_element_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitInitial_element_list"): - listener.exitInitial_element_list(self) - - def initial_element_list(self): - localctx = Modelica.Initial_element_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 36, self.RULE_initial_element_list) - try: - self.enterOuterAlt(localctx, 1) - self.state = 408 - self.element_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Public_element_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def PUBLIC(self): - return self.getToken(Modelica.PUBLIC, 0) - - def element_list(self): - return self.getTypedRuleContext(Modelica.Element_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_public_element_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterPublic_element_list"): - listener.enterPublic_element_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitPublic_element_list"): - listener.exitPublic_element_list(self) - - def public_element_list(self): - localctx = Modelica.Public_element_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 38, self.RULE_public_element_list) - try: - self.enterOuterAlt(localctx, 1) - self.state = 410 - self.match(Modelica.PUBLIC) - self.state = 411 - self.element_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Protected_element_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def PROTECTED(self): - return self.getToken(Modelica.PROTECTED, 0) - - def element_list(self): - return self.getTypedRuleContext(Modelica.Element_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_protected_element_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterProtected_element_list"): - listener.enterProtected_element_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitProtected_element_list"): - listener.exitProtected_element_list(self) - - def protected_element_list(self): - localctx = Modelica.Protected_element_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 40, self.RULE_protected_element_list) - try: - self.enterOuterAlt(localctx, 1) - self.state = 413 - self.match(Modelica.PROTECTED) - self.state = 414 - self.element_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Element_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def element(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ElementContext) - else: - return self.getTypedRuleContext(Modelica.ElementContext, i) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def getRuleIndex(self): - return Modelica.RULE_element_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement_list"): - listener.enterElement_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement_list"): - listener.exitElement_list(self) - - def element_list(self): - localctx = Modelica.Element_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 42, self.RULE_element_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 421 - self._errHandler.sync(self) - _la = self._input.LA(1) - while (((_la) & ~0x3F) == 0 and ((1 << _la) & 576390383559245840) != 0) or ( - (((_la - 66)) & ~0x3F) == 0 and ((1 << (_la - 66)) & 134733423) != 0 - ): - self.state = 416 - self.element() - self.state = 417 - self.match(Modelica.SEMICOLON) - self.state = 423 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class ElementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def import_clause(self): - return self.getTypedRuleContext(Modelica.Import_clauseContext, 0) - - def extends_clause(self): - return self.getTypedRuleContext(Modelica.Extends_clauseContext, 0) - - def declaration_clause(self): - return self.getTypedRuleContext(Modelica.Declaration_clauseContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_element - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement"): - listener.enterElement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement"): - listener.exitElement(self) - - def element(self): - localctx = Modelica.ElementContext(self, self._ctx, self.state) - self.enterRule(localctx, 44, self.RULE_element) - try: - self.state = 427 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [69]: - self.enterOuterAlt(localctx, 1) - self.state = 424 - self.import_clause() - pass - elif token in [68]: - self.enterOuterAlt(localctx, 2) - self.state = 425 - self.extends_clause() - pass - elif token in [ - 4, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 66, - 67, - 71, - 72, - 75, - 76, - 77, - 78, - 80, - 81, - 82, - 83, - 84, - 93, - ]: - self.enterOuterAlt(localctx, 3) - self.state = 426 - self.declaration_clause() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Import_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IMPORT(self): - return self.getToken(Modelica.IMPORT, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def name(self): - return self.getTypedRuleContext(Modelica.NameContext, 0) - - def DOTSTAR(self): - return self.getToken(Modelica.DOTSTAR, 0) - - def DOT(self): - return self.getToken(Modelica.DOT, 0) - - def LCURLY(self): - return self.getToken(Modelica.LCURLY, 0) - - def import_list(self): - return self.getTypedRuleContext(Modelica.Import_listContext, 0) - - def RCURLY(self): - return self.getToken(Modelica.RCURLY, 0) - - def getRuleIndex(self): - return Modelica.RULE_import_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterImport_clause"): - listener.enterImport_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitImport_clause"): - listener.exitImport_clause(self) - - def import_clause(self): - localctx = Modelica.Import_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 46, self.RULE_import_clause) - try: - self.enterOuterAlt(localctx, 1) - self.state = 429 - self.match(Modelica.IMPORT) - self.state = 442 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 34, self._ctx) - if la_ == 1: - self.state = 430 - self.match(Modelica.IDENT) - self.state = 431 - self.match(Modelica.EQUAL) - self.state = 432 - self.name() - pass - - elif la_ == 2: - self.state = 433 - self.name() - self.state = 440 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [22]: - self.state = 434 - self.match(Modelica.DOTSTAR) - pass - elif token in [4]: - self.state = 435 - self.match(Modelica.DOT) - self.state = 436 - self.match(Modelica.LCURLY) - self.state = 437 - self.import_list() - self.state = 438 - self.match(Modelica.RCURLY) - pass - elif token in [5, 86, 90]: - pass - else: - pass - pass - - self.state = 444 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Import_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.IDENT) - else: - return self.getToken(Modelica.IDENT, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_import_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterImport_list"): - listener.enterImport_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitImport_list"): - listener.exitImport_list(self) - - def import_list(self): - localctx = Modelica.Import_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 48, self.RULE_import_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 446 - self.match(Modelica.IDENT) - self.state = 451 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 447 - self.match(Modelica.COMMA) - self.state = 448 - self.match(Modelica.IDENT) - self.state = 453 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Declaration_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def class_definition(self): - return self.getTypedRuleContext(Modelica.Class_definitionContext, 0) - - def component_clause(self): - return self.getTypedRuleContext(Modelica.Component_clauseContext, 0) - - def REDECLARE(self): - return self.getToken(Modelica.REDECLARE, 0) - - def FINAL(self): - return self.getToken(Modelica.FINAL, 0) - - def INNER(self): - return self.getToken(Modelica.INNER, 0) - - def OUTER(self): - return self.getToken(Modelica.OUTER, 0) - - def REPLACEABLE(self): - return self.getToken(Modelica.REPLACEABLE, 0) - - def constraining_clause(self): - return self.getTypedRuleContext(Modelica.Constraining_clauseContext, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_declaration_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterDeclaration_clause"): - listener.enterDeclaration_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitDeclaration_clause"): - listener.exitDeclaration_clause(self) - - def declaration_clause(self): - localctx = Modelica.Declaration_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 50, self.RULE_declaration_clause) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 455 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 75: - self.state = 454 - self.match(Modelica.REDECLARE) - - self.state = 458 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 66: - self.state = 457 - self.match(Modelica.FINAL) - - self.state = 461 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 76: - self.state = 460 - self.match(Modelica.INNER) - - self.state = 464 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 77: - self.state = 463 - self.match(Modelica.OUTER) - - self.state = 467 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 78: - self.state = 466 - self.match(Modelica.REPLACEABLE) - - self.state = 471 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 67]: - self.state = 469 - self.class_definition() - pass - elif token in [4, 71, 72, 80, 81, 82, 83, 84, 93]: - self.state = 470 - self.component_clause() - pass - else: - raise NoViableAltException(self) - - self.state = 476 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 79: - self.state = 473 - self.constraining_clause() - self.state = 474 - self.description() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Extends_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def EXTENDS(self): - return self.getToken(Modelica.EXTENDS, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def class_or_inheritance_modification(self): - return self.getTypedRuleContext( - Modelica.Class_or_inheritance_modificationContext, 0 - ) - - def annotation(self): - return self.getTypedRuleContext(Modelica.AnnotationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_extends_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExtends_clause"): - listener.enterExtends_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExtends_clause"): - listener.exitExtends_clause(self) - - def extends_clause(self): - localctx = Modelica.Extends_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 52, self.RULE_extends_clause) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 478 - self.match(Modelica.EXTENDS) - self.state = 479 - self.type_specifier() - self.state = 481 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 7: - self.state = 480 - self.class_or_inheritance_modification() - - self.state = 484 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 86: - self.state = 483 - self.annotation() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Constraining_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def CONSTRAINEDBY(self): - return self.getToken(Modelica.CONSTRAINEDBY, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_constraining_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConstraining_clause"): - listener.enterConstraining_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConstraining_clause"): - listener.exitConstraining_clause(self) - - def constraining_clause(self): - localctx = Modelica.Constraining_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 54, self.RULE_constraining_clause) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 486 - self.match(Modelica.CONSTRAINEDBY) - self.state = 487 - self.type_specifier() - self.state = 489 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 7: - self.state = 488 - self.class_modification() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_or_inheritance_modificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def argument_or_inheritance_modification_list(self): - return self.getTypedRuleContext( - Modelica.Argument_or_inheritance_modification_listContext, 0 - ) - - def getRuleIndex(self): - return Modelica.RULE_class_or_inheritance_modification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_or_inheritance_modification"): - listener.enterClass_or_inheritance_modification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_or_inheritance_modification"): - listener.exitClass_or_inheritance_modification(self) - - def class_or_inheritance_modification(self): - localctx = Modelica.Class_or_inheritance_modificationContext( - self, self._ctx, self.state - ) - self.enterRule(localctx, 56, self.RULE_class_or_inheritance_modification) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 491 - self.match(Modelica.LPAREN) - self.state = 493 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la - 44)) & ~0x3F) == 0 and ( - (1 << (_la - 44)) & 565168308224001 - ) != 0: - self.state = 492 - self.argument_or_inheritance_modification_list() - - self.state = 495 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Argument_or_inheritance_modification_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def argument(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ArgumentContext) - else: - return self.getTypedRuleContext(Modelica.ArgumentContext, i) - - def inheritance_modification(self, i: int = None): - if i is None: - return self.getTypedRuleContexts( - Modelica.Inheritance_modificationContext - ) - else: - return self.getTypedRuleContext( - Modelica.Inheritance_modificationContext, i - ) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_argument_or_inheritance_modification_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArgument_or_inheritance_modification_list"): - listener.enterArgument_or_inheritance_modification_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArgument_or_inheritance_modification_list"): - listener.exitArgument_or_inheritance_modification_list(self) - - def argument_or_inheritance_modification_list(self): - localctx = Modelica.Argument_or_inheritance_modification_listContext( - self, self._ctx, self.state - ) - self.enterRule( - localctx, 58, self.RULE_argument_or_inheritance_modification_list - ) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 499 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [66, 75, 78, 85, 93]: - self.state = 497 - self.argument() - pass - elif token in [44]: - self.state = 498 - self.inheritance_modification() - pass - else: - raise NoViableAltException(self) - - self.state = 508 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 501 - self.match(Modelica.COMMA) - self.state = 504 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [66, 75, 78, 85, 93]: - self.state = 502 - self.argument() - pass - elif token in [44]: - self.state = 503 - self.inheritance_modification() - pass - else: - raise NoViableAltException(self) - - self.state = 510 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Inheritance_modificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def BREAK(self): - return self.getToken(Modelica.BREAK, 0) - - def connect_equation(self): - return self.getTypedRuleContext(Modelica.Connect_equationContext, 0) - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def getRuleIndex(self): - return Modelica.RULE_inheritance_modification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterInheritance_modification"): - listener.enterInheritance_modification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitInheritance_modification"): - listener.exitInheritance_modification(self) - - def inheritance_modification(self): - localctx = Modelica.Inheritance_modificationContext(self, self._ctx, self.state) - self.enterRule(localctx, 60, self.RULE_inheritance_modification) - try: - self.enterOuterAlt(localctx, 1) - self.state = 511 - self.match(Modelica.BREAK) - self.state = 514 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [61]: - self.state = 512 - self.connect_equation() - pass - elif token in [93]: - self.state = 513 - self.match(Modelica.IDENT) - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Component_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def type_prefix(self): - return self.getTypedRuleContext(Modelica.Type_prefixContext, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def component_list(self): - return self.getTypedRuleContext(Modelica.Component_listContext, 0) - - def array_subscripts(self): - return self.getTypedRuleContext(Modelica.Array_subscriptsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_component_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterComponent_clause"): - listener.enterComponent_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitComponent_clause"): - listener.exitComponent_clause(self) - - def component_clause(self): - localctx = Modelica.Component_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 62, self.RULE_component_clause) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 516 - self.type_prefix() - self.state = 517 - self.type_specifier() - self.state = 519 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 11: - self.state = 518 - self.array_subscripts() - - self.state = 521 - self.component_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Type_prefixContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def FLOW(self): - return self.getToken(Modelica.FLOW, 0) - - def STREAM(self): - return self.getToken(Modelica.STREAM, 0) - - def DISCRETE(self): - return self.getToken(Modelica.DISCRETE, 0) - - def PARAMETER(self): - return self.getToken(Modelica.PARAMETER, 0) - - def CONSTANT(self): - return self.getToken(Modelica.CONSTANT, 0) - - def INPUT(self): - return self.getToken(Modelica.INPUT, 0) - - def OUTPUT(self): - return self.getToken(Modelica.OUTPUT, 0) - - def getRuleIndex(self): - return Modelica.RULE_type_prefix - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterType_prefix"): - listener.enterType_prefix(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitType_prefix"): - listener.exitType_prefix(self) - - def type_prefix(self): - localctx = Modelica.Type_prefixContext(self, self._ctx, self.state) - self.enterRule(localctx, 64, self.RULE_type_prefix) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 524 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 80 or _la == 81: - self.state = 523 - _la = self._input.LA(1) - if not (_la == 80 or _la == 81): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - - self.state = 527 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la - 82)) & ~0x3F) == 0 and ((1 << (_la - 82)) & 7) != 0: - self.state = 526 - _la = self._input.LA(1) - if not (((((_la - 82)) & ~0x3F) == 0 and ((1 << (_la - 82)) & 7) != 0)): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - - self.state = 530 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 71 or _la == 72: - self.state = 529 - _la = self._input.LA(1) - if not (_la == 71 or _la == 72): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Component_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def component_declaration(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Component_declarationContext) - else: - return self.getTypedRuleContext( - Modelica.Component_declarationContext, i - ) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_component_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterComponent_list"): - listener.enterComponent_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitComponent_list"): - listener.exitComponent_list(self) - - def component_list(self): - localctx = Modelica.Component_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 66, self.RULE_component_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 532 - self.component_declaration() - self.state = 537 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 533 - self.match(Modelica.COMMA) - self.state = 534 - self.component_declaration() - self.state = 539 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Component_declarationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def declaration(self): - return self.getTypedRuleContext(Modelica.DeclarationContext, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def IF(self): - return self.getToken(Modelica.IF, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_component_declaration - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterComponent_declaration"): - listener.enterComponent_declaration(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitComponent_declaration"): - listener.exitComponent_declaration(self) - - def component_declaration(self): - localctx = Modelica.Component_declarationContext(self, self._ctx, self.state) - self.enterRule(localctx, 68, self.RULE_component_declaration) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 540 - self.declaration() - self.state = 543 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 36: - self.state = 541 - self.match(Modelica.IF) - self.state = 542 - self.expression() - - self.state = 545 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class DeclarationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def array_subscripts(self): - return self.getTypedRuleContext(Modelica.Array_subscriptsContext, 0) - - def modification(self): - return self.getTypedRuleContext(Modelica.ModificationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_declaration - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterDeclaration"): - listener.enterDeclaration(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitDeclaration"): - listener.exitDeclaration(self) - - def declaration(self): - localctx = Modelica.DeclarationContext(self, self._ctx, self.state) - self.enterRule(localctx, 70, self.RULE_declaration) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 547 - self.match(Modelica.IDENT) - self.state = 549 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 11: - self.state = 548 - self.array_subscripts() - - self.state = 552 - self._errHandler.sync(self) - _la = self._input.LA(1) - if ((_la) & ~0x3F) == 0 and ((1 << _la) & 24704) != 0: - self.state = 551 - self.modification() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class ModificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def modification_expression(self): - return self.getTypedRuleContext(Modelica.Modification_expressionContext, 0) - - def ASSIGN(self): - return self.getToken(Modelica.ASSIGN, 0) - - def getRuleIndex(self): - return Modelica.RULE_modification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterModification"): - listener.enterModification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitModification"): - listener.exitModification(self) - - def modification(self): - localctx = Modelica.ModificationContext(self, self._ctx, self.state) - self.enterRule(localctx, 72, self.RULE_modification) - self._la = 0 # Token type - try: - self.state = 563 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [7]: - self.enterOuterAlt(localctx, 1) - self.state = 554 - self.class_modification() - self.state = 557 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 13: - self.state = 555 - self.match(Modelica.EQUAL) - self.state = 556 - self.modification_expression() - - pass - elif token in [13]: - self.enterOuterAlt(localctx, 2) - self.state = 559 - self.match(Modelica.EQUAL) - self.state = 560 - self.modification_expression() - pass - elif token in [14]: - self.enterOuterAlt(localctx, 3) - self.state = 561 - self.match(Modelica.ASSIGN) - self.state = 562 - self.modification_expression() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Modification_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def BREAK(self): - return self.getToken(Modelica.BREAK, 0) - - def getRuleIndex(self): - return Modelica.RULE_modification_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterModification_expression"): - listener.enterModification_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitModification_expression"): - listener.exitModification_expression(self) - - def modification_expression(self): - localctx = Modelica.Modification_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 74, self.RULE_modification_expression) - try: - self.state = 567 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [ - 4, - 7, - 9, - 11, - 15, - 16, - 20, - 21, - 31, - 36, - 57, - 59, - 60, - 62, - 90, - 91, - 92, - 93, - ]: - self.enterOuterAlt(localctx, 1) - self.state = 565 - self.expression() - pass - elif token in [44]: - self.enterOuterAlt(localctx, 2) - self.state = 566 - self.match(Modelica.BREAK) - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Class_modificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def argument_list(self): - return self.getTypedRuleContext(Modelica.Argument_listContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_class_modification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterClass_modification"): - listener.enterClass_modification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitClass_modification"): - listener.exitClass_modification(self) - - def class_modification(self): - localctx = Modelica.Class_modificationContext(self, self._ctx, self.state) - self.enterRule(localctx, 76, self.RULE_class_modification) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 569 - self.match(Modelica.LPAREN) - self.state = 571 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la - 66)) & ~0x3F) == 0 and ((1 << (_la - 66)) & 134746625) != 0: - self.state = 570 - self.argument_list() - - self.state = 573 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Argument_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def argument(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ArgumentContext) - else: - return self.getTypedRuleContext(Modelica.ArgumentContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_argument_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArgument_list"): - listener.enterArgument_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArgument_list"): - listener.exitArgument_list(self) - - def argument_list(self): - localctx = Modelica.Argument_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 78, self.RULE_argument_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 575 - self.argument() - self.state = 580 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 576 - self.match(Modelica.COMMA) - self.state = 577 - self.argument() - self.state = 582 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class ArgumentContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def element_modification_or_replaceable(self): - return self.getTypedRuleContext( - Modelica.Element_modification_or_replaceableContext, 0 - ) - - def element_redeclaration(self): - return self.getTypedRuleContext(Modelica.Element_redeclarationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_argument - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArgument"): - listener.enterArgument(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArgument"): - listener.exitArgument(self) - - def argument(self): - localctx = Modelica.ArgumentContext(self, self._ctx, self.state) - self.enterRule(localctx, 80, self.RULE_argument) - try: - self.state = 585 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [66, 78, 85, 93]: - self.enterOuterAlt(localctx, 1) - self.state = 583 - self.element_modification_or_replaceable() - pass - elif token in [75]: - self.enterOuterAlt(localctx, 2) - self.state = 584 - self.element_redeclaration() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Element_modification_or_replaceableContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def element_modification(self): - return self.getTypedRuleContext(Modelica.Element_modificationContext, 0) - - def element_replaceable(self): - return self.getTypedRuleContext(Modelica.Element_replaceableContext, 0) - - def EACH(self): - return self.getToken(Modelica.EACH, 0) - - def FINAL(self): - return self.getToken(Modelica.FINAL, 0) - - def getRuleIndex(self): - return Modelica.RULE_element_modification_or_replaceable - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement_modification_or_replaceable"): - listener.enterElement_modification_or_replaceable(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement_modification_or_replaceable"): - listener.exitElement_modification_or_replaceable(self) - - def element_modification_or_replaceable(self): - localctx = Modelica.Element_modification_or_replaceableContext( - self, self._ctx, self.state - ) - self.enterRule(localctx, 82, self.RULE_element_modification_or_replaceable) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 588 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 85: - self.state = 587 - self.match(Modelica.EACH) - - self.state = 591 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 66: - self.state = 590 - self.match(Modelica.FINAL) - - self.state = 595 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [93]: - self.state = 593 - self.element_modification() - pass - elif token in [78]: - self.state = 594 - self.element_replaceable() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Element_modificationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def name(self): - return self.getTypedRuleContext(Modelica.NameContext, 0) - - def description_string(self): - return self.getTypedRuleContext(Modelica.Description_stringContext, 0) - - def modification(self): - return self.getTypedRuleContext(Modelica.ModificationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_element_modification - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement_modification"): - listener.enterElement_modification(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement_modification"): - listener.exitElement_modification(self) - - def element_modification(self): - localctx = Modelica.Element_modificationContext(self, self._ctx, self.state) - self.enterRule(localctx, 84, self.RULE_element_modification) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 597 - self.name() - self.state = 599 - self._errHandler.sync(self) - _la = self._input.LA(1) - if ((_la) & ~0x3F) == 0 and ((1 << _la) & 24704) != 0: - self.state = 598 - self.modification() - - self.state = 601 - self.description_string() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Element_redeclarationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def REDECLARE(self): - return self.getToken(Modelica.REDECLARE, 0) - - def short_definition(self): - return self.getTypedRuleContext(Modelica.Short_definitionContext, 0) - - def short_component_clause(self): - return self.getTypedRuleContext(Modelica.Short_component_clauseContext, 0) - - def element_replaceable(self): - return self.getTypedRuleContext(Modelica.Element_replaceableContext, 0) - - def EACH(self): - return self.getToken(Modelica.EACH, 0) - - def FINAL(self): - return self.getToken(Modelica.FINAL, 0) - - def getRuleIndex(self): - return Modelica.RULE_element_redeclaration - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement_redeclaration"): - listener.enterElement_redeclaration(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement_redeclaration"): - listener.exitElement_redeclaration(self) - - def element_redeclaration(self): - localctx = Modelica.Element_redeclarationContext(self, self._ctx, self.state) - self.enterRule(localctx, 86, self.RULE_element_redeclaration) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 603 - self.match(Modelica.REDECLARE) - self.state = 605 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 85: - self.state = 604 - self.match(Modelica.EACH) - - self.state = 608 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 66: - self.state = 607 - self.match(Modelica.FINAL) - - self.state = 613 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58]: - self.state = 610 - self.short_definition() - pass - elif token in [4, 71, 72, 80, 81, 82, 83, 84, 93]: - self.state = 611 - self.short_component_clause() - pass - elif token in [78]: - self.state = 612 - self.element_replaceable() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Element_replaceableContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def REPLACEABLE(self): - return self.getToken(Modelica.REPLACEABLE, 0) - - def short_definition(self): - return self.getTypedRuleContext(Modelica.Short_definitionContext, 0) - - def short_component_clause(self): - return self.getTypedRuleContext(Modelica.Short_component_clauseContext, 0) - - def constraining_clause(self): - return self.getTypedRuleContext(Modelica.Constraining_clauseContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_element_replaceable - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElement_replaceable"): - listener.enterElement_replaceable(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElement_replaceable"): - listener.exitElement_replaceable(self) - - def element_replaceable(self): - localctx = Modelica.Element_replaceableContext(self, self._ctx, self.state) - self.enterRule(localctx, 88, self.RULE_element_replaceable) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 615 - self.match(Modelica.REPLACEABLE) - self.state = 618 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58]: - self.state = 616 - self.short_definition() - pass - elif token in [4, 71, 72, 80, 81, 82, 83, 84, 93]: - self.state = 617 - self.short_component_clause() - pass - else: - raise NoViableAltException(self) - - self.state = 621 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 79: - self.state = 620 - self.constraining_clause() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Short_component_clauseContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def type_prefix(self): - return self.getTypedRuleContext(Modelica.Type_prefixContext, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def short_component_declaration(self): - return self.getTypedRuleContext( - Modelica.Short_component_declarationContext, 0 - ) - - def getRuleIndex(self): - return Modelica.RULE_short_component_clause - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterShort_component_clause"): - listener.enterShort_component_clause(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitShort_component_clause"): - listener.exitShort_component_clause(self) - - def short_component_clause(self): - localctx = Modelica.Short_component_clauseContext(self, self._ctx, self.state) - self.enterRule(localctx, 90, self.RULE_short_component_clause) - try: - self.enterOuterAlt(localctx, 1) - self.state = 623 - self.type_prefix() - self.state = 624 - self.type_specifier() - self.state = 625 - self.short_component_declaration() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Short_component_declarationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def declaration(self): - return self.getTypedRuleContext(Modelica.DeclarationContext, 0) - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_short_component_declaration - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterShort_component_declaration"): - listener.enterShort_component_declaration(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitShort_component_declaration"): - listener.exitShort_component_declaration(self) - - def short_component_declaration(self): - localctx = Modelica.Short_component_declarationContext( - self, self._ctx, self.state - ) - self.enterRule(localctx, 92, self.RULE_short_component_declaration) - try: - self.enterOuterAlt(localctx, 1) - self.state = 627 - self.declaration() - self.state = 628 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Short_definitionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def class_prefixes(self): - return self.getTypedRuleContext(Modelica.Class_prefixesContext, 0) - - def short_class_specifier(self): - return self.getTypedRuleContext(Modelica.Short_class_specifierContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_short_definition - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterShort_definition"): - listener.enterShort_definition(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitShort_definition"): - listener.exitShort_definition(self) - - def short_definition(self): - localctx = Modelica.Short_definitionContext(self, self._ctx, self.state) - self.enterRule(localctx, 94, self.RULE_short_definition) - try: - self.enterOuterAlt(localctx, 1) - self.state = 630 - self.class_prefixes() - self.state = 631 - self.short_class_specifier() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Equation_sectionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def EQUATION(self): - return self.getToken(Modelica.EQUATION, 0) - - def equation_list(self): - return self.getTypedRuleContext(Modelica.Equation_listContext, 0) - - def INITIAL(self): - return self.getToken(Modelica.INITIAL, 0) - - def getRuleIndex(self): - return Modelica.RULE_equation_section - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEquation_section"): - listener.enterEquation_section(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEquation_section"): - listener.exitEquation_section(self) - - def equation_section(self): - localctx = Modelica.Equation_sectionContext(self, self._ctx, self.state) - self.enterRule(localctx, 96, self.RULE_equation_section) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 634 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 62: - self.state = 633 - self.match(Modelica.INITIAL) - - self.state = 636 - self.match(Modelica.EQUATION) - self.state = 637 - self.equation_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Algorithm_sectionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ALGORITHM(self): - return self.getToken(Modelica.ALGORITHM, 0) - - def statement_list(self): - return self.getTypedRuleContext(Modelica.Statement_listContext, 0) - - def INITIAL(self): - return self.getToken(Modelica.INITIAL, 0) - - def getRuleIndex(self): - return Modelica.RULE_algorithm_section - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterAlgorithm_section"): - listener.enterAlgorithm_section(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitAlgorithm_section"): - listener.exitAlgorithm_section(self) - - def algorithm_section(self): - localctx = Modelica.Algorithm_sectionContext(self, self._ctx, self.state) - self.enterRule(localctx, 98, self.RULE_algorithm_section) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 640 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 62: - self.state = 639 - self.match(Modelica.INITIAL) - - self.state = 642 - self.match(Modelica.ALGORITHM) - self.state = 643 - self.statement_list() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Equation_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def equation(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.EquationContext) - else: - return self.getTypedRuleContext(Modelica.EquationContext, i) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def getRuleIndex(self): - return Modelica.RULE_equation_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEquation_list"): - listener.enterEquation_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEquation_list"): - listener.exitEquation_list(self) - - def equation_list(self): - localctx = Modelica.Equation_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 100, self.RULE_equation_list) - try: - self.enterOuterAlt(localctx, 1) - self.state = 650 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 76, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: - self.state = 645 - self.equation() - self.state = 646 - self.match(Modelica.SEMICOLON) - self.state = 652 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 76, self._ctx) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Statement_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def statement(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.StatementContext) - else: - return self.getTypedRuleContext(Modelica.StatementContext, i) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def getRuleIndex(self): - return Modelica.RULE_statement_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterStatement_list"): - listener.enterStatement_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitStatement_list"): - listener.exitStatement_list(self) - - def statement_list(self): - localctx = Modelica.Statement_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 102, self.RULE_statement_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 658 - self._errHandler.sync(self) - _la = self._input.LA(1) - while ( - ((_la) & ~0x3F) == 0 and ((1 << _la) & 58377195487376) != 0 - ) or _la == 93: - self.state = 653 - self.statement() - self.state = 654 - self.match(Modelica.SEMICOLON) - self.state = 660 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class EquationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def simple_expression(self): - return self.getTypedRuleContext(Modelica.Simple_expressionContext, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def if_equation(self): - return self.getTypedRuleContext(Modelica.If_equationContext, 0) - - def for_equation(self): - return self.getTypedRuleContext(Modelica.For_equationContext, 0) - - def connect_equation(self): - return self.getTypedRuleContext(Modelica.Connect_equationContext, 0) - - def when_equation(self): - return self.getTypedRuleContext(Modelica.When_equationContext, 0) - - def component_reference(self): - return self.getTypedRuleContext(Modelica.Component_referenceContext, 0) - - def function_call_args(self): - return self.getTypedRuleContext(Modelica.Function_call_argsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_equation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterEquation"): - listener.enterEquation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitEquation"): - listener.exitEquation(self) - - def equation(self): - localctx = Modelica.EquationContext(self, self._ctx, self.state) - self.enterRule(localctx, 104, self.RULE_equation) - try: - self.enterOuterAlt(localctx, 1) - self.state = 672 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 78, self._ctx) - if la_ == 1: - self.state = 661 - self.simple_expression() - self.state = 662 - self.match(Modelica.EQUAL) - self.state = 663 - self.expression() - pass - - elif la_ == 2: - self.state = 665 - self.if_equation() - pass - - elif la_ == 3: - self.state = 666 - self.for_equation() - pass - - elif la_ == 4: - self.state = 667 - self.connect_equation() - pass - - elif la_ == 5: - self.state = 668 - self.when_equation() - pass - - elif la_ == 6: - self.state = 669 - self.component_reference() - self.state = 670 - self.function_call_args() - pass - - self.state = 674 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class StatementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def description(self): - return self.getTypedRuleContext(Modelica.DescriptionContext, 0) - - def component_reference(self): - return self.getTypedRuleContext(Modelica.Component_referenceContext, 0) - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def output_expression_list(self): - return self.getTypedRuleContext(Modelica.Output_expression_listContext, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def ASSIGN(self): - return self.getToken(Modelica.ASSIGN, 0) - - def function_call_args(self): - return self.getTypedRuleContext(Modelica.Function_call_argsContext, 0) - - def BREAK(self): - return self.getToken(Modelica.BREAK, 0) - - def RETURN(self): - return self.getToken(Modelica.RETURN, 0) - - def if_statement(self): - return self.getTypedRuleContext(Modelica.If_statementContext, 0) - - def for_statement(self): - return self.getTypedRuleContext(Modelica.For_statementContext, 0) - - def while_statement(self): - return self.getTypedRuleContext(Modelica.While_statementContext, 0) - - def when_statement(self): - return self.getTypedRuleContext(Modelica.When_statementContext, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_statement - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterStatement"): - listener.enterStatement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitStatement"): - listener.exitStatement(self) - - def statement(self): - localctx = Modelica.StatementContext(self, self._ctx, self.state) - self.enterRule(localctx, 106, self.RULE_statement) - try: - self.enterOuterAlt(localctx, 1) - self.state = 695 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [4, 93]: - self.state = 676 - self.component_reference() - self.state = 680 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [14]: - self.state = 677 - self.match(Modelica.ASSIGN) - self.state = 678 - self.expression() - pass - elif token in [7]: - self.state = 679 - self.function_call_args() - pass - else: - raise NoViableAltException(self) - - pass - elif token in [7]: - self.state = 682 - self.match(Modelica.LPAREN) - self.state = 683 - self.output_expression_list() - self.state = 684 - self.match(Modelica.RPAREN) - self.state = 685 - self.match(Modelica.ASSIGN) - self.state = 686 - self.component_reference() - self.state = 687 - self.function_call_args() - pass - elif token in [44]: - self.state = 689 - self.match(Modelica.BREAK) - pass - elif token in [45]: - self.state = 690 - self.match(Modelica.RETURN) - pass - elif token in [36]: - self.state = 691 - self.if_statement() - pass - elif token in [35]: - self.state = 692 - self.for_statement() - pass - elif token in [42]: - self.state = 693 - self.while_statement() - pass - elif token in [40]: - self.state = 694 - self.when_statement() - pass - else: - raise NoViableAltException(self) - - self.state = 697 - self.description() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class If_equationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def if_branch(self): - return self.getTypedRuleContext(Modelica.If_branchContext, 0) - - def conditional_equations(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Conditional_equationsContext) - else: - return self.getTypedRuleContext( - Modelica.Conditional_equationsContext, i - ) - - def END(self): - return self.getToken(Modelica.END, 0) - - def IF(self): - return self.getToken(Modelica.IF, 0) - - def elseif_branch(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Elseif_branchContext) - else: - return self.getTypedRuleContext(Modelica.Elseif_branchContext, i) - - def else_branch(self): - return self.getTypedRuleContext(Modelica.Else_branchContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_if_equation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterIf_equation"): - listener.enterIf_equation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitIf_equation"): - listener.exitIf_equation(self) - - def if_equation(self): - localctx = Modelica.If_equationContext(self, self._ctx, self.state) - self.enterRule(localctx, 108, self.RULE_if_equation) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 699 - self.if_branch() - self.state = 700 - self.conditional_equations() - self.state = 706 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 38: - self.state = 701 - self.elseif_branch() - self.state = 702 - self.conditional_equations() - self.state = 708 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 712 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 37: - self.state = 709 - self.else_branch() - self.state = 710 - self.conditional_equations() - - self.state = 714 - self.match(Modelica.END) - self.state = 715 - self.match(Modelica.IF) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Conditional_equationsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def equation(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.EquationContext) - else: - return self.getTypedRuleContext(Modelica.EquationContext, i) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def getRuleIndex(self): - return Modelica.RULE_conditional_equations - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConditional_equations"): - listener.enterConditional_equations(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConditional_equations"): - listener.exitConditional_equations(self) - - def conditional_equations(self): - localctx = Modelica.Conditional_equationsContext(self, self._ctx, self.state) - self.enterRule(localctx, 110, self.RULE_conditional_equations) - try: - self.enterOuterAlt(localctx, 1) - self.state = 722 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 83, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: - self.state = 717 - self.equation() - self.state = 718 - self.match(Modelica.SEMICOLON) - self.state = 724 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 83, self._ctx) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class If_statementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def if_branch(self): - return self.getTypedRuleContext(Modelica.If_branchContext, 0) - - def conditional_statements(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Conditional_statementsContext) - else: - return self.getTypedRuleContext( - Modelica.Conditional_statementsContext, i - ) - - def END(self): - return self.getToken(Modelica.END, 0) - - def IF(self): - return self.getToken(Modelica.IF, 0) - - def elseif_branch(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Elseif_branchContext) - else: - return self.getTypedRuleContext(Modelica.Elseif_branchContext, i) - - def else_branch(self): - return self.getTypedRuleContext(Modelica.Else_branchContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_if_statement - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterIf_statement"): - listener.enterIf_statement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitIf_statement"): - listener.exitIf_statement(self) - - def if_statement(self): - localctx = Modelica.If_statementContext(self, self._ctx, self.state) - self.enterRule(localctx, 112, self.RULE_if_statement) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 725 - self.if_branch() - self.state = 726 - self.conditional_statements() - self.state = 732 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 38: - self.state = 727 - self.elseif_branch() - self.state = 728 - self.conditional_statements() - self.state = 734 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 738 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 37: - self.state = 735 - self.else_branch() - self.state = 736 - self.conditional_statements() - - self.state = 740 - self.match(Modelica.END) - self.state = 741 - self.match(Modelica.IF) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class If_branchContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IF(self): - return self.getToken(Modelica.IF, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_if_branch - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterIf_branch"): - listener.enterIf_branch(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitIf_branch"): - listener.exitIf_branch(self) - - def if_branch(self): - localctx = Modelica.If_branchContext(self, self._ctx, self.state) - self.enterRule(localctx, 114, self.RULE_if_branch) - try: - self.enterOuterAlt(localctx, 1) - self.state = 743 - self.match(Modelica.IF) - self.state = 744 - self.expression() - self.state = 745 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Elseif_branchContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ELSEIF(self): - return self.getToken(Modelica.ELSEIF, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_elseif_branch - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElseif_branch"): - listener.enterElseif_branch(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElseif_branch"): - listener.exitElseif_branch(self) - - def elseif_branch(self): - localctx = Modelica.Elseif_branchContext(self, self._ctx, self.state) - self.enterRule(localctx, 116, self.RULE_elseif_branch) - try: - self.enterOuterAlt(localctx, 1) - self.state = 747 - self.match(Modelica.ELSEIF) - self.state = 748 - self.expression() - self.state = 749 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Else_branchContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ELSE(self): - return self.getToken(Modelica.ELSE, 0) - - def getRuleIndex(self): - return Modelica.RULE_else_branch - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElse_branch"): - listener.enterElse_branch(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElse_branch"): - listener.exitElse_branch(self) - - def else_branch(self): - localctx = Modelica.Else_branchContext(self, self._ctx, self.state) - self.enterRule(localctx, 118, self.RULE_else_branch) - try: - self.enterOuterAlt(localctx, 1) - self.state = 751 - self.match(Modelica.ELSE) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Conditional_statementsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def statement(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.StatementContext) - else: - return self.getTypedRuleContext(Modelica.StatementContext, i) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def getRuleIndex(self): - return Modelica.RULE_conditional_statements - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConditional_statements"): - listener.enterConditional_statements(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConditional_statements"): - listener.exitConditional_statements(self) - - def conditional_statements(self): - localctx = Modelica.Conditional_statementsContext(self, self._ctx, self.state) - self.enterRule(localctx, 120, self.RULE_conditional_statements) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 758 - self._errHandler.sync(self) - _la = self._input.LA(1) - while ( - ((_la) & ~0x3F) == 0 and ((1 << _la) & 58377195487376) != 0 - ) or _la == 93: - self.state = 753 - self.statement() - self.state = 754 - self.match(Modelica.SEMICOLON) - self.state = 760 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class For_equationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def FOR(self, i: int = None): - if i is None: - return self.getTokens(Modelica.FOR) - else: - return self.getToken(Modelica.FOR, i) - - def for_indices(self): - return self.getTypedRuleContext(Modelica.For_indicesContext, 0) - - def LOOP(self): - return self.getToken(Modelica.LOOP, 0) - - def conditional_equations(self): - return self.getTypedRuleContext(Modelica.Conditional_equationsContext, 0) - - def END(self): - return self.getToken(Modelica.END, 0) - - def getRuleIndex(self): - return Modelica.RULE_for_equation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFor_equation"): - listener.enterFor_equation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFor_equation"): - listener.exitFor_equation(self) - - def for_equation(self): - localctx = Modelica.For_equationContext(self, self._ctx, self.state) - self.enterRule(localctx, 122, self.RULE_for_equation) - try: - self.enterOuterAlt(localctx, 1) - self.state = 761 - self.match(Modelica.FOR) - self.state = 762 - self.for_indices() - self.state = 763 - self.match(Modelica.LOOP) - self.state = 764 - self.conditional_equations() - self.state = 765 - self.match(Modelica.END) - self.state = 766 - self.match(Modelica.FOR) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class For_statementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def FOR(self, i: int = None): - if i is None: - return self.getTokens(Modelica.FOR) - else: - return self.getToken(Modelica.FOR, i) - - def for_indices(self): - return self.getTypedRuleContext(Modelica.For_indicesContext, 0) - - def LOOP(self): - return self.getToken(Modelica.LOOP, 0) - - def conditional_statements(self): - return self.getTypedRuleContext(Modelica.Conditional_statementsContext, 0) - - def END(self): - return self.getToken(Modelica.END, 0) - - def getRuleIndex(self): - return Modelica.RULE_for_statement - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFor_statement"): - listener.enterFor_statement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFor_statement"): - listener.exitFor_statement(self) - - def for_statement(self): - localctx = Modelica.For_statementContext(self, self._ctx, self.state) - self.enterRule(localctx, 124, self.RULE_for_statement) - try: - self.enterOuterAlt(localctx, 1) - self.state = 768 - self.match(Modelica.FOR) - self.state = 769 - self.for_indices() - self.state = 770 - self.match(Modelica.LOOP) - self.state = 771 - self.conditional_statements() - self.state = 772 - self.match(Modelica.END) - self.state = 773 - self.match(Modelica.FOR) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class For_indicesContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def for_index(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.For_indexContext) - else: - return self.getTypedRuleContext(Modelica.For_indexContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_for_indices - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFor_indices"): - listener.enterFor_indices(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFor_indices"): - listener.exitFor_indices(self) - - def for_indices(self): - localctx = Modelica.For_indicesContext(self, self._ctx, self.state) - self.enterRule(localctx, 126, self.RULE_for_indices) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 775 - self.for_index() - self.state = 780 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 776 - self.match(Modelica.COMMA) - self.state = 777 - self.for_index() - self.state = 782 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class For_indexContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def IN(self): - return self.getToken(Modelica.IN, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_for_index - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFor_index"): - listener.enterFor_index(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFor_index"): - listener.exitFor_index(self) - - def for_index(self): - localctx = Modelica.For_indexContext(self, self._ctx, self.state) - self.enterRule(localctx, 128, self.RULE_for_index) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 783 - self.match(Modelica.IDENT) - self.state = 786 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 34: - self.state = 784 - self.match(Modelica.IN) - self.state = 785 - self.expression() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class While_statementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def WHILE(self, i: int = None): - if i is None: - return self.getTokens(Modelica.WHILE) - else: - return self.getToken(Modelica.WHILE, i) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def LOOP(self): - return self.getToken(Modelica.LOOP, 0) - - def conditional_statements(self): - return self.getTypedRuleContext(Modelica.Conditional_statementsContext, 0) - - def END(self): - return self.getToken(Modelica.END, 0) - - def getRuleIndex(self): - return Modelica.RULE_while_statement - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterWhile_statement"): - listener.enterWhile_statement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitWhile_statement"): - listener.exitWhile_statement(self) - - def while_statement(self): - localctx = Modelica.While_statementContext(self, self._ctx, self.state) - self.enterRule(localctx, 130, self.RULE_while_statement) - try: - self.enterOuterAlt(localctx, 1) - self.state = 788 - self.match(Modelica.WHILE) - self.state = 789 - self.expression() - self.state = 790 - self.match(Modelica.LOOP) - self.state = 791 - self.conditional_statements() - self.state = 792 - self.match(Modelica.END) - self.state = 793 - self.match(Modelica.WHILE) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class When_equationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def when_branch(self): - return self.getTypedRuleContext(Modelica.When_branchContext, 0) - - def conditional_equations(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Conditional_equationsContext) - else: - return self.getTypedRuleContext( - Modelica.Conditional_equationsContext, i - ) - - def END(self): - return self.getToken(Modelica.END, 0) - - def WHEN(self): - return self.getToken(Modelica.WHEN, 0) - - def elsewhen_branch(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Elsewhen_branchContext) - else: - return self.getTypedRuleContext(Modelica.Elsewhen_branchContext, i) - - def getRuleIndex(self): - return Modelica.RULE_when_equation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterWhen_equation"): - listener.enterWhen_equation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitWhen_equation"): - listener.exitWhen_equation(self) - - def when_equation(self): - localctx = Modelica.When_equationContext(self, self._ctx, self.state) - self.enterRule(localctx, 132, self.RULE_when_equation) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 795 - self.when_branch() - self.state = 796 - self.conditional_equations() - self.state = 802 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 41: - self.state = 797 - self.elsewhen_branch() - self.state = 798 - self.conditional_equations() - self.state = 804 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 805 - self.match(Modelica.END) - self.state = 806 - self.match(Modelica.WHEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class When_statementContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def when_branch(self): - return self.getTypedRuleContext(Modelica.When_branchContext, 0) - - def conditional_statements(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Conditional_statementsContext) - else: - return self.getTypedRuleContext( - Modelica.Conditional_statementsContext, i - ) - - def END(self): - return self.getToken(Modelica.END, 0) - - def WHEN(self): - return self.getToken(Modelica.WHEN, 0) - - def elsewhen_branch(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Elsewhen_branchContext) - else: - return self.getTypedRuleContext(Modelica.Elsewhen_branchContext, i) - - def getRuleIndex(self): - return Modelica.RULE_when_statement - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterWhen_statement"): - listener.enterWhen_statement(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitWhen_statement"): - listener.exitWhen_statement(self) - - def when_statement(self): - localctx = Modelica.When_statementContext(self, self._ctx, self.state) - self.enterRule(localctx, 134, self.RULE_when_statement) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 808 - self.when_branch() - self.state = 809 - self.conditional_statements() - self.state = 815 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 41: - self.state = 810 - self.elsewhen_branch() - self.state = 811 - self.conditional_statements() - self.state = 817 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 818 - self.match(Modelica.END) - self.state = 819 - self.match(Modelica.WHEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class When_branchContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def WHEN(self): - return self.getToken(Modelica.WHEN, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_when_branch - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterWhen_branch"): - listener.enterWhen_branch(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitWhen_branch"): - listener.exitWhen_branch(self) - - def when_branch(self): - localctx = Modelica.When_branchContext(self, self._ctx, self.state) - self.enterRule(localctx, 136, self.RULE_when_branch) - try: - self.enterOuterAlt(localctx, 1) - self.state = 821 - self.match(Modelica.WHEN) - self.state = 822 - self.expression() - self.state = 823 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Elsewhen_branchContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ELSEWHEN(self): - return self.getToken(Modelica.ELSEWHEN, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_elsewhen_branch - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElsewhen_branch"): - listener.enterElsewhen_branch(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElsewhen_branch"): - listener.exitElsewhen_branch(self) - - def elsewhen_branch(self): - localctx = Modelica.Elsewhen_branchContext(self, self._ctx, self.state) - self.enterRule(localctx, 138, self.RULE_elsewhen_branch) - try: - self.enterOuterAlt(localctx, 1) - self.state = 825 - self.match(Modelica.ELSEWHEN) - self.state = 826 - self.expression() - self.state = 827 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Connect_equationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def CONNECT(self): - return self.getToken(Modelica.CONNECT, 0) - - def connected_components(self): - return self.getTypedRuleContext(Modelica.Connected_componentsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_connect_equation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConnect_equation"): - listener.enterConnect_equation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConnect_equation"): - listener.exitConnect_equation(self) - - def connect_equation(self): - localctx = Modelica.Connect_equationContext(self, self._ctx, self.state) - self.enterRule(localctx, 140, self.RULE_connect_equation) - try: - self.enterOuterAlt(localctx, 1) - self.state = 829 - self.match(Modelica.CONNECT) - self.state = 830 - self.connected_components() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Connected_componentsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def component_reference(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Component_referenceContext) - else: - return self.getTypedRuleContext(Modelica.Component_referenceContext, i) - - def COMMA(self): - return self.getToken(Modelica.COMMA, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def getRuleIndex(self): - return Modelica.RULE_connected_components - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConnected_components"): - listener.enterConnected_components(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConnected_components"): - listener.exitConnected_components(self) - - def connected_components(self): - localctx = Modelica.Connected_componentsContext(self, self._ctx, self.state) - self.enterRule(localctx, 142, self.RULE_connected_components) - try: - self.enterOuterAlt(localctx, 1) - self.state = 832 - self.match(Modelica.LPAREN) - self.state = 833 - self.component_reference() - self.state = 834 - self.match(Modelica.COMMA) - self.state = 835 - self.component_reference() - self.state = 836 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class ExpressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def simple_expression(self): - return self.getTypedRuleContext(Modelica.Simple_expressionContext, 0) - - def if_expression(self): - return self.getTypedRuleContext(Modelica.If_expressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExpression"): - listener.enterExpression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExpression"): - listener.exitExpression(self) - - def expression(self): - localctx = Modelica.ExpressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 144, self.RULE_expression) - try: - self.state = 840 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [ - 4, - 7, - 9, - 11, - 15, - 16, - 20, - 21, - 31, - 57, - 59, - 60, - 62, - 90, - 91, - 92, - 93, - ]: - self.enterOuterAlt(localctx, 1) - self.state = 838 - self.simple_expression() - pass - elif token in [36]: - self.enterOuterAlt(localctx, 2) - self.state = 839 - self.if_expression() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class If_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def if_eval(self): - return self.getTypedRuleContext(Modelica.If_evalContext, 0) - - def conditional_expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Conditional_expressionContext) - else: - return self.getTypedRuleContext( - Modelica.Conditional_expressionContext, i - ) - - def else_eval(self): - return self.getTypedRuleContext(Modelica.Else_evalContext, 0) - - def elseif_eval(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Elseif_evalContext) - else: - return self.getTypedRuleContext(Modelica.Elseif_evalContext, i) - - def getRuleIndex(self): - return Modelica.RULE_if_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterIf_expression"): - listener.enterIf_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitIf_expression"): - listener.exitIf_expression(self) - - def if_expression(self): - localctx = Modelica.If_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 146, self.RULE_if_expression) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 842 - self.if_eval() - self.state = 843 - self.conditional_expression() - self.state = 849 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 38: - self.state = 844 - self.elseif_eval() - self.state = 845 - self.conditional_expression() - self.state = 851 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 852 - self.else_eval() - self.state = 853 - self.conditional_expression() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class If_evalContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IF(self): - return self.getToken(Modelica.IF, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_if_eval - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterIf_eval"): - listener.enterIf_eval(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitIf_eval"): - listener.exitIf_eval(self) - - def if_eval(self): - localctx = Modelica.If_evalContext(self, self._ctx, self.state) - self.enterRule(localctx, 148, self.RULE_if_eval) - try: - self.enterOuterAlt(localctx, 1) - self.state = 855 - self.match(Modelica.IF) - self.state = 856 - self.expression() - self.state = 857 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Elseif_evalContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ELSEIF(self): - return self.getToken(Modelica.ELSEIF, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def THEN(self): - return self.getToken(Modelica.THEN, 0) - - def getRuleIndex(self): - return Modelica.RULE_elseif_eval - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElseif_eval"): - listener.enterElseif_eval(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElseif_eval"): - listener.exitElseif_eval(self) - - def elseif_eval(self): - localctx = Modelica.Elseif_evalContext(self, self._ctx, self.state) - self.enterRule(localctx, 150, self.RULE_elseif_eval) - try: - self.enterOuterAlt(localctx, 1) - self.state = 859 - self.match(Modelica.ELSEIF) - self.state = 860 - self.expression() - self.state = 861 - self.match(Modelica.THEN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Else_evalContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ELSE(self): - return self.getToken(Modelica.ELSE, 0) - - def getRuleIndex(self): - return Modelica.RULE_else_eval - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterElse_eval"): - listener.enterElse_eval(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitElse_eval"): - listener.exitElse_eval(self) - - def else_eval(self): - localctx = Modelica.Else_evalContext(self, self._ctx, self.state) - self.enterRule(localctx, 152, self.RULE_else_eval) - try: - self.enterOuterAlt(localctx, 1) - self.state = 863 - self.match(Modelica.ELSE) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Conditional_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_conditional_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterConditional_expression"): - listener.enterConditional_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitConditional_expression"): - listener.exitConditional_expression(self) - - def conditional_expression(self): - localctx = Modelica.Conditional_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 154, self.RULE_conditional_expression) - try: - self.enterOuterAlt(localctx, 1) - self.state = 865 - self.expression() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Simple_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def logical_expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Logical_expressionContext) - else: - return self.getTypedRuleContext(Modelica.Logical_expressionContext, i) - - def COLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COLON) - else: - return self.getToken(Modelica.COLON, i) - - def getRuleIndex(self): - return Modelica.RULE_simple_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterSimple_expression"): - listener.enterSimple_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitSimple_expression"): - listener.exitSimple_expression(self) - - def simple_expression(self): - localctx = Modelica.Simple_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 156, self.RULE_simple_expression) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 867 - self.logical_expression() - self.state = 874 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 6: - self.state = 868 - self.match(Modelica.COLON) - self.state = 869 - self.logical_expression() - self.state = 872 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 6: - self.state = 870 - self.match(Modelica.COLON) - self.state = 871 - self.logical_expression() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Logical_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def logical_term(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Logical_termContext) - else: - return self.getTypedRuleContext(Modelica.Logical_termContext, i) - - def or_operator(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Or_operatorContext) - else: - return self.getTypedRuleContext(Modelica.Or_operatorContext, i) - - def getRuleIndex(self): - return Modelica.RULE_logical_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterLogical_expression"): - listener.enterLogical_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitLogical_expression"): - listener.exitLogical_expression(self) - - def logical_expression(self): - localctx = Modelica.Logical_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 158, self.RULE_logical_expression) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 876 - self.logical_term() - self.state = 882 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 33: - self.state = 877 - self.or_operator() - self.state = 878 - self.logical_term() - self.state = 884 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Or_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def OR(self): - return self.getToken(Modelica.OR, 0) - - def getRuleIndex(self): - return Modelica.RULE_or_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterOr_operator"): - listener.enterOr_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitOr_operator"): - listener.exitOr_operator(self) - - def or_operator(self): - localctx = Modelica.Or_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 160, self.RULE_or_operator) - try: - self.enterOuterAlt(localctx, 1) - self.state = 885 - self.match(Modelica.OR) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Logical_termContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def logical_factor(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Logical_factorContext) - else: - return self.getTypedRuleContext(Modelica.Logical_factorContext, i) - - def and_operator(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.And_operatorContext) - else: - return self.getTypedRuleContext(Modelica.And_operatorContext, i) - - def getRuleIndex(self): - return Modelica.RULE_logical_term - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterLogical_term"): - listener.enterLogical_term(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitLogical_term"): - listener.exitLogical_term(self) - - def logical_term(self): - localctx = Modelica.Logical_termContext(self, self._ctx, self.state) - self.enterRule(localctx, 162, self.RULE_logical_term) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 887 - self.logical_factor() - self.state = 893 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 32: - self.state = 888 - self.and_operator() - self.state = 889 - self.logical_factor() - self.state = 895 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class And_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def AND(self): - return self.getToken(Modelica.AND, 0) - - def getRuleIndex(self): - return Modelica.RULE_and_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterAnd_operator"): - listener.enterAnd_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitAnd_operator"): - listener.exitAnd_operator(self) - - def and_operator(self): - localctx = Modelica.And_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 164, self.RULE_and_operator) - try: - self.enterOuterAlt(localctx, 1) - self.state = 896 - self.match(Modelica.AND) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Logical_factorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def relation(self): - return self.getTypedRuleContext(Modelica.RelationContext, 0) - - def NOT(self): - return self.getToken(Modelica.NOT, 0) - - def getRuleIndex(self): - return Modelica.RULE_logical_factor - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterLogical_factor"): - listener.enterLogical_factor(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitLogical_factor"): - listener.exitLogical_factor(self) - - def logical_factor(self): - localctx = Modelica.Logical_factorContext(self, self._ctx, self.state) - self.enterRule(localctx, 166, self.RULE_logical_factor) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 899 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 31: - self.state = 898 - self.match(Modelica.NOT) - - self.state = 901 - self.relation() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class RelationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def arithmetic_expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Arithmetic_expressionContext) - else: - return self.getTypedRuleContext( - Modelica.Arithmetic_expressionContext, i - ) - - def relational_operator(self): - return self.getTypedRuleContext(Modelica.Relational_operatorContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_relation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterRelation"): - listener.enterRelation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitRelation"): - listener.exitRelation(self) - - def relation(self): - localctx = Modelica.RelationContext(self, self._ctx, self.state) - self.enterRule(localctx, 168, self.RULE_relation) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 903 - self.arithmetic_expression() - self.state = 907 - self._errHandler.sync(self) - _la = self._input.LA(1) - if ((_la) & ~0x3F) == 0 and ((1 << _la) & 2113929216) != 0: - self.state = 904 - self.relational_operator() - self.state = 905 - self.arithmetic_expression() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Relational_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def GRE(self): - return self.getToken(Modelica.GRE, 0) - - def GEQ(self): - return self.getToken(Modelica.GEQ, 0) - - def LES(self): - return self.getToken(Modelica.LES, 0) - - def LEQ(self): - return self.getToken(Modelica.LEQ, 0) - - def NEQ(self): - return self.getToken(Modelica.NEQ, 0) - - def EEQ(self): - return self.getToken(Modelica.EEQ, 0) - - def getRuleIndex(self): - return Modelica.RULE_relational_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterRelational_operator"): - listener.enterRelational_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitRelational_operator"): - listener.exitRelational_operator(self) - - def relational_operator(self): - localctx = Modelica.Relational_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 170, self.RULE_relational_operator) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 909 - _la = self._input.LA(1) - if not ((((_la) & ~0x3F) == 0 and ((1 << _la) & 2113929216) != 0)): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Arithmetic_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def term(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.TermContext) - else: - return self.getTypedRuleContext(Modelica.TermContext, i) - - def add_operator(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Add_operatorContext) - else: - return self.getTypedRuleContext(Modelica.Add_operatorContext, i) - - def getRuleIndex(self): - return Modelica.RULE_arithmetic_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArithmetic_expression"): - listener.enterArithmetic_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArithmetic_expression"): - listener.exitArithmetic_expression(self) - - def arithmetic_expression(self): - localctx = Modelica.Arithmetic_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 172, self.RULE_arithmetic_expression) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 911 - self.term() - self.state = 917 - self._errHandler.sync(self) - _la = self._input.LA(1) - while ((_la) & ~0x3F) == 0 and ((1 << _la) & 3244032) != 0: - self.state = 912 - self.add_operator() - self.state = 913 - self.term() - self.state = 919 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Unary_expressionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def add_operator(self): - return self.getTypedRuleContext(Modelica.Add_operatorContext, 0) - - def unary_operand(self): - return self.getTypedRuleContext(Modelica.Unary_operandContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_unary_expression - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterUnary_expression"): - listener.enterUnary_expression(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitUnary_expression"): - listener.exitUnary_expression(self) - - def unary_expression(self): - localctx = Modelica.Unary_expressionContext(self, self._ctx, self.state) - self.enterRule(localctx, 174, self.RULE_unary_expression) - try: - self.enterOuterAlt(localctx, 1) - self.state = 920 - self.add_operator() - self.state = 921 - self.unary_operand() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Unary_operandContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def primary(self): - return self.getTypedRuleContext(Modelica.PrimaryContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_unary_operand - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterUnary_operand"): - listener.enterUnary_operand(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitUnary_operand"): - listener.exitUnary_operand(self) - - def unary_operand(self): - localctx = Modelica.Unary_operandContext(self, self._ctx, self.state) - self.enterRule(localctx, 176, self.RULE_unary_operand) - try: - self.enterOuterAlt(localctx, 1) - self.state = 923 - self.primary() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Add_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def PLUS(self): - return self.getToken(Modelica.PLUS, 0) - - def MINUS(self): - return self.getToken(Modelica.MINUS, 0) - - def DOTPLUS(self): - return self.getToken(Modelica.DOTPLUS, 0) - - def DOTMINUS(self): - return self.getToken(Modelica.DOTMINUS, 0) - - def getRuleIndex(self): - return Modelica.RULE_add_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterAdd_operator"): - listener.enterAdd_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitAdd_operator"): - listener.exitAdd_operator(self) - - def add_operator(self): - localctx = Modelica.Add_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 178, self.RULE_add_operator) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 925 - _la = self._input.LA(1) - if not ((((_la) & ~0x3F) == 0 and ((1 << _la) & 3244032) != 0)): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class TermContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def factor(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.FactorContext) - else: - return self.getTypedRuleContext(Modelica.FactorContext, i) - - def mul_operator(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Mul_operatorContext) - else: - return self.getTypedRuleContext(Modelica.Mul_operatorContext, i) - - def getRuleIndex(self): - return Modelica.RULE_term - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterTerm"): - listener.enterTerm(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitTerm"): - listener.exitTerm(self) - - def term(self): - localctx = Modelica.TermContext(self, self._ctx, self.state) - self.enterRule(localctx, 180, self.RULE_term) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 927 - self.factor() - self.state = 933 - self._errHandler.sync(self) - _la = self._input.LA(1) - while ((_la) & ~0x3F) == 0 and ((1 << _la) & 12976128) != 0: - self.state = 928 - self.mul_operator() - self.state = 929 - self.factor() - self.state = 935 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Mul_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def STAR(self): - return self.getToken(Modelica.STAR, 0) - - def SLASH(self): - return self.getToken(Modelica.SLASH, 0) - - def DOTSTAR(self): - return self.getToken(Modelica.DOTSTAR, 0) - - def DOTSLASH(self): - return self.getToken(Modelica.DOTSLASH, 0) - - def getRuleIndex(self): - return Modelica.RULE_mul_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterMul_operator"): - listener.enterMul_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitMul_operator"): - listener.exitMul_operator(self) - - def mul_operator(self): - localctx = Modelica.Mul_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 182, self.RULE_mul_operator) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 936 - _la = self._input.LA(1) - if not ((((_la) & ~0x3F) == 0 and ((1 << _la) & 12976128) != 0)): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class FactorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def primary(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.PrimaryContext) - else: - return self.getTypedRuleContext(Modelica.PrimaryContext, i) - - def exp_operator(self): - return self.getTypedRuleContext(Modelica.Exp_operatorContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_factor - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFactor"): - listener.enterFactor(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFactor"): - listener.exitFactor(self) - - def factor(self): - localctx = Modelica.FactorContext(self, self._ctx, self.state) - self.enterRule(localctx, 184, self.RULE_factor) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 938 - self.primary() - self.state = 942 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 19 or _la == 24: - self.state = 939 - self.exp_operator() - self.state = 940 - self.primary() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Exp_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def FLEX(self): - return self.getToken(Modelica.FLEX, 0) - - def DOTFLEX(self): - return self.getToken(Modelica.DOTFLEX, 0) - - def getRuleIndex(self): - return Modelica.RULE_exp_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExp_operator"): - listener.enterExp_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExp_operator"): - listener.exitExp_operator(self) - - def exp_operator(self): - localctx = Modelica.Exp_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 186, self.RULE_exp_operator) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 944 - _la = self._input.LA(1) - if not (_la == 19 or _la == 24): - self._errHandler.recoverInline(self) - else: - self._errHandler.reportMatch(self) - self.consume() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class PrimaryContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def UNUM(self): - return self.getToken(Modelica.UNUM, 0) - - def STRING(self): - return self.getToken(Modelica.STRING, 0) - - def BOOL(self): - return self.getToken(Modelica.BOOL, 0) - - def unary_expression(self): - return self.getTypedRuleContext(Modelica.Unary_expressionContext, 0) - - def function_call_args(self): - return self.getTypedRuleContext(Modelica.Function_call_argsContext, 0) - - def component_reference(self): - return self.getTypedRuleContext(Modelica.Component_referenceContext, 0) - - def DER(self): - return self.getToken(Modelica.DER, 0) - - def INITIAL(self): - return self.getToken(Modelica.INITIAL, 0) - - def PURE(self): - return self.getToken(Modelica.PURE, 0) - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def output_expression_list(self): - return self.getTypedRuleContext(Modelica.Output_expression_listContext, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def LBRACK(self): - return self.getToken(Modelica.LBRACK, 0) - - def expression_list(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Expression_listContext) - else: - return self.getTypedRuleContext(Modelica.Expression_listContext, i) - - def RBRACK(self): - return self.getToken(Modelica.RBRACK, 0) - - def SEMICOLON(self, i: int = None): - if i is None: - return self.getTokens(Modelica.SEMICOLON) - else: - return self.getToken(Modelica.SEMICOLON, i) - - def LCURLY(self): - return self.getToken(Modelica.LCURLY, 0) - - def array_arguments(self): - return self.getTypedRuleContext(Modelica.Array_argumentsContext, 0) - - def RCURLY(self): - return self.getToken(Modelica.RCURLY, 0) - - def END(self): - return self.getToken(Modelica.END, 0) - - def getRuleIndex(self): - return Modelica.RULE_primary - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterPrimary"): - listener.enterPrimary(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitPrimary"): - listener.exitPrimary(self) - - def primary(self): - localctx = Modelica.PrimaryContext(self, self._ctx, self.state) - self.enterRule(localctx, 188, self.RULE_primary) - self._la = 0 # Token type - try: - self.state = 978 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 104, self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 946 - self.match(Modelica.UNUM) - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 947 - self.match(Modelica.STRING) - pass - - elif la_ == 3: - self.enterOuterAlt(localctx, 3) - self.state = 948 - self.match(Modelica.BOOL) - pass - - elif la_ == 4: - self.enterOuterAlt(localctx, 4) - self.state = 949 - self.unary_expression() - pass - - elif la_ == 5: - self.enterOuterAlt(localctx, 5) - self.state = 954 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [4, 93]: - self.state = 950 - self.component_reference() - pass - elif token in [60]: - self.state = 951 - self.match(Modelica.DER) - pass - elif token in [62]: - self.state = 952 - self.match(Modelica.INITIAL) - pass - elif token in [57]: - self.state = 953 - self.match(Modelica.PURE) - pass - else: - raise NoViableAltException(self) - - self.state = 956 - self.function_call_args() - pass - - elif la_ == 6: - self.enterOuterAlt(localctx, 6) - self.state = 957 - self.component_reference() - pass - - elif la_ == 7: - self.enterOuterAlt(localctx, 7) - self.state = 958 - self.match(Modelica.LPAREN) - self.state = 959 - self.output_expression_list() - self.state = 960 - self.match(Modelica.RPAREN) - pass - - elif la_ == 8: - self.enterOuterAlt(localctx, 8) - self.state = 962 - self.match(Modelica.LBRACK) - self.state = 963 - self.expression_list() - self.state = 968 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 5: - self.state = 964 - self.match(Modelica.SEMICOLON) - self.state = 965 - self.expression_list() - self.state = 970 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 971 - self.match(Modelica.RBRACK) - pass - - elif la_ == 9: - self.enterOuterAlt(localctx, 9) - self.state = 973 - self.match(Modelica.LCURLY) - self.state = 974 - self.array_arguments() - self.state = 975 - self.match(Modelica.RCURLY) - pass - - elif la_ == 10: - self.enterOuterAlt(localctx, 10) - self.state = 977 - self.match(Modelica.END) - pass - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Type_specifierContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.IDENT) - else: - return self.getToken(Modelica.IDENT, i) - - def DOT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.DOT) - else: - return self.getToken(Modelica.DOT, i) - - def getRuleIndex(self): - return Modelica.RULE_type_specifier - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterType_specifier"): - listener.enterType_specifier(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitType_specifier"): - listener.exitType_specifier(self) - - def type_specifier(self): - localctx = Modelica.Type_specifierContext(self, self._ctx, self.state) - self.enterRule(localctx, 190, self.RULE_type_specifier) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 981 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 4: - self.state = 980 - self.match(Modelica.DOT) - - self.state = 983 - self.match(Modelica.IDENT) - self.state = 988 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 4: - self.state = 984 - self.match(Modelica.DOT) - self.state = 985 - self.match(Modelica.IDENT) - self.state = 990 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class NameContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.IDENT) - else: - return self.getToken(Modelica.IDENT, i) - - def DOT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.DOT) - else: - return self.getToken(Modelica.DOT, i) - - def getRuleIndex(self): - return Modelica.RULE_name - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterName"): - listener.enterName(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitName"): - listener.exitName(self) - - def name(self): - localctx = Modelica.NameContext(self, self._ctx, self.state) - self.enterRule(localctx, 192, self.RULE_name) - try: - self.enterOuterAlt(localctx, 1) - self.state = 991 - self.match(Modelica.IDENT) - self.state = 996 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 107, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: - self.state = 992 - self.match(Modelica.DOT) - self.state = 993 - self.match(Modelica.IDENT) - self.state = 998 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 107, self._ctx) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Component_referenceContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.IDENT) - else: - return self.getToken(Modelica.IDENT, i) - - def DOT(self, i: int = None): - if i is None: - return self.getTokens(Modelica.DOT) - else: - return self.getToken(Modelica.DOT, i) - - def array_subscripts(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Array_subscriptsContext) - else: - return self.getTypedRuleContext(Modelica.Array_subscriptsContext, i) - - def getRuleIndex(self): - return Modelica.RULE_component_reference - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterComponent_reference"): - listener.enterComponent_reference(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitComponent_reference"): - listener.exitComponent_reference(self) - - def component_reference(self): - localctx = Modelica.Component_referenceContext(self, self._ctx, self.state) - self.enterRule(localctx, 194, self.RULE_component_reference) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1000 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 4: - self.state = 999 - self.match(Modelica.DOT) - - self.state = 1002 - self.match(Modelica.IDENT) - self.state = 1004 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 11: - self.state = 1003 - self.array_subscripts() - - self.state = 1013 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 4: - self.state = 1006 - self.match(Modelica.DOT) - self.state = 1007 - self.match(Modelica.IDENT) - self.state = 1009 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 11: - self.state = 1008 - self.array_subscripts() - - self.state = 1015 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Function_call_argsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def function_arguments(self): - return self.getTypedRuleContext(Modelica.Function_argumentsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_function_call_args - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFunction_call_args"): - listener.enterFunction_call_args(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFunction_call_args"): - listener.exitFunction_call_args(self) - - def function_call_args(self): - localctx = Modelica.Function_call_argsContext(self, self._ctx, self.state) - self.enterRule(localctx, 196, self.RULE_function_call_args) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1016 - self.match(Modelica.LPAREN) - self.state = 1018 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la) & ~0x3F) == 0 and ((1 << _la) & 6487435334097406608) != 0) or ( - (((_la - 90)) & ~0x3F) == 0 and ((1 << (_la - 90)) & 15) != 0 - ): - self.state = 1017 - self.function_arguments() - - self.state = 1020 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Function_argumentsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def FOR(self): - return self.getToken(Modelica.FOR, 0) - - def for_indices(self): - return self.getTypedRuleContext(Modelica.For_indicesContext, 0) - - def function_argument(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Function_argumentContext) - else: - return self.getTypedRuleContext(Modelica.Function_argumentContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def named_arguments(self): - return self.getTypedRuleContext(Modelica.Named_argumentsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_function_arguments - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFunction_arguments"): - listener.enterFunction_arguments(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFunction_arguments"): - listener.exitFunction_arguments(self) - - def function_arguments(self): - localctx = Modelica.Function_argumentsContext(self, self._ctx, self.state) - self.enterRule(localctx, 198, self.RULE_function_arguments) - self._la = 0 # Token type - try: - self.state = 1039 - self._errHandler.sync(self) - la_ = self._interp.adaptivePredict(self._input, 115, self._ctx) - if la_ == 1: - self.enterOuterAlt(localctx, 1) - self.state = 1022 - self.expression() - self.state = 1023 - self.match(Modelica.FOR) - self.state = 1024 - self.for_indices() - pass - - elif la_ == 2: - self.enterOuterAlt(localctx, 2) - self.state = 1026 - self.function_argument() - self.state = 1031 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 113, self._ctx) - while _alt != 2 and _alt != ATN.INVALID_ALT_NUMBER: - if _alt == 1: - self.state = 1027 - self.match(Modelica.COMMA) - self.state = 1028 - self.function_argument() - self.state = 1033 - self._errHandler.sync(self) - _alt = self._interp.adaptivePredict(self._input, 113, self._ctx) - - self.state = 1036 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 3: - self.state = 1034 - self.match(Modelica.COMMA) - self.state = 1035 - self.named_arguments() - - pass - - elif la_ == 3: - self.enterOuterAlt(localctx, 3) - self.state = 1038 - self.named_arguments() - pass - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Named_argumentsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def named_argument(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Named_argumentContext) - else: - return self.getTypedRuleContext(Modelica.Named_argumentContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_named_arguments - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterNamed_arguments"): - listener.enterNamed_arguments(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitNamed_arguments"): - listener.exitNamed_arguments(self) - - def named_arguments(self): - localctx = Modelica.Named_argumentsContext(self, self._ctx, self.state) - self.enterRule(localctx, 200, self.RULE_named_arguments) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1041 - self.named_argument() - self.state = 1046 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 1042 - self.match(Modelica.COMMA) - self.state = 1043 - self.named_argument() - self.state = 1048 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Named_argumentContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def IDENT(self): - return self.getToken(Modelica.IDENT, 0) - - def EQUAL(self): - return self.getToken(Modelica.EQUAL, 0) - - def function_argument(self): - return self.getTypedRuleContext(Modelica.Function_argumentContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_named_argument - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterNamed_argument"): - listener.enterNamed_argument(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitNamed_argument"): - listener.exitNamed_argument(self) - - def named_argument(self): - localctx = Modelica.Named_argumentContext(self, self._ctx, self.state) - self.enterRule(localctx, 202, self.RULE_named_argument) - try: - self.enterOuterAlt(localctx, 1) - self.state = 1049 - self.match(Modelica.IDENT) - self.state = 1050 - self.match(Modelica.EQUAL) - self.state = 1051 - self.function_argument() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Function_argumentContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def function_partial_application(self): - return self.getTypedRuleContext( - Modelica.Function_partial_applicationContext, 0 - ) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_function_argument - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFunction_argument"): - listener.enterFunction_argument(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFunction_argument"): - listener.exitFunction_argument(self) - - def function_argument(self): - localctx = Modelica.Function_argumentContext(self, self._ctx, self.state) - self.enterRule(localctx, 204, self.RULE_function_argument) - try: - self.state = 1055 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [51]: - self.enterOuterAlt(localctx, 1) - self.state = 1053 - self.function_partial_application() - pass - elif token in [ - 4, - 7, - 9, - 11, - 15, - 16, - 20, - 21, - 31, - 36, - 57, - 59, - 60, - 62, - 90, - 91, - 92, - 93, - ]: - self.enterOuterAlt(localctx, 2) - self.state = 1054 - self.expression() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Function_partial_applicationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def FUNCTION(self): - return self.getToken(Modelica.FUNCTION, 0) - - def type_specifier(self): - return self.getTypedRuleContext(Modelica.Type_specifierContext, 0) - - def LPAREN(self): - return self.getToken(Modelica.LPAREN, 0) - - def RPAREN(self): - return self.getToken(Modelica.RPAREN, 0) - - def named_arguments(self): - return self.getTypedRuleContext(Modelica.Named_argumentsContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_function_partial_application - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterFunction_partial_application"): - listener.enterFunction_partial_application(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitFunction_partial_application"): - listener.exitFunction_partial_application(self) - - def function_partial_application(self): - localctx = Modelica.Function_partial_applicationContext( - self, self._ctx, self.state - ) - self.enterRule(localctx, 206, self.RULE_function_partial_application) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1057 - self.match(Modelica.FUNCTION) - self.state = 1058 - self.type_specifier() - self.state = 1059 - self.match(Modelica.LPAREN) - self.state = 1061 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 93: - self.state = 1060 - self.named_arguments() - - self.state = 1063 - self.match(Modelica.RPAREN) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Output_expression_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ExpressionContext) - else: - return self.getTypedRuleContext(Modelica.ExpressionContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_output_expression_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterOutput_expression_list"): - listener.enterOutput_expression_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitOutput_expression_list"): - listener.exitOutput_expression_list(self) - - def output_expression_list(self): - localctx = Modelica.Output_expression_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 208, self.RULE_output_expression_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1066 - self._errHandler.sync(self) - _la = self._input.LA(1) - if (((_la) & ~0x3F) == 0 and ((1 << _la) & 6485183534283721360) != 0) or ( - (((_la - 90)) & ~0x3F) == 0 and ((1 << (_la - 90)) & 15) != 0 - ): - self.state = 1065 - self.expression() - - self.state = 1074 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 1068 - self.match(Modelica.COMMA) - self.state = 1070 - self._errHandler.sync(self) - _la = self._input.LA(1) - if ( - ((_la) & ~0x3F) == 0 and ((1 << _la) & 6485183534283721360) != 0 - ) or ((((_la - 90)) & ~0x3F) == 0 and ((1 << (_la - 90)) & 15) != 0): - self.state = 1069 - self.expression() - - self.state = 1076 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Expression_listContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ExpressionContext) - else: - return self.getTypedRuleContext(Modelica.ExpressionContext, i) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_expression_list - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterExpression_list"): - listener.enterExpression_list(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitExpression_list"): - listener.exitExpression_list(self) - - def expression_list(self): - localctx = Modelica.Expression_listContext(self, self._ctx, self.state) - self.enterRule(localctx, 210, self.RULE_expression_list) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1077 - self.expression() - self.state = 1082 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 1078 - self.match(Modelica.COMMA) - self.state = 1079 - self.expression() - self.state = 1084 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Array_argumentsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def expression(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.ExpressionContext) - else: - return self.getTypedRuleContext(Modelica.ExpressionContext, i) - - def FOR(self): - return self.getToken(Modelica.FOR, 0) - - def for_indices(self): - return self.getTypedRuleContext(Modelica.For_indicesContext, 0) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_array_arguments - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArray_arguments"): - listener.enterArray_arguments(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArray_arguments"): - listener.exitArray_arguments(self) - - def array_arguments(self): - localctx = Modelica.Array_argumentsContext(self, self._ctx, self.state) - self.enterRule(localctx, 212, self.RULE_array_arguments) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1085 - self.expression() - self.state = 1095 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [3, 10]: - self.state = 1090 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 1086 - self.match(Modelica.COMMA) - self.state = 1087 - self.expression() - self.state = 1092 - self._errHandler.sync(self) - _la = self._input.LA(1) - - pass - elif token in [35]: - self.state = 1093 - self.match(Modelica.FOR) - self.state = 1094 - self.for_indices() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Array_subscriptsContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def LBRACK(self): - return self.getToken(Modelica.LBRACK, 0) - - def subscript(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.SubscriptContext) - else: - return self.getTypedRuleContext(Modelica.SubscriptContext, i) - - def RBRACK(self): - return self.getToken(Modelica.RBRACK, 0) - - def COMMA(self, i: int = None): - if i is None: - return self.getTokens(Modelica.COMMA) - else: - return self.getToken(Modelica.COMMA, i) - - def getRuleIndex(self): - return Modelica.RULE_array_subscripts - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterArray_subscripts"): - listener.enterArray_subscripts(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitArray_subscripts"): - listener.exitArray_subscripts(self) - - def array_subscripts(self): - localctx = Modelica.Array_subscriptsContext(self, self._ctx, self.state) - self.enterRule(localctx, 214, self.RULE_array_subscripts) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1097 - self.match(Modelica.LBRACK) - self.state = 1098 - self.subscript() - self.state = 1103 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 3: - self.state = 1099 - self.match(Modelica.COMMA) - self.state = 1100 - self.subscript() - self.state = 1105 - self._errHandler.sync(self) - _la = self._input.LA(1) - - self.state = 1106 - self.match(Modelica.RBRACK) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class SubscriptContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def COLON(self): - return self.getToken(Modelica.COLON, 0) - - def expression(self): - return self.getTypedRuleContext(Modelica.ExpressionContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_subscript - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterSubscript"): - listener.enterSubscript(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitSubscript"): - listener.exitSubscript(self) - - def subscript(self): - localctx = Modelica.SubscriptContext(self, self._ctx, self.state) - self.enterRule(localctx, 216, self.RULE_subscript) - try: - self.state = 1110 - self._errHandler.sync(self) - token = self._input.LA(1) - if token in [6]: - self.enterOuterAlt(localctx, 1) - self.state = 1108 - self.match(Modelica.COLON) - pass - elif token in [ - 4, - 7, - 9, - 11, - 15, - 16, - 20, - 21, - 31, - 36, - 57, - 59, - 60, - 62, - 90, - 91, - 92, - 93, - ]: - self.enterOuterAlt(localctx, 2) - self.state = 1109 - self.expression() - pass - else: - raise NoViableAltException(self) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class DescriptionContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def description_string(self): - return self.getTypedRuleContext(Modelica.Description_stringContext, 0) - - def annotation(self): - return self.getTypedRuleContext(Modelica.AnnotationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_description - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterDescription"): - listener.enterDescription(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitDescription"): - listener.exitDescription(self) - - def description(self): - localctx = Modelica.DescriptionContext(self, self._ctx, self.state) - self.enterRule(localctx, 218, self.RULE_description) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1112 - self.description_string() - self.state = 1114 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 86: - self.state = 1113 - self.annotation() - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Description_stringContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def STRING(self, i: int = None): - if i is None: - return self.getTokens(Modelica.STRING) - else: - return self.getToken(Modelica.STRING, i) - - def cat_operator(self, i: int = None): - if i is None: - return self.getTypedRuleContexts(Modelica.Cat_operatorContext) - else: - return self.getTypedRuleContext(Modelica.Cat_operatorContext, i) - - def getRuleIndex(self): - return Modelica.RULE_description_string - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterDescription_string"): - listener.enterDescription_string(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitDescription_string"): - listener.exitDescription_string(self) - - def description_string(self): - localctx = Modelica.Description_stringContext(self, self._ctx, self.state) - self.enterRule(localctx, 220, self.RULE_description_string) - self._la = 0 # Token type - try: - self.enterOuterAlt(localctx, 1) - self.state = 1125 - self._errHandler.sync(self) - _la = self._input.LA(1) - if _la == 90: - self.state = 1116 - self.match(Modelica.STRING) - self.state = 1122 - self._errHandler.sync(self) - _la = self._input.LA(1) - while _la == 15: - self.state = 1117 - self.cat_operator() - self.state = 1118 - self.match(Modelica.STRING) - self.state = 1124 - self._errHandler.sync(self) - _la = self._input.LA(1) - - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class Cat_operatorContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def PLUS(self): - return self.getToken(Modelica.PLUS, 0) - - def getRuleIndex(self): - return Modelica.RULE_cat_operator - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterCat_operator"): - listener.enterCat_operator(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitCat_operator"): - listener.exitCat_operator(self) - - def cat_operator(self): - localctx = Modelica.Cat_operatorContext(self, self._ctx, self.state) - self.enterRule(localctx, 222, self.RULE_cat_operator) - try: - self.enterOuterAlt(localctx, 1) - self.state = 1127 - self.match(Modelica.PLUS) - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx - - class AnnotationContext(ParserRuleContext): - __slots__ = "parser" - - def __init__( - self, parser, parent: ParserRuleContext = None, invokingState: int = -1 - ): - super().__init__(parent, invokingState) - self.parser = parser - - def ANNOTATION(self): - return self.getToken(Modelica.ANNOTATION, 0) - - def class_modification(self): - return self.getTypedRuleContext(Modelica.Class_modificationContext, 0) - - def getRuleIndex(self): - return Modelica.RULE_annotation - - def enterRule(self, listener: ParseTreeListener): - if hasattr(listener, "enterAnnotation"): - listener.enterAnnotation(self) - - def exitRule(self, listener: ParseTreeListener): - if hasattr(listener, "exitAnnotation"): - listener.exitAnnotation(self) - - def annotation(self): - localctx = Modelica.AnnotationContext(self, self._ctx, self.state) - self.enterRule(localctx, 224, self.RULE_annotation) - try: - self.enterOuterAlt(localctx, 1) - self.state = 1129 - self.match(Modelica.ANNOTATION) - self.state = 1130 - self.class_modification() - except RecognitionException as re: - localctx.exception = re - self._errHandler.reportError(self, re) - self._errHandler.recover(self, re) - finally: - self.exitRule() - return localctx diff --git a/mofmt/parsing/generated/Modelica.tokens b/mofmt/parsing/generated/Modelica.tokens deleted file mode 100644 index c2e50f6..0000000 --- a/mofmt/parsing/generated/Modelica.tokens +++ /dev/null @@ -1,179 +0,0 @@ -WS=1 -DQUOTE=2 -COMMA=3 -DOT=4 -SEMICOLON=5 -COLON=6 -LPAREN=7 -RPAREN=8 -LCURLY=9 -RCURLY=10 -LBRACK=11 -RBRACK=12 -EQUAL=13 -ASSIGN=14 -PLUS=15 -MINUS=16 -STAR=17 -SLASH=18 -FLEX=19 -DOTPLUS=20 -DOTMINUS=21 -DOTSTAR=22 -DOTSLASH=23 -DOTFLEX=24 -GRE=25 -GEQ=26 -LES=27 -LEQ=28 -NEQ=29 -EEQ=30 -NOT=31 -AND=32 -OR=33 -IN=34 -FOR=35 -IF=36 -ELSE=37 -ELSEIF=38 -THEN=39 -WHEN=40 -ELSEWHEN=41 -WHILE=42 -LOOP=43 -BREAK=44 -RETURN=45 -PARTIAL=46 -OPERATOR=47 -EXPANDABLE=48 -CLASS=49 -MODEL=50 -FUNCTION=51 -RECORD=52 -TYPE=53 -BLOCK=54 -CONNECTOR=55 -PACKAGE=56 -PURE=57 -IMPURE=58 -END=59 -DER=60 -CONNECT=61 -INITIAL=62 -EQUATION=63 -ALGORITHM=64 -WITHIN=65 -FINAL=66 -ENCAPSULATED=67 -EXTENDS=68 -IMPORT=69 -ENUMERATION=70 -INPUT=71 -OUTPUT=72 -PUBLIC=73 -PROTECTED=74 -REDECLARE=75 -INNER=76 -OUTER=77 -REPLACEABLE=78 -CONSTRAINEDBY=79 -FLOW=80 -STREAM=81 -DISCRETE=82 -PARAMETER=83 -CONSTANT=84 -EACH=85 -ANNOTATION=86 -EXTERNAL=87 -BLOCK_COMMENT=88 -LINE_COMMENT=89 -STRING=90 -UNUM=91 -BOOL=92 -IDENT=93 -'"'=2 -','=3 -'.'=4 -';'=5 -':'=6 -'('=7 -')'=8 -'{'=9 -'}'=10 -'['=11 -']'=12 -'='=13 -':='=14 -'+'=15 -'-'=16 -'*'=17 -'/'=18 -'^'=19 -'.+'=20 -'.-'=21 -'.*'=22 -'./'=23 -'.^'=24 -'>'=25 -'>='=26 -'<'=27 -'<='=28 -'<>'=29 -'=='=30 -'not'=31 -'and'=32 -'or'=33 -'in'=34 -'for'=35 -'if'=36 -'else'=37 -'elseif'=38 -'then'=39 -'when'=40 -'elsewhen'=41 -'while'=42 -'loop'=43 -'break'=44 -'return'=45 -'partial'=46 -'operator'=47 -'expandable'=48 -'class'=49 -'model'=50 -'function'=51 -'record'=52 -'type'=53 -'block'=54 -'connector'=55 -'package'=56 -'pure'=57 -'impure'=58 -'end'=59 -'der'=60 -'connect'=61 -'initial'=62 -'equation'=63 -'algorithm'=64 -'within'=65 -'final'=66 -'encapsulated'=67 -'extends'=68 -'import'=69 -'enumeration'=70 -'input'=71 -'output'=72 -'public'=73 -'protected'=74 -'redeclare'=75 -'inner'=76 -'outer'=77 -'replaceable'=78 -'constrainedby'=79 -'flow'=80 -'stream'=81 -'discrete'=82 -'parameter'=83 -'constant'=84 -'each'=85 -'annotation'=86 -'external'=87 diff --git a/mofmt/parsing/generated/ModelicaLexer.interp b/mofmt/parsing/generated/ModelicaLexer.interp deleted file mode 100644 index 5573c28..0000000 --- a/mofmt/parsing/generated/ModelicaLexer.interp +++ /dev/null @@ -1,309 +0,0 @@ -token literal names: -null -null -'"' -',' -'.' -';' -':' -'(' -')' -'{' -'}' -'[' -']' -'=' -':=' -'+' -'-' -'*' -'/' -'^' -'.+' -'.-' -'.*' -'./' -'.^' -'>' -'>=' -'<' -'<=' -'<>' -'==' -'not' -'and' -'or' -'in' -'for' -'if' -'else' -'elseif' -'then' -'when' -'elsewhen' -'while' -'loop' -'break' -'return' -'partial' -'operator' -'expandable' -'class' -'model' -'function' -'record' -'type' -'block' -'connector' -'package' -'pure' -'impure' -'end' -'der' -'connect' -'initial' -'equation' -'algorithm' -'within' -'final' -'encapsulated' -'extends' -'import' -'enumeration' -'input' -'output' -'public' -'protected' -'redeclare' -'inner' -'outer' -'replaceable' -'constrainedby' -'flow' -'stream' -'discrete' -'parameter' -'constant' -'each' -'annotation' -'external' -null -null -null -null -null -null - -token symbolic names: -null -WS -DQUOTE -COMMA -DOT -SEMICOLON -COLON -LPAREN -RPAREN -LCURLY -RCURLY -LBRACK -RBRACK -EQUAL -ASSIGN -PLUS -MINUS -STAR -SLASH -FLEX -DOTPLUS -DOTMINUS -DOTSTAR -DOTSLASH -DOTFLEX -GRE -GEQ -LES -LEQ -NEQ -EEQ -NOT -AND -OR -IN -FOR -IF -ELSE -ELSEIF -THEN -WHEN -ELSEWHEN -WHILE -LOOP -BREAK -RETURN -PARTIAL -OPERATOR -EXPANDABLE -CLASS -MODEL -FUNCTION -RECORD -TYPE -BLOCK -CONNECTOR -PACKAGE -PURE -IMPURE -END -DER -CONNECT -INITIAL -EQUATION -ALGORITHM -WITHIN -FINAL -ENCAPSULATED -EXTENDS -IMPORT -ENUMERATION -INPUT -OUTPUT -PUBLIC -PROTECTED -REDECLARE -INNER -OUTER -REPLACEABLE -CONSTRAINEDBY -FLOW -STREAM -DISCRETE -PARAMETER -CONSTANT -EACH -ANNOTATION -EXTERNAL -BLOCK_COMMENT -LINE_COMMENT -STRING -UNUM -BOOL -IDENT - -rule names: -WS -DQUOTE -COMMA -DOT -SEMICOLON -COLON -LPAREN -RPAREN -LCURLY -RCURLY -LBRACK -RBRACK -EQUAL -ASSIGN -PLUS -MINUS -STAR -SLASH -FLEX -DOTPLUS -DOTMINUS -DOTSTAR -DOTSLASH -DOTFLEX -GRE -GEQ -LES -LEQ -NEQ -EEQ -NOT -AND -OR -IN -FOR -IF -ELSE -ELSEIF -THEN -WHEN -ELSEWHEN -WHILE -LOOP -BREAK -RETURN -PARTIAL -OPERATOR -EXPANDABLE -CLASS -MODEL -FUNCTION -RECORD -TYPE -BLOCK -CONNECTOR -PACKAGE -PURE -IMPURE -END -DER -CONNECT -INITIAL -EQUATION -ALGORITHM -WITHIN -FINAL -ENCAPSULATED -EXTENDS -IMPORT -ENUMERATION -INPUT -OUTPUT -PUBLIC -PROTECTED -REDECLARE -INNER -OUTER -REPLACEABLE -CONSTRAINEDBY -FLOW -STREAM -DISCRETE -PARAMETER -CONSTANT -EACH -ANNOTATION -EXTERNAL -BLOCK_COMMENT -LINE_COMMENT -S_ESCAPE -DIGIT -NONDIGIT -Q_CHAR -Q_IDENT -S_CHAR -E -UINT -UREAL -STRING -UNUM -BOOL -IDENT - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN -null -null -WHITESPACE -COMMENTS - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 93, 800, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 2, 62, 7, 62, 2, 63, 7, 63, 2, 64, 7, 64, 2, 65, 7, 65, 2, 66, 7, 66, 2, 67, 7, 67, 2, 68, 7, 68, 2, 69, 7, 69, 2, 70, 7, 70, 2, 71, 7, 71, 2, 72, 7, 72, 2, 73, 7, 73, 2, 74, 7, 74, 2, 75, 7, 75, 2, 76, 7, 76, 2, 77, 7, 77, 2, 78, 7, 78, 2, 79, 7, 79, 2, 80, 7, 80, 2, 81, 7, 81, 2, 82, 7, 82, 2, 83, 7, 83, 2, 84, 7, 84, 2, 85, 7, 85, 2, 86, 7, 86, 2, 87, 7, 87, 2, 88, 7, 88, 2, 89, 7, 89, 2, 90, 7, 90, 2, 91, 7, 91, 2, 92, 7, 92, 2, 93, 7, 93, 2, 94, 7, 94, 2, 95, 7, 95, 2, 96, 7, 96, 2, 97, 7, 97, 2, 98, 7, 98, 2, 99, 7, 99, 2, 100, 7, 100, 2, 101, 7, 101, 1, 0, 4, 0, 207, 8, 0, 11, 0, 12, 0, 208, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 37, 1, 37, 1, 37, 1, 37, 1, 37, 1, 37, 1, 37, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 41, 1, 41, 1, 41, 1, 41, 1, 41, 1, 41, 1, 42, 1, 42, 1, 42, 1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 43, 1, 43, 1, 43, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 46, 1, 46, 1, 46, 1, 46, 1, 46, 1, 46, 1, 46, 1, 46, 1, 46, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 1, 49, 1, 49, 1, 49, 1, 49, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 50, 1, 51, 1, 51, 1, 51, 1, 51, 1, 51, 1, 51, 1, 51, 1, 52, 1, 52, 1, 52, 1, 52, 1, 52, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 54, 1, 55, 1, 55, 1, 55, 1, 55, 1, 55, 1, 55, 1, 55, 1, 55, 1, 56, 1, 56, 1, 56, 1, 56, 1, 56, 1, 57, 1, 57, 1, 57, 1, 57, 1, 57, 1, 57, 1, 57, 1, 58, 1, 58, 1, 58, 1, 58, 1, 59, 1, 59, 1, 59, 1, 59, 1, 60, 1, 60, 1, 60, 1, 60, 1, 60, 1, 60, 1, 60, 1, 60, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 61, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 63, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 64, 1, 65, 1, 65, 1, 65, 1, 65, 1, 65, 1, 65, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 66, 1, 67, 1, 67, 1, 67, 1, 67, 1, 67, 1, 67, 1, 67, 1, 67, 1, 68, 1, 68, 1, 68, 1, 68, 1, 68, 1, 68, 1, 68, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, 1, 70, 1, 70, 1, 70, 1, 70, 1, 70, 1, 70, 1, 71, 1, 71, 1, 71, 1, 71, 1, 71, 1, 71, 1, 71, 1, 72, 1, 72, 1, 72, 1, 72, 1, 72, 1, 72, 1, 72, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 74, 1, 75, 1, 75, 1, 75, 1, 75, 1, 75, 1, 75, 1, 76, 1, 76, 1, 76, 1, 76, 1, 76, 1, 76, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 77, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 78, 1, 79, 1, 79, 1, 79, 1, 79, 1, 79, 1, 80, 1, 80, 1, 80, 1, 80, 1, 80, 1, 80, 1, 80, 1, 81, 1, 81, 1, 81, 1, 81, 1, 81, 1, 81, 1, 81, 1, 81, 1, 81, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 82, 1, 83, 1, 83, 1, 83, 1, 83, 1, 83, 1, 83, 1, 83, 1, 83, 1, 83, 1, 84, 1, 84, 1, 84, 1, 84, 1, 84, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 85, 1, 86, 1, 86, 1, 86, 1, 86, 1, 86, 1, 86, 1, 86, 1, 86, 1, 86, 1, 87, 1, 87, 1, 87, 1, 87, 5, 87, 697, 8, 87, 10, 87, 12, 87, 700, 9, 87, 1, 87, 1, 87, 1, 87, 1, 87, 1, 87, 1, 88, 1, 88, 1, 88, 1, 88, 5, 88, 711, 8, 88, 10, 88, 12, 88, 714, 9, 88, 1, 88, 1, 88, 1, 89, 1, 89, 1, 89, 1, 90, 1, 90, 1, 91, 1, 91, 1, 92, 1, 92, 1, 92, 3, 92, 728, 8, 92, 1, 93, 1, 93, 1, 93, 5, 93, 733, 8, 93, 10, 93, 12, 93, 736, 9, 93, 1, 93, 1, 93, 1, 94, 1, 94, 1, 95, 1, 95, 1, 96, 4, 96, 745, 8, 96, 11, 96, 12, 96, 746, 1, 97, 1, 97, 1, 97, 3, 97, 752, 8, 97, 3, 97, 754, 8, 97, 1, 97, 1, 97, 1, 97, 3, 97, 759, 8, 97, 1, 97, 1, 97, 3, 97, 763, 8, 97, 1, 98, 1, 98, 1, 98, 5, 98, 768, 8, 98, 10, 98, 12, 98, 771, 9, 98, 1, 98, 1, 98, 1, 99, 1, 99, 3, 99, 777, 8, 99, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 3, 100, 788, 8, 100, 1, 101, 1, 101, 1, 101, 5, 101, 793, 8, 101, 10, 101, 12, 101, 796, 9, 101, 1, 101, 3, 101, 799, 8, 101, 1, 698, 0, 102, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 35, 71, 36, 73, 37, 75, 38, 77, 39, 79, 40, 81, 41, 83, 42, 85, 43, 87, 44, 89, 45, 91, 46, 93, 47, 95, 48, 97, 49, 99, 50, 101, 51, 103, 52, 105, 53, 107, 54, 109, 55, 111, 56, 113, 57, 115, 58, 117, 59, 119, 60, 121, 61, 123, 62, 125, 63, 127, 64, 129, 65, 131, 66, 133, 67, 135, 68, 137, 69, 139, 70, 141, 71, 143, 72, 145, 73, 147, 74, 149, 75, 151, 76, 153, 77, 155, 78, 157, 79, 159, 80, 161, 81, 163, 82, 165, 83, 167, 84, 169, 85, 171, 86, 173, 87, 175, 88, 177, 89, 179, 0, 181, 0, 183, 0, 185, 0, 187, 0, 189, 0, 191, 0, 193, 0, 195, 0, 197, 90, 199, 91, 201, 92, 203, 93, 1, 0, 8, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 10, 10, 13, 13, 10, 0, 34, 34, 39, 39, 63, 63, 92, 92, 97, 98, 102, 102, 110, 110, 114, 114, 116, 116, 118, 118, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 6, 0, 32, 38, 40, 47, 58, 64, 91, 91, 93, 94, 123, 126, 2, 0, 34, 34, 92, 92, 2, 0, 69, 69, 101, 101, 810, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 0, 83, 1, 0, 0, 0, 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, 0, 0, 93, 1, 0, 0, 0, 0, 95, 1, 0, 0, 0, 0, 97, 1, 0, 0, 0, 0, 99, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 103, 1, 0, 0, 0, 0, 105, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 0, 115, 1, 0, 0, 0, 0, 117, 1, 0, 0, 0, 0, 119, 1, 0, 0, 0, 0, 121, 1, 0, 0, 0, 0, 123, 1, 0, 0, 0, 0, 125, 1, 0, 0, 0, 0, 127, 1, 0, 0, 0, 0, 129, 1, 0, 0, 0, 0, 131, 1, 0, 0, 0, 0, 133, 1, 0, 0, 0, 0, 135, 1, 0, 0, 0, 0, 137, 1, 0, 0, 0, 0, 139, 1, 0, 0, 0, 0, 141, 1, 0, 0, 0, 0, 143, 1, 0, 0, 0, 0, 145, 1, 0, 0, 0, 0, 147, 1, 0, 0, 0, 0, 149, 1, 0, 0, 0, 0, 151, 1, 0, 0, 0, 0, 153, 1, 0, 0, 0, 0, 155, 1, 0, 0, 0, 0, 157, 1, 0, 0, 0, 0, 159, 1, 0, 0, 0, 0, 161, 1, 0, 0, 0, 0, 163, 1, 0, 0, 0, 0, 165, 1, 0, 0, 0, 0, 167, 1, 0, 0, 0, 0, 169, 1, 0, 0, 0, 0, 171, 1, 0, 0, 0, 0, 173, 1, 0, 0, 0, 0, 175, 1, 0, 0, 0, 0, 177, 1, 0, 0, 0, 0, 197, 1, 0, 0, 0, 0, 199, 1, 0, 0, 0, 0, 201, 1, 0, 0, 0, 0, 203, 1, 0, 0, 0, 1, 206, 1, 0, 0, 0, 3, 212, 1, 0, 0, 0, 5, 214, 1, 0, 0, 0, 7, 216, 1, 0, 0, 0, 9, 218, 1, 0, 0, 0, 11, 220, 1, 0, 0, 0, 13, 222, 1, 0, 0, 0, 15, 224, 1, 0, 0, 0, 17, 226, 1, 0, 0, 0, 19, 228, 1, 0, 0, 0, 21, 230, 1, 0, 0, 0, 23, 232, 1, 0, 0, 0, 25, 234, 1, 0, 0, 0, 27, 236, 1, 0, 0, 0, 29, 239, 1, 0, 0, 0, 31, 241, 1, 0, 0, 0, 33, 243, 1, 0, 0, 0, 35, 245, 1, 0, 0, 0, 37, 247, 1, 0, 0, 0, 39, 249, 1, 0, 0, 0, 41, 252, 1, 0, 0, 0, 43, 255, 1, 0, 0, 0, 45, 258, 1, 0, 0, 0, 47, 261, 1, 0, 0, 0, 49, 264, 1, 0, 0, 0, 51, 266, 1, 0, 0, 0, 53, 269, 1, 0, 0, 0, 55, 271, 1, 0, 0, 0, 57, 274, 1, 0, 0, 0, 59, 277, 1, 0, 0, 0, 61, 280, 1, 0, 0, 0, 63, 284, 1, 0, 0, 0, 65, 288, 1, 0, 0, 0, 67, 291, 1, 0, 0, 0, 69, 294, 1, 0, 0, 0, 71, 298, 1, 0, 0, 0, 73, 301, 1, 0, 0, 0, 75, 306, 1, 0, 0, 0, 77, 313, 1, 0, 0, 0, 79, 318, 1, 0, 0, 0, 81, 323, 1, 0, 0, 0, 83, 332, 1, 0, 0, 0, 85, 338, 1, 0, 0, 0, 87, 343, 1, 0, 0, 0, 89, 349, 1, 0, 0, 0, 91, 356, 1, 0, 0, 0, 93, 364, 1, 0, 0, 0, 95, 373, 1, 0, 0, 0, 97, 384, 1, 0, 0, 0, 99, 390, 1, 0, 0, 0, 101, 396, 1, 0, 0, 0, 103, 405, 1, 0, 0, 0, 105, 412, 1, 0, 0, 0, 107, 417, 1, 0, 0, 0, 109, 423, 1, 0, 0, 0, 111, 433, 1, 0, 0, 0, 113, 441, 1, 0, 0, 0, 115, 446, 1, 0, 0, 0, 117, 453, 1, 0, 0, 0, 119, 457, 1, 0, 0, 0, 121, 461, 1, 0, 0, 0, 123, 469, 1, 0, 0, 0, 125, 477, 1, 0, 0, 0, 127, 486, 1, 0, 0, 0, 129, 496, 1, 0, 0, 0, 131, 503, 1, 0, 0, 0, 133, 509, 1, 0, 0, 0, 135, 522, 1, 0, 0, 0, 137, 530, 1, 0, 0, 0, 139, 537, 1, 0, 0, 0, 141, 549, 1, 0, 0, 0, 143, 555, 1, 0, 0, 0, 145, 562, 1, 0, 0, 0, 147, 569, 1, 0, 0, 0, 149, 579, 1, 0, 0, 0, 151, 589, 1, 0, 0, 0, 153, 595, 1, 0, 0, 0, 155, 601, 1, 0, 0, 0, 157, 613, 1, 0, 0, 0, 159, 627, 1, 0, 0, 0, 161, 632, 1, 0, 0, 0, 163, 639, 1, 0, 0, 0, 165, 648, 1, 0, 0, 0, 167, 658, 1, 0, 0, 0, 169, 667, 1, 0, 0, 0, 171, 672, 1, 0, 0, 0, 173, 683, 1, 0, 0, 0, 175, 692, 1, 0, 0, 0, 177, 706, 1, 0, 0, 0, 179, 717, 1, 0, 0, 0, 181, 720, 1, 0, 0, 0, 183, 722, 1, 0, 0, 0, 185, 727, 1, 0, 0, 0, 187, 729, 1, 0, 0, 0, 189, 739, 1, 0, 0, 0, 191, 741, 1, 0, 0, 0, 193, 744, 1, 0, 0, 0, 195, 748, 1, 0, 0, 0, 197, 764, 1, 0, 0, 0, 199, 776, 1, 0, 0, 0, 201, 787, 1, 0, 0, 0, 203, 798, 1, 0, 0, 0, 205, 207, 7, 0, 0, 0, 206, 205, 1, 0, 0, 0, 207, 208, 1, 0, 0, 0, 208, 206, 1, 0, 0, 0, 208, 209, 1, 0, 0, 0, 209, 210, 1, 0, 0, 0, 210, 211, 6, 0, 0, 0, 211, 2, 1, 0, 0, 0, 212, 213, 5, 34, 0, 0, 213, 4, 1, 0, 0, 0, 214, 215, 5, 44, 0, 0, 215, 6, 1, 0, 0, 0, 216, 217, 5, 46, 0, 0, 217, 8, 1, 0, 0, 0, 218, 219, 5, 59, 0, 0, 219, 10, 1, 0, 0, 0, 220, 221, 5, 58, 0, 0, 221, 12, 1, 0, 0, 0, 222, 223, 5, 40, 0, 0, 223, 14, 1, 0, 0, 0, 224, 225, 5, 41, 0, 0, 225, 16, 1, 0, 0, 0, 226, 227, 5, 123, 0, 0, 227, 18, 1, 0, 0, 0, 228, 229, 5, 125, 0, 0, 229, 20, 1, 0, 0, 0, 230, 231, 5, 91, 0, 0, 231, 22, 1, 0, 0, 0, 232, 233, 5, 93, 0, 0, 233, 24, 1, 0, 0, 0, 234, 235, 5, 61, 0, 0, 235, 26, 1, 0, 0, 0, 236, 237, 5, 58, 0, 0, 237, 238, 5, 61, 0, 0, 238, 28, 1, 0, 0, 0, 239, 240, 5, 43, 0, 0, 240, 30, 1, 0, 0, 0, 241, 242, 5, 45, 0, 0, 242, 32, 1, 0, 0, 0, 243, 244, 5, 42, 0, 0, 244, 34, 1, 0, 0, 0, 245, 246, 5, 47, 0, 0, 246, 36, 1, 0, 0, 0, 247, 248, 5, 94, 0, 0, 248, 38, 1, 0, 0, 0, 249, 250, 5, 46, 0, 0, 250, 251, 5, 43, 0, 0, 251, 40, 1, 0, 0, 0, 252, 253, 5, 46, 0, 0, 253, 254, 5, 45, 0, 0, 254, 42, 1, 0, 0, 0, 255, 256, 5, 46, 0, 0, 256, 257, 5, 42, 0, 0, 257, 44, 1, 0, 0, 0, 258, 259, 5, 46, 0, 0, 259, 260, 5, 47, 0, 0, 260, 46, 1, 0, 0, 0, 261, 262, 5, 46, 0, 0, 262, 263, 5, 94, 0, 0, 263, 48, 1, 0, 0, 0, 264, 265, 5, 62, 0, 0, 265, 50, 1, 0, 0, 0, 266, 267, 5, 62, 0, 0, 267, 268, 5, 61, 0, 0, 268, 52, 1, 0, 0, 0, 269, 270, 5, 60, 0, 0, 270, 54, 1, 0, 0, 0, 271, 272, 5, 60, 0, 0, 272, 273, 5, 61, 0, 0, 273, 56, 1, 0, 0, 0, 274, 275, 5, 60, 0, 0, 275, 276, 5, 62, 0, 0, 276, 58, 1, 0, 0, 0, 277, 278, 5, 61, 0, 0, 278, 279, 5, 61, 0, 0, 279, 60, 1, 0, 0, 0, 280, 281, 5, 110, 0, 0, 281, 282, 5, 111, 0, 0, 282, 283, 5, 116, 0, 0, 283, 62, 1, 0, 0, 0, 284, 285, 5, 97, 0, 0, 285, 286, 5, 110, 0, 0, 286, 287, 5, 100, 0, 0, 287, 64, 1, 0, 0, 0, 288, 289, 5, 111, 0, 0, 289, 290, 5, 114, 0, 0, 290, 66, 1, 0, 0, 0, 291, 292, 5, 105, 0, 0, 292, 293, 5, 110, 0, 0, 293, 68, 1, 0, 0, 0, 294, 295, 5, 102, 0, 0, 295, 296, 5, 111, 0, 0, 296, 297, 5, 114, 0, 0, 297, 70, 1, 0, 0, 0, 298, 299, 5, 105, 0, 0, 299, 300, 5, 102, 0, 0, 300, 72, 1, 0, 0, 0, 301, 302, 5, 101, 0, 0, 302, 303, 5, 108, 0, 0, 303, 304, 5, 115, 0, 0, 304, 305, 5, 101, 0, 0, 305, 74, 1, 0, 0, 0, 306, 307, 5, 101, 0, 0, 307, 308, 5, 108, 0, 0, 308, 309, 5, 115, 0, 0, 309, 310, 5, 101, 0, 0, 310, 311, 5, 105, 0, 0, 311, 312, 5, 102, 0, 0, 312, 76, 1, 0, 0, 0, 313, 314, 5, 116, 0, 0, 314, 315, 5, 104, 0, 0, 315, 316, 5, 101, 0, 0, 316, 317, 5, 110, 0, 0, 317, 78, 1, 0, 0, 0, 318, 319, 5, 119, 0, 0, 319, 320, 5, 104, 0, 0, 320, 321, 5, 101, 0, 0, 321, 322, 5, 110, 0, 0, 322, 80, 1, 0, 0, 0, 323, 324, 5, 101, 0, 0, 324, 325, 5, 108, 0, 0, 325, 326, 5, 115, 0, 0, 326, 327, 5, 101, 0, 0, 327, 328, 5, 119, 0, 0, 328, 329, 5, 104, 0, 0, 329, 330, 5, 101, 0, 0, 330, 331, 5, 110, 0, 0, 331, 82, 1, 0, 0, 0, 332, 333, 5, 119, 0, 0, 333, 334, 5, 104, 0, 0, 334, 335, 5, 105, 0, 0, 335, 336, 5, 108, 0, 0, 336, 337, 5, 101, 0, 0, 337, 84, 1, 0, 0, 0, 338, 339, 5, 108, 0, 0, 339, 340, 5, 111, 0, 0, 340, 341, 5, 111, 0, 0, 341, 342, 5, 112, 0, 0, 342, 86, 1, 0, 0, 0, 343, 344, 5, 98, 0, 0, 344, 345, 5, 114, 0, 0, 345, 346, 5, 101, 0, 0, 346, 347, 5, 97, 0, 0, 347, 348, 5, 107, 0, 0, 348, 88, 1, 0, 0, 0, 349, 350, 5, 114, 0, 0, 350, 351, 5, 101, 0, 0, 351, 352, 5, 116, 0, 0, 352, 353, 5, 117, 0, 0, 353, 354, 5, 114, 0, 0, 354, 355, 5, 110, 0, 0, 355, 90, 1, 0, 0, 0, 356, 357, 5, 112, 0, 0, 357, 358, 5, 97, 0, 0, 358, 359, 5, 114, 0, 0, 359, 360, 5, 116, 0, 0, 360, 361, 5, 105, 0, 0, 361, 362, 5, 97, 0, 0, 362, 363, 5, 108, 0, 0, 363, 92, 1, 0, 0, 0, 364, 365, 5, 111, 0, 0, 365, 366, 5, 112, 0, 0, 366, 367, 5, 101, 0, 0, 367, 368, 5, 114, 0, 0, 368, 369, 5, 97, 0, 0, 369, 370, 5, 116, 0, 0, 370, 371, 5, 111, 0, 0, 371, 372, 5, 114, 0, 0, 372, 94, 1, 0, 0, 0, 373, 374, 5, 101, 0, 0, 374, 375, 5, 120, 0, 0, 375, 376, 5, 112, 0, 0, 376, 377, 5, 97, 0, 0, 377, 378, 5, 110, 0, 0, 378, 379, 5, 100, 0, 0, 379, 380, 5, 97, 0, 0, 380, 381, 5, 98, 0, 0, 381, 382, 5, 108, 0, 0, 382, 383, 5, 101, 0, 0, 383, 96, 1, 0, 0, 0, 384, 385, 5, 99, 0, 0, 385, 386, 5, 108, 0, 0, 386, 387, 5, 97, 0, 0, 387, 388, 5, 115, 0, 0, 388, 389, 5, 115, 0, 0, 389, 98, 1, 0, 0, 0, 390, 391, 5, 109, 0, 0, 391, 392, 5, 111, 0, 0, 392, 393, 5, 100, 0, 0, 393, 394, 5, 101, 0, 0, 394, 395, 5, 108, 0, 0, 395, 100, 1, 0, 0, 0, 396, 397, 5, 102, 0, 0, 397, 398, 5, 117, 0, 0, 398, 399, 5, 110, 0, 0, 399, 400, 5, 99, 0, 0, 400, 401, 5, 116, 0, 0, 401, 402, 5, 105, 0, 0, 402, 403, 5, 111, 0, 0, 403, 404, 5, 110, 0, 0, 404, 102, 1, 0, 0, 0, 405, 406, 5, 114, 0, 0, 406, 407, 5, 101, 0, 0, 407, 408, 5, 99, 0, 0, 408, 409, 5, 111, 0, 0, 409, 410, 5, 114, 0, 0, 410, 411, 5, 100, 0, 0, 411, 104, 1, 0, 0, 0, 412, 413, 5, 116, 0, 0, 413, 414, 5, 121, 0, 0, 414, 415, 5, 112, 0, 0, 415, 416, 5, 101, 0, 0, 416, 106, 1, 0, 0, 0, 417, 418, 5, 98, 0, 0, 418, 419, 5, 108, 0, 0, 419, 420, 5, 111, 0, 0, 420, 421, 5, 99, 0, 0, 421, 422, 5, 107, 0, 0, 422, 108, 1, 0, 0, 0, 423, 424, 5, 99, 0, 0, 424, 425, 5, 111, 0, 0, 425, 426, 5, 110, 0, 0, 426, 427, 5, 110, 0, 0, 427, 428, 5, 101, 0, 0, 428, 429, 5, 99, 0, 0, 429, 430, 5, 116, 0, 0, 430, 431, 5, 111, 0, 0, 431, 432, 5, 114, 0, 0, 432, 110, 1, 0, 0, 0, 433, 434, 5, 112, 0, 0, 434, 435, 5, 97, 0, 0, 435, 436, 5, 99, 0, 0, 436, 437, 5, 107, 0, 0, 437, 438, 5, 97, 0, 0, 438, 439, 5, 103, 0, 0, 439, 440, 5, 101, 0, 0, 440, 112, 1, 0, 0, 0, 441, 442, 5, 112, 0, 0, 442, 443, 5, 117, 0, 0, 443, 444, 5, 114, 0, 0, 444, 445, 5, 101, 0, 0, 445, 114, 1, 0, 0, 0, 446, 447, 5, 105, 0, 0, 447, 448, 5, 109, 0, 0, 448, 449, 5, 112, 0, 0, 449, 450, 5, 117, 0, 0, 450, 451, 5, 114, 0, 0, 451, 452, 5, 101, 0, 0, 452, 116, 1, 0, 0, 0, 453, 454, 5, 101, 0, 0, 454, 455, 5, 110, 0, 0, 455, 456, 5, 100, 0, 0, 456, 118, 1, 0, 0, 0, 457, 458, 5, 100, 0, 0, 458, 459, 5, 101, 0, 0, 459, 460, 5, 114, 0, 0, 460, 120, 1, 0, 0, 0, 461, 462, 5, 99, 0, 0, 462, 463, 5, 111, 0, 0, 463, 464, 5, 110, 0, 0, 464, 465, 5, 110, 0, 0, 465, 466, 5, 101, 0, 0, 466, 467, 5, 99, 0, 0, 467, 468, 5, 116, 0, 0, 468, 122, 1, 0, 0, 0, 469, 470, 5, 105, 0, 0, 470, 471, 5, 110, 0, 0, 471, 472, 5, 105, 0, 0, 472, 473, 5, 116, 0, 0, 473, 474, 5, 105, 0, 0, 474, 475, 5, 97, 0, 0, 475, 476, 5, 108, 0, 0, 476, 124, 1, 0, 0, 0, 477, 478, 5, 101, 0, 0, 478, 479, 5, 113, 0, 0, 479, 480, 5, 117, 0, 0, 480, 481, 5, 97, 0, 0, 481, 482, 5, 116, 0, 0, 482, 483, 5, 105, 0, 0, 483, 484, 5, 111, 0, 0, 484, 485, 5, 110, 0, 0, 485, 126, 1, 0, 0, 0, 486, 487, 5, 97, 0, 0, 487, 488, 5, 108, 0, 0, 488, 489, 5, 103, 0, 0, 489, 490, 5, 111, 0, 0, 490, 491, 5, 114, 0, 0, 491, 492, 5, 105, 0, 0, 492, 493, 5, 116, 0, 0, 493, 494, 5, 104, 0, 0, 494, 495, 5, 109, 0, 0, 495, 128, 1, 0, 0, 0, 496, 497, 5, 119, 0, 0, 497, 498, 5, 105, 0, 0, 498, 499, 5, 116, 0, 0, 499, 500, 5, 104, 0, 0, 500, 501, 5, 105, 0, 0, 501, 502, 5, 110, 0, 0, 502, 130, 1, 0, 0, 0, 503, 504, 5, 102, 0, 0, 504, 505, 5, 105, 0, 0, 505, 506, 5, 110, 0, 0, 506, 507, 5, 97, 0, 0, 507, 508, 5, 108, 0, 0, 508, 132, 1, 0, 0, 0, 509, 510, 5, 101, 0, 0, 510, 511, 5, 110, 0, 0, 511, 512, 5, 99, 0, 0, 512, 513, 5, 97, 0, 0, 513, 514, 5, 112, 0, 0, 514, 515, 5, 115, 0, 0, 515, 516, 5, 117, 0, 0, 516, 517, 5, 108, 0, 0, 517, 518, 5, 97, 0, 0, 518, 519, 5, 116, 0, 0, 519, 520, 5, 101, 0, 0, 520, 521, 5, 100, 0, 0, 521, 134, 1, 0, 0, 0, 522, 523, 5, 101, 0, 0, 523, 524, 5, 120, 0, 0, 524, 525, 5, 116, 0, 0, 525, 526, 5, 101, 0, 0, 526, 527, 5, 110, 0, 0, 527, 528, 5, 100, 0, 0, 528, 529, 5, 115, 0, 0, 529, 136, 1, 0, 0, 0, 530, 531, 5, 105, 0, 0, 531, 532, 5, 109, 0, 0, 532, 533, 5, 112, 0, 0, 533, 534, 5, 111, 0, 0, 534, 535, 5, 114, 0, 0, 535, 536, 5, 116, 0, 0, 536, 138, 1, 0, 0, 0, 537, 538, 5, 101, 0, 0, 538, 539, 5, 110, 0, 0, 539, 540, 5, 117, 0, 0, 540, 541, 5, 109, 0, 0, 541, 542, 5, 101, 0, 0, 542, 543, 5, 114, 0, 0, 543, 544, 5, 97, 0, 0, 544, 545, 5, 116, 0, 0, 545, 546, 5, 105, 0, 0, 546, 547, 5, 111, 0, 0, 547, 548, 5, 110, 0, 0, 548, 140, 1, 0, 0, 0, 549, 550, 5, 105, 0, 0, 550, 551, 5, 110, 0, 0, 551, 552, 5, 112, 0, 0, 552, 553, 5, 117, 0, 0, 553, 554, 5, 116, 0, 0, 554, 142, 1, 0, 0, 0, 555, 556, 5, 111, 0, 0, 556, 557, 5, 117, 0, 0, 557, 558, 5, 116, 0, 0, 558, 559, 5, 112, 0, 0, 559, 560, 5, 117, 0, 0, 560, 561, 5, 116, 0, 0, 561, 144, 1, 0, 0, 0, 562, 563, 5, 112, 0, 0, 563, 564, 5, 117, 0, 0, 564, 565, 5, 98, 0, 0, 565, 566, 5, 108, 0, 0, 566, 567, 5, 105, 0, 0, 567, 568, 5, 99, 0, 0, 568, 146, 1, 0, 0, 0, 569, 570, 5, 112, 0, 0, 570, 571, 5, 114, 0, 0, 571, 572, 5, 111, 0, 0, 572, 573, 5, 116, 0, 0, 573, 574, 5, 101, 0, 0, 574, 575, 5, 99, 0, 0, 575, 576, 5, 116, 0, 0, 576, 577, 5, 101, 0, 0, 577, 578, 5, 100, 0, 0, 578, 148, 1, 0, 0, 0, 579, 580, 5, 114, 0, 0, 580, 581, 5, 101, 0, 0, 581, 582, 5, 100, 0, 0, 582, 583, 5, 101, 0, 0, 583, 584, 5, 99, 0, 0, 584, 585, 5, 108, 0, 0, 585, 586, 5, 97, 0, 0, 586, 587, 5, 114, 0, 0, 587, 588, 5, 101, 0, 0, 588, 150, 1, 0, 0, 0, 589, 590, 5, 105, 0, 0, 590, 591, 5, 110, 0, 0, 591, 592, 5, 110, 0, 0, 592, 593, 5, 101, 0, 0, 593, 594, 5, 114, 0, 0, 594, 152, 1, 0, 0, 0, 595, 596, 5, 111, 0, 0, 596, 597, 5, 117, 0, 0, 597, 598, 5, 116, 0, 0, 598, 599, 5, 101, 0, 0, 599, 600, 5, 114, 0, 0, 600, 154, 1, 0, 0, 0, 601, 602, 5, 114, 0, 0, 602, 603, 5, 101, 0, 0, 603, 604, 5, 112, 0, 0, 604, 605, 5, 108, 0, 0, 605, 606, 5, 97, 0, 0, 606, 607, 5, 99, 0, 0, 607, 608, 5, 101, 0, 0, 608, 609, 5, 97, 0, 0, 609, 610, 5, 98, 0, 0, 610, 611, 5, 108, 0, 0, 611, 612, 5, 101, 0, 0, 612, 156, 1, 0, 0, 0, 613, 614, 5, 99, 0, 0, 614, 615, 5, 111, 0, 0, 615, 616, 5, 110, 0, 0, 616, 617, 5, 115, 0, 0, 617, 618, 5, 116, 0, 0, 618, 619, 5, 114, 0, 0, 619, 620, 5, 97, 0, 0, 620, 621, 5, 105, 0, 0, 621, 622, 5, 110, 0, 0, 622, 623, 5, 101, 0, 0, 623, 624, 5, 100, 0, 0, 624, 625, 5, 98, 0, 0, 625, 626, 5, 121, 0, 0, 626, 158, 1, 0, 0, 0, 627, 628, 5, 102, 0, 0, 628, 629, 5, 108, 0, 0, 629, 630, 5, 111, 0, 0, 630, 631, 5, 119, 0, 0, 631, 160, 1, 0, 0, 0, 632, 633, 5, 115, 0, 0, 633, 634, 5, 116, 0, 0, 634, 635, 5, 114, 0, 0, 635, 636, 5, 101, 0, 0, 636, 637, 5, 97, 0, 0, 637, 638, 5, 109, 0, 0, 638, 162, 1, 0, 0, 0, 639, 640, 5, 100, 0, 0, 640, 641, 5, 105, 0, 0, 641, 642, 5, 115, 0, 0, 642, 643, 5, 99, 0, 0, 643, 644, 5, 114, 0, 0, 644, 645, 5, 101, 0, 0, 645, 646, 5, 116, 0, 0, 646, 647, 5, 101, 0, 0, 647, 164, 1, 0, 0, 0, 648, 649, 5, 112, 0, 0, 649, 650, 5, 97, 0, 0, 650, 651, 5, 114, 0, 0, 651, 652, 5, 97, 0, 0, 652, 653, 5, 109, 0, 0, 653, 654, 5, 101, 0, 0, 654, 655, 5, 116, 0, 0, 655, 656, 5, 101, 0, 0, 656, 657, 5, 114, 0, 0, 657, 166, 1, 0, 0, 0, 658, 659, 5, 99, 0, 0, 659, 660, 5, 111, 0, 0, 660, 661, 5, 110, 0, 0, 661, 662, 5, 115, 0, 0, 662, 663, 5, 116, 0, 0, 663, 664, 5, 97, 0, 0, 664, 665, 5, 110, 0, 0, 665, 666, 5, 116, 0, 0, 666, 168, 1, 0, 0, 0, 667, 668, 5, 101, 0, 0, 668, 669, 5, 97, 0, 0, 669, 670, 5, 99, 0, 0, 670, 671, 5, 104, 0, 0, 671, 170, 1, 0, 0, 0, 672, 673, 5, 97, 0, 0, 673, 674, 5, 110, 0, 0, 674, 675, 5, 110, 0, 0, 675, 676, 5, 111, 0, 0, 676, 677, 5, 116, 0, 0, 677, 678, 5, 97, 0, 0, 678, 679, 5, 116, 0, 0, 679, 680, 5, 105, 0, 0, 680, 681, 5, 111, 0, 0, 681, 682, 5, 110, 0, 0, 682, 172, 1, 0, 0, 0, 683, 684, 5, 101, 0, 0, 684, 685, 5, 120, 0, 0, 685, 686, 5, 116, 0, 0, 686, 687, 5, 101, 0, 0, 687, 688, 5, 114, 0, 0, 688, 689, 5, 110, 0, 0, 689, 690, 5, 97, 0, 0, 690, 691, 5, 108, 0, 0, 691, 174, 1, 0, 0, 0, 692, 693, 5, 47, 0, 0, 693, 694, 5, 42, 0, 0, 694, 698, 1, 0, 0, 0, 695, 697, 9, 0, 0, 0, 696, 695, 1, 0, 0, 0, 697, 700, 1, 0, 0, 0, 698, 699, 1, 0, 0, 0, 698, 696, 1, 0, 0, 0, 699, 701, 1, 0, 0, 0, 700, 698, 1, 0, 0, 0, 701, 702, 5, 42, 0, 0, 702, 703, 5, 47, 0, 0, 703, 704, 1, 0, 0, 0, 704, 705, 6, 87, 1, 0, 705, 176, 1, 0, 0, 0, 706, 707, 5, 47, 0, 0, 707, 708, 5, 47, 0, 0, 708, 712, 1, 0, 0, 0, 709, 711, 8, 1, 0, 0, 710, 709, 1, 0, 0, 0, 711, 714, 1, 0, 0, 0, 712, 710, 1, 0, 0, 0, 712, 713, 1, 0, 0, 0, 713, 715, 1, 0, 0, 0, 714, 712, 1, 0, 0, 0, 715, 716, 6, 88, 1, 0, 716, 178, 1, 0, 0, 0, 717, 718, 5, 92, 0, 0, 718, 719, 7, 2, 0, 0, 719, 180, 1, 0, 0, 0, 720, 721, 7, 3, 0, 0, 721, 182, 1, 0, 0, 0, 722, 723, 7, 4, 0, 0, 723, 184, 1, 0, 0, 0, 724, 728, 3, 183, 91, 0, 725, 728, 3, 181, 90, 0, 726, 728, 7, 5, 0, 0, 727, 724, 1, 0, 0, 0, 727, 725, 1, 0, 0, 0, 727, 726, 1, 0, 0, 0, 728, 186, 1, 0, 0, 0, 729, 734, 5, 39, 0, 0, 730, 733, 3, 185, 92, 0, 731, 733, 3, 179, 89, 0, 732, 730, 1, 0, 0, 0, 732, 731, 1, 0, 0, 0, 733, 736, 1, 0, 0, 0, 734, 732, 1, 0, 0, 0, 734, 735, 1, 0, 0, 0, 735, 737, 1, 0, 0, 0, 736, 734, 1, 0, 0, 0, 737, 738, 5, 39, 0, 0, 738, 188, 1, 0, 0, 0, 739, 740, 8, 6, 0, 0, 740, 190, 1, 0, 0, 0, 741, 742, 7, 7, 0, 0, 742, 192, 1, 0, 0, 0, 743, 745, 3, 181, 90, 0, 744, 743, 1, 0, 0, 0, 745, 746, 1, 0, 0, 0, 746, 744, 1, 0, 0, 0, 746, 747, 1, 0, 0, 0, 747, 194, 1, 0, 0, 0, 748, 753, 3, 193, 96, 0, 749, 751, 3, 7, 3, 0, 750, 752, 3, 193, 96, 0, 751, 750, 1, 0, 0, 0, 751, 752, 1, 0, 0, 0, 752, 754, 1, 0, 0, 0, 753, 749, 1, 0, 0, 0, 753, 754, 1, 0, 0, 0, 754, 762, 1, 0, 0, 0, 755, 758, 3, 191, 95, 0, 756, 759, 3, 29, 14, 0, 757, 759, 3, 31, 15, 0, 758, 756, 1, 0, 0, 0, 758, 757, 1, 0, 0, 0, 758, 759, 1, 0, 0, 0, 759, 760, 1, 0, 0, 0, 760, 761, 3, 193, 96, 0, 761, 763, 1, 0, 0, 0, 762, 755, 1, 0, 0, 0, 762, 763, 1, 0, 0, 0, 763, 196, 1, 0, 0, 0, 764, 769, 3, 3, 1, 0, 765, 768, 3, 189, 94, 0, 766, 768, 3, 179, 89, 0, 767, 765, 1, 0, 0, 0, 767, 766, 1, 0, 0, 0, 768, 771, 1, 0, 0, 0, 769, 767, 1, 0, 0, 0, 769, 770, 1, 0, 0, 0, 770, 772, 1, 0, 0, 0, 771, 769, 1, 0, 0, 0, 772, 773, 3, 3, 1, 0, 773, 198, 1, 0, 0, 0, 774, 777, 3, 195, 97, 0, 775, 777, 3, 193, 96, 0, 776, 774, 1, 0, 0, 0, 776, 775, 1, 0, 0, 0, 777, 200, 1, 0, 0, 0, 778, 779, 5, 116, 0, 0, 779, 780, 5, 114, 0, 0, 780, 781, 5, 117, 0, 0, 781, 788, 5, 101, 0, 0, 782, 783, 5, 102, 0, 0, 783, 784, 5, 97, 0, 0, 784, 785, 5, 108, 0, 0, 785, 786, 5, 115, 0, 0, 786, 788, 5, 101, 0, 0, 787, 778, 1, 0, 0, 0, 787, 782, 1, 0, 0, 0, 788, 202, 1, 0, 0, 0, 789, 794, 3, 183, 91, 0, 790, 793, 3, 181, 90, 0, 791, 793, 3, 183, 91, 0, 792, 790, 1, 0, 0, 0, 792, 791, 1, 0, 0, 0, 793, 796, 1, 0, 0, 0, 794, 792, 1, 0, 0, 0, 794, 795, 1, 0, 0, 0, 795, 799, 1, 0, 0, 0, 796, 794, 1, 0, 0, 0, 797, 799, 3, 187, 93, 0, 798, 789, 1, 0, 0, 0, 798, 797, 1, 0, 0, 0, 799, 204, 1, 0, 0, 0, 19, 0, 208, 698, 712, 727, 732, 734, 746, 751, 753, 758, 762, 767, 769, 776, 787, 792, 794, 798, 2, 0, 2, 0, 0, 3, 0] diff --git a/mofmt/parsing/generated/ModelicaLexer.py b/mofmt/parsing/generated/ModelicaLexer.py deleted file mode 100644 index 34b3378..0000000 --- a/mofmt/parsing/generated/ModelicaLexer.py +++ /dev/null @@ -1,7224 +0,0 @@ -# Generated from grammar/ModelicaLexer.g4 by ANTLR 4.13.0 -import sys -from io import StringIO - -from antlr4 import * - -if sys.version_info[1] > 5: - from typing import TextIO -else: - from typing.io import TextIO - - -def serializedATN(): - return [ - 4, - 0, - 93, - 800, - 6, - -1, - 2, - 0, - 7, - 0, - 2, - 1, - 7, - 1, - 2, - 2, - 7, - 2, - 2, - 3, - 7, - 3, - 2, - 4, - 7, - 4, - 2, - 5, - 7, - 5, - 2, - 6, - 7, - 6, - 2, - 7, - 7, - 7, - 2, - 8, - 7, - 8, - 2, - 9, - 7, - 9, - 2, - 10, - 7, - 10, - 2, - 11, - 7, - 11, - 2, - 12, - 7, - 12, - 2, - 13, - 7, - 13, - 2, - 14, - 7, - 14, - 2, - 15, - 7, - 15, - 2, - 16, - 7, - 16, - 2, - 17, - 7, - 17, - 2, - 18, - 7, - 18, - 2, - 19, - 7, - 19, - 2, - 20, - 7, - 20, - 2, - 21, - 7, - 21, - 2, - 22, - 7, - 22, - 2, - 23, - 7, - 23, - 2, - 24, - 7, - 24, - 2, - 25, - 7, - 25, - 2, - 26, - 7, - 26, - 2, - 27, - 7, - 27, - 2, - 28, - 7, - 28, - 2, - 29, - 7, - 29, - 2, - 30, - 7, - 30, - 2, - 31, - 7, - 31, - 2, - 32, - 7, - 32, - 2, - 33, - 7, - 33, - 2, - 34, - 7, - 34, - 2, - 35, - 7, - 35, - 2, - 36, - 7, - 36, - 2, - 37, - 7, - 37, - 2, - 38, - 7, - 38, - 2, - 39, - 7, - 39, - 2, - 40, - 7, - 40, - 2, - 41, - 7, - 41, - 2, - 42, - 7, - 42, - 2, - 43, - 7, - 43, - 2, - 44, - 7, - 44, - 2, - 45, - 7, - 45, - 2, - 46, - 7, - 46, - 2, - 47, - 7, - 47, - 2, - 48, - 7, - 48, - 2, - 49, - 7, - 49, - 2, - 50, - 7, - 50, - 2, - 51, - 7, - 51, - 2, - 52, - 7, - 52, - 2, - 53, - 7, - 53, - 2, - 54, - 7, - 54, - 2, - 55, - 7, - 55, - 2, - 56, - 7, - 56, - 2, - 57, - 7, - 57, - 2, - 58, - 7, - 58, - 2, - 59, - 7, - 59, - 2, - 60, - 7, - 60, - 2, - 61, - 7, - 61, - 2, - 62, - 7, - 62, - 2, - 63, - 7, - 63, - 2, - 64, - 7, - 64, - 2, - 65, - 7, - 65, - 2, - 66, - 7, - 66, - 2, - 67, - 7, - 67, - 2, - 68, - 7, - 68, - 2, - 69, - 7, - 69, - 2, - 70, - 7, - 70, - 2, - 71, - 7, - 71, - 2, - 72, - 7, - 72, - 2, - 73, - 7, - 73, - 2, - 74, - 7, - 74, - 2, - 75, - 7, - 75, - 2, - 76, - 7, - 76, - 2, - 77, - 7, - 77, - 2, - 78, - 7, - 78, - 2, - 79, - 7, - 79, - 2, - 80, - 7, - 80, - 2, - 81, - 7, - 81, - 2, - 82, - 7, - 82, - 2, - 83, - 7, - 83, - 2, - 84, - 7, - 84, - 2, - 85, - 7, - 85, - 2, - 86, - 7, - 86, - 2, - 87, - 7, - 87, - 2, - 88, - 7, - 88, - 2, - 89, - 7, - 89, - 2, - 90, - 7, - 90, - 2, - 91, - 7, - 91, - 2, - 92, - 7, - 92, - 2, - 93, - 7, - 93, - 2, - 94, - 7, - 94, - 2, - 95, - 7, - 95, - 2, - 96, - 7, - 96, - 2, - 97, - 7, - 97, - 2, - 98, - 7, - 98, - 2, - 99, - 7, - 99, - 2, - 100, - 7, - 100, - 2, - 101, - 7, - 101, - 1, - 0, - 4, - 0, - 207, - 8, - 0, - 11, - 0, - 12, - 0, - 208, - 1, - 0, - 1, - 0, - 1, - 1, - 1, - 1, - 1, - 2, - 1, - 2, - 1, - 3, - 1, - 3, - 1, - 4, - 1, - 4, - 1, - 5, - 1, - 5, - 1, - 6, - 1, - 6, - 1, - 7, - 1, - 7, - 1, - 8, - 1, - 8, - 1, - 9, - 1, - 9, - 1, - 10, - 1, - 10, - 1, - 11, - 1, - 11, - 1, - 12, - 1, - 12, - 1, - 13, - 1, - 13, - 1, - 13, - 1, - 14, - 1, - 14, - 1, - 15, - 1, - 15, - 1, - 16, - 1, - 16, - 1, - 17, - 1, - 17, - 1, - 18, - 1, - 18, - 1, - 19, - 1, - 19, - 1, - 19, - 1, - 20, - 1, - 20, - 1, - 20, - 1, - 21, - 1, - 21, - 1, - 21, - 1, - 22, - 1, - 22, - 1, - 22, - 1, - 23, - 1, - 23, - 1, - 23, - 1, - 24, - 1, - 24, - 1, - 25, - 1, - 25, - 1, - 25, - 1, - 26, - 1, - 26, - 1, - 27, - 1, - 27, - 1, - 27, - 1, - 28, - 1, - 28, - 1, - 28, - 1, - 29, - 1, - 29, - 1, - 29, - 1, - 30, - 1, - 30, - 1, - 30, - 1, - 30, - 1, - 31, - 1, - 31, - 1, - 31, - 1, - 31, - 1, - 32, - 1, - 32, - 1, - 32, - 1, - 33, - 1, - 33, - 1, - 33, - 1, - 34, - 1, - 34, - 1, - 34, - 1, - 34, - 1, - 35, - 1, - 35, - 1, - 35, - 1, - 36, - 1, - 36, - 1, - 36, - 1, - 36, - 1, - 36, - 1, - 37, - 1, - 37, - 1, - 37, - 1, - 37, - 1, - 37, - 1, - 37, - 1, - 37, - 1, - 38, - 1, - 38, - 1, - 38, - 1, - 38, - 1, - 38, - 1, - 39, - 1, - 39, - 1, - 39, - 1, - 39, - 1, - 39, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 40, - 1, - 41, - 1, - 41, - 1, - 41, - 1, - 41, - 1, - 41, - 1, - 41, - 1, - 42, - 1, - 42, - 1, - 42, - 1, - 42, - 1, - 42, - 1, - 43, - 1, - 43, - 1, - 43, - 1, - 43, - 1, - 43, - 1, - 43, - 1, - 44, - 1, - 44, - 1, - 44, - 1, - 44, - 1, - 44, - 1, - 44, - 1, - 44, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 45, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 46, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 47, - 1, - 48, - 1, - 48, - 1, - 48, - 1, - 48, - 1, - 48, - 1, - 48, - 1, - 49, - 1, - 49, - 1, - 49, - 1, - 49, - 1, - 49, - 1, - 49, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 50, - 1, - 51, - 1, - 51, - 1, - 51, - 1, - 51, - 1, - 51, - 1, - 51, - 1, - 51, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 52, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 53, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 54, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 55, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 56, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 57, - 1, - 58, - 1, - 58, - 1, - 58, - 1, - 58, - 1, - 59, - 1, - 59, - 1, - 59, - 1, - 59, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 60, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 61, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 62, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 63, - 1, - 64, - 1, - 64, - 1, - 64, - 1, - 64, - 1, - 64, - 1, - 64, - 1, - 64, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 65, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 66, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 67, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 68, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 69, - 1, - 70, - 1, - 70, - 1, - 70, - 1, - 70, - 1, - 70, - 1, - 70, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 71, - 1, - 72, - 1, - 72, - 1, - 72, - 1, - 72, - 1, - 72, - 1, - 72, - 1, - 72, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 73, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 74, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 75, - 1, - 76, - 1, - 76, - 1, - 76, - 1, - 76, - 1, - 76, - 1, - 76, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 77, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 78, - 1, - 79, - 1, - 79, - 1, - 79, - 1, - 79, - 1, - 79, - 1, - 80, - 1, - 80, - 1, - 80, - 1, - 80, - 1, - 80, - 1, - 80, - 1, - 80, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 81, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 82, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 83, - 1, - 84, - 1, - 84, - 1, - 84, - 1, - 84, - 1, - 84, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 85, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 86, - 1, - 87, - 1, - 87, - 1, - 87, - 1, - 87, - 5, - 87, - 697, - 8, - 87, - 10, - 87, - 12, - 87, - 700, - 9, - 87, - 1, - 87, - 1, - 87, - 1, - 87, - 1, - 87, - 1, - 87, - 1, - 88, - 1, - 88, - 1, - 88, - 1, - 88, - 5, - 88, - 711, - 8, - 88, - 10, - 88, - 12, - 88, - 714, - 9, - 88, - 1, - 88, - 1, - 88, - 1, - 89, - 1, - 89, - 1, - 89, - 1, - 90, - 1, - 90, - 1, - 91, - 1, - 91, - 1, - 92, - 1, - 92, - 1, - 92, - 3, - 92, - 728, - 8, - 92, - 1, - 93, - 1, - 93, - 1, - 93, - 5, - 93, - 733, - 8, - 93, - 10, - 93, - 12, - 93, - 736, - 9, - 93, - 1, - 93, - 1, - 93, - 1, - 94, - 1, - 94, - 1, - 95, - 1, - 95, - 1, - 96, - 4, - 96, - 745, - 8, - 96, - 11, - 96, - 12, - 96, - 746, - 1, - 97, - 1, - 97, - 1, - 97, - 3, - 97, - 752, - 8, - 97, - 3, - 97, - 754, - 8, - 97, - 1, - 97, - 1, - 97, - 1, - 97, - 3, - 97, - 759, - 8, - 97, - 1, - 97, - 1, - 97, - 3, - 97, - 763, - 8, - 97, - 1, - 98, - 1, - 98, - 1, - 98, - 5, - 98, - 768, - 8, - 98, - 10, - 98, - 12, - 98, - 771, - 9, - 98, - 1, - 98, - 1, - 98, - 1, - 99, - 1, - 99, - 3, - 99, - 777, - 8, - 99, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 1, - 100, - 3, - 100, - 788, - 8, - 100, - 1, - 101, - 1, - 101, - 1, - 101, - 5, - 101, - 793, - 8, - 101, - 10, - 101, - 12, - 101, - 796, - 9, - 101, - 1, - 101, - 3, - 101, - 799, - 8, - 101, - 1, - 698, - 0, - 102, - 1, - 1, - 3, - 2, - 5, - 3, - 7, - 4, - 9, - 5, - 11, - 6, - 13, - 7, - 15, - 8, - 17, - 9, - 19, - 10, - 21, - 11, - 23, - 12, - 25, - 13, - 27, - 14, - 29, - 15, - 31, - 16, - 33, - 17, - 35, - 18, - 37, - 19, - 39, - 20, - 41, - 21, - 43, - 22, - 45, - 23, - 47, - 24, - 49, - 25, - 51, - 26, - 53, - 27, - 55, - 28, - 57, - 29, - 59, - 30, - 61, - 31, - 63, - 32, - 65, - 33, - 67, - 34, - 69, - 35, - 71, - 36, - 73, - 37, - 75, - 38, - 77, - 39, - 79, - 40, - 81, - 41, - 83, - 42, - 85, - 43, - 87, - 44, - 89, - 45, - 91, - 46, - 93, - 47, - 95, - 48, - 97, - 49, - 99, - 50, - 101, - 51, - 103, - 52, - 105, - 53, - 107, - 54, - 109, - 55, - 111, - 56, - 113, - 57, - 115, - 58, - 117, - 59, - 119, - 60, - 121, - 61, - 123, - 62, - 125, - 63, - 127, - 64, - 129, - 65, - 131, - 66, - 133, - 67, - 135, - 68, - 137, - 69, - 139, - 70, - 141, - 71, - 143, - 72, - 145, - 73, - 147, - 74, - 149, - 75, - 151, - 76, - 153, - 77, - 155, - 78, - 157, - 79, - 159, - 80, - 161, - 81, - 163, - 82, - 165, - 83, - 167, - 84, - 169, - 85, - 171, - 86, - 173, - 87, - 175, - 88, - 177, - 89, - 179, - 0, - 181, - 0, - 183, - 0, - 185, - 0, - 187, - 0, - 189, - 0, - 191, - 0, - 193, - 0, - 195, - 0, - 197, - 90, - 199, - 91, - 201, - 92, - 203, - 93, - 1, - 0, - 8, - 3, - 0, - 9, - 10, - 13, - 13, - 32, - 32, - 2, - 0, - 10, - 10, - 13, - 13, - 10, - 0, - 34, - 34, - 39, - 39, - 63, - 63, - 92, - 92, - 97, - 98, - 102, - 102, - 110, - 110, - 114, - 114, - 116, - 116, - 118, - 118, - 1, - 0, - 48, - 57, - 3, - 0, - 65, - 90, - 95, - 95, - 97, - 122, - 6, - 0, - 32, - 38, - 40, - 47, - 58, - 64, - 91, - 91, - 93, - 94, - 123, - 126, - 2, - 0, - 34, - 34, - 92, - 92, - 2, - 0, - 69, - 69, - 101, - 101, - 810, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 3, - 1, - 0, - 0, - 0, - 0, - 5, - 1, - 0, - 0, - 0, - 0, - 7, - 1, - 0, - 0, - 0, - 0, - 9, - 1, - 0, - 0, - 0, - 0, - 11, - 1, - 0, - 0, - 0, - 0, - 13, - 1, - 0, - 0, - 0, - 0, - 15, - 1, - 0, - 0, - 0, - 0, - 17, - 1, - 0, - 0, - 0, - 0, - 19, - 1, - 0, - 0, - 0, - 0, - 21, - 1, - 0, - 0, - 0, - 0, - 23, - 1, - 0, - 0, - 0, - 0, - 25, - 1, - 0, - 0, - 0, - 0, - 27, - 1, - 0, - 0, - 0, - 0, - 29, - 1, - 0, - 0, - 0, - 0, - 31, - 1, - 0, - 0, - 0, - 0, - 33, - 1, - 0, - 0, - 0, - 0, - 35, - 1, - 0, - 0, - 0, - 0, - 37, - 1, - 0, - 0, - 0, - 0, - 39, - 1, - 0, - 0, - 0, - 0, - 41, - 1, - 0, - 0, - 0, - 0, - 43, - 1, - 0, - 0, - 0, - 0, - 45, - 1, - 0, - 0, - 0, - 0, - 47, - 1, - 0, - 0, - 0, - 0, - 49, - 1, - 0, - 0, - 0, - 0, - 51, - 1, - 0, - 0, - 0, - 0, - 53, - 1, - 0, - 0, - 0, - 0, - 55, - 1, - 0, - 0, - 0, - 0, - 57, - 1, - 0, - 0, - 0, - 0, - 59, - 1, - 0, - 0, - 0, - 0, - 61, - 1, - 0, - 0, - 0, - 0, - 63, - 1, - 0, - 0, - 0, - 0, - 65, - 1, - 0, - 0, - 0, - 0, - 67, - 1, - 0, - 0, - 0, - 0, - 69, - 1, - 0, - 0, - 0, - 0, - 71, - 1, - 0, - 0, - 0, - 0, - 73, - 1, - 0, - 0, - 0, - 0, - 75, - 1, - 0, - 0, - 0, - 0, - 77, - 1, - 0, - 0, - 0, - 0, - 79, - 1, - 0, - 0, - 0, - 0, - 81, - 1, - 0, - 0, - 0, - 0, - 83, - 1, - 0, - 0, - 0, - 0, - 85, - 1, - 0, - 0, - 0, - 0, - 87, - 1, - 0, - 0, - 0, - 0, - 89, - 1, - 0, - 0, - 0, - 0, - 91, - 1, - 0, - 0, - 0, - 0, - 93, - 1, - 0, - 0, - 0, - 0, - 95, - 1, - 0, - 0, - 0, - 0, - 97, - 1, - 0, - 0, - 0, - 0, - 99, - 1, - 0, - 0, - 0, - 0, - 101, - 1, - 0, - 0, - 0, - 0, - 103, - 1, - 0, - 0, - 0, - 0, - 105, - 1, - 0, - 0, - 0, - 0, - 107, - 1, - 0, - 0, - 0, - 0, - 109, - 1, - 0, - 0, - 0, - 0, - 111, - 1, - 0, - 0, - 0, - 0, - 113, - 1, - 0, - 0, - 0, - 0, - 115, - 1, - 0, - 0, - 0, - 0, - 117, - 1, - 0, - 0, - 0, - 0, - 119, - 1, - 0, - 0, - 0, - 0, - 121, - 1, - 0, - 0, - 0, - 0, - 123, - 1, - 0, - 0, - 0, - 0, - 125, - 1, - 0, - 0, - 0, - 0, - 127, - 1, - 0, - 0, - 0, - 0, - 129, - 1, - 0, - 0, - 0, - 0, - 131, - 1, - 0, - 0, - 0, - 0, - 133, - 1, - 0, - 0, - 0, - 0, - 135, - 1, - 0, - 0, - 0, - 0, - 137, - 1, - 0, - 0, - 0, - 0, - 139, - 1, - 0, - 0, - 0, - 0, - 141, - 1, - 0, - 0, - 0, - 0, - 143, - 1, - 0, - 0, - 0, - 0, - 145, - 1, - 0, - 0, - 0, - 0, - 147, - 1, - 0, - 0, - 0, - 0, - 149, - 1, - 0, - 0, - 0, - 0, - 151, - 1, - 0, - 0, - 0, - 0, - 153, - 1, - 0, - 0, - 0, - 0, - 155, - 1, - 0, - 0, - 0, - 0, - 157, - 1, - 0, - 0, - 0, - 0, - 159, - 1, - 0, - 0, - 0, - 0, - 161, - 1, - 0, - 0, - 0, - 0, - 163, - 1, - 0, - 0, - 0, - 0, - 165, - 1, - 0, - 0, - 0, - 0, - 167, - 1, - 0, - 0, - 0, - 0, - 169, - 1, - 0, - 0, - 0, - 0, - 171, - 1, - 0, - 0, - 0, - 0, - 173, - 1, - 0, - 0, - 0, - 0, - 175, - 1, - 0, - 0, - 0, - 0, - 177, - 1, - 0, - 0, - 0, - 0, - 197, - 1, - 0, - 0, - 0, - 0, - 199, - 1, - 0, - 0, - 0, - 0, - 201, - 1, - 0, - 0, - 0, - 0, - 203, - 1, - 0, - 0, - 0, - 1, - 206, - 1, - 0, - 0, - 0, - 3, - 212, - 1, - 0, - 0, - 0, - 5, - 214, - 1, - 0, - 0, - 0, - 7, - 216, - 1, - 0, - 0, - 0, - 9, - 218, - 1, - 0, - 0, - 0, - 11, - 220, - 1, - 0, - 0, - 0, - 13, - 222, - 1, - 0, - 0, - 0, - 15, - 224, - 1, - 0, - 0, - 0, - 17, - 226, - 1, - 0, - 0, - 0, - 19, - 228, - 1, - 0, - 0, - 0, - 21, - 230, - 1, - 0, - 0, - 0, - 23, - 232, - 1, - 0, - 0, - 0, - 25, - 234, - 1, - 0, - 0, - 0, - 27, - 236, - 1, - 0, - 0, - 0, - 29, - 239, - 1, - 0, - 0, - 0, - 31, - 241, - 1, - 0, - 0, - 0, - 33, - 243, - 1, - 0, - 0, - 0, - 35, - 245, - 1, - 0, - 0, - 0, - 37, - 247, - 1, - 0, - 0, - 0, - 39, - 249, - 1, - 0, - 0, - 0, - 41, - 252, - 1, - 0, - 0, - 0, - 43, - 255, - 1, - 0, - 0, - 0, - 45, - 258, - 1, - 0, - 0, - 0, - 47, - 261, - 1, - 0, - 0, - 0, - 49, - 264, - 1, - 0, - 0, - 0, - 51, - 266, - 1, - 0, - 0, - 0, - 53, - 269, - 1, - 0, - 0, - 0, - 55, - 271, - 1, - 0, - 0, - 0, - 57, - 274, - 1, - 0, - 0, - 0, - 59, - 277, - 1, - 0, - 0, - 0, - 61, - 280, - 1, - 0, - 0, - 0, - 63, - 284, - 1, - 0, - 0, - 0, - 65, - 288, - 1, - 0, - 0, - 0, - 67, - 291, - 1, - 0, - 0, - 0, - 69, - 294, - 1, - 0, - 0, - 0, - 71, - 298, - 1, - 0, - 0, - 0, - 73, - 301, - 1, - 0, - 0, - 0, - 75, - 306, - 1, - 0, - 0, - 0, - 77, - 313, - 1, - 0, - 0, - 0, - 79, - 318, - 1, - 0, - 0, - 0, - 81, - 323, - 1, - 0, - 0, - 0, - 83, - 332, - 1, - 0, - 0, - 0, - 85, - 338, - 1, - 0, - 0, - 0, - 87, - 343, - 1, - 0, - 0, - 0, - 89, - 349, - 1, - 0, - 0, - 0, - 91, - 356, - 1, - 0, - 0, - 0, - 93, - 364, - 1, - 0, - 0, - 0, - 95, - 373, - 1, - 0, - 0, - 0, - 97, - 384, - 1, - 0, - 0, - 0, - 99, - 390, - 1, - 0, - 0, - 0, - 101, - 396, - 1, - 0, - 0, - 0, - 103, - 405, - 1, - 0, - 0, - 0, - 105, - 412, - 1, - 0, - 0, - 0, - 107, - 417, - 1, - 0, - 0, - 0, - 109, - 423, - 1, - 0, - 0, - 0, - 111, - 433, - 1, - 0, - 0, - 0, - 113, - 441, - 1, - 0, - 0, - 0, - 115, - 446, - 1, - 0, - 0, - 0, - 117, - 453, - 1, - 0, - 0, - 0, - 119, - 457, - 1, - 0, - 0, - 0, - 121, - 461, - 1, - 0, - 0, - 0, - 123, - 469, - 1, - 0, - 0, - 0, - 125, - 477, - 1, - 0, - 0, - 0, - 127, - 486, - 1, - 0, - 0, - 0, - 129, - 496, - 1, - 0, - 0, - 0, - 131, - 503, - 1, - 0, - 0, - 0, - 133, - 509, - 1, - 0, - 0, - 0, - 135, - 522, - 1, - 0, - 0, - 0, - 137, - 530, - 1, - 0, - 0, - 0, - 139, - 537, - 1, - 0, - 0, - 0, - 141, - 549, - 1, - 0, - 0, - 0, - 143, - 555, - 1, - 0, - 0, - 0, - 145, - 562, - 1, - 0, - 0, - 0, - 147, - 569, - 1, - 0, - 0, - 0, - 149, - 579, - 1, - 0, - 0, - 0, - 151, - 589, - 1, - 0, - 0, - 0, - 153, - 595, - 1, - 0, - 0, - 0, - 155, - 601, - 1, - 0, - 0, - 0, - 157, - 613, - 1, - 0, - 0, - 0, - 159, - 627, - 1, - 0, - 0, - 0, - 161, - 632, - 1, - 0, - 0, - 0, - 163, - 639, - 1, - 0, - 0, - 0, - 165, - 648, - 1, - 0, - 0, - 0, - 167, - 658, - 1, - 0, - 0, - 0, - 169, - 667, - 1, - 0, - 0, - 0, - 171, - 672, - 1, - 0, - 0, - 0, - 173, - 683, - 1, - 0, - 0, - 0, - 175, - 692, - 1, - 0, - 0, - 0, - 177, - 706, - 1, - 0, - 0, - 0, - 179, - 717, - 1, - 0, - 0, - 0, - 181, - 720, - 1, - 0, - 0, - 0, - 183, - 722, - 1, - 0, - 0, - 0, - 185, - 727, - 1, - 0, - 0, - 0, - 187, - 729, - 1, - 0, - 0, - 0, - 189, - 739, - 1, - 0, - 0, - 0, - 191, - 741, - 1, - 0, - 0, - 0, - 193, - 744, - 1, - 0, - 0, - 0, - 195, - 748, - 1, - 0, - 0, - 0, - 197, - 764, - 1, - 0, - 0, - 0, - 199, - 776, - 1, - 0, - 0, - 0, - 201, - 787, - 1, - 0, - 0, - 0, - 203, - 798, - 1, - 0, - 0, - 0, - 205, - 207, - 7, - 0, - 0, - 0, - 206, - 205, - 1, - 0, - 0, - 0, - 207, - 208, - 1, - 0, - 0, - 0, - 208, - 206, - 1, - 0, - 0, - 0, - 208, - 209, - 1, - 0, - 0, - 0, - 209, - 210, - 1, - 0, - 0, - 0, - 210, - 211, - 6, - 0, - 0, - 0, - 211, - 2, - 1, - 0, - 0, - 0, - 212, - 213, - 5, - 34, - 0, - 0, - 213, - 4, - 1, - 0, - 0, - 0, - 214, - 215, - 5, - 44, - 0, - 0, - 215, - 6, - 1, - 0, - 0, - 0, - 216, - 217, - 5, - 46, - 0, - 0, - 217, - 8, - 1, - 0, - 0, - 0, - 218, - 219, - 5, - 59, - 0, - 0, - 219, - 10, - 1, - 0, - 0, - 0, - 220, - 221, - 5, - 58, - 0, - 0, - 221, - 12, - 1, - 0, - 0, - 0, - 222, - 223, - 5, - 40, - 0, - 0, - 223, - 14, - 1, - 0, - 0, - 0, - 224, - 225, - 5, - 41, - 0, - 0, - 225, - 16, - 1, - 0, - 0, - 0, - 226, - 227, - 5, - 123, - 0, - 0, - 227, - 18, - 1, - 0, - 0, - 0, - 228, - 229, - 5, - 125, - 0, - 0, - 229, - 20, - 1, - 0, - 0, - 0, - 230, - 231, - 5, - 91, - 0, - 0, - 231, - 22, - 1, - 0, - 0, - 0, - 232, - 233, - 5, - 93, - 0, - 0, - 233, - 24, - 1, - 0, - 0, - 0, - 234, - 235, - 5, - 61, - 0, - 0, - 235, - 26, - 1, - 0, - 0, - 0, - 236, - 237, - 5, - 58, - 0, - 0, - 237, - 238, - 5, - 61, - 0, - 0, - 238, - 28, - 1, - 0, - 0, - 0, - 239, - 240, - 5, - 43, - 0, - 0, - 240, - 30, - 1, - 0, - 0, - 0, - 241, - 242, - 5, - 45, - 0, - 0, - 242, - 32, - 1, - 0, - 0, - 0, - 243, - 244, - 5, - 42, - 0, - 0, - 244, - 34, - 1, - 0, - 0, - 0, - 245, - 246, - 5, - 47, - 0, - 0, - 246, - 36, - 1, - 0, - 0, - 0, - 247, - 248, - 5, - 94, - 0, - 0, - 248, - 38, - 1, - 0, - 0, - 0, - 249, - 250, - 5, - 46, - 0, - 0, - 250, - 251, - 5, - 43, - 0, - 0, - 251, - 40, - 1, - 0, - 0, - 0, - 252, - 253, - 5, - 46, - 0, - 0, - 253, - 254, - 5, - 45, - 0, - 0, - 254, - 42, - 1, - 0, - 0, - 0, - 255, - 256, - 5, - 46, - 0, - 0, - 256, - 257, - 5, - 42, - 0, - 0, - 257, - 44, - 1, - 0, - 0, - 0, - 258, - 259, - 5, - 46, - 0, - 0, - 259, - 260, - 5, - 47, - 0, - 0, - 260, - 46, - 1, - 0, - 0, - 0, - 261, - 262, - 5, - 46, - 0, - 0, - 262, - 263, - 5, - 94, - 0, - 0, - 263, - 48, - 1, - 0, - 0, - 0, - 264, - 265, - 5, - 62, - 0, - 0, - 265, - 50, - 1, - 0, - 0, - 0, - 266, - 267, - 5, - 62, - 0, - 0, - 267, - 268, - 5, - 61, - 0, - 0, - 268, - 52, - 1, - 0, - 0, - 0, - 269, - 270, - 5, - 60, - 0, - 0, - 270, - 54, - 1, - 0, - 0, - 0, - 271, - 272, - 5, - 60, - 0, - 0, - 272, - 273, - 5, - 61, - 0, - 0, - 273, - 56, - 1, - 0, - 0, - 0, - 274, - 275, - 5, - 60, - 0, - 0, - 275, - 276, - 5, - 62, - 0, - 0, - 276, - 58, - 1, - 0, - 0, - 0, - 277, - 278, - 5, - 61, - 0, - 0, - 278, - 279, - 5, - 61, - 0, - 0, - 279, - 60, - 1, - 0, - 0, - 0, - 280, - 281, - 5, - 110, - 0, - 0, - 281, - 282, - 5, - 111, - 0, - 0, - 282, - 283, - 5, - 116, - 0, - 0, - 283, - 62, - 1, - 0, - 0, - 0, - 284, - 285, - 5, - 97, - 0, - 0, - 285, - 286, - 5, - 110, - 0, - 0, - 286, - 287, - 5, - 100, - 0, - 0, - 287, - 64, - 1, - 0, - 0, - 0, - 288, - 289, - 5, - 111, - 0, - 0, - 289, - 290, - 5, - 114, - 0, - 0, - 290, - 66, - 1, - 0, - 0, - 0, - 291, - 292, - 5, - 105, - 0, - 0, - 292, - 293, - 5, - 110, - 0, - 0, - 293, - 68, - 1, - 0, - 0, - 0, - 294, - 295, - 5, - 102, - 0, - 0, - 295, - 296, - 5, - 111, - 0, - 0, - 296, - 297, - 5, - 114, - 0, - 0, - 297, - 70, - 1, - 0, - 0, - 0, - 298, - 299, - 5, - 105, - 0, - 0, - 299, - 300, - 5, - 102, - 0, - 0, - 300, - 72, - 1, - 0, - 0, - 0, - 301, - 302, - 5, - 101, - 0, - 0, - 302, - 303, - 5, - 108, - 0, - 0, - 303, - 304, - 5, - 115, - 0, - 0, - 304, - 305, - 5, - 101, - 0, - 0, - 305, - 74, - 1, - 0, - 0, - 0, - 306, - 307, - 5, - 101, - 0, - 0, - 307, - 308, - 5, - 108, - 0, - 0, - 308, - 309, - 5, - 115, - 0, - 0, - 309, - 310, - 5, - 101, - 0, - 0, - 310, - 311, - 5, - 105, - 0, - 0, - 311, - 312, - 5, - 102, - 0, - 0, - 312, - 76, - 1, - 0, - 0, - 0, - 313, - 314, - 5, - 116, - 0, - 0, - 314, - 315, - 5, - 104, - 0, - 0, - 315, - 316, - 5, - 101, - 0, - 0, - 316, - 317, - 5, - 110, - 0, - 0, - 317, - 78, - 1, - 0, - 0, - 0, - 318, - 319, - 5, - 119, - 0, - 0, - 319, - 320, - 5, - 104, - 0, - 0, - 320, - 321, - 5, - 101, - 0, - 0, - 321, - 322, - 5, - 110, - 0, - 0, - 322, - 80, - 1, - 0, - 0, - 0, - 323, - 324, - 5, - 101, - 0, - 0, - 324, - 325, - 5, - 108, - 0, - 0, - 325, - 326, - 5, - 115, - 0, - 0, - 326, - 327, - 5, - 101, - 0, - 0, - 327, - 328, - 5, - 119, - 0, - 0, - 328, - 329, - 5, - 104, - 0, - 0, - 329, - 330, - 5, - 101, - 0, - 0, - 330, - 331, - 5, - 110, - 0, - 0, - 331, - 82, - 1, - 0, - 0, - 0, - 332, - 333, - 5, - 119, - 0, - 0, - 333, - 334, - 5, - 104, - 0, - 0, - 334, - 335, - 5, - 105, - 0, - 0, - 335, - 336, - 5, - 108, - 0, - 0, - 336, - 337, - 5, - 101, - 0, - 0, - 337, - 84, - 1, - 0, - 0, - 0, - 338, - 339, - 5, - 108, - 0, - 0, - 339, - 340, - 5, - 111, - 0, - 0, - 340, - 341, - 5, - 111, - 0, - 0, - 341, - 342, - 5, - 112, - 0, - 0, - 342, - 86, - 1, - 0, - 0, - 0, - 343, - 344, - 5, - 98, - 0, - 0, - 344, - 345, - 5, - 114, - 0, - 0, - 345, - 346, - 5, - 101, - 0, - 0, - 346, - 347, - 5, - 97, - 0, - 0, - 347, - 348, - 5, - 107, - 0, - 0, - 348, - 88, - 1, - 0, - 0, - 0, - 349, - 350, - 5, - 114, - 0, - 0, - 350, - 351, - 5, - 101, - 0, - 0, - 351, - 352, - 5, - 116, - 0, - 0, - 352, - 353, - 5, - 117, - 0, - 0, - 353, - 354, - 5, - 114, - 0, - 0, - 354, - 355, - 5, - 110, - 0, - 0, - 355, - 90, - 1, - 0, - 0, - 0, - 356, - 357, - 5, - 112, - 0, - 0, - 357, - 358, - 5, - 97, - 0, - 0, - 358, - 359, - 5, - 114, - 0, - 0, - 359, - 360, - 5, - 116, - 0, - 0, - 360, - 361, - 5, - 105, - 0, - 0, - 361, - 362, - 5, - 97, - 0, - 0, - 362, - 363, - 5, - 108, - 0, - 0, - 363, - 92, - 1, - 0, - 0, - 0, - 364, - 365, - 5, - 111, - 0, - 0, - 365, - 366, - 5, - 112, - 0, - 0, - 366, - 367, - 5, - 101, - 0, - 0, - 367, - 368, - 5, - 114, - 0, - 0, - 368, - 369, - 5, - 97, - 0, - 0, - 369, - 370, - 5, - 116, - 0, - 0, - 370, - 371, - 5, - 111, - 0, - 0, - 371, - 372, - 5, - 114, - 0, - 0, - 372, - 94, - 1, - 0, - 0, - 0, - 373, - 374, - 5, - 101, - 0, - 0, - 374, - 375, - 5, - 120, - 0, - 0, - 375, - 376, - 5, - 112, - 0, - 0, - 376, - 377, - 5, - 97, - 0, - 0, - 377, - 378, - 5, - 110, - 0, - 0, - 378, - 379, - 5, - 100, - 0, - 0, - 379, - 380, - 5, - 97, - 0, - 0, - 380, - 381, - 5, - 98, - 0, - 0, - 381, - 382, - 5, - 108, - 0, - 0, - 382, - 383, - 5, - 101, - 0, - 0, - 383, - 96, - 1, - 0, - 0, - 0, - 384, - 385, - 5, - 99, - 0, - 0, - 385, - 386, - 5, - 108, - 0, - 0, - 386, - 387, - 5, - 97, - 0, - 0, - 387, - 388, - 5, - 115, - 0, - 0, - 388, - 389, - 5, - 115, - 0, - 0, - 389, - 98, - 1, - 0, - 0, - 0, - 390, - 391, - 5, - 109, - 0, - 0, - 391, - 392, - 5, - 111, - 0, - 0, - 392, - 393, - 5, - 100, - 0, - 0, - 393, - 394, - 5, - 101, - 0, - 0, - 394, - 395, - 5, - 108, - 0, - 0, - 395, - 100, - 1, - 0, - 0, - 0, - 396, - 397, - 5, - 102, - 0, - 0, - 397, - 398, - 5, - 117, - 0, - 0, - 398, - 399, - 5, - 110, - 0, - 0, - 399, - 400, - 5, - 99, - 0, - 0, - 400, - 401, - 5, - 116, - 0, - 0, - 401, - 402, - 5, - 105, - 0, - 0, - 402, - 403, - 5, - 111, - 0, - 0, - 403, - 404, - 5, - 110, - 0, - 0, - 404, - 102, - 1, - 0, - 0, - 0, - 405, - 406, - 5, - 114, - 0, - 0, - 406, - 407, - 5, - 101, - 0, - 0, - 407, - 408, - 5, - 99, - 0, - 0, - 408, - 409, - 5, - 111, - 0, - 0, - 409, - 410, - 5, - 114, - 0, - 0, - 410, - 411, - 5, - 100, - 0, - 0, - 411, - 104, - 1, - 0, - 0, - 0, - 412, - 413, - 5, - 116, - 0, - 0, - 413, - 414, - 5, - 121, - 0, - 0, - 414, - 415, - 5, - 112, - 0, - 0, - 415, - 416, - 5, - 101, - 0, - 0, - 416, - 106, - 1, - 0, - 0, - 0, - 417, - 418, - 5, - 98, - 0, - 0, - 418, - 419, - 5, - 108, - 0, - 0, - 419, - 420, - 5, - 111, - 0, - 0, - 420, - 421, - 5, - 99, - 0, - 0, - 421, - 422, - 5, - 107, - 0, - 0, - 422, - 108, - 1, - 0, - 0, - 0, - 423, - 424, - 5, - 99, - 0, - 0, - 424, - 425, - 5, - 111, - 0, - 0, - 425, - 426, - 5, - 110, - 0, - 0, - 426, - 427, - 5, - 110, - 0, - 0, - 427, - 428, - 5, - 101, - 0, - 0, - 428, - 429, - 5, - 99, - 0, - 0, - 429, - 430, - 5, - 116, - 0, - 0, - 430, - 431, - 5, - 111, - 0, - 0, - 431, - 432, - 5, - 114, - 0, - 0, - 432, - 110, - 1, - 0, - 0, - 0, - 433, - 434, - 5, - 112, - 0, - 0, - 434, - 435, - 5, - 97, - 0, - 0, - 435, - 436, - 5, - 99, - 0, - 0, - 436, - 437, - 5, - 107, - 0, - 0, - 437, - 438, - 5, - 97, - 0, - 0, - 438, - 439, - 5, - 103, - 0, - 0, - 439, - 440, - 5, - 101, - 0, - 0, - 440, - 112, - 1, - 0, - 0, - 0, - 441, - 442, - 5, - 112, - 0, - 0, - 442, - 443, - 5, - 117, - 0, - 0, - 443, - 444, - 5, - 114, - 0, - 0, - 444, - 445, - 5, - 101, - 0, - 0, - 445, - 114, - 1, - 0, - 0, - 0, - 446, - 447, - 5, - 105, - 0, - 0, - 447, - 448, - 5, - 109, - 0, - 0, - 448, - 449, - 5, - 112, - 0, - 0, - 449, - 450, - 5, - 117, - 0, - 0, - 450, - 451, - 5, - 114, - 0, - 0, - 451, - 452, - 5, - 101, - 0, - 0, - 452, - 116, - 1, - 0, - 0, - 0, - 453, - 454, - 5, - 101, - 0, - 0, - 454, - 455, - 5, - 110, - 0, - 0, - 455, - 456, - 5, - 100, - 0, - 0, - 456, - 118, - 1, - 0, - 0, - 0, - 457, - 458, - 5, - 100, - 0, - 0, - 458, - 459, - 5, - 101, - 0, - 0, - 459, - 460, - 5, - 114, - 0, - 0, - 460, - 120, - 1, - 0, - 0, - 0, - 461, - 462, - 5, - 99, - 0, - 0, - 462, - 463, - 5, - 111, - 0, - 0, - 463, - 464, - 5, - 110, - 0, - 0, - 464, - 465, - 5, - 110, - 0, - 0, - 465, - 466, - 5, - 101, - 0, - 0, - 466, - 467, - 5, - 99, - 0, - 0, - 467, - 468, - 5, - 116, - 0, - 0, - 468, - 122, - 1, - 0, - 0, - 0, - 469, - 470, - 5, - 105, - 0, - 0, - 470, - 471, - 5, - 110, - 0, - 0, - 471, - 472, - 5, - 105, - 0, - 0, - 472, - 473, - 5, - 116, - 0, - 0, - 473, - 474, - 5, - 105, - 0, - 0, - 474, - 475, - 5, - 97, - 0, - 0, - 475, - 476, - 5, - 108, - 0, - 0, - 476, - 124, - 1, - 0, - 0, - 0, - 477, - 478, - 5, - 101, - 0, - 0, - 478, - 479, - 5, - 113, - 0, - 0, - 479, - 480, - 5, - 117, - 0, - 0, - 480, - 481, - 5, - 97, - 0, - 0, - 481, - 482, - 5, - 116, - 0, - 0, - 482, - 483, - 5, - 105, - 0, - 0, - 483, - 484, - 5, - 111, - 0, - 0, - 484, - 485, - 5, - 110, - 0, - 0, - 485, - 126, - 1, - 0, - 0, - 0, - 486, - 487, - 5, - 97, - 0, - 0, - 487, - 488, - 5, - 108, - 0, - 0, - 488, - 489, - 5, - 103, - 0, - 0, - 489, - 490, - 5, - 111, - 0, - 0, - 490, - 491, - 5, - 114, - 0, - 0, - 491, - 492, - 5, - 105, - 0, - 0, - 492, - 493, - 5, - 116, - 0, - 0, - 493, - 494, - 5, - 104, - 0, - 0, - 494, - 495, - 5, - 109, - 0, - 0, - 495, - 128, - 1, - 0, - 0, - 0, - 496, - 497, - 5, - 119, - 0, - 0, - 497, - 498, - 5, - 105, - 0, - 0, - 498, - 499, - 5, - 116, - 0, - 0, - 499, - 500, - 5, - 104, - 0, - 0, - 500, - 501, - 5, - 105, - 0, - 0, - 501, - 502, - 5, - 110, - 0, - 0, - 502, - 130, - 1, - 0, - 0, - 0, - 503, - 504, - 5, - 102, - 0, - 0, - 504, - 505, - 5, - 105, - 0, - 0, - 505, - 506, - 5, - 110, - 0, - 0, - 506, - 507, - 5, - 97, - 0, - 0, - 507, - 508, - 5, - 108, - 0, - 0, - 508, - 132, - 1, - 0, - 0, - 0, - 509, - 510, - 5, - 101, - 0, - 0, - 510, - 511, - 5, - 110, - 0, - 0, - 511, - 512, - 5, - 99, - 0, - 0, - 512, - 513, - 5, - 97, - 0, - 0, - 513, - 514, - 5, - 112, - 0, - 0, - 514, - 515, - 5, - 115, - 0, - 0, - 515, - 516, - 5, - 117, - 0, - 0, - 516, - 517, - 5, - 108, - 0, - 0, - 517, - 518, - 5, - 97, - 0, - 0, - 518, - 519, - 5, - 116, - 0, - 0, - 519, - 520, - 5, - 101, - 0, - 0, - 520, - 521, - 5, - 100, - 0, - 0, - 521, - 134, - 1, - 0, - 0, - 0, - 522, - 523, - 5, - 101, - 0, - 0, - 523, - 524, - 5, - 120, - 0, - 0, - 524, - 525, - 5, - 116, - 0, - 0, - 525, - 526, - 5, - 101, - 0, - 0, - 526, - 527, - 5, - 110, - 0, - 0, - 527, - 528, - 5, - 100, - 0, - 0, - 528, - 529, - 5, - 115, - 0, - 0, - 529, - 136, - 1, - 0, - 0, - 0, - 530, - 531, - 5, - 105, - 0, - 0, - 531, - 532, - 5, - 109, - 0, - 0, - 532, - 533, - 5, - 112, - 0, - 0, - 533, - 534, - 5, - 111, - 0, - 0, - 534, - 535, - 5, - 114, - 0, - 0, - 535, - 536, - 5, - 116, - 0, - 0, - 536, - 138, - 1, - 0, - 0, - 0, - 537, - 538, - 5, - 101, - 0, - 0, - 538, - 539, - 5, - 110, - 0, - 0, - 539, - 540, - 5, - 117, - 0, - 0, - 540, - 541, - 5, - 109, - 0, - 0, - 541, - 542, - 5, - 101, - 0, - 0, - 542, - 543, - 5, - 114, - 0, - 0, - 543, - 544, - 5, - 97, - 0, - 0, - 544, - 545, - 5, - 116, - 0, - 0, - 545, - 546, - 5, - 105, - 0, - 0, - 546, - 547, - 5, - 111, - 0, - 0, - 547, - 548, - 5, - 110, - 0, - 0, - 548, - 140, - 1, - 0, - 0, - 0, - 549, - 550, - 5, - 105, - 0, - 0, - 550, - 551, - 5, - 110, - 0, - 0, - 551, - 552, - 5, - 112, - 0, - 0, - 552, - 553, - 5, - 117, - 0, - 0, - 553, - 554, - 5, - 116, - 0, - 0, - 554, - 142, - 1, - 0, - 0, - 0, - 555, - 556, - 5, - 111, - 0, - 0, - 556, - 557, - 5, - 117, - 0, - 0, - 557, - 558, - 5, - 116, - 0, - 0, - 558, - 559, - 5, - 112, - 0, - 0, - 559, - 560, - 5, - 117, - 0, - 0, - 560, - 561, - 5, - 116, - 0, - 0, - 561, - 144, - 1, - 0, - 0, - 0, - 562, - 563, - 5, - 112, - 0, - 0, - 563, - 564, - 5, - 117, - 0, - 0, - 564, - 565, - 5, - 98, - 0, - 0, - 565, - 566, - 5, - 108, - 0, - 0, - 566, - 567, - 5, - 105, - 0, - 0, - 567, - 568, - 5, - 99, - 0, - 0, - 568, - 146, - 1, - 0, - 0, - 0, - 569, - 570, - 5, - 112, - 0, - 0, - 570, - 571, - 5, - 114, - 0, - 0, - 571, - 572, - 5, - 111, - 0, - 0, - 572, - 573, - 5, - 116, - 0, - 0, - 573, - 574, - 5, - 101, - 0, - 0, - 574, - 575, - 5, - 99, - 0, - 0, - 575, - 576, - 5, - 116, - 0, - 0, - 576, - 577, - 5, - 101, - 0, - 0, - 577, - 578, - 5, - 100, - 0, - 0, - 578, - 148, - 1, - 0, - 0, - 0, - 579, - 580, - 5, - 114, - 0, - 0, - 580, - 581, - 5, - 101, - 0, - 0, - 581, - 582, - 5, - 100, - 0, - 0, - 582, - 583, - 5, - 101, - 0, - 0, - 583, - 584, - 5, - 99, - 0, - 0, - 584, - 585, - 5, - 108, - 0, - 0, - 585, - 586, - 5, - 97, - 0, - 0, - 586, - 587, - 5, - 114, - 0, - 0, - 587, - 588, - 5, - 101, - 0, - 0, - 588, - 150, - 1, - 0, - 0, - 0, - 589, - 590, - 5, - 105, - 0, - 0, - 590, - 591, - 5, - 110, - 0, - 0, - 591, - 592, - 5, - 110, - 0, - 0, - 592, - 593, - 5, - 101, - 0, - 0, - 593, - 594, - 5, - 114, - 0, - 0, - 594, - 152, - 1, - 0, - 0, - 0, - 595, - 596, - 5, - 111, - 0, - 0, - 596, - 597, - 5, - 117, - 0, - 0, - 597, - 598, - 5, - 116, - 0, - 0, - 598, - 599, - 5, - 101, - 0, - 0, - 599, - 600, - 5, - 114, - 0, - 0, - 600, - 154, - 1, - 0, - 0, - 0, - 601, - 602, - 5, - 114, - 0, - 0, - 602, - 603, - 5, - 101, - 0, - 0, - 603, - 604, - 5, - 112, - 0, - 0, - 604, - 605, - 5, - 108, - 0, - 0, - 605, - 606, - 5, - 97, - 0, - 0, - 606, - 607, - 5, - 99, - 0, - 0, - 607, - 608, - 5, - 101, - 0, - 0, - 608, - 609, - 5, - 97, - 0, - 0, - 609, - 610, - 5, - 98, - 0, - 0, - 610, - 611, - 5, - 108, - 0, - 0, - 611, - 612, - 5, - 101, - 0, - 0, - 612, - 156, - 1, - 0, - 0, - 0, - 613, - 614, - 5, - 99, - 0, - 0, - 614, - 615, - 5, - 111, - 0, - 0, - 615, - 616, - 5, - 110, - 0, - 0, - 616, - 617, - 5, - 115, - 0, - 0, - 617, - 618, - 5, - 116, - 0, - 0, - 618, - 619, - 5, - 114, - 0, - 0, - 619, - 620, - 5, - 97, - 0, - 0, - 620, - 621, - 5, - 105, - 0, - 0, - 621, - 622, - 5, - 110, - 0, - 0, - 622, - 623, - 5, - 101, - 0, - 0, - 623, - 624, - 5, - 100, - 0, - 0, - 624, - 625, - 5, - 98, - 0, - 0, - 625, - 626, - 5, - 121, - 0, - 0, - 626, - 158, - 1, - 0, - 0, - 0, - 627, - 628, - 5, - 102, - 0, - 0, - 628, - 629, - 5, - 108, - 0, - 0, - 629, - 630, - 5, - 111, - 0, - 0, - 630, - 631, - 5, - 119, - 0, - 0, - 631, - 160, - 1, - 0, - 0, - 0, - 632, - 633, - 5, - 115, - 0, - 0, - 633, - 634, - 5, - 116, - 0, - 0, - 634, - 635, - 5, - 114, - 0, - 0, - 635, - 636, - 5, - 101, - 0, - 0, - 636, - 637, - 5, - 97, - 0, - 0, - 637, - 638, - 5, - 109, - 0, - 0, - 638, - 162, - 1, - 0, - 0, - 0, - 639, - 640, - 5, - 100, - 0, - 0, - 640, - 641, - 5, - 105, - 0, - 0, - 641, - 642, - 5, - 115, - 0, - 0, - 642, - 643, - 5, - 99, - 0, - 0, - 643, - 644, - 5, - 114, - 0, - 0, - 644, - 645, - 5, - 101, - 0, - 0, - 645, - 646, - 5, - 116, - 0, - 0, - 646, - 647, - 5, - 101, - 0, - 0, - 647, - 164, - 1, - 0, - 0, - 0, - 648, - 649, - 5, - 112, - 0, - 0, - 649, - 650, - 5, - 97, - 0, - 0, - 650, - 651, - 5, - 114, - 0, - 0, - 651, - 652, - 5, - 97, - 0, - 0, - 652, - 653, - 5, - 109, - 0, - 0, - 653, - 654, - 5, - 101, - 0, - 0, - 654, - 655, - 5, - 116, - 0, - 0, - 655, - 656, - 5, - 101, - 0, - 0, - 656, - 657, - 5, - 114, - 0, - 0, - 657, - 166, - 1, - 0, - 0, - 0, - 658, - 659, - 5, - 99, - 0, - 0, - 659, - 660, - 5, - 111, - 0, - 0, - 660, - 661, - 5, - 110, - 0, - 0, - 661, - 662, - 5, - 115, - 0, - 0, - 662, - 663, - 5, - 116, - 0, - 0, - 663, - 664, - 5, - 97, - 0, - 0, - 664, - 665, - 5, - 110, - 0, - 0, - 665, - 666, - 5, - 116, - 0, - 0, - 666, - 168, - 1, - 0, - 0, - 0, - 667, - 668, - 5, - 101, - 0, - 0, - 668, - 669, - 5, - 97, - 0, - 0, - 669, - 670, - 5, - 99, - 0, - 0, - 670, - 671, - 5, - 104, - 0, - 0, - 671, - 170, - 1, - 0, - 0, - 0, - 672, - 673, - 5, - 97, - 0, - 0, - 673, - 674, - 5, - 110, - 0, - 0, - 674, - 675, - 5, - 110, - 0, - 0, - 675, - 676, - 5, - 111, - 0, - 0, - 676, - 677, - 5, - 116, - 0, - 0, - 677, - 678, - 5, - 97, - 0, - 0, - 678, - 679, - 5, - 116, - 0, - 0, - 679, - 680, - 5, - 105, - 0, - 0, - 680, - 681, - 5, - 111, - 0, - 0, - 681, - 682, - 5, - 110, - 0, - 0, - 682, - 172, - 1, - 0, - 0, - 0, - 683, - 684, - 5, - 101, - 0, - 0, - 684, - 685, - 5, - 120, - 0, - 0, - 685, - 686, - 5, - 116, - 0, - 0, - 686, - 687, - 5, - 101, - 0, - 0, - 687, - 688, - 5, - 114, - 0, - 0, - 688, - 689, - 5, - 110, - 0, - 0, - 689, - 690, - 5, - 97, - 0, - 0, - 690, - 691, - 5, - 108, - 0, - 0, - 691, - 174, - 1, - 0, - 0, - 0, - 692, - 693, - 5, - 47, - 0, - 0, - 693, - 694, - 5, - 42, - 0, - 0, - 694, - 698, - 1, - 0, - 0, - 0, - 695, - 697, - 9, - 0, - 0, - 0, - 696, - 695, - 1, - 0, - 0, - 0, - 697, - 700, - 1, - 0, - 0, - 0, - 698, - 699, - 1, - 0, - 0, - 0, - 698, - 696, - 1, - 0, - 0, - 0, - 699, - 701, - 1, - 0, - 0, - 0, - 700, - 698, - 1, - 0, - 0, - 0, - 701, - 702, - 5, - 42, - 0, - 0, - 702, - 703, - 5, - 47, - 0, - 0, - 703, - 704, - 1, - 0, - 0, - 0, - 704, - 705, - 6, - 87, - 1, - 0, - 705, - 176, - 1, - 0, - 0, - 0, - 706, - 707, - 5, - 47, - 0, - 0, - 707, - 708, - 5, - 47, - 0, - 0, - 708, - 712, - 1, - 0, - 0, - 0, - 709, - 711, - 8, - 1, - 0, - 0, - 710, - 709, - 1, - 0, - 0, - 0, - 711, - 714, - 1, - 0, - 0, - 0, - 712, - 710, - 1, - 0, - 0, - 0, - 712, - 713, - 1, - 0, - 0, - 0, - 713, - 715, - 1, - 0, - 0, - 0, - 714, - 712, - 1, - 0, - 0, - 0, - 715, - 716, - 6, - 88, - 1, - 0, - 716, - 178, - 1, - 0, - 0, - 0, - 717, - 718, - 5, - 92, - 0, - 0, - 718, - 719, - 7, - 2, - 0, - 0, - 719, - 180, - 1, - 0, - 0, - 0, - 720, - 721, - 7, - 3, - 0, - 0, - 721, - 182, - 1, - 0, - 0, - 0, - 722, - 723, - 7, - 4, - 0, - 0, - 723, - 184, - 1, - 0, - 0, - 0, - 724, - 728, - 3, - 183, - 91, - 0, - 725, - 728, - 3, - 181, - 90, - 0, - 726, - 728, - 7, - 5, - 0, - 0, - 727, - 724, - 1, - 0, - 0, - 0, - 727, - 725, - 1, - 0, - 0, - 0, - 727, - 726, - 1, - 0, - 0, - 0, - 728, - 186, - 1, - 0, - 0, - 0, - 729, - 734, - 5, - 39, - 0, - 0, - 730, - 733, - 3, - 185, - 92, - 0, - 731, - 733, - 3, - 179, - 89, - 0, - 732, - 730, - 1, - 0, - 0, - 0, - 732, - 731, - 1, - 0, - 0, - 0, - 733, - 736, - 1, - 0, - 0, - 0, - 734, - 732, - 1, - 0, - 0, - 0, - 734, - 735, - 1, - 0, - 0, - 0, - 735, - 737, - 1, - 0, - 0, - 0, - 736, - 734, - 1, - 0, - 0, - 0, - 737, - 738, - 5, - 39, - 0, - 0, - 738, - 188, - 1, - 0, - 0, - 0, - 739, - 740, - 8, - 6, - 0, - 0, - 740, - 190, - 1, - 0, - 0, - 0, - 741, - 742, - 7, - 7, - 0, - 0, - 742, - 192, - 1, - 0, - 0, - 0, - 743, - 745, - 3, - 181, - 90, - 0, - 744, - 743, - 1, - 0, - 0, - 0, - 745, - 746, - 1, - 0, - 0, - 0, - 746, - 744, - 1, - 0, - 0, - 0, - 746, - 747, - 1, - 0, - 0, - 0, - 747, - 194, - 1, - 0, - 0, - 0, - 748, - 753, - 3, - 193, - 96, - 0, - 749, - 751, - 3, - 7, - 3, - 0, - 750, - 752, - 3, - 193, - 96, - 0, - 751, - 750, - 1, - 0, - 0, - 0, - 751, - 752, - 1, - 0, - 0, - 0, - 752, - 754, - 1, - 0, - 0, - 0, - 753, - 749, - 1, - 0, - 0, - 0, - 753, - 754, - 1, - 0, - 0, - 0, - 754, - 762, - 1, - 0, - 0, - 0, - 755, - 758, - 3, - 191, - 95, - 0, - 756, - 759, - 3, - 29, - 14, - 0, - 757, - 759, - 3, - 31, - 15, - 0, - 758, - 756, - 1, - 0, - 0, - 0, - 758, - 757, - 1, - 0, - 0, - 0, - 758, - 759, - 1, - 0, - 0, - 0, - 759, - 760, - 1, - 0, - 0, - 0, - 760, - 761, - 3, - 193, - 96, - 0, - 761, - 763, - 1, - 0, - 0, - 0, - 762, - 755, - 1, - 0, - 0, - 0, - 762, - 763, - 1, - 0, - 0, - 0, - 763, - 196, - 1, - 0, - 0, - 0, - 764, - 769, - 3, - 3, - 1, - 0, - 765, - 768, - 3, - 189, - 94, - 0, - 766, - 768, - 3, - 179, - 89, - 0, - 767, - 765, - 1, - 0, - 0, - 0, - 767, - 766, - 1, - 0, - 0, - 0, - 768, - 771, - 1, - 0, - 0, - 0, - 769, - 767, - 1, - 0, - 0, - 0, - 769, - 770, - 1, - 0, - 0, - 0, - 770, - 772, - 1, - 0, - 0, - 0, - 771, - 769, - 1, - 0, - 0, - 0, - 772, - 773, - 3, - 3, - 1, - 0, - 773, - 198, - 1, - 0, - 0, - 0, - 774, - 777, - 3, - 195, - 97, - 0, - 775, - 777, - 3, - 193, - 96, - 0, - 776, - 774, - 1, - 0, - 0, - 0, - 776, - 775, - 1, - 0, - 0, - 0, - 777, - 200, - 1, - 0, - 0, - 0, - 778, - 779, - 5, - 116, - 0, - 0, - 779, - 780, - 5, - 114, - 0, - 0, - 780, - 781, - 5, - 117, - 0, - 0, - 781, - 788, - 5, - 101, - 0, - 0, - 782, - 783, - 5, - 102, - 0, - 0, - 783, - 784, - 5, - 97, - 0, - 0, - 784, - 785, - 5, - 108, - 0, - 0, - 785, - 786, - 5, - 115, - 0, - 0, - 786, - 788, - 5, - 101, - 0, - 0, - 787, - 778, - 1, - 0, - 0, - 0, - 787, - 782, - 1, - 0, - 0, - 0, - 788, - 202, - 1, - 0, - 0, - 0, - 789, - 794, - 3, - 183, - 91, - 0, - 790, - 793, - 3, - 181, - 90, - 0, - 791, - 793, - 3, - 183, - 91, - 0, - 792, - 790, - 1, - 0, - 0, - 0, - 792, - 791, - 1, - 0, - 0, - 0, - 793, - 796, - 1, - 0, - 0, - 0, - 794, - 792, - 1, - 0, - 0, - 0, - 794, - 795, - 1, - 0, - 0, - 0, - 795, - 799, - 1, - 0, - 0, - 0, - 796, - 794, - 1, - 0, - 0, - 0, - 797, - 799, - 3, - 187, - 93, - 0, - 798, - 789, - 1, - 0, - 0, - 0, - 798, - 797, - 1, - 0, - 0, - 0, - 799, - 204, - 1, - 0, - 0, - 0, - 19, - 0, - 208, - 698, - 712, - 727, - 732, - 734, - 746, - 751, - 753, - 758, - 762, - 767, - 769, - 776, - 787, - 792, - 794, - 798, - 2, - 0, - 2, - 0, - 0, - 3, - 0, - ] - - -class ModelicaLexer(Lexer): - atn = ATNDeserializer().deserialize(serializedATN()) - - decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState)] - - WHITESPACE = 2 - COMMENTS = 3 - - WS = 1 - DQUOTE = 2 - COMMA = 3 - DOT = 4 - SEMICOLON = 5 - COLON = 6 - LPAREN = 7 - RPAREN = 8 - LCURLY = 9 - RCURLY = 10 - LBRACK = 11 - RBRACK = 12 - EQUAL = 13 - ASSIGN = 14 - PLUS = 15 - MINUS = 16 - STAR = 17 - SLASH = 18 - FLEX = 19 - DOTPLUS = 20 - DOTMINUS = 21 - DOTSTAR = 22 - DOTSLASH = 23 - DOTFLEX = 24 - GRE = 25 - GEQ = 26 - LES = 27 - LEQ = 28 - NEQ = 29 - EEQ = 30 - NOT = 31 - AND = 32 - OR = 33 - IN = 34 - FOR = 35 - IF = 36 - ELSE = 37 - ELSEIF = 38 - THEN = 39 - WHEN = 40 - ELSEWHEN = 41 - WHILE = 42 - LOOP = 43 - BREAK = 44 - RETURN = 45 - PARTIAL = 46 - OPERATOR = 47 - EXPANDABLE = 48 - CLASS = 49 - MODEL = 50 - FUNCTION = 51 - RECORD = 52 - TYPE = 53 - BLOCK = 54 - CONNECTOR = 55 - PACKAGE = 56 - PURE = 57 - IMPURE = 58 - END = 59 - DER = 60 - CONNECT = 61 - INITIAL = 62 - EQUATION = 63 - ALGORITHM = 64 - WITHIN = 65 - FINAL = 66 - ENCAPSULATED = 67 - EXTENDS = 68 - IMPORT = 69 - ENUMERATION = 70 - INPUT = 71 - OUTPUT = 72 - PUBLIC = 73 - PROTECTED = 74 - REDECLARE = 75 - INNER = 76 - OUTER = 77 - REPLACEABLE = 78 - CONSTRAINEDBY = 79 - FLOW = 80 - STREAM = 81 - DISCRETE = 82 - PARAMETER = 83 - CONSTANT = 84 - EACH = 85 - ANNOTATION = 86 - EXTERNAL = 87 - BLOCK_COMMENT = 88 - LINE_COMMENT = 89 - STRING = 90 - UNUM = 91 - BOOL = 92 - IDENT = 93 - - channelNames = ["DEFAULT_TOKEN_CHANNEL", "HIDDEN", "WHITESPACE", "COMMENTS"] - - modeNames = ["DEFAULT_MODE"] - - literalNames = [ - "", - "'\"'", - "','", - "'.'", - "';'", - "':'", - "'('", - "')'", - "'{'", - "'}'", - "'['", - "']'", - "'='", - "':='", - "'+'", - "'-'", - "'*'", - "'/'", - "'^'", - "'.+'", - "'.-'", - "'.*'", - "'./'", - "'.^'", - "'>'", - "'>='", - "'<'", - "'<='", - "'<>'", - "'=='", - "'not'", - "'and'", - "'or'", - "'in'", - "'for'", - "'if'", - "'else'", - "'elseif'", - "'then'", - "'when'", - "'elsewhen'", - "'while'", - "'loop'", - "'break'", - "'return'", - "'partial'", - "'operator'", - "'expandable'", - "'class'", - "'model'", - "'function'", - "'record'", - "'type'", - "'block'", - "'connector'", - "'package'", - "'pure'", - "'impure'", - "'end'", - "'der'", - "'connect'", - "'initial'", - "'equation'", - "'algorithm'", - "'within'", - "'final'", - "'encapsulated'", - "'extends'", - "'import'", - "'enumeration'", - "'input'", - "'output'", - "'public'", - "'protected'", - "'redeclare'", - "'inner'", - "'outer'", - "'replaceable'", - "'constrainedby'", - "'flow'", - "'stream'", - "'discrete'", - "'parameter'", - "'constant'", - "'each'", - "'annotation'", - "'external'", - ] - - symbolicNames = [ - "", - "WS", - "DQUOTE", - "COMMA", - "DOT", - "SEMICOLON", - "COLON", - "LPAREN", - "RPAREN", - "LCURLY", - "RCURLY", - "LBRACK", - "RBRACK", - "EQUAL", - "ASSIGN", - "PLUS", - "MINUS", - "STAR", - "SLASH", - "FLEX", - "DOTPLUS", - "DOTMINUS", - "DOTSTAR", - "DOTSLASH", - "DOTFLEX", - "GRE", - "GEQ", - "LES", - "LEQ", - "NEQ", - "EEQ", - "NOT", - "AND", - "OR", - "IN", - "FOR", - "IF", - "ELSE", - "ELSEIF", - "THEN", - "WHEN", - "ELSEWHEN", - "WHILE", - "LOOP", - "BREAK", - "RETURN", - "PARTIAL", - "OPERATOR", - "EXPANDABLE", - "CLASS", - "MODEL", - "FUNCTION", - "RECORD", - "TYPE", - "BLOCK", - "CONNECTOR", - "PACKAGE", - "PURE", - "IMPURE", - "END", - "DER", - "CONNECT", - "INITIAL", - "EQUATION", - "ALGORITHM", - "WITHIN", - "FINAL", - "ENCAPSULATED", - "EXTENDS", - "IMPORT", - "ENUMERATION", - "INPUT", - "OUTPUT", - "PUBLIC", - "PROTECTED", - "REDECLARE", - "INNER", - "OUTER", - "REPLACEABLE", - "CONSTRAINEDBY", - "FLOW", - "STREAM", - "DISCRETE", - "PARAMETER", - "CONSTANT", - "EACH", - "ANNOTATION", - "EXTERNAL", - "BLOCK_COMMENT", - "LINE_COMMENT", - "STRING", - "UNUM", - "BOOL", - "IDENT", - ] - - ruleNames = [ - "WS", - "DQUOTE", - "COMMA", - "DOT", - "SEMICOLON", - "COLON", - "LPAREN", - "RPAREN", - "LCURLY", - "RCURLY", - "LBRACK", - "RBRACK", - "EQUAL", - "ASSIGN", - "PLUS", - "MINUS", - "STAR", - "SLASH", - "FLEX", - "DOTPLUS", - "DOTMINUS", - "DOTSTAR", - "DOTSLASH", - "DOTFLEX", - "GRE", - "GEQ", - "LES", - "LEQ", - "NEQ", - "EEQ", - "NOT", - "AND", - "OR", - "IN", - "FOR", - "IF", - "ELSE", - "ELSEIF", - "THEN", - "WHEN", - "ELSEWHEN", - "WHILE", - "LOOP", - "BREAK", - "RETURN", - "PARTIAL", - "OPERATOR", - "EXPANDABLE", - "CLASS", - "MODEL", - "FUNCTION", - "RECORD", - "TYPE", - "BLOCK", - "CONNECTOR", - "PACKAGE", - "PURE", - "IMPURE", - "END", - "DER", - "CONNECT", - "INITIAL", - "EQUATION", - "ALGORITHM", - "WITHIN", - "FINAL", - "ENCAPSULATED", - "EXTENDS", - "IMPORT", - "ENUMERATION", - "INPUT", - "OUTPUT", - "PUBLIC", - "PROTECTED", - "REDECLARE", - "INNER", - "OUTER", - "REPLACEABLE", - "CONSTRAINEDBY", - "FLOW", - "STREAM", - "DISCRETE", - "PARAMETER", - "CONSTANT", - "EACH", - "ANNOTATION", - "EXTERNAL", - "BLOCK_COMMENT", - "LINE_COMMENT", - "S_ESCAPE", - "DIGIT", - "NONDIGIT", - "Q_CHAR", - "Q_IDENT", - "S_CHAR", - "E", - "UINT", - "UREAL", - "STRING", - "UNUM", - "BOOL", - "IDENT", - ] - - grammarFileName = "ModelicaLexer.g4" - - def __init__(self, input=None, output: TextIO = sys.stdout): - super().__init__(input, output) - self.checkVersion("4.13.0") - self._interp = LexerATNSimulator( - self, self.atn, self.decisionsToDFA, PredictionContextCache() - ) - self._actions = None - self._predicates = None diff --git a/mofmt/parsing/generated/ModelicaLexer.tokens b/mofmt/parsing/generated/ModelicaLexer.tokens deleted file mode 100644 index c2e50f6..0000000 --- a/mofmt/parsing/generated/ModelicaLexer.tokens +++ /dev/null @@ -1,179 +0,0 @@ -WS=1 -DQUOTE=2 -COMMA=3 -DOT=4 -SEMICOLON=5 -COLON=6 -LPAREN=7 -RPAREN=8 -LCURLY=9 -RCURLY=10 -LBRACK=11 -RBRACK=12 -EQUAL=13 -ASSIGN=14 -PLUS=15 -MINUS=16 -STAR=17 -SLASH=18 -FLEX=19 -DOTPLUS=20 -DOTMINUS=21 -DOTSTAR=22 -DOTSLASH=23 -DOTFLEX=24 -GRE=25 -GEQ=26 -LES=27 -LEQ=28 -NEQ=29 -EEQ=30 -NOT=31 -AND=32 -OR=33 -IN=34 -FOR=35 -IF=36 -ELSE=37 -ELSEIF=38 -THEN=39 -WHEN=40 -ELSEWHEN=41 -WHILE=42 -LOOP=43 -BREAK=44 -RETURN=45 -PARTIAL=46 -OPERATOR=47 -EXPANDABLE=48 -CLASS=49 -MODEL=50 -FUNCTION=51 -RECORD=52 -TYPE=53 -BLOCK=54 -CONNECTOR=55 -PACKAGE=56 -PURE=57 -IMPURE=58 -END=59 -DER=60 -CONNECT=61 -INITIAL=62 -EQUATION=63 -ALGORITHM=64 -WITHIN=65 -FINAL=66 -ENCAPSULATED=67 -EXTENDS=68 -IMPORT=69 -ENUMERATION=70 -INPUT=71 -OUTPUT=72 -PUBLIC=73 -PROTECTED=74 -REDECLARE=75 -INNER=76 -OUTER=77 -REPLACEABLE=78 -CONSTRAINEDBY=79 -FLOW=80 -STREAM=81 -DISCRETE=82 -PARAMETER=83 -CONSTANT=84 -EACH=85 -ANNOTATION=86 -EXTERNAL=87 -BLOCK_COMMENT=88 -LINE_COMMENT=89 -STRING=90 -UNUM=91 -BOOL=92 -IDENT=93 -'"'=2 -','=3 -'.'=4 -';'=5 -':'=6 -'('=7 -')'=8 -'{'=9 -'}'=10 -'['=11 -']'=12 -'='=13 -':='=14 -'+'=15 -'-'=16 -'*'=17 -'/'=18 -'^'=19 -'.+'=20 -'.-'=21 -'.*'=22 -'./'=23 -'.^'=24 -'>'=25 -'>='=26 -'<'=27 -'<='=28 -'<>'=29 -'=='=30 -'not'=31 -'and'=32 -'or'=33 -'in'=34 -'for'=35 -'if'=36 -'else'=37 -'elseif'=38 -'then'=39 -'when'=40 -'elsewhen'=41 -'while'=42 -'loop'=43 -'break'=44 -'return'=45 -'partial'=46 -'operator'=47 -'expandable'=48 -'class'=49 -'model'=50 -'function'=51 -'record'=52 -'type'=53 -'block'=54 -'connector'=55 -'package'=56 -'pure'=57 -'impure'=58 -'end'=59 -'der'=60 -'connect'=61 -'initial'=62 -'equation'=63 -'algorithm'=64 -'within'=65 -'final'=66 -'encapsulated'=67 -'extends'=68 -'import'=69 -'enumeration'=70 -'input'=71 -'output'=72 -'public'=73 -'protected'=74 -'redeclare'=75 -'inner'=76 -'outer'=77 -'replaceable'=78 -'constrainedby'=79 -'flow'=80 -'stream'=81 -'discrete'=82 -'parameter'=83 -'constant'=84 -'each'=85 -'annotation'=86 -'external'=87 diff --git a/mofmt/parsing/generated/ModelicaListener.py b/mofmt/parsing/generated/ModelicaListener.py deleted file mode 100644 index e936e53..0000000 --- a/mofmt/parsing/generated/ModelicaListener.py +++ /dev/null @@ -1,943 +0,0 @@ -# Generated from grammar/Modelica.g4 by ANTLR 4.13.0 -from antlr4 import * - -if "." in __name__: - from .Modelica import Modelica -else: - from Modelica import Modelica - - -# This class defines a complete listener for a parse tree produced by Modelica. -class ModelicaListener(ParseTreeListener): - # Enter a parse tree produced by Modelica#stored_definition. - def enterStored_definition(self, ctx: Modelica.Stored_definitionContext): - pass - - # Exit a parse tree produced by Modelica#stored_definition. - def exitStored_definition(self, ctx: Modelica.Stored_definitionContext): - pass - - # Enter a parse tree produced by Modelica#class_definition. - def enterClass_definition(self, ctx: Modelica.Class_definitionContext): - pass - - # Exit a parse tree produced by Modelica#class_definition. - def exitClass_definition(self, ctx: Modelica.Class_definitionContext): - pass - - # Enter a parse tree produced by Modelica#class_prefixes. - def enterClass_prefixes(self, ctx: Modelica.Class_prefixesContext): - pass - - # Exit a parse tree produced by Modelica#class_prefixes. - def exitClass_prefixes(self, ctx: Modelica.Class_prefixesContext): - pass - - # Enter a parse tree produced by Modelica#class_specifier. - def enterClass_specifier(self, ctx: Modelica.Class_specifierContext): - pass - - # Exit a parse tree produced by Modelica#class_specifier. - def exitClass_specifier(self, ctx: Modelica.Class_specifierContext): - pass - - # Enter a parse tree produced by Modelica#long_class_specifier. - def enterLong_class_specifier(self, ctx: Modelica.Long_class_specifierContext): - pass - - # Exit a parse tree produced by Modelica#long_class_specifier. - def exitLong_class_specifier(self, ctx: Modelica.Long_class_specifierContext): - pass - - # Enter a parse tree produced by Modelica#end_clause. - def enterEnd_clause(self, ctx: Modelica.End_clauseContext): - pass - - # Exit a parse tree produced by Modelica#end_clause. - def exitEnd_clause(self, ctx: Modelica.End_clauseContext): - pass - - # Enter a parse tree produced by Modelica#short_class_specifier. - def enterShort_class_specifier(self, ctx: Modelica.Short_class_specifierContext): - pass - - # Exit a parse tree produced by Modelica#short_class_specifier. - def exitShort_class_specifier(self, ctx: Modelica.Short_class_specifierContext): - pass - - # Enter a parse tree produced by Modelica#der_class_specifier. - def enterDer_class_specifier(self, ctx: Modelica.Der_class_specifierContext): - pass - - # Exit a parse tree produced by Modelica#der_class_specifier. - def exitDer_class_specifier(self, ctx: Modelica.Der_class_specifierContext): - pass - - # Enter a parse tree produced by Modelica#base_prefix. - def enterBase_prefix(self, ctx: Modelica.Base_prefixContext): - pass - - # Exit a parse tree produced by Modelica#base_prefix. - def exitBase_prefix(self, ctx: Modelica.Base_prefixContext): - pass - - # Enter a parse tree produced by Modelica#enumerations. - def enterEnumerations(self, ctx: Modelica.EnumerationsContext): - pass - - # Exit a parse tree produced by Modelica#enumerations. - def exitEnumerations(self, ctx: Modelica.EnumerationsContext): - pass - - # Enter a parse tree produced by Modelica#enum_list. - def enterEnum_list(self, ctx: Modelica.Enum_listContext): - pass - - # Exit a parse tree produced by Modelica#enum_list. - def exitEnum_list(self, ctx: Modelica.Enum_listContext): - pass - - # Enter a parse tree produced by Modelica#enumeration_literal. - def enterEnumeration_literal(self, ctx: Modelica.Enumeration_literalContext): - pass - - # Exit a parse tree produced by Modelica#enumeration_literal. - def exitEnumeration_literal(self, ctx: Modelica.Enumeration_literalContext): - pass - - # Enter a parse tree produced by Modelica#composition. - def enterComposition(self, ctx: Modelica.CompositionContext): - pass - - # Exit a parse tree produced by Modelica#composition. - def exitComposition(self, ctx: Modelica.CompositionContext): - pass - - # Enter a parse tree produced by Modelica#class_annotation. - def enterClass_annotation(self, ctx: Modelica.Class_annotationContext): - pass - - # Exit a parse tree produced by Modelica#class_annotation. - def exitClass_annotation(self, ctx: Modelica.Class_annotationContext): - pass - - # Enter a parse tree produced by Modelica#external_element. - def enterExternal_element(self, ctx: Modelica.External_elementContext): - pass - - # Exit a parse tree produced by Modelica#external_element. - def exitExternal_element(self, ctx: Modelica.External_elementContext): - pass - - # Enter a parse tree produced by Modelica#language_specification. - def enterLanguage_specification(self, ctx: Modelica.Language_specificationContext): - pass - - # Exit a parse tree produced by Modelica#language_specification. - def exitLanguage_specification(self, ctx: Modelica.Language_specificationContext): - pass - - # Enter a parse tree produced by Modelica#external_function_call. - def enterExternal_function_call(self, ctx: Modelica.External_function_callContext): - pass - - # Exit a parse tree produced by Modelica#external_function_call. - def exitExternal_function_call(self, ctx: Modelica.External_function_callContext): - pass - - # Enter a parse tree produced by Modelica#external_function_args. - def enterExternal_function_args(self, ctx: Modelica.External_function_argsContext): - pass - - # Exit a parse tree produced by Modelica#external_function_args. - def exitExternal_function_args(self, ctx: Modelica.External_function_argsContext): - pass - - # Enter a parse tree produced by Modelica#initial_element_list. - def enterInitial_element_list(self, ctx: Modelica.Initial_element_listContext): - pass - - # Exit a parse tree produced by Modelica#initial_element_list. - def exitInitial_element_list(self, ctx: Modelica.Initial_element_listContext): - pass - - # Enter a parse tree produced by Modelica#public_element_list. - def enterPublic_element_list(self, ctx: Modelica.Public_element_listContext): - pass - - # Exit a parse tree produced by Modelica#public_element_list. - def exitPublic_element_list(self, ctx: Modelica.Public_element_listContext): - pass - - # Enter a parse tree produced by Modelica#protected_element_list. - def enterProtected_element_list(self, ctx: Modelica.Protected_element_listContext): - pass - - # Exit a parse tree produced by Modelica#protected_element_list. - def exitProtected_element_list(self, ctx: Modelica.Protected_element_listContext): - pass - - # Enter a parse tree produced by Modelica#element_list. - def enterElement_list(self, ctx: Modelica.Element_listContext): - pass - - # Exit a parse tree produced by Modelica#element_list. - def exitElement_list(self, ctx: Modelica.Element_listContext): - pass - - # Enter a parse tree produced by Modelica#element. - def enterElement(self, ctx: Modelica.ElementContext): - pass - - # Exit a parse tree produced by Modelica#element. - def exitElement(self, ctx: Modelica.ElementContext): - pass - - # Enter a parse tree produced by Modelica#import_clause. - def enterImport_clause(self, ctx: Modelica.Import_clauseContext): - pass - - # Exit a parse tree produced by Modelica#import_clause. - def exitImport_clause(self, ctx: Modelica.Import_clauseContext): - pass - - # Enter a parse tree produced by Modelica#import_list. - def enterImport_list(self, ctx: Modelica.Import_listContext): - pass - - # Exit a parse tree produced by Modelica#import_list. - def exitImport_list(self, ctx: Modelica.Import_listContext): - pass - - # Enter a parse tree produced by Modelica#declaration_clause. - def enterDeclaration_clause(self, ctx: Modelica.Declaration_clauseContext): - pass - - # Exit a parse tree produced by Modelica#declaration_clause. - def exitDeclaration_clause(self, ctx: Modelica.Declaration_clauseContext): - pass - - # Enter a parse tree produced by Modelica#extends_clause. - def enterExtends_clause(self, ctx: Modelica.Extends_clauseContext): - pass - - # Exit a parse tree produced by Modelica#extends_clause. - def exitExtends_clause(self, ctx: Modelica.Extends_clauseContext): - pass - - # Enter a parse tree produced by Modelica#constraining_clause. - def enterConstraining_clause(self, ctx: Modelica.Constraining_clauseContext): - pass - - # Exit a parse tree produced by Modelica#constraining_clause. - def exitConstraining_clause(self, ctx: Modelica.Constraining_clauseContext): - pass - - # Enter a parse tree produced by Modelica#class_or_inheritance_modification. - def enterClass_or_inheritance_modification( - self, ctx: Modelica.Class_or_inheritance_modificationContext - ): - pass - - # Exit a parse tree produced by Modelica#class_or_inheritance_modification. - def exitClass_or_inheritance_modification( - self, ctx: Modelica.Class_or_inheritance_modificationContext - ): - pass - - # Enter a parse tree produced by Modelica#argument_or_inheritance_modification_list. - def enterArgument_or_inheritance_modification_list( - self, ctx: Modelica.Argument_or_inheritance_modification_listContext - ): - pass - - # Exit a parse tree produced by Modelica#argument_or_inheritance_modification_list. - def exitArgument_or_inheritance_modification_list( - self, ctx: Modelica.Argument_or_inheritance_modification_listContext - ): - pass - - # Enter a parse tree produced by Modelica#inheritance_modification. - def enterInheritance_modification( - self, ctx: Modelica.Inheritance_modificationContext - ): - pass - - # Exit a parse tree produced by Modelica#inheritance_modification. - def exitInheritance_modification( - self, ctx: Modelica.Inheritance_modificationContext - ): - pass - - # Enter a parse tree produced by Modelica#component_clause. - def enterComponent_clause(self, ctx: Modelica.Component_clauseContext): - pass - - # Exit a parse tree produced by Modelica#component_clause. - def exitComponent_clause(self, ctx: Modelica.Component_clauseContext): - pass - - # Enter a parse tree produced by Modelica#type_prefix. - def enterType_prefix(self, ctx: Modelica.Type_prefixContext): - pass - - # Exit a parse tree produced by Modelica#type_prefix. - def exitType_prefix(self, ctx: Modelica.Type_prefixContext): - pass - - # Enter a parse tree produced by Modelica#component_list. - def enterComponent_list(self, ctx: Modelica.Component_listContext): - pass - - # Exit a parse tree produced by Modelica#component_list. - def exitComponent_list(self, ctx: Modelica.Component_listContext): - pass - - # Enter a parse tree produced by Modelica#component_declaration. - def enterComponent_declaration(self, ctx: Modelica.Component_declarationContext): - pass - - # Exit a parse tree produced by Modelica#component_declaration. - def exitComponent_declaration(self, ctx: Modelica.Component_declarationContext): - pass - - # Enter a parse tree produced by Modelica#declaration. - def enterDeclaration(self, ctx: Modelica.DeclarationContext): - pass - - # Exit a parse tree produced by Modelica#declaration. - def exitDeclaration(self, ctx: Modelica.DeclarationContext): - pass - - # Enter a parse tree produced by Modelica#modification. - def enterModification(self, ctx: Modelica.ModificationContext): - pass - - # Exit a parse tree produced by Modelica#modification. - def exitModification(self, ctx: Modelica.ModificationContext): - pass - - # Enter a parse tree produced by Modelica#modification_expression. - def enterModification_expression( - self, ctx: Modelica.Modification_expressionContext - ): - pass - - # Exit a parse tree produced by Modelica#modification_expression. - def exitModification_expression(self, ctx: Modelica.Modification_expressionContext): - pass - - # Enter a parse tree produced by Modelica#class_modification. - def enterClass_modification(self, ctx: Modelica.Class_modificationContext): - pass - - # Exit a parse tree produced by Modelica#class_modification. - def exitClass_modification(self, ctx: Modelica.Class_modificationContext): - pass - - # Enter a parse tree produced by Modelica#argument_list. - def enterArgument_list(self, ctx: Modelica.Argument_listContext): - pass - - # Exit a parse tree produced by Modelica#argument_list. - def exitArgument_list(self, ctx: Modelica.Argument_listContext): - pass - - # Enter a parse tree produced by Modelica#argument. - def enterArgument(self, ctx: Modelica.ArgumentContext): - pass - - # Exit a parse tree produced by Modelica#argument. - def exitArgument(self, ctx: Modelica.ArgumentContext): - pass - - # Enter a parse tree produced by Modelica#element_modification_or_replaceable. - def enterElement_modification_or_replaceable( - self, ctx: Modelica.Element_modification_or_replaceableContext - ): - pass - - # Exit a parse tree produced by Modelica#element_modification_or_replaceable. - def exitElement_modification_or_replaceable( - self, ctx: Modelica.Element_modification_or_replaceableContext - ): - pass - - # Enter a parse tree produced by Modelica#element_modification. - def enterElement_modification(self, ctx: Modelica.Element_modificationContext): - pass - - # Exit a parse tree produced by Modelica#element_modification. - def exitElement_modification(self, ctx: Modelica.Element_modificationContext): - pass - - # Enter a parse tree produced by Modelica#element_redeclaration. - def enterElement_redeclaration(self, ctx: Modelica.Element_redeclarationContext): - pass - - # Exit a parse tree produced by Modelica#element_redeclaration. - def exitElement_redeclaration(self, ctx: Modelica.Element_redeclarationContext): - pass - - # Enter a parse tree produced by Modelica#element_replaceable. - def enterElement_replaceable(self, ctx: Modelica.Element_replaceableContext): - pass - - # Exit a parse tree produced by Modelica#element_replaceable. - def exitElement_replaceable(self, ctx: Modelica.Element_replaceableContext): - pass - - # Enter a parse tree produced by Modelica#short_component_clause. - def enterShort_component_clause(self, ctx: Modelica.Short_component_clauseContext): - pass - - # Exit a parse tree produced by Modelica#short_component_clause. - def exitShort_component_clause(self, ctx: Modelica.Short_component_clauseContext): - pass - - # Enter a parse tree produced by Modelica#short_component_declaration. - def enterShort_component_declaration( - self, ctx: Modelica.Short_component_declarationContext - ): - pass - - # Exit a parse tree produced by Modelica#short_component_declaration. - def exitShort_component_declaration( - self, ctx: Modelica.Short_component_declarationContext - ): - pass - - # Enter a parse tree produced by Modelica#short_definition. - def enterShort_definition(self, ctx: Modelica.Short_definitionContext): - pass - - # Exit a parse tree produced by Modelica#short_definition. - def exitShort_definition(self, ctx: Modelica.Short_definitionContext): - pass - - # Enter a parse tree produced by Modelica#equation_section. - def enterEquation_section(self, ctx: Modelica.Equation_sectionContext): - pass - - # Exit a parse tree produced by Modelica#equation_section. - def exitEquation_section(self, ctx: Modelica.Equation_sectionContext): - pass - - # Enter a parse tree produced by Modelica#algorithm_section. - def enterAlgorithm_section(self, ctx: Modelica.Algorithm_sectionContext): - pass - - # Exit a parse tree produced by Modelica#algorithm_section. - def exitAlgorithm_section(self, ctx: Modelica.Algorithm_sectionContext): - pass - - # Enter a parse tree produced by Modelica#equation_list. - def enterEquation_list(self, ctx: Modelica.Equation_listContext): - pass - - # Exit a parse tree produced by Modelica#equation_list. - def exitEquation_list(self, ctx: Modelica.Equation_listContext): - pass - - # Enter a parse tree produced by Modelica#statement_list. - def enterStatement_list(self, ctx: Modelica.Statement_listContext): - pass - - # Exit a parse tree produced by Modelica#statement_list. - def exitStatement_list(self, ctx: Modelica.Statement_listContext): - pass - - # Enter a parse tree produced by Modelica#equation. - def enterEquation(self, ctx: Modelica.EquationContext): - pass - - # Exit a parse tree produced by Modelica#equation. - def exitEquation(self, ctx: Modelica.EquationContext): - pass - - # Enter a parse tree produced by Modelica#statement. - def enterStatement(self, ctx: Modelica.StatementContext): - pass - - # Exit a parse tree produced by Modelica#statement. - def exitStatement(self, ctx: Modelica.StatementContext): - pass - - # Enter a parse tree produced by Modelica#if_equation. - def enterIf_equation(self, ctx: Modelica.If_equationContext): - pass - - # Exit a parse tree produced by Modelica#if_equation. - def exitIf_equation(self, ctx: Modelica.If_equationContext): - pass - - # Enter a parse tree produced by Modelica#conditional_equations. - def enterConditional_equations(self, ctx: Modelica.Conditional_equationsContext): - pass - - # Exit a parse tree produced by Modelica#conditional_equations. - def exitConditional_equations(self, ctx: Modelica.Conditional_equationsContext): - pass - - # Enter a parse tree produced by Modelica#if_statement. - def enterIf_statement(self, ctx: Modelica.If_statementContext): - pass - - # Exit a parse tree produced by Modelica#if_statement. - def exitIf_statement(self, ctx: Modelica.If_statementContext): - pass - - # Enter a parse tree produced by Modelica#if_branch. - def enterIf_branch(self, ctx: Modelica.If_branchContext): - pass - - # Exit a parse tree produced by Modelica#if_branch. - def exitIf_branch(self, ctx: Modelica.If_branchContext): - pass - - # Enter a parse tree produced by Modelica#elseif_branch. - def enterElseif_branch(self, ctx: Modelica.Elseif_branchContext): - pass - - # Exit a parse tree produced by Modelica#elseif_branch. - def exitElseif_branch(self, ctx: Modelica.Elseif_branchContext): - pass - - # Enter a parse tree produced by Modelica#else_branch. - def enterElse_branch(self, ctx: Modelica.Else_branchContext): - pass - - # Exit a parse tree produced by Modelica#else_branch. - def exitElse_branch(self, ctx: Modelica.Else_branchContext): - pass - - # Enter a parse tree produced by Modelica#conditional_statements. - def enterConditional_statements(self, ctx: Modelica.Conditional_statementsContext): - pass - - # Exit a parse tree produced by Modelica#conditional_statements. - def exitConditional_statements(self, ctx: Modelica.Conditional_statementsContext): - pass - - # Enter a parse tree produced by Modelica#for_equation. - def enterFor_equation(self, ctx: Modelica.For_equationContext): - pass - - # Exit a parse tree produced by Modelica#for_equation. - def exitFor_equation(self, ctx: Modelica.For_equationContext): - pass - - # Enter a parse tree produced by Modelica#for_statement. - def enterFor_statement(self, ctx: Modelica.For_statementContext): - pass - - # Exit a parse tree produced by Modelica#for_statement. - def exitFor_statement(self, ctx: Modelica.For_statementContext): - pass - - # Enter a parse tree produced by Modelica#for_indices. - def enterFor_indices(self, ctx: Modelica.For_indicesContext): - pass - - # Exit a parse tree produced by Modelica#for_indices. - def exitFor_indices(self, ctx: Modelica.For_indicesContext): - pass - - # Enter a parse tree produced by Modelica#for_index. - def enterFor_index(self, ctx: Modelica.For_indexContext): - pass - - # Exit a parse tree produced by Modelica#for_index. - def exitFor_index(self, ctx: Modelica.For_indexContext): - pass - - # Enter a parse tree produced by Modelica#while_statement. - def enterWhile_statement(self, ctx: Modelica.While_statementContext): - pass - - # Exit a parse tree produced by Modelica#while_statement. - def exitWhile_statement(self, ctx: Modelica.While_statementContext): - pass - - # Enter a parse tree produced by Modelica#when_equation. - def enterWhen_equation(self, ctx: Modelica.When_equationContext): - pass - - # Exit a parse tree produced by Modelica#when_equation. - def exitWhen_equation(self, ctx: Modelica.When_equationContext): - pass - - # Enter a parse tree produced by Modelica#when_statement. - def enterWhen_statement(self, ctx: Modelica.When_statementContext): - pass - - # Exit a parse tree produced by Modelica#when_statement. - def exitWhen_statement(self, ctx: Modelica.When_statementContext): - pass - - # Enter a parse tree produced by Modelica#when_branch. - def enterWhen_branch(self, ctx: Modelica.When_branchContext): - pass - - # Exit a parse tree produced by Modelica#when_branch. - def exitWhen_branch(self, ctx: Modelica.When_branchContext): - pass - - # Enter a parse tree produced by Modelica#elsewhen_branch. - def enterElsewhen_branch(self, ctx: Modelica.Elsewhen_branchContext): - pass - - # Exit a parse tree produced by Modelica#elsewhen_branch. - def exitElsewhen_branch(self, ctx: Modelica.Elsewhen_branchContext): - pass - - # Enter a parse tree produced by Modelica#connect_equation. - def enterConnect_equation(self, ctx: Modelica.Connect_equationContext): - pass - - # Exit a parse tree produced by Modelica#connect_equation. - def exitConnect_equation(self, ctx: Modelica.Connect_equationContext): - pass - - # Enter a parse tree produced by Modelica#connected_components. - def enterConnected_components(self, ctx: Modelica.Connected_componentsContext): - pass - - # Exit a parse tree produced by Modelica#connected_components. - def exitConnected_components(self, ctx: Modelica.Connected_componentsContext): - pass - - # Enter a parse tree produced by Modelica#expression. - def enterExpression(self, ctx: Modelica.ExpressionContext): - pass - - # Exit a parse tree produced by Modelica#expression. - def exitExpression(self, ctx: Modelica.ExpressionContext): - pass - - # Enter a parse tree produced by Modelica#if_expression. - def enterIf_expression(self, ctx: Modelica.If_expressionContext): - pass - - # Exit a parse tree produced by Modelica#if_expression. - def exitIf_expression(self, ctx: Modelica.If_expressionContext): - pass - - # Enter a parse tree produced by Modelica#if_eval. - def enterIf_eval(self, ctx: Modelica.If_evalContext): - pass - - # Exit a parse tree produced by Modelica#if_eval. - def exitIf_eval(self, ctx: Modelica.If_evalContext): - pass - - # Enter a parse tree produced by Modelica#elseif_eval. - def enterElseif_eval(self, ctx: Modelica.Elseif_evalContext): - pass - - # Exit a parse tree produced by Modelica#elseif_eval. - def exitElseif_eval(self, ctx: Modelica.Elseif_evalContext): - pass - - # Enter a parse tree produced by Modelica#else_eval. - def enterElse_eval(self, ctx: Modelica.Else_evalContext): - pass - - # Exit a parse tree produced by Modelica#else_eval. - def exitElse_eval(self, ctx: Modelica.Else_evalContext): - pass - - # Enter a parse tree produced by Modelica#conditional_expression. - def enterConditional_expression(self, ctx: Modelica.Conditional_expressionContext): - pass - - # Exit a parse tree produced by Modelica#conditional_expression. - def exitConditional_expression(self, ctx: Modelica.Conditional_expressionContext): - pass - - # Enter a parse tree produced by Modelica#simple_expression. - def enterSimple_expression(self, ctx: Modelica.Simple_expressionContext): - pass - - # Exit a parse tree produced by Modelica#simple_expression. - def exitSimple_expression(self, ctx: Modelica.Simple_expressionContext): - pass - - # Enter a parse tree produced by Modelica#logical_expression. - def enterLogical_expression(self, ctx: Modelica.Logical_expressionContext): - pass - - # Exit a parse tree produced by Modelica#logical_expression. - def exitLogical_expression(self, ctx: Modelica.Logical_expressionContext): - pass - - # Enter a parse tree produced by Modelica#or_operator. - def enterOr_operator(self, ctx: Modelica.Or_operatorContext): - pass - - # Exit a parse tree produced by Modelica#or_operator. - def exitOr_operator(self, ctx: Modelica.Or_operatorContext): - pass - - # Enter a parse tree produced by Modelica#logical_term. - def enterLogical_term(self, ctx: Modelica.Logical_termContext): - pass - - # Exit a parse tree produced by Modelica#logical_term. - def exitLogical_term(self, ctx: Modelica.Logical_termContext): - pass - - # Enter a parse tree produced by Modelica#and_operator. - def enterAnd_operator(self, ctx: Modelica.And_operatorContext): - pass - - # Exit a parse tree produced by Modelica#and_operator. - def exitAnd_operator(self, ctx: Modelica.And_operatorContext): - pass - - # Enter a parse tree produced by Modelica#logical_factor. - def enterLogical_factor(self, ctx: Modelica.Logical_factorContext): - pass - - # Exit a parse tree produced by Modelica#logical_factor. - def exitLogical_factor(self, ctx: Modelica.Logical_factorContext): - pass - - # Enter a parse tree produced by Modelica#relation. - def enterRelation(self, ctx: Modelica.RelationContext): - pass - - # Exit a parse tree produced by Modelica#relation. - def exitRelation(self, ctx: Modelica.RelationContext): - pass - - # Enter a parse tree produced by Modelica#relational_operator. - def enterRelational_operator(self, ctx: Modelica.Relational_operatorContext): - pass - - # Exit a parse tree produced by Modelica#relational_operator. - def exitRelational_operator(self, ctx: Modelica.Relational_operatorContext): - pass - - # Enter a parse tree produced by Modelica#arithmetic_expression. - def enterArithmetic_expression(self, ctx: Modelica.Arithmetic_expressionContext): - pass - - # Exit a parse tree produced by Modelica#arithmetic_expression. - def exitArithmetic_expression(self, ctx: Modelica.Arithmetic_expressionContext): - pass - - # Enter a parse tree produced by Modelica#unary_expression. - def enterUnary_expression(self, ctx: Modelica.Unary_expressionContext): - pass - - # Exit a parse tree produced by Modelica#unary_expression. - def exitUnary_expression(self, ctx: Modelica.Unary_expressionContext): - pass - - # Enter a parse tree produced by Modelica#unary_operand. - def enterUnary_operand(self, ctx: Modelica.Unary_operandContext): - pass - - # Exit a parse tree produced by Modelica#unary_operand. - def exitUnary_operand(self, ctx: Modelica.Unary_operandContext): - pass - - # Enter a parse tree produced by Modelica#add_operator. - def enterAdd_operator(self, ctx: Modelica.Add_operatorContext): - pass - - # Exit a parse tree produced by Modelica#add_operator. - def exitAdd_operator(self, ctx: Modelica.Add_operatorContext): - pass - - # Enter a parse tree produced by Modelica#term. - def enterTerm(self, ctx: Modelica.TermContext): - pass - - # Exit a parse tree produced by Modelica#term. - def exitTerm(self, ctx: Modelica.TermContext): - pass - - # Enter a parse tree produced by Modelica#mul_operator. - def enterMul_operator(self, ctx: Modelica.Mul_operatorContext): - pass - - # Exit a parse tree produced by Modelica#mul_operator. - def exitMul_operator(self, ctx: Modelica.Mul_operatorContext): - pass - - # Enter a parse tree produced by Modelica#factor. - def enterFactor(self, ctx: Modelica.FactorContext): - pass - - # Exit a parse tree produced by Modelica#factor. - def exitFactor(self, ctx: Modelica.FactorContext): - pass - - # Enter a parse tree produced by Modelica#exp_operator. - def enterExp_operator(self, ctx: Modelica.Exp_operatorContext): - pass - - # Exit a parse tree produced by Modelica#exp_operator. - def exitExp_operator(self, ctx: Modelica.Exp_operatorContext): - pass - - # Enter a parse tree produced by Modelica#primary. - def enterPrimary(self, ctx: Modelica.PrimaryContext): - pass - - # Exit a parse tree produced by Modelica#primary. - def exitPrimary(self, ctx: Modelica.PrimaryContext): - pass - - # Enter a parse tree produced by Modelica#type_specifier. - def enterType_specifier(self, ctx: Modelica.Type_specifierContext): - pass - - # Exit a parse tree produced by Modelica#type_specifier. - def exitType_specifier(self, ctx: Modelica.Type_specifierContext): - pass - - # Enter a parse tree produced by Modelica#name. - def enterName(self, ctx: Modelica.NameContext): - pass - - # Exit a parse tree produced by Modelica#name. - def exitName(self, ctx: Modelica.NameContext): - pass - - # Enter a parse tree produced by Modelica#component_reference. - def enterComponent_reference(self, ctx: Modelica.Component_referenceContext): - pass - - # Exit a parse tree produced by Modelica#component_reference. - def exitComponent_reference(self, ctx: Modelica.Component_referenceContext): - pass - - # Enter a parse tree produced by Modelica#function_call_args. - def enterFunction_call_args(self, ctx: Modelica.Function_call_argsContext): - pass - - # Exit a parse tree produced by Modelica#function_call_args. - def exitFunction_call_args(self, ctx: Modelica.Function_call_argsContext): - pass - - # Enter a parse tree produced by Modelica#function_arguments. - def enterFunction_arguments(self, ctx: Modelica.Function_argumentsContext): - pass - - # Exit a parse tree produced by Modelica#function_arguments. - def exitFunction_arguments(self, ctx: Modelica.Function_argumentsContext): - pass - - # Enter a parse tree produced by Modelica#named_arguments. - def enterNamed_arguments(self, ctx: Modelica.Named_argumentsContext): - pass - - # Exit a parse tree produced by Modelica#named_arguments. - def exitNamed_arguments(self, ctx: Modelica.Named_argumentsContext): - pass - - # Enter a parse tree produced by Modelica#named_argument. - def enterNamed_argument(self, ctx: Modelica.Named_argumentContext): - pass - - # Exit a parse tree produced by Modelica#named_argument. - def exitNamed_argument(self, ctx: Modelica.Named_argumentContext): - pass - - # Enter a parse tree produced by Modelica#function_argument. - def enterFunction_argument(self, ctx: Modelica.Function_argumentContext): - pass - - # Exit a parse tree produced by Modelica#function_argument. - def exitFunction_argument(self, ctx: Modelica.Function_argumentContext): - pass - - # Enter a parse tree produced by Modelica#function_partial_application. - def enterFunction_partial_application( - self, ctx: Modelica.Function_partial_applicationContext - ): - pass - - # Exit a parse tree produced by Modelica#function_partial_application. - def exitFunction_partial_application( - self, ctx: Modelica.Function_partial_applicationContext - ): - pass - - # Enter a parse tree produced by Modelica#output_expression_list. - def enterOutput_expression_list(self, ctx: Modelica.Output_expression_listContext): - pass - - # Exit a parse tree produced by Modelica#output_expression_list. - def exitOutput_expression_list(self, ctx: Modelica.Output_expression_listContext): - pass - - # Enter a parse tree produced by Modelica#expression_list. - def enterExpression_list(self, ctx: Modelica.Expression_listContext): - pass - - # Exit a parse tree produced by Modelica#expression_list. - def exitExpression_list(self, ctx: Modelica.Expression_listContext): - pass - - # Enter a parse tree produced by Modelica#array_arguments. - def enterArray_arguments(self, ctx: Modelica.Array_argumentsContext): - pass - - # Exit a parse tree produced by Modelica#array_arguments. - def exitArray_arguments(self, ctx: Modelica.Array_argumentsContext): - pass - - # Enter a parse tree produced by Modelica#array_subscripts. - def enterArray_subscripts(self, ctx: Modelica.Array_subscriptsContext): - pass - - # Exit a parse tree produced by Modelica#array_subscripts. - def exitArray_subscripts(self, ctx: Modelica.Array_subscriptsContext): - pass - - # Enter a parse tree produced by Modelica#subscript. - def enterSubscript(self, ctx: Modelica.SubscriptContext): - pass - - # Exit a parse tree produced by Modelica#subscript. - def exitSubscript(self, ctx: Modelica.SubscriptContext): - pass - - # Enter a parse tree produced by Modelica#description. - def enterDescription(self, ctx: Modelica.DescriptionContext): - pass - - # Exit a parse tree produced by Modelica#description. - def exitDescription(self, ctx: Modelica.DescriptionContext): - pass - - # Enter a parse tree produced by Modelica#description_string. - def enterDescription_string(self, ctx: Modelica.Description_stringContext): - pass - - # Exit a parse tree produced by Modelica#description_string. - def exitDescription_string(self, ctx: Modelica.Description_stringContext): - pass - - # Enter a parse tree produced by Modelica#cat_operator. - def enterCat_operator(self, ctx: Modelica.Cat_operatorContext): - pass - - # Exit a parse tree produced by Modelica#cat_operator. - def exitCat_operator(self, ctx: Modelica.Cat_operatorContext): - pass - - # Enter a parse tree produced by Modelica#annotation. - def enterAnnotation(self, ctx: Modelica.AnnotationContext): - pass - - # Exit a parse tree produced by Modelica#annotation. - def exitAnnotation(self, ctx: Modelica.AnnotationContext): - pass - - -del Modelica diff --git a/mofmt/parsing/generated/__init__.py b/mofmt/parsing/generated/__init__.py deleted file mode 100644 index e605518..0000000 --- a/mofmt/parsing/generated/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Module containing Antlr-generated files""" - -from .Modelica import Modelica -from .ModelicaLexer import ModelicaLexer -from .ModelicaListener import ModelicaListener diff --git a/mofmt/parsing/parser.py b/mofmt/parsing/parser.py deleted file mode 100644 index 973ebea..0000000 --- a/mofmt/parsing/parser.py +++ /dev/null @@ -1,412 +0,0 @@ -"""Classes used for parsing.""" -# In future this code should be replaced by custom parser. - -import antlr4 as antlr -from antlr4.Lexer import Lexer - -from mofmt.collecting.collector import Collector - -from .generated import Modelica, ModelicaLexer, ModelicaListener - -NO_SPACE_BEFORE = ( - ModelicaLexer.RPAREN, - ModelicaLexer.RBRACK, - ModelicaLexer.RCURLY, - ModelicaLexer.SEMICOLON, - ModelicaLexer.COMMA, - ModelicaLexer.COLON, -) - -NO_SPACE_AFTER = ( - ModelicaLexer.LPAREN, - ModelicaLexer.DOT, - ModelicaLexer.LBRACK, - ModelicaLexer.LCURLY, - ModelicaLexer.SEMICOLON, - ModelicaLexer.COLON, -) - -NO_BREAK_BEFORE = ( - ModelicaLexer.END, - ModelicaLexer.ELSE, - ModelicaLexer.ELSEIF, - ModelicaLexer.ELSEWHEN, -) - - -class Listener(ModelicaListener): # type: ignore - """Custom listener for parsing Modelica source""" - - def __init__(self, stream: antlr.CommonTokenStream) -> None: - super().__init__() - self.stream = stream - self.collector = Collector() - self.prev_token_line: int = 1 - self.prev_token: int = 0 - self.rule_stack = [0] - self.group_stack: list[bool] = [False] - self.wrap_stack: list[bool] = [False] - # Number of unclosed brackets - self.bracket_counter: int = 0 - - def handle_comments(self, comments: list[antlr.Token], current_line: int) -> None: - """ - Handle comments and separate them if needed. - - Parameters - ---------- - comments : list - List of comments that were originally located before token - current_line : int - Line where token occured - """ - line = self.prev_token_line - line_diff = comments[0].line - line - tail = [] - if line_diff == 0: - tail = self.collector.cache_tail() - for comment in comments: - line_diff = comment.line - line - if line_diff == 0: - self.collector.add_space() - elif line_diff == 1: - self.collector.add_break() - else: - if self.prev_token == ModelicaLexer.SEMICOLON: - self.collector.add_blank() - self.collector.add_comment(comment.text) - line = comment.line - if self.prev_token_line == 1: - self.collector.add_break() - return - if len(tail) > 0: - self.collector.append(tail) - return - line_diff = current_line - line - if line_diff == 1: - self.collector.add_break() - return - if line_diff > 1: - self.collector.add_blank() - - def visitTerminal(self, node: antlr.TerminalNode) -> None: - """ - Generic method called by Antlr listener every time it finds - terminal. - """ - token: antlr.Token = node.getSymbol() - kind = token.type - line = token.line - comments = self.stream.getHiddenTokensToLeft( - token.tokenIndex, ModelicaLexer.COMMENTS - ) - if self.prev_token == ModelicaLexer.SEMICOLON: - if self.bracket_counter == 0: - self.collector.add_break() - else: - self.collector.add_space() - if not comments: - if line - self.prev_token_line > 1 and kind not in NO_BREAK_BEFORE: - self.collector.add_blank() - if comments: - self.handle_comments(comments, line) - - # Handle special cases - if kind == ModelicaLexer.LBRACK: - self.bracket_counter += 1 - if self.prev_token not in (ModelicaLexer.IDENT,) + NO_SPACE_AFTER: - self.collector.add_space() - elif kind == ModelicaLexer.RBRACK: - self.bracket_counter -= 1 - elif kind == ModelicaLexer.FOR: - self.break_or_space() - elif kind == ModelicaLexer.DOT: - # Only first dot in type specifiers etc. can be preceded with a space - if ( - self.prev_token - not in (ModelicaLexer.IDENT, ModelicaLexer.RBRACK) + NO_SPACE_AFTER - ): - self.collector.add_space() - elif kind not in NO_SPACE_BEFORE and self.prev_token not in NO_SPACE_AFTER: - self.collector.add_space() - - self.collector.add_token(token.text) - if kind == ModelicaLexer.ANNOTATION: - self.collector.add_space() - self.prev_token = kind - self.prev_token_line = line - - def enter_grouped_rule(self, ctx: antlr.ParserRuleContext) -> None: - """If the rule was wrapped add info to the stack and increase indent""" - self.group_stack.append(False) - if is_multiline(ctx): - self.group_stack[-1] = True - if ctx.getRuleIndex() == Modelica.RULE_if_expression: - if get_preceding_token(ctx, self.stream).type in ( - ModelicaLexer.EQUAL, - ModelicaLexer.ASSIGN, - ): - self.collector.add_indent() - elif ctx.getRuleIndex() == Modelica.RULE_expression_list: - if not self.group_stack[-2]: - self.collector.add_indent() - else: - self.collector.add_indent() - - def exit_grouped_rule(self, ctx: antlr.ParserRuleContext) -> None: - """Decrease indent when leaving wrapped group""" - if self.group_stack[-1]: - if ctx.getRuleIndex() == Modelica.RULE_if_expression: - if get_preceding_token(ctx, self.stream).type in ( - ModelicaLexer.EQUAL, - ModelicaLexer.ASSIGN, - ): - self.collector.add_dedent() - elif ctx.getRuleIndex() == Modelica.RULE_expression_list: - if not self.group_stack[-2]: - self.collector.add_dedent() - else: - self.collector.add_dedent() - self.group_stack.pop() - - def break_or_space(self): - """Insert line break or space""" - if self.group_stack[-1]: - self.collector.add_break() - else: - if self.prev_token not in NO_SPACE_AFTER: - self.collector.add_space() - - def wrap_expression(self, ctx: antlr.ParserRuleContext): - """Wrap the expression""" - next_token = get_following_token(ctx, self.stream) - # Check if there was a line break around the wrap point - if next_token.line > self.prev_token_line: - # Exclude unary expressions - if ctx.parentCtx.getRuleIndex() != Modelica.RULE_unary_expression: - if not self.wrap_stack[-1]: - self.collector.add_indent() - self.collector.add_wrappoint() - self.wrap_stack[-1] = True - - def enterEveryRule(self, ctx: antlr.ParserRuleContext) -> None: - """ - Generic method called by Antlr listener every time it enters a - grammar rule. - """ - if len(ctx.getText()) == 0: - return - rule = ctx.getRuleIndex() - self.rule_stack.append(rule) - if rule == Modelica.RULE_description_string: - self.collector.add_indent() - self.collector.add_break() - elif rule == Modelica.RULE_annotation: - self.collector.add_indent() - self.collector.add_break() - elif rule == Modelica.RULE_constraining_clause: - self.collector.add_indent() - self.collector.add_break() - elif rule == Modelica.RULE_conditional_equations: - self.collector.add_indent() - self.collector.add_break() - elif rule == Modelica.RULE_conditional_statements: - self.collector.add_indent() - self.collector.add_break() - elif rule == Modelica.RULE_enumeration_literal: - self.collector.add_break() - elif rule == Modelica.RULE_elseif_branch: - self.collector.add_break() - elif rule == Modelica.RULE_else_branch: - self.collector.add_break() - elif rule == Modelica.RULE_elsewhen_branch: - self.collector.add_break() - elif rule == Modelica.RULE_element_list: - self.collector.add_indent() - self.collector.add_blank() - elif rule == Modelica.RULE_external_element: - self.collector.add_indent() - self.collector.add_blank() - elif rule == Modelica.RULE_equation_list: - self.collector.add_indent() - self.collector.add_blank() - elif rule == Modelica.RULE_statement_list: - self.collector.add_indent() - self.collector.add_blank() - elif rule == Modelica.RULE_class_annotation: - self.collector.add_indent() - self.collector.add_blank() - elif rule == Modelica.RULE_enum_list: - self.collector.add_indent() - elif rule == Modelica.RULE_conditional_expression: - self.collector.add_indent() - self.break_or_space() - elif rule == Modelica.RULE_equation_section: - self.collector.add_blank() - elif rule == Modelica.RULE_algorithm_section: - self.collector.add_blank() - elif rule == Modelica.RULE_protected_element_list: - self.collector.add_blank() - elif rule == Modelica.RULE_public_element_list: - self.collector.add_blank() - elif rule == Modelica.RULE_end_clause: - self.collector.add_blank() - elif rule == Modelica.RULE_external_function_args: - self.collector.add_ignore() - elif rule == Modelica.RULE_enumerations: - self.collector.add_ignore() - elif rule == Modelica.RULE_unary_operand: - self.collector.add_ignore() - elif rule == Modelica.RULE_connected_components: - self.collector.add_ignore() - elif rule == Modelica.RULE_if_expression: - self.enter_grouped_rule(ctx) - elif rule == Modelica.RULE_primary: - # Handle matrix or array - if ctx.start.type in (ModelicaLexer.LBRACK, ModelicaLexer.LCURLY): - self.enter_grouped_rule(ctx) - elif rule == Modelica.RULE_function_call_args: - self.enter_grouped_rule(ctx) - self.collector.add_ignore() - elif rule == Modelica.RULE_class_or_inheritance_modification: - self.enter_grouped_rule(ctx) - self.collector.add_ignore() - elif rule == Modelica.RULE_class_modification: - self.enter_grouped_rule(ctx) - self.collector.add_ignore() - elif rule == Modelica.RULE_array_subscripts: - self.enter_grouped_rule(ctx) - self.collector.add_ignore() - elif rule == Modelica.RULE_expression_list: - self.break_or_space() - self.enter_grouped_rule(ctx) - elif rule == Modelica.RULE_subscript: - self.break_or_space() - elif rule == Modelica.RULE_function_argument: - # do not break if it is part of named arg - if self.prev_token != ModelicaLexer.EQUAL: - self.break_or_space() - elif rule == Modelica.RULE_named_argument: - self.break_or_space() - elif rule == Modelica.RULE_argument: - self.break_or_space() - elif rule == Modelica.RULE_inheritance_modification: - self.break_or_space() - elif rule == Modelica.RULE_if_eval: - self.break_or_space() - elif rule == Modelica.RULE_elseif_eval: - self.break_or_space() - elif rule == Modelica.RULE_else_eval: - self.break_or_space() - elif rule == Modelica.RULE_conditional_expression: - self.break_or_space() - elif rule == Modelica.RULE_exp_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_mul_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_add_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_relational_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_cat_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_or_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_and_operator: - self.wrap_expression(ctx) - elif rule == Modelica.RULE_expression: - # Handle arguments etc. - if self.rule_stack[-2] in ( - Modelica.RULE_expression_list, - Modelica.RULE_external_function_args, - Modelica.RULE_array_arguments, - ): - self.break_or_space() - self.wrap_stack.append(False) - - def exitEveryRule(self, ctx: antlr.ParserRuleContext) -> None: - """ - Generic method called by Antlr listener every time it exits a - grammar rule. - """ - if len(ctx.getText()) == 0: - return - rule = self.rule_stack.pop() - if rule == Modelica.RULE_description_string: - self.collector.add_dedent() - elif rule == Modelica.RULE_annotation: - self.collector.add_dedent() - elif rule == Modelica.RULE_constraining_clause: - self.collector.add_dedent() - elif rule == Modelica.RULE_conditional_equations: - self.collector.add_dedent() - elif rule == Modelica.RULE_conditional_statements: - self.collector.add_dedent() - elif rule == Modelica.RULE_element_list: - self.collector.add_dedent() - elif rule == Modelica.RULE_external_element: - self.collector.add_dedent() - elif rule == Modelica.RULE_equation_list: - self.collector.add_dedent() - elif rule == Modelica.RULE_statement_list: - self.collector.add_dedent() - elif rule == Modelica.RULE_class_annotation: - self.collector.add_dedent() - elif rule == Modelica.RULE_enum_list: - self.collector.add_dedent() - elif rule == Modelica.RULE_conditional_expression: - self.collector.add_dedent() - elif rule == Modelica.RULE_if_expression: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_primary: - # Handle matrix - if ctx.start.type in (ModelicaLexer.LBRACK, ModelicaLexer.LCURLY): - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_function_call_args: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_class_or_inheritance_modification: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_class_modification: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_array_subscripts: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_expression_list: - self.exit_grouped_rule(ctx) - elif rule == Modelica.RULE_expression: - wrapped = self.wrap_stack.pop() - if wrapped: - self.collector.add_dedent() - - -# Helper functions - - -def is_multiline(ctx: antlr.ParserRuleContext) -> bool: - """Return `True` if the rule is multiline""" - # To satisfy the mypy - result: bool = (ctx.stop.line - ctx.start.line) > 0 - return result - - -def get_preceding_token( - ctx: antlr.ParserRuleContext, stream: antlr.CommonTokenStream -) -> antlr.Token: - """Return token that precedes this rule""" - prev_token_idx = stream.previousTokenOnChannel( - ctx.start.tokenIndex - 1, Lexer.DEFAULT_TOKEN_CHANNEL - ) - return stream.filterForChannel( - prev_token_idx, prev_token_idx, Lexer.DEFAULT_TOKEN_CHANNEL - )[0] - - -def get_following_token( - ctx: antlr.ParserRuleContext, stream: antlr.CommonTokenStream -) -> antlr.Token: - """Return token that follows this rule""" - next_token_id = stream.nextTokenOnChannel( - ctx.stop.tokenIndex + 1, Lexer.DEFAULT_TOKEN_CHANNEL - ) - return stream.filterForChannel( - next_token_id, next_token_id + 1, Lexer.DEFAULT_TOKEN_CHANNEL - )[0] diff --git a/mofmt/parsing/parsing.py b/mofmt/parsing/parsing.py deleted file mode 100644 index c9f7218..0000000 --- a/mofmt/parsing/parsing.py +++ /dev/null @@ -1,62 +0,0 @@ -"""Helper functions used to parse source code""" - -import sys -from pathlib import Path -from typing import Callable - -import antlr4 as antlr -from antlr4.error.ErrorListener import ConsoleErrorListener - -from mofmt.collecting.collector import Marker - -from .generated import Modelica, ModelicaLexer -from .parser import Listener - - -def parse_source( - path: Path, - source: str, - entry_rule: Callable[ - [Modelica], antlr.ParserRuleContext - ] = Modelica.stored_definition, -) -> list[Marker]: - """ - Return list of printing markers generated from Modelica source code. - - Parameters - ---------- - source : str - Modelica source code - - Returns - ------- - list - List of printing markers - """ - input_stream = antlr.InputStream(source) - lexer = ModelicaLexer(input_stream) - stream = antlr.CommonTokenStream(lexer) - parser = Modelica(stream) - handler = ErrorHandler(path) - parser.removeErrorListeners() - parser.addErrorListener(handler) - listener = Listener(stream) - walker = antlr.ParseTreeWalker() - walker.walk(listener, entry_rule(parser)) - # Append empty line - listener.collector.add_break() - if parser._syntaxErrors > 0: - listener.collector.markers = [] - return listener.collector.markers - - -class ErrorHandler(ConsoleErrorListener): - def __init__(self, path) -> None: - self.path = path - super().__init__() - - def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): - print( - f"{self.path}:{line}:{column}: {msg}", - file=sys.stderr, - ) diff --git a/mofmt/printing/__init__.py b/mofmt/printing/__init__.py deleted file mode 100644 index 30108f2..0000000 --- a/mofmt/printing/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Module related to pretty printing""" - -__all__ = ["Printer"] - -from .printing import Printer diff --git a/mofmt/printing/printing.py b/mofmt/printing/printing.py deleted file mode 100644 index 8388075..0000000 --- a/mofmt/printing/printing.py +++ /dev/null @@ -1,63 +0,0 @@ -"""Functions used for pretty printing Modelica code""" - -from mofmt.collecting.collector import Marker - - -class Printer: - """ - Class used for markers printing. - - Attributes - ---------- - lvl : int - Current indentation level - markers : list of Marker - Markers collected in the Collector object - printable : list of str - List of strings generated from Markers - """ - - INDENT = " " - __slots__ = ("lvl", "markers", "printable") - - def __init__(self, markers: list[Marker]) -> None: - self.lvl: int = 0 - self.markers = markers - self.printable: list[str] = [] - - def print_marker(self, marker: Marker) -> str: - """ - Return marker converted to string and update indentation level. - - Parameters - ---------- - marker : Marker - Single marker produced in collector - - Returns - ------- - str - String produced from marker - """ - typ = marker.typ - if typ == Marker.INDENT: - self.lvl += 1 - return marker.val - if typ == Marker.DEDENT: - self.lvl -= 1 - return marker.val - if typ >= Marker.BLANK: - marker.val += self.lvl * Printer.INDENT - return marker.val - - def pretty_print(self) -> str: - """ - Return formatted Modelica code as a string. - - Returns - ------- - str - Pretty Modelica code - """ - self.printable = list(map(self.print_marker, self.markers)) - return "".join(self.printable) diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index e1aca51..0000000 --- a/poetry.lock +++ /dev/null @@ -1,560 +0,0 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. - -[[package]] -name = "antlr4-python3-runtime" -version = "4.13.0" -description = "ANTLR 4.13.0 runtime for Python 3" -optional = false -python-versions = "*" -files = [ - {file = "antlr4-python3-runtime-4.13.0.tar.gz", hash = "sha256:0d5454928ae40c8a6b653caa35046cd8492c8743b5fbc22ff4009099d074c7ae"}, - {file = "antlr4_python3_runtime-4.13.0-py3-none-any.whl", hash = "sha256:53e6e208cf4a1ad53fb8b1b4467b756375a4f827331e290618aedcf481cb1d5c"}, -] - -[[package]] -name = "black" -version = "23.11.0" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.8" -files = [ - {file = "black-23.11.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dbea0bb8575c6b6303cc65017b46351dc5953eea5c0a59d7b7e3a2d2f433a911"}, - {file = "black-23.11.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:412f56bab20ac85927f3a959230331de5614aecda1ede14b373083f62ec24e6f"}, - {file = "black-23.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d136ef5b418c81660ad847efe0e55c58c8208b77a57a28a503a5f345ccf01394"}, - {file = "black-23.11.0-cp310-cp310-win_amd64.whl", hash = "sha256:6c1cac07e64433f646a9a838cdc00c9768b3c362805afc3fce341af0e6a9ae9f"}, - {file = "black-23.11.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cf57719e581cfd48c4efe28543fea3d139c6b6f1238b3f0102a9c73992cbb479"}, - {file = "black-23.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:698c1e0d5c43354ec5d6f4d914d0d553a9ada56c85415700b81dc90125aac244"}, - {file = "black-23.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:760415ccc20f9e8747084169110ef75d545f3b0932ee21368f63ac0fee86b221"}, - {file = "black-23.11.0-cp311-cp311-win_amd64.whl", hash = "sha256:58e5f4d08a205b11800332920e285bd25e1a75c54953e05502052738fe16b3b5"}, - {file = "black-23.11.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:45aa1d4675964946e53ab81aeec7a37613c1cb71647b5394779e6efb79d6d187"}, - {file = "black-23.11.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4c44b7211a3a0570cc097e81135faa5f261264f4dfaa22bd5ee2875a4e773bd6"}, - {file = "black-23.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2a9acad1451632021ee0d146c8765782a0c3846e0e0ea46659d7c4f89d9b212b"}, - {file = "black-23.11.0-cp38-cp38-win_amd64.whl", hash = "sha256:fc7f6a44d52747e65a02558e1d807c82df1d66ffa80a601862040a43ec2e3142"}, - {file = "black-23.11.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7f622b6822f02bfaf2a5cd31fdb7cd86fcf33dab6ced5185c35f5db98260b055"}, - {file = "black-23.11.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:250d7e60f323fcfc8ea6c800d5eba12f7967400eb6c2d21ae85ad31c204fb1f4"}, - {file = "black-23.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5133f5507007ba08d8b7b263c7aa0f931af5ba88a29beacc4b2dc23fcefe9c06"}, - {file = "black-23.11.0-cp39-cp39-win_amd64.whl", hash = "sha256:421f3e44aa67138ab1b9bfbc22ee3780b22fa5b291e4db8ab7eee95200726b07"}, - {file = "black-23.11.0-py3-none-any.whl", hash = "sha256:54caaa703227c6e0c87b76326d0862184729a69b73d3b7305b6288e1d830067e"}, - {file = "black-23.11.0.tar.gz", hash = "sha256:4c68855825ff432d197229846f971bc4d6666ce90492e5b02013bcaca4d9ab05"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -packaging = ">=22.0" -pathspec = ">=0.9.0" -platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - -[[package]] -name = "cachetools" -version = "5.3.2" -description = "Extensible memoizing collections and decorators" -optional = false -python-versions = ">=3.7" -files = [ - {file = "cachetools-5.3.2-py3-none-any.whl", hash = "sha256:861f35a13a451f94e301ce2bec7cac63e881232ccce7ed67fab9b5df4d3beaa1"}, - {file = "cachetools-5.3.2.tar.gz", hash = "sha256:086ee420196f7b2ab9ca2db2520aca326318b68fe5ba8bc4d49cca91add450f2"}, -] - -[[package]] -name = "cfgv" -version = "3.4.0" -description = "Validate configuration and produce human readable error messages." -optional = false -python-versions = ">=3.8" -files = [ - {file = "cfgv-3.4.0-py2.py3-none-any.whl", hash = "sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9"}, - {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, -] - -[[package]] -name = "chardet" -version = "5.2.0" -description = "Universal encoding detector for Python 3" -optional = false -python-versions = ">=3.7" -files = [ - {file = "chardet-5.2.0-py3-none-any.whl", hash = "sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970"}, - {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, -] - -[[package]] -name = "click" -version = "8.1.7" -description = "Composable command line interface toolkit" -optional = false -python-versions = ">=3.7" -files = [ - {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, - {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} - -[[package]] -name = "colorama" -version = "0.4.6" -description = "Cross-platform colored terminal text." -optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" -files = [ - {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, - {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, -] - -[[package]] -name = "distlib" -version = "0.3.7" -description = "Distribution utilities" -optional = false -python-versions = "*" -files = [ - {file = "distlib-0.3.7-py2.py3-none-any.whl", hash = "sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057"}, - {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, -] - -[[package]] -name = "exceptiongroup" -version = "1.2.0" -description = "Backport of PEP 654 (exception groups)" -optional = false -python-versions = ">=3.7" -files = [ - {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, - {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, -] - -[package.extras] -test = ["pytest (>=6)"] - -[[package]] -name = "filelock" -version = "3.13.1" -description = "A platform independent file lock." -optional = false -python-versions = ">=3.8" -files = [ - {file = "filelock-3.13.1-py3-none-any.whl", hash = "sha256:57dbda9b35157b05fb3e58ee91448612eb674172fab98ee235ccb0b5bee19a1c"}, - {file = "filelock-3.13.1.tar.gz", hash = "sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e"}, -] - -[package.extras] -docs = ["furo (>=2023.9.10)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.24)"] -testing = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "diff-cover (>=8)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)", "pytest-timeout (>=2.2)"] -typing = ["typing-extensions (>=4.8)"] - -[[package]] -name = "identify" -version = "2.5.32" -description = "File identification library for Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "identify-2.5.32-py2.py3-none-any.whl", hash = "sha256:0b7656ef6cba81664b783352c73f8c24b39cf82f926f78f4550eda928e5e0545"}, - {file = "identify-2.5.32.tar.gz", hash = "sha256:5d9979348ec1a21c768ae07e0a652924538e8bce67313a73cb0f681cf08ba407"}, -] - -[package.extras] -license = ["ukkonen"] - -[[package]] -name = "iniconfig" -version = "2.0.0" -description = "brain-dead simple config-ini parsing" -optional = false -python-versions = ">=3.7" -files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, -] - -[[package]] -name = "isort" -version = "5.12.0" -description = "A Python utility / library to sort Python imports." -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, - {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, -] - -[package.extras] -colors = ["colorama (>=0.4.3)"] -pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] -plugins = ["setuptools"] -requirements-deprecated-finder = ["pip-api", "pipreqs"] - -[[package]] -name = "mypy" -version = "1.7.0" -description = "Optional static typing for Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "mypy-1.7.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5da84d7bf257fd8f66b4f759a904fd2c5a765f70d8b52dde62b521972a0a2357"}, - {file = "mypy-1.7.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a3637c03f4025f6405737570d6cbfa4f1400eb3c649317634d273687a09ffc2f"}, - {file = "mypy-1.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b633f188fc5ae1b6edca39dae566974d7ef4e9aaaae00bc36efe1f855e5173ac"}, - {file = "mypy-1.7.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:d6ed9a3997b90c6f891138e3f83fb8f475c74db4ccaa942a1c7bf99e83a989a1"}, - {file = "mypy-1.7.0-cp310-cp310-win_amd64.whl", hash = "sha256:1fe46e96ae319df21359c8db77e1aecac8e5949da4773c0274c0ef3d8d1268a9"}, - {file = "mypy-1.7.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:df67fbeb666ee8828f675fee724cc2cbd2e4828cc3df56703e02fe6a421b7401"}, - {file = "mypy-1.7.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a79cdc12a02eb526d808a32a934c6fe6df07b05f3573d210e41808020aed8b5d"}, - {file = "mypy-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f65f385a6f43211effe8c682e8ec3f55d79391f70a201575def73d08db68ead1"}, - {file = "mypy-1.7.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:0e81ffd120ee24959b449b647c4b2fbfcf8acf3465e082b8d58fd6c4c2b27e46"}, - {file = "mypy-1.7.0-cp311-cp311-win_amd64.whl", hash = "sha256:f29386804c3577c83d76520abf18cfcd7d68264c7e431c5907d250ab502658ee"}, - {file = "mypy-1.7.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:87c076c174e2c7ef8ab416c4e252d94c08cd4980a10967754f91571070bf5fbe"}, - {file = "mypy-1.7.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6cb8d5f6d0fcd9e708bb190b224089e45902cacef6f6915481806b0c77f7786d"}, - {file = "mypy-1.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d93e76c2256aa50d9c82a88e2f569232e9862c9982095f6d54e13509f01222fc"}, - {file = "mypy-1.7.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:cddee95dea7990e2215576fae95f6b78a8c12f4c089d7e4367564704e99118d3"}, - {file = "mypy-1.7.0-cp312-cp312-win_amd64.whl", hash = "sha256:d01921dbd691c4061a3e2ecdbfbfad029410c5c2b1ee88946bf45c62c6c91210"}, - {file = "mypy-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:185cff9b9a7fec1f9f7d8352dff8a4c713b2e3eea9c6c4b5ff7f0edf46b91e41"}, - {file = "mypy-1.7.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7a7b1e399c47b18feb6f8ad4a3eef3813e28c1e871ea7d4ea5d444b2ac03c418"}, - {file = "mypy-1.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fc9fe455ad58a20ec68599139ed1113b21f977b536a91b42bef3ffed5cce7391"}, - {file = "mypy-1.7.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:d0fa29919d2e720c8dbaf07d5578f93d7b313c3e9954c8ec05b6d83da592e5d9"}, - {file = "mypy-1.7.0-cp38-cp38-win_amd64.whl", hash = "sha256:2b53655a295c1ed1af9e96b462a736bf083adba7b314ae775563e3fb4e6795f5"}, - {file = "mypy-1.7.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c1b06b4b109e342f7dccc9efda965fc3970a604db70f8560ddfdee7ef19afb05"}, - {file = "mypy-1.7.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:bf7a2f0a6907f231d5e41adba1a82d7d88cf1f61a70335889412dec99feeb0f8"}, - {file = "mypy-1.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:551d4a0cdcbd1d2cccdcc7cb516bb4ae888794929f5b040bb51aae1846062901"}, - {file = "mypy-1.7.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:55d28d7963bef00c330cb6461db80b0b72afe2f3c4e2963c99517cf06454e665"}, - {file = "mypy-1.7.0-cp39-cp39-win_amd64.whl", hash = "sha256:870bd1ffc8a5862e593185a4c169804f2744112b4a7c55b93eb50f48e7a77010"}, - {file = "mypy-1.7.0-py3-none-any.whl", hash = "sha256:96650d9a4c651bc2a4991cf46f100973f656d69edc7faf91844e87fe627f7e96"}, - {file = "mypy-1.7.0.tar.gz", hash = "sha256:1e280b5697202efa698372d2f39e9a6713a0395a756b1c6bd48995f8d72690dc"}, -] - -[package.dependencies] -mypy-extensions = ">=1.0.0" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = ">=4.1.0" - -[package.extras] -dmypy = ["psutil (>=4.0)"] -install-types = ["pip"] -mypyc = ["setuptools (>=50)"] -reports = ["lxml"] - -[[package]] -name = "mypy-extensions" -version = "1.0.0" -description = "Type system extensions for programs checked with the mypy type checker." -optional = false -python-versions = ">=3.5" -files = [ - {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, - {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, -] - -[[package]] -name = "nodeenv" -version = "1.8.0" -description = "Node.js virtual environment builder" -optional = false -python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" -files = [ - {file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"}, - {file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"}, -] - -[package.dependencies] -setuptools = "*" - -[[package]] -name = "packaging" -version = "23.2" -description = "Core utilities for Python packages" -optional = false -python-versions = ">=3.7" -files = [ - {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, - {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, -] - -[[package]] -name = "pathspec" -version = "0.11.2" -description = "Utility library for gitignore style pattern matching of file paths." -optional = false -python-versions = ">=3.7" -files = [ - {file = "pathspec-0.11.2-py3-none-any.whl", hash = "sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20"}, - {file = "pathspec-0.11.2.tar.gz", hash = "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3"}, -] - -[[package]] -name = "platformdirs" -version = "4.0.0" -description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -optional = false -python-versions = ">=3.7" -files = [ - {file = "platformdirs-4.0.0-py3-none-any.whl", hash = "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b"}, - {file = "platformdirs-4.0.0.tar.gz", hash = "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731"}, -] - -[package.extras] -docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] -test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] - -[[package]] -name = "pluggy" -version = "1.3.0" -description = "plugin and hook calling mechanisms for python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, - {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, -] - -[package.extras] -dev = ["pre-commit", "tox"] -testing = ["pytest", "pytest-benchmark"] - -[[package]] -name = "pre-commit" -version = "3.5.0" -description = "A framework for managing and maintaining multi-language pre-commit hooks." -optional = false -python-versions = ">=3.8" -files = [ - {file = "pre_commit-3.5.0-py2.py3-none-any.whl", hash = "sha256:841dc9aef25daba9a0238cd27984041fa0467b4199fc4852e27950664919f660"}, - {file = "pre_commit-3.5.0.tar.gz", hash = "sha256:5804465c675b659b0862f07907f96295d490822a450c4c40e747d0b1c6ebcb32"}, -] - -[package.dependencies] -cfgv = ">=2.0.0" -identify = ">=1.0.0" -nodeenv = ">=0.11.1" -pyyaml = ">=5.1" -virtualenv = ">=20.10.0" - -[[package]] -name = "pyproject-api" -version = "1.6.1" -description = "API to interact with the python pyproject.toml based projects" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pyproject_api-1.6.1-py3-none-any.whl", hash = "sha256:4c0116d60476b0786c88692cf4e325a9814965e2469c5998b830bba16b183675"}, - {file = "pyproject_api-1.6.1.tar.gz", hash = "sha256:1817dc018adc0d1ff9ca1ed8c60e1623d5aaca40814b953af14a9cf9a5cae538"}, -] - -[package.dependencies] -packaging = ">=23.1" -tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} - -[package.extras] -docs = ["furo (>=2023.8.19)", "sphinx (<7.2)", "sphinx-autodoc-typehints (>=1.24)"] -testing = ["covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "setuptools (>=68.1.2)", "wheel (>=0.41.2)"] - -[[package]] -name = "pytest" -version = "7.4.3" -description = "pytest: simple powerful testing with Python" -optional = false -python-versions = ">=3.7" -files = [ - {file = "pytest-7.4.3-py3-none-any.whl", hash = "sha256:0d009c083ea859a71b76adf7c1d502e4bc170b80a8ef002da5806527b9591fac"}, - {file = "pytest-7.4.3.tar.gz", hash = "sha256:d989d136982de4e3b29dabcc838ad581c64e8ed52c11fbe86ddebd9da0818cd5"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "sys_platform == \"win32\""} -exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} -iniconfig = "*" -packaging = "*" -pluggy = ">=0.12,<2.0" -tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} - -[package.extras] -testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] - -[[package]] -name = "pyyaml" -version = "6.0.1" -description = "YAML parser and emitter for Python" -optional = false -python-versions = ">=3.6" -files = [ - {file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"}, - {file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, - {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, - {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, - {file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, - {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, - {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, - {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, - {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd"}, - {file = "PyYAML-6.0.1-cp36-cp36m-win32.whl", hash = "sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585"}, - {file = "PyYAML-6.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa"}, - {file = "PyYAML-6.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3"}, - {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27"}, - {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3"}, - {file = "PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c"}, - {file = "PyYAML-6.0.1-cp37-cp37m-win32.whl", hash = "sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba"}, - {file = "PyYAML-6.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867"}, - {file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, - {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, - {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, - {file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, - {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, - {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, -] - -[[package]] -name = "ruff" -version = "0.1.6" -description = "An extremely fast Python linter and code formatter, written in Rust." -optional = false -python-versions = ">=3.7" -files = [ - {file = "ruff-0.1.6-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:88b8cdf6abf98130991cbc9f6438f35f6e8d41a02622cc5ee130a02a0ed28703"}, - {file = "ruff-0.1.6-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:5c549ed437680b6105a1299d2cd30e4964211606eeb48a0ff7a93ef70b902248"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1cf5f701062e294f2167e66d11b092bba7af6a057668ed618a9253e1e90cfd76"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:05991ee20d4ac4bb78385360c684e4b417edd971030ab12a4fbd075ff535050e"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:87455a0c1f739b3c069e2f4c43b66479a54dea0276dd5d4d67b091265f6fd1dc"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:683aa5bdda5a48cb8266fcde8eea2a6af4e5700a392c56ea5fb5f0d4bfdc0240"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:137852105586dcbf80c1717facb6781555c4e99f520c9c827bd414fac67ddfb6"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:bd98138a98d48a1c36c394fd6b84cd943ac92a08278aa8ac8c0fdefcf7138f35"}, - {file = "ruff-0.1.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a0cd909d25f227ac5c36d4e7e681577275fb74ba3b11d288aff7ec47e3ae745"}, - {file = "ruff-0.1.6-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e8fd1c62a47aa88a02707b5dd20c5ff20d035d634aa74826b42a1da77861b5ff"}, - {file = "ruff-0.1.6-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:fd89b45d374935829134a082617954120d7a1470a9f0ec0e7f3ead983edc48cc"}, - {file = "ruff-0.1.6-py3-none-musllinux_1_2_i686.whl", hash = "sha256:491262006e92f825b145cd1e52948073c56560243b55fb3b4ecb142f6f0e9543"}, - {file = "ruff-0.1.6-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:ea284789861b8b5ca9d5443591a92a397ac183d4351882ab52f6296b4fdd5462"}, - {file = "ruff-0.1.6-py3-none-win32.whl", hash = "sha256:1610e14750826dfc207ccbcdd7331b6bd285607d4181df9c1c6ae26646d6848a"}, - {file = "ruff-0.1.6-py3-none-win_amd64.whl", hash = "sha256:4558b3e178145491e9bc3b2ee3c4b42f19d19384eaa5c59d10acf6e8f8b57e33"}, - {file = "ruff-0.1.6-py3-none-win_arm64.whl", hash = "sha256:03910e81df0d8db0e30050725a5802441c2022ea3ae4fe0609b76081731accbc"}, - {file = "ruff-0.1.6.tar.gz", hash = "sha256:1b09f29b16c6ead5ea6b097ef2764b42372aebe363722f1605ecbcd2b9207184"}, -] - -[[package]] -name = "setuptools" -version = "69.0.2" -description = "Easily download, build, install, upgrade, and uninstall Python packages" -optional = false -python-versions = ">=3.8" -files = [ - {file = "setuptools-69.0.2-py3-none-any.whl", hash = "sha256:1e8fdff6797d3865f37397be788a4e3cba233608e9b509382a2777d25ebde7f2"}, - {file = "setuptools-69.0.2.tar.gz", hash = "sha256:735896e78a4742605974de002ac60562d286fa8051a7e2299445e8e8fbb01aa6"}, -] - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] -testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] - -[[package]] -name = "tomli" -version = "2.0.1" -description = "A lil' TOML parser" -optional = false -python-versions = ">=3.7" -files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, -] - -[[package]] -name = "tox" -version = "4.11.3" -description = "tox is a generic virtualenv management and test command line tool" -optional = false -python-versions = ">=3.8" -files = [ - {file = "tox-4.11.3-py3-none-any.whl", hash = "sha256:599af5e5bb0cad0148ac1558a0b66f8fff219ef88363483b8d92a81e4246f28f"}, - {file = "tox-4.11.3.tar.gz", hash = "sha256:5039f68276461fae6a9452a3b2c7295798f00a0e92edcd9a3b78ba1a73577951"}, -] - -[package.dependencies] -cachetools = ">=5.3.1" -chardet = ">=5.2" -colorama = ">=0.4.6" -filelock = ">=3.12.3" -packaging = ">=23.1" -platformdirs = ">=3.10" -pluggy = ">=1.3" -pyproject-api = ">=1.6.1" -tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} -virtualenv = ">=20.24.3" - -[package.extras] -docs = ["furo (>=2023.8.19)", "sphinx (>=7.2.4)", "sphinx-argparse-cli (>=1.11.1)", "sphinx-autodoc-typehints (>=1.24)", "sphinx-copybutton (>=0.5.2)", "sphinx-inline-tabs (>=2023.4.21)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] -testing = ["build[virtualenv] (>=0.10)", "covdefaults (>=2.3)", "detect-test-pollution (>=1.1.1)", "devpi-process (>=1)", "diff-cover (>=7.7)", "distlib (>=0.3.7)", "flaky (>=3.7)", "hatch-vcs (>=0.3)", "hatchling (>=1.18)", "psutil (>=5.9.5)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-xdist (>=3.3.1)", "re-assert (>=1.1)", "time-machine (>=2.12)", "wheel (>=0.41.2)"] - -[[package]] -name = "tox-gh-actions" -version = "3.1.3" -description = "Seamless integration of tox into GitHub Actions" -optional = false -python-versions = ">=3.7" -files = [ - {file = "tox-gh-actions-3.1.3.tar.gz", hash = "sha256:ffd4151fe8b62c6f401a2fc5a01317835d7ab380923f6e0d063c300750308328"}, - {file = "tox_gh_actions-3.1.3-py2.py3-none-any.whl", hash = "sha256:5954766fe2ed0e284f3cdc87535dfdf68d0f803f1011b17ff8cf52ed3156e6c1"}, -] - -[package.dependencies] -tox = ">=4,<5" - -[package.extras] -testing = ["black", "devpi-process", "flake8 (>=6,<7)", "mypy", "pytest (>=7,<8)", "pytest-cov (>=3,<4)", "pytest-mock (>=3,<4)", "pytest-randomly (>=3)"] - -[[package]] -name = "typing-extensions" -version = "4.8.0" -description = "Backported and Experimental Type Hints for Python 3.8+" -optional = false -python-versions = ">=3.8" -files = [ - {file = "typing_extensions-4.8.0-py3-none-any.whl", hash = "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0"}, - {file = "typing_extensions-4.8.0.tar.gz", hash = "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"}, -] - -[[package]] -name = "virtualenv" -version = "20.24.7" -description = "Virtual Python Environment builder" -optional = false -python-versions = ">=3.7" -files = [ - {file = "virtualenv-20.24.7-py3-none-any.whl", hash = "sha256:a18b3fd0314ca59a2e9f4b556819ed07183b3e9a3702ecfe213f593d44f7b3fd"}, - {file = "virtualenv-20.24.7.tar.gz", hash = "sha256:69050ffb42419c91f6c1284a7b24e0475d793447e35929b488bf6a0aade39353"}, -] - -[package.dependencies] -distlib = ">=0.3.7,<1" -filelock = ">=3.12.2,<4" -platformdirs = ">=3.9.1,<5" - -[package.extras] -docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] -test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] - -[metadata] -lock-version = "2.0" -python-versions = "^3.9" -content-hash = "dacc36577217ae7f564e3509566255c8defcf384c5c20228ffc5e9b9649e15b6" diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 1d41d33..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,65 +0,0 @@ -[tool.poetry] -name = "mofmt" -version = "0.3.5" -description = "Modelica Code Formatter" -authors = ["Eryk Mroczek "] -repository = "https://github.com/ErykMroczek/mofmt" -homepage = "https://github.com/ErykMroczek/mofmt" -license = "MIT" -readme = "README.md" -packages = [{include = "mofmt"}] -keywords = ["Modelica", "automation", "formatter"] -include = ["CHANGELOG.md"] - -[tool.poetry.urls] -"changelog" = "https://github.com/ErykMroczek/mofmt/blob/main/CHANGELOG.md" - -[tool.poetry.dependencies] -python = "^3.9" -antlr4-python3-runtime = "4.13.0" - -[tool.poetry.group.dev.dependencies] -pre-commit = "^3.3.2" -tox = "^4.6.3" -tox-gh-actions = "^3.1.1" - -[tool.poetry.group.test.dependencies] -pytest = "^7.2.1" - -[tool.poetry.group.lint.dependencies] -black = "^23.1.0" -mypy = "^1.0.1" -ruff = "^0.1.0" -isort = "^5.12.0" - -[tool.poetry.scripts] -mofmt = "mofmt.mofmt:main" - -[build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" - -[tool.mypy] -exclude = ['venv/', 'tests', 'mofmt/parsing/generated'] -warn_return_any = true -strict_equality = true -ignore_missing_imports = true - -[[tool.mypy.overrides]] -module = "mofmt.parsing.generated.*" -follow_imports = "skip" - -[[tool.mypy.overrides]] -module = "antlr4" -ignore_missing_imports = true - -[tool.isort] -profile = "black" -extend_skip = ["mofmt/parsing/generated"] - -[tool.black] -extend-exclude = 'mofmt/parsing/generated' - -[tool.ruff] -extend-exclude = ['mofmt/parsing/generated', 'tests/'] -extend-select = ["B"] diff --git a/scripts/__init__.py b/scripts/__init__.py deleted file mode 100644 index 357a830..0000000 --- a/scripts/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Helper scripts used for mofmt development""" diff --git a/scripts/generate_parser.py b/scripts/generate_parser.py deleted file mode 100644 index ce96436..0000000 --- a/scripts/generate_parser.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Script for parser generationa after grammar updates""" - -import subprocess - - -def update_parser() -> None: - """Generate new parser""" - subprocess.run( - [ - "antlr4", - "-v", - "4.13.0", - "-Dlanguage=Python3", - "-o", - "mofmt/parsing/generated", - "grammar/ModelicaLexer.g4", - "grammar/Modelica.g4", - ] - ) - print("Parser updated") - - -if __name__ == "__main__": - update_parser() diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/functional/test_mofmt.py b/tests/functional/test_mofmt.py deleted file mode 100644 index 663640b..0000000 --- a/tests/functional/test_mofmt.py +++ /dev/null @@ -1,102 +0,0 @@ -""" -Module with end-to-end test of mofmt. Those tests are not concerned too -much with formatting style. -""" - -from pathlib import Path - -import pytest - -from mofmt.io.io import NotModelicaFileError -from mofmt.mofmt import format_files - -INPUT_CODE = """within Lib; -package Sources -"Source and boundary nodes" -extends Modelica.Icons.SourcesPackage; -end Sources; -""" - -EXPECTED_CODE = """within Lib; -package Sources - "Source and boundary nodes" - - extends Modelica.Icons.SourcesPackage; - -end Sources; -""" - - -def test_files(tmp_path): - """Check if mofmt handles proper Modelica files""" - d: Path = tmp_path - n_files = 3 - files = [] - for i in range(n_files): - p = Path(d, f"file_{i}.mo") - p.write_text(INPUT_CODE, "utf-8") - files.append(p.as_posix()) - format_files(["mofmt"] + files) - i = 0 - for f in files: - i += 1 - code = Path(f).read_text("utf-8") - assert code == EXPECTED_CODE - assert i == n_files - - -def test_directories(tmp_path): - """Check if mofmt handles directories of Modelica files""" - d: Path = tmp_path - n_dirs = 3 - n_files = 2 - dirs = [] - files = [] - for i in range(n_dirs): - p = Path(d, f"directory_{i}.mo") - p.mkdir() - for j in range(n_files): - f = Path(p, f"file_{j}.mo") - f.write_text(INPUT_CODE, "utf-8") - files.append(f) - dirs.append(p.as_posix()) - format_files(["mofmt"] + dirs) - i = 0 - for f in files: - i += 1 - code = f.read_text("utf-8") - assert code == EXPECTED_CODE - assert i == n_files * n_dirs - - -def test_recursive_directories(tmp_path): - """Check if mofmt handles recursive Modelica directories""" - d: Path = tmp_path - n_files = 2 - files = [] - for i in range(n_files): - p = Path(d, f"file_{i}.mo") - p.write_text(INPUT_CODE, "utf-8") - files.append(p.as_posix()) - d_recursive = Path(d, "dir") - d_recursive.mkdir() - for i in range(n_files): - p = Path(d_recursive, f"file_{i}.mo") - p.write_text(INPUT_CODE, "utf-8") - files.append(p.as_posix()) - format_files(["mofmt", d.as_posix()]) - i = 0 - for f in files: - i += 1 - code = Path(f).read_text("utf-8") - assert code == EXPECTED_CODE - assert i == n_files * 2 - - -def test_errors(tmp_path): - """Check error handling""" - # Check file extension reckognition - p = Path(tmp_path, "file.txt") - p.write_text(INPUT_CODE, "utf-8") - with pytest.raises(NotModelicaFileError): - format_files(["mofmt", p.as_posix()]) diff --git a/tests/style/__init__.py b/tests/style/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/style/conftest.py b/tests/style/conftest.py deleted file mode 100644 index 9b5d599..0000000 --- a/tests/style/conftest.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Pytest fixtures""" - -from pathlib import Path - -import pytest - -from mofmt.io import read_file -from mofmt.parsing import parse_source -from mofmt.printing import Printer - - -@pytest.fixture(name="format_file", scope="function") -def format_file(): - """Fixture used for parsing and formatting code samples""" - - def _format(file, entry): - code = read_file(Path(file)) - parsed = parse_source(Path(file), code, entry) - return Printer(parsed).pretty_print() - - return _format diff --git a/tests/style/test_style.py b/tests/style/test_style.py deleted file mode 100644 index c0ebeee..0000000 --- a/tests/style/test_style.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Tests checking formatting style""" - -from pathlib import Path - -from mofmt.io import read_file -from mofmt.parsing.generated.Modelica import Modelica - -from .conftest import format_file - - -def test_equations(format_file): - """Check formatting in equations""" - input_file = "tests/style/samples/equations/equations-input.mo" - template_file = "tests/style/samples/equations/equations-output.mo" - entry = Modelica.equation_list - actual = format_file(input_file, entry) - expected = read_file(Path(template_file)) - assert actual == expected - - -def test_statements(format_file): - """Check formatting in statements""" - input_file = "tests/style/samples/statements/statements-input.mo" - template_file = "tests/style/samples/statements/statements-output.mo" - entry = Modelica.statement_list - actual = format_file(input_file, entry) - expected = read_file(Path(template_file)) - assert actual == expected - - -def test_elements(format_file): - """Check formatting in elements""" - input_file = "tests/style/samples/elements/elements-input.mo" - template_file = "tests/style/samples/elements/elements-output.mo" - entry = Modelica.element_list - actual = format_file(input_file, entry) - expected = read_file(Path(template_file)) - assert actual == expected - - -def test_classes(format_file): - """Check formatting in classes""" - input_file = "tests/style/samples/classes/classes-input.mo" - template_file = "tests/style/samples/classes/classes-output.mo" - entry = Modelica.stored_definition - actual = format_file(input_file, entry) - expected = read_file(Path(template_file)) - assert actual == expected diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py deleted file mode 100644 index b3a6be9..0000000 --- a/tests/unit/test_collector.py +++ /dev/null @@ -1,85 +0,0 @@ -"""Unit tests for Collector class functionalities""" - -from mofmt.collecting.collector import Collector, Marker - - -def test_tokens(): - """Check tokens collecting""" - col = Collector() - val_1, val_2 = "TOK1", "TOK2" - col.add_token(val_1) - col.add_token(val_2) - # Test if number of markers is correct - assert len(col.markers) == 2 - # Test if markers has a correct type - for m in col.markers: - assert m.typ == Marker.TOKEN - # Test markers values and representations - assert col.markers[0].val == val_1 - assert col.markers[-1].val == val_2 - assert col.markers[0].val == col.markers[0].rep - - -def test_comments(): - """Check comments collecting""" - col = Collector() - val_1, val_2 = "COM1", "COM2" - col.add_comment(val_1) - col.add_comment(val_2) - # Test if number of markers is correct - assert len(col.markers) == 2 - # Test if markers has a correct type - for m in col.markers: - assert m.typ == Marker.COMMENT - # Test markers values and representations - assert col.markers[0].val == val_1 - assert col.markers[-1].val == val_2 - assert col.markers[0].val == col.markers[0].rep - - -def test_tail_caching(): - """Check collector tail caching that is used in comments handling""" - col = Collector() - col.add_token("tok") - col.add_space() - col.add_indent() - col.add_break() - col.add_space() - tail = col.cache_tail() - # There should be just indent and break - assert len(tail) == 2 - assert tail[0].typ == Marker.INDENT - assert tail[1].typ == Marker.BREAK - # Only single token should be left in collector - assert len(col.markers) == 1 - assert col.markers[0].typ == Marker.TOKEN - - -def test_space(): - """Check space collecting""" - col = Collector() - # Initial spaces should be discarded - col.add_space() - col.add_space() - assert len(col.markers) == 0 - # But should be accepted when following a token or comment - col.add_token("tok") - col.add_space() - assert col.markers[-1].typ == Marker.SPACE - # But they should be discarded while following ignore marker or - # newline - col.add_ignore() - col.add_space() - assert col.markers[-1].typ == Marker.IGNORE - col.add_break() - col.add_space() - assert col.markers[-1].typ == Marker.BREAK - - -def test_blank(): - """Check blanks collecting""" - col = Collector() - col.add_token("tok") - col.add_break() - col.add_blank() - assert len(col.markers) == 2 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index b3fb15c..0000000 --- a/tox.ini +++ /dev/null @@ -1,38 +0,0 @@ -[tox] -requires = tox >= 4 -skipsdist = true -env_list = - py{39,310,311} - format - typecheck - lint -isolated_build = true - -[gh-actions] -python = - 3.9: py39 - 3.10: py310 - 3.11: py311,format,typecheck,lint - -[testenv] -description = run tests -skip_install = true -allowlist_externals = poetry -commands_pre = poetry install --without lint,dev -commands = - py39,py310,py311: poetry run pytest tests/ - format: poetry run black . - typecheck: poetry run mypy . - lint: poetry run ruff . - -[testenv:{format,typecheck,lint}] -commands_pre = poetry install --only lint - -[testenv:format] -description = run formatter - -[testenv:typecheck] -description = run type checker - -[testenv:lint] -description = run linter From 80e3fe84c7b59650a57f9e08c8f72070ee5a2414 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 4 Jan 2024 19:17:51 +0100 Subject: [PATCH 14/67] First style test Fix few minor issues. Remove the cause of overflow in debug mode --- src/formatting.rs | 43 +++++-- tests/style/samples/models-input.mo | 129 +++++++++++++++++++++ tests/style/samples/models-output.mo | 160 +++++++++++++++++++++++++++ tests/style_tests.rs | 19 ++++ 4 files changed, 340 insertions(+), 11 deletions(-) create mode 100644 tests/style/samples/models-input.mo create mode 100644 tests/style/samples/models-output.mo create mode 100644 tests/style_tests.rs diff --git a/src/formatting.rs b/src/formatting.rs index 20ef802..a5984c0 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -86,8 +86,7 @@ impl<'a> Formatter<'a> { self.markers.push(Marker::Break); } else if tail.len() > 0 { self.markers.append(&mut tail); - } - else if diff == 1 { + } else if diff == 1 { self.markers.push(Marker::Break); } else if diff > 1 { self.markers.push(Marker::Blank); @@ -119,7 +118,14 @@ impl<'a> Formatter<'a> { if first.start.line < last.end.line { // Handle conditional expression if first.typ == TokenKind::If { - if [TokenKind::Equal, TokenKind::Assign].contains(&self.prev_token) { + if [ + TokenKind::Equal, + TokenKind::Assign, + TokenKind::Then, + TokenKind::Else, + ] + .contains(&self.prev_token) + { self.markers.push(Marker::Indent); } // Handle matrix row @@ -141,8 +147,13 @@ impl<'a> Formatter<'a> { if group_broken { // Handle conditional expression if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If { - if [TokenKind::Equal, TokenKind::Assign] - .contains(&self.tokens.get_token(enter.tok - 1).unwrap().typ) + if [ + TokenKind::Equal, + TokenKind::Assign, + TokenKind::Then, + TokenKind::Else, + ] + .contains(&self.tokens.get_token(enter.tok - 1).unwrap().typ) { self.markers.push(Marker::Dedent); } @@ -294,7 +305,7 @@ impl<'a> Formatter<'a> { match kind { TokenKind::Annotation => self.markers.push(Marker::Space), TokenKind::Equation | TokenKind::Algorithm => { - self.markers.push(Marker::Blank); + self.markers.push(Marker::Break); } TokenKind::Plus | TokenKind::DotPlus | TokenKind::Minus | TokenKind::DotMinus => { // Do not add next space if unary operator @@ -351,8 +362,14 @@ impl<'a> Formatter<'a> { } SyntaxKind::Equation | SyntaxKind::Statement => { self.markers.push(Marker::Indent); - if [TokenKind::Loop, TokenKind::Then, TokenKind::Else] - .contains(&self.prev_token) + if [ + TokenKind::Loop, + TokenKind::Then, + TokenKind::Else, + TokenKind::Equation, + TokenKind::Algorithm, + ] + .contains(&self.prev_token) { self.markers.push(Marker::Break); } @@ -461,6 +478,8 @@ impl<'a> Formatter<'a> { } } } + // Add one trailing newline + self.markers.push(Marker::Break); } } @@ -474,12 +493,16 @@ fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> let mut comments = Vec::new(); loop { let prev_item = tokens.get_item(rest).unwrap(); - rest -= 1; if [TokenKind::LineComment, TokenKind::BlockComment].contains(&prev_item.typ) { comments.push(prev_item); } else { break; } + if rest > 0 { + rest -= 1; + } else { + break; + } } if comments.len() == 0 { None @@ -488,5 +511,3 @@ fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> Some(comments) } } - -mod test {} diff --git a/tests/style/samples/models-input.mo b/tests/style/samples/models-input.mo new file mode 100644 index 0000000..fed3952 --- /dev/null +++ b/tests/style/samples/models-input.mo @@ -0,0 +1,129 @@ +within Bark.Baark; +model Foo "Foo description" + +import Modelica.Constants; +import Modelica.SI; + + extends Bar(a=0, b= 1, + c = if x then - 1 else 1 , + break uselessVar, anotherUselessVar = break, // USELESS! + final d = true); + + // Bunch of elements +replaceable package Medium = .Modelica.Media.Interfaces.PartialMedium + "Medium model" annotation (choicesAllMatching=true); + + + final /* Unexpected comment! */ parameter Real foo(start = 0, min = -1000) = if d then Constants.inf + else if y then 5*2+ + (2^4) + +111 else 66 + "Parameter with some fairly complex modification expression" + annotation (Dialog(tab = "General", group="Bunch")); + + SI.Length[3] 'length of "whatever"'(start = 0, + min = -1, max = 1, nominal=0) = { 1* 0.25 for i in 1 : 3}; +protected +/* It is too valuable to be public */ + Integer n_protected; +public +.Modelica.Blocks.Interfaces.BooleanInput b +annotation (Placement( + transformation( + extent={{-20,-10},{20,10}},rotation=90, + origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, + rotation=90, + origin={-68,0}))); + + +initial equation +if foo == Types.Dynamics.FixedInitial then + bar = bar_start; + elseif foo == Types.Dynamics.SteadyStateInitial then +der(bar) = 0; + end if; + + equation +a = -b*c; + x *( - y) = 2^z/ (m-n); + +A = toString([2.12,-4.34;-2.56, -1.67]); + +/* Wrapped equations */ + +Q_flow = alpha * surfaceArea* +(T_a - T_b); +volume =height*pi + * diameter^2/4; + + +/* If-else blocks */ + +if wetConditions then + + // Latent heat flow is present + Q_flow_latent = Q_flow - Q_flow_sensible; + +else + Q_flow_latent=0; // Latent heat flow is absent +end if; + +if a String { + let input = fs::read_to_string(path).expect("error"); + let tokens = moparse::lex(&input); + let events = moparse::parse(&tokens, moparse::SyntaxKind::StoredDefinition); + let markers = mofmt::format(&tokens, &events); + mofmt::pretty_print(&tokens, &markers) +} + +#[test] +fn models_formatting() { + let formatted = format_file("tests/style/samples/models-input.mo"); + let expected = fs::read_to_string("tests/style/samples/models-output.mo").expect("error"); + assert_eq!(expected, formatted); +} From 54ed4353924fa34db428ca470804a02114a80fb0 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 9 Jan 2024 15:39:27 +0100 Subject: [PATCH 15/67] Reproduce the fix in comment handling --- src/formatting.rs | 6 +++--- tests/style/samples/models-input.mo | 6 ++++++ tests/style/samples/models-output.mo | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index a5984c0..ae9590f 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -74,7 +74,7 @@ impl<'a> Formatter<'a> { } else if diff == 1 { self.markers.push(Marker::Break); } else { - if self.prev_token == TokenKind::Semi { + if self.prev_token == TokenKind::Semi || line > self.prev_line { self.markers.push(Marker::Blank); } } @@ -478,8 +478,8 @@ impl<'a> Formatter<'a> { } } } - // Add one trailing newline - self.markers.push(Marker::Break); + // Add one trailing newline + self.markers.push(Marker::Break); } } diff --git a/tests/style/samples/models-input.mo b/tests/style/samples/models-input.mo index fed3952..0202d17 100644 --- a/tests/style/samples/models-input.mo +++ b/tests/style/samples/models-input.mo @@ -27,6 +27,12 @@ protected /* It is too valuable to be public */ Integer n_protected; public + // Here we have to comments + + /* + And they are separated + with a single blank line + */ .Modelica.Blocks.Interfaces.BooleanInput b annotation (Placement( transformation( diff --git a/tests/style/samples/models-output.mo b/tests/style/samples/models-output.mo index abf5a52..537350c 100644 --- a/tests/style/samples/models-output.mo +++ b/tests/style/samples/models-output.mo @@ -44,6 +44,13 @@ protected public + // Here we have to comments + + /* + And they are separated + with a single blank line + */ + .Modelica.Blocks.Interfaces.BooleanInput b annotation ( Placement( From 76fe3642c018752ebb036b98c42897a679d12675 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Wed, 10 Jan 2024 08:21:58 +0100 Subject: [PATCH 16/67] Further style tests Fix some formatting issues in output expressions. --- src/formatting.rs | 31 ++++++++--- tests/style/samples/functions-input.mo | 54 ++++++++++++++++++ tests/style/samples/functions-output.mo | 74 +++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 tests/style/samples/functions-input.mo create mode 100644 tests/style/samples/functions-output.mo diff --git a/src/formatting.rs b/src/formatting.rs index ae9590f..4f2dfad 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -270,7 +270,6 @@ impl<'a> Formatter<'a> { } TokenKind::Protected | TokenKind::Public => self.markers.push(Marker::Blank), TokenKind::External => { - self.markers.push(Marker::Indent); self.markers.push(Marker::Blank); } TokenKind::Plus @@ -293,6 +292,20 @@ impl<'a> Formatter<'a> { | TokenKind::Neq => { self.wrap_expression(i); } + TokenKind::LParen => { + if ![ + TokenKind::Ident, + TokenKind::Pure, + TokenKind::Der, + TokenKind::Initial, + TokenKind::RBracket, + ] + .contains(&self.prev_token) + && !NO_SPACE_AFTER.contains(&self.prev_token) + { + self.markers.push(Marker::Space); + } + } _ => { if !NO_SPACE_BEFORE.contains(&kind) && !NO_SPACE_AFTER.contains(&self.prev_token) { self.markers.push(Marker::Space); @@ -354,7 +367,10 @@ impl<'a> Formatter<'a> { SyntaxKind::AnnotationClause => { self.markers.push(Marker::Indent); // Handle class annotations - if *parent == SyntaxKind::Composition { + if *parent == SyntaxKind::Composition + && ![TokenKind::External, TokenKind::String, TokenKind::RParen] + .contains(&self.prev_token) + { self.markers.push(Marker::Blank); } else { self.markers.push(Marker::Break); @@ -390,9 +406,9 @@ impl<'a> Formatter<'a> { SyntaxKind::FunctionCallArgs | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification - | SyntaxKind::ArraySubscripts => { + | SyntaxKind::ArraySubscripts + | SyntaxKind::OutputExpressionList => { self.enter_group(p.typ, first, last); - self.markers.push(Marker::Ignore); } SyntaxKind::ExpressionList => { self.break_or_space(); @@ -409,7 +425,7 @@ impl<'a> Formatter<'a> { self.break_or_space(); } SyntaxKind::Expression => { - if *parent == SyntaxKind::ExpressionList { + if [SyntaxKind::ExpressionList, SyntaxKind::OutputExpressionList].contains(parent) { self.break_or_space(); // Handle conditional expression } else if first.typ == TokenKind::If { @@ -456,7 +472,8 @@ impl<'a> Formatter<'a> { | SyntaxKind::ClassOrInheritanceModification | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts - | SyntaxKind::ExpressionList => self.exit_group(p_start, p_end), + | SyntaxKind::ExpressionList + | SyntaxKind::OutputExpressionList => self.exit_group(p_start, p_end), SyntaxKind::Expression => { // Handle conditional expression if first.typ == TokenKind::If { @@ -478,8 +495,6 @@ impl<'a> Formatter<'a> { } } } - // Add one trailing newline - self.markers.push(Marker::Break); } } diff --git a/tests/style/samples/functions-input.mo b/tests/style/samples/functions-input.mo new file mode 100644 index 0000000..b430176 --- /dev/null +++ b/tests/style/samples/functions-input.mo @@ -0,0 +1,54 @@ +within; +final encapsulated function Foo "Return something" + + extends .Modelica.Icons.Function; + + input Integer a "Aaa"; + output Real result "Length"; + +protected + + Real b "Bbb"; + +algorithm + (A, B, C) := foo.bar.baz(a); + (D, , E) := foo.bar .baz(b); + (F, G, (H, + J)) := foo.bar.baz(c); + +foo:={ + {bar[i] + j*(baz[i] - ber[i])/n for i in 1:n} for j in 1:m}; +bar:={{foo[i] + j*(baz[i] - foo[i])/n +for i in 1:n} + for j in 1:m}; + +external"C" foo[1].bar [2] = baz(x,y,z) +annotation (Library="doesn't matter"); +annotation (smoothOrder = 2); +end Foo; + +partial function Bar "Just in case" + initial algorithm + + x := y; + + /* If statement */ +foo := if a == 1 then bar +else baz +"What is this about?"; + +/* Multiline statements */ +y := u1 > 0 +and u2 > 0 and +u3 > 0 + and u4 > 0; + +y := u1 > 0 +or u2 > 0 or +u3 > 0 + or u4 > 0; + +Modelica.Utilities.Streams.print( + "foo" + "bar" + + "baz"); +end Bar; diff --git a/tests/style/samples/functions-output.mo b/tests/style/samples/functions-output.mo new file mode 100644 index 0000000..6274ec8 --- /dev/null +++ b/tests/style/samples/functions-output.mo @@ -0,0 +1,74 @@ +within; +final encapsulated function Foo + "Return something" + + extends .Modelica.Icons.Function; + + input Integer a + "Aaa"; + output Real result + "Length"; + +protected + + Real b + "Bbb"; + +algorithm + + (A, B, C) := foo.bar.baz(a); + (D,, E) := foo.bar.baz(b); + ( + F, + G, + ( + H, + J)) := foo.bar.baz(c); + + foo := { + {bar[i] + j * (baz[i] - ber[i]) / n for i in 1:n} + for j in 1:m}; + bar := { + { + foo[i] + j * (baz[i] - foo[i]) / n + for i in 1:n} + for j in 1:m}; + +external "C" foo[1].bar[2] = baz(x, y, z) + annotation (Library = "doesn't matter"); + + annotation (smoothOrder = 2); + +end Foo; + +partial function Bar + "Just in case" + +initial algorithm + + x := y; + + /* If statement */ + foo := + if a == 1 then + bar + else + baz + "What is this about?"; + + /* Multiline statements */ + y := u1 > 0 + and u2 > 0 + and u3 > 0 + and u4 > 0; + + y := u1 > 0 + or u2 > 0 + or u3 > 0 + or u4 > 0; + + Modelica.Utilities.Streams.print( + "foo" + "bar" + + "baz"); + +end Bar; From 16c3d8b82de1c0ff87a314ae2a386b3462368a2a Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Wed, 10 Jan 2024 09:59:44 +0100 Subject: [PATCH 17/67] Restructure test folder --- src/formatting.rs | 8 +- tests/{style => }/samples/functions-input.mo | 0 tests/{style => }/samples/functions-output.mo | 0 tests/{style => }/samples/models-input.mo | 0 tests/{style => }/samples/models-output.mo | 0 tests/style/samples/classes/classes-input.mo | 86 ------------- tests/style/samples/classes/classes-output.mo | 114 ------------------ .../style/samples/elements/elements-input.mo | 29 ----- .../style/samples/elements/elements-output.mo | 48 -------- .../samples/equations/equations-input.mo | 84 ------------- .../samples/equations/equations-output.mo | 91 -------------- .../samples/statements/statements-input.mo | 16 --- .../samples/statements/statements-output.mo | 18 --- tests/style_tests.rs | 10 +- 14 files changed, 14 insertions(+), 490 deletions(-) rename tests/{style => }/samples/functions-input.mo (100%) rename tests/{style => }/samples/functions-output.mo (100%) rename tests/{style => }/samples/models-input.mo (100%) rename tests/{style => }/samples/models-output.mo (100%) delete mode 100644 tests/style/samples/classes/classes-input.mo delete mode 100644 tests/style/samples/classes/classes-output.mo delete mode 100644 tests/style/samples/elements/elements-input.mo delete mode 100644 tests/style/samples/elements/elements-output.mo delete mode 100644 tests/style/samples/equations/equations-input.mo delete mode 100644 tests/style/samples/equations/equations-output.mo delete mode 100644 tests/style/samples/statements/statements-input.mo delete mode 100644 tests/style/samples/statements/statements-output.mo diff --git a/src/formatting.rs b/src/formatting.rs index 4f2dfad..cc94ab2 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -316,7 +316,7 @@ impl<'a> Formatter<'a> { self.markers.push(Marker::Token(tok.idx)); match kind { - TokenKind::Annotation => self.markers.push(Marker::Space), + //TokenKind::Annotation => self.markers.push(Marker::Space), TokenKind::Equation | TokenKind::Algorithm => { self.markers.push(Marker::Break); } @@ -425,7 +425,9 @@ impl<'a> Formatter<'a> { self.break_or_space(); } SyntaxKind::Expression => { - if [SyntaxKind::ExpressionList, SyntaxKind::OutputExpressionList].contains(parent) { + if [SyntaxKind::ExpressionList, SyntaxKind::OutputExpressionList] + .contains(parent) + { self.break_or_space(); // Handle conditional expression } else if first.typ == TokenKind::If { @@ -495,6 +497,8 @@ impl<'a> Formatter<'a> { } } } + // Add one trailing newline + self.markers.push(Marker::Break); } } diff --git a/tests/style/samples/functions-input.mo b/tests/samples/functions-input.mo similarity index 100% rename from tests/style/samples/functions-input.mo rename to tests/samples/functions-input.mo diff --git a/tests/style/samples/functions-output.mo b/tests/samples/functions-output.mo similarity index 100% rename from tests/style/samples/functions-output.mo rename to tests/samples/functions-output.mo diff --git a/tests/style/samples/models-input.mo b/tests/samples/models-input.mo similarity index 100% rename from tests/style/samples/models-input.mo rename to tests/samples/models-input.mo diff --git a/tests/style/samples/models-output.mo b/tests/samples/models-output.mo similarity index 100% rename from tests/style/samples/models-output.mo rename to tests/samples/models-output.mo diff --git a/tests/style/samples/classes/classes-input.mo b/tests/style/samples/classes/classes-input.mo deleted file mode 100644 index bc92c58..0000000 --- a/tests/style/samples/classes/classes-input.mo +++ /dev/null @@ -1,86 +0,0 @@ -within ; -function length "Return length of a vector" - - extends .Modelica.Icons.Function; - - input Complex v[:] "Vector"; - output Real result "Length"; - -algorithm - result := sqrt(sum({v[i].re^2 + v[i].im^2 for i in 1:size(v,1)})); - -end length; - -function h_pT "Enthalpy by pressure and temperature" -input Real P; - input Real T; - - -output Real H; -protected - RefdllHandle h=dllHandle; -external"C" H = h_pT(h, -P,T) -annotation (Library="doesn't matter"); -end h_pT; - - -model Tank "Tank model" - - import Modelica.Constants.pi; - - // Geometry - SIunits.Height level(stateSelect=StateSelect.prefer, - start=level_start) - "liquid level"; - SIunits.Volume V "Tank volume"; - parameter SIunits.Height height "Height of tank"; - parameter SIunits.Area crossArea "Area of tank"; - - extends Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel( - break someUselessVar, - anotherUselessVar = break, // Who need that? - final fluidVolume = V, - final fluidLevel = level, - final fluidLevel_max = height, - final vesselArea = crossArea, - heatTransfer(surfaceAreas={crossArea+2*sqrt(crossArea*pi)*level})); - - // Initialization - parameter SI.Height level_start(min=0) = 0.5*height - "Start value of tank level" - annotation(Dialog(tab="Initialization")); - protected - final parameter SIunits.Height level_start = max(level_start, Modelica.Constants.eps); - -equation - // Total quantities - V = crossArea*level "Volume of fluid"; - medium.p = p_ambient; - - // Source terms - if Medium.singleState or energyDynamics == Types.Dynamics.SteadyState then - Wb_flow = 0; - else - Wb_flow = -p_ambient*der(V); - end if; - -initial equation - if massDynamics == Types.Dynamics.FixedInitial then - level = level_start; - elseif massDynamics == Types.Dynamics.SteadyStateInitial then - der(level) = 0; - end if; - annotation (Documentation(info=" -

Some documentation

-")); -end Tank; - -partial record 'Quoted "record"' -import It.is.empty; -end 'Quoted "record"'; - -block Foo -import Modelica.Units.SI; - .Modelica.Blocks.Interfaces.BooleanInput b; -end Foo; diff --git a/tests/style/samples/classes/classes-output.mo b/tests/style/samples/classes/classes-output.mo deleted file mode 100644 index 467ff7f..0000000 --- a/tests/style/samples/classes/classes-output.mo +++ /dev/null @@ -1,114 +0,0 @@ -within; -function length - "Return length of a vector" - - extends .Modelica.Icons.Function; - - input Complex v[:] - "Vector"; - output Real result - "Length"; - -algorithm - - result := sqrt(sum({v[i].re ^ 2 + v[i].im ^ 2 for i in 1:size(v, 1)})); - -end length; - -function h_pT - "Enthalpy by pressure and temperature" - - input Real P; - input Real T; - - output Real H; - -protected - - RefdllHandle h = dllHandle; - - external "C" H = h_pT( - h, - P, - T) - annotation (Library = "doesn't matter"); - -end h_pT; - -model Tank - "Tank model" - - import Modelica.Constants.pi; - - // Geometry - SIunits.Height level( - stateSelect = StateSelect.prefer, - start = level_start) - "liquid level"; - SIunits.Volume V - "Tank volume"; - parameter SIunits.Height height - "Height of tank"; - parameter SIunits.Area crossArea - "Area of tank"; - - extends Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel( - break someUselessVar, - anotherUselessVar = break, // Who need that? - final fluidVolume = V, - final fluidLevel = level, - final fluidLevel_max = height, - final vesselArea = crossArea, - heatTransfer(surfaceAreas = {crossArea + 2 * sqrt(crossArea * pi) * level})); - - // Initialization - parameter SI.Height level_start(min = 0) = 0.5 * height - "Start value of tank level" - annotation (Dialog(tab = "Initialization")); - -protected - - final parameter SIunits.Height level_start = max(level_start, Modelica.Constants.eps); - -equation - - // Total quantities - V = crossArea * level - "Volume of fluid"; - medium.p = p_ambient; - - // Source terms - if Medium.singleState or energyDynamics == Types.Dynamics.SteadyState then - Wb_flow = 0; - else - Wb_flow = -p_ambient * der(V); - end if; - -initial equation - - if massDynamics == Types.Dynamics.FixedInitial then - level = level_start; - elseif massDynamics == Types.Dynamics.SteadyStateInitial then - der(level) = 0; - end if; - - annotation ( - Documentation( - info = " -

Some documentation

-")); - -end Tank; - -partial record 'Quoted "record"' - - import It.is.empty; - -end 'Quoted "record"'; - -block Foo - - import Modelica.Units.SI; - .Modelica.Blocks.Interfaces.BooleanInput b; - -end Foo; diff --git a/tests/style/samples/elements/elements-input.mo b/tests/style/samples/elements/elements-input.mo deleted file mode 100644 index 6021f6b..0000000 --- a/tests/style/samples/elements/elements-input.mo +++ /dev/null @@ -1,29 +0,0 @@ -replaceable package Medium = .Modelica.Media.Interfaces.PartialMedium - "Medium model" annotation (choicesAllMatching=true); - - -parameter /* Unexpected comment! */Integer n=1 "Discretization number" annotation(tab="General"); -Modelica.Fluid.Interfaces.HeatPorts_a[n] heatPorts_a /* Where is b? */annotation (Placement( - transformation( - extent={{-20,-10},{20,10}},rotation=90, - origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, - rotation=90, - origin={-68,0}))); - -extends BaseClasses.PartialTwoPortFlow(final lengths=fill(length/n, n), - final crossAreas=fill(crossArea, n),final dimensions=fill(4*crossArea/perimeter, n), - final roughnesses=fill(roughness, n), - final dheights=height_ab*dxs); - -final Real dimensions={4*crossArea/perimeter, -4*crossArea/perimeter}; - -final parameter Integer nFM=if useLumpedPressure then nFMLumped else nFMDistributed; -final parameter Integer nFMLumped=if modelStructure==Types.ModelStructure.a_v_b then 2+a -else 1 "Number of lumped flow models"; - -final parameter SIunits.Height[n,m] height={ - {pass_bottom[i] + j*(pass[i] - pass_bottom[i])/n for i in 1:n} for j in 1:m}; -final parameter SIunits.Height[n,m] height={{pass_bottom[i] + j*(pass[i] - pass_bottom[i])/n -for i in 1:n} - for j in 1:m}; diff --git a/tests/style/samples/elements/elements-output.mo b/tests/style/samples/elements/elements-output.mo deleted file mode 100644 index 18b4f8e..0000000 --- a/tests/style/samples/elements/elements-output.mo +++ /dev/null @@ -1,48 +0,0 @@ - - - replaceable package Medium = .Modelica.Media.Interfaces.PartialMedium - "Medium model" - annotation (choicesAllMatching = true); - - parameter /* Unexpected comment! */ Integer n = 1 - "Discretization number" - annotation (tab = "General"); - Modelica.Fluid.Interfaces.HeatPorts_a[n] heatPorts_a /* Where is b? */ - annotation ( - Placement( - transformation( - extent = {{-20, -10}, {20, 10}}, - rotation = 90, - origin = {-98, 4}), - iconTransformation( - extent = {{-40, -10}, {40, 10}}, - rotation = 90, - origin = {-68, 0}))); - - extends BaseClasses.PartialTwoPortFlow( - final lengths = fill(length / n, n), - final crossAreas = fill(crossArea, n), - final dimensions = fill(4 * crossArea / perimeter, n), - final roughnesses = fill(roughness, n), - final dheights = height_ab * dxs); - - final Real dimensions = { - 4 * crossArea / perimeter, - 4 * crossArea / perimeter}; - - final parameter Integer nFM = if useLumpedPressure then nFMLumped else nFMDistributed; - final parameter Integer nFMLumped = - if modelStructure == Types.ModelStructure.a_v_b then - 2 + a - else - 1 - "Number of lumped flow models"; - - final parameter SIunits.Height[n, m] height = { - {pass_bottom[i] + j * (pass[i] - pass_bottom[i]) / n for i in 1:n} - for j in 1:m}; - final parameter SIunits.Height[n, m] height = { - { - pass_bottom[i] + j * (pass[i] - pass_bottom[i]) / n - for i in 1:n} - for j in 1:m}; diff --git a/tests/style/samples/equations/equations-input.mo b/tests/style/samples/equations/equations-input.mo deleted file mode 100644 index 979e323..0000000 --- a/tests/style/samples/equations/equations-input.mo +++ /dev/null @@ -1,84 +0,0 @@ -/* Simple equations */ - -a = -b*c; - x *( - y) = 2^z/ (m-n); - -A = toString([2.12,-4.34;-2.56, -1.67]); - -/* Wrapped equations */ - -Q_flow = alpha * surfaceArea* -(T_a - T_b); -volume =height*pi - * diameter^2/4; - - -/* If-else blocks */ - -if wetConditions then - - // Latent heat flow is present - Q_flow_latent = Q_flow - Q_flow_sensible; - -else - Q_flow_latent=0; // Latent heat flow is absent -end if; - -if a 0 -and u2 > 0 and -u3 > 0 - and u4 > 0; - -Modelica.Utilities.Streams.print( - "foo" + "bar" - + "baz"); diff --git a/tests/style/samples/statements/statements-output.mo b/tests/style/samples/statements/statements-output.mo deleted file mode 100644 index e245286..0000000 --- a/tests/style/samples/statements/statements-output.mo +++ /dev/null @@ -1,18 +0,0 @@ -/* If statement */ -foo := - if a == 1 then - bar - else - baz - "What is this about?"; - -/* Multiline statements */ - -y := u1 > 0 - and u2 > 0 - and u3 > 0 - and u4 > 0; - -Modelica.Utilities.Streams.print( - "foo" + "bar" - + "baz"); diff --git a/tests/style_tests.rs b/tests/style_tests.rs index 6e212cf..a64374b 100644 --- a/tests/style_tests.rs +++ b/tests/style_tests.rs @@ -13,7 +13,13 @@ fn format_file(path: &str) -> String { #[test] fn models_formatting() { - let formatted = format_file("tests/style/samples/models-input.mo"); - let expected = fs::read_to_string("tests/style/samples/models-output.mo").expect("error"); + let formatted = format_file("tests/samples/models-input.mo"); + let expected = fs::read_to_string("tests/samples/models-output.mo").expect("error"); + assert_eq!(expected, formatted); +} +#[test] +fn functions_formatting() { + let formatted = format_file("tests/samples/functions-input.mo"); + let expected = fs::read_to_string("tests/samples/functions-output.mo").expect("error"); assert_eq!(expected, formatted); } From eedc1d47b01fa694ad7918974a078ae40be02c55 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Wed, 10 Jan 2024 10:38:01 +0100 Subject: [PATCH 18/67] Fix issue with additional spaces --- src/markers.rs | 5 +++++ tests/samples/models-input.mo | 3 +++ tests/samples/models-output.mo | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/markers.rs b/src/markers.rs index 1a41f4d..83ba5d7 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -28,6 +28,11 @@ impl MarkerCollector { if self.markers.len() == 0 || *self.markers.last().unwrap() >= Marker::Space { return; } + if [Marker::Indent, Marker::Dedent].contains(self.markers.last().unwrap()) + && *self.markers.get(self.markers.len() - 2).unwrap() >= Marker::Blank + { + return; + } } Marker::Blank => { // Remove preceding break diff --git a/tests/samples/models-input.mo b/tests/samples/models-input.mo index 0202d17..716714e 100644 --- a/tests/samples/models-input.mo +++ b/tests/samples/models-input.mo @@ -55,6 +55,9 @@ a = -b*c; A = toString([2.12,-4.34;-2.56, -1.67]); +foo = bar(x, y, baz(a, +b)); + /* Wrapped equations */ Q_flow = alpha * surfaceArea* diff --git a/tests/samples/models-output.mo b/tests/samples/models-output.mo index 537350c..e681a38 100644 --- a/tests/samples/models-output.mo +++ b/tests/samples/models-output.mo @@ -78,6 +78,13 @@ equation A = toString([2.12, -4.34; -2.56, -1.67]); + foo = bar( + x, + y, + baz( + a, + b)); + /* Wrapped equations */ Q_flow = alpha * surfaceArea @@ -158,7 +165,7 @@ equation points = { {-98, -60}, - { + { -64, -60}, {-64, -63.4667}, From b6888b012f57d3f1b113524e0e597b584af459c1 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 11 Jan 2024 07:13:49 +0100 Subject: [PATCH 19/67] Create helper functions for main() --- src/main.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 006fa7f..23fe421 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,59 @@ -use moparse::{parse, lex, SyntaxKind}; -use mofmt::{pretty_print, format}; -use std::fs; +use mofmt::{format, pretty_print}; +use moparse::{lex, parse, SyntaxKind}; use std::env; +use std::fs; +use std::path::Path; +use std::path::PathBuf; fn main() { let args: Vec = env::args().collect(); let file_path = &args[1]; - let contents = fs::read_to_string(file_path) - .expect("error"); + let contents = read_file(file_path); let tokens = lex(&contents); let events = parse(&tokens, SyntaxKind::StoredDefinition); let markers = format(&tokens, &events); let output = pretty_print(&tokens, &markers); - println!("{}", output); + write_file(file_path, output); +} + +/// Return all Modelica files from the given directory +fn get_files_from_dir(dir: &Path) -> Vec { + let mut files = Vec::new(); + let paths = fs::read_dir(dir) + .expect(format!("{}: error reading from a directory", dir.display()).as_str()); + for item in paths { + match item { + Ok(entry) => { + let path = entry.path(); + if path.is_file() && path.extension().is_some() { + if path.extension().unwrap() == "mo" { + files.push(path); + } + } else if path.is_dir() { + files.append(&mut get_files_from_dir(path.as_path())); + } + } + Err(_) => (), + } + } + + files +} + +/// Return contents of the Modelica file +fn read_file(from: &String) -> String { + let path = Path::new(&from); + let suffix = path + .extension() + .expect(format!("{}: is not a Modelica file", from).as_str()); + if suffix != "mo" { + panic!("{}: is not a Modelica file", from); + } + + fs::read_to_string(path).expect(format!("{}: error reading a file", from).as_str()) +} + +/// Write formatted code to a file +fn write_file(to: &String, code: String) { + fs::write(to, code).expect(format!("{}: error writing a file", to).as_str()); } From 9f59bad826b9eb00f6e2dcd5413d830e680d8b46 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 11 Jan 2024 08:49:53 +0100 Subject: [PATCH 20/67] Add support for recursive directory formatting --- src/main.rs | 91 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23fe421..0a9b723 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,59 +1,74 @@ use mofmt::{format, pretty_print}; use moparse::{lex, parse, SyntaxKind}; -use std::env; -use std::fs; -use std::path::Path; -use std::path::PathBuf; +use std::{env, fs}; +use std::path::{Path, PathBuf}; fn main() { let args: Vec = env::args().collect(); - let file_path = &args[1]; - let contents = read_file(file_path); - let tokens = lex(&contents); - let events = parse(&tokens, SyntaxKind::StoredDefinition); - let markers = format(&tokens, &events); - let output = pretty_print(&tokens, &markers); - write_file(file_path, output); + format_files(&args[1..]); +} + +/// Format files specified in the argument list +fn format_files(args: &[String]) { + let mut files = Vec::new(); + args.into_iter() + .map(|s| PathBuf::from(s)) + .map(|p| { + if p.is_dir() { + get_files_from_dir(p) + } else { + vec![p] + } + }) + .for_each(|mut v| files.append(&mut v)); + files.iter().for_each(|p| { + let contents = read_file(p); + let tokens = lex(&contents); + let events = parse(&tokens, SyntaxKind::StoredDefinition); + let markers = format(&tokens, &events); + let output = pretty_print(&tokens, &markers); + write_file(p, output); + }); } /// Return all Modelica files from the given directory -fn get_files_from_dir(dir: &Path) -> Vec { +fn get_files_from_dir(dir: PathBuf) -> Vec { let mut files = Vec::new(); - let paths = fs::read_dir(dir) + let paths = fs::read_dir(&dir) .expect(format!("{}: error reading from a directory", dir.display()).as_str()); - for item in paths { - match item { - Ok(entry) => { - let path = entry.path(); - if path.is_file() && path.extension().is_some() { - if path.extension().unwrap() == "mo" { - files.push(path); - } - } else if path.is_dir() { - files.append(&mut get_files_from_dir(path.as_path())); - } + paths + .map(|e| e.unwrap().path()) + .map(|p| { + if p.is_dir() { + get_files_from_dir(p) + } else if is_modelica(p.as_path()) { + vec![p] + } else { + Vec::new() } - Err(_) => (), - } - } + }) + .for_each(|mut v| files.append(&mut v)); files } -/// Return contents of the Modelica file -fn read_file(from: &String) -> String { - let path = Path::new(&from); - let suffix = path - .extension() - .expect(format!("{}: is not a Modelica file", from).as_str()); - if suffix != "mo" { - panic!("{}: is not a Modelica file", from); +/// Return `true` if the file is a Modelica file +fn is_modelica(f: &Path) -> bool { + if let Some(suffix) = f.extension() { + return suffix == "mo"; } + false +} - fs::read_to_string(path).expect(format!("{}: error reading a file", from).as_str()) +/// Return contents of the Modelica file +fn read_file(from: &Path) -> String { + if !is_modelica(from) { + panic!("{}: is not a Modelica file", from.display()); + } + fs::read_to_string(from).expect(format!("{}: error reading a file", from.display()).as_str()) } /// Write formatted code to a file -fn write_file(to: &String, code: String) { - fs::write(to, code).expect(format!("{}: error writing a file", to).as_str()); +fn write_file(to: &Path, code: String) { + fs::write(to, code).expect(format!("{}: error writing a file", to.display()).as_str()); } From 77d754d2298e61d4b49a129b2a988028758ccb6c Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 11 Jan 2024 10:50:13 +0100 Subject: [PATCH 21/67] Safer unwrapping and less loops --- src/formatting.rs | 112 ++++++++++++++++++++++--------------------- src/main.rs | 2 +- src/markers.rs | 20 ++++---- src/printing.rs | 33 ++++++------- tests/style_tests.rs | 2 +- 5 files changed, 85 insertions(+), 84 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index cc94ab2..123608f 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -52,9 +52,9 @@ impl<'a> Formatter<'a> { prev_token: TokenKind::EOF, prev_line: 1, brackets: 0, - groups: vec![false], - rules: vec![SyntaxKind::StoredDefinition], - wraps: vec![false], + groups: Vec::new(), + rules: Vec::new(), + wraps: Vec::new(), } } @@ -62,11 +62,8 @@ impl<'a> Formatter<'a> { fn handle_comments(&mut self, comments: Vec<&Token>, current_line: usize) { let mut line = self.prev_line; let mut diff = comments[0].start.line - line; - let mut tail = Vec::new(); - if diff == 0 { - // Handle inline comments - tail = self.markers.cache_tail(); - } + // Handle inline comments + let tail = if diff == 0 { None } else { self.markers.cache_tail() }; for comment in comments { diff = comment.start.line - line; if diff == 0 { @@ -84,7 +81,7 @@ impl<'a> Formatter<'a> { diff = current_line - line; if self.prev_line == 1 { self.markers.push(Marker::Break); - } else if tail.len() > 0 { + } else if let Some(mut tail) = tail { self.markers.append(&mut tail); } else if diff == 1 { self.markers.push(Marker::Break); @@ -95,26 +92,22 @@ impl<'a> Formatter<'a> { /// Insert line break or space fn break_or_space(&mut self) { - match self.groups.last() { - Some(b) => { - if *b { - self.markers.push(Marker::Break); - } else { - if !NO_SPACE_AFTER.contains(&self.prev_token) { - self.markers.push(Marker::Space); - } - } - } - None => { + if let Some(b) = self.groups.last() { + if *b { + self.markers.push(Marker::Break); + } else { if !NO_SPACE_AFTER.contains(&self.prev_token) { self.markers.push(Marker::Space); } } + } else { + if !NO_SPACE_AFTER.contains(&self.prev_token) { + self.markers.push(Marker::Space); + } } } fn enter_group(&mut self, typ: SyntaxKind, first: &Token, last: &Token) { - // Mark the group as broken if group was multiline if first.start.line < last.end.line { // Handle conditional expression if first.typ == TokenKind::If { @@ -130,20 +123,19 @@ impl<'a> Formatter<'a> { } // Handle matrix row } else if typ == SyntaxKind::ExpressionList { - if !*self.groups.last().unwrap() { + if !*self.groups.last().unwrap_or_else(|| &false) { self.markers.push(Marker::Indent); } } else { self.markers.push(Marker::Indent); } - self.groups.push(true); - } else { - self.groups.push(false); } + // Mark the group as broken if group was multiline + self.groups.push(first.start.line < last.end.line); } - fn exit_group(&mut self, enter: &Payload, exit: &Payload) { - let group_broken = self.groups.pop().unwrap(); + fn exit_group(&mut self, enter: &Payload) { + let group_broken = self.groups.pop().unwrap_or_else(|| false); if group_broken { // Handle conditional expression if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If { @@ -158,8 +150,8 @@ impl<'a> Formatter<'a> { self.markers.push(Marker::Dedent); } // Handle matrix row - } else if exit.typ == SyntaxKind::ExpressionList { - if !*self.groups.last().unwrap() { + } else if enter.typ == SyntaxKind::ExpressionList { + if !*self.groups.last().unwrap_or_else(|| &false) { self.markers.push(Marker::Dedent); } } else { @@ -189,12 +181,13 @@ impl<'a> Formatter<'a> { .contains(&self.prev_token) { // Only indent if this is a first wrap - let wrapped = self.wraps.last_mut().unwrap(); - if !*wrapped { - self.markers.push(Marker::Indent); - *wrapped = true; + if let Some(wrapped) = self.wraps.last_mut() { + if !*wrapped { + self.markers.push(Marker::Indent); + *wrapped = true; + } + self.markers.push(Marker::Wrap); } - self.markers.push(Marker::Wrap); } } else { if !NO_SPACE_AFTER.contains(&self.prev_token) { @@ -206,7 +199,10 @@ impl<'a> Formatter<'a> { fn handle_token(&mut self, i: usize) { let tok = self.tokens.get_token(i).unwrap(); let kind = tok.typ; - let parent = *self.rules.last().unwrap(); + let parent = *self + .rules + .last() + .unwrap_or_else(|| &SyntaxKind::StoredDefinition); let comments = preceding_comments(self.tokens, tok.idx); if self.prev_token == TokenKind::Semi { // Handle matrix rows @@ -247,9 +243,7 @@ impl<'a> Formatter<'a> { } TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { // Handle conditional expression context - if parent == SyntaxKind::Expression { - self.break_or_space(); - } else if [ + if [ SyntaxKind::IfEquation, SyntaxKind::IfStatement, SyntaxKind::WhenEquation, @@ -258,6 +252,8 @@ impl<'a> Formatter<'a> { .contains(&parent) { self.markers.push(Marker::Break); + } else { + self.break_or_space(); } } TokenKind::Dot => { @@ -268,9 +264,8 @@ impl<'a> Formatter<'a> { self.markers.push(Marker::Space); } } - TokenKind::Protected | TokenKind::Public => self.markers.push(Marker::Blank), - TokenKind::External => { - self.markers.push(Marker::Blank); + TokenKind::Protected | TokenKind::Public | TokenKind::External => { + self.markers.push(Marker::Blank) } TokenKind::Plus | TokenKind::DotPlus @@ -347,8 +342,8 @@ impl<'a> Formatter<'a> { } fn walk_events(&mut self) { - for idx in 0..self.events.len() { - match &self.events[idx] { + for event in self.events { + match event { SyntaxEvent::Advance(t) => match t { Terminal::Token(i) => self.handle_token(*i), _ => (), @@ -356,7 +351,10 @@ impl<'a> Formatter<'a> { SyntaxEvent::Enter(p) => { let first = self.tokens.get_token(p.tok).unwrap(); let last = self.events[p.pair].get_token(self.tokens); - let parent = self.rules.last().unwrap(); + let parent = self + .rules + .last() + .unwrap_or_else(|| &SyntaxKind::StoredDefinition); match p.typ { SyntaxKind::DescriptionString | SyntaxKind::ConstrainingClause @@ -447,16 +445,17 @@ impl<'a> Formatter<'a> { self.rules.push(p.typ); } SyntaxEvent::Exit(p_end) => { - let typ = self.rules.pop().unwrap(); + let typ = self + .rules + .pop() + .unwrap_or_else(|| SyntaxKind::StoredDefinition); let p_start; match &self.events[p_end.pair] { SyntaxEvent::Enter(enter) => p_start = enter, _ => unreachable!(), } let first = self.tokens.get_token(p_start.tok).unwrap(); - let last = self.tokens.get_token(p_end.tok).unwrap(); match typ { - // TODO: external element SyntaxKind::DescriptionString | SyntaxKind::AnnotationClause | SyntaxKind::ConstrainingClause @@ -467,7 +466,7 @@ impl<'a> Formatter<'a> { SyntaxKind::Primary => { // Handle matrix or array if [TokenKind::LBracket, TokenKind::LCurly].contains(&first.typ) { - self.exit_group(p_start, p_end); + self.exit_group(p_start); } } SyntaxKind::FunctionCallArgs @@ -475,21 +474,26 @@ impl<'a> Formatter<'a> { | SyntaxKind::ClassModification | SyntaxKind::ArraySubscripts | SyntaxKind::ExpressionList - | SyntaxKind::OutputExpressionList => self.exit_group(p_start, p_end), + | SyntaxKind::OutputExpressionList => self.exit_group(p_start), SyntaxKind::Expression => { // Handle conditional expression if first.typ == TokenKind::If { - self.exit_group(p_start, p_end); + self.exit_group(p_start); // Handle conditional part of the expression } else if [TokenKind::Then, TokenKind::Else] .contains(&self.tokens.get_token(p_start.tok - 1).unwrap().typ) - && *self.rules.last().unwrap() == SyntaxKind::Expression + && *self + .rules + .last() + .unwrap_or_else(|| &SyntaxKind::StoredDefinition) + == SyntaxKind::Expression { self.markers.push(Marker::Dedent); } - let wrapped = self.wraps.pop().unwrap(); - if wrapped { - self.markers.push(Marker::Dedent); + if let Some(wrapped) = self.wraps.pop() { + if wrapped { + self.markers.push(Marker::Dedent); + } } } _ => (), diff --git a/src/main.rs b/src/main.rs index 0a9b723..515191c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn format_files(args: &[String]) { let tokens = lex(&contents); let events = parse(&tokens, SyntaxKind::StoredDefinition); let markers = format(&tokens, &events); - let output = pretty_print(&tokens, &markers); + let output = pretty_print(&tokens, markers); write_file(p, output); }); } diff --git a/src/markers.rs b/src/markers.rs index 83ba5d7..5d6cc3c 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -51,22 +51,22 @@ impl MarkerCollector { self.markers.push(m); } - pub fn cache_tail(&mut self) -> Vec { + pub fn cache_tail(&mut self) -> Option> { let mut tail = Vec::new(); - loop { - let last = self.markers.last(); - if last.is_none() { + while let Some(last) = self.markers.last() { + if *last < Marker::Indent { break; } - if *last.unwrap() < Marker::Indent { - break; - } - if *last.unwrap() != Marker::Space { + if *last != Marker::Space { tail.push(self.markers.pop().unwrap()); } } - tail.reverse(); - tail + if tail.len() == 0 { + None + } else { + tail.reverse(); + Some(tail) + } } pub fn append(&mut self, markers: &mut Vec) { diff --git a/src/printing.rs b/src/printing.rs index d5ff5a4..d811ed3 100644 --- a/src/printing.rs +++ b/src/printing.rs @@ -2,14 +2,13 @@ use moparse::TokenCollection; use crate::markers::Marker; -pub fn pretty_print(tokens: &TokenCollection, markers: &Vec) -> String { +pub fn pretty_print(tokens: &TokenCollection, markers: Vec) -> String { let mut printer = Printer::new(); - let mut formatted = String::new(); - for marker in markers { - let s = printer.print_marker(marker, tokens); - formatted += s.as_str(); - } - formatted + let formatted: Vec = markers + .into_iter() + .filter_map(|m| printer.print_marker(m, tokens)) + .collect(); + formatted.join("") } struct Printer { @@ -21,29 +20,27 @@ impl Printer { Printer { indent: 0 } } - fn print_marker(&mut self, m: &Marker, tokens: &TokenCollection) -> String { + fn print_marker(&mut self, m: Marker, tokens: &TokenCollection) -> Option { const INDENT: &str = " "; match m { - Marker::Space => String::from(" "), - Marker::Ignore => String::new(), + Marker::Space => Some(String::from(" ")), + Marker::Ignore => None, Marker::Indent => { self.indent += 1; - String::new() + None } Marker::Dedent => { self.indent -= 1; - String::new() + None } - Marker::Token(i) | Marker::Comment(i) => tokens.get_item(*i).unwrap().text.clone(), + Marker::Token(i) | Marker::Comment(i) => Some(tokens.get_item(i).unwrap().text.clone()), _ => { let mut out = String::from("\n"); - if m == &Marker::Blank { + if m == Marker::Blank { out += "\n"; } - for i in 0..self.indent { - out += INDENT - } - out + (0..self.indent).for_each(|_| out += INDENT); + Some(out) } } } diff --git a/tests/style_tests.rs b/tests/style_tests.rs index a64374b..989ae8e 100644 --- a/tests/style_tests.rs +++ b/tests/style_tests.rs @@ -8,7 +8,7 @@ fn format_file(path: &str) -> String { let tokens = moparse::lex(&input); let events = moparse::parse(&tokens, moparse::SyntaxKind::StoredDefinition); let markers = mofmt::format(&tokens, &events); - mofmt::pretty_print(&tokens, &markers) + mofmt::pretty_print(&tokens, markers) } #[test] From 2d3585d4ae26cfae51ec58f257cbfb6966777aca Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 12 Jan 2024 12:58:59 +0100 Subject: [PATCH 22/67] Include more test samples --- src/formatting.rs | 10 +++++++--- tests/samples/functions-input.mo | 17 +++++++++++++++-- tests/samples/functions-output.mo | 23 ++++++++++++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 123608f..0f1276b 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -63,7 +63,11 @@ impl<'a> Formatter<'a> { let mut line = self.prev_line; let mut diff = comments[0].start.line - line; // Handle inline comments - let tail = if diff == 0 { None } else { self.markers.cache_tail() }; + let tail = if diff == 0 { + None + } else { + self.markers.cache_tail() + }; for comment in comments { diff = comment.start.line - line; if diff == 0 { @@ -423,8 +427,8 @@ impl<'a> Formatter<'a> { self.break_or_space(); } SyntaxKind::Expression => { - if [SyntaxKind::ExpressionList, SyntaxKind::OutputExpressionList] - .contains(parent) + if *parent == SyntaxKind::ExpressionList + || *parent == SyntaxKind::OutputExpressionList { self.break_or_space(); // Handle conditional expression diff --git a/tests/samples/functions-input.mo b/tests/samples/functions-input.mo index b430176..0407ecf 100644 --- a/tests/samples/functions-input.mo +++ b/tests/samples/functions-input.mo @@ -16,12 +16,17 @@ algorithm (F, G, (H, J)) := foo.bar.baz(c); -foo:={ - {bar[i] + j*(baz[i] - ber[i])/n for i in 1:n} for j in 1:m}; +foo:={{bar[i] + j* +(baz[i] - ber[i])/n for i in 1:n} for j in 1:m}; bar:={{foo[i] + j*(baz[i] - foo[i])/n for i in 1:n} for j in 1:m}; +baz := aaa ++ bbb * (ccc + ddd- + eee) + - fff * ggg; + external"C" foo[1].bar [2] = baz(x,y,z) annotation (Library="doesn't matter"); annotation (smoothOrder = 2); @@ -51,4 +56,12 @@ u3 > 0 Modelica.Utilities.Streams.print( "foo" + "bar" + "baz"); + + for i in 1:5 loop + foo[i] := bar[i] ^ 2 + * (4 - bar[i] / (6 * bar[i] + 6) + + sum({(4 - 2 * bar[i] / ((bar[i] + 1) * (k + 3)) + * ((bar[i] - 1) / bar[i]) ^ k) for k in 1:10})); + end for; + end Bar; diff --git a/tests/samples/functions-output.mo b/tests/samples/functions-output.mo index 6274ec8..b3600ed 100644 --- a/tests/samples/functions-output.mo +++ b/tests/samples/functions-output.mo @@ -26,7 +26,10 @@ algorithm J)) := foo.bar.baz(c); foo := { - {bar[i] + j * (baz[i] - ber[i]) / n for i in 1:n} + { + bar[i] + j + * (baz[i] - ber[i]) / n + for i in 1:n} for j in 1:m}; bar := { { @@ -34,6 +37,12 @@ algorithm for i in 1:n} for j in 1:m}; + baz := aaa + + bbb * ( + ccc + ddd + - eee) + - fff * ggg; + external "C" foo[1].bar[2] = baz(x, y, z) annotation (Library = "doesn't matter"); @@ -71,4 +80,16 @@ initial algorithm "foo" + "bar" + "baz"); + for i in 1:5 loop + foo[i] := bar[i] ^ 2 + * ( + 4 - bar[i] / (6 * bar[i] + 6) + + sum( + { + ( + 4 - 2 * bar[i] / ((bar[i] + 1) * (k + 3)) + * ((bar[i] - 1) / bar[i]) ^ k) + for k in 1:10})); + end for; + end Bar; From c07695ded52235b7cde3f7a955f4cab378de7a05 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 12 Jan 2024 16:24:57 +0100 Subject: [PATCH 23/67] Include error handling --- Cargo.toml | 2 +- src/formatting.rs | 11 ++++++++--- src/main.rs | 26 ++++++++++++++++++++++++-- tests/style_tests.rs | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c044628..773d4c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.2-rc2" +moparse = "0.1.2-rc3" diff --git a/src/formatting.rs b/src/formatting.rs index 0f1276b..fb268b7 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,16 +1,17 @@ use crate::markers::{Marker, MarkerCollector}; use moparse::*; -pub fn format(tokens: &TokenCollection, events: &Vec) -> Vec { +pub fn format(tokens: &TokenCollection, events: &Vec) -> (Vec, Vec) { let mut fmt = Formatter::new(tokens, events); fmt.walk_events(); - fmt.markers.markers + (fmt.markers.markers, fmt.errors) } struct Formatter<'a> { tokens: &'a TokenCollection, events: &'a Vec, markers: MarkerCollector, + errors: Vec, prev_token: TokenKind, prev_line: usize, brackets: usize, @@ -49,6 +50,7 @@ impl<'a> Formatter<'a> { tokens, events, markers: MarkerCollector::new(), + errors: Vec::new(), prev_token: TokenKind::EOF, prev_line: 1, brackets: 0, @@ -350,7 +352,10 @@ impl<'a> Formatter<'a> { match event { SyntaxEvent::Advance(t) => match t { Terminal::Token(i) => self.handle_token(*i), - _ => (), + Terminal::Error { msg, tok } => { + let bad_tok = self.tokens.get_token(*tok).unwrap(); + self.errors.push(format!("{}:{}: {}", bad_tok.start.line, bad_tok.start.col, msg)); + }, }, SyntaxEvent::Enter(p) => { let first = self.tokens.get_token(p.tok).unwrap(); diff --git a/src/main.rs b/src/main.rs index 515191c..1fd5b44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use mofmt::{format, pretty_print}; use moparse::{lex, parse, SyntaxKind}; -use std::{env, fs}; use std::path::{Path, PathBuf}; +use std::{env, fs}; fn main() { let args: Vec = env::args().collect(); @@ -24,8 +24,30 @@ fn format_files(args: &[String]) { files.iter().for_each(|p| { let contents = read_file(p); let tokens = lex(&contents); + if tokens.error_count() > 0 { + let messages: Vec = tokens + .errors() + .map(|e| { + format!( + "{}:{}:{}: {}", + p.display(), + e.start.line, + e.start.col, + e.text + ) + }) + .collect(); + panic!("Lexical errors detected:\n{}", messages.join("\n")); + } let events = parse(&tokens, SyntaxKind::StoredDefinition); - let markers = format(&tokens, &events); + let (markers, errors) = format(&tokens, &events); + if errors.len() > 0 { + let messages: Vec = errors + .iter() + .map(|e| format!("{}:{}", p.display(), e)) + .collect(); + panic!("Syntax errors detected:\n{}", messages.join("\n")); + } let output = pretty_print(&tokens, markers); write_file(p, output); }); diff --git a/tests/style_tests.rs b/tests/style_tests.rs index 989ae8e..a75677d 100644 --- a/tests/style_tests.rs +++ b/tests/style_tests.rs @@ -7,7 +7,7 @@ fn format_file(path: &str) -> String { let input = fs::read_to_string(path).expect("error"); let tokens = moparse::lex(&input); let events = moparse::parse(&tokens, moparse::SyntaxKind::StoredDefinition); - let markers = mofmt::format(&tokens, &events); + let (markers, _) = mofmt::format(&tokens, &events); mofmt::pretty_print(&tokens, markers) } From dd21efe8eaab9d566e03b8867769c978ca68f8e3 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Tue, 23 Jan 2024 09:47:29 +0100 Subject: [PATCH 24/67] New approach to formatting Every production formatted via dedicated function --- src/formatting.rs | 675 +++++++++++++++++++--------------------------- src/markers.rs | 149 +++++----- src/printing.rs | 93 ++++--- 3 files changed, 391 insertions(+), 526 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index fb268b7..7e333c9 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,9 +1,10 @@ -use crate::markers::{Marker, MarkerCollector}; +use std::net; + +use crate::markers::{self, Marker, MarkerCollector}; use moparse::*; pub fn format(tokens: &TokenCollection, events: &Vec) -> (Vec, Vec) { let mut fmt = Formatter::new(tokens, events); - fmt.walk_events(); (fmt.markers.markers, fmt.errors) } @@ -18,6 +19,7 @@ struct Formatter<'a> { groups: Vec, rules: Vec, wraps: Vec, + pos: usize, } const NO_SPACE_AFTER: [TokenKind; 7] = [ @@ -57,6 +59,7 @@ impl<'a> Formatter<'a> { groups: Vec::new(), rules: Vec::new(), wraps: Vec::new(), + pos: 0, } } @@ -96,422 +99,46 @@ impl<'a> Formatter<'a> { } } - /// Insert line break or space - fn break_or_space(&mut self) { - if let Some(b) = self.groups.last() { - if *b { - self.markers.push(Marker::Break); - } else { - if !NO_SPACE_AFTER.contains(&self.prev_token) { - self.markers.push(Marker::Space); - } - } - } else { - if !NO_SPACE_AFTER.contains(&self.prev_token) { - self.markers.push(Marker::Space); - } - } + fn next(&self) -> Option<&SyntaxEvent> { + self.events.get(self.pos) } - fn enter_group(&mut self, typ: SyntaxKind, first: &Token, last: &Token) { - if first.start.line < last.end.line { - // Handle conditional expression - if first.typ == TokenKind::If { - if [ - TokenKind::Equal, - TokenKind::Assign, - TokenKind::Then, - TokenKind::Else, - ] - .contains(&self.prev_token) - { - self.markers.push(Marker::Indent); - } - // Handle matrix row - } else if typ == SyntaxKind::ExpressionList { - if !*self.groups.last().unwrap_or_else(|| &false) { - self.markers.push(Marker::Indent); - } - } else { - self.markers.push(Marker::Indent); - } - } - // Mark the group as broken if group was multiline - self.groups.push(first.start.line < last.end.line); + fn advance(&mut self) { + self.pos += 1; } - fn exit_group(&mut self, enter: &Payload) { - let group_broken = self.groups.pop().unwrap_or_else(|| false); - if group_broken { - // Handle conditional expression - if self.tokens.get_token(enter.tok).unwrap().typ == TokenKind::If { - if [ - TokenKind::Equal, - TokenKind::Assign, - TokenKind::Then, - TokenKind::Else, - ] - .contains(&self.tokens.get_token(enter.tok - 1).unwrap().typ) - { - self.markers.push(Marker::Dedent); - } - // Handle matrix row - } else if enter.typ == SyntaxKind::ExpressionList { - if !*self.groups.last().unwrap_or_else(|| &false) { - self.markers.push(Marker::Dedent); - } - } else { - self.markers.push(Marker::Dedent); - } - } + fn token(&self, i: usize) -> &Token { + self.tokens.get_token(i).unwrap() } - /// Place the line break at the i-th token - fn wrap_expression(&mut self, i: usize) { - let next_tok = self.tokens.get_token(i + 1).unwrap(); - // Check if there was a line break around the wrap point - if next_tok.start.line > self.prev_line { - // Consider only binary operators - if [ - TokenKind::RBracket, - TokenKind::RParen, - TokenKind::RCurly, - TokenKind::Ident, - TokenKind::String, - TokenKind::Uint, - TokenKind::Ureal, - TokenKind::True, - TokenKind::False, - TokenKind::End, - ] - .contains(&self.prev_token) - { - // Only indent if this is a first wrap - if let Some(wrapped) = self.wraps.last_mut() { - if !*wrapped { - self.markers.push(Marker::Indent); - *wrapped = true; - } - self.markers.push(Marker::Wrap); - } - } - } else { - if !NO_SPACE_AFTER.contains(&self.prev_token) { - self.markers.push(Marker::Space); - } - } + fn next_token(&self, i: usize) -> &Token { + self.tokens + .get_token(i + 1) + .unwrap_or_else(|| self.token(i)) } - fn handle_token(&mut self, i: usize) { - let tok = self.tokens.get_token(i).unwrap(); - let kind = tok.typ; - let parent = *self - .rules - .last() - .unwrap_or_else(|| &SyntaxKind::StoredDefinition); - let comments = preceding_comments(self.tokens, tok.idx); - if self.prev_token == TokenKind::Semi { - // Handle matrix rows - if self.brackets == 0 { - self.markers.push(Marker::Break); - } else { - self.markers.push(Marker::Space); - } - if comments.is_none() { - if tok.start.line - self.prev_line > 1 && !NO_BREAK_BEFORE.contains(&kind) { - self.markers.push(Marker::Blank); - } - } - } - - // Handle comments - if comments.is_some() { - self.handle_comments(comments.unwrap(), tok.start.line); - } - - match kind { - TokenKind::LBracket => { - self.brackets += 1; - if self.prev_token != TokenKind::Ident && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - TokenKind::RBracket => self.brackets -= 1, - TokenKind::For => self.break_or_space(), - TokenKind::End => { - // Handle end clause in class specifiers - if parent == SyntaxKind::LongClassSpecifier { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Space); - } - } - TokenKind::Elif | TokenKind::Else | TokenKind::Elwhen => { - // Handle conditional expression context - if [ - SyntaxKind::IfEquation, - SyntaxKind::IfStatement, - SyntaxKind::WhenEquation, - SyntaxKind::WhenStatement, - ] - .contains(&parent) - { - self.markers.push(Marker::Break); - } else { - self.break_or_space(); - } - } - TokenKind::Dot => { - // Only first dot in type specifiers etc. can be preceded with a space - if ![TokenKind::Ident, TokenKind::RBracket].contains(&self.prev_token) - && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - TokenKind::Protected | TokenKind::Public | TokenKind::External => { - self.markers.push(Marker::Blank) - } - TokenKind::Plus - | TokenKind::DotPlus - | TokenKind::Minus - | TokenKind::DotMinus - | TokenKind::Star - | TokenKind::DotStar - | TokenKind::Slash - | TokenKind::DotSlash - | TokenKind::Flex - | TokenKind::DotFlex - | TokenKind::And - | TokenKind::Or - | TokenKind::Gre - | TokenKind::Geq - | TokenKind::Les - | TokenKind::Leq - | TokenKind::Eq - | TokenKind::Neq => { - self.wrap_expression(i); - } - TokenKind::LParen => { - if ![ - TokenKind::Ident, - TokenKind::Pure, - TokenKind::Der, - TokenKind::Initial, - TokenKind::RBracket, - ] - .contains(&self.prev_token) - && !NO_SPACE_AFTER.contains(&self.prev_token) - { - self.markers.push(Marker::Space); - } - } - _ => { - if !NO_SPACE_BEFORE.contains(&kind) && !NO_SPACE_AFTER.contains(&self.prev_token) { - self.markers.push(Marker::Space); - } - } - } - - self.markers.push(Marker::Token(tok.idx)); + fn prev_token(&self, i: usize) -> &Token { + self.tokens + .get_token(i - 1) + .unwrap_or_else(|| self.token(i)) + } - match kind { - //TokenKind::Annotation => self.markers.push(Marker::Space), - TokenKind::Equation | TokenKind::Algorithm => { - self.markers.push(Marker::Break); + fn is_multiline(&self) -> bool { + if let SyntaxEvent::Enter(enter) = self.next().unwrap() { + if let SyntaxEvent::Exit(exit) = self.events.get(enter.pair).unwrap() { + let first = self.token(enter.tok); + let last = self.token(exit.tok); + return first.start.line < last.end.line; } - TokenKind::Plus | TokenKind::DotPlus | TokenKind::Minus | TokenKind::DotMinus => { - // Do not add next space if unary operator - if ![ - TokenKind::RBracket, - TokenKind::RParen, - TokenKind::RCurly, - TokenKind::Ident, - TokenKind::String, - TokenKind::Uint, - TokenKind::Ureal, - TokenKind::True, - TokenKind::False, - TokenKind::End, - ] - .contains(&self.prev_token) - { - self.markers.push(Marker::Ignore); - } - } - _ => (), } - - self.prev_token = kind; - self.prev_line = tok.start.line; + false } - fn walk_events(&mut self) { - for event in self.events { - match event { - SyntaxEvent::Advance(t) => match t { - Terminal::Token(i) => self.handle_token(*i), - Terminal::Error { msg, tok } => { - let bad_tok = self.tokens.get_token(*tok).unwrap(); - self.errors.push(format!("{}:{}: {}", bad_tok.start.line, bad_tok.start.col, msg)); - }, - }, - SyntaxEvent::Enter(p) => { - let first = self.tokens.get_token(p.tok).unwrap(); - let last = self.events[p.pair].get_token(self.tokens); - let parent = self - .rules - .last() - .unwrap_or_else(|| &SyntaxKind::StoredDefinition); - match p.typ { - SyntaxKind::DescriptionString - | SyntaxKind::ConstrainingClause - | SyntaxKind::EnumerationLiteral => { - self.markers.push(Marker::Indent); - self.markers.push(Marker::Break); - } - SyntaxKind::AnnotationClause => { - self.markers.push(Marker::Indent); - // Handle class annotations - if *parent == SyntaxKind::Composition - && ![TokenKind::External, TokenKind::String, TokenKind::RParen] - .contains(&self.prev_token) - { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Break); - } - } - SyntaxKind::Equation | SyntaxKind::Statement => { - self.markers.push(Marker::Indent); - if [ - TokenKind::Loop, - TokenKind::Then, - TokenKind::Else, - TokenKind::Equation, - TokenKind::Algorithm, - ] - .contains(&self.prev_token) - { - self.markers.push(Marker::Break); - } - } - SyntaxKind::ElementList => { - self.markers.push(Marker::Indent); - self.markers.push(Marker::Blank); - } - SyntaxKind::EquationSection | SyntaxKind::AlgorithmSection => { - self.markers.push(Marker::Blank); - } - SyntaxKind::Primary => { - // Handle matrix or array - if [TokenKind::LBracket, TokenKind::LCurly].contains(&first.typ) { - self.enter_group(p.typ, first, last); - } - } - SyntaxKind::FunctionCallArgs - | SyntaxKind::ClassOrInheritanceModification - | SyntaxKind::ClassModification - | SyntaxKind::ArraySubscripts - | SyntaxKind::OutputExpressionList => { - self.enter_group(p.typ, first, last); - } - SyntaxKind::ExpressionList => { - self.break_or_space(); - self.enter_group(p.typ, first, last); - } - SyntaxKind::Subscript - | SyntaxKind::NamedArgument - | SyntaxKind::Argument - | SyntaxKind::InheritanceModification - | SyntaxKind::FunctionArgumentsNonFirst - | SyntaxKind::FunctionArguments - | SyntaxKind::ArrayArguments - | SyntaxKind::ArrayArgumentsNonFirst => { - self.break_or_space(); - } - SyntaxKind::Expression => { - if *parent == SyntaxKind::ExpressionList - || *parent == SyntaxKind::OutputExpressionList - { - self.break_or_space(); - // Handle conditional expression - } else if first.typ == TokenKind::If { - self.enter_group(p.typ, first, last); - self.break_or_space(); - // Handle conditional parts in conditional expression - } else if [TokenKind::Then, TokenKind::Else].contains(&self.prev_token) - && *parent == SyntaxKind::Expression - { - self.markers.push(Marker::Indent); - self.break_or_space(); - } - self.wraps.push(false); - } - _ => (), - } - self.rules.push(p.typ); - } - SyntaxEvent::Exit(p_end) => { - let typ = self - .rules - .pop() - .unwrap_or_else(|| SyntaxKind::StoredDefinition); - let p_start; - match &self.events[p_end.pair] { - SyntaxEvent::Enter(enter) => p_start = enter, - _ => unreachable!(), - } - let first = self.tokens.get_token(p_start.tok).unwrap(); - match typ { - SyntaxKind::DescriptionString - | SyntaxKind::AnnotationClause - | SyntaxKind::ConstrainingClause - | SyntaxKind::Equation - | SyntaxKind::Statement - | SyntaxKind::ElementList - | SyntaxKind::EnumerationLiteral => self.markers.push(Marker::Dedent), - SyntaxKind::Primary => { - // Handle matrix or array - if [TokenKind::LBracket, TokenKind::LCurly].contains(&first.typ) { - self.exit_group(p_start); - } - } - SyntaxKind::FunctionCallArgs - | SyntaxKind::ClassOrInheritanceModification - | SyntaxKind::ClassModification - | SyntaxKind::ArraySubscripts - | SyntaxKind::ExpressionList - | SyntaxKind::OutputExpressionList => self.exit_group(p_start), - SyntaxKind::Expression => { - // Handle conditional expression - if first.typ == TokenKind::If { - self.exit_group(p_start); - // Handle conditional part of the expression - } else if [TokenKind::Then, TokenKind::Else] - .contains(&self.tokens.get_token(p_start.tok - 1).unwrap().typ) - && *self - .rules - .last() - .unwrap_or_else(|| &SyntaxKind::StoredDefinition) - == SyntaxKind::Expression - { - self.markers.push(Marker::Dedent); - } - if let Some(wrapped) = self.wraps.pop() { - if wrapped { - self.markers.push(Marker::Dedent); - } - } - } - _ => (), - } - } - } + fn is_empty(&self) -> bool { + if let SyntaxEvent::Enter(enter) = self.next().unwrap() { + return enter.pair - self.pos == 1; } - // Add one trailing newline - self.markers.push(Marker::Break); + false } } @@ -543,3 +170,243 @@ fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> Some(comments) } } + +fn wrap(f: &Formatter, i: usize, wrapped: &mut bool, markers: &mut Vec) { + let prev = f.prev_token(i); + let next = f.next_token(i); + if next.start.line > prev.end.line { + if !*wrapped { + markers.push(Marker::Indent); + *wrapped = true; + } + markers.push(Marker::Break); + } else { + markers.push(Marker::Space); + } +} + +fn format_prod(f: &mut Formatter, prod: SyntaxKind) -> Marker { + match prod { + SyntaxKind::Name => name(f), + SyntaxKind::TypeSpecifier => type_specifier(f), + SyntaxKind::ArraySubscripts => array_subscripts(f), + SyntaxKind::Subscript => subscript(f), + SyntaxKind::Description => description(f), + SyntaxKind::DescriptionString => description_string(f), + SyntaxKind::AnnotationClause => annotation_clause(f), + SyntaxKind::Error => error(f), + _ => Marker::Sequence(Vec::new()), + } +} +// Format `TypeSpecifier` production. There are no spaces between tokens. +fn type_specifier(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => { + let tok = f.token(*i); + markers.push(Marker::Token(tok.idx)); + } + Terminal::Error { .. } => unreachable!("Error in `TypeSpecifier` production"), + }, + } + f.advance(); + } + Marker::Sequence(markers) +} + +// Format `Name` production. There are no spaces between tokens. +fn name(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + let is_multiline = f.is_multiline(); + if is_multiline { + markers.push(Marker::Indent); + } + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => { + let tok = f.token(*i); + if is_multiline && tok.typ == TokenKind::Dot { + markers.push(Marker::Break); + } + markers.push(Marker::Token(tok.idx)); + } + Terminal::Error { .. } => unreachable!("Error in `Name` production"), + }, + } + f.advance(); + } + if is_multiline { + markers.push(Marker::Dedent); + } + Marker::Sequence(markers) +} + +fn array_subscripts(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + let is_multiline = f.is_multiline(); + if is_multiline { + markers.push(Marker::Indent); + } + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => { + let tok = f.token(*i); + markers.push(Marker::Token(tok.idx)); + match tok.typ { + TokenKind::Comma => { + if is_multiline { + markers.push(Marker::Break); + } else { + markers.push(Marker::Space); + } + } + TokenKind::LBracket => { + if is_multiline { + markers.push(Marker::Break); + } + } + _ => (), + } + } + Terminal::Error { .. } => unreachable!("Error in `Subscript` production"), + }, + } + f.advance(); + } + if is_multiline { + markers.push(Marker::Dedent); + } + Marker::Sequence(markers) +} + +// Format `Subscript` production. +fn subscript(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => markers.push(Marker::Token(*i)), + Terminal::Error { .. } => unreachable!("Error in `Subscript` production"), + }, + } + f.advance(); + } + markers.pop().unwrap() +} + +// Format `Description` production. +fn description(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => { + if let Some(Marker::Sequence(string)) = markers.first() { + if string.len() > 0 { + markers.push(Marker::Break); + } + } + markers.push(format_prod(f, p.typ)); + } + SyntaxEvent::Advance(_) => unreachable!("Terminal in `Description` production"), + } + f.advance(); + } + Marker::Sequence(markers) +} + +// Format `DescriptionString` production. +fn description_string(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + f.advance(); + let mut wrapped = false; + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => { + let tok = f.token(*i); + if tok.typ == TokenKind::Plus { + wrap(f, *i, &mut wrapped, &mut markers); + markers.push(Marker::Token(tok.idx)); + markers.push(Marker::Space); + } else { + markers.push(Marker::Token(tok.idx)); + } + } + Terminal::Error { .. } => unreachable!("Error in `DescriptionString` production"), + }, + } + f.advance(); + } + if wrapped { + markers.push(Marker::Dedent); + } + Marker::Sequence(markers) +} + +// Format `AnnotationClause` production. +fn annotation_clause(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(i) => { + let tok = f.token(*i); + markers.push(Marker::Token(tok.idx)); + markers.push(Marker::Space); + } + Terminal::Error { .. } => unreachable!("Error in `AnnotationClause` production"), + }, + } + f.advance(); + } + Marker::Sequence(markers) +} + +// Format `Error` production and store error message +fn error(f: &mut Formatter) -> Marker { + let mut markers = Vec::new(); + f.advance(); + while let Some(event) = f.next() { + match event { + SyntaxEvent::Exit(_) => break, + SyntaxEvent::Enter(_) => unreachable!("Another production in `Error`"), + SyntaxEvent::Advance(terminal) => match terminal { + Terminal::Token(_) => unreachable!("Token in `Error` production"), + Terminal::Error { msg, tok } => { + let bad_tok = f.tokens.get_token(*tok).unwrap(); + f.errors.push(format!( + "{}:{}: {}", + bad_tok.start.line, bad_tok.start.col, msg + )); + markers.push(Marker::Space); + markers.push(Marker::Token(bad_tok.idx)); + markers.push(Marker::Space); + } + }, + } + f.advance(); + } + Marker::Sequence(markers) +} diff --git a/src/markers.rs b/src/markers.rs index 5d6cc3c..ec079f3 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -1,75 +1,74 @@ -#[derive(PartialEq, PartialOrd)] -pub enum Marker { - Token(usize), - Comment(usize), - Indent, - Dedent, - Space, - Ignore, - Blank, - Break, - Wrap, -} - -pub struct MarkerCollector { - pub markers: Vec, -} - -impl MarkerCollector { - pub fn new() -> Self { - MarkerCollector { - markers: Vec::new(), - } - } - - pub fn push(&mut self, m: Marker) { - match m { - Marker::Space => { - if self.markers.len() == 0 || *self.markers.last().unwrap() >= Marker::Space { - return; - } - if [Marker::Indent, Marker::Dedent].contains(self.markers.last().unwrap()) - && *self.markers.get(self.markers.len() - 2).unwrap() >= Marker::Blank - { - return; - } - } - Marker::Blank => { - // Remove preceding break - if *self.markers.last().unwrap() >= Marker::Blank { - self.markers.pop(); - } - } - Marker::Break => { - // Do not add unnecessary breaks - if *self.markers.last().unwrap() >= Marker::Blank { - return; - } - } - _ => (), - } - self.markers.push(m); - } - - pub fn cache_tail(&mut self) -> Option> { - let mut tail = Vec::new(); - while let Some(last) = self.markers.last() { - if *last < Marker::Indent { - break; - } - if *last != Marker::Space { - tail.push(self.markers.pop().unwrap()); - } - } - if tail.len() == 0 { - None - } else { - tail.reverse(); - Some(tail) - } - } - - pub fn append(&mut self, markers: &mut Vec) { - self.markers.append(markers); - } -} +#[derive(PartialEq, PartialOrd)] +pub enum Marker { + Token(usize), + Comment(usize), + Indent, + Dedent, + Space, + Blank, + Break, + Sequence(Vec), +} + +pub struct MarkerCollector { + pub markers: Vec, +} + +impl MarkerCollector { + pub fn new() -> Self { + MarkerCollector { + markers: Vec::new(), + } + } + + pub fn push(&mut self, m: Marker) { + match m { + Marker::Space => { + if self.markers.len() == 0 || *self.markers.last().unwrap() >= Marker::Space { + return; + } + if [Marker::Indent, Marker::Dedent].contains(self.markers.last().unwrap()) + && *self.markers.get(self.markers.len() - 2).unwrap() >= Marker::Blank + { + return; + } + } + Marker::Blank => { + // Remove preceding break + if *self.markers.last().unwrap() >= Marker::Blank { + self.markers.pop(); + } + } + Marker::Break => { + // Do not add unnecessary breaks + if *self.markers.last().unwrap() >= Marker::Blank { + return; + } + } + _ => (), + } + self.markers.push(m); + } + + pub fn cache_tail(&mut self) -> Option> { + let mut tail = Vec::new(); + while let Some(last) = self.markers.last() { + if *last < Marker::Indent { + break; + } + if *last != Marker::Space { + tail.push(self.markers.pop().unwrap()); + } + } + if tail.len() == 0 { + None + } else { + tail.reverse(); + Some(tail) + } + } + + pub fn append(&mut self, markers: &mut Vec) { + self.markers.append(markers); + } +} diff --git a/src/printing.rs b/src/printing.rs index d811ed3..0611ec1 100644 --- a/src/printing.rs +++ b/src/printing.rs @@ -1,47 +1,46 @@ -use moparse::TokenCollection; - -use crate::markers::Marker; - -pub fn pretty_print(tokens: &TokenCollection, markers: Vec) -> String { - let mut printer = Printer::new(); - let formatted: Vec = markers - .into_iter() - .filter_map(|m| printer.print_marker(m, tokens)) - .collect(); - formatted.join("") -} - -struct Printer { - indent: usize, -} - -impl Printer { - fn new() -> Self { - Printer { indent: 0 } - } - - fn print_marker(&mut self, m: Marker, tokens: &TokenCollection) -> Option { - const INDENT: &str = " "; - match m { - Marker::Space => Some(String::from(" ")), - Marker::Ignore => None, - Marker::Indent => { - self.indent += 1; - None - } - Marker::Dedent => { - self.indent -= 1; - None - } - Marker::Token(i) | Marker::Comment(i) => Some(tokens.get_item(i).unwrap().text.clone()), - _ => { - let mut out = String::from("\n"); - if m == Marker::Blank { - out += "\n"; - } - (0..self.indent).for_each(|_| out += INDENT); - Some(out) - } - } - } -} +use moparse::TokenCollection; + +use crate::markers::Marker; + +pub fn pretty_print(tokens: &TokenCollection, markers: Vec) -> String { + let mut printer = Printer::new(); + let formatted: Vec = markers + .into_iter() + .filter_map(|m| printer.print_marker(m, tokens)) + .collect(); + formatted.join("") +} + +struct Printer { + indent: usize, +} + +impl Printer { + fn new() -> Self { + Printer { indent: 0 } + } + + fn print_marker(&mut self, m: Marker, tokens: &TokenCollection) -> Option { + const INDENT: &str = " "; + match m { + Marker::Space => Some(String::from(" ")), + Marker::Indent => { + self.indent += 1; + None + } + Marker::Dedent => { + self.indent -= 1; + None + } + Marker::Token(i) | Marker::Comment(i) => Some(tokens.get_item(i).unwrap().text.clone()), + _ => { + let mut out = String::from("\n"); + if m == Marker::Blank { + out += "\n"; + } + (0..self.indent).for_each(|_| out += INDENT); + Some(out) + } + } + } +} From 29f157bdcf2ca3c2d0520df78d488b8eb41f72f3 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 20:42:31 +0100 Subject: [PATCH 25/67] Use newest moparse --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 773d4c6..fb5d2cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.2-rc3" +moparse = "0.1.3" From 06ffaeb0ad5584a08b1465605893aa735b4fe16f Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 20:59:07 +0100 Subject: [PATCH 26/67] Add parse tree builder --- src/lib.rs | 9 +++-- src/tree.rs | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 src/tree.rs diff --git a/src/lib.rs b/src/lib.rs index 9e51a80..7b99841 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ -pub use self::printing::pretty_print; -pub use self::formatting::format; +//pub use self::printing::pretty_print; +//pub use self::formatting::format; -mod formatting; +//mod formatting; mod markers; -mod printing; +//mod printing; +mod tree; diff --git a/src/tree.rs b/src/tree.rs new file mode 100644 index 0000000..4970c30 --- /dev/null +++ b/src/tree.rs @@ -0,0 +1,103 @@ +use moparse::{ParsedModelica, SyntaxEvent, SyntaxKind, Token}; + +pub fn build_tree(parsed: ParsedModelica) -> Tree { + let mut stack = Vec::new(); + let mut tokens = parsed.tokens.into_iter(); + let mut events = parsed.events; + + assert!(matches!(events.pop(), Some(SyntaxEvent::Exit))); + + for event in events { + match event { + SyntaxEvent::Enter(kind) => stack.push(Tree::new(kind)), + SyntaxEvent::Exit => { + let tree = stack.pop().unwrap(); + if tree.len() > 0 { + stack.last_mut().unwrap().push(Child::Tree(tree)); + } + } + SyntaxEvent::Advance => { + let token = tokens.next().unwrap(); + stack.last_mut().unwrap().push(Child::Token(token)); + } + } + } + + stack.pop().unwrap() +} + +pub struct Tree { + pub kind: SyntaxKind, + pub children: Vec, +} + +pub enum Child { + Token(Token), + Tree(Tree), +} + +impl Tree { + pub fn new(kind: SyntaxKind) -> Self { + Tree { + kind, + children: Vec::new(), + } + } + + pub fn push(&mut self, child: Child) { + self.children.push(child); + } + + pub fn len(&self) -> usize { + self.children.len() + } + + pub fn start(&self) -> &Token { + match self.children.first().unwrap() { + Child::Token(token) => token, + Child::Tree(tree) => tree.start(), + } + } + + pub fn end(&self) -> &Token { + match self.children.last().unwrap() { + Child::Token(token) => token, + Child::Tree(tree) => tree.end(), + } + } +} + +#[cfg(test)] +mod tests { + use moparse::{parse, ModelicaToken}; + + use super::*; + + fn tree(source: &str, start: SyntaxKind) -> Tree { + let parsed = parse(source, start); + build_tree(parsed) + } + + #[test] + fn test_empty_rules() { + const SOURCE: &str = "annotation ()"; + let tree = tree(SOURCE, SyntaxKind::Description); + assert_eq!(tree.len(), 1); + } + + #[test] + fn test_start_and_end() { + const SOURCE: &str = r#""descr" annotation ()"#; + let tree = tree(SOURCE, SyntaxKind::Description); + assert_eq!(tree.len(), 2); + if let Child::Tree(annotation) = tree.children.get(1).unwrap() { + assert_eq!(annotation.len(), 2); + } else { + panic!("annotation not found"); + } + assert_eq!(tree.start().kind, ModelicaToken::String); + assert_eq!(tree.start().text, r#""descr""#); + assert_eq!(tree.end().kind, ModelicaToken::RParen); + assert_eq!(tree.end().end.pos, 21); + } +} From b2615055e23111e942c223bfe579523e58f2ee18 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 21:00:48 +0100 Subject: [PATCH 27/67] Add assertions to tree builder --- src/tree.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tree.rs b/src/tree.rs index 4970c30..6396a5f 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -23,6 +23,9 @@ pub fn build_tree(parsed: ParsedModelica) -> Tree { } } + assert!(matches!(tokens.next(), None)); + assert!(stack.len() == 1); + stack.pop().unwrap() } From 8b710d235fbc0189bb18d1b41d907591a690ea27 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 21:07:13 +0100 Subject: [PATCH 28/67] Include comments in the parse tree --- src/tree.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tree.rs b/src/tree.rs index 6396a5f..ec2712e 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -4,6 +4,7 @@ pub fn build_tree(parsed: ParsedModelica) -> Tree { let mut stack = Vec::new(); let mut tokens = parsed.tokens.into_iter(); let mut events = parsed.events; + let mut comments = parsed.comments.into_iter().peekable(); assert!(matches!(events.pop(), Some(SyntaxEvent::Exit))); @@ -18,6 +19,14 @@ pub fn build_tree(parsed: ParsedModelica) -> Tree { } SyntaxEvent::Advance => { let token = tokens.next().unwrap(); + while let Some(comment) = comments.peek() { + if comment.idx < token.idx { + stack + .last_mut() + .unwrap() + .push(Child::Token(comments.next().unwrap())); + } + } stack.last_mut().unwrap().push(Child::Token(token)); } } @@ -68,6 +77,12 @@ impl Tree { Child::Tree(tree) => tree.end(), } } + + pub fn is_multiline(&self) -> bool { + let first = self.start(); + let last = self.end(); + first.start.line > last.end.line + } } #[cfg(test)] From d9c2c8553031af8f528df7cc50bcf27f45729ae3 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 21:10:25 +0100 Subject: [PATCH 29/67] Remove MarkerCollector structure --- src/markers.rs | 71 +++----------------------------------------------- 1 file changed, 4 insertions(+), 67 deletions(-) diff --git a/src/markers.rs b/src/markers.rs index ec079f3..eb88f1d 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -1,74 +1,11 @@ -#[derive(PartialEq, PartialOrd)] +use moparse::Token; + +#[derive(PartialEq)] pub enum Marker { - Token(usize), - Comment(usize), + Token(Token), Indent, Dedent, Space, Blank, Break, - Sequence(Vec), -} - -pub struct MarkerCollector { - pub markers: Vec, -} - -impl MarkerCollector { - pub fn new() -> Self { - MarkerCollector { - markers: Vec::new(), - } - } - - pub fn push(&mut self, m: Marker) { - match m { - Marker::Space => { - if self.markers.len() == 0 || *self.markers.last().unwrap() >= Marker::Space { - return; - } - if [Marker::Indent, Marker::Dedent].contains(self.markers.last().unwrap()) - && *self.markers.get(self.markers.len() - 2).unwrap() >= Marker::Blank - { - return; - } - } - Marker::Blank => { - // Remove preceding break - if *self.markers.last().unwrap() >= Marker::Blank { - self.markers.pop(); - } - } - Marker::Break => { - // Do not add unnecessary breaks - if *self.markers.last().unwrap() >= Marker::Blank { - return; - } - } - _ => (), - } - self.markers.push(m); - } - - pub fn cache_tail(&mut self) -> Option> { - let mut tail = Vec::new(); - while let Some(last) = self.markers.last() { - if *last < Marker::Indent { - break; - } - if *last != Marker::Space { - tail.push(self.markers.pop().unwrap()); - } - } - if tail.len() == 0 { - None - } else { - tail.reverse(); - Some(tail) - } - } - - pub fn append(&mut self, markers: &mut Vec) { - self.markers.append(markers); - } } From 6915f22403397402f998c8648de39152bb642fd5 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Thu, 1 Feb 2024 21:54:26 +0100 Subject: [PATCH 30/67] new approach to formatting --- src/formatting.rs | 444 +++++++++------------------------------------- src/lib.rs | 2 +- src/markers.rs | 4 +- 3 files changed, 83 insertions(+), 367 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 7e333c9..8541b74 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,412 +1,130 @@ -use std::net; - -use crate::markers::{self, Marker, MarkerCollector}; +use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; -pub fn format(tokens: &TokenCollection, events: &Vec) -> (Vec, Vec) { - let mut fmt = Formatter::new(tokens, events); - (fmt.markers.markers, fmt.errors) -} - -struct Formatter<'a> { - tokens: &'a TokenCollection, - events: &'a Vec, - markers: MarkerCollector, - errors: Vec, - prev_token: TokenKind, - prev_line: usize, - brackets: usize, +struct Formatter { + markers: Vec, groups: Vec, rules: Vec, - wraps: Vec, - pos: usize, } -const NO_SPACE_AFTER: [TokenKind; 7] = [ - TokenKind::LParen, - TokenKind::Dot, - TokenKind::LBracket, - TokenKind::LCurly, - TokenKind::Semi, - TokenKind::Colon, - TokenKind::Connect, -]; -const NO_SPACE_BEFORE: [TokenKind; 6] = [ - TokenKind::RParen, - TokenKind::RBracket, - TokenKind::RCurly, - TokenKind::Semi, - TokenKind::Comma, - TokenKind::Colon, -]; -const NO_BREAK_BEFORE: [TokenKind; 4] = [ - TokenKind::End, - TokenKind::Else, - TokenKind::Elif, - TokenKind::Elwhen, -]; - -impl<'a> Formatter<'a> { - fn new(tokens: &'a TokenCollection, events: &'a Vec) -> Self { - Formatter { - tokens, - events, - markers: MarkerCollector::new(), - errors: Vec::new(), - prev_token: TokenKind::EOF, - prev_line: 1, - brackets: 0, - groups: Vec::new(), - rules: Vec::new(), - wraps: Vec::new(), - pos: 0, - } - } - - /// Handle comments and separate them if needed. - fn handle_comments(&mut self, comments: Vec<&Token>, current_line: usize) { - let mut line = self.prev_line; - let mut diff = comments[0].start.line - line; - // Handle inline comments - let tail = if diff == 0 { - None - } else { - self.markers.cache_tail() - }; - for comment in comments { - diff = comment.start.line - line; - if diff == 0 { - self.markers.push(Marker::Space); - } else if diff == 1 { - self.markers.push(Marker::Break); - } else { - if self.prev_token == TokenKind::Semi || line > self.prev_line { - self.markers.push(Marker::Blank); - } - } - self.markers.push(Marker::Comment(comment.idx)); - line = comment.start.line; - } - diff = current_line - line; - if self.prev_line == 1 { +impl Formatter { + fn break_or_space(&mut self, is_multiline: bool) { + if is_multiline { self.markers.push(Marker::Break); - } else if let Some(mut tail) = tail { - self.markers.append(&mut tail); - } else if diff == 1 { - self.markers.push(Marker::Break); - } else if diff > 1 { - self.markers.push(Marker::Blank); - } - } - - fn next(&self) -> Option<&SyntaxEvent> { - self.events.get(self.pos) - } - - fn advance(&mut self) { - self.pos += 1; - } - - fn token(&self, i: usize) -> &Token { - self.tokens.get_token(i).unwrap() - } - - fn next_token(&self, i: usize) -> &Token { - self.tokens - .get_token(i + 1) - .unwrap_or_else(|| self.token(i)) - } - - fn prev_token(&self, i: usize) -> &Token { - self.tokens - .get_token(i - 1) - .unwrap_or_else(|| self.token(i)) - } - - fn is_multiline(&self) -> bool { - if let SyntaxEvent::Enter(enter) = self.next().unwrap() { - if let SyntaxEvent::Exit(exit) = self.events.get(enter.pair).unwrap() { - let first = self.token(enter.tok); - let last = self.token(exit.tok); - return first.start.line < last.end.line; - } - } - false - } - - fn is_empty(&self) -> bool { - if let SyntaxEvent::Enter(enter) = self.next().unwrap() { - return enter.pair - self.pos == 1; - } - false - } -} - -/// Return comments that precedes the token of the given index -fn preceding_comments(tokens: &TokenCollection, i: usize) -> Option> { - // Check if the current token is not a first one - if i == 0 { - return None; - } - let mut rest = i - 1; - let mut comments = Vec::new(); - loop { - let prev_item = tokens.get_item(rest).unwrap(); - if [TokenKind::LineComment, TokenKind::BlockComment].contains(&prev_item.typ) { - comments.push(prev_item); } else { - break; + self.markers.push(Marker::Space); } - if rest > 0 { - rest -= 1; - } else { - break; - } - } - if comments.len() == 0 { - None - } else { - comments.reverse(); - Some(comments) } } -fn wrap(f: &Formatter, i: usize, wrapped: &mut bool, markers: &mut Vec) { - let prev = f.prev_token(i); - let next = f.next_token(i); - if next.start.line > prev.end.line { - if !*wrapped { - markers.push(Marker::Indent); - *wrapped = true; - } - markers.push(Marker::Break); - } else { - markers.push(Marker::Space); - } -} +fn class_modification(f: &mut Formatter, tree: Tree) {} -fn format_prod(f: &mut Formatter, prod: SyntaxKind) -> Marker { - match prod { - SyntaxKind::Name => name(f), - SyntaxKind::TypeSpecifier => type_specifier(f), - SyntaxKind::ArraySubscripts => array_subscripts(f), - SyntaxKind::Subscript => subscript(f), - SyntaxKind::Description => description(f), - SyntaxKind::DescriptionString => description_string(f), - SyntaxKind::AnnotationClause => annotation_clause(f), - SyntaxKind::Error => error(f), - _ => Marker::Sequence(Vec::new()), - } -} -// Format `TypeSpecifier` production. There are no spaces between tokens. -fn type_specifier(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => { - let tok = f.token(*i); - markers.push(Marker::Token(tok.idx)); - } - Terminal::Error { .. } => unreachable!("Error in `TypeSpecifier` production"), - }, +fn expression(f: &mut Formatter, tree: Tree) {} + +fn type_specifier(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(t) => name(f, t), + Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), } - f.advance(); } - Marker::Sequence(markers) } -// Format `Name` production. There are no spaces between tokens. -fn name(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - let is_multiline = f.is_multiline(); - if is_multiline { - markers.push(Marker::Indent); - } - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => { - let tok = f.token(*i); - if is_multiline && tok.typ == TokenKind::Dot { - markers.push(Marker::Break); - } - markers.push(Marker::Token(tok.idx)); - } - Terminal::Error { .. } => unreachable!("Error in `Name` production"), - }, +fn name(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(_) => unreachable!(), + Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), } - f.advance(); } - if is_multiline { - markers.push(Marker::Dedent); - } - Marker::Sequence(markers) } -fn array_subscripts(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - let is_multiline = f.is_multiline(); - if is_multiline { - markers.push(Marker::Indent); - } - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => { - let tok = f.token(*i); - markers.push(Marker::Token(tok.idx)); - match tok.typ { - TokenKind::Comma => { - if is_multiline { - markers.push(Marker::Break); - } else { - markers.push(Marker::Space); - } - } - TokenKind::LBracket => { - if is_multiline { - markers.push(Marker::Break); - } +fn array_subscripts(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + let is_multiline = tree.is_multiline(); + for child in tree.children { + match child { + Child::Tree(t) => match t.kind { + SyntaxKind::Subscript => subscript(f, t), + _ => unreachable!(), + }, + Child::Token(tok) => { + f.markers.push(Marker::Token(tok.text)); + match tok.kind { + ModelicaToken::LBracket => { + if is_multiline { + f.markers.push(Marker::Break); } - _ => (), } + ModelicaToken::Comma => f.break_or_space(is_multiline), + _ => (), } - Terminal::Error { .. } => unreachable!("Error in `Subscript` production"), - }, + } } - f.advance(); - } - if is_multiline { - markers.push(Marker::Dedent); } - Marker::Sequence(markers) + f.markers.push(Marker::Dedent); } -// Format `Subscript` production. -fn subscript(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => markers.push(Marker::Token(*i)), - Terminal::Error { .. } => unreachable!("Error in `Subscript` production"), +fn subscript(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(t) => match t.kind { + SyntaxKind::Expression => expression(f, t), + _ => unreachable!(), }, + Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), } - f.advance(); } - markers.pop().unwrap() } -// Format `Description` production. -fn description(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => { - if let Some(Marker::Sequence(string)) = markers.first() { - if string.len() > 0 { - markers.push(Marker::Break); +fn description(f: &mut Formatter, tree: Tree) { + for (idx, child) in tree.children.into_iter().enumerate() { + match child { + Child::Tree(t) => match t.kind { + SyntaxKind::DescriptionString => description_string(f, t), + SyntaxKind::AnnotationClause => { + if idx > 0 { + f.markers.push(Marker::Break); } + annotation_clause(f, t); } - markers.push(format_prod(f, p.typ)); - } - SyntaxEvent::Advance(_) => unreachable!("Terminal in `Description` production"), - } - f.advance(); - } - Marker::Sequence(markers) -} - -// Format `DescriptionString` production. -fn description_string(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - f.advance(); - let mut wrapped = false; - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => { - let tok = f.token(*i); - if tok.typ == TokenKind::Plus { - wrap(f, *i, &mut wrapped, &mut markers); - markers.push(Marker::Token(tok.idx)); - markers.push(Marker::Space); - } else { - markers.push(Marker::Token(tok.idx)); - } - } - Terminal::Error { .. } => unreachable!("Error in `DescriptionString` production"), + _ => unreachable!(), }, + Child::Token(_) => unreachable!(), } - f.advance(); - } - if wrapped { - markers.push(Marker::Dedent); } - Marker::Sequence(markers) } -// Format `AnnotationClause` production. -fn annotation_clause(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(p) => markers.push(format_prod(f, p.typ)), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(i) => { - let tok = f.token(*i); - markers.push(Marker::Token(tok.idx)); - markers.push(Marker::Space); +fn description_string(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Token(token) => match token.kind { + ModelicaToken::Plus => { + f.break_or_space(is_multiline); + f.markers.push(Marker::Token(token.text)); + f.markers.push(Marker::Space); } - Terminal::Error { .. } => unreachable!("Error in `AnnotationClause` production"), + ModelicaToken::String => f.markers.push(Marker::Token(token.text)), + _ => unreachable!(), }, + Child::Tree(_) => unreachable!(), } - f.advance(); } - Marker::Sequence(markers) + f.markers.push(Marker::Dedent); } -// Format `Error` production and store error message -fn error(f: &mut Formatter) -> Marker { - let mut markers = Vec::new(); - f.advance(); - while let Some(event) = f.next() { - match event { - SyntaxEvent::Exit(_) => break, - SyntaxEvent::Enter(_) => unreachable!("Another production in `Error`"), - SyntaxEvent::Advance(terminal) => match terminal { - Terminal::Token(_) => unreachable!("Token in `Error` production"), - Terminal::Error { msg, tok } => { - let bad_tok = f.tokens.get_token(*tok).unwrap(); - f.errors.push(format!( - "{}:{}: {}", - bad_tok.start.line, bad_tok.start.col, msg - )); - markers.push(Marker::Space); - markers.push(Marker::Token(bad_tok.idx)); - markers.push(Marker::Space); - } - }, +fn annotation_clause(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Token(token) => { + f.markers.push(Marker::Token(token.text)); + f.markers.push(Marker::Space); + } + Child::Tree(t) => { + class_modification(f, t); + } } - f.advance(); } - Marker::Sequence(markers) } diff --git a/src/lib.rs b/src/lib.rs index 7b99841..fb10835 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //pub use self::printing::pretty_print; //pub use self::formatting::format; -//mod formatting; +mod formatting; mod markers; //mod printing; mod tree; diff --git a/src/markers.rs b/src/markers.rs index eb88f1d..8122840 100644 --- a/src/markers.rs +++ b/src/markers.rs @@ -1,8 +1,6 @@ -use moparse::Token; - #[derive(PartialEq)] pub enum Marker { - Token(Token), + Token(String), Indent, Dedent, Space, From 8fdd9a0d54831191d00cadfc663c4beb6ae20b14 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 2 Feb 2024 12:07:47 +0100 Subject: [PATCH 31/67] Move comments out of the parse tree --- src/tree.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/tree.rs b/src/tree.rs index ec2712e..992e3a6 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -1,10 +1,9 @@ -use moparse::{ParsedModelica, SyntaxEvent, SyntaxKind, Token}; +use moparse::{SyntaxEvent, SyntaxKind, Token}; -pub fn build_tree(parsed: ParsedModelica) -> Tree { +pub fn build_tree(tokens: Vec, events: Vec) -> Tree { let mut stack = Vec::new(); - let mut tokens = parsed.tokens.into_iter(); - let mut events = parsed.events; - let mut comments = parsed.comments.into_iter().peekable(); + let mut tokens = tokens.into_iter(); + let mut events = events; assert!(matches!(events.pop(), Some(SyntaxEvent::Exit))); @@ -19,14 +18,6 @@ pub fn build_tree(parsed: ParsedModelica) -> Tree { } SyntaxEvent::Advance => { let token = tokens.next().unwrap(); - while let Some(comment) = comments.peek() { - if comment.idx < token.idx { - stack - .last_mut() - .unwrap() - .push(Child::Token(comments.next().unwrap())); - } - } stack.last_mut().unwrap().push(Child::Token(token)); } } @@ -93,7 +84,7 @@ mod tests { fn tree(source: &str, start: SyntaxKind) -> Tree { let parsed = parse(source, start); - build_tree(parsed) + build_tree(parsed.tokens, parsed.events) } #[test] From 8aaa16000d35ed8ccd6f0fcf943672195cf863ce Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 2 Feb 2024 12:10:52 +0100 Subject: [PATCH 32/67] Create formatting functions up to primary production --- src/formatting.rs | 357 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 322 insertions(+), 35 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 8541b74..7b35c86 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,63 +1,355 @@ +use std::{iter::Peekable, vec::IntoIter}; + use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; struct Formatter { + comments: Peekable>, markers: Vec, groups: Vec, rules: Vec, + in_matrix: usize, + prev_tok: ModelicaToken, + prev_line: usize, } impl Formatter { - fn break_or_space(&mut self, is_multiline: bool) { + fn break_or_space(&mut self, is_multiline: bool, tok: &Token) { if is_multiline { - self.markers.push(Marker::Break); + self.handle_break(tok, false); } else { self.markers.push(Marker::Space); } } + + fn handle_break(&mut self, tok: &Token, allow_blanks: bool) { + let (inlines, comments) = self.comments_before(tok); + for comment in inlines { + self.markers.push(Marker::Space); + self.markers.push(Marker::Token(comment.text)); + } + let mut line = self.prev_line; + for comment in comments { + if comment.start.line - line > 1 { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } + self.markers.push(Marker::Token(comment.text)); + line = comment.end.line; + } + if tok.start.line - line > 1 && allow_blanks { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } + } + + fn comments_before(&mut self, tok: &Token) -> (Vec, Vec) { + let mut comments = Vec::new(); + let mut inlines = Vec::new(); + while let Some(comment) = self.comments.peek() { + if comment.idx < tok.idx { + if comment.start.line == self.prev_line { + inlines.push(self.comments.next().unwrap()); + } else { + comments.push(self.comments.next().unwrap()); + } + } + } + (inlines, comments) + } + + fn handle_token(&mut self, tok: Token) { + self.prev_line = tok.end.line; + self.prev_tok = tok.kind; + self.markers.push(Marker::Token(tok.text)); + } } fn class_modification(f: &mut Formatter, tree: Tree) {} +fn for_indices(f: &mut Formatter, tree: Tree) {} + fn expression(f: &mut Formatter, tree: Tree) {} fn type_specifier(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { Child::Tree(t) => name(f, t), - Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), + Child::Token(tok) => f.handle_token(tok), } } } fn name(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn component_reference(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { - Child::Tree(_) => unreachable!(), - Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), + Child::Tree(t) => array_subscripts(f, t), + Child::Token(tok) => f.handle_token(tok), } } } -fn array_subscripts(f: &mut Formatter, tree: Tree) { - f.markers.push(Marker::Indent); +fn result_reference(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(t) => component_reference(f, t), + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::Comma { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn function_call_args(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::LParen && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + Child::Tree(tree) => function_arguments(f, tree, is_multiline), + } + } +} + +fn function_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { for child in tree.children { match child { - Child::Tree(t) => match t.kind { - SyntaxKind::Subscript => subscript(f, t), + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => expression(f, tree), + SyntaxKind::FunctionPartialApplication => function_partial_application(f, tree), + SyntaxKind::ForIndices => for_indices(f, tree), + SyntaxKind::FunctionArgumentsNonFirst => { + f.break_or_space(is_multiline, tree.start()); + array_arguments_non_first(f, tree, is_multiline); + } + SyntaxKind::NamedArguments => named_arguments(f, tree, is_multiline), + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::For { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } else { + f.handle_token(tok); + } + } + } + } +} + +fn function_arguments_non_first(f: &mut Formatter, tree: Tree, is_multiline: bool) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::FunctionArgument => function_argument(f, tree), + SyntaxKind::FunctionArgumentsNonFirst => { + f.break_or_space(is_multiline, tree.start()); + array_arguments_non_first(f, tree, is_multiline); + } + SyntaxKind::NamedArguments => named_arguments(f, tree, is_multiline), + _ => unreachable!(), + }, + Child::Token(tok) => f.handle_token(tok), + } + } +} + +fn array_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => expression(f, tree), + SyntaxKind::ArrayArgumentsNonFirst => { + f.break_or_space(is_multiline, tree.start()); + array_arguments_non_first(f, tree, is_multiline); + } + SyntaxKind::ForIndices => for_indices(f, tree), _ => unreachable!(), }, Child::Token(tok) => { - f.markers.push(Marker::Token(tok.text)); - match tok.kind { - ModelicaToken::LBracket => { - if is_multiline { - f.markers.push(Marker::Break); + if tok.kind == ModelicaToken::For { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } else { + f.handle_token(tok); + } + } + } + } +} + +fn array_arguments_non_first(f: &mut Formatter, tree: Tree, is_multiline: bool) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => expression(f, tree), + SyntaxKind::ArrayArgumentsNonFirst => { + f.break_or_space(is_multiline, tree.start()); + array_arguments_non_first(f, tree, is_multiline); + } + _ => unreachable!(), + }, + Child::Token(tok) => f.handle_token(tok), + } + } +} + +fn named_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::NamedArgument => named_argument(f, tree), + SyntaxKind::NamedArguments => { + f.break_or_space(is_multiline, tree.start()); + named_arguments(f, tree, is_multiline); + } + _ => unreachable!(), + }, + Child::Token(tok) => f.handle_token(tok), + } + } +} + +fn named_argument(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + function_argument(f, tree); + } else if let Child::Token(tok) = child { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } +} + +fn function_argument(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::FunctionPartialApplication => function_partial_application(f, tree), + SyntaxKind::Expression => expression(f, tree), + _ => unreachable!(), + } + } + } +} + +fn function_partial_application(f: &mut Formatter, tree: Tree) { + let mut is_multiline = false; + let mut children = tree.children.iter(); + while let Some(child) = children.next() { + if let Child::Token(token) = child { + if token.kind == ModelicaToken::LParen { + while let Some(child) = children.next() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::RParen { + is_multiline = tok.start.line > token.start.line; } } - ModelicaToken::Comma => f.break_or_space(is_multiline), - _ => (), + } + } + } + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => match t.kind { + SyntaxKind::TypeSpecifier => { + f.markers.push(Marker::Space); + type_specifier(f, t); + } + SyntaxKind::NamedArguments => named_arguments(f, t, is_multiline), + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::LParen { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + } + } +} + +fn output_expression_list(f: &mut Formatter, tree: Tree, is_multiline: bool) { + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => expression(f, t), + Child::Token(tok) => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + } + } +} + +fn expression_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { + // Expression list could be already wrapped in an outer production + // at the brackets or parentheses + if !is_multiline { + is_multiline = tree.is_multiline(); + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => expression(f, t), + Child::Token(tok) => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + } + } +} + +fn array_subscripts(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + let is_multiline = tree.is_multiline(); + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => subscript(f, t), + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::LBracket && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } else if kind == ModelicaToken::Comma { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } } } } @@ -68,29 +360,25 @@ fn array_subscripts(f: &mut Formatter, tree: Tree) { fn subscript(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { - Child::Tree(t) => match t.kind { - SyntaxKind::Expression => expression(f, t), - _ => unreachable!(), - }, - Child::Token(tok) => f.markers.push(Marker::Token(tok.text)), + Child::Tree(t) => expression(f, t), + Child::Token(tok) => f.handle_token(tok), } } } fn description(f: &mut Formatter, tree: Tree) { for (idx, child) in tree.children.into_iter().enumerate() { - match child { - Child::Tree(t) => match t.kind { + if let Child::Tree(t) = child { + match t.kind { SyntaxKind::DescriptionString => description_string(f, t), SyntaxKind::AnnotationClause => { if idx > 0 { - f.markers.push(Marker::Break); + f.handle_break(t.start(), false); } annotation_clause(f, t); } _ => unreachable!(), - }, - Child::Token(_) => unreachable!(), + } } } } @@ -99,17 +387,16 @@ fn description_string(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); f.markers.push(Marker::Indent); for child in tree.children { - match child { - Child::Token(token) => match token.kind { + if let Child::Token(tok) = child { + match tok.kind { ModelicaToken::Plus => { - f.break_or_space(is_multiline); - f.markers.push(Marker::Token(token.text)); + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); f.markers.push(Marker::Space); } - ModelicaToken::String => f.markers.push(Marker::Token(token.text)), + ModelicaToken::String => f.handle_token(tok), _ => unreachable!(), - }, - Child::Tree(_) => unreachable!(), + } } } f.markers.push(Marker::Dedent); @@ -118,8 +405,8 @@ fn description_string(f: &mut Formatter, tree: Tree) { fn annotation_clause(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { - Child::Token(token) => { - f.markers.push(Marker::Token(token.text)); + Child::Token(tok) => { + f.handle_token(tok); f.markers.push(Marker::Space); } Child::Tree(t) => { From e7a48300f2caaceab31702edd53bd7d7af5f476f Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 2 Feb 2024 13:32:56 +0100 Subject: [PATCH 33/67] Create formatting function for all rules in expression section --- src/formatting.rs | 247 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 2 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 7b35c86..d966374 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -71,7 +71,250 @@ fn class_modification(f: &mut Formatter, tree: Tree) {} fn for_indices(f: &mut Formatter, tree: Tree) {} -fn expression(f: &mut Formatter, tree: Tree) {} +fn expression(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + let mut conditional = false; + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.break_or_space(is_multiline, tree.start()); + expression(f, tree); + if conditional { + f.markers.push(Marker::Dedent); + if let Some(next_child) = children.peek() { + if let Child::Token(next_tok) = next_child { + f.break_or_space(is_multiline, next_tok); + } + } + } + conditional = false; + } + SyntaxKind::SimpleExpression => simple_expression(f, tree), + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::Then || kind == ModelicaToken::Else { + conditional = true; + f.markers.push(Marker::Indent); + } else { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn simple_expression(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => logical_expression(f, tree), + Child::Token(tok) => { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn logical_expression(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => logical_term(f, tree), + Child::Token(tok) => { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn logical_term(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => logical_factor(f, tree), + Child::Token(tok) => { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn logical_factor(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => relation(f, tree), + Child::Token(tok) => { + f.markers.push(Marker::Space); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn relation(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + if let Child::Tree(tree) = child { + if tree.kind == SyntaxKind::RelationalOperator { + f.break_or_space(is_multiline, tree.start()); + relational_operator(f, tree); + f.markers.push(Marker::Space); + } else { + arithmetic_expression(f, tree); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn relational_operator(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn arithmetic_expression(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for (idx, child) in tree.children.into_iter().enumerate() { + if let Child::Tree(tree) = child { + if tree.kind == SyntaxKind::AddOperator { + if idx > 0 { + f.break_or_space(is_multiline, tree.start()); + } + add_operator(f, tree); + if idx > 0 { + f.markers.push(Marker::Space); + } + } else { + term(f, tree); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn add_operator(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn term(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + if let Child::Tree(tree) = child { + if tree.kind == SyntaxKind::MulOperator { + f.break_or_space(is_multiline, tree.start()); + mul_operator(f, tree); + f.markers.push(Marker::Space); + } else { + factor(f, tree); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn mul_operator(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn factor(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => primary(f, tree), + Child::Token(tok) => { + f.break_or_space(is_multiline, &tok); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } + f.markers.push(Marker::Dedent); +} + +fn primary(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + let children_count = tree.children.len(); + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Token(tok) => match tok.kind { + ModelicaToken::UInt + | ModelicaToken::UReal + | ModelicaToken::String + | ModelicaToken::Bool + | ModelicaToken::Der + | ModelicaToken::Initial + | ModelicaToken::Pure + | ModelicaToken::End => f.handle_token(tok), + ModelicaToken::Semicolon => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + // Arrays etc. + ModelicaToken::LCurly | ModelicaToken::LBracket | ModelicaToken::LParen => { + f.handle_token(tok); + f.markers.push(Marker::Indent); + if is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + ModelicaToken::RCurly | ModelicaToken::RBracket | ModelicaToken::RParen => { + f.markers.push(Marker::Dedent); + f.handle_token(tok); + } + _ => unreachable!(), + }, + Child::Tree(tree) => match tree.kind { + SyntaxKind::ComponentReference => component_reference(f, tree), + SyntaxKind::FunctionCallArgs => function_call_args(f, tree), + SyntaxKind::ArraySubscripts => array_subscripts(f, tree), + SyntaxKind::ArrayArguments => array_arguments(f, tree, is_multiline), + SyntaxKind::ExpressionList => { + expression_list(f, tree, is_multiline && children_count == 3) + } + SyntaxKind::OutputExpressionList => output_expression_list(f, tree, is_multiline), + _ => unreachable!(), + }, + } + } +} fn type_specifier(f: &mut Formatter, tree: Tree) { for child in tree.children { @@ -287,7 +530,7 @@ fn function_partial_application(f: &mut Formatter, tree: Tree) { Child::Token(tok) => { let kind = tok.kind; f.handle_token(tok); - if kind == ModelicaToken::LParen { + if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { f.handle_break(next_tree.start(), false); } From f1ecb8a87895e6b03252c325d643a567374c71f5 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 2 Feb 2024 14:34:56 +0100 Subject: [PATCH 34/67] Manual test of expression formatting Fix indentation bugs --- Cargo.toml | 2 +- src/formatting.rs | 103 +++++++++++++++++++++++++++++++++++----------- src/lib.rs | 15 +++++-- src/main.rs | 29 +++---------- src/printing.rs | 10 ++--- src/tree.rs | 2 +- 6 files changed, 104 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb5d2cc..4099339 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.3" +moparse = "0.1.4-rc1" diff --git a/src/formatting.rs b/src/formatting.rs index d966374..0cd9935 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -3,17 +3,32 @@ use std::{iter::Peekable, vec::IntoIter}; use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; +pub fn format(tree: Tree, comments: Vec) -> Vec { + let mut f = Formatter::new(comments); + match tree.kind { + SyntaxKind::Expression => expression(&mut f, tree), + _ => (), + } + f.markers +} + struct Formatter { comments: Peekable>, markers: Vec, - groups: Vec, - rules: Vec, - in_matrix: usize, prev_tok: ModelicaToken, prev_line: usize, } impl Formatter { + fn new(comments: Vec) -> Self { + Formatter { + comments: comments.into_iter().peekable(), + markers: Vec::new(), + prev_tok: ModelicaToken::EOF, + prev_line: 1, + } + } + fn break_or_space(&mut self, is_multiline: bool, tok: &Token) { if is_multiline { self.handle_break(tok, false); @@ -55,6 +70,8 @@ impl Formatter { } else { comments.push(self.comments.next().unwrap()); } + } else { + break; } } (inlines, comments) @@ -79,7 +96,11 @@ fn expression(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::Expression => { - f.break_or_space(is_multiline, tree.start()); + if conditional { + f.break_or_space(is_multiline, tree.start()); + } else { + f.markers.push(Marker::Space); + } expression(f, tree); if conditional { f.markers.push(Marker::Dedent); @@ -88,6 +109,8 @@ fn expression(f: &mut Formatter, tree: Tree) { f.break_or_space(is_multiline, next_tok); } } + } else { + f.markers.push(Marker::Space); } conditional = false; } @@ -100,8 +123,6 @@ fn expression(f: &mut Formatter, tree: Tree) { if kind == ModelicaToken::Then || kind == ModelicaToken::Else { conditional = true; f.markers.push(Marker::Indent); - } else { - f.markers.push(Marker::Space); } } } @@ -110,7 +131,10 @@ fn expression(f: &mut Formatter, tree: Tree) { fn simple_expression(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { match child { Child::Tree(tree) => logical_expression(f, tree), @@ -121,12 +145,17 @@ fn simple_expression(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn logical_expression(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { match child { Child::Tree(tree) => logical_term(f, tree), @@ -137,12 +166,17 @@ fn logical_expression(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn logical_term(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { match child { Child::Tree(tree) => logical_factor(f, tree), @@ -153,7 +187,9 @@ fn logical_term(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn logical_factor(f: &mut Formatter, tree: Tree) { @@ -161,7 +197,6 @@ fn logical_factor(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => relation(f, tree), Child::Token(tok) => { - f.markers.push(Marker::Space); f.handle_token(tok); f.markers.push(Marker::Space); } @@ -171,7 +206,10 @@ fn logical_factor(f: &mut Formatter, tree: Tree) { fn relation(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { if let Child::Tree(tree) = child { if tree.kind == SyntaxKind::RelationalOperator { @@ -183,7 +221,9 @@ fn relation(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn relational_operator(f: &mut Formatter, tree: Tree) { @@ -196,7 +236,10 @@ fn relational_operator(f: &mut Formatter, tree: Tree) { fn arithmetic_expression(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for (idx, child) in tree.children.into_iter().enumerate() { if let Child::Tree(tree) = child { if tree.kind == SyntaxKind::AddOperator { @@ -212,7 +255,9 @@ fn arithmetic_expression(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn add_operator(f: &mut Formatter, tree: Tree) { @@ -225,7 +270,10 @@ fn add_operator(f: &mut Formatter, tree: Tree) { fn term(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { if let Child::Tree(tree) = child { if tree.kind == SyntaxKind::MulOperator { @@ -237,7 +285,9 @@ fn term(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn mul_operator(f: &mut Formatter, tree: Tree) { @@ -250,7 +300,10 @@ fn mul_operator(f: &mut Formatter, tree: Tree) { fn factor(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); - f.markers.push(Marker::Indent); + let length = tree.len(); + if is_multiline && length > 1 { + f.markers.push(Marker::Indent); + } for child in tree.children { match child { Child::Tree(tree) => primary(f, tree), @@ -261,7 +314,9 @@ fn factor(f: &mut Formatter, tree: Tree) { } } } - f.markers.push(Marker::Dedent); + if is_multiline && length > 1 { + f.markers.push(Marker::Dedent); + } } fn primary(f: &mut Formatter, tree: Tree) { @@ -360,6 +415,7 @@ fn result_reference(f: &mut Formatter, tree: Tree) { fn function_call_args(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); let mut children = tree.children.into_iter().peekable(); + f.markers.push(Marker::Indent); while let Some(child) = children.next() { match child { Child::Token(tok) => { @@ -374,6 +430,7 @@ fn function_call_args(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => function_arguments(f, tree, is_multiline), } } + f.markers.push(Marker::Dedent); } fn function_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { @@ -385,7 +442,7 @@ fn function_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { SyntaxKind::ForIndices => for_indices(f, tree), SyntaxKind::FunctionArgumentsNonFirst => { f.break_or_space(is_multiline, tree.start()); - array_arguments_non_first(f, tree, is_multiline); + function_arguments_non_first(f, tree, is_multiline); } SyntaxKind::NamedArguments => named_arguments(f, tree, is_multiline), _ => unreachable!(), @@ -410,7 +467,7 @@ fn function_arguments_non_first(f: &mut Formatter, tree: Tree, is_multiline: boo SyntaxKind::FunctionArgument => function_argument(f, tree), SyntaxKind::FunctionArgumentsNonFirst => { f.break_or_space(is_multiline, tree.start()); - array_arguments_non_first(f, tree, is_multiline); + function_arguments_non_first(f, tree, is_multiline); } SyntaxKind::NamedArguments => named_arguments(f, tree, is_multiline), _ => unreachable!(), diff --git a/src/lib.rs b/src/lib.rs index fb10835..c840f07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,16 @@ -//pub use self::printing::pretty_print; -//pub use self::formatting::format; +use moparse::{SyntaxEvent, Token}; + +use self::printing::print; +use self::tree::build_tree; +use self::formatting::format; + +pub fn pretty_print(tokens: Vec, comments: Vec, events: Vec) -> String { + let tree = build_tree(tokens, events); + let markers = format(tree, comments); + print(markers) +} mod formatting; mod markers; -//mod printing; +mod printing; mod tree; diff --git a/src/main.rs b/src/main.rs index 1fd5b44..b375268 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use mofmt::{format, pretty_print}; -use moparse::{lex, parse, SyntaxKind}; +use mofmt::pretty_print; +use moparse::{parse, SyntaxKind}; use std::path::{Path, PathBuf}; use std::{env, fs}; @@ -23,32 +23,15 @@ fn format_files(args: &[String]) { .for_each(|mut v| files.append(&mut v)); files.iter().for_each(|p| { let contents = read_file(p); - let tokens = lex(&contents); - if tokens.error_count() > 0 { - let messages: Vec = tokens - .errors() - .map(|e| { - format!( - "{}:{}:{}: {}", - p.display(), - e.start.line, - e.start.col, - e.text - ) - }) - .collect(); - panic!("Lexical errors detected:\n{}", messages.join("\n")); - } - let events = parse(&tokens, SyntaxKind::StoredDefinition); - let (markers, errors) = format(&tokens, &events); - if errors.len() > 0 { - let messages: Vec = errors + let parsed = parse(&contents, SyntaxKind::Expression); + if parsed.errors.len() > 0 { + let messages: Vec = parsed.errors .iter() .map(|e| format!("{}:{}", p.display(), e)) .collect(); panic!("Syntax errors detected:\n{}", messages.join("\n")); } - let output = pretty_print(&tokens, markers); + let output = pretty_print(parsed.tokens, parsed.comments, parsed.events); write_file(p, output); }); } diff --git a/src/printing.rs b/src/printing.rs index 0611ec1..0c170ca 100644 --- a/src/printing.rs +++ b/src/printing.rs @@ -1,12 +1,10 @@ -use moparse::TokenCollection; - use crate::markers::Marker; -pub fn pretty_print(tokens: &TokenCollection, markers: Vec) -> String { +pub fn print(markers: Vec) -> String { let mut printer = Printer::new(); let formatted: Vec = markers .into_iter() - .filter_map(|m| printer.print_marker(m, tokens)) + .filter_map(|m| printer.print_marker(m)) .collect(); formatted.join("") } @@ -20,7 +18,7 @@ impl Printer { Printer { indent: 0 } } - fn print_marker(&mut self, m: Marker, tokens: &TokenCollection) -> Option { + fn print_marker(&mut self, m: Marker) -> Option { const INDENT: &str = " "; match m { Marker::Space => Some(String::from(" ")), @@ -32,7 +30,7 @@ impl Printer { self.indent -= 1; None } - Marker::Token(i) | Marker::Comment(i) => Some(tokens.get_item(i).unwrap().text.clone()), + Marker::Token(txt) => Some(txt), _ => { let mut out = String::from("\n"); if m == Marker::Blank { diff --git a/src/tree.rs b/src/tree.rs index 992e3a6..34fac33 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -72,7 +72,7 @@ impl Tree { pub fn is_multiline(&self) -> bool { let first = self.start(); let last = self.end(); - first.start.line > last.end.line + first.start.line < last.end.line } } From 912410b65d4ba2a986a38bb3dc09848b11aa3773 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Fri, 2 Feb 2024 16:45:39 +0100 Subject: [PATCH 35/67] Finish equation section formatting --- Cargo.toml | 2 +- src/formatting.rs | 432 ++++++++++++++++++++++++++++++++++++++++++++-- src/main.rs | 2 +- 3 files changed, 423 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4099339..11f763c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.4-rc1" +moparse = "0.1.4-rc2" diff --git a/src/formatting.rs b/src/formatting.rs index 0cd9935..03a0e9e 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,4 +1,4 @@ -use std::{iter::Peekable, vec::IntoIter}; +use std::{collections::hash_map::RandomState, iter::Peekable, vec::IntoIter}; use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; @@ -6,6 +6,20 @@ use moparse::*; pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { + SyntaxKind::EquationSection => equation_section(&mut f, tree), + SyntaxKind::AlgorithmSection => algorithm_section(&mut f, tree), + SyntaxKind::Equation => equation(&mut f, tree), + SyntaxKind::Statement => statement(&mut f, tree), + SyntaxKind::IfEquation => if_equation(&mut f, tree), + SyntaxKind::IfStatement => if_statement(&mut f, tree), + SyntaxKind::ForEquation => for_equation(&mut f, tree), + SyntaxKind::ForStatement => for_statement(&mut f, tree), + SyntaxKind::ForIndices => for_indices(&mut f, tree), + SyntaxKind::ForIndex => for_index(&mut f, tree), + SyntaxKind::WhileStatement => while_statement(&mut f, tree), + SyntaxKind::WhenEquation => when_equation(&mut f, tree), + SyntaxKind::WhenStatement => when_statement(&mut f, tree), + SyntaxKind::ConnectEquation => connect_equation(&mut f, tree), SyntaxKind::Expression => expression(&mut f, tree), _ => (), } @@ -38,25 +52,34 @@ impl Formatter { } fn handle_break(&mut self, tok: &Token, allow_blanks: bool) { + let section_opening = + [ModelicaToken::Equation, ModelicaToken::Algorithm].contains(&self.prev_tok); let (inlines, comments) = self.comments_before(tok); for comment in inlines { self.markers.push(Marker::Space); self.markers.push(Marker::Token(comment.text)); } + if section_opening { + self.markers.push(Marker::Blank); + } let mut line = self.prev_line; for comment in comments { - if comment.start.line - line > 1 { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Break); + if !section_opening && line != self.prev_line { + if comment.start.line - line > 1 { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } } self.markers.push(Marker::Token(comment.text)); line = comment.end.line; } - if tok.start.line - line > 1 && allow_blanks { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Break); + if !(section_opening && line == self.prev_line) { + if tok.start.line - line > 1 && allow_blanks { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } } } @@ -86,7 +109,391 @@ impl Formatter { fn class_modification(f: &mut Formatter, tree: Tree) {} -fn for_indices(f: &mut Formatter, tree: Tree) {} +fn equation_section(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => { + f.handle_break(tree.start(), true); + equation(f, tree); + } + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::Initial { + f.markers.push(Marker::Space); + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn algorithm_section(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => { + f.handle_break(tree.start(), true); + statement(f, tree); + } + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::Initial { + f.markers.push(Marker::Space); + } else if kind == ModelicaToken::Algorithm { + f.markers.push(Marker::Blank); + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn equation(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::SimpleExpression => simple_expression(f, tree), + SyntaxKind::Expression => expression(f, tree), + SyntaxKind::IfEquation => if_equation(f, tree), + SyntaxKind::ForEquation => for_equation(f, tree), + SyntaxKind::ConnectEquation => connect_equation(f, tree), + SyntaxKind::WhenEquation => when_equation(f, tree), + SyntaxKind::ComponentReference => component_reference(f, tree), + SyntaxKind::FunctionCallArgs => function_call_args(f, tree), + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn statement(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ComponentReference => component_reference(f, tree), + SyntaxKind::Expression => expression(f, tree), + SyntaxKind::FunctionCallArgs => function_call_args(f, tree), + SyntaxKind::OutputExpressionList => { + let is_multiline = f.prev_line < tree.start().start.line || tree.is_multiline(); + if is_multiline { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + } + output_expression_list(f, tree, is_multiline); + if is_multiline { + f.markers.push(Marker::Dedent); + } + } + SyntaxKind::IfStatement => if_statement(f, tree), + SyntaxKind::ForStatement => for_statement(f, tree), + SyntaxKind::WhileStatement => while_statement(f, tree), + SyntaxKind::WhenStatement => when_statement(f, tree), + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Assign { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::Assign { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn if_equation(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.markers.push(Marker::Space); + expression(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Equation => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + equation(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::If && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if [ + ModelicaToken::ElseIf, + ModelicaToken::Else, + ModelicaToken::End, + ] + .contains(&tok.kind) + { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn if_statement(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.markers.push(Marker::Space); + expression(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Statement => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + statement(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::If && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if [ + ModelicaToken::ElseIf, + ModelicaToken::Else, + ModelicaToken::End, + ] + .contains(&tok.kind) + { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn for_equation(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ForIndices => { + f.markers.push(Marker::Space); + for_indices(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Equation => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + equation(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::For && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if tok.kind == ModelicaToken::End { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn for_statement(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ForIndices => { + f.markers.push(Marker::Space); + for_indices(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Statement => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + statement(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::For && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if tok.kind == ModelicaToken::End { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn for_indices(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => for_index(f, tree), + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn for_index(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => expression(f, tree), + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::In { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::In { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn while_statement(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.markers.push(Marker::Space); + expression(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Statement => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + statement(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::While && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if tok.kind == ModelicaToken::End { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn when_equation(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.markers.push(Marker::Space); + expression(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Equation => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + equation(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::When && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if tok.kind == ModelicaToken::ElseWhen || tok.kind == ModelicaToken::End { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn when_statement(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Expression => { + f.markers.push(Marker::Space); + expression(f, tree); + f.markers.push(Marker::Space); + } + SyntaxKind::Statement => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + statement(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + if tok.kind == ModelicaToken::When && f.prev_tok == ModelicaToken::End { + f.markers.push(Marker::Space); + } else if tok.kind == ModelicaToken::ElseWhen || tok.kind == ModelicaToken::End { + f.handle_break(&tok, false); + } + f.handle_token(tok); + } + } + } +} + +fn connect_equation(f: &mut Formatter, tree: Tree) { + let is_multiline = tree.is_multiline(); + f.markers.push(Marker::Indent); + for (idx, child) in tree.children.into_iter().enumerate() { + match child { + Child::Tree(tree) => { + if idx == 2 { + if is_multiline { + f.handle_break(tree.start(), false); + } + } else { + f.break_or_space(is_multiline, tree.start()); + } + component_reference(f, tree); + } + Child::Token(tok) => f.handle_token(tok), + } + } + f.markers.push(Marker::Dedent); +} fn expression(f: &mut Formatter, tree: Tree) { let is_multiline = tree.is_multiline(); @@ -603,8 +1010,11 @@ fn output_expression_list(f: &mut Formatter, tree: Tree, is_multiline: bool) { match child { Child::Tree(t) => expression(f, t), Child::Token(tok) => { + if f.prev_tok == ModelicaToken::Comma { + f.break_or_space(is_multiline, &tok); + } f.handle_token(tok); - if let Child::Tree(next_tree) = children.peek().unwrap() { + if let Some(Child::Tree(next_tree)) = children.peek() { f.break_or_space(is_multiline, next_tree.start()); } } diff --git a/src/main.rs b/src/main.rs index b375268..bec6808 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ fn format_files(args: &[String]) { .for_each(|mut v| files.append(&mut v)); files.iter().for_each(|p| { let contents = read_file(p); - let parsed = parse(&contents, SyntaxKind::Expression); + let parsed = parse(&contents, SyntaxKind::EquationSection); if parsed.errors.len() > 0 { let messages: Vec = parsed.errors .iter() From 93d6faf38b5924920d595d7eab9d906a202b2290 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 13:48:08 +0100 Subject: [PATCH 36/67] Complete formating of Modification section --- src/formatting.rs | 223 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) diff --git a/src/formatting.rs b/src/formatting.rs index 03a0e9e..780cabf 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -6,6 +6,16 @@ use moparse::*; pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { + SyntaxKind::Argument => argument(&mut f, tree), + SyntaxKind::ElementModificationOrReplaceable => { + element_modification_or_replaceable(&mut f, tree) + } + SyntaxKind::ElementModification => element_modification(&mut f, tree), + SyntaxKind::ElementRedeclaration => element_redeclaration(&mut f, tree), + SyntaxKind::ElementReplaceable => element_replaceable(&mut f, tree), + SyntaxKind::ComponentClause1 => component_clause1(&mut f, tree), + SyntaxKind::ComponentDeclaration1 => component_declaration1(&mut f, tree), + SyntaxKind::ShortClassDefinition => short_class_definition(&mut f, tree), SyntaxKind::EquationSection => equation_section(&mut f, tree), SyntaxKind::AlgorithmSection => algorithm_section(&mut f, tree), SyntaxKind::Equation => equation(&mut f, tree), @@ -107,7 +117,218 @@ impl Formatter { } } -fn class_modification(f: &mut Formatter, tree: Tree) {} +fn class_prefixes(f: &mut Formatter, tree: Tree) {} + +fn short_class_specifier(f: &mut Formatter, tree: Tree) {} + +fn type_prefix(f: &mut Formatter, tree: Tree) {} + +fn declaration(f: &mut Formatter, tree: Tree) {} + +fn constraining_clause(f: &mut Formatter, tree: Tree) {} + +fn modification(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ClassModification => class_modification(f, tree), + SyntaxKind::ModificationExpression => modification_expression(f, tree), + _ => unreachable!(), + } + Child::Token(tok) => { + f.markers.push(Marker::Space); + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn modification_expression(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => expression(f, tree), + Child::Token(tok) => f.handle_token(tok), + } + } +} + +fn class_modification(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + let is_multiline = tree.is_multiline(); + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => argument_list(f, t, is_multiline), + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::LParen && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn argument_list(f: &mut Formatter, tree: Tree, is_multiline: bool) { + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => argument(f, t), + Child::Token(tok) => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + } + } +} + +fn argument(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::ElementModificationOrReplaceable => { + element_modification_or_replaceable(f, tree) + } + SyntaxKind::ElementRedeclaration => element_redeclaration(f, tree), + _ => unreachable!(), + } + } + } +} + +fn element_modification_or_replaceable(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ElementModification => element_modification(f, tree), + SyntaxKind::ElementReplaceable => element_replaceable(f, tree), + _ => unreachable!(), + }, + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn element_modification(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::Name => name(f, tree), + SyntaxKind::Modification => modification(f, tree), + SyntaxKind::DescriptionString => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description_string(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + } + } +} + +fn element_redeclaration(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ShortClassDefinition => short_class_definition(f, tree), + SyntaxKind::ComponentClause1 => component_clause1(f, tree), + SyntaxKind::ConstrainingClause => element_replaceable(f, tree), + _ => unreachable!(), + }, + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn element_replaceable(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ShortClassDefinition => short_class_definition(f, tree), + SyntaxKind::ComponentClause1 => component_clause1(f, tree), + SyntaxKind::ConstrainingClause => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + constraining_clause(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn component_clause1(f: &mut Formatter, tree: Tree) { + let children_count = tree.len(); + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::TypePrefix => type_prefix(f, tree), + SyntaxKind::TypeSpecifier => { + if children_count > 2 { + f.markers.push(Marker::Space); + } + type_specifier(f, tree); + } + SyntaxKind::ComponentDeclaration1 => { + f.markers.push(Marker::Space); + component_declaration1(f, tree); + } + _ => unreachable!(), + } + } + } +} + +fn component_declaration1(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::Declaration => declaration(f, tree), + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + } + } +} + +fn short_class_definition(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::ClassPrefixes => class_prefixes(f, tree), + SyntaxKind::ShortClassSpecifier => { + f.markers.push(Marker::Space); + short_class_specifier(f, tree); + } + _ => unreachable!(), + } + } + } +} fn equation_section(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Indent); From cc041970bd3dee8840b3aa25eb63a375c523d3ad Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 13:48:24 +0100 Subject: [PATCH 37/67] Complete formatting of Component Clause section --- src/formatting.rs | 124 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 7 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 780cabf..2eee2a0 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,11 +1,25 @@ -use std::{collections::hash_map::RandomState, iter::Peekable, vec::IntoIter}; +use std::{iter::Peekable, vec::IntoIter}; -use crate::{markers::Marker, tree::Child, tree::Tree}; +use crate::{ + markers::Marker, + tree::Tree, + tree::Child, +}; use moparse::*; pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { + SyntaxKind::ComponentClause => component_clause(&mut f, tree), + SyntaxKind::TypePrefix => type_prefix(&mut f, tree), + SyntaxKind::ComponentList => component_list(&mut f, tree), + SyntaxKind::ComponentDeclaration => component_declaration(&mut f, tree), + SyntaxKind::ConditionAttribute => condition_attribute(&mut f, tree), + SyntaxKind::Declaration => declaration(&mut f, tree), + SyntaxKind::Modification => modification(&mut f, tree), + SyntaxKind::ModificationExpression => modification_expression(&mut f, tree), + SyntaxKind::ClassModification => class_modification(&mut f, tree), + SyntaxKind::ArgumentList => argument_list(&mut f, tree, false), SyntaxKind::Argument => argument(&mut f, tree), SyntaxKind::ElementModificationOrReplaceable => { element_modification_or_replaceable(&mut f, tree) @@ -121,11 +135,104 @@ fn class_prefixes(f: &mut Formatter, tree: Tree) {} fn short_class_specifier(f: &mut Formatter, tree: Tree) {} -fn type_prefix(f: &mut Formatter, tree: Tree) {} +fn constraining_clause(f: &mut Formatter, tree: Tree) {} -fn declaration(f: &mut Formatter, tree: Tree) {} +fn component_clause(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::TypePrefix => { + let is_empty = tree.len() == 0; + type_prefix(f, tree); + if !is_empty { + f.markers.push(Marker::Space); + } + } + SyntaxKind::TypeSpecifier => type_specifier(f, tree), + SyntaxKind::ArraySubscripts => array_subscripts(f, tree), + SyntaxKind::ComponentList => component_list(f, tree), + _ => unreachable!(), + } + } + } +} -fn constraining_clause(f: &mut Formatter, tree: Tree) {} +fn type_prefix(f: &mut Formatter, tree: Tree) { + for (idx, child) in tree.children.into_iter().enumerate() { + if let Child::Token(tok) = child { + if idx > 0 { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + } + } +} + +fn component_list(f: &mut Formatter, tree: Tree) { + let mut is_multiline = tree.is_multiline(); + let children_count = tree.len(); + if is_multiline && children_count > 1 { + f.markers.push(Marker::Indent); + } + for child in tree.children { + match child { + Child::Tree(tree) => { + f.break_or_space(is_multiline && children_count > 1, tree.start()); + component_declaration(f, tree); + } + Child::Token(tok) => f.handle_token(tok), + } + } + if is_multiline && children_count > 1 { + f.markers.push(Marker::Dedent); + } +} + +fn component_declaration(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::Declaration => declaration(f, tree), + SyntaxKind::ConditionAttribute => { + f.markers.push(Marker::Space); + condition_attribute(f, tree); + } + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + } + } +} + +fn condition_attribute(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => expression(f, tree), + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn declaration(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ArraySubscripts => array_subscripts(f, tree), + SyntaxKind::Modification => modification(f, tree), + _ => unreachable!(), + }, + Child::Token(tok) => f.handle_token(tok), + } + } +} fn modification(f: &mut Formatter, tree: Tree) { for child in tree.children { @@ -134,7 +241,7 @@ fn modification(f: &mut Formatter, tree: Tree) { SyntaxKind::ClassModification => class_modification(f, tree), SyntaxKind::ModificationExpression => modification_expression(f, tree), _ => unreachable!(), - } + }, Child::Token(tok) => { f.markers.push(Marker::Space); f.handle_token(tok); @@ -174,7 +281,10 @@ fn class_modification(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } -fn argument_list(f: &mut Formatter, tree: Tree, is_multiline: bool) { +fn argument_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { + if !is_multiline { + is_multiline = tree.is_multiline(); + } let mut children = tree.children.into_iter().peekable(); while let Some(child) = children.next() { match child { From b03249098be2591be4a38c73924b4b9649dcdd2b Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 14:10:07 +0100 Subject: [PATCH 38/67] Complete formatting of Extends section --- src/formatting.rs | 95 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/src/formatting.rs b/src/formatting.rs index 2eee2a0..eb2656c 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -10,6 +10,11 @@ use moparse::*; pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { + SyntaxKind::ExtendsClause => extends_clause(&mut f, tree), + SyntaxKind::ConstrainingClause => constraining_clause(&mut f, tree), + SyntaxKind::ClassOrInheritanceModification => class_or_inheritance_modification(&mut f, tree), + SyntaxKind::ArgumentOrInheritanceModificationList => argument_or_inheritance_modification_list(&mut f, tree, false), + SyntaxKind::InheritanceModification => inheritance_modification(&mut f, tree), SyntaxKind::ComponentClause => component_clause(&mut f, tree), SyntaxKind::TypePrefix => type_prefix(&mut f, tree), SyntaxKind::ComponentList => component_list(&mut f, tree), @@ -135,7 +140,95 @@ fn class_prefixes(f: &mut Formatter, tree: Tree) {} fn short_class_specifier(f: &mut Formatter, tree: Tree) {} -fn constraining_clause(f: &mut Formatter, tree: Tree) {} +fn extends_clause(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::TypeSpecifier => type_specifier(f, tree), + SyntaxKind::ClassOrInheritanceModification => class_or_inheritance_modification(f, tree), + SyntaxKind::AnnotationClause => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + annotation_clause(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn constraining_clause(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::TypeSpecifier => type_specifier(f, tree), + SyntaxKind::ClassModification => class_modification(f, tree), + _ => unreachable!(), + } + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn class_or_inheritance_modification(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + let is_multiline = tree.is_multiline() && tree.len() > 2; + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => argument_or_inheritance_modification_list(f, t, is_multiline), + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::LParen && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn argument_or_inheritance_modification_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { + if !is_multiline { + is_multiline = tree.is_multiline(); + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Argument => argument(f, tree), + SyntaxKind::InheritanceModification => inheritance_modification(f, tree), + _ => unreachable!(), + } + Child::Token(tok) => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + } + } +} + +fn inheritance_modification(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } +} fn component_clause(f: &mut Formatter, tree: Tree) { for child in tree.children { From 9abefe5c4038dedff399f31945097caabd1d6901 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 15:31:45 +0100 Subject: [PATCH 39/67] Finish all formatting rules --- src/formatting.rs | 497 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 478 insertions(+), 19 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index eb2656c..615c06e 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,19 +1,36 @@ use std::{iter::Peekable, vec::IntoIter}; -use crate::{ - markers::Marker, - tree::Tree, - tree::Child, -}; +use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { + SyntaxKind::StoredDefinition => stored_definition(&mut f, tree), + SyntaxKind::ClassDefinition => class_definition(&mut f, tree), + SyntaxKind::ClassPrefixes => class_prefixes(&mut f, tree), + SyntaxKind::ClassSpecifier => class_specifier(&mut f, tree), + SyntaxKind::LongClassSpecifier => long_class_specifier(&mut f, tree), + SyntaxKind::ShortClassSpecifier => short_class_specifier(&mut f, tree), + SyntaxKind::DerClassSpecifier => der_class_specifier(&mut f, tree), + SyntaxKind::BasePrefix => base_prefix(&mut f, tree), + SyntaxKind::EnumList => enum_list(&mut f, tree, false), + SyntaxKind::EnumerationLiteral => enumeration_literal(&mut f, tree), + SyntaxKind::Composition => composition(&mut f, tree), + SyntaxKind::LanguageSpecification => language_specification(&mut f, tree), + SyntaxKind::ExternalFunctionCall => external_function_call(&mut f, tree), + SyntaxKind::ElementList => element_list(&mut f, tree), + SyntaxKind::Element => element(&mut f, tree), + SyntaxKind::ImportClause => import_clause(&mut f, tree), + SyntaxKind::ImportList => import_list(&mut f, tree, false), SyntaxKind::ExtendsClause => extends_clause(&mut f, tree), SyntaxKind::ConstrainingClause => constraining_clause(&mut f, tree), - SyntaxKind::ClassOrInheritanceModification => class_or_inheritance_modification(&mut f, tree), - SyntaxKind::ArgumentOrInheritanceModificationList => argument_or_inheritance_modification_list(&mut f, tree, false), + SyntaxKind::ClassOrInheritanceModification => { + class_or_inheritance_modification(&mut f, tree) + } + SyntaxKind::ArgumentOrInheritanceModificationList => { + argument_or_inheritance_modification_list(&mut f, tree, false) + } SyntaxKind::InheritanceModification => inheritance_modification(&mut f, tree), SyntaxKind::ComponentClause => component_clause(&mut f, tree), SyntaxKind::TypePrefix => type_prefix(&mut f, tree), @@ -81,14 +98,22 @@ impl Formatter { } fn handle_break(&mut self, tok: &Token, allow_blanks: bool) { - let section_opening = - [ModelicaToken::Equation, ModelicaToken::Algorithm].contains(&self.prev_tok); + let section_opening = [ + ModelicaToken::Equation, + ModelicaToken::Algorithm, + ModelicaToken::Protected, + ModelicaToken::Public, + ] + .contains(&self.prev_tok); let (inlines, comments) = self.comments_before(tok); for comment in inlines { self.markers.push(Marker::Space); self.markers.push(Marker::Token(comment.text)); } - if section_opening { + if section_opening + || (self.prev_tok == ModelicaToken::Semicolon && tok.kind == ModelicaToken::Annotation) + || (self.prev_tok == ModelicaToken::Semicolon && tok.kind == ModelicaToken::End) + { self.markers.push(Marker::Blank); } let mut line = self.prev_line; @@ -136,16 +161,448 @@ impl Formatter { } } -fn class_prefixes(f: &mut Formatter, tree: Tree) {} +fn stored_definition(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Name => name(f, tree), + SyntaxKind::ClassDefinition => { + f.handle_break(tree.start(), true); + class_definition(f, tree); + } + _ => unreachable!(), + } + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::Final || kind == ModelicaToken::Within { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn class_definition(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ClassSpecifier => { + f.markers.push(Marker::Space); + class_specifier(f, tree); + } + SyntaxKind::ClassPrefixes => class_prefixes(f, tree), + _ => unreachable!(), + } + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn class_prefixes(f: &mut Formatter, tree: Tree) { + for (idx, child) in tree.children.into_iter().enumerate() { + if let Child::Token(tok) = child { + if idx > 0 { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + } + } +} + +fn class_specifier(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Tree(tree) = child { + match tree.kind { + SyntaxKind::LongClassSpecifier => long_class_specifier(f, tree), + SyntaxKind::ShortClassSpecifier => short_class_specifier(f, tree), + SyntaxKind::DerClassSpecifier => der_class_specifier(f, tree), + _ => unreachable!(), + } + } + } +} + +fn long_class_specifier(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::DescriptionString => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + SyntaxKind::ClassModification => class_modification(f, tree), + SyntaxKind::Composition => { + f.markers.push(Marker::Blank); + composition(f, tree); + } + _ => unreachable!(), + } + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::End { + f.handle_break(&tok, true); + } + f.handle_token(tok); + if kind == ModelicaToken::End || kind == ModelicaToken::Extends { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn short_class_specifier(f: &mut Formatter, tree: Tree) { + let mut is_multiline = false; + let mut children = tree.children.iter(); + while let Some(child) = children.next() { + if let Child::Token(token) = child { + if token.kind == ModelicaToken::LParen { + while let Some(child) = children.next() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::RParen { + is_multiline = tok.start.line > token.start.line; + } + } + } + } + } + } + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::BasePrefix => { + let is_empty = tree.len() == 0; + base_prefix(f, tree); + if !is_empty { + f.markers.push(Marker::Space); + } + } + SyntaxKind::TypeSpecifier => type_specifier(f, tree), + SyntaxKind::ArraySubscripts => array_subscripts(f, tree), + SyntaxKind::ClassModification => class_modification(f, tree), + SyntaxKind::EnumList => { + if is_multiline { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + } + enum_list(f, tree, is_multiline); + if is_multiline { + f.markers.push(Marker::Dedent); + } + } + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn der_class_specifier(f: &mut Formatter, tree: Tree) { + let mut is_multiline = false; + f.markers.push(Marker::Indent); + let mut children = tree.children.iter(); + while let Some(child) = children.next() { + if let Child::Token(token) = child { + if token.kind == ModelicaToken::LParen { + while let Some(child) = children.next() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::RParen { + is_multiline = tok.start.line > token.start.line; + } + } + } + } + } + } + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::TypeSpecifier => { + if is_multiline { + f.handle_break(tree.start(), false); + } + type_specifier(f, tree); + } + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + } + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } else if kind == ModelicaToken::Identifier && f.prev_tok == ModelicaToken::Comma { + f.break_or_space(is_multiline, &tok) + } + f.handle_token(tok); + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn base_prefix(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn enum_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { + if !is_multiline { + is_multiline = tree.is_multiline(); + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(t) => enumeration_literal(f, t), + Child::Token(tok) => { + f.handle_token(tok); + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.break_or_space(is_multiline, next_tree.start()); + } + } + } + } +} + +fn enumeration_literal(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + Child::Token(tok) => f.handle_token(tok), + } + } +} + +fn composition(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ElementList => element_list(f, tree), + SyntaxKind::EquationSection => equation_section(f, tree), + SyntaxKind::AlgorithmSection => algorithm_section(f, tree), + SyntaxKind::LanguageSpecification => language_specification(f, tree), + SyntaxKind::ExternalFunctionCall => external_function_call(f, tree), + SyntaxKind::AnnotationClause => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), f.prev_tok == ModelicaToken::Semicolon); + annotation_clause(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + f.handle_token(tok); + if kind == ModelicaToken::External { + f.markers.push(Marker::Space); + } + } + } + } +} + +fn language_specification(f: &mut Formatter, tree: Tree) { + for child in tree.children { + if let Child::Token(tok) = child { + f.handle_token(tok); + } + } +} + +fn external_function_call(f: &mut Formatter, tree: Tree) { + let mut is_multiline = false; + f.markers.push(Marker::Indent); + let mut children = tree.children.iter(); + while let Some(child) = children.next() { + if let Child::Token(token) = child { + if token.kind == ModelicaToken::LParen { + while let Some(child) = children.next() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::RParen { + is_multiline = tok.start.line > token.start.line; + } + } + } + } + } + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ComponentReference => component_reference(f, tree), + SyntaxKind::ExpressionList => expression_list(f, tree, is_multiline), + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } else if kind == ModelicaToken::LParen && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + } + } + f.markers.push(Marker::Dedent); +} + +fn element_list(f: &mut Formatter, tree: Tree) { + f.markers.push(Marker::Indent); + for child in tree.children { + match child { + Child::Tree(tree) => { + f.handle_break(tree.start(), true); + element(f, tree); + } + Child::Token(tok) => f.handle_token(tok), + } + } + f.markers.push(Marker::Dedent); +} -fn short_class_specifier(f: &mut Formatter, tree: Tree) {} +fn element(f: &mut Formatter, tree: Tree) { + for child in tree.children { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::ImportClause => import_clause(f, tree), + SyntaxKind::ExtendsClause => extends_clause(f, tree), + SyntaxKind::ClassDefinition => class_definition(f, tree), + SyntaxKind::ComponentClause => component_clause(f, tree), + SyntaxKind::ConstrainingClause => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + constraining_clause(f, tree); + f.markers.push(Marker::Dedent); + } + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } + } + } +} + +fn import_clause(f: &mut Formatter, tree: Tree) { + let mut is_multiline = false; + let mut children = tree.children.iter(); + while let Some(child) = children.next() { + if let Child::Token(token) = child { + if token.kind == ModelicaToken::LCurly { + while let Some(child) = children.next() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::RCurly { + is_multiline = tok.start.line > token.start.line; + } + } + } + } + } + } + let mut children = tree.children.into_iter().peekable(); + while let Some(child) = children.next() { + match child { + Child::Tree(tree) => match tree.kind { + SyntaxKind::Name => name(f, tree), + SyntaxKind::ImportList => import_list(f, tree, is_multiline), + SyntaxKind::Description => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), false); + description(f, tree); + f.markers.push(Marker::Dedent); + } + _ => unreachable!(), + }, + Child::Token(tok) => { + let kind = tok.kind; + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } + f.handle_token(tok); + if kind == ModelicaToken::Import || kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } else if kind == ModelicaToken::LCurly && is_multiline { + if let Child::Tree(next_tree) = children.peek().unwrap() { + f.handle_break(next_tree.start(), false); + } + } + } + } + } +} + +fn import_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { + if !is_multiline { + is_multiline = tree.is_multiline(); + } + for (idx, child) in tree.children.into_iter().enumerate() { + if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::Identifier && idx > 1 { + f.break_or_space(is_multiline, &tok); + } + f.handle_token(tok); + } + } +} fn extends_clause(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::TypeSpecifier => type_specifier(f, tree), - SyntaxKind::ClassOrInheritanceModification => class_or_inheritance_modification(f, tree), + SyntaxKind::ClassOrInheritanceModification => { + class_or_inheritance_modification(f, tree) + } SyntaxKind::AnnotationClause => { f.markers.push(Marker::Indent); f.handle_break(tree.start(), false); @@ -153,7 +610,7 @@ fn extends_clause(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } _ => unreachable!(), - } + }, Child::Token(tok) => { f.handle_token(tok); f.markers.push(Marker::Space); @@ -169,7 +626,7 @@ fn constraining_clause(f: &mut Formatter, tree: Tree) { SyntaxKind::TypeSpecifier => type_specifier(f, tree), SyntaxKind::ClassModification => class_modification(f, tree), _ => unreachable!(), - } + }, Child::Token(tok) => { f.handle_token(tok); f.markers.push(Marker::Space); @@ -199,7 +656,11 @@ fn class_or_inheritance_modification(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } -fn argument_or_inheritance_modification_list(f: &mut Formatter, tree: Tree, mut is_multiline: bool) { +fn argument_or_inheritance_modification_list( + f: &mut Formatter, + tree: Tree, + mut is_multiline: bool, +) { if !is_multiline { is_multiline = tree.is_multiline(); } @@ -210,7 +671,7 @@ fn argument_or_inheritance_modification_list(f: &mut Formatter, tree: Tree, mut SyntaxKind::Argument => argument(f, tree), SyntaxKind::InheritanceModification => inheritance_modification(f, tree), _ => unreachable!(), - } + }, Child::Token(tok) => { f.handle_token(tok); if let Child::Tree(next_tree) = children.peek().unwrap() { @@ -566,8 +1027,6 @@ fn algorithm_section(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::Initial { f.markers.push(Marker::Space); - } else if kind == ModelicaToken::Algorithm { - f.markers.push(Marker::Blank); } } } From b843fb2a688041c6ebfc525550e0a0700a33d7c0 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 15:39:13 +0100 Subject: [PATCH 40/67] Fix description string formatting in long class spec --- src/formatting.rs | 19 ++++++++++++------- src/main.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 615c06e..b03a3db 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -167,13 +167,18 @@ fn stored_definition(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::Name => name(f, tree), SyntaxKind::ClassDefinition => { - f.handle_break(tree.start(), true); + if f.prev_tok == ModelicaToken::Semicolon { + f.handle_break(tree.start(), true); + } class_definition(f, tree); } _ => unreachable!(), - } + }, Child::Token(tok) => { let kind = tok.kind; + if kind == ModelicaToken::Final { + f.handle_break(&tok, true); + } f.handle_token(tok); if kind == ModelicaToken::Final || kind == ModelicaToken::Within { f.markers.push(Marker::Space); @@ -193,7 +198,7 @@ fn class_definition(f: &mut Formatter, tree: Tree) { } SyntaxKind::ClassPrefixes => class_prefixes(f, tree), _ => unreachable!(), - } + }, Child::Token(tok) => { f.handle_token(tok); f.markers.push(Marker::Space); @@ -233,7 +238,7 @@ fn long_class_specifier(f: &mut Formatter, tree: Tree) { SyntaxKind::DescriptionString => { f.markers.push(Marker::Indent); f.handle_break(tree.start(), false); - description(f, tree); + description_string(f, tree); f.markers.push(Marker::Dedent); } SyntaxKind::ClassModification => class_modification(f, tree), @@ -242,7 +247,7 @@ fn long_class_specifier(f: &mut Formatter, tree: Tree) { composition(f, tree); } _ => unreachable!(), - } + }, Child::Token(tok) => { let kind = tok.kind; if kind == ModelicaToken::End { @@ -303,7 +308,7 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } _ => unreachable!(), - } + }, Child::Token(tok) => { let kind = tok.kind; if kind == ModelicaToken::Equal { @@ -351,7 +356,7 @@ fn der_class_specifier(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } _ => unreachable!(), - } + }, Child::Token(tok) => { let kind = tok.kind; if kind == ModelicaToken::Equal { diff --git a/src/main.rs b/src/main.rs index bec6808..ae232b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ fn format_files(args: &[String]) { .for_each(|mut v| files.append(&mut v)); files.iter().for_each(|p| { let contents = read_file(p); - let parsed = parse(&contents, SyntaxKind::EquationSection); + let parsed = parse(&contents, SyntaxKind::StoredDefinition); if parsed.errors.len() > 0 { let messages: Vec = parsed.errors .iter() From 5e1705bf672a825dce75c7750180f571c2e9c4eb Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 19:05:29 +0100 Subject: [PATCH 41/67] Improvement in blanks and comment handling --- src/formatting.rs | 181 +++++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 68 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index b03a3db..b056b7e 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -3,6 +3,12 @@ use std::{iter::Peekable, vec::IntoIter}; use crate::{markers::Marker, tree::Child, tree::Tree}; use moparse::*; +enum Blank { + Required, + Legal, + Illegal, +} + pub fn format(tree: Tree, comments: Vec) -> Vec { let mut f = Formatter::new(comments); match tree.kind { @@ -91,34 +97,32 @@ impl Formatter { fn break_or_space(&mut self, is_multiline: bool, tok: &Token) { if is_multiline { - self.handle_break(tok, false); + self.handle_break(tok, Blank::Illegal); } else { self.markers.push(Marker::Space); } } - fn handle_break(&mut self, tok: &Token, allow_blanks: bool) { - let section_opening = [ - ModelicaToken::Equation, - ModelicaToken::Algorithm, - ModelicaToken::Protected, - ModelicaToken::Public, - ] - .contains(&self.prev_tok); + fn handle_break(&mut self, tok: &Token, blanks: Blank) { let (inlines, comments) = self.comments_before(tok); for comment in inlines { self.markers.push(Marker::Space); self.markers.push(Marker::Token(comment.text)); } - if section_opening - || (self.prev_tok == ModelicaToken::Semicolon && tok.kind == ModelicaToken::Annotation) - || (self.prev_tok == ModelicaToken::Semicolon && tok.kind == ModelicaToken::End) - { + if let Blank::Required = blanks { self.markers.push(Marker::Blank); } let mut line = self.prev_line; for comment in comments { - if !section_opening && line != self.prev_line { + if let Blank::Required = blanks { + if line > self.prev_line { + if comment.start.line - line > 1 { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } + } + } else { if comment.start.line - line > 1 { self.markers.push(Marker::Blank); } else { @@ -128,12 +132,22 @@ impl Formatter { self.markers.push(Marker::Token(comment.text)); line = comment.end.line; } - if !(section_opening && line == self.prev_line) { - if tok.start.line - line > 1 && allow_blanks { + if let Blank::Legal = blanks { + if tok.start.line - line > 1 { self.markers.push(Marker::Blank); } else { self.markers.push(Marker::Break); } + } else if let Blank::Illegal = blanks { + self.markers.push(Marker::Break); + } else { + if line > self.prev_line { + if tok.start.line - line > 1 { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); + } + } } } @@ -168,7 +182,7 @@ fn stored_definition(f: &mut Formatter, tree: Tree) { SyntaxKind::Name => name(f, tree), SyntaxKind::ClassDefinition => { if f.prev_tok == ModelicaToken::Semicolon { - f.handle_break(tree.start(), true); + f.handle_break(tree.start(), Blank::Legal); } class_definition(f, tree); } @@ -177,7 +191,7 @@ fn stored_definition(f: &mut Formatter, tree: Tree) { Child::Token(tok) => { let kind = tok.kind; if kind == ModelicaToken::Final { - f.handle_break(&tok, true); + f.handle_break(&tok, Blank::Legal); } f.handle_token(tok); if kind == ModelicaToken::Final || kind == ModelicaToken::Within { @@ -237,7 +251,7 @@ fn long_class_specifier(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::DescriptionString => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description_string(f, tree); f.markers.push(Marker::Dedent); } @@ -245,14 +259,12 @@ fn long_class_specifier(f: &mut Formatter, tree: Tree) { SyntaxKind::Composition => { f.markers.push(Marker::Blank); composition(f, tree); + f.markers.push(Marker::Blank); } _ => unreachable!(), }, Child::Token(tok) => { let kind = tok.kind; - if kind == ModelicaToken::End { - f.handle_break(&tok, true); - } f.handle_token(tok); if kind == ModelicaToken::End || kind == ModelicaToken::Extends { f.markers.push(Marker::Space); @@ -294,7 +306,7 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { SyntaxKind::EnumList => { if is_multiline { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); } enum_list(f, tree, is_multiline); if is_multiline { @@ -303,7 +315,7 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { } SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -345,13 +357,13 @@ fn der_class_specifier(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::TypeSpecifier => { if is_multiline { - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); } type_specifier(f, tree); } SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -405,7 +417,7 @@ fn enumeration_literal(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -418,14 +430,23 @@ fn composition(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { Child::Tree(tree) => match tree.kind { - SyntaxKind::ElementList => element_list(f, tree), + SyntaxKind::ElementList => { + element_list(f, tree); + } SyntaxKind::EquationSection => equation_section(f, tree), SyntaxKind::AlgorithmSection => algorithm_section(f, tree), SyntaxKind::LanguageSpecification => language_specification(f, tree), SyntaxKind::ExternalFunctionCall => external_function_call(f, tree), SyntaxKind::AnnotationClause => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), f.prev_tok == ModelicaToken::Semicolon); + f.handle_break( + tree.start(), + if f.prev_tok == ModelicaToken::Semicolon { + Blank::Required + } else { + Blank::Illegal + }, + ); annotation_clause(f, tree); f.markers.push(Marker::Dedent); } @@ -433,6 +454,9 @@ fn composition(f: &mut Formatter, tree: Tree) { }, Child::Token(tok) => { let kind = tok.kind; + if kind == ModelicaToken::Protected || kind == ModelicaToken::Public { + f.handle_break(&tok, Blank::Required); + } f.handle_token(tok); if kind == ModelicaToken::External { f.markers.push(Marker::Space); @@ -485,7 +509,7 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Space); } else if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -496,10 +520,17 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { fn element_list(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Indent); - for child in tree.children { + for (idx, child) in tree.children.into_iter().enumerate() { match child { Child::Tree(tree) => { - f.handle_break(tree.start(), true); + f.handle_break( + tree.start(), + if idx > 1 { + Blank::Legal + } else { + Blank::Illegal + }, + ); element(f, tree); } Child::Token(tok) => f.handle_token(tok), @@ -518,13 +549,13 @@ fn element(f: &mut Formatter, tree: Tree) { SyntaxKind::ComponentClause => component_clause(f, tree), SyntaxKind::ConstrainingClause => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); constraining_clause(f, tree); f.markers.push(Marker::Dedent); } SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -562,7 +593,7 @@ fn import_clause(f: &mut Formatter, tree: Tree) { SyntaxKind::ImportList => import_list(f, tree, is_multiline), SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -578,7 +609,7 @@ fn import_clause(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Space); } else if kind == ModelicaToken::LCurly && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -610,7 +641,7 @@ fn extends_clause(f: &mut Formatter, tree: Tree) { } SyntaxKind::AnnotationClause => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); annotation_clause(f, tree); f.markers.push(Marker::Dedent); } @@ -652,7 +683,7 @@ fn class_or_inheritance_modification(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -758,7 +789,7 @@ fn component_declaration(f: &mut Formatter, tree: Tree) { } SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -831,7 +862,7 @@ fn class_modification(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -896,7 +927,7 @@ fn element_modification(f: &mut Formatter, tree: Tree) { SyntaxKind::Modification => modification(f, tree), SyntaxKind::DescriptionString => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description_string(f, tree); f.markers.push(Marker::Dedent); } @@ -931,7 +962,7 @@ fn element_replaceable(f: &mut Formatter, tree: Tree) { SyntaxKind::ComponentClause1 => component_clause1(f, tree), SyntaxKind::ConstrainingClause => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); constraining_clause(f, tree); f.markers.push(Marker::Dedent); } @@ -974,7 +1005,7 @@ fn component_declaration1(f: &mut Formatter, tree: Tree) { SyntaxKind::Declaration => declaration(f, tree), SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -1004,7 +1035,14 @@ fn equation_section(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { Child::Tree(tree) => { - f.handle_break(tree.start(), true); + f.handle_break( + tree.start(), + if f.prev_tok == ModelicaToken::Equation { + Blank::Required + } else { + Blank::Legal + }, + ); equation(f, tree); } Child::Token(tok) => { @@ -1024,7 +1062,14 @@ fn algorithm_section(f: &mut Formatter, tree: Tree) { for child in tree.children { match child { Child::Tree(tree) => { - f.handle_break(tree.start(), true); + f.handle_break( + tree.start(), + if f.prev_tok == ModelicaToken::Algorithm { + Blank::Required + } else { + Blank::Legal + }, + ); statement(f, tree); } Child::Token(tok) => { @@ -1053,7 +1098,7 @@ fn equation(f: &mut Formatter, tree: Tree) { SyntaxKind::FunctionCallArgs => function_call_args(f, tree), SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -1084,7 +1129,7 @@ fn statement(f: &mut Formatter, tree: Tree) { let is_multiline = f.prev_line < tree.start().start.line || tree.is_multiline(); if is_multiline { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); } output_expression_list(f, tree, is_multiline); if is_multiline { @@ -1097,7 +1142,7 @@ fn statement(f: &mut Formatter, tree: Tree) { SyntaxKind::WhenStatement => when_statement(f, tree), SyntaxKind::Description => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); description(f, tree); f.markers.push(Marker::Dedent); } @@ -1128,7 +1173,7 @@ fn if_equation(f: &mut Formatter, tree: Tree) { } SyntaxKind::Equation => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); equation(f, tree); f.markers.push(Marker::Dedent); } @@ -1144,7 +1189,7 @@ fn if_equation(f: &mut Formatter, tree: Tree) { ] .contains(&tok.kind) { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1163,7 +1208,7 @@ fn if_statement(f: &mut Formatter, tree: Tree) { } SyntaxKind::Statement => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); statement(f, tree); f.markers.push(Marker::Dedent); } @@ -1179,7 +1224,7 @@ fn if_statement(f: &mut Formatter, tree: Tree) { ] .contains(&tok.kind) { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1198,7 +1243,7 @@ fn for_equation(f: &mut Formatter, tree: Tree) { } SyntaxKind::Equation => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); equation(f, tree); f.markers.push(Marker::Dedent); } @@ -1208,7 +1253,7 @@ fn for_equation(f: &mut Formatter, tree: Tree) { if tok.kind == ModelicaToken::For && f.prev_tok == ModelicaToken::End { f.markers.push(Marker::Space); } else if tok.kind == ModelicaToken::End { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1227,7 +1272,7 @@ fn for_statement(f: &mut Formatter, tree: Tree) { } SyntaxKind::Statement => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); statement(f, tree); f.markers.push(Marker::Dedent); } @@ -1237,7 +1282,7 @@ fn for_statement(f: &mut Formatter, tree: Tree) { if tok.kind == ModelicaToken::For && f.prev_tok == ModelicaToken::End { f.markers.push(Marker::Space); } else if tok.kind == ModelicaToken::End { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1286,7 +1331,7 @@ fn while_statement(f: &mut Formatter, tree: Tree) { } SyntaxKind::Statement => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); statement(f, tree); f.markers.push(Marker::Dedent); } @@ -1296,7 +1341,7 @@ fn while_statement(f: &mut Formatter, tree: Tree) { if tok.kind == ModelicaToken::While && f.prev_tok == ModelicaToken::End { f.markers.push(Marker::Space); } else if tok.kind == ModelicaToken::End { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1315,7 +1360,7 @@ fn when_equation(f: &mut Formatter, tree: Tree) { } SyntaxKind::Equation => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); equation(f, tree); f.markers.push(Marker::Dedent); } @@ -1325,7 +1370,7 @@ fn when_equation(f: &mut Formatter, tree: Tree) { if tok.kind == ModelicaToken::When && f.prev_tok == ModelicaToken::End { f.markers.push(Marker::Space); } else if tok.kind == ModelicaToken::ElseWhen || tok.kind == ModelicaToken::End { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1344,7 +1389,7 @@ fn when_statement(f: &mut Formatter, tree: Tree) { } SyntaxKind::Statement => { f.markers.push(Marker::Indent); - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); statement(f, tree); f.markers.push(Marker::Dedent); } @@ -1354,7 +1399,7 @@ fn when_statement(f: &mut Formatter, tree: Tree) { if tok.kind == ModelicaToken::When && f.prev_tok == ModelicaToken::End { f.markers.push(Marker::Space); } else if tok.kind == ModelicaToken::ElseWhen || tok.kind == ModelicaToken::End { - f.handle_break(&tok, false); + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); } @@ -1370,7 +1415,7 @@ fn connect_equation(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => { if idx == 2 { if is_multiline { - f.handle_break(tree.start(), false); + f.handle_break(tree.start(), Blank::Illegal); } } else { f.break_or_space(is_multiline, tree.start()); @@ -1641,7 +1686,7 @@ fn primary(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Indent); if is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -1718,7 +1763,7 @@ fn function_call_args(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -1884,7 +1929,7 @@ fn function_partial_application(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } } @@ -1942,7 +1987,7 @@ fn array_subscripts(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::LBracket && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { - f.handle_break(next_tree.start(), false); + f.handle_break(next_tree.start(), Blank::Illegal); } } else if kind == ModelicaToken::Comma { if let Child::Tree(next_tree) = children.peek().unwrap() { @@ -1971,7 +2016,7 @@ fn description(f: &mut Formatter, tree: Tree) { SyntaxKind::DescriptionString => description_string(f, t), SyntaxKind::AnnotationClause => { if idx > 0 { - f.handle_break(t.start(), false); + f.handle_break(t.start(), Blank::Illegal); } annotation_clause(f, t); } From d0ce12a3c62d9e9ed7b7cb322318fd1268c4293e Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Sun, 4 Feb 2024 21:39:55 +0100 Subject: [PATCH 42/67] Prepare new code sample --- Cargo.toml | 2 +- src/formatting.rs | 80 +++++++++++++++++--------- tests/samples/code-input.mo | 108 ++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 27 deletions(-) create mode 100644 tests/samples/code-input.mo diff --git a/Cargo.toml b/Cargo.toml index 11f763c..4099e6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.4-rc2" +moparse = "0.1.4-rc3" diff --git a/src/formatting.rs b/src/formatting.rs index b056b7e..5756bd7 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -106,7 +106,9 @@ impl Formatter { fn handle_break(&mut self, tok: &Token, blanks: Blank) { let (inlines, comments) = self.comments_before(tok); for comment in inlines { - self.markers.push(Marker::Space); + if self.markers.len() > 0 { + self.markers.push(Marker::Space); + } self.markers.push(Marker::Token(comment.text)); } if let Blank::Required = blanks { @@ -192,6 +194,8 @@ fn stored_definition(f: &mut Formatter, tree: Tree) { let kind = tok.kind; if kind == ModelicaToken::Final { f.handle_break(&tok, Blank::Legal); + } else if kind == ModelicaToken::Within { + f.handle_break(&tok, Blank::Illegal); } f.handle_token(tok); if kind == ModelicaToken::Final || kind == ModelicaToken::Within { @@ -256,15 +260,14 @@ fn long_class_specifier(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } SyntaxKind::ClassModification => class_modification(f, tree), - SyntaxKind::Composition => { - f.markers.push(Marker::Blank); - composition(f, tree); - f.markers.push(Marker::Blank); - } + SyntaxKind::Composition => composition(f, tree), _ => unreachable!(), }, Child::Token(tok) => { let kind = tok.kind; + if kind == ModelicaToken::End { + f.handle_break(&tok, Blank::Required); + } f.handle_token(tok); if kind == ModelicaToken::End || kind == ModelicaToken::Extends { f.markers.push(Marker::Space); @@ -431,10 +434,19 @@ fn composition(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::ElementList => { + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), Blank::Required); element_list(f, tree); + f.markers.push(Marker::Dedent); + } + SyntaxKind::EquationSection => { + f.handle_break(tree.start(), Blank::Required); + equation_section(f, tree); + } + SyntaxKind::AlgorithmSection => { + f.handle_break(tree.start(), Blank::Required); + algorithm_section(f, tree); } - SyntaxKind::EquationSection => equation_section(f, tree), - SyntaxKind::AlgorithmSection => algorithm_section(f, tree), SyntaxKind::LanguageSpecification => language_specification(f, tree), SyntaxKind::ExternalFunctionCall => external_function_call(f, tree), SyntaxKind::AnnotationClause => { @@ -454,7 +466,13 @@ fn composition(f: &mut Formatter, tree: Tree) { }, Child::Token(tok) => { let kind = tok.kind; - if kind == ModelicaToken::Protected || kind == ModelicaToken::Public { + if [ + ModelicaToken::Protected, + ModelicaToken::Public, + ModelicaToken::External, + ] + .contains(&kind) + { f.handle_break(&tok, Blank::Required); } f.handle_token(tok); @@ -519,24 +537,17 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { } fn element_list(f: &mut Formatter, tree: Tree) { - f.markers.push(Marker::Indent); - for (idx, child) in tree.children.into_iter().enumerate() { + for child in tree.children { match child { Child::Tree(tree) => { - f.handle_break( - tree.start(), - if idx > 1 { - Blank::Legal - } else { - Blank::Illegal - }, - ); + if f.prev_tok == ModelicaToken::Semicolon { + f.handle_break(tree.start(), Blank::Legal); + } element(f, tree); } Child::Token(tok) => f.handle_token(tok), } } - f.markers.push(Marker::Dedent); } fn element(f: &mut Formatter, tree: Tree) { @@ -608,9 +619,12 @@ fn import_clause(f: &mut Formatter, tree: Tree) { if kind == ModelicaToken::Import || kind == ModelicaToken::Equal { f.markers.push(Marker::Space); } else if kind == ModelicaToken::LCurly && is_multiline { + f.markers.push(Marker::Indent); if let Child::Tree(next_tree) = children.peek().unwrap() { f.handle_break(next_tree.start(), Blank::Illegal); } + } else if kind == ModelicaToken::RCurly && is_multiline { + f.markers.push(Marker::Dedent); } } } @@ -720,9 +734,12 @@ fn argument_or_inheritance_modification_list( fn inheritance_modification(f: &mut Formatter, tree: Tree) { for child in tree.children { - if let Child::Token(tok) = child { - f.handle_token(tok); - f.markers.push(Marker::Space); + match child { + Child::Tree(tree) => connect_equation(f, tree), + Child::Token(tok) => { + f.handle_token(tok); + f.markers.push(Marker::Space); + } } } } @@ -759,7 +776,7 @@ fn type_prefix(f: &mut Formatter, tree: Tree) { } fn component_list(f: &mut Formatter, tree: Tree) { - let mut is_multiline = tree.is_multiline(); + let is_multiline = tree.is_multiline(); let children_count = tree.len(); if is_multiline && children_count > 1 { f.markers.push(Marker::Indent); @@ -829,13 +846,24 @@ fn modification(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::ClassModification => class_modification(f, tree), - SyntaxKind::ModificationExpression => modification_expression(f, tree), + SyntaxKind::ModificationExpression => { + let is_multiline_if = tree.start().kind == ModelicaToken::If && tree.is_multiline(); + if is_multiline_if { + f.markers.push(Marker::Indent); + f.break_or_space(true, tree.start()); + } else { + f.markers.push(Marker::Space); + } + modification_expression(f, tree); + if is_multiline_if { + f.markers.push(Marker::Dedent); + } + } _ => unreachable!(), }, Child::Token(tok) => { f.markers.push(Marker::Space); f.handle_token(tok); - f.markers.push(Marker::Space); } } } diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo new file mode 100644 index 0000000..a91c06e --- /dev/null +++ b/tests/samples/code-input.mo @@ -0,0 +1,108 @@ +// Some code samples +// to check if the applied style is correct +within foo.bar; + + // Let's check some class with a quoted identifier +final +encapsulated partial operator record +'Quoted record "whatever"' "Quoted record" + +/* Few imports */ +import Foo.Bar "Foo import" + + annotation(ignore = false); +import Baz = Foo.Baz; +import Bar.*; +import Bark.{Foo,Bar, Baz}; +import Ark.{ + Bar, Baz}; + +// Some extension + extends .Bark.Bark() +annotation(); + +// Now some other class specifiers! + + +inner outer record Inner=der(.Foo.Baz, Foo,bar) "Der?"; + + +redeclare final inner package Foo = input +Foo.Bar[1,2](x=2+3) "Foo"; +protected // Now protected section + +flow constant Foo.Baz Bar=2, Baar; parameter Real Foo(start=2, fixed=false), +Bar if false; +annotation(Icon()); +end 'Quoted record'; + +// Now some model! + +final partial model FooModel + "Foo model" + extends .Bark.Bark(break connect(a.b ,c), + anotherUselessVar = break); + +// Some conditional expressions +parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; +Integer[1, 3, 4] bar =if true then +1 elseif baz<2 then 3 else 2; + +protected + +String A = toString([2.12,-4.34;-2.56, - 1.67] ); +public + +redeclare Foo x(y=z) = Bar; + +initial equation + if foo == Types.Dynamics.FixedInitial then +bar = bar_start; elseif foo == Types.Dynamics.SteadyStateInitial then + der(bar) = 0; end if; +equation + a = -b*c "Equation"; + x* ( -y) =2^z / (m- n); + foo =if bar then 0 else + 3; + + foo = bar(x,y=y,z=baz( + a, + b)); + +/* If-else blocks */ + + if foo then + // comment + bar = baz * bar; +else + bar = 0;// another + end if; +if a Date: Mon, 5 Feb 2024 07:47:58 +0100 Subject: [PATCH 43/67] Fix formatting in external calls --- src/formatting.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 5756bd7..3fa4c78 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -447,8 +447,14 @@ fn composition(f: &mut Formatter, tree: Tree) { f.handle_break(tree.start(), Blank::Required); algorithm_section(f, tree); } - SyntaxKind::LanguageSpecification => language_specification(f, tree), - SyntaxKind::ExternalFunctionCall => external_function_call(f, tree), + SyntaxKind::LanguageSpecification => { + f.markers.push(Marker::Space); + language_specification(f, tree); + } + SyntaxKind::ExternalFunctionCall => { + f.markers.push(Marker::Space); + external_function_call(f, tree); + } SyntaxKind::AnnotationClause => { f.markers.push(Marker::Indent); f.handle_break( @@ -476,9 +482,6 @@ fn composition(f: &mut Formatter, tree: Tree) { f.handle_break(&tok, Blank::Required); } f.handle_token(tok); - if kind == ModelicaToken::External { - f.markers.push(Marker::Space); - } } } } From a38304f968bf609d9d21e5d80c0de512d57763f1 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 07:48:21 +0100 Subject: [PATCH 44/67] Add more samples --- tests/samples/code-input.mo | 126 +++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index a91c06e..5e13b65 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -49,11 +49,24 @@ Integer[1, 3, 4] bar =if true then 1 elseif baz<2 then 3 else 2; protected + // Here we have to comments + /* + And they are separated + with a single blank line + */ String A = toString([2.12,-4.34;-2.56, - 1.67] ); +SI.Length[3] 'length of "whatever"'(start = 0, + min = -1, max = 1, nominal=0) = { 1* 0.25 for i in 1 : 3}; public -redeclare Foo x(y=z) = Bar; +redeclare Foo x(y=z) = Bar +annotation (Placement( + transformation( + extent={{-20,-10},{20,10}},rotation=90, + origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, + rotation=90, + origin={-68,0}))); initial equation if foo == Types.Dynamics.FixedInitial then @@ -105,4 +118,113 @@ connect(a[i], b[i, k]); end for; end for; -end FooModel; \ No newline at end of file + +/* Wrapped equations */ + +foo =foo*pi + * bar^2/4; +foo = bar * baz*(bark + - bam); + +/* Nested wrapping */ + +a_nominal = Z_factor * func_a(foo = b_nominal, bar = c) +* Av * Y * func_b( +x_nominal * p_nominal * d_nominal, +x_small = d_limit * d_small) +"Description"; + +/* Arrays */ + +volumes = {diameter[i] * diameter[i] +* 0.25 * length[i] for i in 1:n}; +foo = sum(bar[i] - baz[i] +for i in 1:10); + points={{-98,-60},{-64, + -60},{-64,-63.4667},{-27.1111,-63.4667}}; + foo = (bar - 1) ^ 3 +*(1-(baz + 12) / (10 * (baz + 1)) + sum( + (1 - 2 * (foo - k) / ((foo + 1) * k * (k + 1))) * 1 / (k - 1) * ((bar - 1) / r) ^ (k - 3) + for k in 1:42)); +/* Matrices */ + +extent = [-10, 110; 10, 90]; +extent = [ + -10, 110; 10, 90]; + a[:,:]=[1,1,1,1,1; 2,2,2, + 2,2]; +m[:,:] = Math.Matrices.sort( + [ + Math.Vectors.length(v1), + Math.Vectors.length(v2); + Math.Vectors.length(v1 + v2), + Math.Vectors.length(v2 - v1) + ]); +end FooModel; +// And now functions! +final pure function Foo "Return something" + extends .Modelica.Icons.Function + ; + + input Integer a "Aaa"; + output Real result "Length"; + +protected + + Real b "Bbb"; + +algorithm + (A,B,C):= foo.bar.baz + (a); + (D,,E) := foo.bar .baz(b); + (F, G,(H, + J)) := foo.bar.baz(c); + +foo:={{bar[i] + j* +(baz[i] - ber[i])/n for i in 1:n} for j in 1:m}; +bar:={{foo[i] + j*(baz[i] - foo[i])/n +for i in 1:n} + for j in 1:m}; + +baz := aaa ++ bbb * (ccc + ddd- + eee) + - fff * ggg; + +external"C" foo[1].bar [2] = baz(x +,y,z) +annotation (Library="doesn't matter"); +annotation (smoothOrder = 2); +end Foo; +partial function Bar "Just in case" + initial algorithm + + x := y; + + /* If statement */ +foo := if a == 1 then bar +else baz +"What is this about?"; + +/* Multiline statements */ +y := u1 > 0 +and u2 > 0 and +u3 > 0 + and u4 > 0; + +y := u1 > 0 +or u2 > 0 or +u3 > 0 + or u4 > 0; + +Modelica.Utilities.Streams.print( + "foo" + "bar" + + "baz"); +end Bar; + +// And some enums + +type Foo=enumeration(Foo1, foo2) "foo enum"; +type Foo=enumeration(Foo1, + foo2) "foo enum"; + type Foo=enumeration(Foo1 "foo1", foo2) "foo enum with description of one element"; From 8877335e31d141637b9b8b85101c9e418da0414b Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 09:10:33 +0100 Subject: [PATCH 45/67] Support line wrapping in enums and arguments list with descriptions --- Cargo.toml | 2 +- src/formatting.rs | 7 ++++++- src/tree.rs | 21 ++++++++++++++++++++- tests/samples/code-input.mo | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4099e6e..cbfaf09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -moparse = "0.1.4-rc3" +moparse = "0.1.4-rc4" diff --git a/src/formatting.rs b/src/formatting.rs index 3fa4c78..d48943e 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -307,6 +307,11 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { SyntaxKind::ArraySubscripts => array_subscripts(f, tree), SyntaxKind::ClassModification => class_modification(f, tree), SyntaxKind::EnumList => { + if !is_multiline { + // Enum list could be unwrapped, yet if it + // contains any description it should be wrapped + is_multiline = tree.contains(SyntaxKind::Description); + } if is_multiline { f.markers.push(Marker::Indent); f.handle_break(tree.start(), Blank::Illegal); @@ -883,7 +888,7 @@ fn modification_expression(f: &mut Formatter, tree: Tree) { fn class_modification(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Indent); - let is_multiline = tree.is_multiline(); + let is_multiline = tree.is_multiline() || tree.contains(SyntaxKind::DescriptionString) || tree.contains(SyntaxKind::Description); let mut children = tree.children.into_iter().peekable(); while let Some(child) = children.next() { match child { diff --git a/src/tree.rs b/src/tree.rs index 34fac33..23cdb57 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -29,11 +29,13 @@ pub fn build_tree(tokens: Vec, events: Vec) -> Tree { stack.pop().unwrap() } +#[derive(Debug)] pub struct Tree { pub kind: SyntaxKind, pub children: Vec, } +#[derive(Debug)] pub enum Child { Token(Token), Tree(Tree), @@ -74,6 +76,23 @@ impl Tree { let last = self.end(); first.start.line < last.end.line } + + pub fn contains(&self, kind: SyntaxKind) -> bool { + let mut contains = false; + for child in self.children.iter() { + if let Child::Tree(tree) = child { + if tree.kind == kind { + contains = true; + } else { + contains = tree.contains(kind); + } + } + if contains { + return contains; + } + } + contains + } } #[cfg(test)] @@ -89,7 +108,7 @@ mod tests { #[test] fn test_empty_rules() { - const SOURCE: &str = "annotation ()"; + const SOURCE: &str = r#"annotation (choices(choice = 0 "Foo", choice = 1 "Bar"))"#; let tree = tree(SOURCE, SyntaxKind::Description); assert_eq!(tree.len(), 1); } diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index 5e13b65..6e98602 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -172,6 +172,7 @@ final pure function Foo "Return something" protected Real b "Bbb"; + parameter Integer control = 0 annotation (choices(choice = 0 "Foo", choice = 1 "Bar")); algorithm (A,B,C):= foo.bar.baz From 443fb5b34ba240741f1b712500fd62718362ecb3 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 09:41:04 +0100 Subject: [PATCH 46/67] Improve indent in modification expressions, equations and statements --- src/formatting.rs | 49 ++++++++++++++++++++++++++++--------- tests/samples/code-input.mo | 3 ++- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index d48943e..25c22a1 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -855,15 +855,13 @@ fn modification(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::ClassModification => class_modification(f, tree), SyntaxKind::ModificationExpression => { - let is_multiline_if = tree.start().kind == ModelicaToken::If && tree.is_multiline(); - if is_multiline_if { + let is_multiline = tree.is_multiline(); + if is_multiline { f.markers.push(Marker::Indent); - f.break_or_space(true, tree.start()); - } else { - f.markers.push(Marker::Space); } + f.break_or_space(is_multiline, tree.start()); modification_expression(f, tree); - if is_multiline_if { + if is_multiline { f.markers.push(Marker::Dedent); } } @@ -1125,7 +1123,17 @@ fn equation(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::SimpleExpression => simple_expression(f, tree), - SyntaxKind::Expression => expression(f, tree), + SyntaxKind::Expression => { + let is_multiline = tree.is_multiline(); + if is_multiline { + f.markers.push(Marker::Indent); + } + f.break_or_space(is_multiline, tree.start()); + expression(f, tree); + if is_multiline { + f.markers.push(Marker::Dedent); + } + } SyntaxKind::IfEquation => if_equation(f, tree), SyntaxKind::ForEquation => for_equation(f, tree), SyntaxKind::ConnectEquation => connect_equation(f, tree), @@ -1146,9 +1154,6 @@ fn equation(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Space); } f.handle_token(tok); - if kind == ModelicaToken::Equal { - f.markers.push(Marker::Space); - } } } } @@ -1159,7 +1164,17 @@ fn statement(f: &mut Formatter, tree: Tree) { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::ComponentReference => component_reference(f, tree), - SyntaxKind::Expression => expression(f, tree), + SyntaxKind::Expression => { + let is_multiline = tree.is_multiline(); + if is_multiline { + f.markers.push(Marker::Indent); + } + f.break_or_space(is_multiline, tree.start()); + expression(f, tree); + if is_multiline { + f.markers.push(Marker::Dedent); + } + } SyntaxKind::FunctionCallArgs => function_call_args(f, tree), SyntaxKind::OutputExpressionList => { let is_multiline = f.prev_line < tree.start().start.line || tree.is_multiline(); @@ -1913,10 +1928,20 @@ fn named_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { fn named_argument(f: &mut Formatter, tree: Tree) { for child in tree.children { if let Child::Tree(tree) = child { + let is_multiline = tree.is_multiline(); + if is_multiline { + f.markers.push(Marker::Indent); + } + f.break_or_space(is_multiline, tree.start()); function_argument(f, tree); + if is_multiline { + f.markers.push(Marker::Dedent); + } } else if let Child::Token(tok) = child { + if tok.kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } f.handle_token(tok); - f.markers.push(Marker::Space); } } } diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index 6e98602..b03f678 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -131,7 +131,8 @@ foo = bar * baz*(bark a_nominal = Z_factor * func_a(foo = b_nominal, bar = c) * Av * Y * func_b( x_nominal * p_nominal * d_nominal, -x_small = d_limit * d_small) +x_small = d_limit +* d_small) "Description"; /* Arrays */ From 9781beacda502714af8524e2617a07a92c8a7ee5 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 09:46:16 +0100 Subject: [PATCH 47/67] Update style tests --- tests/samples/code-output.mo | 347 ++++++++++++++++++++++++++++++ tests/samples/functions-input.mo | 67 ------ tests/samples/functions-output.mo | 95 -------- tests/samples/models-input.mo | 138 ------------ tests/samples/models-output.mo | 174 --------------- tests/style_tests.rs | 42 ++-- 6 files changed, 364 insertions(+), 499 deletions(-) create mode 100644 tests/samples/code-output.mo delete mode 100644 tests/samples/functions-input.mo delete mode 100644 tests/samples/functions-output.mo delete mode 100644 tests/samples/models-input.mo delete mode 100644 tests/samples/models-output.mo diff --git a/tests/samples/code-output.mo b/tests/samples/code-output.mo new file mode 100644 index 0000000..d6ad308 --- /dev/null +++ b/tests/samples/code-output.mo @@ -0,0 +1,347 @@ +// Some code samples +// to check if the applied style is correct +within foo.bar; + +// Let's check some class with a quoted identifier +final encapsulated partial operator record 'Quoted record "whatever"' + "Quoted record" + + /* Few imports */ + import Foo.Bar + "Foo import" + annotation (ignore = false); + import Baz = Foo.Baz; + import Bar.*; + import Bark.{Foo, Bar, Baz}; + import Ark.{ + Bar, + Baz}; + + // Some extension + extends .Bark.Bark() + annotation (); + + // Now some other class specifiers! + + inner outer record Inner = der(.Foo.Baz, Foo, bar) + "Der?"; + + redeclare final inner package Foo = input Foo.Bar[1, 2](x = 2 + 3) + "Foo"; + +protected // Now protected section + + flow constant Foo.Baz Bar = 2, Baar; + parameter Real + Foo(start = 2, fixed = false), + Bar if false; + + annotation (Icon()); + +end 'Quoted record'; + +// Now some model! + +final partial model FooModel + "Foo model" + + extends .Bark.Bark( + break connect(a.b, c), + anotherUselessVar = break); + + // Some conditional expressions + parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; + Integer[1, 3, 4] bar = + if true then + 1 + elseif baz < 2 then + 3 + else + 2; + +protected + + // Here we have to comments + + /* + And they are separated + with a single blank line + */ + String A = toString([2.12, -4.34; -2.56, -1.67]); + SI.Length[3] 'length of "whatever"'( + start = 0, + min = -1, + max = 1, + nominal = 0) = {1 * 0.25 for i in 1 : 3}; + +public + + redeclare Foo x(y = z) = Bar + annotation ( + Placement( + transformation( + extent = {{-20, -10}, {20, 10}}, + rotation = 90, + origin = {-98, 4}), + iconTransformation( + extent = {{-40, -10}, {40, 10}}, + rotation = 90, + origin = {-68, 0}))); + +initial equation + + if foo == Types.Dynamics.FixedInitial then + bar = bar_start; + elseif foo == Types.Dynamics.SteadyStateInitial then + der(bar) = 0; + end if; + +equation + + a = -b * c + "Equation"; + x * (-y) = 2 ^ z / (m - n); + foo = + if bar then + 0 + else + 3; + + foo = + bar( + x, + y = y, + z = + baz( + a, + b)); + + /* If-else blocks */ + + if foo then + // comment + bar = baz * bar; + else + bar = 0; // another + end if; + if a < b then + if x < 0 then + m = n; + elseif x < y then + m = 2 * n; + else + m = 0; + end if; + else + m = n ^ 2; + end if; + + /* For loop */ + + for i in 1 : n loop + h[i] = c[i] * T[i]; + end for; + + for i in 1 : m loop + for j in 1 : n loop + connect(a[i], b[i, k]); + end for; + end for; + + /* Wrapped equations */ + + foo = + foo + * pi + * bar ^ 2 + / 4; + foo = + bar + * baz + * ( + bark + - bam); + + /* Nested wrapping */ + + a_nominal = + Z_factor + * func_a(foo = b_nominal, bar = c) + * Av + * Y + * func_b( + x_nominal * p_nominal * d_nominal, + x_small = + d_limit + * d_small) + "Description"; + + /* Arrays */ + + volumes = + { + diameter[i] + * diameter[i] + * 0.25 + * length[i] + for i in 1 : n}; + foo = + sum( + bar[i] - baz[i] + for i in 1 : 10); + points = + { + {-98, -60}, + { + -64, + -60}, + {-64, -63.4667}, + {-27.1111, -63.4667}}; + foo = + (bar - 1) ^ 3 + * ( + 1 + - (baz + 12) / (10 * (baz + 1)) + + sum( + (1 - 2 * (foo - k) / ((foo + 1) * k * (k + 1))) * 1 / (k - 1) * ((bar - 1) / r) ^ (k - 3) + for k in 1 : 42)); + /* Matrices */ + + extent = [-10, 110; 10, 90]; + extent = + [ + -10, 110; + 10, 90]; + a[:, :] = + [ + 1, 1, 1, 1, 1; + 2, + 2, + 2, + 2, + 2]; + m[:, :] = + Math.Matrices.sort( + [ + Math.Vectors.length(v1), + Math.Vectors.length(v2); + Math.Vectors.length(v1 + v2), + Math.Vectors.length(v2 - v1)]); + +end FooModel; +// And now functions! +final pure function Foo + "Return something" + + extends .Modelica.Icons.Function; + + input Integer a + "Aaa"; + output Real result + "Length"; + +protected + + Real b + "Bbb"; + parameter Integer control = 0 + annotation ( + choices( + choice = 0 + "Foo", + choice = 1 + "Bar")); + +algorithm + + (A, B, C) := foo.bar.baz(a); + (D, , E) := foo.bar.baz(b); + ( + F, + G, + ( + H, + J)) := foo.bar.baz(c); + + foo := + { + { + bar[i] + + j + * (baz[i] - ber[i]) + / n + for i in 1 : n} + for j in 1 : m}; + bar := + { + { + foo[i] + j * (baz[i] - foo[i]) / n + for i in 1 : n} + for j in 1 : m}; + + baz := + aaa + + bbb + * ( + ccc + + ddd + - eee) + - fff * ggg; + +external "C" foo[1].bar[2] = baz( + x, + y, + z) + annotation (Library = "doesn't matter"); + + annotation (smoothOrder = 2); + +end Foo; +partial function Bar + "Just in case" + +initial algorithm + + x := y; + + /* If statement */ + foo := + if a == 1 then + bar + else + baz + "What is this about?"; + + /* Multiline statements */ + y := + u1 > 0 + and u2 > 0 + and u3 > 0 + and u4 > 0; + + y := + u1 > 0 + or u2 > 0 + or u3 > 0 + or u4 > 0; + + Modelica.Utilities.Streams.print( + "foo" + + "bar" + + "baz"); + +end Bar; + +// And some enums + +type Foo = enumeration(Foo1, foo2) + "foo enum"; +type Foo = enumeration( + Foo1, + foo2) + "foo enum"; +type Foo = enumeration( + Foo1 + "foo1", + foo2) + "foo enum with description of one element"; diff --git a/tests/samples/functions-input.mo b/tests/samples/functions-input.mo deleted file mode 100644 index 0407ecf..0000000 --- a/tests/samples/functions-input.mo +++ /dev/null @@ -1,67 +0,0 @@ -within; -final encapsulated function Foo "Return something" - - extends .Modelica.Icons.Function; - - input Integer a "Aaa"; - output Real result "Length"; - -protected - - Real b "Bbb"; - -algorithm - (A, B, C) := foo.bar.baz(a); - (D, , E) := foo.bar .baz(b); - (F, G, (H, - J)) := foo.bar.baz(c); - -foo:={{bar[i] + j* -(baz[i] - ber[i])/n for i in 1:n} for j in 1:m}; -bar:={{foo[i] + j*(baz[i] - foo[i])/n -for i in 1:n} - for j in 1:m}; - -baz := aaa -+ bbb * (ccc + ddd- - eee) - - fff * ggg; - -external"C" foo[1].bar [2] = baz(x,y,z) -annotation (Library="doesn't matter"); -annotation (smoothOrder = 2); -end Foo; - -partial function Bar "Just in case" - initial algorithm - - x := y; - - /* If statement */ -foo := if a == 1 then bar -else baz -"What is this about?"; - -/* Multiline statements */ -y := u1 > 0 -and u2 > 0 and -u3 > 0 - and u4 > 0; - -y := u1 > 0 -or u2 > 0 or -u3 > 0 - or u4 > 0; - -Modelica.Utilities.Streams.print( - "foo" + "bar" - + "baz"); - - for i in 1:5 loop - foo[i] := bar[i] ^ 2 - * (4 - bar[i] / (6 * bar[i] + 6) - + sum({(4 - 2 * bar[i] / ((bar[i] + 1) * (k + 3)) - * ((bar[i] - 1) / bar[i]) ^ k) for k in 1:10})); - end for; - -end Bar; diff --git a/tests/samples/functions-output.mo b/tests/samples/functions-output.mo deleted file mode 100644 index b3600ed..0000000 --- a/tests/samples/functions-output.mo +++ /dev/null @@ -1,95 +0,0 @@ -within; -final encapsulated function Foo - "Return something" - - extends .Modelica.Icons.Function; - - input Integer a - "Aaa"; - output Real result - "Length"; - -protected - - Real b - "Bbb"; - -algorithm - - (A, B, C) := foo.bar.baz(a); - (D,, E) := foo.bar.baz(b); - ( - F, - G, - ( - H, - J)) := foo.bar.baz(c); - - foo := { - { - bar[i] + j - * (baz[i] - ber[i]) / n - for i in 1:n} - for j in 1:m}; - bar := { - { - foo[i] + j * (baz[i] - foo[i]) / n - for i in 1:n} - for j in 1:m}; - - baz := aaa - + bbb * ( - ccc + ddd - - eee) - - fff * ggg; - -external "C" foo[1].bar[2] = baz(x, y, z) - annotation (Library = "doesn't matter"); - - annotation (smoothOrder = 2); - -end Foo; - -partial function Bar - "Just in case" - -initial algorithm - - x := y; - - /* If statement */ - foo := - if a == 1 then - bar - else - baz - "What is this about?"; - - /* Multiline statements */ - y := u1 > 0 - and u2 > 0 - and u3 > 0 - and u4 > 0; - - y := u1 > 0 - or u2 > 0 - or u3 > 0 - or u4 > 0; - - Modelica.Utilities.Streams.print( - "foo" + "bar" - + "baz"); - - for i in 1:5 loop - foo[i] := bar[i] ^ 2 - * ( - 4 - bar[i] / (6 * bar[i] + 6) - + sum( - { - ( - 4 - 2 * bar[i] / ((bar[i] + 1) * (k + 3)) - * ((bar[i] - 1) / bar[i]) ^ k) - for k in 1:10})); - end for; - -end Bar; diff --git a/tests/samples/models-input.mo b/tests/samples/models-input.mo deleted file mode 100644 index 716714e..0000000 --- a/tests/samples/models-input.mo +++ /dev/null @@ -1,138 +0,0 @@ -within Bark.Baark; -model Foo "Foo description" - -import Modelica.Constants; -import Modelica.SI; - - extends Bar(a=0, b= 1, - c = if x then - 1 else 1 , - break uselessVar, anotherUselessVar = break, // USELESS! - final d = true); - - // Bunch of elements -replaceable package Medium = .Modelica.Media.Interfaces.PartialMedium - "Medium model" annotation (choicesAllMatching=true); - - - final /* Unexpected comment! */ parameter Real foo(start = 0, min = -1000) = if d then Constants.inf - else if y then 5*2+ - (2^4) - +111 else 66 - "Parameter with some fairly complex modification expression" - annotation (Dialog(tab = "General", group="Bunch")); - - SI.Length[3] 'length of "whatever"'(start = 0, - min = -1, max = 1, nominal=0) = { 1* 0.25 for i in 1 : 3}; -protected -/* It is too valuable to be public */ - Integer n_protected; -public - // Here we have to comments - - /* - And they are separated - with a single blank line - */ -.Modelica.Blocks.Interfaces.BooleanInput b -annotation (Placement( - transformation( - extent={{-20,-10},{20,10}},rotation=90, - origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, - rotation=90, - origin={-68,0}))); - - -initial equation -if foo == Types.Dynamics.FixedInitial then - bar = bar_start; - elseif foo == Types.Dynamics.SteadyStateInitial then -der(bar) = 0; - end if; - - equation -a = -b*c; - x *( - y) = 2^z/ (m-n); - -A = toString([2.12,-4.34;-2.56, -1.67]); - -foo = bar(x, y, baz(a, -b)); - -/* Wrapped equations */ - -Q_flow = alpha * surfaceArea* -(T_a - T_b); -volume =height*pi - * diameter^2/4; - - -/* If-else blocks */ - -if wetConditions then - - // Latent heat flow is present - Q_flow_latent = Q_flow - Q_flow_sensible; - -else - Q_flow_latent=0; // Latent heat flow is absent -end if; - -if a String { - let input = fs::read_to_string(path).expect("error"); - let tokens = moparse::lex(&input); - let events = moparse::parse(&tokens, moparse::SyntaxKind::StoredDefinition); - let (markers, _) = mofmt::format(&tokens, &events); - mofmt::pretty_print(&tokens, markers) -} - -#[test] -fn models_formatting() { - let formatted = format_file("tests/samples/models-input.mo"); - let expected = fs::read_to_string("tests/samples/models-output.mo").expect("error"); - assert_eq!(expected, formatted); -} -#[test] -fn functions_formatting() { - let formatted = format_file("tests/samples/functions-input.mo"); - let expected = fs::read_to_string("tests/samples/functions-output.mo").expect("error"); - assert_eq!(expected, formatted); -} +use mofmt; +use moparse; +use std::fs; + +// Helper functions +fn format_file(path: &str) -> String { + let input = fs::read_to_string(path).expect("error"); + let parsed = moparse::parse(&input, moparse::SyntaxKind::StoredDefinition); + mofmt::pretty_print(parsed.tokens, parsed.comments, parsed.events) +} + +#[test] +fn test_formatting() { + let formatted = format_file("tests/samples/code-input.mo"); + let expected = fs::read_to_string("tests/samples/code-output.mo").expect("error"); + assert_eq!(expected, formatted); +} From 550d57eed8f7a844b3a1c26120abad4723260c5b Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 10:46:40 +0100 Subject: [PATCH 48/67] Improve wrapping in function calls --- src/formatting.rs | 50 ++++++++++++++++++++++++++++-------- tests/samples/code-output.mo | 15 ++++++----- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 25c22a1..65b1bea 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -75,6 +75,7 @@ pub fn format(tree: Tree, comments: Vec) -> Vec { SyntaxKind::Expression => expression(&mut f, tree), _ => (), } + f.markers.push(Marker::Break); f.markers } @@ -457,14 +458,20 @@ fn composition(f: &mut Formatter, tree: Tree) { language_specification(f, tree); } SyntaxKind::ExternalFunctionCall => { - f.markers.push(Marker::Space); + f.markers.push(Marker::Indent); + f.handle_break(tree.start(), Blank::Required); external_function_call(f, tree); + f.markers.push(Marker::Dedent); } SyntaxKind::AnnotationClause => { f.markers.push(Marker::Indent); + let extern_element_annotation = f.prev_tok != ModelicaToken::Semicolon; + if extern_element_annotation { + f.markers.push(Marker::Indent); + } f.handle_break( tree.start(), - if f.prev_tok == ModelicaToken::Semicolon { + if !extern_element_annotation { Blank::Required } else { Blank::Illegal @@ -472,6 +479,9 @@ fn composition(f: &mut Formatter, tree: Tree) { ); annotation_clause(f, tree); f.markers.push(Marker::Dedent); + if extern_element_annotation { + f.markers.push(Marker::Dedent); + } } _ => unreachable!(), }, @@ -529,14 +539,17 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { let kind = tok.kind; if kind == ModelicaToken::Equal { f.markers.push(Marker::Space); + } else if kind == ModelicaToken::Identifier { + f.break_or_space(is_multiline, &tok); } f.handle_token(tok); - if kind == ModelicaToken::Equal { - f.markers.push(Marker::Space); - } else if kind == ModelicaToken::LParen && is_multiline { + if kind == ModelicaToken::LParen && is_multiline { + f.markers.push(Marker::Indent); if let Child::Tree(next_tree) = children.peek().unwrap() { f.handle_break(next_tree.start(), Blank::Illegal); } + } else if kind == ModelicaToken::RParen && is_multiline { + f.markers.push(Marker::Dedent); } } } @@ -1160,10 +1173,23 @@ fn equation(f: &mut Formatter, tree: Tree) { } fn statement(f: &mut Formatter, tree: Tree) { - for child in tree.children { + let mut children = tree.children.into_iter().peekable(); + let mut is_multiline_call = false; + while let Some(child) = children.next() { match child { Child::Tree(tree) => match tree.kind { - SyntaxKind::ComponentReference => component_reference(f, tree), + SyntaxKind::ComponentReference => { + if f.prev_tok == ModelicaToken::Assign { + if let Some(Child::Tree(next_tree)) = children.peek() { + is_multiline_call = next_tree.is_multiline(); + if is_multiline_call { + f.markers.push(Marker::Indent); + } + f.break_or_space(is_multiline_call, tree.start()); + } + } + component_reference(f, tree); + } SyntaxKind::Expression => { let is_multiline = tree.is_multiline(); if is_multiline { @@ -1175,7 +1201,12 @@ fn statement(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Dedent); } } - SyntaxKind::FunctionCallArgs => function_call_args(f, tree), + SyntaxKind::FunctionCallArgs => { + function_call_args(f, tree); + if is_multiline_call { + f.markers.push(Marker::Dedent); + } + } SyntaxKind::OutputExpressionList => { let is_multiline = f.prev_line < tree.start().start.line || tree.is_multiline(); if is_multiline { @@ -1205,9 +1236,6 @@ fn statement(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Space); } f.handle_token(tok); - if kind == ModelicaToken::Assign { - f.markers.push(Marker::Space); - } } } } diff --git a/tests/samples/code-output.mo b/tests/samples/code-output.mo index d6ad308..0f819d5 100644 --- a/tests/samples/code-output.mo +++ b/tests/samples/code-output.mo @@ -288,11 +288,14 @@ algorithm - eee) - fff * ggg; -external "C" foo[1].bar[2] = baz( - x, - y, - z) - annotation (Library = "doesn't matter"); +external "C" + + foo[1].bar[2] = + baz( + x, + y, + z) + annotation (Library = "doesn't matter"); annotation (smoothOrder = 2); @@ -302,7 +305,7 @@ partial function Bar initial algorithm - x := y; + x := y; /* If statement */ foo := From 1feda992179989ecf8f15f25f0925ca344b82f88 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 13:14:27 +0100 Subject: [PATCH 49/67] Standardize indents at if expressions --- src/formatting.rs | 63 ++---- tests/samples/code-input.mo | 427 +++++++++++++++++++++-------------- tests/samples/code-output.mo | 207 ++++++++--------- 3 files changed, 382 insertions(+), 315 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 65b1bea..21c0ef2 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -346,7 +346,6 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { fn der_class_specifier(f: &mut Formatter, tree: Tree) { let mut is_multiline = false; - f.markers.push(Marker::Indent); let mut children = tree.children.iter(); while let Some(child) = children.next() { if let Child::Token(token) = child { @@ -388,11 +387,14 @@ fn der_class_specifier(f: &mut Formatter, tree: Tree) { f.handle_token(tok); if kind == ModelicaToken::Equal { f.markers.push(Marker::Space); + } else if kind == ModelicaToken::LParen { + f.markers.push(Marker::Indent); + } else if kind == ModelicaToken::RParen { + f.markers.push(Marker::Dedent); } } } } - f.markers.push(Marker::Dedent); } fn base_prefix(f: &mut Formatter, tree: Tree) { @@ -539,17 +541,14 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { let kind = tok.kind; if kind == ModelicaToken::Equal { f.markers.push(Marker::Space); - } else if kind == ModelicaToken::Identifier { - f.break_or_space(is_multiline, &tok); } f.handle_token(tok); - if kind == ModelicaToken::LParen && is_multiline { - f.markers.push(Marker::Indent); + if kind == ModelicaToken::Equal { + f.markers.push(Marker::Space); + } else if kind == ModelicaToken::LParen && is_multiline { if let Child::Tree(next_tree) = children.peek().unwrap() { f.handle_break(next_tree.start(), Blank::Illegal); } - } else if kind == ModelicaToken::RParen && is_multiline { - f.markers.push(Marker::Dedent); } } } @@ -868,13 +867,13 @@ fn modification(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::ClassModification => class_modification(f, tree), SyntaxKind::ModificationExpression => { - let is_multiline = tree.is_multiline(); - if is_multiline { + let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + if is_multiline_if { f.markers.push(Marker::Indent); } - f.break_or_space(is_multiline, tree.start()); + f.break_or_space(is_multiline_if, tree.start()); modification_expression(f, tree); - if is_multiline { + if is_multiline_if { f.markers.push(Marker::Dedent); } } @@ -1137,13 +1136,13 @@ fn equation(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::SimpleExpression => simple_expression(f, tree), SyntaxKind::Expression => { - let is_multiline = tree.is_multiline(); - if is_multiline { + let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + if is_multiline_if { f.markers.push(Marker::Indent); } - f.break_or_space(is_multiline, tree.start()); + f.break_or_space(is_multiline_if, tree.start()); expression(f, tree); - if is_multiline { + if is_multiline_if { f.markers.push(Marker::Dedent); } } @@ -1174,39 +1173,27 @@ fn equation(f: &mut Formatter, tree: Tree) { fn statement(f: &mut Formatter, tree: Tree) { let mut children = tree.children.into_iter().peekable(); - let mut is_multiline_call = false; while let Some(child) = children.next() { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::ComponentReference => { if f.prev_tok == ModelicaToken::Assign { - if let Some(Child::Tree(next_tree)) = children.peek() { - is_multiline_call = next_tree.is_multiline(); - if is_multiline_call { - f.markers.push(Marker::Indent); - } - f.break_or_space(is_multiline_call, tree.start()); - } + f.markers.push(Marker::Space); } component_reference(f, tree); } SyntaxKind::Expression => { - let is_multiline = tree.is_multiline(); - if is_multiline { + let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + if is_multiline_if { f.markers.push(Marker::Indent); } - f.break_or_space(is_multiline, tree.start()); + f.break_or_space(is_multiline_if, tree.start()); expression(f, tree); - if is_multiline { - f.markers.push(Marker::Dedent); - } - } - SyntaxKind::FunctionCallArgs => { - function_call_args(f, tree); - if is_multiline_call { + if is_multiline_if { f.markers.push(Marker::Dedent); } } + SyntaxKind::FunctionCallArgs => function_call_args(f, tree), SyntaxKind::OutputExpressionList => { let is_multiline = f.prev_line < tree.start().start.line || tree.is_multiline(); if is_multiline { @@ -1956,13 +1943,13 @@ fn named_arguments(f: &mut Formatter, tree: Tree, is_multiline: bool) { fn named_argument(f: &mut Formatter, tree: Tree) { for child in tree.children { if let Child::Tree(tree) = child { - let is_multiline = tree.is_multiline(); - if is_multiline { + let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + if is_multiline_if { f.markers.push(Marker::Indent); } - f.break_or_space(is_multiline, tree.start()); + f.break_or_space(is_multiline_if, tree.start()); function_argument(f, tree); - if is_multiline { + if is_multiline_if { f.markers.push(Marker::Dedent); } } else if let Child::Token(tok) = child { diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index b03f678..dd9c7df 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -2,231 +2,330 @@ // to check if the applied style is correct within foo.bar; - // Let's check some class with a quoted identifier -final -encapsulated partial operator record -'Quoted record "whatever"' "Quoted record" +// Let's check some class with a quoted identifier +final encapsulated partial operator record 'Quoted record "whatever"' + "Quoted record" -/* Few imports */ -import Foo.Bar "Foo import" + /* Few imports */ + import Foo.Bar + "Foo import" + annotation (ignore = false); + import Baz = Foo.Baz; + import Bar.*; + import Bark.{Foo, Bar, Baz}; + import Ark.{ + Bar, + Baz}; - annotation(ignore = false); -import Baz = Foo.Baz; -import Bar.*; -import Bark.{Foo,Bar, Baz}; -import Ark.{ - Bar, Baz}; + // Some extension + extends .Bark.Bark() + annotation (); -// Some extension - extends .Bark.Bark() -annotation(); + // Now some other class specifiers! -// Now some other class specifiers! + inner outer record Inner = der(.Foo.Baz, Foo, bar) + "Der?"; + redeclare final inner package Foo = input Foo.Bar[1, 2](x = 2 + 3) + "Foo"; -inner outer record Inner=der(.Foo.Baz, Foo,bar) "Der?"; +protected // Now protected section + flow constant Foo.Baz Bar = 2, Baar; + parameter Real + Foo(start = 2, fixed = false), + Bar if false; -redeclare final inner package Foo = input -Foo.Bar[1,2](x=2+3) "Foo"; -protected // Now protected section + annotation (Icon()); -flow constant Foo.Baz Bar=2, Baar; parameter Real Foo(start=2, fixed=false), -Bar if false; -annotation(Icon()); -end 'Quoted record'; +end 'Quoted record "whatever"'; // Now some model! final partial model FooModel - "Foo model" - extends .Bark.Bark(break connect(a.b ,c), - anotherUselessVar = break); - -// Some conditional expressions -parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; -Integer[1, 3, 4] bar =if true then -1 elseif baz<2 then 3 else 2; + "Foo model" + + extends .Bark.Bark( + break connect(a.b, c), + anotherUselessVar = break); + + // Some conditional expressions + parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; + Integer[1, 3, 4] bar = + if true then + 1 + elseif baz < 2 then + 3 + else + 2; protected + // Here we have to comments /* And they are separated with a single blank line */ -String A = toString([2.12,-4.34;-2.56, - 1.67] ); -SI.Length[3] 'length of "whatever"'(start = 0, - min = -1, max = 1, nominal=0) = { 1* 0.25 for i in 1 : 3}; + String A = toString([2.12, -4.34; -2.56, -1.67]); + SI.Length[3] 'length of "whatever"'( + start = 0, + min = -1, + max = 1, + nominal = 0) = {1 * 0.25 for i in 1 : 3}; + public -redeclare Foo x(y=z) = Bar -annotation (Placement( - transformation( - extent={{-20,-10},{20,10}},rotation=90, - origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, - rotation=90, - origin={-68,0}))); + redeclare Foo x(y = z) = Bar + annotation ( + Placement( + transformation( + extent = {{-20, -10}, {20, 10}}, + rotation = 90, + origin = {-98, 4}), + iconTransformation( + extent = {{-40, -10}, {40, 10}}, + rotation = 90, + origin = {-68, 0}))); initial equation + if foo == Types.Dynamics.FixedInitial then -bar = bar_start; elseif foo == Types.Dynamics.SteadyStateInitial then - der(bar) = 0; end if; + bar = bar_start; + elseif foo == Types.Dynamics.SteadyStateInitial then + der(bar) = 0; + end if; + equation - a = -b*c "Equation"; - x* ( -y) =2^z / (m- n); - foo =if bar then 0 else - 3; - foo = bar(x,y=y,z=baz( + a = -b * c + "Equation"; + x * (-y) = 2 ^ z / (m - n); + foo = + if bar then + 0 + else + 3; + + foo = bar( + x, + y = y, + z = baz( a, b)); -/* If-else blocks */ + /* If-else blocks */ if foo then // comment bar = baz * bar; -else - bar = 0;// another + else + bar = 0; // another + end if; + if a < b then + if x < 0 then + m = n; + elseif x < y then + m = 2 * n; + else + m = 0; + end if; + else + m = n ^ 2; end if; -if a 0 -and u2 > 0 and -u3 > 0 - and u4 > 0; + x := y; -y := u1 > 0 -or u2 > 0 or -u3 > 0 + /* If statement */ + foo := + if a == 1 then + bar + else + baz + "What is this about?"; + + /* Multiline statements */ + y := u1 > 0 + and u2 > 0 + and u3 > 0 + and u4 > 0; + + y := u1 > 0 + or u2 > 0 + or u3 > 0 or u4 > 0; -Modelica.Utilities.Streams.print( - "foo" + "bar" - + "baz"); + Modelica.Utilities.Streams.print( + "foo" + + "bar" + + "baz"); + end Bar; // And some enums -type Foo=enumeration(Foo1, foo2) "foo enum"; -type Foo=enumeration(Foo1, - foo2) "foo enum"; - type Foo=enumeration(Foo1 "foo1", foo2) "foo enum with description of one element"; +type Foo = enumeration(Foo1, foo2) + "foo enum"; +type Foo = enumeration( + Foo1, + foo2) + "foo enum"; +type Foo = enumeration( + Foo1 + "foo1", + foo2) + "foo enum with description of one element"; diff --git a/tests/samples/code-output.mo b/tests/samples/code-output.mo index 0f819d5..dd9c7df 100644 --- a/tests/samples/code-output.mo +++ b/tests/samples/code-output.mo @@ -24,7 +24,7 @@ final encapsulated partial operator record 'Quoted record "whatever"' // Now some other class specifiers! inner outer record Inner = der(.Foo.Baz, Foo, bar) - "Der?"; + "Der?"; redeclare final inner package Foo = input Foo.Bar[1, 2](x = 2 + 3) "Foo"; @@ -38,7 +38,7 @@ protected // Now protected section annotation (Icon()); -end 'Quoted record'; +end 'Quoted record "whatever"'; // Now some model! @@ -107,14 +107,12 @@ equation else 3; - foo = - bar( - x, - y = y, - z = - baz( - a, - b)); + foo = bar( + x, + y = y, + z = baz( + a, + b)); /* If-else blocks */ @@ -150,83 +148,72 @@ equation /* Wrapped equations */ - foo = - foo - * pi - * bar ^ 2 - / 4; - foo = - bar - * baz - * ( - bark - - bam); + foo = foo + * pi + * bar ^ 2 + / 4; + foo = bar + * baz + * ( + bark + - bam); /* Nested wrapping */ - a_nominal = - Z_factor - * func_a(foo = b_nominal, bar = c) - * Av - * Y - * func_b( - x_nominal * p_nominal * d_nominal, - x_small = - d_limit - * d_small) + a_nominal = Z_factor + * func_a(foo = b_nominal, bar = c) + * Av + * Y + * func_b( + x_nominal * p_nominal * d_nominal, + x_small = d_limit + * d_small) "Description"; /* Arrays */ - volumes = + volumes = { + diameter[i] + * diameter[i] + * 0.25 + * length[i] + for i in 1 : n}; + foo = sum( + bar[i] - baz[i] + for i in 1 : 10); + points = { + {-98, -60}, { - diameter[i] - * diameter[i] - * 0.25 - * length[i] - for i in 1 : n}; - foo = - sum( - bar[i] - baz[i] - for i in 1 : 10); - points = - { - {-98, -60}, - { - -64, - -60}, - {-64, -63.4667}, - {-27.1111, -63.4667}}; - foo = - (bar - 1) ^ 3 - * ( - 1 - - (baz + 12) / (10 * (baz + 1)) - + sum( - (1 - 2 * (foo - k) / ((foo + 1) * k * (k + 1))) * 1 / (k - 1) * ((bar - 1) / r) ^ (k - 3) - for k in 1 : 42)); + -64, + -60}, + {-64, -63.4667}, + {-27.1111, -63.4667}}; + foo = (bar - 1) ^ 3 + * ( + 1 + - (baz + 12) / (10 * (baz + 1)) + + sum( + (1 - 2 * (foo - k) / ((foo + 1) * k * (k + 1))) * 1 / (k - 1) * ((bar - 1) / r) ^ (k - 3) + for k in 1 : 42)); /* Matrices */ extent = [-10, 110; 10, 90]; - extent = - [ - -10, 110; - 10, 90]; - a[:, :] = + extent = [ + -10, 110; + 10, 90]; + a[:, :] = [ + 1, 1, 1, 1, 1; + 2, + 2, + 2, + 2, + 2]; + m[:, :] = Math.Matrices.sort( [ - 1, 1, 1, 1, 1; - 2, - 2, - 2, - 2, - 2]; - m[:, :] = - Math.Matrices.sort( - [ - Math.Vectors.length(v1), - Math.Vectors.length(v2); - Math.Vectors.length(v1 + v2), - Math.Vectors.length(v2 - v1)]); + Math.Vectors.length(v1), + Math.Vectors.length(v2); + Math.Vectors.length(v1 + v2), + Math.Vectors.length(v2 - v1)]); end FooModel; // And now functions! @@ -263,38 +250,34 @@ algorithm H, J)) := foo.bar.baz(c); - foo := + foo := { { - { - bar[i] - + j - * (baz[i] - ber[i]) - / n - for i in 1 : n} - for j in 1 : m}; - bar := + bar[i] + + j + * (baz[i] - ber[i]) + / n + for i in 1 : n} + for j in 1 : m}; + bar := { { - { - foo[i] + j * (baz[i] - foo[i]) / n - for i in 1 : n} - for j in 1 : m}; - - baz := - aaa - + bbb - * ( - ccc - + ddd - - eee) - - fff * ggg; + foo[i] + j * (baz[i] - foo[i]) / n + for i in 1 : n} + for j in 1 : m}; + + baz := aaa + + bbb + * ( + ccc + + ddd + - eee) + - fff * ggg; external "C" - foo[1].bar[2] = - baz( - x, - y, - z) + foo[1].bar[2] = baz( + x, + y, + z) annotation (Library = "doesn't matter"); annotation (smoothOrder = 2); @@ -316,17 +299,15 @@ initial algorithm "What is this about?"; /* Multiline statements */ - y := - u1 > 0 - and u2 > 0 - and u3 > 0 - and u4 > 0; - - y := - u1 > 0 - or u2 > 0 - or u3 > 0 - or u4 > 0; + y := u1 > 0 + and u2 > 0 + and u3 > 0 + and u4 > 0; + + y := u1 > 0 + or u2 > 0 + or u3 > 0 + or u4 > 0; Modelica.Utilities.Streams.print( "foo" From 610158eeaa99d7220cb73f306807cefc09fb72f2 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 13:24:16 +0100 Subject: [PATCH 50/67] Fix clippy findings --- src/formatting.rs | 56 +++++++++++++++++++++++------------------------ src/main.rs | 12 +++++----- src/tree.rs | 2 +- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 21c0ef2..ad82ecc 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -107,7 +107,7 @@ impl Formatter { fn handle_break(&mut self, tok: &Token, blanks: Blank) { let (inlines, comments) = self.comments_before(tok); for comment in inlines { - if self.markers.len() > 0 { + if !self.markers.is_empty() { self.markers.push(Marker::Space); } self.markers.push(Marker::Token(comment.text)); @@ -125,12 +125,10 @@ impl Formatter { self.markers.push(Marker::Break); } } + } else if comment.start.line - line > 1 { + self.markers.push(Marker::Blank); } else { - if comment.start.line - line > 1 { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Break); - } + self.markers.push(Marker::Break); } self.markers.push(Marker::Token(comment.text)); line = comment.end.line; @@ -143,13 +141,11 @@ impl Formatter { } } else if let Blank::Illegal = blanks { self.markers.push(Marker::Break); - } else { - if line > self.prev_line { - if tok.start.line - line > 1 { - self.markers.push(Marker::Blank); - } else { - self.markers.push(Marker::Break); - } + } else if line > self.prev_line { + if tok.start.line - line > 1 { + self.markers.push(Marker::Blank); + } else { + self.markers.push(Marker::Break); } } } @@ -284,7 +280,7 @@ fn short_class_specifier(f: &mut Formatter, tree: Tree) { while let Some(child) = children.next() { if let Child::Token(token) = child { if token.kind == ModelicaToken::LParen { - while let Some(child) = children.next() { + for child in children.by_ref() { if let Child::Token(tok) = child { if tok.kind == ModelicaToken::RParen { is_multiline = tok.start.line > token.start.line; @@ -350,7 +346,7 @@ fn der_class_specifier(f: &mut Formatter, tree: Tree) { while let Some(child) = children.next() { if let Child::Token(token) = child { if token.kind == ModelicaToken::LParen { - while let Some(child) = children.next() { + for child in children.by_ref() { if let Child::Token(tok) = child { if tok.kind == ModelicaToken::RParen { is_multiline = tok.start.line > token.start.line; @@ -481,7 +477,7 @@ fn composition(f: &mut Formatter, tree: Tree) { ); annotation_clause(f, tree); f.markers.push(Marker::Dedent); - if extern_element_annotation { + if extern_element_annotation { f.markers.push(Marker::Dedent); } } @@ -519,7 +515,7 @@ fn external_function_call(f: &mut Formatter, tree: Tree) { while let Some(child) = children.next() { if let Child::Token(token) = child { if token.kind == ModelicaToken::LParen { - while let Some(child) = children.next() { + for child in children.by_ref() { if let Child::Token(tok) = child { if tok.kind == ModelicaToken::RParen { is_multiline = tok.start.line > token.start.line; @@ -606,7 +602,7 @@ fn import_clause(f: &mut Formatter, tree: Tree) { while let Some(child) = children.next() { if let Child::Token(token) = child { if token.kind == ModelicaToken::LCurly { - while let Some(child) = children.next() { + for child in children.by_ref() { if let Child::Token(tok) = child { if tok.kind == ModelicaToken::RCurly { is_multiline = tok.start.line > token.start.line; @@ -867,7 +863,8 @@ fn modification(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::ClassModification => class_modification(f, tree), SyntaxKind::ModificationExpression => { - let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + let is_multiline_if = + tree.is_multiline() && tree.start().kind == ModelicaToken::If; if is_multiline_if { f.markers.push(Marker::Indent); } @@ -898,7 +895,9 @@ fn modification_expression(f: &mut Formatter, tree: Tree) { fn class_modification(f: &mut Formatter, tree: Tree) { f.markers.push(Marker::Indent); - let is_multiline = tree.is_multiline() || tree.contains(SyntaxKind::DescriptionString) || tree.contains(SyntaxKind::Description); + let is_multiline = tree.is_multiline() + || tree.contains(SyntaxKind::DescriptionString) + || tree.contains(SyntaxKind::Description); let mut children = tree.children.into_iter().peekable(); while let Some(child) = children.next() { match child { @@ -1136,7 +1135,8 @@ fn equation(f: &mut Formatter, tree: Tree) { Child::Tree(tree) => match tree.kind { SyntaxKind::SimpleExpression => simple_expression(f, tree), SyntaxKind::Expression => { - let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + let is_multiline_if = + tree.is_multiline() && tree.start().kind == ModelicaToken::If; if is_multiline_if { f.markers.push(Marker::Indent); } @@ -1172,8 +1172,7 @@ fn equation(f: &mut Formatter, tree: Tree) { } fn statement(f: &mut Formatter, tree: Tree) { - let mut children = tree.children.into_iter().peekable(); - while let Some(child) = children.next() { + for child in tree.children { match child { Child::Tree(tree) => match tree.kind { SyntaxKind::ComponentReference => { @@ -1183,7 +1182,8 @@ fn statement(f: &mut Formatter, tree: Tree) { component_reference(f, tree); } SyntaxKind::Expression => { - let is_multiline_if = tree.is_multiline() && tree.start().kind == ModelicaToken::If; + let is_multiline_if = + tree.is_multiline() && tree.start().kind == ModelicaToken::If; if is_multiline_if { f.markers.push(Marker::Indent); } @@ -1510,10 +1510,8 @@ fn expression(f: &mut Formatter, tree: Tree) { expression(f, tree); if conditional { f.markers.push(Marker::Dedent); - if let Some(next_child) = children.peek() { - if let Child::Token(next_tok) = next_child { - f.break_or_space(is_multiline, next_tok); - } + if let Some(Child::Token(next_tok)) = children.peek() { + f.break_or_space(is_multiline, next_tok); } } else { f.markers.push(Marker::Space); @@ -1979,7 +1977,7 @@ fn function_partial_application(f: &mut Formatter, tree: Tree) { while let Some(child) = children.next() { if let Child::Token(token) = child { if token.kind == ModelicaToken::LParen { - while let Some(child) = children.next() { + for child in children.by_ref() { if let Child::Token(tok) = child { if tok.kind == ModelicaToken::RParen { is_multiline = tok.start.line > token.start.line; diff --git a/src/main.rs b/src/main.rs index ae232b0..e85463f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,8 @@ fn main() { /// Format files specified in the argument list fn format_files(args: &[String]) { let mut files = Vec::new(); - args.into_iter() - .map(|s| PathBuf::from(s)) + args.iter() + .map(PathBuf::from) .map(|p| { if p.is_dir() { get_files_from_dir(p) @@ -24,7 +24,7 @@ fn format_files(args: &[String]) { files.iter().for_each(|p| { let contents = read_file(p); let parsed = parse(&contents, SyntaxKind::StoredDefinition); - if parsed.errors.len() > 0 { + if !parsed.errors.is_empty() { let messages: Vec = parsed.errors .iter() .map(|e| format!("{}:{}", p.display(), e)) @@ -40,7 +40,7 @@ fn format_files(args: &[String]) { fn get_files_from_dir(dir: PathBuf) -> Vec { let mut files = Vec::new(); let paths = fs::read_dir(&dir) - .expect(format!("{}: error reading from a directory", dir.display()).as_str()); + .unwrap_or_else(|_| panic!("{}: error reading from a directory", dir.display())); paths .map(|e| e.unwrap().path()) .map(|p| { @@ -70,10 +70,10 @@ fn read_file(from: &Path) -> String { if !is_modelica(from) { panic!("{}: is not a Modelica file", from.display()); } - fs::read_to_string(from).expect(format!("{}: error reading a file", from.display()).as_str()) + fs::read_to_string(from).unwrap_or_else(|_| panic!("{}: error reading a file", from.display())) } /// Write formatted code to a file fn write_file(to: &Path, code: String) { - fs::write(to, code).expect(format!("{}: error writing a file", to.display()).as_str()); + fs::write(to, code).unwrap_or_else(|_| panic!("{}: error writing a file", to.display())); } diff --git a/src/tree.rs b/src/tree.rs index 23cdb57..d2d3025 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -23,7 +23,7 @@ pub fn build_tree(tokens: Vec, events: Vec) -> Tree { } } - assert!(matches!(tokens.next(), None)); + assert!(tokens.next().is_none()); assert!(stack.len() == 1); stack.pop().unwrap() From 4bbafb8ba7e8cd48e42629973919bb5eac468069 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 13:38:48 +0100 Subject: [PATCH 51/67] Revert formatting of input sample --- tests/samples/code-input.mo | 427 ++++++++++++++---------------------- 1 file changed, 164 insertions(+), 263 deletions(-) diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index dd9c7df..b03f678 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -2,330 +2,231 @@ // to check if the applied style is correct within foo.bar; -// Let's check some class with a quoted identifier -final encapsulated partial operator record 'Quoted record "whatever"' - "Quoted record" + // Let's check some class with a quoted identifier +final +encapsulated partial operator record +'Quoted record "whatever"' "Quoted record" - /* Few imports */ - import Foo.Bar - "Foo import" - annotation (ignore = false); - import Baz = Foo.Baz; - import Bar.*; - import Bark.{Foo, Bar, Baz}; - import Ark.{ - Bar, - Baz}; +/* Few imports */ +import Foo.Bar "Foo import" - // Some extension - extends .Bark.Bark() - annotation (); + annotation(ignore = false); +import Baz = Foo.Baz; +import Bar.*; +import Bark.{Foo,Bar, Baz}; +import Ark.{ + Bar, Baz}; - // Now some other class specifiers! +// Some extension + extends .Bark.Bark() +annotation(); - inner outer record Inner = der(.Foo.Baz, Foo, bar) - "Der?"; +// Now some other class specifiers! - redeclare final inner package Foo = input Foo.Bar[1, 2](x = 2 + 3) - "Foo"; -protected // Now protected section +inner outer record Inner=der(.Foo.Baz, Foo,bar) "Der?"; - flow constant Foo.Baz Bar = 2, Baar; - parameter Real - Foo(start = 2, fixed = false), - Bar if false; - annotation (Icon()); +redeclare final inner package Foo = input +Foo.Bar[1,2](x=2+3) "Foo"; +protected // Now protected section -end 'Quoted record "whatever"'; +flow constant Foo.Baz Bar=2, Baar; parameter Real Foo(start=2, fixed=false), +Bar if false; +annotation(Icon()); +end 'Quoted record'; // Now some model! final partial model FooModel - "Foo model" - - extends .Bark.Bark( - break connect(a.b, c), - anotherUselessVar = break); - - // Some conditional expressions - parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; - Integer[1, 3, 4] bar = - if true then - 1 - elseif baz < 2 then - 3 - else - 2; + "Foo model" + extends .Bark.Bark(break connect(a.b ,c), + anotherUselessVar = break); -protected +// Some conditional expressions +parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; +Integer[1, 3, 4] bar =if true then +1 elseif baz<2 then 3 else 2; +protected // Here we have to comments /* And they are separated with a single blank line */ - String A = toString([2.12, -4.34; -2.56, -1.67]); - SI.Length[3] 'length of "whatever"'( - start = 0, - min = -1, - max = 1, - nominal = 0) = {1 * 0.25 for i in 1 : 3}; - +String A = toString([2.12,-4.34;-2.56, - 1.67] ); +SI.Length[3] 'length of "whatever"'(start = 0, + min = -1, max = 1, nominal=0) = { 1* 0.25 for i in 1 : 3}; public - redeclare Foo x(y = z) = Bar - annotation ( - Placement( - transformation( - extent = {{-20, -10}, {20, 10}}, - rotation = 90, - origin = {-98, 4}), - iconTransformation( - extent = {{-40, -10}, {40, 10}}, - rotation = 90, - origin = {-68, 0}))); +redeclare Foo x(y=z) = Bar +annotation (Placement( + transformation( + extent={{-20,-10},{20,10}},rotation=90, + origin={-98,4}), iconTransformation(extent={{-40,-10},{40,10}}, + rotation=90, + origin={-68,0}))); initial equation - if foo == Types.Dynamics.FixedInitial then - bar = bar_start; - elseif foo == Types.Dynamics.SteadyStateInitial then - der(bar) = 0; - end if; - +bar = bar_start; elseif foo == Types.Dynamics.SteadyStateInitial then + der(bar) = 0; end if; equation + a = -b*c "Equation"; + x* ( -y) =2^z / (m- n); + foo =if bar then 0 else + 3; - a = -b * c - "Equation"; - x * (-y) = 2 ^ z / (m - n); - foo = - if bar then - 0 - else - 3; - - foo = bar( - x, - y = y, - z = baz( + foo = bar(x,y=y,z=baz( a, b)); - /* If-else blocks */ +/* If-else blocks */ if foo then // comment bar = baz * bar; - else - bar = 0; // another - end if; - if a < b then - if x < 0 then - m = n; - elseif x < y then - m = 2 * n; - else - m = 0; - end if; - else - m = n ^ 2; +else + bar = 0;// another end if; +if a 0 - and u2 > 0 - and u3 > 0 - and u4 > 0; - - y := u1 > 0 - or u2 > 0 - or u3 > 0 - or u4 > 0; + /* If statement */ +foo := if a == 1 then bar +else baz +"What is this about?"; + +/* Multiline statements */ +y := u1 > 0 +and u2 > 0 and +u3 > 0 + and u4 > 0; - Modelica.Utilities.Streams.print( - "foo" - + "bar" - + "baz"); +y := u1 > 0 +or u2 > 0 or +u3 > 0 + or u4 > 0; +Modelica.Utilities.Streams.print( + "foo" + "bar" + + "baz"); end Bar; // And some enums -type Foo = enumeration(Foo1, foo2) - "foo enum"; -type Foo = enumeration( - Foo1, - foo2) - "foo enum"; -type Foo = enumeration( - Foo1 - "foo1", - foo2) - "foo enum with description of one element"; +type Foo=enumeration(Foo1, foo2) "foo enum"; +type Foo=enumeration(Foo1, + foo2) "foo enum"; + type Foo=enumeration(Foo1 "foo1", foo2) "foo enum with description of one element"; From 1d9df37d0c86f3a1a1831ba461c29a5b44a625e6 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 13:58:25 +0100 Subject: [PATCH 52/67] Improve error recovery in the mofmt --- src/main.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index e85463f..44134f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,16 +23,26 @@ fn format_files(args: &[String]) { .for_each(|mut v| files.append(&mut v)); files.iter().for_each(|p| { let contents = read_file(p); - let parsed = parse(&contents, SyntaxKind::StoredDefinition); - if !parsed.errors.is_empty() { - let messages: Vec = parsed.errors - .iter() - .map(|e| format!("{}:{}", p.display(), e)) - .collect(); - panic!("Syntax errors detected:\n{}", messages.join("\n")); + match contents { + Ok(source) => { + let parsed = parse(&source, SyntaxKind::StoredDefinition); + if !parsed.errors.is_empty() { + let messages: Vec = parsed + .errors + .iter() + .map(|e| format!("{}:{}", p.display(), e)) + .collect(); + println!( + "Syntax errors detected (mofmt won't touch this file):\n{}", + messages.join("\n") + ); + } else { + let output = pretty_print(parsed.tokens, parsed.comments, parsed.events); + write_file(p, output); + } + } + Err(e) => println!("{}: error: {}", p.display(), e), } - let output = pretty_print(parsed.tokens, parsed.comments, parsed.events); - write_file(p, output); }); } @@ -66,11 +76,14 @@ fn is_modelica(f: &Path) -> bool { } /// Return contents of the Modelica file -fn read_file(from: &Path) -> String { +fn read_file(from: &Path) -> Result { if !is_modelica(from) { - panic!("{}: is not a Modelica file", from.display()); + return Err(format!("{} is not a Modelica file", from.display())); + } + match fs::read_to_string(from) { + Ok(s) => Ok(s), + Err(e) => Err(e.to_string()), } - fs::read_to_string(from).unwrap_or_else(|_| panic!("{}: error reading a file", from.display())) } /// Write formatted code to a file From fa6358286977e2b179ba2eeb6f9d6230929b8aac Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 14:00:28 +0100 Subject: [PATCH 53/67] Align input sample with the output --- tests/samples/code-input.mo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index b03f678..24563d2 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -34,7 +34,7 @@ protected // Now protected section flow constant Foo.Baz Bar=2, Baar; parameter Real Foo(start=2, fixed=false), Bar if false; annotation(Icon()); -end 'Quoted record'; +end 'Quoted record "whatever"'; // Now some model! From 3f4f5fb8bb33e83f977a9e2b36a5119276d96bd2 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 14:10:23 +0100 Subject: [PATCH 54/67] Relicense as MPL --- LICENSE | 396 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 375 insertions(+), 21 deletions(-) diff --git a/LICENSE b/LICENSE index a081730..f7d9d73 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,375 @@ -MIT License - -Copyright (c) 2023 Eryk Mroczek - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +Mozilla Public License Version 2.0 +================================== + +Copyright (c) 2023 Eryk Mroczek + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. From f6067c608cec8e6cb4d9e0167cab2fdb7f3c6d0b Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 14:10:38 +0100 Subject: [PATCH 55/67] Fill the manifest file --- Cargo.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cbfaf09..e191e6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,13 @@ [package] name = "mofmt" -version = "0.1.0" +description = "Modelica language formatter" +authors = ["Eryk Mroczek "] +version = "0.4.0" edition = "2021" +license = "MPL-2.0" +readme = "README.md" +repository = "https://github.com/ErykMroczek/mofmt" +keywords = ["Modelica", "development", "formatter"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 1c516eb47f18d79b2f685ce0a7cf213814b785f9 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 14:14:14 +0100 Subject: [PATCH 56/67] Update README --- README.md | 157 +++++++++++++++++------------------------------------- 1 file changed, 49 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 82dc61c..5263071 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,49 @@ -# mofmt - Modelica code formatter - -*Mofmt* is a code formatter for [Modelica](https://modelica.org/) -language. It aims to enhance readability and provide style constistency -across different Modelica projects. - -Although functionality is basically finished, it can of course exhibit -buggy behavior. *mofmt* doesn't modify files if it meets syntax errors. -I advice to double-check changed files. - -Code style applied by the *mofmt* is described in `code-style.md`. - -## Installation and usage - -### Installation - -*Mofmt* can be installed from PYPI: - -```shell -pip install mofmt -``` - -On top of that, repo contains a necessary `pre-commit-hooks.yaml` file, -so if you are using Git, you can delegate running *mofmt* to -[pre-commit](https://pre-commit.com/) framework. - -### Usage - -*mofmt* takes one kind of argument - path that points to Modelica source -file or directory that is supposed to contain such files. *mofmt* can -accept multiple such arguments. - -```shell -mofmt PATH ... -``` - -## Features and limitations - -### Vertical spacing and grouping - -*Mofmt* aims to ensure that Modelica code is vertically grouped and -indented in a intuitive way that additionally allows you to fold/unfold -specific sections in your text editor. Yet it will try to preserve -single blank lines that you have placed manually, unless they were -placed in places that *mofmt* considers prohibited. - -### Comments - -Modelica language specification allows you to place comments between any -lexical units, but at least some software doesn't respect that and -displace your comments if it feels like it. *Mofmt* tries to avoid that -(but bugs may happen!). Both comments and whitespaces between them are -preserved. Additionally, *mofmt* preceeds your inline comments with a -single space to enhance readability. - -### Line wrapping - -*Mofmt* doesn't have a notion of maximum line length and doesn't wrap -lines automatically. This is a deliberate choice, for many expressions -in Modelica are written in a way that resembles textbook formulas. Such -formulas contain terms that have a specific meaning and probably are -kept on the same line by Modelica developers. Any (reasonably simple) -algorithm would probably be too stupid for that, so there is no wrapping -algorithm in *mofmt*. Instead, it will respect your wrapping inside -expressions (provided you wrapped at some operator): - -```modelica -Q_flow = alpha * surfaceArea * -(T_a - T_b); -``` - -and only adjust it slightly: - -```modelica -Q_flow = alpha * surfaceArea - * (T_a - T_b); -``` - -If wrap is placed inside function call, array etc.: - -```modelica -cp = specificHeat_pT(p = p, T = temperature_ph(p = p, -h = h)); -``` - -*mofmt* will ensure that the whole argument list is formatted -consistently, including nested calls: - -```modelica -cp = specificHeat_pT( - p = p, - T = temperature_ph( - p = p, - h = h)); -``` - -## TODO - -* improve parsing performance -* (maybe) include HTML pretty-printer - -## License - -MIT - -## Authors - -Eryk Mroczek: +# mofmt - Modelica code formatter + +*mofmt* is a code formatter for [Modelica](https://modelica.org/) +language. It aims to enhance readability and provide style constistency +across different Modelica projects. + +*mofmt* doesn't modify files if it meets syntax errors. + +Code style applied by the *mofmt* is described in `code-style.md`. + +## Installation and usage + +### Installation + +*mofmt* can be installed with `cargo`: + +```shell +cargo install mofmt +``` + +or you can just grab one of the released libraries. + +On top of that, repo contains a necessary `pre-commit-hooks.yaml` file, +so if you are using Git, you can delegate running *mofmt* to +[pre-commit](https://pre-commit.com/) framework. + +### Usage + +*mofmt* takes one kind of argument - path that points to Modelica source +file or directory that is supposed to contain such files. *mofmt* can +accept multiple such arguments. + +```shell +mofmt PATH ... +``` + +## TODO + +* include HTML pretty-printer +* include simple syntactical simplifications that don't affect the code + semantics (removing redundant parentheses etc.) + +## License + +MPL-2.0 + +## Authors + +Eryk Mroczek: From dd93d0ace079a51dfb625a2f234562632430da5a Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 14:26:22 +0100 Subject: [PATCH 57/67] Simple CLI interface --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.rs b/src/main.rs index 44134f0..a16e1ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,30 @@ use moparse::{parse, SyntaxKind}; use std::path::{Path, PathBuf}; use std::{env, fs}; +const VERSION: &str = "0.4.0"; + +const HELP: &str = r#" +mofmt: Modelica code formatter + +Usage: mofmt SRC ... + +Options: +-h, --help: display this message and exit +-v, --version: display a version number and exit +"#; + fn main() { let args: Vec = env::args().collect(); + if args.len() < 2 { + eprintln!("{}", HELP); + std::process::exit(1); + } else if ["-h", "--help"].contains(&args[1].as_str()) { + println!("{}", HELP); + std::process::exit(0); + } else if ["-v", "--version"].contains(&args[1].as_str()) { + println!("mofmt, {}", VERSION); + std::process::exit(0); + } format_files(&args[1..]); } From d739c6f9c63a6e5ed614513ce9aa970754cbc595 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 16:15:56 +0100 Subject: [PATCH 58/67] Run formatter on a whole crate --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c840f07..a3568bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,7 @@ -use moparse::{SyntaxEvent, Token}; - +use self::formatting::format; use self::printing::print; use self::tree::build_tree; -use self::formatting::format; +use moparse::{SyntaxEvent, Token}; pub fn pretty_print(tokens: Vec, comments: Vec, events: Vec) -> String { let tree = build_tree(tokens, events); From b116ecb8f883a8fa8f141ac4bbea6bf5559074f0 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 16:27:03 +0100 Subject: [PATCH 59/67] Include all productions in format() --- src/formatting.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/formatting.rs b/src/formatting.rs index ad82ecc..17e1b98 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -73,7 +73,39 @@ pub fn format(tree: Tree, comments: Vec) -> Vec { SyntaxKind::WhenStatement => when_statement(&mut f, tree), SyntaxKind::ConnectEquation => connect_equation(&mut f, tree), SyntaxKind::Expression => expression(&mut f, tree), - _ => (), + SyntaxKind::SimpleExpression => simple_expression(&mut f, tree), + SyntaxKind::LogicalExpression => logical_expression(&mut f, tree), + SyntaxKind::LogicalTerm => logical_term(&mut f, tree), + SyntaxKind::LogicalFactor => logical_factor(&mut f, tree), + SyntaxKind::Relation => relation(&mut f, tree), + SyntaxKind::RelationalOperator => relational_operator(&mut f, tree), + SyntaxKind::ArithmeticExpression => arithmetic_expression(&mut f, tree), + SyntaxKind::AddOperator => add_operator(&mut f, tree), + SyntaxKind::Term => term(&mut f, tree), + SyntaxKind::MulOperator => mul_operator(&mut f, tree), + SyntaxKind::Factor => factor(&mut f, tree), + SyntaxKind::Primary => primary(&mut f, tree), + SyntaxKind::TypeSpecifier => type_specifier(&mut f, tree), + SyntaxKind::Name => name(&mut f, tree), + SyntaxKind::ComponentReference => component_reference(&mut f, tree), + SyntaxKind::ResultReference => result_reference(&mut f, tree), + SyntaxKind::FunctionCallArgs => function_call_args(&mut f, tree), + SyntaxKind::FunctionArguments => function_arguments(&mut f, tree, false), + SyntaxKind::FunctionArgumentsNonFirst => function_arguments_non_first(&mut f, tree, false), + SyntaxKind::ArrayArguments => array_arguments(&mut f, tree, false), + SyntaxKind::ArrayArgumentsNonFirst => array_arguments_non_first(&mut f, tree, false), + SyntaxKind::NamedArguments => named_arguments(&mut f, tree, false), + SyntaxKind::NamedArgument => named_argument(&mut f, tree), + SyntaxKind::FunctionArgument => function_argument(&mut f, tree), + SyntaxKind::FunctionPartialApplication => function_partial_application(&mut f, tree), + SyntaxKind::OutputExpressionList => output_expression_list(&mut f, tree, false), + SyntaxKind::ExpressionList => expression_list(&mut f, tree, false), + SyntaxKind::ArraySubscripts => array_subscripts(&mut f, tree), + SyntaxKind::Subscript => subscript(&mut f, tree), + SyntaxKind::Description => description(&mut f, tree), + SyntaxKind::DescriptionString => description_string(&mut f, tree), + SyntaxKind::AnnotationClause => annotation_clause(&mut f, tree), + SyntaxKind::Error => (), } f.markers.push(Marker::Break); f.markers From 5797a758dace1c92b860f97418489504cb57bd86 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 16:31:52 +0100 Subject: [PATCH 60/67] Prepare CI workflow --- .github/workflows/ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b1e7f19 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +on: + workflow_dispatch: + pull_request: + branches: [ "main" ] + +name: CI + +jobs: + + format: + name: Rustfmt + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt + - run: cargo fmt --all --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy + - run: cargo clippy --workspace --all-features -- -D warnings + + build_and_test_linux: + name: Build and Test (Linux) + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + run: cargo test --all-targets + + build_and_test_win: + name: Build and Test (Windows) + runs-on: windows-latest + timeout-minutes: 10 + steps: + - name: Prepare symlink configuration + run: git config --global core.symlinks true + + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + run: cargo test --all-targets From dce57124f1ab38c6d8f70efbe5ab4448302b40bc Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 16:40:42 +0100 Subject: [PATCH 61/67] Move workflow name at the top --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1e7f19..fb5c3e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,10 @@ +name: CI + on: workflow_dispatch: pull_request: branches: [ "main" ] -name: CI - jobs: format: From 3d102b751114547e826738bd75dc0e26f79c3881 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 16:45:57 +0100 Subject: [PATCH 62/67] Remove old workflow --- .github/workflows/workflows.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .github/workflows/workflows.yml diff --git a/.github/workflows/workflows.yml b/.github/workflows/workflows.yml deleted file mode 100644 index 1be0f7f..0000000 --- a/.github/workflows/workflows.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python package - -on: - workflow_dispatch: - pull_request: - branches: [ "main" ] - -jobs: - build: - runs-on: ${{ matrix.platform }} - strategy: - matrix: - platform: [ubuntu-latest] - python-version: ['3.9', '3.10', '3.11'] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install poetry - poetry install --only dev - - name: Test with tox - run: poetry run tox - env: - PLATFORM: ${{ matrix.platform }} From 48a7b6ac3d490bd4b3da27c1b2130bd6004c0bdb Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 17:01:17 +0100 Subject: [PATCH 63/67] Prepare changelog --- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad58b65..6ffe890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,39 @@ All important changes will be described in this file. Or rather I will try to document them here. +## [0.4.0] - 2024-02-XX + +This release marks an important milestone. From now on `mofmt` will be +implemented in Rust. The migration was motivated by very poor +performance of Python implementation. This was caused partially by the +ANTLR parser having a general runtime that couldn't be tailored in any +way, and mainly because of the inherent slowness of Python. + +New Rust implementation was around 50x faster. After including better +and more detailed heuristics it is still between 30-40x faster without +any performance tweaks. This both creates significant performance +savings that can be spent in the future on more advanced features like +HTML formatting, and opens possibilities of performance gains through +multithreading etc. + +Few long exisisting bugs were fixed along the way. There are some minor +changes in the style applied by `mofmt`. Refer to the `code-style.md`. + +### Added + +- support for new syntactical constructs from Modelica 3.7 +- cover *output-expression-list* production + +### Changed + +- expressions are now wrapped at every operator inside the precedence + level where the original wrap occured as well as in all outer levels + +### Fixed + +- enum lists and argument lists are now wrapped if they contain + descriptions without the need to run formatter twice + ## [0.3.6] - 2024-01-09 Bugfixes and performance improvements. From c25bbdd5202a4c3d429ed3a40bd6f888513278b7 Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 17:07:52 +0100 Subject: [PATCH 64/67] Implement discarding of comments that are in illegal places --- src/formatting.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/formatting.rs b/src/formatting.rs index 17e1b98..d41f476 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -200,6 +200,7 @@ impl Formatter { } fn handle_token(&mut self, tok: Token) { + let _ = self.comments_before(&tok); self.prev_line = tok.end.line; self.prev_tok = tok.kind; self.markers.push(Marker::Token(tok.text)); From e4ebfa980717d1d8a2913a295b30ad19bab1078b Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 17:42:48 +0100 Subject: [PATCH 65/67] Update code style document --- code-style.md | 443 +++++++++++++++++++++++++++----------------------- 1 file changed, 239 insertions(+), 204 deletions(-) diff --git a/code-style.md b/code-style.md index 993bf47..7271834 100644 --- a/code-style.md +++ b/code-style.md @@ -1,204 +1,239 @@ -# Code style - -This document describes a code style as applied by *mofmt*. - -## Maximum line length - -There is no line length limit. There are plenty of limits already. - -## Horizontal spacing - -Single space is allowed as a horizontal separator. - -### Binary operators - -All binary operators shall be surrounded by spaces. - -```modelica -2 * (3 - 1.76) -a <= b or x -``` - -### Unary operators - -Except for the `not` operator unary operators shall not be separated -from their operands. - -#### Example - -```modelica --4 --(2 + 3) -not isOff -``` - -### Assignments and equalities - -`:=` and `=` tokens shall be surrounded by spaces. - -```modelica -Q_flow = alpha * A * delta_T; -``` - -### Array elements and function arguments - -Space shall be inserted after every comma. - -#### Example - -```modelica -{1.0, 2.0, 3.0} -enthalpy_pT(p, T) -``` - -## Indentation - -Indentation is 2 spaces per single level. - -Modelica doesn't use indentation to define the scope, but it is -nonetheless useful to use it to enhance readability. Descriptions and -annotations are good examples. Overall, indentation shall be increased at: - -* descriptions and annotations -* constraining clauses -* elements, equations and statement lists -* enumeration items -* inside loops and if blocks - -### Descriptions, annotations and constraining clauses - -Indentation shall be increased only one time per element. - -#### Example - -```modelica -replaceable package Medium = Modelica.Media.R134a.R134a_ph - constrainedby Modelica.Media.Interfaces.PartialMedium - "Fluid medium" - annotation(Dialog(tab = "General", group = "Medium")); -``` - -### Element, statement and equation lists - -Indentation shall be increased before the list. - -#### Example - -```modelica -model BasicBoundary - "Basic fluid boundary model" - - import Modelica.Fluid.Types.PortFlowDirection; - import Modelica.Constants.inf; - - // SNAP - -protected - - parameter PortFlowDirection flowDirection = PortFlowDirection.Bidirectional - "Allowed flow direction"; - -equation - - // SNAP - -end BasicBoundary; -``` - -### Enumeration items - -Indentation shall be increased inside `enumeration()` and at every -description. - -#### Example - -```modelica -type BoundaryType = enumeration( - Pressure - "Pressure boundary", - Flow - "Flow boundary") - "Enumeration of possible boundary types"; -``` - -### Loops and if blocks - -Indentation shall be increased before statement/equation list inside -loop or if-else branch block. - -#### Example - -```modelica -if boundaryType == BoundaryType.Pressure then - medium.p = p_in; -else - port.m_flow = -m_flow_in; -end if; -``` - -## Vertical spacing - -Beside indented elements described in the previous section, a newline -shall be inserted after every semicolon. It is allowable to insert a -single blank line instead. - -Additionally, a single blank shall be inserted before: - -* section keywords -* element, equations and statement lists inside class sections -* before the call to an external function -* before class annotation -* before end clause signifying the class' scope - -## Line wrapping - -### Function calls, arrays, matrices, class modifications etc. - -The main rule here is: be consistent. The following approach shall be -applied: - -1. If line is wrapped at any argument, then wrap at every argument. -2. If line is wrapped inside a nested construct, then wrap at every - argument in every outer construct. - -Indentation shall be increased accordingly to help visually identify the -scope. - -#### Example - -```Modelica -// No wrap is fine -h = enthalpy_pT(p, T); - -// Outer array is wrapped, but inner ones are kept intact -parameter Real A[2,3] = { - {1.0, 2.0, 3.0}, - {5.0, 6.0, 7.0}}; - -// In nested function call, if inner call is wrapped, outer call shall be -// wrapped as well -cp_a = specificHeat_pT( - p = p_a, - T = temperature_ph( - p = p_a, - h = h_a)); - -// But it is fine to wrap only outer call, keeping inner one intact -cp_b = specificHeat_pT( - p = p_b, - T = temperature_ph(p = p_b, h = h_b)); -``` - -### Compound expressions - -Expressions shall be wrapped at binary operators. Operator used as a -wrapping point shall be moved to a new line. Indentation shall be -increased only after the first wrap. - -#### Example - -```Modelica -Wb_flows[1] = vs[1] * crossAreas[1] * ((mediums[2].p - mediums[1].p) / 2 - + flowModel.dps_fg[1] / 2 - system.g*dheights[1] * mediums[1].d) - * nParallel; -``` +# Code style + +This document describes a code style as applied by the *mofmt*. + +## Maximum line length + +There is no line length limit. There are plenty of limits already. + +## Horizontal spacing + +Single space is used as a horizontal separator. + +```modelica +parameter Real Foo(start = 0); // Comment +``` + +### Binary operators + +All binary operators are surrounded with spaces. + +```modelica +2 * (3 - 1.76) +a <= b or x +1 : 10 +``` + +### Unary operators + +`not` operator is followed by a space. Unary addition or subtraction, +including element-wise, are not. + +```modelica +-4 +.-(2 + 3) +not isOff +``` + +### Assignments and equalities + +`:=` and `=` tokens are surrounded with spaces. +Exception occurs when equality or assignment is +followed by a multiline if-expression. In such case the symbol is only +preceeded with a space. + +```modelica +foo = bar * 2 +Real foo(min = 0, max = 2) = 1 / 2 +foo := bar(x) +foo := if x < 2 then bar else baz +``` + +But: + +```modelica +foo := + if x < 2 then + bar + else + baz +``` + +### Arrays, modifications, function calls, expression lists + +If there is no line wrap every comma and semicolon is followed by a +space. This includes discarded slots in *output-expression-list*. + +```modelica +{1.0, 2.0, 3.0} // Array +enthalpy_pT(p, T) // Function call +(foo, ,bar, baz) // Output expression list with a discared second element +[x, y; a, b] // Matrix +``` + +## Indentation + +Indentation is 2 spaces per level. + +Modelica doesn't use indentation to define the scope, but it is +nonetheless useful to use it to enhance readability. Descriptions and +annotations are good examples. Overall, indentation is increased at: + +* descriptions and annotations +* constraining clauses +* elements, equations, statements and external function calls +* enumeration items +* inside loops and if blocks + +### Descriptions, annotations and constraining clauses + +Indentation is increased only one time per element. + +```modelica +replaceable package Medium = Modelica.Media.R134a.R134a_ph + constrainedby Modelica.Media.Interfaces.PartialMedium + "Fluid medium" + annotation(Dialog(tab = "General", group = "Medium")); +``` + +### Element, statement and equation lists + +Indentation is increased once per section. + +```modelica +model Model + "Some model" + + import FooPackage; + import Modelica.Constants.inf; + + // SNAP + +protected + + parameter FooPackage foo + "foo parameter"; + +equation + + // SNAP + foo = bar; + +end Model; +``` + +### Enumeration items + +Indentation is increased inside `enumeration()` and at every +description. + +```modelica +type BoundaryType = enumeration( + Pressure + "Pressure boundary", + Flow + "Flow boundary") + "Enumeration of possible boundary types"; +``` + +### Loops and ifs + +Indentation is increased once per block. + +```modelica +if foo == bar then + baz := bark; + bam := bem; +else + baz := 0; + bam := 1; +end if; +``` + +## Vertical spacing + +Beside indented elements described in the previous section, a newline or +two are inserted after every element, statement or equation. + +Additionally, a single blank is inserted: + +* before and after section keywords like `equation` or `protected` +* before and after the *composition* production +* before class-wide annotation in the *long-class-specifier* + +## Line wrapping + +### Function calls, arrays, matrices, modifications, lists + +The main rule here is: be consistent. The following approach is applied: + +1. If line is wrapped at any argument, then wrap at every argument. +2. If line is wrapped inside a nested construct, then wrap at every + argument in every outer construct. + +Indentation is increased accordingly to help visually identify the +scope. + +```Modelica +// No wrap is fine +h = enthalpy_pT(p, T) + +// Outer array is wrapped, but inner ones are kept intact +parameter Real A[2, 3] = { + {1.0, 2.0, 3.0}, + {5.0, 6.0, 7.0}} + +// In nested function call, if inner call is wrapped, outer call is +// wrapped as well +cp_a = specificHeat_pT( + p = p_a, + T = temperature_ph( + p = p_a, + h = h_a)) + +// But it is fine to wrap only outer call, keeping inner one intact +cp_b = specificHeat_pT( + p = p_b, + T = temperature_ph(p = p_b, h = h_b)); + +// Wrapped comprehensions are little bit special +{ + a[i] * b[i] + for i in 1 : n} + +// Output expression lists +( + foo, + bar) := baz(x, y) + +// Import lists +import Modelica.Constants.{ + pi, + inf}; +``` + +### Expressions + +Expressions (arithmetic, logical etc.) are handled in a very same way as +function calls and arrays. The difference is that instead of commas line +is wrapped before binary operators. Wrapping is applied to all operators +of the same precedence (as defined by the grammar). If wrap occured +inside higher precedence (inner) part, lower precedence (outer) parts +are wrapped as well. + +```Modelica +// No wrap +foo = bar + baz + +// Outer rule wrapped +foo := 2 + * (bar - baz) + / 5 + +// Some inner rule wrapped +foo := -2 + + bam + / baz ^ 2 + * bark + - 33 +``` From b1458a2b36fb4a4388c96dcd3926e419f39ade5a Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 17:44:32 +0100 Subject: [PATCH 66/67] Update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 5263071..4fab94b 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ language. It aims to enhance readability and provide style constistency across different Modelica projects. -*mofmt* doesn't modify files if it meets syntax errors. - Code style applied by the *mofmt* is described in `code-style.md`. ## Installation and usage From 0c76a0a1fe579d0015cd44b76b523851b71eeeec Mon Sep 17 00:00:00 2001 From: Eryk Mroczek Date: Mon, 5 Feb 2024 17:46:49 +0100 Subject: [PATCH 67/67] Include general subscripting example in code samples --- tests/samples/code-input.mo | 2 ++ tests/samples/code-output.mo | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo index 24563d2..84a2bb4 100644 --- a/tests/samples/code-input.mo +++ b/tests/samples/code-input.mo @@ -48,6 +48,8 @@ parameter Real[1] foo = if bar then 2 elseif baz then 3 else 4; Integer[1, 3, 4] bar =if true then 1 elseif baz<2 then 3 else 2; +Real smallest=(Modelica.Math.Vectors.sort({4,2,5,1}))[1]; + protected // Here we have to comments diff --git a/tests/samples/code-output.mo b/tests/samples/code-output.mo index dd9c7df..c071a83 100644 --- a/tests/samples/code-output.mo +++ b/tests/samples/code-output.mo @@ -59,6 +59,8 @@ final partial model FooModel else 2; + Real smallest = (Modelica.Math.Vectors.sort({4, 2, 5, 1}))[1]; + protected // Here we have to comments