genMinima.go 1.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package gengo

import (
	"fmt"
	"io"

	wish "github.com/warpfork/go-wish"
)

// EmitInternalEnums creates a file with enum types used internal.
// For example, the state machine values used in map and list builders.
func EmitInternalEnums(packageName string, w io.Writer) {
	fmt.Fprint(w, wish.Dedent(`
		package `+packageName+`

16 17 18 19
		import (
			"github.com/ipld/go-ipld-prime/schema"
		)

20 21
		// Code generated go-ipld-prime DO NOT EDIT.

22 23 24 25 26 27 28 29 30 31
		const (
			// The 'Maybe' enum does double-duty in this package as a state machine for assembler completion.
			// The 'Maybe_Absent' value gains the additional semantic of "clear to assign (but not null)"
			//  (which works because if you're *in* a value assembler, "absent" as a final result is already off the table).
			// Additionally, we get a few extra states that we cram into the same area of bits:

			midvalue = schema.Maybe(4) // used by assemblers of recursives to block AssignNull after BeginX.
			allowNull = schema.Maybe(5) // used by parent assemblers to tell child a transition to Maybe_Null is allowed.
		)

32 33 34 35 36 37 38 39 40
		type maState uint8

		const (
			maState_initial     maState = iota
			maState_midKey
			maState_expectValue
			maState_midValue
			maState_finished
		)
Eric Myhre's avatar
Eric Myhre committed
41 42 43 44 45 46 47 48

		type laState uint8

		const (
			laState_initial  laState = iota
			laState_midValue
			laState_finished
		)
49 50
	`))
}