Skip to content

Commit

Permalink
Merge pull request #124 from niuez/fix_107
Browse files Browse the repository at this point in the history
[fix] empty struct instantiation syntax
  • Loading branch information
niuez authored Jan 23, 2022
2 parents eec5c91 + b738036 commit c64d184
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/expression/if_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl MoveCheck for IfExpr {
}
}


pub fn parse_if_expr(s: ContentStr<'_>) -> IResult<ContentStr<'_>, Expression> {
let (s, (_, _, if_cond, _, if_block, _, many, el_block, _)) = tuple((tag("if"), multispace1, parse_expression, multispace0, parse_block, multispace0,
many0(tuple((tag("else"), multispace1, tag("if"), multispace1, parse_expression, multispace0, parse_block, multispace0))),
Expand All @@ -134,5 +133,6 @@ pub fn parse_if_expr(s: ContentStr<'_>) -> IResult<ContentStr<'_>, Expression> {

#[test]
fn parse_if_expr_test() {
println!("{:?}", parse_if_expr("if a == b { c } else { d }".into_content(0)).ok());
println!("{:?}", parse_if_expr("if a == b { c } else { d }".into_content(0)).unwrap());
println!("{:?}", parse_if_expr("if a == b {} else { let a = 0; }".into_content(0)).unwrap());
}
6 changes: 5 additions & 1 deletion src/structs/struct_instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use nom::IResult;
use nom::character::complete::*;
use nom::multi::*;
use nom::sequence::*;
use nom::branch::*;
use nom::combinator::*;

use crate::identifier::{ Identifier, parse_identifier, Tag };
Expand Down Expand Up @@ -53,7 +54,10 @@ fn parse_member(s: ContentStr<'_>) -> IResult<ContentStr<'_>, (Identifier, (Expr

pub fn parse_struct_instantiation(s: ContentStr<'_>) -> IResult<ContentStr<'_>, UnaryExpr> {
let (s, ((struct_id, _, _, _, opts, _), range)) = with_range(tuple((parse_type_id, multispace0, char('{'), multispace0,
opt(tuple((parse_member, many0(tuple((multispace0, char(','), multispace0, parse_member))), opt(tuple((multispace0, char(',')))), multispace0))),
alt((
map(tuple((parse_member, many0(tuple((multispace0, char(','), multispace0, parse_member))), opt(tuple((multispace0, char(',')))), multispace0)), |p| Some(p)),
map(tuple((char(','), multispace0)), |_| None)
)),
char('}'))))(s)?;
let members = match opts {
None => HashMap::new(),
Expand Down

0 comments on commit c64d184

Please sign in to comment.