ast topic

A simplified abstract syntax tree for code and JSON processing.

Code

Every datatype is an AbstractType. An AbstractType stores the actual datatype name. AbstractTypes are implemented by:

  • StandardType
  • CustomType
  • EnumType

StandardType

StandardTypes are based on all types supported by the standard message codec. Meaning all standard types are Dart types that support efficient binary serialization of simple JSON-like values.

AST Dart
IntType int
NullableIntType int?
DoubleType double
NullableDoubleType double?
StringType String
StringTypeType String?
BooleanType bool
NullableBooleanType bool?
ListType List
NullableListType List?
MapType Map
NullableMapType Map?
Uint8ListType Uint8List
NullableUint8ListType Uint8List?
Int32ListType Int32ListType
NullableInt32ListType Int32ListType?
Int64ListType Int64ListType
NullableInt64ListType Int64ListType?
Float32ListType Float32List
NullableFloat32ListType Float32List?
Float64ListType Float64List
NullableFloat64ListType Float64List?

CustomType

A custom type is a user defined class consisting of:

  • Class name
  • 1 or more fields (TypeMember)

A TypeMember has a name and a type (AbstractType).

Example:

@squint
class SimpleResponse {
  ///
  SimpleResponse({
    required this.a1,
    this.a2,
  });

  final int a1;
  final String? a2;
}
  • type: CustomType
  • className: SimpleResponse
  • members:
    • name: a1, type: IntType
    • name: a2, type: NullableStringType

EnumType

An enum is a user defined enumeration consisting of:

  • Class name
  • 1 or more values
  • 1 or more JSON values
@squint
enum MyEnum {

  @JsonValue("foo!")
  foo("foo"),

  @JsonValue("bar!")
  bar("bar");

  const MyEnum(this.someValue);

  final String someValue;

}

JSON

The JSON AST types are used to encode/decode JSON. Decoding JSON with Squint will return a JsonObject instance from which child nodes can be accessed. All data is wrapped in JSON AST nodes. This makes it easier to access (nested) data. Values are always strongly typed. There is no dynamic mapping. Decoding a List inside a List inside a List, etc. does not require multiple mapping.

AST JSON
JsonObject object
JsonArray array
JsonString string
JsonIntegerNumber number (int)
JsonFloatingNumber number (double)
JsonBoolean boolean
JsonObjectOrNull object?
JsonArrayOrNull array?
JsonStringOrNull string?
JsonIntegerNumberOrNull number (int?)
JsonFloatingNumberOrNull number (double?)
JsonBooleanOrNull bool?
JsonNull null

Classes

AbstractType ast
Main type parent implemented by:
AbstractType ast
Main type parent implemented by:
AbstractType ast
Main type parent implemented by:
BooleanType ast
A Boolean StandardType.
BooleanType ast
A Boolean StandardType.
BooleanType ast
A Boolean StandardType.
CustomType ast
A custom class definition.
CustomType ast
A custom class definition.
CustomType ast
A custom class definition.
DoubleType ast
A double StandardType.
DoubleType ast
A double StandardType.
DoubleType ast
A double StandardType.
EnumType ast
A custom enumeration definition.
EnumType ast
A custom enumeration definition.
EnumType ast
A custom enumeration definition.
Float32ListType ast
A Float32List StandardType.
Float32ListType ast
A Float32List StandardType.
Float32ListType ast
A Float32List StandardType.
Float64ListType ast
A Float64List StandardType.
Float64ListType ast
A Float64List StandardType.
Float64ListType ast
A Float64List StandardType.
Int32ListType ast
A Int32List StandardType.
Int32ListType ast
A Int32List StandardType.
Int32ListType ast
A Int32List StandardType.
Int64ListType ast
A Int64List StandardType.
Int64ListType ast
A Int64List StandardType.
Int64ListType ast
A Int64List StandardType.
IntType ast
A Integer StandardType.
IntType ast
A Integer StandardType.
IntType ast
A Integer StandardType.
JsonArray<T> ast decoder encoder
A JSON element containing an Array value.
JsonArray<T> ast decoder encoder
A JSON element containing an Array value.
JsonArray<T> ast decoder encoder
A JSON element containing an Array value.
JsonArrayOrNull<T> ast decoder encoder
A JSON element containing an Array value or null.
JsonArrayOrNull<T> ast decoder encoder
A JSON element containing an Array value or null.
JsonArrayOrNull<T> ast decoder encoder
A JSON element containing an Array value or null.
JsonBoolean ast decoder encoder
A JSON element containing a bool value.
JsonBoolean ast decoder encoder
A JSON element containing a bool value.
JsonBoolean ast decoder encoder
A JSON element containing a bool value.
JsonBooleanOrNull ast decoder encoder
A JSON element containing a bool value or null.
JsonBooleanOrNull ast decoder encoder
A JSON element containing a bool value or null.
JsonBooleanOrNull ast decoder encoder
A JSON element containing a bool value or null.
JsonFloatingNumber ast decoder encoder
A JSON element containing a double value.
JsonFloatingNumber ast decoder encoder
A JSON element containing a double value.
JsonFloatingNumber ast decoder encoder
A JSON element containing a double value.
JsonFloatingNumberOrNull ast decoder encoder
A JSON element containing a double value or null.
JsonFloatingNumberOrNull ast decoder encoder
A JSON element containing a double value or null.
JsonFloatingNumberOrNull ast decoder encoder
A JSON element containing a double value or null.
JsonIntegerNumber ast decoder encoder
A JSON element containing an int value.
JsonIntegerNumber ast decoder encoder
A JSON element containing an int value.
JsonIntegerNumber ast decoder encoder
A JSON element containing an int value.
JsonIntegerNumberOrNull ast decoder encoder
A JSON element containing an int value or null.
JsonIntegerNumberOrNull ast decoder encoder
A JSON element containing an int value or null.
JsonIntegerNumberOrNull ast decoder encoder
A JSON element containing an int value or null.
JsonMissing ast decoder encoder
A JSON element containing a null value and key.
JsonMissing ast decoder encoder
A JSON element containing a null value and key.
JsonMissing ast decoder encoder
A JSON element containing a null value and key.
JsonNode<T> ast decoder encoder
A single JSON node representation consisting of a String key and T data.
JsonNode<T> ast decoder encoder
A single JSON node representation consisting of a String key and T data.
JsonNode<T> ast decoder encoder
A single JSON node representation consisting of a String key and T data.
JsonNull ast decoder encoder
A JSON element containing a null value.
JsonNull ast decoder encoder
A JSON element containing a null value.
JsonNull ast decoder encoder
A JSON element containing a null value.
JsonObject ast decoder encoder
JSON Object (Map) element.
JsonObject ast decoder encoder
JSON Object (Map) element.
JsonObject ast decoder encoder
JSON Object (Map) element.
JsonObjectOrNull ast decoder encoder
JSON Object (Map) element.
JsonObjectOrNull ast decoder encoder
JSON Object (Map) element.
JsonObjectOrNull ast decoder encoder
JSON Object (Map) element.
JsonString ast decoder encoder
A JSON element containing a String value.
JsonString ast decoder encoder
A JSON element containing a String value.
JsonString ast decoder encoder
A JSON element containing a String value.
JsonStringOrNull ast decoder encoder
A JSON element containing a String or null value.
JsonStringOrNull ast decoder encoder
A JSON element containing a String or null value.
JsonStringOrNull ast decoder encoder
A JSON element containing a String or null value.
ListType ast
A List StandardType.
ListType ast
A List StandardType.
ListType ast
A List StandardType.
MapType ast
A Map StandardType.
MapType ast
A Map StandardType.
MapType ast
A Map StandardType.
NullableBooleanType ast
A nullable Boolean StandardType.
NullableBooleanType ast
A nullable Boolean StandardType.
NullableBooleanType ast
A nullable Boolean StandardType.
NullableDoubleType ast
A nullable double StandardType.
NullableDoubleType ast
A nullable double StandardType.
NullableDoubleType ast
A nullable double StandardType.
NullableFloat32ListType ast
A nullable Float32List StandardType.
NullableFloat32ListType ast
A nullable Float32List StandardType.
NullableFloat32ListType ast
A nullable Float32List StandardType.
NullableFloat64ListType ast
A nullable Float64List StandardType.
NullableFloat64ListType ast
A nullable Float64List StandardType.
NullableFloat64ListType ast
A nullable Float64List StandardType.
NullableInt32ListType ast
A nullable Int32List StandardType.
NullableInt32ListType ast
A nullable Int32List StandardType.
NullableInt32ListType ast
A nullable Int32List StandardType.
NullableInt64ListType ast
A nullable Int64List StandardType.
NullableInt64ListType ast
A nullable Int64List StandardType.
NullableInt64ListType ast
A nullable Int64List StandardType.
NullableIntType ast
A nullable Integer IntType.
NullableIntType ast
A nullable Integer IntType.
NullableIntType ast
A nullable Integer IntType.
NullableListType ast
A nullable List StandardType.
NullableListType ast
A nullable List StandardType.
NullableListType ast
A nullable List StandardType.
NullableMapType ast
A nullable Map MapType.
NullableMapType ast
A nullable Map MapType.
NullableMapType ast
A nullable Map MapType.
NullableStringType ast
A nullable String StandardType.
NullableStringType ast
A nullable String StandardType.
NullableStringType ast
A nullable String StandardType.
NullableUint8ListType ast
A nullable Uint8List StandardType.
NullableUint8ListType ast
A nullable Uint8List StandardType.
NullableUint8ListType ast
A nullable Uint8List StandardType.
StandardType ast
A standard Dart type being one of:
StandardType ast
A standard Dart type being one of:
StandardType ast
A standard Dart type being one of:
StringType ast
A String StandardType.
StringType ast
A String StandardType.
StringType ast
A String StandardType.
TypeAnnotation ast
Annotation data.
TypeAnnotation ast
Annotation data.
TypeAnnotation ast
Annotation data.
TypeMember ast
A class type member (field).
TypeMember ast
A class type member (field).
TypeMember ast
A class type member (field).
Uint8ListType ast
A Uint8List StandardType.
Uint8ListType ast
A Uint8List StandardType.
Uint8ListType ast
A Uint8List StandardType.

Constants

standardNullableTypes → const Map<String, StandardType> ast
Map of all standard nullable types.
standardNullableTypes → const Map<String, StandardType> ast
Map of all standard nullable types.
standardNullableTypes → const Map<String, StandardType> ast
Map of all standard nullable types.
standardTypes → const Map<String, StandardType> ast
Map of all standard types.
standardTypes → const Map<String, StandardType> ast
Map of all standard types.
standardTypes → const Map<String, StandardType> ast
Map of all standard types.