spec_to_rest
Parser reuse

What the parser must handle

Edit on GitHub

The constructs the spec language has to parse

Last updated:

The spec language is small but specific, and the constructs it has to parse are the yardstick every reuse candidate is measured against. They come straight from its grammar.

ConstructWhat it isExample
Entity declarationstyped fields with multiplicities and inline where constraintsentity UrlMapping { code: ShortCode where len(code) >= 6 }
State declarationsmutable service state as typed relationsstate { store: ShortCode -> lone LongURL }
Operations with contractsinput and output, plus requires and ensuresoperation Shorten { requires: ... ensures: ... }
Invariants and factsglobal constraints that always holdinvariant: isValidURI(url)
Transition declarationsentity lifecycle state machinestransition Lifecycle { Active -> Suspended via Suspend }
Convention blocksHTTP mapping overridesconventions { Resolve.http_method = "GET" }
Multiplicity annotationsone, lone, some, set on relationstags: Post -> set Tag
Quantified expressionsall, some, no, exists over a setall c in store | store[c] != none
Primed and pre-stateafter-state and before-state referencesstore' = pre(store) + {code -> url}
Relational typestyped relations with a multiplicitymapping: ShortCode -> lone LongURL
Refinement typesa base type narrowed by a predicatetype Email = String where value matches /.../
Cardinality operator# for collection size#store' = #store + 1
Collection typesparameterized Set, Map, SeqSet[UrlMapping], Map[String, Int]
Enum declarationsfinite value typesenum Status { Active, Suspended, Deleted }

No single existing language offers all of them. The set borrows on purpose from several traditions: Alloy's relational modeling and multiplicities, the pre- and postcondition style of VDM and Dafny, Quint's readable surface syntax, and the HTTP-override idea from TypeSpec and Smithy. That spread is exactly why reusing one parser wholesale is hard, and the next two pages weigh the attempt, the formal-methods languages first, then the API description languages.