diff --git a/codegen/arrai/auto/go.arrai b/codegen/arrai/auto/go.arrai index 61c4aff7..e8a06633 100644 --- a/codegen/arrai/auto/go.arrai +++ b/codegen/arrai/auto/go.arrai @@ -2,7 +2,10 @@ let sysl = //{./sysl}; let name = let wordRE = //re.compile(`[\p{L}_][\p{L}\p{N}_]*`); - let trimRE = //re.compile(`^_+`).sub(""); + # types starting with _ aren't exported so remove the underscores + # types can't start with an integer, if it does add an N to the start + let trimRE = \word + //re.compile(`^_+`).sub("", word) -> //re.compile(`^(\d)`).sub("N$1", .); let initialisms = { # https://github.com/golang/lint/blob/8f45f776aaf18cebc8d65861cc70c33c60471952/lint.go#L771 "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", @@ -15,8 +18,8 @@ let name = }; let uppers = \word (wordRE.match(word) >> .(0)) -> \[first, ...rest] [trimRE(first)] ++ rest >> \v - let upper = //str.upper(trimRE(v)); - cond {upper <: initialisms: upper, _: //str.title(v)}; + let upper = //str.upper(trimRE(v)); + cond {upper <: initialisms: upper, _: //str.title(v)}; \word let result = cond word {"": "", _: //seq.concat(uppers(word))}; cond {result <: restricted: result++"_", _: result}; diff --git a/codegen/arrai/auto/tests/rest_miscellaneous/cmd/gateway/main_test.go b/codegen/arrai/auto/tests/rest_miscellaneous/cmd/gateway/main_test.go index 2c4d4260..cbde9849 100644 --- a/codegen/arrai/auto/tests/rest_miscellaneous/cmd/gateway/main_test.go +++ b/codegen/arrai/auto/tests/rest_miscellaneous/cmd/gateway/main_test.go @@ -354,6 +354,12 @@ func TestMiscellaneous_DoubleUnderscore(t *testing.T) { _ = encoder_backend.Double_underscore{S: "accessible"} } +func TestMiscellaneous_StartWithInteger(t *testing.T) { + t.Parallel() + // Just want to confirm that it generates a valid type + _ = encoder_backend.N1TypeStartsWithInt{N1s: "accessible"} +} + func TestMiscellaneous_TypesSomethingExternal(t *testing.T) { t.Parallel() diff --git a/codegen/arrai/auto/tests/rest_miscellaneous/specs/encoder_backend.sysl b/codegen/arrai/auto/tests/rest_miscellaneous/specs/encoder_backend.sysl index 7f25a185..692ee56b 100644 --- a/codegen/arrai/auto/tests/rest_miscellaneous/specs/encoder_backend.sysl +++ b/codegen/arrai/auto/tests/rest_miscellaneous/specs/encoder_backend.sysl @@ -23,3 +23,9 @@ EncoderBackend [package="encoder_backend", ~vars_in_url_name]: !type __double_underscore: __s <: string + /start_with_int: + POST: + return ok <: _1TypeStartsWithInt + + !type _1TypeStartsWithInt: + _1s <: string