Skip to content

Commit

Permalink
Add postfix if the field name matches keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
ccycle committed Feb 16, 2023
1 parent aebd273 commit d89c30d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Proto3/Suite/DotProto/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,16 @@ prefixedFieldName msgName fieldName = do

prefixedFieldNameWithFlag :: MonadError CompileError m => IsPrefixed -> String -> String -> m String
prefixedFieldNameWithFlag (IsPrefixed flag) msgName fieldName = do
if flag then prefixedFieldName msgName fieldName else return fieldName
if flag then prefixedFieldName msgName fieldName else return $ if fieldName `elem` keywords then fieldName ++ "_" else fieldName
where
-- copy from https://hackage.haskell.org/package/hscolour-1.20.3/docs/src/Language-Haskell-HsColour-Classify.html#keywords
-- and remove "forall", "qualified", "ccall", "as", "safe", "unsafe"
keywords =
["case","class","data","default","deriving","do","else"
,"if","import","in","infix","infixl","infixr","instance","let","module"
,"newtype","of","then","type","where","_"
,"foreign"
]

dpIdentUnqualName :: MonadError CompileError m => DotProtoIdentifier -> m String
dpIdentUnqualName (Single name) = pure name
Expand Down

0 comments on commit d89c30d

Please sign in to comment.