Skip to content

Commit

Permalink
Merge pull request #244 from Nahuel-M/master
Browse files Browse the repository at this point in the history
Fixed bug in logical_listeral parser
  • Loading branch information
ytanimura committed Aug 16, 2023
2 parents d7f93bf + 7124ce8 commit 520dcb5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ In addition to original Keep-a-Changelog, we use following rules:
- Recursive `get_owned` for select type without boxed variant. https://github.com/ricosjp/ruststep/pull/234

### Fixed
- Fixed bug in logical_listeral parser. https://github.com/ricosjp/ruststep/pull/244
- Deseialize `Option::Some`. https://github.com/ricosjp/ruststep/pull/232
- Recursive implementation of `ruststep::tables::EntityTable::{get_owned, owned_iter}` for select types. https://github.com/ricosjp/ruststep/pull/230

Expand Down Expand Up @@ -114,4 +115,4 @@ In addition to original Keep-a-Changelog, we use following rules:

## 0.1.0 - 2021-09-28

See https://github.com/ricosjp/ruststep/releases/tag/ruststep-0.1.0
See https://github.com/ricosjp/ruststep/releases/tag/ruststep-0.1.0
7 changes: 7 additions & 0 deletions espr/src/parser/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ pub fn not<'a>(f: impl EsprParser<'a, &'a str>) -> impl EsprParser<'a, &'a str>
}
}

pub fn peek<'a>(f: impl EsprParser<'a, &'a str>) -> impl EsprParser<'a, &'a str> {
move |input: &'a str| {
let (input, _) = nom::combinator::peek(f.clone())(input)?;
Ok((input, ("", Vec::new())))
}
}

pub fn char<'a>(c: char) -> impl EsprParser<'a, char> {
move |input| {
let (input, c) = nom::character::complete::char(c)(input)?;
Expand Down
12 changes: 8 additions & 4 deletions espr/src/parser/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ pub fn literal(input: &str) -> ParseResult<Literal> {

/// 255 logical_literal = `FALSE` | `TRUE` | `UNKNOWN` .
pub fn logical_literal(input: &str) -> ParseResult<Logical> {
alt((
value(Logical::True, tag("TRUE")),
value(Logical::False, tag("FALSE")),
value(Logical::Unknown, tag("UNKNOWN")),
tuple((
alt((
value(Logical::True, tag("TRUE")),
value(Logical::False, tag("FALSE")),
value(Logical::Unknown, tag("UNKNOWN")),
)),
peek(not(remarked(nom::character::complete::alpha1))),
))
.map(|(logical, _non_alpha)| logical)
.parse(input)
}

Expand Down
47 changes: 47 additions & 0 deletions espr/tests/logical_literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use espr::{ast::SyntaxTree, codegen::rust::*, ir::IR};

const EXPRESS: &str = r#"
SCHEMA IFC4X3_DEV_6a23ae8;
ENTITY IfcGeometricRepresentationContext;
TrueNorth : OPTIONAL BOOLEAN;
WHERE
North2D : NOT(EXISTS(TrueNorth)) OR (HIINDEX(TrueNorth.DirectionRatios) = 2);
END_ENTITY;
END_SCHEMA;
"#;

#[test]
fn logical_literal() {
let st = SyntaxTree::parse(EXPRESS).unwrap();
let ir = IR::from_syntax_tree(&st).unwrap();
let tt = ir.to_token_stream(CratePrefix::External).to_string();

let tt = rustfmt(tt);

insta::assert_snapshot!(tt, @r###"
pub mod IFC4X3_DEV_6a23ae8 {
use ruststep::{as_holder, derive_more::*, primitive::*, Holder, TableInit};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Default, TableInit)]
pub struct Tables {
IfcGeometricRepresentationContext:
HashMap<u64, as_holder!(IfcGeometricRepresentationContext)>,
}
impl Tables {
pub fn IfcGeometricRepresentationContext_holders(
&self,
) -> &HashMap<u64, as_holder!(IfcGeometricRepresentationContext)> {
&self.IfcGeometricRepresentationContext
}
}
#[derive(Debug, Clone, PartialEq, :: derive_new :: new, Holder)]
# [holder (table = Tables)]
# [holder (field = IfcGeometricRepresentationContext)]
#[holder(generate_deserialize)]
pub struct IfcGeometricRepresentationContext {
pub TrueNorth: Option<bool>,
}
}
"###);
}

0 comments on commit 520dcb5

Please sign in to comment.