Skip to content

Commit

Permalink
Improved parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jul 29, 2024
1 parent 764a541 commit 693a0d0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
24 changes: 9 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ pub fn main_args(args: Args) -> Result<(), WErr> {
let parsed = parse(PathBuf::from(&args.input))?;
);

println!("{:#?}", parsed);

print!("Resolving Names... ");
time!(
let (global_table, unprocessed_functions) = resolve(parsed)?;
Expand Down
32 changes: 12 additions & 20 deletions src/root/parser/parse_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
use crate::root::parser::parse::{ErrorTree, ParseResult, Span};
use crate::root::parser::parse_blocks::take_until_discard_smart;
use crate::root::parser::parse_blocks::{take_until_discard_smart, take_until_or_end_discard_smart};
use crate::root::parser::parse_function::parse_evaluable::{
parse_evaluable, EvaluableToken, EvaluableTokens,
};
use crate::root::parser::parse_name::SimpleNameToken;
use nom::bytes::complete::take_until;
use nom::InputTake;
use crate::root::parser::parse_util::discard_ignored;

pub fn parse_arguments<'a, 'b>(
s: Span<'a>,
containing_class: Option<&'b SimpleNameToken>,
) -> ParseResult<'a, (), Vec<EvaluableToken>> {
let mut s = s;
println!("ARGS SPAN - {}", s);
let mut args = Vec::new();
let mut last = false;

loop {
// TODO: Account for brackets
let (ns, section) = if let Ok((ns, section)) = take_until_discard_smart(s, ",") {
(ns, section)
} else {
last = true;
s.take_split(s.len())
};
let (ns, _) = discard_ignored(s)?;
let (ns, section) = take_until_or_end_discard_smart(ns, ",")?;

let res = parse_evaluable(section, containing_class, false)?.1;

if matches!(res.token(), EvaluableTokens::None) {
if !last {
todo!() // Expected evaluable
}
} else {
args.push(res);
if section.is_empty() {
break;
}

let res = parse_evaluable(section, containing_class, false)?.1;
args.push(res);

s = ns;
if last {
break;
}
}

println!("{}", args.len());

Ok(((), args))
}
8 changes: 4 additions & 4 deletions src/root/parser/parse_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn take_until_or_end_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseRes
let original = s.clone();
let mut s = s;
let mut found = false;
while !s.is_empty() {
'outer: while !s.is_empty() {
if let Ok((ns, _)) = tag::<&str, LocatedSpan<&str, &Rc<PathBuf>>, ErrorTree>(until)(s) {
found = true;
s = ns;
Expand All @@ -132,7 +132,7 @@ pub fn take_until_or_end_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseRes
for t in &DEFAULT_TERMINATORS {
if t.opening == c {
s = parse_terminator_default_set(s, t)?.0;
continue;
continue 'outer;
}
}

Expand All @@ -151,7 +151,7 @@ pub fn take_until_or_end_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseRes
pub fn take_until_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseResult<'a> {
let original = s.clone();
let mut s = s;
loop {
'outer: loop {
if s.is_empty() {
return Err(nom::Err::Error(ErrorTree::from_error_kind(
original,
Expand All @@ -169,7 +169,7 @@ pub fn take_until_discard_smart<'a>(s: Span<'a>, until: &str) -> ParseResult<'a>
for t in &DEFAULT_TERMINATORS {
if t.opening == c {
s = parse_terminator_default_set(s, t)?.0;
continue;
continue 'outer;
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/root/parser/parse_function/parse_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ pub fn parse_evaluable<'a, 'b>(
semicolon_terminated: bool,
) -> ParseResult<'a, Span<'a>, EvaluableToken> {
let mut s = s;
println!("{s}");

let mut evaluables = Vec::new();

Expand All @@ -234,6 +233,16 @@ pub fn parse_evaluable<'a, 'b>(
// Terminate on semicolon if semicolon terminated
if semicolon_terminated {
if let Ok((ns, _)) = char::<_, ErrorTree>(';')(ns) {
if evaluables.is_empty() {
return Ok((
ns,
EvaluableToken {
location: Location::from_span(&ns),
token: EvaluableTokens::None,
},
));
}

s = ns;
break;
}
Expand Down

0 comments on commit 693a0d0

Please sign in to comment.