-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from gmarcosb/main
Add TypeDef support, minor tweaks to XML output (to match XSD)
- Loading branch information
Showing
18 changed files
with
190 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package spec | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/project-chip/alchemy/asciidoc" | ||
"github.com/project-chip/alchemy/internal/text" | ||
"github.com/project-chip/alchemy/matter" | ||
"github.com/project-chip/alchemy/matter/types" | ||
) | ||
|
||
func (s *Section) toTypeDef(d *Doc, entityMap map[asciidoc.Attributable][]types.Entity) (ms *matter.TypeDef, err error) { | ||
name := text.TrimCaseInsensitiveSuffix(s.Name, " Type") | ||
ms = matter.NewTypeDef(s.Base) | ||
ms.Name = name | ||
|
||
dt := s.GetDataType() | ||
if (dt == nil) || !dt.BaseType.IsSimple() { | ||
return nil, fmt.Errorf("unknown typedef data type: %s", dt.Name) | ||
} | ||
ms.Type = dt | ||
entityMap[s.Base] = append(entityMap[s.Base], ms) | ||
ms.Name = CanonicalName(ms.Name) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package matter | ||
|
||
import ( | ||
"github.com/project-chip/alchemy/asciidoc" | ||
"github.com/project-chip/alchemy/matter/types" | ||
) | ||
|
||
type TypeDef struct { | ||
entity | ||
Name string `json:"name,omitempty"` | ||
Description string `json:"description,omitempty"` | ||
Type *types.DataType `json:"type,omitempty"` | ||
} | ||
|
||
func NewTypeDef(source asciidoc.Element) *TypeDef { | ||
return &TypeDef{ | ||
entity: entity{source: source}, | ||
} | ||
} | ||
|
||
func (*TypeDef) EntityType() types.EntityType { | ||
return types.EntityTypeDef | ||
} | ||
|
||
func (s *TypeDef) Clone() *TypeDef { | ||
ns := &TypeDef{Name: s.Name, Description: s.Description, Type: s.Type} | ||
return ns | ||
} | ||
|
||
func (s *TypeDef) Inherit(parent *TypeDef) { | ||
if len(s.Description) == 0 { | ||
s.Description = parent.Description | ||
} | ||
s.Type = s.Type | ||
} | ||
|
||
type TypeDefSet []*TypeDef | ||
|
||
func (ss TypeDefSet) Identifier(name string) (types.Entity, bool) { | ||
for _, e := range ss { | ||
if e.Name == name { | ||
return e, true | ||
} | ||
} | ||
return nil, false | ||
} |
Oops, something went wrong.