JOJ3/internal/parser/plugin/parser.go
张泊明518370910136 1e75ab1c6e
All checks were successful
submodules sync / sync (push) Successful in 46s
build / build (push) Successful in 1m48s
build / trigger-build-image (push) Successful in 8s
feat(parser/plugin): new parser that can load from a plugin (#81)
2025-02-17 09:10:19 -05:00

32 lines
654 B
Go

package plugin
import (
"fmt"
"plugin"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
func (*Plugin) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
plug, err := plugin.Open(conf.ModPath)
if err != nil {
return nil, true, err
}
symParser, err := plug.Lookup(conf.SymName)
if err != nil {
return nil, true, err
}
var parser stage.Parser
parser, ok := symParser.(stage.Parser)
if !ok {
return nil, true, fmt.Errorf("unexpected type from module symbol")
}
return parser.Run(results, confAny)
}