Allow unbounded / untyped record type constraints

This commit is contained in:
Tobie Morgan Hitchcock 2023-03-26 23:54:57 +01:00
parent 3f5347e4b3
commit 6ede630d41
2 changed files with 3 additions and 3 deletions

View file

@ -7,7 +7,7 @@ use nom::branch::alt;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::character::complete::char; use nom::character::complete::char;
use nom::combinator::map; use nom::combinator::map;
use nom::multi::separated_list1; use nom::multi::{separated_list0, separated_list1};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
@ -76,7 +76,7 @@ fn record(i: &str) -> IResult<&str, Vec<Table>> {
let (i, _) = tag("record")(i)?; let (i, _) = tag("record")(i)?;
let (i, _) = mightbespace(i)?; let (i, _) = mightbespace(i)?;
let (i, _) = char('(')(i)?; let (i, _) = char('(')(i)?;
let (i, v) = separated_list1(commas, table)(i)?; let (i, v) = separated_list0(commas, table)(i)?;
let (i, _) = char(')')(i)?; let (i, _) = char(')')(i)?;
Ok((i, v)) Ok((i, v))
} }

View file

@ -762,7 +762,7 @@ impl Value {
/// Check if this Value is a Thing of a specific type /// Check if this Value is a Thing of a specific type
pub fn is_type_record(&self, types: &[Table]) -> bool { pub fn is_type_record(&self, types: &[Table]) -> bool {
match self { match self {
Value::Thing(v) => types.iter().any(|tb| tb.0 == v.tb), Value::Thing(v) => types.is_empty() || types.iter().any(|tb| tb.0 == v.tb),
_ => false, _ => false,
} }
} }