Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ld
go-ld-prime
Commits
3da7e2ad
Commit
3da7e2ad
authored
Jan 22, 2021
by
Eric Myhre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
schema unification progress: map representations, enums, etc.
parent
d74ecb3e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
4 deletions
+113
-4
schema/compiler.go
schema/compiler.go
+15
-3
schema/dmt/compile.go
schema/dmt/compile.go
+15
-1
schema/type_enum.go
schema/type_enum.go
+57
-0
schema/type_map.go
schema/type_map.go
+18
-0
schema/type_struct.go
schema/type_struct.go
+4
-0
schema/type_union.go
schema/type_union.go
+4
-0
No files found.
schema/compiler.go
View file @
3da7e2ad
...
...
@@ -84,10 +84,18 @@ func (c *Compiler) Init() {
}
}
func
(
c
*
Compiler
)
Compile
()
(
TypeSystem
,
error
)
{
func
(
c
*
Compiler
)
Compile
()
(
*
TypeSystem
,
error
)
{
panic
(
"TODO"
)
}
func
(
c
*
Compiler
)
MustCompile
()
*
TypeSystem
{
ts
,
err
:=
c
.
Compile
()
if
err
!=
nil
{
panic
(
err
)
}
return
ts
}
func
(
c
*
Compiler
)
addType
(
t
Type
)
{
c
.
mustHaveNameFree
(
t
.
Name
())
c
.
ts
.
types
[
TypeReference
(
t
.
Name
())]
=
t
...
...
@@ -160,8 +168,12 @@ func (Compiler) MakeStructRepresentation_Map(fieldDetails structFieldNameStructR
//go:generate quickimmut -output=compiler_carriers.go -attach=Compiler map StructFieldName StructRepresentation_Map_FieldDetails
func
(
c
*
Compiler
)
TypeMap
(
name
TypeName
,
keyTypeRef
TypeName
,
valueTypeRef
TypeReference
,
valueNullable
bool
)
{
c
.
addType
(
&
TypeMap
{
c
.
ts
,
name
,
keyTypeRef
,
valueTypeRef
,
valueNullable
})
func
(
c
*
Compiler
)
TypeMap
(
name
TypeName
,
keyTypeRef
TypeName
,
valueTypeRef
TypeReference
,
valueNullable
bool
,
rstrat
MapRepresentation
)
{
c
.
addType
(
&
TypeMap
{
c
.
ts
,
name
,
keyTypeRef
,
valueTypeRef
,
valueNullable
,
rstrat
})
}
func
(
Compiler
)
MakeMapRepresentation_Stringpairs
(
innerDelim
string
,
entryDelim
string
)
MapRepresentation
{
return
MapRepresentation_Stringpairs
{
innerDelim
,
entryDelim
}
}
func
(
c
*
Compiler
)
TypeList
(
name
TypeName
,
valueTypeRef
TypeReference
,
valueNullable
bool
)
{
...
...
schema/dmt/compile.go
View file @
3da7e2ad
...
...
@@ -10,7 +10,7 @@ import (
// and so we've just chained it all together with switch statements;
// creating a separate interface per result type seems just not super relevant.
func
(
schdmt
Schema
)
Compile
()
(
schema
.
TypeSystem
,
error
)
{
func
(
schdmt
Schema
)
Compile
()
(
*
schema
.
TypeSystem
,
error
)
{
c
:=
&
schema
.
Compiler
{}
typesdmt
:=
schdmt
.
FieldTypes
()
for
itr
:=
typesdmt
.
Iterator
();
!
itr
.
Done
();
{
...
...
@@ -38,6 +38,7 @@ func (schdmt Schema) Compile() (schema.TypeSystem, error) {
schema
.
TypeName
(
t2
.
FieldKeyType
()
.
String
()),
t2
.
FieldValueType
()
.
TypeReference
(),
t2
.
FieldValueNullable
()
.
Bool
(),
t2
.
FieldRepresentation
()
.
compile
(
c
),
)
// If the field typeReference is TypeDefnInline, that needs a chance to take additional action.
t2
.
FieldValueType
()
.
compile
(
c
)
...
...
@@ -139,6 +140,19 @@ func (dmt TypeNameOrInlineDefn) compile(c *schema.Compiler) {
}
}
func
(
dmt
MapRepresentation
)
compile
(
c
*
schema
.
Compiler
)
schema
.
MapRepresentation
{
switch
rdmt
:=
dmt
.
AsInterface
()
.
(
type
)
{
case
MapRepresentation_Map
:
return
schema
.
MapRepresentation_Map
{}
case
MapRepresentation_Listpairs
:
return
schema
.
MapRepresentation_Listpairs
{}
case
MapRepresentation_Stringpairs
:
return
c
.
MakeMapRepresentation_Stringpairs
(
rdmt
.
FieldInnerDelim
()
.
String
(),
rdmt
.
FieldEntryDelim
()
.
String
())
default
:
panic
(
"unreachable"
)
}
}
func
(
dmt
StructRepresentation_Map
)
compile
()
schema
.
StructRepresentation
{
if
!
dmt
.
FieldFields
()
.
Exists
()
{
return
schema
.
Compiler
{}
.
MakeStructRepresentation_Map
(
schema
.
Compiler
{}
.
MakeStructFieldNameStructRepresentation_Map_FieldDetailsMap
())
...
...
schema/type_enum.go
0 → 100644
View file @
3da7e2ad
package
schema
import
(
"github.com/ipld/go-ipld-prime"
)
type
TypeEnum
struct
{
name
TypeName
members
[]
string
// a map in the dmt, but really an ordered set. easier as a slice in golang.
ts
*
TypeSystem
rstrat
EnumRepresentation
}
func
(
t
*
TypeEnum
)
Representation
()
EnumRepresentation
{
return
t
.
rstrat
}
type
EnumRepresentation
interface
{
_EnumRepresentation
()
}
func
(
EnumRepresentation_String
)
_EnumRepresentation
()
{}
func
(
EnumRepresentation_Int
)
_EnumRepresentation
()
{}
type
EnumRepresentation_String
struct
{
labels
map
[
string
]
string
// member:label
}
type
EnumRepresentation_Int
struct
{
labels
map
[
string
]
int
// member:label
}
// -- schema.Type interface satisfaction -->
var
_
Type
=
(
*
TypeEnum
)(
nil
)
func
(
t
*
TypeEnum
)
_Type
()
{}
func
(
t
*
TypeEnum
)
TypeSystem
()
*
TypeSystem
{
return
t
.
ts
}
func
(
TypeEnum
)
TypeKind
()
TypeKind
{
return
TypeKind_Enum
}
func
(
t
*
TypeEnum
)
Name
()
TypeName
{
return
t
.
name
}
func
(
t
TypeEnum
)
RepresentationBehavior
()
ipld
.
Kind
{
switch
t
.
rstrat
.
(
type
)
{
case
EnumRepresentation_String
:
return
ipld
.
Kind_String
case
EnumRepresentation_Int
:
return
ipld
.
Kind_Int
default
:
panic
(
"unreachable"
)
}
}
schema/type_map.go
View file @
3da7e2ad
...
...
@@ -10,6 +10,24 @@ type TypeMap struct {
keyTypeRef
TypeName
// is a TypeName and not a TypeReference because it can't be an anon.
valueTypeRef
TypeReference
valueNullable
bool
rstrat
MapRepresentation
}
func
(
t
*
TypeMap
)
Representation
()
MapRepresentation
{
return
t
.
rstrat
}
type
MapRepresentation
interface
{
_MapRepresentation
()
}
func
(
MapRepresentation_Map
)
_MapRepresentation
()
{}
func
(
MapRepresentation_Listpairs
)
_MapRepresentation
()
{}
func
(
MapRepresentation_Stringpairs
)
_MapRepresentation
()
{}
type
MapRepresentation_Map
struct
{}
type
MapRepresentation_Listpairs
struct
{}
type
MapRepresentation_Stringpairs
struct
{
innerDelim
string
entryDelim
string
}
// -- Type interface satisfaction -->
...
...
schema/type_struct.go
View file @
3da7e2ad
...
...
@@ -22,6 +22,10 @@ type StructField struct {
type
StructFieldName
string
func
(
t
*
TypeStruct
)
Representation
()
StructRepresentation
{
return
t
.
rstrat
}
type
StructRepresentation
interface
{
_StructRepresentation
()
}
func
(
StructRepresentation_Map
)
_StructRepresentation
()
{}
...
...
schema/type_union.go
View file @
3da7e2ad
...
...
@@ -11,6 +11,10 @@ type TypeUnion struct {
rstrat
UnionRepresentation
}
func
(
t
*
TypeUnion
)
Representation
()
UnionRepresentation
{
return
t
.
rstrat
}
type
UnionRepresentation
interface
{
_UnionRepresentation
()
}
func
(
UnionRepresentation_Keyed
)
_UnionRepresentation
()
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment