From 49b7c7c5db6ded8835469e51f9867c426313fb93 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Tue, 11 Feb 2025 03:41:17 -0500 Subject: [PATCH] chore(parser): move Conf struct to meta.go --- internal/parser/clangtidy/meta.go | 16 ++++++++++++++++ internal/parser/clangtidy/parser.go | 16 ---------------- internal/parser/cppcheck/meta.go | 15 +++++++++++++++ internal/parser/cppcheck/parser.go | 15 --------------- internal/parser/cpplint/meta.go | 15 +++++++++++++++ internal/parser/cpplint/parser.go | 15 --------------- internal/parser/debug/meta.go | 4 ++++ internal/parser/debug/parser.go | 4 ---- internal/parser/diff/meta.go | 20 ++++++++++++++++++++ internal/parser/diff/parser.go | 20 -------------------- internal/parser/dummy/meta.go | 8 ++++++++ internal/parser/dummy/parser.go | 8 -------- internal/parser/healthcheck/meta.go | 7 +++++++ internal/parser/healthcheck/parser.go | 7 ------- internal/parser/keyword/meta.go | 15 +++++++++++++++ internal/parser/keyword/parser.go | 15 --------------- internal/parser/log/meta.go | 8 ++++++++ internal/parser/log/parser.go | 8 -------- internal/parser/resultdetail/meta.go | 15 +++++++++++++++ internal/parser/resultdetail/parser.go | 15 --------------- internal/parser/resultstatus/meta.go | 8 ++++++++ internal/parser/resultstatus/parser.go | 8 -------- internal/parser/sample/meta.go | 9 +++++++++ internal/parser/sample/parser.go | 9 --------- 24 files changed, 140 insertions(+), 140 deletions(-) diff --git a/internal/parser/clangtidy/meta.go b/internal/parser/clangtidy/meta.go index 4b00adf..366d7a8 100644 --- a/internal/parser/clangtidy/meta.go +++ b/internal/parser/clangtidy/meta.go @@ -4,6 +4,22 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "clangtidy" +type Match struct { + Keywords []string + Score int +} + +type Conf struct { + Score int + RootDir string `default:"/w"` + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` +} + +type ClangTidy struct{} + func init() { stage.RegisterParser(name, &ClangTidy{}) } diff --git a/internal/parser/clangtidy/parser.go b/internal/parser/clangtidy/parser.go index 58505d4..c9e280b 100644 --- a/internal/parser/clangtidy/parser.go +++ b/internal/parser/clangtidy/parser.go @@ -6,22 +6,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Match struct { - Keywords []string - Score int -} - -type Conf struct { - Score int - RootDir string `default:"/w"` - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` - ForceQuitOnDeduct bool `default:"false"` -} - -type ClangTidy struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { stdout := executorResult.Files[conf.Stdout] // stderr := executorResult.Files[conf.Stderr] diff --git a/internal/parser/cppcheck/meta.go b/internal/parser/cppcheck/meta.go index 3013177..15c8880 100644 --- a/internal/parser/cppcheck/meta.go +++ b/internal/parser/cppcheck/meta.go @@ -4,6 +4,21 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "cppcheck" +type Match struct { + Keywords []string + Score int +} + +type Conf struct { + Score int + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` +} + +type CppCheck struct{} + func init() { stage.RegisterParser(name, &CppCheck{}) } diff --git a/internal/parser/cppcheck/parser.go b/internal/parser/cppcheck/parser.go index d1b00ea..4a56bff 100644 --- a/internal/parser/cppcheck/parser.go +++ b/internal/parser/cppcheck/parser.go @@ -8,19 +8,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Match struct { - Keywords []string - Score int -} - -type Conf struct { - Score int - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` - ForceQuitOnDeduct bool `default:"false"` -} - type Record struct { File string `json:"file"` Line int `json:"line"` @@ -30,8 +17,6 @@ type Record struct { Id string `json:"id"` } -type CppCheck struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { // stdout := executorResult.Files[conf.Stdout] stderr := executorResult.Files[conf.Stderr] diff --git a/internal/parser/cpplint/meta.go b/internal/parser/cpplint/meta.go index 4f3adbd..9f5d2fe 100644 --- a/internal/parser/cpplint/meta.go +++ b/internal/parser/cpplint/meta.go @@ -4,6 +4,21 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "cpplint" +type Match struct { + Keywords []string + Score int +} + +type Conf struct { + Score int + Matches []Match + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` + ForceQuitOnDeduct bool `default:"false"` +} + +type Cpplint struct{} + func init() { stage.RegisterParser(name, &Cpplint{}) } diff --git a/internal/parser/cpplint/parser.go b/internal/parser/cpplint/parser.go index 6537b00..bf69301 100644 --- a/internal/parser/cpplint/parser.go +++ b/internal/parser/cpplint/parser.go @@ -9,21 +9,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Match struct { - Keywords []string - Score int -} - -type Conf struct { - Score int - Matches []Match - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` - ForceQuitOnDeduct bool `default:"false"` -} - -type Cpplint struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { stderr := executorResult.Files[conf.Stderr] pattern := `(.+):(\d+): (.+) \[(.+)\] \[(\d)]\n` diff --git a/internal/parser/debug/meta.go b/internal/parser/debug/meta.go index a1d807b..224d045 100644 --- a/internal/parser/debug/meta.go +++ b/internal/parser/debug/meta.go @@ -4,6 +4,10 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "debug" +type Conf struct{} + +type Debug struct{} + func init() { stage.RegisterParser(name, &Debug{}) } diff --git a/internal/parser/debug/parser.go b/internal/parser/debug/parser.go index 4efc6f6..61cdc3b 100644 --- a/internal/parser/debug/parser.go +++ b/internal/parser/debug/parser.go @@ -6,10 +6,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Conf struct{} - -type Debug struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { slog.Debug("debug parser", "executorResult", executorResult) for name, content := range executorResult.Files { diff --git a/internal/parser/diff/meta.go b/internal/parser/diff/meta.go index 023d1c0..181abd2 100644 --- a/internal/parser/diff/meta.go +++ b/internal/parser/diff/meta.go @@ -4,6 +4,26 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "diff" +type Conf struct { + PassComment string `default:"🥳Passed!\n"` + FailComment string `default:"🧐Failed...\n"` + FailOnNotAccepted bool `default:"true"` + ForceQuitOnFailed bool `default:"false"` + Cases []struct { + Outputs []struct { + Score int + FileName string + AnswerPath string + CompareSpace bool + AlwaysHide bool + ForceQuitOnDiff bool + MaxDiffLength int `default:"2048"` // just for reference + } + } +} + +type Diff struct{} + func init() { stage.RegisterParser(name, &Diff{}) } diff --git a/internal/parser/diff/parser.go b/internal/parser/diff/parser.go index 3fd6777..fbf5dae 100644 --- a/internal/parser/diff/parser.go +++ b/internal/parser/diff/parser.go @@ -19,26 +19,6 @@ const ( MOVE ) -type Conf struct { - PassComment string `default:"🥳Passed!\n"` - FailComment string `default:"🧐Failed...\n"` - FailOnNotAccepted bool `default:"true"` - ForceQuitOnFailed bool `default:"false"` - Cases []struct { - Outputs []struct { - Score int - FileName string - AnswerPath string - CompareSpace bool - AlwaysHide bool - ForceQuitOnDiff bool - MaxDiffLength int `default:"2048"` // just for reference - } - } -} - -type Diff struct{} - func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { diff --git a/internal/parser/dummy/meta.go b/internal/parser/dummy/meta.go index 202fad8..fd9aaef 100644 --- a/internal/parser/dummy/meta.go +++ b/internal/parser/dummy/meta.go @@ -4,6 +4,14 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "dummy" +type Conf struct { + Score int + Comment string + ForceQuit bool +} + +type Dummy struct{} + func init() { stage.RegisterParser(name, &Dummy{}) } diff --git a/internal/parser/dummy/parser.go b/internal/parser/dummy/parser.go index 86cc258..cb33e1f 100644 --- a/internal/parser/dummy/parser.go +++ b/internal/parser/dummy/parser.go @@ -4,14 +4,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Conf struct { - Score int - Comment string - ForceQuit bool -} - -type Dummy struct{} - func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { diff --git a/internal/parser/healthcheck/meta.go b/internal/parser/healthcheck/meta.go index 4c14311..879a7e9 100644 --- a/internal/parser/healthcheck/meta.go +++ b/internal/parser/healthcheck/meta.go @@ -4,6 +4,13 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "healthcheck" +type Healthcheck struct{} + +type Conf struct { + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` +} + func init() { stage.RegisterParser(name, &Healthcheck{}) } diff --git a/internal/parser/healthcheck/parser.go b/internal/parser/healthcheck/parser.go index a78cdae..4ac3194 100644 --- a/internal/parser/healthcheck/parser.go +++ b/internal/parser/healthcheck/parser.go @@ -10,13 +10,6 @@ import ( "github.com/joint-online-judge/JOJ3/pkg/healthcheck" ) -type Healthcheck struct{} - -type Conf struct { - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` -} - func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) { stdout := executorResult.Files[conf.Stdout] stderr := executorResult.Files[conf.Stderr] diff --git a/internal/parser/keyword/meta.go b/internal/parser/keyword/meta.go index 36814af..bc0e4b9 100644 --- a/internal/parser/keyword/meta.go +++ b/internal/parser/keyword/meta.go @@ -4,6 +4,21 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "keyword" +type Match struct { + Keywords []string + Score int + MaxMatchCount int +} + +type Conf struct { + Score int + Files []string + ForceQuitOnDeduct bool `default:"false"` + Matches []Match +} + +type Keyword struct{} + func init() { stage.RegisterParser(name, &Keyword{}) } diff --git a/internal/parser/keyword/parser.go b/internal/parser/keyword/parser.go index dc3a4b5..53248a0 100644 --- a/internal/parser/keyword/parser.go +++ b/internal/parser/keyword/parser.go @@ -8,21 +8,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Match struct { - Keywords []string - Score int - MaxMatchCount int -} - -type Conf struct { - Score int - Files []string - ForceQuitOnDeduct bool `default:"false"` - Matches []Match -} - -type Keyword struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { score := conf.Score comment := "" diff --git a/internal/parser/log/meta.go b/internal/parser/log/meta.go index bb578d1..db4b87c 100644 --- a/internal/parser/log/meta.go +++ b/internal/parser/log/meta.go @@ -4,6 +4,14 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "log" +type Conf struct { + FileName string `default:"stdout"` + Msg string `default:"log msg"` + Level int `default:"0"` +} + +type Log struct{} + func init() { stage.RegisterParser(name, &Log{}) } diff --git a/internal/parser/log/parser.go b/internal/parser/log/parser.go index 16e1a01..cc4d483 100644 --- a/internal/parser/log/parser.go +++ b/internal/parser/log/parser.go @@ -9,14 +9,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Conf struct { - FileName string `default:"stdout"` - Msg string `default:"log msg"` - Level int `default:"0"` -} - -type Log struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { content := executorResult.Files[conf.FileName] var data map[string]any diff --git a/internal/parser/resultdetail/meta.go b/internal/parser/resultdetail/meta.go index 06c13cd..e3a7185 100644 --- a/internal/parser/resultdetail/meta.go +++ b/internal/parser/resultdetail/meta.go @@ -4,6 +4,21 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "result-detail" +type Conf struct { + Score int + ShowExecutorStatus bool `default:"true"` + ShowExitStatus bool `default:"false"` + ShowError bool `default:"false"` + ShowTime bool `default:"true"` + ShowMemory bool `default:"true"` + ShowRunTime bool `default:"false"` + ShowFiles []string + FilesInCodeBlock bool `default:"true"` + MaxFileLength int `default:"65536"` +} + +type ResultDetail struct{} + func init() { stage.RegisterParser(name, &ResultDetail{}) } diff --git a/internal/parser/resultdetail/parser.go b/internal/parser/resultdetail/parser.go index f4e19ad..01bf768 100644 --- a/internal/parser/resultdetail/parser.go +++ b/internal/parser/resultdetail/parser.go @@ -6,21 +6,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Conf struct { - Score int - ShowExecutorStatus bool `default:"true"` - ShowExitStatus bool `default:"false"` - ShowError bool `default:"false"` - ShowTime bool `default:"true"` - ShowMemory bool `default:"true"` - ShowRunTime bool `default:"false"` - ShowFiles []string - FilesInCodeBlock bool `default:"true"` - MaxFileLength int `default:"65536"` -} - -type ResultDetail struct{} - func (*ResultDetail) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { diff --git a/internal/parser/resultstatus/meta.go b/internal/parser/resultstatus/meta.go index 579d2bb..7eff5b2 100644 --- a/internal/parser/resultstatus/meta.go +++ b/internal/parser/resultstatus/meta.go @@ -4,6 +4,14 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "result-status" +type Conf struct { + Score int + Comment string + ForceQuitOnNotAccepted bool `default:"true"` +} + +type ResultStatus struct{} + func init() { stage.RegisterParser(name, &ResultStatus{}) } diff --git a/internal/parser/resultstatus/parser.go b/internal/parser/resultstatus/parser.go index 485179f..9282246 100644 --- a/internal/parser/resultstatus/parser.go +++ b/internal/parser/resultstatus/parser.go @@ -7,14 +7,6 @@ import ( "github.com/joint-online-judge/JOJ3/internal/stage" ) -type Conf struct { - Score int - Comment string - ForceQuitOnNotAccepted bool `default:"true"` -} - -type ResultStatus struct{} - func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( []stage.ParserResult, bool, error, ) { diff --git a/internal/parser/sample/meta.go b/internal/parser/sample/meta.go index cfae4e8..8d3873a 100644 --- a/internal/parser/sample/meta.go +++ b/internal/parser/sample/meta.go @@ -4,6 +4,15 @@ import "github.com/joint-online-judge/JOJ3/internal/stage" var name = "sample" +type Conf struct { + Score int + Comment string + Stdout string `default:"stdout"` + Stderr string `default:"stderr"` +} + +type Sample struct{} + func init() { stage.RegisterParser(name, &Sample{}) } diff --git a/internal/parser/sample/parser.go b/internal/parser/sample/parser.go index 95a411f..9f9cf13 100644 --- a/internal/parser/sample/parser.go +++ b/internal/parser/sample/parser.go @@ -8,15 +8,6 @@ import ( "github.com/joint-online-judge/JOJ3/pkg/sample" ) -type Conf struct { - Score int - Comment string - Stdout string `default:"stdout"` - Stderr string `default:"stderr"` -} - -type Sample struct{} - func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { stdout := executorResult.Files[conf.Stdout] // stderr := executorResult.Files[conf.Stderr]