diff --git a/internal/confgen/confgen.go b/internal/confgen/confgen.go index cf76060f..4e17a757 100644 --- a/internal/confgen/confgen.go +++ b/internal/confgen/confgen.go @@ -40,10 +40,6 @@ func NewGenerator(protoPackage, indir, outdir string, setters ...options.Option) } func NewGeneratorWithOptions(protoPackage, indir, outdir string, opts *options.Options) *Generator { - // TODO: define tableau in package constants. - if protoPackage == "tableau" { - log.Panicf(`proto package can not be "tableau" which is reserved`) - } g := &Generator{ ProtoPackage: protoPackage, InputDir: indir, diff --git a/internal/confgen/parser.go b/internal/confgen/parser.go index d589c8c0..18c5e53a 100644 --- a/internal/confgen/parser.go +++ b/internal/confgen/parser.go @@ -14,7 +14,6 @@ import ( "github.com/tableauio/tableau/internal/importer/book" "github.com/tableauio/tableau/internal/types" "github.com/tableauio/tableau/internal/xproto" - "github.com/tableauio/tableau/log" "github.com/tableauio/tableau/options" "github.com/tableauio/tableau/proto/tableaupb" "github.com/tableauio/tableau/xerrors" @@ -341,13 +340,8 @@ func (sp *sheetParser) Parse(protomsg proto.Message, sheet *book.Sheet) error { // parseFieldOptions is aimed to parse the options of all the fields of a protobuf message. func (sp *sheetParser) parseFieldOptions(msg protoreflect.Message, rc *book.RowCells, prefix string) (present bool, err error) { md := msg.Descriptor() - pkg := md.ParentFile().Package() for i := 0; i < md.Fields().Len(); i++ { fd := md.Fields().Get(i) - if string(pkg) != sp.ProtoPackage && pkg != "google.protobuf" { - log.Debugf("no need to process package: %v", pkg) - return false, nil - } err := func() error { field := parseFieldDescriptor(fd, sp.opts.Sep, sp.opts.Subsep) defer field.release() diff --git a/internal/protogen/protogen.go b/internal/protogen/protogen.go index 066b3560..94a9cbcd 100644 --- a/internal/protogen/protogen.go +++ b/internal/protogen/protogen.go @@ -26,10 +26,6 @@ import ( "google.golang.org/protobuf/reflect/protoregistry" ) -const ( - TableauProtoPackage = "tableau" -) - type Generator struct { ProtoPackage string // protobuf package name. InputDir string // input dir of workbooks. @@ -265,7 +261,7 @@ func (gen *Generator) convert(dir, filename string, checkProtoFileConflicts bool absPath := filepath.Join(dir, filename) var imp importer.Importer if pass == firstPass { - parser := confgen.NewSheetParser(TableauProtoPackage, gen.LocationName, book.MetasheetOptions()) + parser := confgen.NewSheetParser(xproto.TableauProtoPackage, gen.LocationName, book.MetasheetOptions()) imp, err = importer.New(absPath, importer.Parser(parser), importer.Mode(importer.Protogen)) if err != nil { return xerrors.WrapKV(err, xerrors.KeyBookName, absPath) @@ -450,7 +446,7 @@ func (gen *Generator) extractTypeInfoFromSpecialSheetMode(mode tableaupb.Mode, s Namerow: 1, Datarow: 2, } - parser := confgen.NewSheetParser(TableauProtoPackage, gen.LocationName, sheetOpts) + parser := confgen.NewSheetParser(xproto.TableauProtoPackage, gen.LocationName, sheetOpts) // parse each special sheet mode switch mode { case tableaupb.Mode_MODE_ENUM_TYPE: @@ -529,7 +525,7 @@ func (gen *Generator) parseSpecialSheetMode(mode tableaupb.Mode, ws *tableaupb.W Namerow: 1, Datarow: 2, } - parser := confgen.NewSheetParser(TableauProtoPackage, gen.LocationName, sheetOpts) + parser := confgen.NewSheetParser(xproto.TableauProtoPackage, gen.LocationName, sheetOpts) // parse each special sheet mode switch mode { diff --git a/internal/xproto/package.go b/internal/xproto/package.go new file mode 100644 index 00000000..2a43c98d --- /dev/null +++ b/internal/xproto/package.go @@ -0,0 +1,5 @@ +package xproto + +const ( + TableauProtoPackage = "tableau" +) diff --git a/tableau.go b/tableau.go index e66befdf..e2554ca7 100644 --- a/tableau.go +++ b/tableau.go @@ -9,6 +9,7 @@ import ( "github.com/tableauio/tableau/internal/localizer" "github.com/tableauio/tableau/internal/protogen" "github.com/tableauio/tableau/internal/xlsxgen" + "github.com/tableauio/tableau/internal/xproto" "github.com/tableauio/tableau/log" "github.com/tableauio/tableau/options" ) @@ -92,6 +93,6 @@ func Proto2Excel(protoPackage, indir, outdir string) { // NewImporter creates a new importer of the specified workbook. func NewImporter(workbookPath string) (importer.Importer, error) { - parser := confgen.NewSheetParser(protogen.TableauProtoPackage, "", book.MetasheetOptions()) + parser := confgen.NewSheetParser(xproto.TableauProtoPackage, "", book.MetasheetOptions()) return importer.New(workbookPath, importer.Parser(parser)) } diff --git a/test/functest/conf/PredefinedCrossCellStruct.json b/test/functest/conf/PredefinedCrossCellStruct.json new file mode 100644 index 00000000..638c1be2 --- /dev/null +++ b/test/functest/conf/PredefinedCrossCellStruct.json @@ -0,0 +1,28 @@ +{ + "itemMap": { + "1": { + "id": 1, + "prop": { + "id": 1, + "name": "Apple", + "desc": "A kind of delicious fruit." + } + }, + "2": { + "id": 2, + "prop": { + "id": 2, + "name": "Orange", + "desc": "" + } + }, + "3": { + "id": 3, + "prop": { + "id": 3, + "name": "", + "desc": "" + } + } + } +} \ No newline at end of file diff --git a/test/functest/proto/excel__struct__struct.proto b/test/functest/proto/excel__struct__struct.proto index fe46caf3..9b172822 100644 --- a/test/functest/proto/excel__struct__struct.proto +++ b/test/functest/proto/excel__struct__struct.proto @@ -50,6 +50,16 @@ message InCellStruct { } } +message PredefinedCrossCellStruct { + option (tableau.worksheet) = {name:"PredefinedCrossCellStruct" namerow:1 typerow:2 noterow:3 datarow:4}; + + map item_map = 1 [(tableau.field) = {key:"ID" layout:LAYOUT_VERTICAL}]; + message Item { + uint32 id = 1 [(tableau.field) = {name:"ID"}]; + base.Property prop = 2 [(tableau.field) = {name:"Prop"}]; + } +} + message PredefinedInCellStruct { option (tableau.worksheet) = {name:"PredefinedInCellStruct" namerow:1 typerow:2 noterow:3 datarow:4}; diff --git a/test/functest/testdata/excel/metasheet/BookAlias#@TABLEAU.csv b/test/functest/testdata/excel/metasheet/BookAlias#@TABLEAU.csv index 7dfb5eeb..8c71b851 100644 --- a/test/functest/testdata/excel/metasheet/BookAlias#@TABLEAU.csv +++ b/test/functest/testdata/excel/metasheet/BookAlias#@TABLEAU.csv @@ -1,3 +1,3 @@ -Sheet,Alias -#,AliasedWorkbook -Scalar,AliasedSheetScalar, \ No newline at end of file +Sheet,Alias +#,AliasedWorkbook +Scalar,AliasedSheetScalar diff --git a/test/functest/testdata/excel/struct/Struct#PredefinedCrossCellStruct.csv b/test/functest/testdata/excel/struct/Struct#PredefinedCrossCellStruct.csv new file mode 100644 index 00000000..2bc115bf --- /dev/null +++ b/test/functest/testdata/excel/struct/Struct#PredefinedCrossCellStruct.csv @@ -0,0 +1,6 @@ +ID,PropID,PropName,PropDesc +"map",{base.Property}int32,string,string +Item's ID,Property ID,Property name,Property desc +1,1,Apple,A kind of delicious fruit. +2,2,Orange, +3,3,,