MCPcopy Create free account
hub / github.com/akyoto/q / compileLoopControl

Method compileLoopControl

src/core/compileLoopControl.go:10–47  ·  view source on GitHub ↗

compileLoopControl compiles loop control statements.

(control *ast.LoopControl)

Source from the content-addressed store, hash-verified

8
9// compileLoopControl compiles loop control statements.
10func (f *Function) compileLoopControl(control *ast.LoopControl) error {
11 call := control.Expression
12
13 if call.Token.Kind != token.Call {
14 return errors.New(InvalidExpression, f.File, control.Expression.Source())
15 }
16
17 if len(call.Children) != 1 {
18 return errors.New(InvalidExpression, f.File, control.Expression.Source())
19 }
20
21 loop := f.loopStack.Current()
22
23 if loop == nil {
24 return errors.New(LoopControlWithoutLoop, f.File, control.Expression.Source())
25 }
26
27 name := call.Children[0].Token.StringFrom(f.File.Bytes)
28
29 switch name {
30 case "next":
31 f.loopNext(loop)
32 case "restart":
33 // reserved
34 case "stop":
35 f.jump(loop.Exit)
36 default:
37 correctName := ""
38
39 if name == "break" {
40 correctName = "stop"
41 }
42
43 return errors.New(&InvalidLoopControl{Name: name, CorrectName: correctName}, f.File, call.Children[0].Source())
44 }
45
46 return nil
47}

Callers 1

compileASTNodeMethod · 0.95

Calls 6

loopNextMethod · 0.95
jumpMethod · 0.95
NewFunction · 0.92
CurrentMethod · 0.80
StringFromMethod · 0.65
SourceMethod · 0.45

Tested by

no test coverage detected