Code
Program's own code as data. Code models a running Program in two forms: the recursive Code.Language.Json.Value tree that mirrors the JSON command form every program is written in, and the serialised syntax tree under Code.Language.Program.Structure — modules, functions, records, unions, and the commands inside a body. Reader functions decode JSON into these structures, a stringifier serialises them back, and the Code.Parse helpers thread parsing state through a rule. Every value is reactive, so a decoded tree recomputes when its source text changes.
Contents
Types
- Code.Language.Json.Value
- Code.Language.Program.Structure.Argument
- Code.Language.Program.Structure.Assignment
- Code.Language.Program.Structure.AssignmentValue
- Code.Language.Program.Structure.BodyCommand
- Code.Language.Program.Structure.Constant
- Code.Language.Program.Structure.ConstantValue
- Code.Language.Program.Structure.Direction
- Code.Language.Program.Structure.Field
- Code.Language.Program.Structure.Function
- Code.Language.Program.Structure.FunctionBody
- Code.Language.Program.Structure.FunctionCall
- Code.Language.Program.Structure.Input
- Code.Language.Program.Structure.Module
- Code.Language.Program.Structure.ModuleContent
- Code.Language.Program.Structure.NativeType
- Code.Language.Program.Structure.PlatformImpl
- Code.Language.Program.Structure.Program
- Code.Language.Program.Structure.ProgramContent
- Code.Language.Program.Structure.Record
- Code.Language.Program.Structure.RecordBodyEntry
- Code.Language.Program.Structure.Return
- Code.Language.Program.Structure.Reverse
- Code.Language.Program.Structure.SetterPair
- Code.Language.Program.Structure.State
- Code.Parse.Result
- Code.Parse.Result.Error
- Code.Parse.Result.NoMatch
- Code.Parse.Result.Success
Functions
- Code.Language.Json.FromJsonArray
- Code.Language.Json.FromObjectFromStringMap
- Code.Language.Json.GetArray
- Code.Language.Json.GetArrayElement
- Code.Language.Json.GetArrayLength
- Code.Language.Json.GetBoolean
- Code.Language.Json.GetInteger
- Code.Language.Json.GetNumber
- Code.Language.Json.GetObject
- Code.Language.Json.GetObjectField
- Code.Language.Json.GetString
- Code.Language.Json.OptionalGetArray
- Code.Language.Json.OptionalGetArrayElement
- Code.Language.Json.OptionalGetInteger
- Code.Language.Json.OptionalGetObject
- Code.Language.Json.OptionalGetObjectField
- Code.Language.Json.OptionalStringify
- Code.Language.Json.OptionalText
- Code.Language.Json.Parse
- Code.Language.Json.Stringify
- Code.Language.Program.Structure.Argument.FromJson
- Code.Language.Program.Structure.Assignment.FromJson
- Code.Language.Program.Structure.AssignmentValue.FromJson
- Code.Language.Program.Structure.BodyCommand.FromJson
- Code.Language.Program.Structure.Constant.FromJson
- Code.Language.Program.Structure.ConstantValue.FromJson
- Code.Language.Program.Structure.Direction.FromJson
- Code.Language.Program.Structure.Field.FromJson
- Code.Language.Program.Structure.Function.FromJson
- Code.Language.Program.Structure.FunctionBody.FromJson
- Code.Language.Program.Structure.FunctionCall.FromJson
- Code.Language.Program.Structure.Input.FromJson
- Code.Language.Program.Structure.Module.FromJson
- Code.Language.Program.Structure.ModuleContent.FromJson
- Code.Language.Program.Structure.NativeType.FromJson
- Code.Language.Program.Structure.PlatformImpl.FromJson
- Code.Language.Program.Structure.Program.FromJson
- Code.Language.Program.Structure.ProgramContent.FromJson
- Code.Language.Program.Structure.Record.FromJson
- Code.Language.Program.Structure.RecordBodyEntry.FromJson
- Code.Language.Program.Structure.Return.FromJson
- Code.Language.Program.Structure.Reverse.FromJson
- Code.Language.Program.Structure.SetterPair.FromJson
- Code.Language.Program.Structure.State.FromJson
- Code.Language.Program.Structure.StringFromJson
- Code.Parse.Context.WithInput
- Code.Parse.Context.WithMutable
- Code.Parse.State.GetIndex
- Code.Parse.State.GetValue
- Code.Parse.State.Set
- Code.Parse.State.SetIndex
Types
Code.Language.Json.Value
A JSON value: text, a number, a boolean, an array of values, or an object mapping names to values. Arrays and objects nest, so the type is recursive.
Options
| Option | Type | Description |
|---|---|---|
boolean | Logic.Maybe | The boolean case. |
number | Maths.Real | The number case. |
text | Text | The text case. |
array | Collection.Array(Code.Language.Json.Value) | An ordered array of nested values. |
object | Collection.Map(Code.Language.Json.Value) | An object mapping names to nested values. |
Definition
TYPE Code.Language.Json.Value
OPTION Logic.Maybe boolean
OPTION Maths.Real number
OPTION Text text
OPTION Collection.Array(Code.Language.Json.Value) array
OPTION Collection.Map(Code.Language.Json.Value) objectExample
LET Code.Language.Json.Value payload = Code.Language.Json.FromObjectFromStringMap fieldsCode.Language.Program.Structure.Argument
An argument in a function call: a reference to a value, an inline closure, or an inline constant.
Options
| Option | Type | Description |
|---|---|---|
reference | Text | A reference to a value by name. |
closure | Code.Language.Program.Structure.Function | An inline closure function. |
inlineConstant | Code.Language.Program.Structure.ConstantValue | An inline literal constant. |
Definition
TYPE Code.Language.Program.Structure.Argument
OPTION Text reference
OPTION Code.Language.Program.Structure.Function closure
OPTION Code.Language.Program.Structure.ConstantValue inlineConstantCode.Language.Program.Structure.Assignment
An assignment (=) command: a named, typed local bound to a computed value.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The local name. |
type | Text | The declared type. |
value | Code.Language.Program.Structure.AssignmentValue | The value bound to the name. |
Definition
TYPE Code.Language.Program.Structure.Assignment
FIELD Text name
FIELD Text type
FIELD Code.Language.Program.Structure.AssignmentValue valueCode.Language.Program.Structure.AssignmentValue
The right-hand side of an assignment: a reference to a value, or a function call.
Options
| Option | Type | Description |
|---|---|---|
reference | Text | A reference to a value by name. |
call | Code.Language.Program.Structure.FunctionCall | A function call. |
Definition
TYPE Code.Language.Program.Structure.AssignmentValue
OPTION Text reference
OPTION Code.Language.Program.Structure.FunctionCall callCode.Language.Program.Structure.BodyCommand
One command inside a function body: a comment, state, constant, assignment, call, or reverse.
Options
| Option | Type | Description |
|---|---|---|
comment | Text | A comment line. |
state | Code.Language.Program.Structure.State | A state declaration. |
constant | Code.Language.Program.Structure.Constant | A constant declaration. |
assignment | Code.Language.Program.Structure.Assignment | An assignment. |
call | Code.Language.Program.Structure.FunctionCall | A function call. |
reverse | Code.Language.Program.Structure.Reverse | A reverse command. |
Definition
TYPE Code.Language.Program.Structure.BodyCommand
OPTION Text comment
OPTION Code.Language.Program.Structure.State state
OPTION Code.Language.Program.Structure.Constant constant
OPTION Code.Language.Program.Structure.Assignment assignment
OPTION Code.Language.Program.Structure.FunctionCall call
OPTION Code.Language.Program.Structure.Reverse reverseCode.Language.Program.Structure.Constant
A constant (#) command: a named, typed constant with its literal value.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The constant name. |
type | Text | The declared type. |
value | Code.Language.Program.Structure.ConstantValue | The literal value. |
Definition
TYPE Code.Language.Program.Structure.Constant
FIELD Text name
FIELD Text type
FIELD Code.Language.Program.Structure.ConstantValue valueCode.Language.Program.Structure.ConstantValue
A literal constant value: text, integer, real, boolean, or none.
Options
| Option | Type | Description |
|---|---|---|
text | Text | A text literal. |
integer | Maths.Integer | An integer literal. |
real | Maths.Real | A real literal. |
boolean | Logic.Maybe | A boolean literal. |
none | Collection.Void | The empty (none) literal. |
Definition
TYPE Code.Language.Program.Structure.ConstantValue
OPTION Text text
OPTION Maths.Integer integer
OPTION Maths.Real real
OPTION Logic.Maybe boolean
OPTION Collection.Void noneCode.Language.Program.Structure.Direction
The direction of an input or return: forward, reverse, or binding.
Options
| Option | Type | Description |
|---|---|---|
forward | Collection.Void | The forward case. |
reverse | Collection.Void | The reverse case. |
binding | Collection.Void | The binding case. |
Definition
TYPE Code.Language.Program.Structure.Direction
OPTION Collection.Void forward
OPTION Collection.Void reverse
OPTION Collection.Void bindingCode.Language.Program.Structure.Field
A named, typed field within a record or union type.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The field name. |
type | Text | The field type. |
Definition
TYPE Code.Language.Program.Structure.Field
FIELD Text name
FIELD Text typeCode.Language.Program.Structure.Function
A function or native declaration: its name, generics, inputs, body, and optional return.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The function name. |
genericTypes | Collection.Array(Text) | The generic type parameter names. |
inputs | Collection.Array(Code.Language.Program.Structure.Input) | The declared inputs. |
body | Code.Language.Program.Structure.FunctionBody | The body or native implementations. |
optionalReturn | Collection.Optional(Code.Language.Program.Structure.Return) | The return declaration, if any. |
Definition
TYPE Code.Language.Program.Structure.Function
FIELD Text name
FIELD Collection.Array(Text) genericTypes
FIELD Collection.Array(Code.Language.Program.Structure.Input) inputs
FIELD Code.Language.Program.Structure.FunctionBody body
FIELD Collection.Optional(Code.Language.Program.Structure.Return) optionalReturnCode.Language.Program.Structure.FunctionBody
A function body: either a list of commands, or a map of per-platform native implementations.
Options
| Option | Type | Description |
|---|---|---|
body | Collection.Array(Code.Language.Program.Structure.BodyCommand) | The command list for a Program function. |
implementations | Collection.Array(Code.Language.Program.Structure.PlatformImpl) | The per-platform code for a native function. |
Definition
TYPE Code.Language.Program.Structure.FunctionBody
OPTION Collection.Array(Code.Language.Program.Structure.BodyCommand) body
OPTION Collection.Array(Code.Language.Program.Structure.PlatformImpl) implementationsCode.Language.Program.Structure.FunctionCall
A call to a function, with its name, type arguments, and arguments.
Fields
| Field | Type | Description |
|---|---|---|
functionName | Text | The called function name. |
typeArguments | Collection.Array(Text) | The type arguments. |
arguments | Collection.Array(Code.Language.Program.Structure.Argument) | The call arguments. |
Definition
TYPE Code.Language.Program.Structure.FunctionCall
FIELD Text functionName
FIELD Collection.Array(Text) typeArguments
FIELD Collection.Array(Code.Language.Program.Structure.Argument) argumentsCode.Language.Program.Structure.Input
A function input: its name, type, and direction.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The input name. |
type | Text | The input type. |
direction | Code.Language.Program.Structure.Direction | The input direction. |
Definition
TYPE Code.Language.Program.Structure.Input
FIELD Text name
FIELD Text type
FIELD Code.Language.Program.Structure.Direction directionCode.Language.Program.Structure.Module
A module declaration: its name and its contents.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The module name. |
contents | Collection.Array(Code.Language.Program.Structure.ModuleContent) | The module members. |
Definition
TYPE Code.Language.Program.Structure.Module
FIELD Text name
FIELD Collection.Array(Code.Language.Program.Structure.ModuleContent) contentsCode.Language.Program.Structure.ModuleContent
One member of a module: a comment, record type, union type, function, native, or native type.
Options
| Option | Type | Description |
|---|---|---|
comment | Text | A comment line. |
dataType | Code.Language.Program.Structure.Record | A record type declaration. |
unionType | Code.Language.Program.Structure.Record | A union type declaration. |
function | Code.Language.Program.Structure.Function | A Program function. |
native | Code.Language.Program.Structure.Function | A native function. |
nativeType | Code.Language.Program.Structure.NativeType | A native type. |
Definition
TYPE Code.Language.Program.Structure.ModuleContent
OPTION Text comment
OPTION Code.Language.Program.Structure.Record dataType
OPTION Code.Language.Program.Structure.Record unionType
OPTION Code.Language.Program.Structure.Function function
OPTION Code.Language.Program.Structure.Function native
OPTION Code.Language.Program.Structure.NativeType nativeTypeCode.Language.Program.Structure.NativeType
A native type declaration: its name, type parameters, and per-platform implementations.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The type name. |
typeParamNames | Collection.Array(Text) | The type parameter names. |
implementations | Collection.Array(Code.Language.Program.Structure.PlatformImpl) | The per-platform native types. |
Definition
TYPE Code.Language.Program.Structure.NativeType
FIELD Text name
FIELD Collection.Array(Text) typeParamNames
FIELD Collection.Array(Code.Language.Program.Structure.PlatformImpl) implementationsCode.Language.Program.Structure.PlatformImpl
A single platform's native implementation: the platform name and its code.
Fields
| Field | Type | Description |
|---|---|---|
platform | Text | The platform name, such as dart or rust. |
code | Text | The native code for that platform. |
Definition
TYPE Code.Language.Program.Structure.PlatformImpl
FIELD Text platform
FIELD Text codeCode.Language.Program.Structure.Program
A whole program: its ordered top-level contents.
Fields
| Field | Type | Description |
|---|---|---|
contents | Collection.Array(Code.Language.Program.Structure.ProgramContent) | The top-level program items. |
Definition
TYPE Code.Language.Program.Structure.Program
FIELD Collection.Array(Code.Language.Program.Structure.ProgramContent) contentsCode.Language.Program.Structure.ProgramContent
One top-level program item: a comment, a module, or a run block.
Options
| Option | Type | Description |
|---|---|---|
comment | Text | A comment line. |
module | Code.Language.Program.Structure.Module | A module. |
run | Collection.Array(Code.Language.Program.Structure.BodyCommand) | A run block of commands. |
Definition
TYPE Code.Language.Program.Structure.ProgramContent
OPTION Text comment
OPTION Code.Language.Program.Structure.Module module
OPTION Collection.Array(Code.Language.Program.Structure.BodyCommand) runCode.Language.Program.Structure.Record
A record or union type declaration: its name, generics, and members.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The type name. |
genericTypes | Collection.Array(Text) | The generic type parameter names. |
members | Collection.Array(Code.Language.Program.Structure.RecordBodyEntry) | The fields or options. |
Definition
TYPE Code.Language.Program.Structure.Record
FIELD Text name
FIELD Collection.Array(Text) genericTypes
FIELD Collection.Array(Code.Language.Program.Structure.RecordBodyEntry) membersCode.Language.Program.Structure.RecordBodyEntry
One entry in a record or union body: a comment, a field, or a header separator.
Options
| Option | Type | Description |
|---|---|---|
comment | Text | A comment line. |
field | Code.Language.Program.Structure.Field | A field or option. |
header | Collection.Void | A header separator. |
Definition
TYPE Code.Language.Program.Structure.RecordBodyEntry
OPTION Text comment
OPTION Code.Language.Program.Structure.Field field
OPTION Collection.Void headerCode.Language.Program.Structure.Return
A function return: the returned variable name, type, and optional direction.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The returned variable name. |
type | Text | The return type. |
optionalDirection | Collection.Optional(Code.Language.Program.Structure.Direction) | The return direction, if any. |
Definition
TYPE Code.Language.Program.Structure.Return
FIELD Text name
FIELD Text type
FIELD Collection.Optional(Code.Language.Program.Structure.Direction) optionalDirectionCode.Language.Program.Structure.Reverse
A reverse (~) command: a name, type, setter pairs, and a body.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The reverse name. |
type | Text | The declared type. |
setters | Collection.Array(Code.Language.Program.Structure.SetterPair) | The setter pairs. |
body | Collection.Array(Code.Language.Program.Structure.BodyCommand) | The reverse body commands. |
Definition
TYPE Code.Language.Program.Structure.Reverse
FIELD Text name
FIELD Text type
FIELD Collection.Array(Code.Language.Program.Structure.SetterPair) setters
FIELD Collection.Array(Code.Language.Program.Structure.BodyCommand) bodyCode.Language.Program.Structure.SetterPair
A setter pair inside a reverse: an outer settable and the inner value written to it.
Fields
| Field | Type | Description |
|---|---|---|
outerSettable | Text | The outer settable reference. |
innerValue | Text | The inner value written to it. |
Definition
TYPE Code.Language.Program.Structure.SetterPair
FIELD Text outerSettable
FIELD Text innerValueCode.Language.Program.Structure.State
A state ($) command: a named, typed, optionally-lockable cell with an optional initial value.
Fields
| Field | Type | Description |
|---|---|---|
name | Text | The state name. |
type | Text | The declared type. |
optionalInitialValue | Collection.Optional(Code.Language.Json.Value) | The initial value, if any. |
lockable | Logic.Maybe | Yes when the state is lockable. |
Definition
TYPE Code.Language.Program.Structure.State
FIELD Text name
FIELD Text type
FIELD Collection.Optional(Code.Language.Json.Value) optionalInitialValue
FIELD Logic.Maybe lockableCode.Parse.Result
The outcome of a parse rule: a success carrying a value, a no-match, or an error.
Generics
T — a generic type parameter.
Options
| Option | Type | Description |
|---|---|---|
success | Code.Parse.Result.Success(T) | A successful parse. |
noMatch | Code.Parse.Result.NoMatch | No match at this position. |
error | Code.Parse.Result.Error | A parse error. |
Definition
TYPE Code.Parse.Result<T>
OPTION Code.Parse.Result.Success(T) success
OPTION Code.Parse.Result.NoMatch noMatch
OPTION Code.Parse.Result.Error errorCode.Parse.Result.Error
A parse error, carrying a message.
Fields
| Field | Type | Description |
|---|---|---|
message | Text | The error message. |
Definition
TYPE Code.Parse.Result.Error
FIELD Text messageCode.Parse.Result.NoMatch
A parse rule that did not match, with an optional explanation.
Fields
| Field | Type | Description |
|---|---|---|
optionalExplanation | Collection.Optional(Text) | Why it did not match, if given. |
Definition
TYPE Code.Parse.Result.NoMatch
FIELD Collection.Optional(Text) optionalExplanationCode.Parse.Result.Success
A successful parse: the parsed value and the index where it ended.
Generics
T — a generic type parameter.
Fields
| Field | Type | Description |
|---|---|---|
value | T | The parsed value. |
endIndex | Maths.Integer | The index just past the match. |
Definition
TYPE Code.Parse.Result.Success<T>
FIELD T value
FIELD Maths.Integer endIndexFunctions
Code.Language.Json.FromJsonArray
Decodes each element of a JSON array with a callback, gathering the results.
Generics
ElementType — a generic type parameter.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonArrayUnion | Collection.Optional(Code.Language.Json.Value) | The array value to decode. |
Callback
A callback that decodes one element (an optional JSON value) into an ElementType.
Returns
Returns Collection.Array(ElementType).
Code.Language.Json.FromObjectFromStringMap
Builds a JSON object value from a map of text values.
Parameters
| Name | Type | Description |
|---|---|---|
stringMap | Collection.Map(Text) | The map of text fields. |
Returns
Returns Code.Language.Json.Value.
Code.Language.Json.GetArray
Reads a JSON value as an array, or an empty array.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
Returns
Returns Collection.Array(Code.Language.Json.Value).
Code.Language.Json.GetArrayElement
Reads the element at an index of a JSON array, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The array value. |
index | Maths.Integer | The element index. |
optionalDefaultValue | Collection.Optional(Code.Language.Json.Value) | Returned when the index is out of range. |
Returns
Returns Collection.Optional(Code.Language.Json.Value).
Code.Language.Json.GetArrayLength
The number of elements in a JSON array, or zero.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The array value. |
Returns
Returns Maths.Integer.
Code.Language.Json.GetBoolean
Reads a JSON value as a boolean, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
defaultValue | Logic.Maybe | Returned when the value is not a boolean. |
Returns
Returns Logic.Maybe.
Code.Language.Json.GetInteger
Reads a JSON value as an integer, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
defaultValue | Maths.Integer | Returned when the value is not a number. |
Returns
Returns Maths.Integer.
Code.Language.Json.GetNumber
Reads a JSON value as a real number, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
defaultValue | Maths.Real | Returned when the value is not a number. |
Returns
Returns Maths.Real.
Code.Language.Json.GetObject
Reads a JSON value as an object, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
defaultValue | Collection.Map(Code.Language.Json.Value) | Returned when the value is not an object. |
Returns
Returns Collection.Map(Code.Language.Json.Value).
Code.Language.Json.GetObjectField
Reads a named field from a JSON object, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The object value. |
field | Text | The field name. |
optionalDefaultValue | Collection.Optional(Code.Language.Json.Value) | Returned when the field is absent. |
Returns
Returns Collection.Optional(Code.Language.Json.Value).
Code.Language.Json.GetString
Reads a JSON value as text, falling back to a default.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
defaultValue | Text | Returned when the value is not text. |
Returns
Returns Text.
Example
LET Text name = Code.Language.Json.GetString field "guest"Code.Language.Json.OptionalGetArray
Reads a JSON value as an array, or nothing when it is not an array.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
Returns
Returns Collection.Optional(Collection.Array(Code.Language.Json.Value)).
Code.Language.Json.OptionalGetArrayElement
Reads the element at an index of a JSON array, or nothing when out of range.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The array value. |
index | Maths.Integer | The element index. |
Returns
Returns Collection.Optional(Code.Language.Json.Value).
Code.Language.Json.OptionalGetInteger
Reads a JSON value as an integer, or nothing when it is not a number.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
Returns
Returns Collection.Optional(Maths.Integer).
Code.Language.Json.OptionalGetObject
Reads the object of a JSON value, or nothing when it is not an object.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
Returns
Returns Collection.Optional(Collection.Map(Code.Language.Json.Value)).
Code.Language.Json.OptionalGetObjectField
Reads a named field from a JSON object, or nothing when absent.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The object value. |
field | Text | The field name. |
Returns
Returns Collection.Optional(Code.Language.Json.Value).
Code.Language.Json.OptionalStringify
Serialises an optional JSON value to JSON text, or empty text when absent.
Parameters
| Name | Type | Description |
|---|---|---|
optionalInput | Collection.Optional(Code.Language.Json.Value) | The value to serialise, if present. |
Returns
Returns Text.
Code.Language.Json.OptionalText
Reads the text of a JSON value, or nothing when it is not text.
Parameters
| Name | Type | Description |
|---|---|---|
optionalUnion | Collection.Optional(Code.Language.Json.Value) | The value to read. |
Returns
Returns Collection.Optional(Text).
Code.Language.Json.Parse
Parses JSON text into a JSON value, or nothing when the text is invalid.
Parameters
| Name | Type | Description |
|---|---|---|
input | Text | The JSON text to parse. |
Returns
Returns Collection.Optional(Code.Language.Json.Value).
Example
LET Collection.Optional(Code.Language.Json.Value) parsed = Code.Language.Json.Parse textCode.Language.Json.Stringify
Serialises a JSON value to its compact JSON text.
Parameters
| Name | Type | Description |
|---|---|---|
input | Code.Language.Json.Value | The value to serialise. |
Returns
Returns Text.
Example
LET Text json = Code.Language.Json.Stringify valueCode.Language.Program.Structure.Argument.FromJson
Builds a call argument from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Argument.
Code.Language.Program.Structure.Assignment.FromJson
Builds an assignment from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Assignment.
Code.Language.Program.Structure.AssignmentValue.FromJson
Builds an assignment value from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.AssignmentValue.
Code.Language.Program.Structure.BodyCommand.FromJson
Builds one body command from its JSON command form, dispatching on its tag.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.BodyCommand.
Code.Language.Program.Structure.Constant.FromJson
Builds a constant declaration from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Constant.
Code.Language.Program.Structure.ConstantValue.FromJson
Builds a literal constant value from its type name and JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
typeName | Text | The declared type name, which selects the literal kind. |
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.ConstantValue.
Code.Language.Program.Structure.Direction.FromJson
Builds a direction from its JSON command form, defaulting to forward.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Direction.
Code.Language.Program.Structure.Field.FromJson
Builds a field from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Field.
Code.Language.Program.Structure.Function.FromJson
Builds a function or native declaration from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Function.
Code.Language.Program.Structure.FunctionBody.FromJson
Builds a function body from its JSON command form, choosing commands or native implementations.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.FunctionBody.
Code.Language.Program.Structure.FunctionCall.FromJson
Builds a function call from its JSON command form, reading fields from a start slot.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
startSlot | Maths.Integer | The array slot at which the call's fields begin. |
Returns
Returns Code.Language.Program.Structure.FunctionCall.
Code.Language.Program.Structure.Input.FromJson
Builds a function input from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Input.
Code.Language.Program.Structure.Module.FromJson
Builds a module from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Module.
Code.Language.Program.Structure.ModuleContent.FromJson
Builds one module member from its JSON command form, dispatching on its tag.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.ModuleContent.
Code.Language.Program.Structure.NativeType.FromJson
Builds a native type from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.NativeType.
Code.Language.Program.Structure.PlatformImpl.FromJson
Builds a per-platform implementation from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.PlatformImpl.
Code.Language.Program.Structure.Program.FromJson
Builds a whole program from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Program.
Example
LET Code.Language.Program.Structure.Program tree = Code.Language.Program.Structure.Program.FromJson jsonCode.Language.Program.Structure.ProgramContent.FromJson
Builds one top-level program item from its JSON command form, dispatching on its tag.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.ProgramContent.
Code.Language.Program.Structure.Record.FromJson
Builds a record or union type from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Record.
Code.Language.Program.Structure.RecordBodyEntry.FromJson
Builds one record body entry from its JSON command form, dispatching on its tag.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.RecordBodyEntry.
Code.Language.Program.Structure.Return.FromJson
Builds a function return from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Return.
Code.Language.Program.Structure.Reverse.FromJson
Builds a reverse command from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.Reverse.
Code.Language.Program.Structure.SetterPair.FromJson
Builds a setter pair from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.SetterPair.
Code.Language.Program.Structure.State.FromJson
Builds a state declaration from its JSON command form.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Code.Language.Program.Structure.State.
Code.Language.Program.Structure.StringFromJson
Reads a JSON value as text, defaulting to empty.
Parameters
| Name | Type | Description |
|---|---|---|
optionalJsonElement | Collection.Optional(Code.Language.Json.Value) | The JSON command form to decode. |
Returns
Returns Text.
Code.Parse.Context.WithInput
Runs a callback with a named input value bound in context, returning its result.
Generics
T — a generic type parameter.
Parameters
| Name | Type | Description |
|---|---|---|
name | Text | The context name to bind. |
inputValue | T | The value to bind. |
Callback
A callback run while the input is bound; its result is returned.
Returns
Returns T.
Code.Parse.Context.WithMutable
Runs a callback with a named mutable value bound in context, returning its result.
Generics
T — a generic type parameter.
Parameters
| Name | Type | Description |
|---|---|---|
name | Text | The context name to bind. |
initialValue | T | The initial mutable value. |
Callback
A callback run while the mutable is bound; its result is returned.
Returns
Returns T.
Code.Parse.State.GetIndex
The current parse index.
Returns
Returns Maths.Integer.
Code.Parse.State.GetValue
The value currently being parsed.
Generics
T — a generic type parameter.
Returns
Returns T.
Code.Parse.State.Set
Sets up the parse context (value, start index, and error slot) then runs a callback.
Generics
T — a generic type parameter.
Parameters
| Name | Type | Description |
|---|---|---|
value | T | The value being parsed. |
initialIndex | Maths.Integer | The starting parse index. |
Callback
A callback run with the parse state established; its result is returned.
Returns
Returns T.
Code.Parse.State.SetIndex
Moves the parse index to a new position.
Parameters
| Name | Type | Description |
|---|---|---|
index | Maths.Integer | The new parse index. |
Returns
Returns nothing.