Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions src/Strategy/Go/Gomod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ gomodParser = do
pure (toGomod name statements')
where
statement =
(singleton <$> goDebugStatements) -- singleton wraps the Parser Statement into a Parser [Statement]
<|> (singleton <$> toolChainStatements)
<|> (singleton <$> toolStatements)
<|> (singleton <$> goVersionStatement)
goDebugStatements -- goDebugStatements is first otherwise goVersion parser overrides it.
<|> (singleton <$> goVersionStatement) -- singleton wraps the Parser Statement into a Parser [Statement]
<|> (singleton <$> toolChainStatement)
<|> toolStatements
<|> requireStatements
<|> replaceStatements
<|> excludeStatements
Expand All @@ -245,18 +245,34 @@ gomodParser = do

-- top-level toolchain statement
-- e.g., toolchain go1.21.1
toolChainStatements :: Parser Statement
toolChainStatements = ToolchainStatement <$ lexeme (chunk "toolchain") <*> anyToken
toolChainStatement :: Parser Statement
toolChainStatement = ToolchainStatement <$ lexeme (chunk "toolchain") <*> anyToken

-- top-level tool statement
-- e.g., tool golang.org/x/tools/cmd/stringer
toolStatements :: Parser Statement
toolStatements = ToolStatement <$ lexeme (chunk "tool") <*> anyToken
-- top-level tool statements
-- e.g.:
-- tool golang.org/x/tools/cmd/stringer
-- tool (
-- github.com/golangci/golangci-lint/v2/cmd/golangci-lint
-- github.com/fossa/fossa-cli
-- )
toolStatements :: Parser [Statement]
toolStatements = block "tool" singleTool

-- top-level godebug statement
-- parse the body of a single tool (without the leading "tool" lexeme)
singleTool = ToolStatement <$> packageName

-- top-level godebug statements
-- e.g., godebug asynctimerchan=0
goDebugStatements :: Parser Statement
goDebugStatements = GoDebugStatements <$ lexeme (chunk "godebug") <*> anyToken
-- godebug (
-- default=go1.21
-- panicnil=1
-- asynctimerchan=0
-- )
goDebugStatements :: Parser [Statement]
goDebugStatements = block "godebug" singleGoDebug

-- parse the body of a single tool (without the leading "godebug" lexeme)
singleGoDebug = GoDebugStatements <$> packageName

-- top-level require statements
-- e.g.:
Expand Down Expand Up @@ -341,7 +357,7 @@ gomodParser = do

-- package name, e.g., golang.org/x/text
packageName :: Parser PackageName
packageName = toText <$> lexeme (some (alphaNumChar <|> char '.' <|> char '/' <|> char '-' <|> char '_'))
packageName = toText <$> lexeme (some (alphaNumChar <|> char '.' <|> char '/' <|> char '-' <|> char '_' <|> char '='))

modulePath :: Parser Text
modulePath =
Expand Down
12 changes: 11 additions & 1 deletion test/Go/testdata/go.mod.edgecases
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ toolchain go1.21.1

tool github.com/golangci/golangci-lint/v2/cmd/golangci-lint

godebug asynctimerchan=0
tool (
github.com/bufbuild/buf/cmd/buf
github.com/wadey/gocovmerge
)

godebug default=go1.21

godebug (
asynctimerchan=0
panicnil=1
)

require repo/name/A v1.0.0 // indirect

Expand Down
Loading