Skip to main content
Glama

protolint-mcp

by yoheimuta
interpreter.go2.13 kB
package disablerule import "github.com/yoheimuta/go-protoparser/v4/parser" // Interpreter represents an interpreter for disable rule comments. type Interpreter struct { ruleID string isDisabled bool } // NewInterpreter creates an Interpreter. func NewInterpreter( ruleID string, ) *Interpreter { return &Interpreter{ ruleID: ruleID, } } // Interpret interprets comments and returns a bool whether not apply the rule to a next or this element. func (i *Interpreter) Interpret( comments []*parser.Comment, inlines ...*parser.Comment, ) (isDisabled bool) { cmds := newCommands(comments) inlineCmds := newCommands(inlines) allCmds := append(append([]command{}, cmds...), inlineCmds...) return i.interpret(allCmds) || i.interpretNext(cmds) || i.interpretThis(inlineCmds) || i.isDisabled } // CallEachIfValid calls a given function each time the line is not disabled. func (i *Interpreter) CallEachIfValid( lines []string, f func(index int, line string), ) { shouldSkip := false for index, line := range lines { cmd, err := newCommand(line) if err != nil { if !i.isDisabled && !shouldSkip { f(index, line) } if shouldSkip { shouldSkip = false } continue } if cmd.enabled(i.ruleID) { i.isDisabled = false f(index, line) continue } if cmd.disabled(i.ruleID) { i.isDisabled = true continue } if cmd.disabledThis(i.ruleID) { continue } if cmd.disabledNext(i.ruleID) { shouldSkip = true f(index, line) continue } if shouldSkip { shouldSkip = false continue } if i.isDisabled { continue } f(index, line) } } func (i *Interpreter) interpret( cmds commands, ) bool { id := i.ruleID if cmds.enabled(id) { i.isDisabled = false return false } if cmds.disabled(id) { i.isDisabled = true return true } return false } func (i *Interpreter) interpretNext( cmds commands, ) bool { id := i.ruleID if cmds.disabledNext(id) { return true } return false } func (i *Interpreter) interpretThis( cmds commands, ) bool { id := i.ruleID if cmds.disabledThis(id) { return true } return false }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yoheimuta/protolint'

If you have feedback or need assistance with the MCP directory API, please join our Discord server