Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Oct 30, 2024
1 parent f8fff97 commit ff07e3e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
3 changes: 1 addition & 2 deletions klang/src/parser/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use super::ast::*;
use super::literals::parse_literal;
use super::parser::Rule;
use pest::iterators::Pair;

pub fn parse_expression(pair: pest::iterators::Pair<Rule>) -> Expression {
pub(crate) fn parse_expression(pair: pest::iterators::Pair<Rule>) -> Expression {
match pair.as_rule() {
Rule::expression => parse_expression(pair.into_inner().next().unwrap()),
Rule::conditional => parse_conditional(pair),
Expand Down
12 changes: 6 additions & 6 deletions klang/src/parser/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ast::*;
use super::parser::Rule;
use pest::iterators::Pair;

pub fn parse_function_def(function_def: Pair<Rule>) -> FunctionDef {
pub(crate) fn parse_function_def(function_def: Pair<Rule>) -> FunctionDef {
let mut name = String::new();
let mut parameters = Vec::new();
let mut doc_string = String::new();
Expand All @@ -26,7 +26,7 @@ pub fn parse_function_def(function_def: Pair<Rule>) -> FunctionDef {
}
}

pub fn parse_parameters(parameters: Pair<Rule>) -> Vec<Parameter> {
fn parse_parameters(parameters: Pair<Rule>) -> Vec<Parameter> {
let mut result = Vec::new();

for part in parameters.into_inner() {
Expand All @@ -41,7 +41,7 @@ pub fn parse_parameters(parameters: Pair<Rule>) -> Vec<Parameter> {
result
}

pub fn parse_parameter_value(parameter_value: Pair<Rule>) -> Parameter {
fn parse_parameter_value(parameter_value: Pair<Rule>) -> Parameter {
let mut identifier = String::new();
let mut param_type = String::new();

Expand All @@ -59,12 +59,12 @@ pub fn parse_parameter_value(parameter_value: Pair<Rule>) -> Parameter {
}
}

pub fn parse_doc_string(pair: Pair<Rule>) -> String {
fn parse_doc_string(pair: Pair<Rule>) -> String {
let inner = pair.into_inner().next().unwrap();
inner.as_str()[1..inner.as_str().len() - 1].to_string()
}

pub fn parse_block(pair: Pair<Rule>) -> Block {
fn parse_block(pair: Pair<Rule>) -> Block {
let statements = pair
.into_inner()
.filter_map(|p| {
Expand All @@ -79,7 +79,7 @@ pub fn parse_block(pair: Pair<Rule>) -> Block {
Block { statements }
}

pub fn parse_statement(pair: Pair<Rule>) -> Statement {
fn parse_statement(pair: Pair<Rule>) -> Statement {
let inner = pair.into_inner().next().unwrap();
match inner.as_rule() {
Rule::assignment_stmt => parse_assignment_statement(inner),
Expand Down
1 change: 0 additions & 1 deletion klang/src/parser/literals.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::ast::*;
use super::parser::Rule;
use pest::iterators::Pair;

pub(crate) fn parse_literal(pair: pest::iterators::Pair<Rule>) -> Expression {
let inner_pair = pair.into_inner().next().unwrap();
Expand Down
7 changes: 2 additions & 5 deletions klang/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ pub mod literals;
pub mod parser;
pub mod statements;

use expressions::*;
use functions::*;
use literals::*;
use parser::*;
use statements::*;
use functions::parse_function_def;
use parser::Rule;

pub fn parse_program(pair: pest::iterators::Pair<Rule>) -> Program {
let mut functions = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions klang/src/parser/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn parse_block(block: Pair<Rule>) -> Block {
Block { statements }
}

pub fn parse_assignment_stmt(assignment_stmt: Pair<Rule>) -> AssignmentStmt {
fn parse_assignment_stmt(assignment_stmt: Pair<Rule>) -> AssignmentStmt {
let mut identifier = String::new();
let mut operator = String::new();
let mut expression = None;
Expand All @@ -80,7 +80,7 @@ pub fn parse_assignment_stmt(assignment_stmt: Pair<Rule>) -> AssignmentStmt {
}
}

pub fn parse_loop_stmt(loop_stmt: Pair<Rule>) -> LoopStmt {
fn parse_loop_stmt(loop_stmt: Pair<Rule>) -> LoopStmt {
let mut body = None;

for part in loop_stmt.into_inner() {
Expand All @@ -95,7 +95,7 @@ pub fn parse_loop_stmt(loop_stmt: Pair<Rule>) -> LoopStmt {
LoopStmt { body }
}

pub fn parse_return_stmt(return_stmt: Pair<Rule>) -> ReturnStmt {
fn parse_return_stmt(return_stmt: Pair<Rule>) -> ReturnStmt {
let mut expression = None;

for part in return_stmt.into_inner() {
Expand Down

0 comments on commit ff07e3e

Please sign in to comment.