Skip to content

Commit

Permalink
Merge pull request #397 from ericevenchick/master
Browse files Browse the repository at this point in the history
dsl support for stringjoin struct repr and stringprefix union repr
  • Loading branch information
warpfork committed Apr 5, 2022
2 parents 81f4ec6 + 456c3a9 commit 0f76b5f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .ipld
Submodule .ipld updated 38 files
+1 −0 .site/.eleventy.js
+4 −1 .site/css/nav.css
+7 −2 .site/css/style.css
+13 −0 FAQ.md
+2 −3 README.md
+1 −1 docs/advanced-data-layouts/dynamic-loading.md
+4 −7 docs/advanced-data-layouts/index.md
+146 −40 docs/advanced-data-layouts/intro.md
+16 −0 docs/advanced-data-layouts/known/index.md
+20 −0 docs/advanced-data-layouts/naming.md
+202 −57 docs/advanced-data-layouts/signalling.md
+33 −3 docs/codecs/known/dag-cbor/index.md
+1 −1 docs/codecs/known/dag-json/index.md
+1 −1 docs/codecs/known/dag-pb/index.md
+2 −2 docs/intro/community.md
+66 −4 docs/schemas/index.md
+1 −1 docs/synthesis/how-ipfs-web-gateways-work.md
+7 −1 glossary.md
+11 −6 libraries/golang/index.md
+12 −0 notebook/exploration-reports/2021.02-cross-language-fixtures.md
+9 −0 notebook/exploration-reports/2021.11-selector-adl.md
+203 −50 package-lock.json
+103 −0 specs/about.md
+1 −0 specs/advanced-data-layouts/index.md
+1 −2 specs/codecs/dag-cbor/index.md
+1 −2 specs/codecs/dag-jose/index.md
+1 −2 specs/codecs/dag-json/index.md
+1 −2 specs/codecs/dag-pb/index.md
+1 −0 specs/codecs/index.md
+1 −0 specs/schemas/index.md
+45 −0 specs/schemas/tests/struct-stringjoin.yml
+0 −32 specs/schemas/tests/struct-stringjoin.yml-old
+34 −0 specs/schemas/tests/union-stringprefix.yml
+ specs/selectors/fixtures/selector-fixtures-adl.car
+89 −0 specs/selectors/fixtures/selector-fixtures-adl.md
+11 −0 specs/selectors/index.md
+28 −9 specs/transport/car/carv1/index.md
+1 −1 specs/transport/index.md
16 changes: 15 additions & 1 deletion schema/dmt/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func spawnType(ts *schema.TypeSystem, name schema.TypeName, defn TypeDefn) (sche
typ.Representation.ListRepresentation_List != nil:
// default behavior
default:
return nil, fmt.Errorf("TODO: support other map repr in schema package")
return nil, fmt.Errorf("TODO: support other list repr in schema package")
}
return schema.SpawnList(name,
*typ.ValueType.TypeName,
Expand All @@ -147,6 +147,8 @@ func spawnType(ts *schema.TypeSystem, name schema.TypeName, defn TypeDefn) (sche
case typ.Representation == nil ||
typ.Representation.MapRepresentation_Map != nil:
// default behavior
case typ.Representation.MapRepresentation_Stringpairs != nil:
return nil, fmt.Errorf("TODO: support stringpairs map repr in schema package")
default:
return nil, fmt.Errorf("TODO: support other map repr in schema package")
}
Expand Down Expand Up @@ -221,6 +223,12 @@ func spawnType(ts *schema.TypeSystem, name schema.TypeName, defn TypeDefn) (sche
break
}
return nil, fmt.Errorf("TODO: support for tuples with field orders in the schema package")
case typ.Representation.StructRepresentation_Stringjoin != nil:
join := typ.Representation.StructRepresentation_Stringjoin.Join
if join == "" {
return nil, fmt.Errorf("stringjoin has empty join value")
}
repr = schema.SpawnStructRepresentationStringjoin(join)
default:
return nil, fmt.Errorf("TODO: support other struct repr in schema package")
}
Expand Down Expand Up @@ -287,6 +295,12 @@ func spawnType(ts *schema.TypeSystem, name schema.TypeName, defn TypeDefn) (sche
}
}
repr = schema.SpawnUnionRepresentationKeyed(table)
case typ.Representation.UnionRepresentation_StringPrefix != nil:
prefixes := typ.Representation.UnionRepresentation_StringPrefix.Prefixes
for _, key := range prefixes.Keys {
validMember(prefixes.Values[key])
}
repr = schema.SpawnUnionRepresentationStringprefix("", prefixes.Values)
default:
return nil, fmt.Errorf("TODO: support other union repr in schema package")
}
Expand Down
61 changes: 60 additions & 1 deletion schema/dsl/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ func (p *parser) consumeString() (string, error) {
return tok[1 : len(tok)-1], nil
}

func (p *parser) consumeStringMap() (map[string]string, error) {
result := map[string]string{}
loop:
for {
tok, err := p.peekToken()
if err != nil {
return result, err
}
switch tok {
case "{":
p.consumePeeked()
case "}":
p.consumePeeked()
break loop
default:
key, err := p.consumeName()
if err != nil {
return result, err
}
value, err := p.consumeString()
if err != nil {
return result, err
}
result[key] = value
}
}
return result, nil
}

func (p *parser) consumeRequired(tok string) error {
got, err := p.consumeToken()
if err != nil {
Expand Down Expand Up @@ -425,6 +454,19 @@ func (p *parser) typeStruct() (*dmt.TypeDefnStruct, error) {
defn.Representation.StructRepresentation_Tuple = &dmt.StructRepresentation_Tuple{}
return defn, nil
// TODO: support custom fieldorder
case "stringjoin":
optMap, err := p.consumeStringMap()
if err != nil {
return nil, err
}
join, hasJoin := optMap["join"]
if !hasJoin {
return nil, p.errf("no join value provided for stringjoin repr")
}
defn.Representation.StructRepresentation_Stringjoin = &dmt.StructRepresentation_Stringjoin{
Join: join,
}
return defn, nil
default:
return nil, p.errf("unknown struct repr: %q", reprName)
}
Expand Down Expand Up @@ -513,7 +555,6 @@ func (p *parser) typeMap() (*dmt.TypeDefnMap, error) {
return defn, err
}

// TODO: repr
return defn, nil
}

Expand Down Expand Up @@ -573,6 +614,24 @@ func (p *parser) typeUnion() (*dmt.TypeDefnUnion, error) {
mapAppend(repr, key, defn.Members[i])
}
defn.Representation.UnionRepresentation_Kinded = repr
case "stringprefix":
repr := &dmt.UnionRepresentation_StringPrefix{
Prefixes: dmt.Map__String__TypeName{
Values: map[string]string{},
},
}
for i, key := range reprKeys {
// unquote prefix string
if len(key) < 2 || key[0] != '"' || key[len(key)-1] != '"' {
return nil, p.errf("invalid stringprefix %q", key)
}
key = key[1 : len(key)-1]

// add prefix to prefixes map
repr.Prefixes.Keys = append(repr.Prefixes.Keys, key)
repr.Prefixes.Values[key] = *defn.Members[i].TypeName
}
defn.Representation.UnionRepresentation_StringPrefix = repr
default:
return nil, p.errf("TODO: union repr %q", reprName)
}
Expand Down

0 comments on commit 0f76b5f

Please sign in to comment.