Expand description
OSD (Omnist Schema Definition) – the text language for the crate::schema
model. Ported from ~/dev/omnist/omnist/osd.py.
Grammar (informal):
schema := record* 'root' NAME
record := 'record' NAME '{' field (',' field)* ','? '}'
field := STRING cardinality? ':' type
cardinality := '[' INT? (',' INT?)? ']' -- [m,n] [m,] [,n] [n]; absent = [1,1]
type := SCALARNAME '?'? | NAME -- one scalar, or one RefQuoting rule: a "quoted" token is always a field label (data string);
an unquoted identifier is always a schema name (scalar keyword or Ref).
There is no value-domain composition (no |, enum, literal fields, or
union).
§The any keyword
Python’s osd.py recognizes "any" as a reserved type keyword and
parses it to ANY (RESERVED_TYPE_NAMES = SCALAR_NAMES | {"any"}). This
module mirrors that: any in a type position parses to
crate::schema::FieldType::Any, and – exactly like Python – any is
still a reserved name that cannot be used as a record name (matching the
grammar). Since Any already includes null, a trailing ? after any
("a": any?) is a SchemaError (“redundant”), not silently accepted.
Functions§
- parse_
schema - Parse OSD text into a
Schema. - to_osd
- Serialize a
Schemaback to OSD text. Ported from Python’sosd.to_osd/_record/_field/_card/_type.