-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proto->sysl: filter out duplicate enum values (#925)
- Loading branch information
1 parent
423659f
commit 2239b33
Showing
7 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
|
@@ -241,10 +241,21 @@ let type = \message \file \appName \imports \prefix | |
# `enum` the enum being converted. | ||
# `file` the file the enum is located in. | ||
let enum = \enum \file | ||
let fields = [email protected]?:{} => (@: .@, @value: evalNumber([email protected]), deprecated: [email protected]?('deprecated')?.b?:false); | ||
let nested = fields nest|@,deprecated|e; | ||
( | ||
name: syslSafeName(enum.@), | ||
attrs: baseAttrs(enum, file), | ||
enum: (items: [email protected]?:{} => (@: .@, @value: evalNumber([email protected]))) | ||
enum: (items: (fields where \f | ||
(let n = ((nested where .@value = f.@value) single).e; | ||
cond { | ||
n count = 1: true, # only entry for value | ||
(n where !.deprecated) count > 1: //error($`enum with multiple names for value ${f.@value} found: ${(n where !.deprecated) => .@}`), | ||
!f.deprecated: true, # this is the only non-deprecated | ||
(n where !.deprecated) count = 1: false, # this is deprecated and there is a non-deprecated value | ||
(n => .@ orderby .)(0) = f.@: true, # use the first (alphabetically) deprecated value | ||
_: false, # skip it | ||
})) => (@: .@, @value: .@value)) | ||
); | ||
|
||
# `endpoint` creates an endpoint out of a rpc. | ||
|
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,15 @@ | ||
syntax = "proto3"; | ||
package enums; | ||
enum e { | ||
E0 = 0; | ||
E1 = 1; | ||
E1_DEP = 1 [deprecated = true]; | ||
E2 = 2; | ||
E2_DEP1 = 2 [deprecated = true]; | ||
E2_DEP2 = 2 [deprecated = true]; | ||
E3_DEP = 3 [deprecated = true]; | ||
E4_DEP1 = 4 [deprecated = true]; | ||
E4_DEP2 = 4 [deprecated = true]; | ||
E5_DEP2 = 5 [deprecated = true]; | ||
E5_DEP1 = 5 [deprecated = true]; | ||
} |
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,12 @@ | ||
# Code generated by Sysl. DO NOT EDIT. | ||
|
||
enums: | ||
@package = "enums" | ||
|
||
!enum e [source_path="proto/tests/enum.proto"]: | ||
E0 : 0 | ||
E1 : 1 | ||
E2 : 2 | ||
E3_DEP : 3 | ||
E4_DEP1 : 4 | ||
E5_DEP1 : 5 |
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,6 @@ | ||
syntax = "proto3"; | ||
package enums; | ||
enum e { | ||
E0 = 0; | ||
E1 = 0; | ||
} |