Ion codec for Morphir IR: v4 #942
Replies: 4 comments
|
Checkpoint 2. v4 attributes are a struct: type nodes carry A hole expression is The opening post is the current note. The document literal is the next slice. |
|
Checkpoint 3. A v4 document literal is A v4 float literal that keeps its source text is That covers the remaining v4 literal. Package-specification annotations stay with issue 944. The opening post is the current note. |
Document tree. An Ion document tree is the same logical tree as the JSON and YAML profiles. The profile name is Each file is one Ion value. Its members are the members of the JSON document-tree file at the same logical path: A writer emits the JSON profile's canonical text: one object, spaces inside the braces, no trailing newline. A reader accepts that text. It also accepts Ion text whose field names are symbols. It reads an S-expression as a list and ignores annotations on a value. It rejects a blob, a clob, a timestamp, a symbol value, and a duplicate field name. A non-integer Ion decimal is read through Ion's display (
Logical paths carry no extension.
An application puts
A hand-written type file with symbol field names reads as the same value: A 4.0.0 tree has no member for a module specification's Morphir The v3 thread records the single-file side: #938. The draft section is |
|
Document tree, revised. This design replaces the earlier document-tree comment. Tree files no longer hold JSON-shaped values. Each file holds the same annotated elements as the single-file distribution. The path is the scope. The same rules apply to v3 (discussion 938). The work is on branch PathsThe tree uses the same paths as the JSON and YAML trees. The extension is
Directory segments and stems are escaped file stems. The path supplies the package, the module, and the name of a node. A file may omit A root with Manifest
No tree file has a Module, type, and value filesUnder Under
A type file holds exactly one type. A value file holds exactly one value. Merge and orderThe merge is additive, with the same rules as the single file. The module file comes first. The type files come next, and the value files come last. Each group is in path order. The reader refuses a type or value that the merge defines twice. A tree orders modules and members by path. WriterThe writer puts only the module header in ExampleA v4 library
The tree reads as this datagram:
A file may write a name that the path supplies, if the name matches. These files read the same as the files above.
The reader refuses this CoverageCoverage matches the single-file Ion codec. Today that codec reads and writes a v4 library. Specs and application distributions come later. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Ion codec for Morphir IR, v4
This note continues discussion 938. The v3 rules stay in force: two layouts, the annotation DSL, spec grouping, empty-array omission, and expression S-expressions.
ionVersionstays0.1.0-draft.1while this draft is refined in place.formatVersionis4.0.0.The local copy lives in
.dev/and is not committed.Checkpoint log
Decisions
formatVersion: "4.0.0"selects the v4 IR. A v3 reader rejects a v4-only node. A v4 reader accepts the v3 expression heads and the v4 nodes in this note.kindislibrary,specs, orapplication.librarycarries its own package as definitions and its dependencies as specifications.specsdistribution carries its own package and its dependencies as specifications. Amodule::specwith nopackagefield belongs to the header package.applicationcarries its own package and its dependencies as definitions.package::defgroups those definition modules the same waypackage::specgroups specification modules. Inline modules combine with top-level modules for that package, in document order. A repeated type or value name in the merged module is rejected.morphirblock of an application. The field is omitted forlibraryandspecs.public::def::valueorprivate::def::value. The other v4 bodies are modifiers in front ofvalue:native::value,external::value, andincomplete::value.inputTypesandinputsare structs keyed by parameter name. Field order is parameter order. A local name that is not an Ion identifier is a quoted symbol.outputTypeis required on an expression, native, and external body, and optional on an incomplete body.source,constraints, andextensions. Value attributes, including patterns, may carrysource,inferredType, andextensions. Empty members are omitted. An empty attribute struct is omitted. On an S-expression the struct follows the head.(hole reason)or(hole reason expectedType). The reason uses the same spellings as an incomplete body.public::def::incomplete::typeorprivate::def::incomplete::type. It carriesincompletenessand an optionalpartialTypeExp.annotationslist on a specification. A definition rejects that field. A compact annotation is the stringpkg:mod#localorpkg:mod#local:free text. A structured annotation is{ name, arguments }. Arguments are value expressions, or{ name, value }when named.(document <payload>). The payload is the document itself. It is a tree ofnull, bool, string, number, list, and struct. A number with no point and no exponent is an Ion int. Any other number is an Ion decimal written with the stored lexeme. Ion float, timestamp, blob, clob, symbol, and s-expression are rejected inside the payload. A document is rejected in pattern position, and a v3 reader rejects thedocumenthead.(float "<lexeme>"). A bare Ion float means the lexeme is the shortest spelling of that finite value. The lexeme is not part of the literal's identity.Distributions
An entry point name is the field name.
targetis a canonical fully qualified name.kindis the symbolmain,command,handler,job, orpolicy.docis omitted when absent. An emptyentryPointsstruct is omitted.A
specsdistribution writes its own modules asmodule::specand its members aspublic::spec::.... Dependency modules setpackageto the other package name.An application dependency uses
package::def. Its modules are access-controlled definitions. A top-levelpublic::def::moduleorprivate::def::modulewith the samepackagecombines with the inline list.The reader's dependency order is still the order of first mention.
Value bodies
inputTypeson a definition andinputson a specification are structs. Order is the parameter order.A native body has no expression.
hintisarithmetic,comparison,stringOp, orcollectionOp. A platform hint isplatformSpecificwith aplatformstring.descriptionis omitted when absent.An external body has one binding per target platform.
bodyis the optional fallback expression.An incomplete body may omit
outputType.incompletenessisdraft, orholewith a reason.partialBodyis omitted when the author left none. A hole reason isunresolvedReferencewithtarget,deletedDuringRefactorwithtxId, ortypeMismatchwithexpectedandfound.The v3 expression heads stay valid. The v4 record-update node uses the same
(update record (fieldName value))head.Attributes
sourcecarriesstartLine,startColumn,endLine, andendColumn. All four are required whensourceis present.constraintsandextensionsare structs whose values are JSON-compatible Ion: null, bool, number, string, list, and struct. A symbol there is rejected, so the payload still fits the IR's JSON value.inferredTypeis a type expression.A pattern uses the same value-attribute struct.
(as {attributes: { inferredType: "morphir/SDK:basics#int" }} (wildcard) score)is a binding with an inferred type.Hole expressions
A hole is a value expression. It is not a definition body. The reason is
unresolvedReference,deletedDuringRefactor, ortypeMismatch, with the same fields as an incomplete value body.expectedTypeis omitted when the hole has none.A v3 reader rejects
hole.Incomplete types
partialTypeExpis omitted when the author left none.typeParamsis omitted when empty. The incompleteness spellings match the incomplete value body. Inside a hole incompleteness,partialBodyis the type expression the author had written, and it is omitted when absent.Morphir annotations
The field is
annotations, written only when the list is non-empty. It may appear onmodule::spec, on apublic::spec::type, and onpublic::spec::value. Adefnode rejects it.A positional argument is a value expression. A named argument is a struct with
nameandvalue. Emptyargumentsare omitted.Document literal
Decision 0013 adds one v4 literal. Its type is the opaque SDK type
morphir/SDK:document#document. The payload is the document verbatim, so the sexpr has one argument and that argument is the tree.{ "value": 1 }inside the payload is a one-member document, not a wrapper around the document.ageis an Ion int.idis an Ion int of arbitrary precision, so it does not pass through a 64-bit float.ratiois an Ion decimal written0.10. The reader stores that lexeme. A number whose lexeme has a point or an exponent is never an Ion float.The payload also allows a scalar.
(document null),(document true), and(document "Alice")are documents. Struct field order is the object order. A duplicate field name is rejected. A field name that is not an Ion identifier is a quoted symbol.These values are rejected inside the payload: an Ion float, a timestamp, a blob, a clob, a symbol used as a value, and an s-expression. Decision 0013 leaves out binary, timestamp, decimal-as-its-own-node, and reference extensions.
A literal pattern cannot hold a document.
(document ...)in pattern position is rejected. A v3 reader rejects thedocumenthead, as it rejectshole.Float lexemes
A v4 float literal stores the text it was written with. Two float literals are the same literal when they denote the same number. The lexeme is for writers that must reproduce the source.
A bare Ion float, such as
100.0, means the lexeme is the shortest spelling of that finite value.NaN, an infinity, and a magnitude nof64can hold are rejected. A v3 float stays a bare Ion float. v3 stores anf64and has no lexeme.Next checkpoint
None. The v3 and v4 IR nodes now have an Ion spelling. Package-specification annotations stay out until issue 944 decides them.
All reactions