2024-07-26 18:11:29 +00:00
|
|
|
package grammars
|
2024-05-21 22:14:16 +00:00
|
|
|
|
|
|
|
type GrammarOption struct {
|
2024-05-23 17:16:08 +00:00
|
|
|
PropOrder string
|
2024-05-31 07:36:27 +00:00
|
|
|
Prefix string
|
2024-05-23 17:16:08 +00:00
|
|
|
MaybeArray bool
|
|
|
|
DisableParallelNewLines bool
|
|
|
|
MaybeString bool
|
|
|
|
NoMixedFreeString bool
|
2024-05-31 07:36:27 +00:00
|
|
|
ExpectStringsAfterJSON bool
|
2024-07-26 18:11:29 +00:00
|
|
|
|
|
|
|
FunctionName string
|
|
|
|
SchemaType SchemaConverterType
|
2024-05-21 22:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (o *GrammarOption) Apply(options ...func(*GrammarOption)) {
|
|
|
|
for _, l := range options {
|
|
|
|
l(o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var EnableMaybeArray = func(o *GrammarOption) {
|
|
|
|
o.MaybeArray = true
|
|
|
|
}
|
|
|
|
|
2024-05-23 17:16:08 +00:00
|
|
|
var DisableParallelNewLines = func(o *GrammarOption) {
|
|
|
|
o.DisableParallelNewLines = true
|
|
|
|
}
|
|
|
|
|
2024-05-21 22:14:16 +00:00
|
|
|
var EnableMaybeString = func(o *GrammarOption) {
|
|
|
|
o.MaybeString = true
|
|
|
|
}
|
|
|
|
|
|
|
|
var NoMixedFreeString func(*GrammarOption) = func(o *GrammarOption) {
|
|
|
|
o.NoMixedFreeString = true
|
|
|
|
}
|
|
|
|
|
2024-05-31 07:36:27 +00:00
|
|
|
// ExpectStringsAfterJSON enables mixed string suffix
|
|
|
|
var ExpectStringsAfterJSON func(*GrammarOption) = func(o *GrammarOption) {
|
|
|
|
o.ExpectStringsAfterJSON = true
|
|
|
|
}
|
|
|
|
|
2024-05-21 22:14:16 +00:00
|
|
|
func SetPrefix(suffix string) func(*GrammarOption) {
|
|
|
|
return func(o *GrammarOption) {
|
2024-05-31 07:36:27 +00:00
|
|
|
o.Prefix = suffix
|
2024-05-21 22:14:16 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-26 12:59:02 +00:00
|
|
|
|
|
|
|
func SetPropOrder(order string) func(*GrammarOption) {
|
|
|
|
return func(o *GrammarOption) {
|
|
|
|
o.PropOrder = order
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 18:11:29 +00:00
|
|
|
|
|
|
|
func WithSchemaType(schemaType SchemaConverterType) func(*GrammarOption) {
|
|
|
|
return func(o *GrammarOption) {
|
|
|
|
o.SchemaType = schemaType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithFunctionName(name string) func(*GrammarOption) {
|
|
|
|
return func(o *GrammarOption) {
|
|
|
|
o.FunctionName = name
|
|
|
|
}
|
|
|
|
}
|