Skip to content

Commit

Permalink
use rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SkymanOne committed Mar 4, 2024
1 parent 76493af commit 5407790
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 234 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: continuous-integration

on: [push]


jobs:
tests:
name: Tests
Expand All @@ -22,5 +21,25 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --workspace --all-targets --all-features
- run: cargo fmt --check --all
- run: cargo doc --workspace --no-deps
- run: cargo doc --workspace --no-deps

rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt

- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check --verbose
60 changes: 60 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
max_width = 100 # changed
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
use_small_heuristics = "Default"
indent_style = "Block"
wrap_comments = true # changed
format_code_in_doc_comments = true # changed
doc_comment_code_block_width = 100 # changed
comment_width = 90 # changed
normalize_comments = true # changed
normalize_doc_attributes = false
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Vertical" # changed
imports_granularity = "Crate" # changed
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = false # changed
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = true # changed
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = false # changed
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2021" # changed
version = "One"
merge_derives = true
use_try_shorthand = true # changed
use_field_init_shorthand = true # changed
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
unstable_features = true # changed
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
ignore = []
12 changes: 7 additions & 5 deletions crates/derive_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ fn node_derive(mut s: synstructure::Structure) -> TokenStream2 {
.underscore_const(true);
match &s.ast().data {
syn::Data::Struct(_) => node_derive_struct(s).unwrap_or_else(|err| err.to_compile_error()),
_ => syn::Error::new(
s.ast().span(),
"can only derive `Node` for Rust `struct` items",
)
.to_compile_error(),
_ => {
syn::Error::new(
s.ast().span(),
"can only derive `Node` for Rust `struct` items",
)
.to_compile_error()
}
}
}

Expand Down
20 changes: 14 additions & 6 deletions crates/parser/src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use super::Span;
use logos::{Logos, SpannedIter};
use std::{fmt, num::ParseIntError};
use logos::{
Logos,
SpannedIter,
};
use std::{
fmt,
num::ParseIntError,
};
use thiserror::Error;

#[derive(Default, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -323,10 +329,12 @@ impl<'input> Iterator for Lexer<'input> {
fn next(&mut self) -> Option<Self::Item> {
if let Some((tok_res, span)) = self.token_stream.next() {
match tok_res {
Ok(tok) => match tok {
Token::Comment(_) => self.next(),
_ => Some((span.start, tok, span.end)),
},
Ok(tok) => {
match tok {
Token::Comment(_) => self.next(),
_ => Some((span.start, tok, span.end)),
}
}
Err(err) => {
self.errors.push(logos_to_lexical_error(&err, &span));
self.next()
Expand Down
23 changes: 16 additions & 7 deletions crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ pub mod lexer;

use ast::Source;
use folidity_diagnostics::Report;
use lalrpop_util::ParseError;
use lalrpop_util::{lalrpop_mod, ErrorRecovery};
use lexer::{Lexer, LexicalError, Token};
use lalrpop_util::{
lalrpop_mod,
ErrorRecovery,
ParseError,
};
use lexer::{
Lexer,
LexicalError,
Token,
};
use std::ops::Range;

pub type Span = Range<usize>;
Expand Down Expand Up @@ -54,10 +61,12 @@ impl From<LexicalError> for Report {
LexicalError::InvalidElseBlock(l) => {
Report::lexer_error(l, "Invalid branch block".to_string())
}
LexicalError::UnknownError => Report::lexer_error(
Range { start: 0, end: 0 },
"Unknown error occurred".to_string(),
),
LexicalError::UnknownError => {
Report::lexer_error(
Range { start: 0, end: 0 },
"Unknown error occurred".to_string(),
)
}
}
}
}
Expand Down
39 changes: 33 additions & 6 deletions crates/parser/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
use crate::{
ast::{
self, AccessAttribute, BinaryExpression, Declaration, EnumDeclaration, Expression,
FuncReturnType, FunctionCall, FunctionDeclaration, FunctionVisibility, Identifier, IfElse,
List, Mapping, MappingRelation, MemberAccess, ModelDeclaration, Param, Set, Source,
StBlock, StateDeclaration, Statement, StatementBlock, StructDeclaration, StructInit,
TypeVariant, UnaryExpression, Variable,
self,
AccessAttribute,
BinaryExpression,
Declaration,
EnumDeclaration,
Expression,
FuncReturnType,
FunctionCall,
FunctionDeclaration,
FunctionVisibility,
Identifier,
IfElse,
List,
Mapping,
MappingRelation,
MemberAccess,
ModelDeclaration,
Param,
Set,
Source,
StBlock,
StateDeclaration,
Statement,
StatementBlock,
StructDeclaration,
StructInit,
TypeVariant,
UnaryExpression,
Variable,
},
lexer::{
Lexer,
Token,
},
lexer::{Lexer, Token},
parse,
};

Expand Down
20 changes: 16 additions & 4 deletions crates/semantics/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
use std::{collections::HashSet, fmt::Display};
use std::{
collections::HashSet,
fmt::Display,
};

use derive_node::Node;
use folidity_parser::{
ast::{Identifier, MappingRelation},
ast::{
Identifier,
MappingRelation,
},
Span,
};
use indexmap::IndexMap;
use num_bigint::{BigInt, BigUint};
use num_bigint::{
BigInt,
BigUint,
};
use num_rational::BigRational;

use crate::{global_symbol::SymbolInfo, symtable::SymTable};
use crate::{
global_symbol::SymbolInfo,
symtable::SymTable,
};
use algonaut_core::Address;

#[derive(Clone, Debug, PartialEq, Node, Default)]
Expand Down
51 changes: 37 additions & 14 deletions crates/semantics/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
use std::collections::HashMap;

use folidity_diagnostics::Report;
use folidity_parser::ast::{self as parsed_ast, Identifier};
use folidity_parser::{ast::Source, Span};
use folidity_parser::{
ast::{
self as parsed_ast,
Identifier,
Source,
},
Span,
};
use indexmap::IndexMap;

use crate::ast::{
EnumDeclaration, Function, ModelDeclaration, Param, StateBody, StateDeclaration,
EnumDeclaration,
Function,
ModelDeclaration,
Param,
StateBody,
StateDeclaration,
StructDeclaration,
};

use crate::functions::function_decl;
use crate::global_symbol::SymbolInfo;
use crate::global_symbol::{GlobalSymbol, SymbolKind};
use crate::types::{
find_user_type_recursion, map_type, validate_fields, DelayedBounds, DelayedDeclaration,
DelayedDeclarations,
use crate::{
functions::function_decl,
global_symbol::{
GlobalSymbol,
SymbolInfo,
SymbolKind,
},
types::{
find_user_type_recursion,
map_type,
validate_fields,
DelayedBounds,
DelayedDeclaration,
DelayedDeclarations,
},
};

/// Arbitrary limit of a max number of topic.
Expand Down Expand Up @@ -83,9 +103,11 @@ impl ContractDefinition {
let mut delayed_bodies: Vec<DelayedDeclaration<parsed_ast::FunctionDeclaration>> =
Vec::new();

for f in tree.declarations.iter().filter_map(|d| match d {
parsed_ast::Declaration::FunDeclaration(func) => Some(func),
_ => None,
for f in tree.declarations.iter().filter_map(|d| {
match d {
parsed_ast::Declaration::FunDeclaration(func) => Some(func),
_ => None,
}
}) {
if let Ok(id) = function_decl(f, self) {
delayed_bodies.push(DelayedDeclaration {
Expand All @@ -100,7 +122,7 @@ impl ContractDefinition {
}
}

//todo: resolve bodies
// todo: resolve bodies
// for f in delayed_bodies {}
}

Expand All @@ -124,7 +146,8 @@ impl ContractDefinition {
let fields = self.analyze_fields(params, &state.decl.name);
Some(StateBody::Raw(fields))
}
// If the body is a model, then we need to resolve the model symbol in the symbol table
// If the body is a model, then we need to resolve the model symbol in the
// symbol table
Some(parsed_ast::StateBody::Model(ident)) => {
let Some(symbol) = GlobalSymbol::lookup(self, ident) else {
continue;
Expand Down
14 changes: 11 additions & 3 deletions crates/semantics/src/expression/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ use folidity_diagnostics::Report;
use folidity_parser::ast::Identifier;

use crate::{
ast::{Expression, FunctionType, TypeVariant, UnaryExpression},
ast::{
Expression,
FunctionType,
TypeVariant,
UnaryExpression,
},
contract::ContractDefinition,
global_symbol::SymbolKind,
symtable::{Scope, VariableSym},
types::{report_type_mismatch, ExpectedType},
symtable::Scope,
types::{
report_type_mismatch,
ExpectedType,
},
};

/// Resolve variable to a AST expression.
Expand Down
Loading

0 comments on commit 5407790

Please sign in to comment.