/*
Generated by PEG.js 0.10.0.

http://pegjs.org/
352990
function peg$subclass(child, parent) {
  function ctor() {
    this.constructor = child;
  }
  ctor.prototype = parent.prototype;
  child.prototype = new ctor();
}
1278471
func (app *App) RegFlags() {
	if app.Flags.values == nil {
		app.Flags.values = make(map[string]Flag)
	}
	app.flagsRegistered = true
	for _, v := range app.flagsQueue {
		app.Flags.values[v.Name] = Flag{
			Name:        v.Name,
			Description: v.Description,
			Default:     v.Default,
			Value:       flag.String(v.Name, v.Default, v.Description),
		}
	}
}
1140608
func (p *Polygon) ChainEdge(i, j int) Edge {
	return Edge{p.Loop(i).OrientedVertex(j), p.Loop(i).OrientedVertex(j + 1)}
}
1330904
func main() {
	env, err := plugins.NewEnvironment()
	env.RespondAndExitIfError(err)

	packageName, err := resolvePackageName(env.Request.OutputPath)
	env.RespondAndExitIfError(err)

	// Use the name used to run the plugin to decide which files to generate.
	var files []string
	switch {
	case strings.Contains(env.Invocation, "gnostic-go-client"):
		files = []string{"client.go", "types.go", "constants.go"}
	case strings.Contains(env.Invocation, "gnostic-go-server"):
		files = []string{"server.go", "provider.go", "types.go", "constants.go"}
	default:
		files = []string{"client.go", "server.go", "provider.go", "types.go", "constants.go"}
	}

	for _, model := range env.Request.Models {
		switch model.TypeUrl {
		case "surface.v1.Model":
			surfaceModel := &surface.Model{}
			err = proto.Unmarshal(model.Value, surfaceModel)
			if err == nil {
				// Customize the code surface model for Go
				NewGoLanguageModel().Prepare(surfaceModel)

				modelJSON, _ := json.MarshalIndent(surfaceModel, "", "  ")
				modelFile := &plugins.File{Name: "model.json", Data: modelJSON}
				env.Response.Files = append(env.Response.Files, modelFile)

				// Create the renderer.
				renderer, err := NewServiceRenderer(surfaceModel)
				renderer.Package = packageName
				env.RespondAndExitIfError(err)

				// Run the renderer to generate files and add them to the response object.
				err = renderer.Render(env.Response, files)
				env.RespondAndExitIfError(err)

				// Return with success.
				env.RespondAndExit()
			}
		}
	}
	err = errors.New("No generated code surface model is available.")
	env.RespondAndExitIfError(err)
}
49059
func (p *Polygon) initEdgesAndIndex() {
	if p.IsFull() {
		return
	}
	const maxLinearSearchLoops = 12 // Based on benchmarks.
	if len(p.loops) > maxLinearSearchLoops {
		p.cumulativeEdges = make([]int, 0, len(p.loops))
	}

	for _, l := range p.loops {
		if p.cumulativeEdges != nil {
			p.cumulativeEdges = append(p.cumulativeEdges, p.numEdges)
		}
		p.numEdges += len(l.vertices)
	}

	p.index = NewShapeIndex()
	p.index.Add(p)
}
1029840
func PaddleIconStyle(id string) kml.Element {
	return kml.IconStyle(
		kml.HotSpot(kml.Vec2{X: 0.5, Y: 0, XUnits: "fraction", YUnits: "fraction"}),
		kml.Icon(
			kml.Href(PaddleHref(id)),
		),
	)
}
1082183
func PaddedCellFromParentIJ(parent *PaddedCell, i, j int) *PaddedCell {
	// Compute the position and orientation of the child incrementally from the
	// orientation of the parent.
	pos := ijToPos[parent.orientation][2*i+j]

	p := &PaddedCell{
		id:          parent.id.Children()[pos],
		padding:     parent.padding,
		bound:       parent.bound,
		orientation: parent.orientation ^ posToOrientation[pos],
		level:       parent.level + 1,
		middle:      r2.EmptyRect(),
	}

	ijSize := sizeIJ(p.level)
	p.iLo = parent.iLo + i*ijSize
	p.jLo = parent.jLo + j*ijSize

	// For each child, one corner of the bound is taken directly from the parent
	// while the diagonally opposite corner is taken from middle().
	middle := parent.Middle()
	if i == 1 {
		p.bound.X.Lo = middle.X.Lo
	} else {
		p.bound.X.Hi = middle.X.Hi
	}
	if j == 1 {
		p.bound.Y.Lo = middle.Y.Lo
	} else {
		p.bound.Y.Hi = middle.Y.Hi
	}

	return p
}
714445
func Flatten(obj interface{}, filter []string, primitiveOnly bool) map[string]string {
	flat := make(map[string]string)
	v := reflect.ValueOf(obj)
	if !v.IsValid() {
		return nil
	}

	flatten("", v, primitiveOnly, false, flat)
	for _, f := range filter {
		if _, ok := flat[f]; ok {
			delete(flat, f)
		}
	}
	return flat
}
825604
func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag {
	var flags []cli.Flag
	for _, slice := range flagSlices {
		flags = append(flags, slice...)
	}
	return flags
}
1063780
func anyxmlIndent(m map[string]interface{}, prefix string, indent string, rootTag ...string) ([]byte, error) {
	var err error
	s := new(string)
	p := new(pretty)
	p.indent = indent
	p.padding = prefix

	if len(m) == 1 && len(rootTag) == 0 {
		// this can extract the key for the single map element
		// use it if it isn't a key for a list
		for key, value := range m {
			if _, ok := value.([]interface{}); ok {
				err = mapToXmlIndent(true, s, DefaultRootTag, m, p)
			} else {
				err = mapToXmlIndent(true, s, key, value, p)
			}
		}
	} else if len(rootTag) == 1 {
		err = mapToXmlIndent(true, s, rootTag[0], m, p)
	} else {
		err = mapToXmlIndent(true, s, DefaultRootTag, m, p)
	}
	return []byte(*s), err
}
923497
func main() {
	request := []string{"Hello world"}
	reply := []string{}
	var err error

	endpoints := len(os.Args) - 1
	if endpoints == 0 {
		fmt.Printf("I: syntax: %s <endpoint> ...\n", os.Args[0])
	} else if endpoints == 1 {
		//  For one endpoint, we retry N times
		for retries := 0; retries < MAX_RETRIES; retries++ {
			endpoint := os.Args[1]
			reply, err = try_request(endpoint, request)
			if err == nil {
				break //  Successful
			}
			fmt.Printf("W: no response from %s, retrying...\n", endpoint)
		}
	} else {
		//  For multiple endpoints, try each at most once
		for endpoint_nbr := 0; endpoint_nbr < endpoints; endpoint_nbr++ {
			endpoint := os.Args[endpoint_nbr+1]
			reply, err = try_request(endpoint, request)
			if err == nil {
				break //  Successful
			}
			fmt.Println("W: no response from", endpoint)
		}
	}
	if len(reply) > 0 {
		fmt.Printf("Service is running OK: %q\n", reply)
	}
}
439425
func Massage(in bytes.Buffer) string {
	svg := string(in.Bytes())

	// Work around for dot bug which misses quoting some ampersands,
	// resulting on unparsable SVG.
	svg = strings.Replace(svg, "&;", "&amp;;", -1)

	//Dot's SVG output is
	//
	//    <svg width="___" height="___"
	//     viewBox="___" xmlns=...>
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </svg>
	//
	// Change it to
	//
	//    <svg width="100%" height="100%"
	//     xmlns=...>
	//    <script>...</script>
	//    <g id="viewport" transform="translate(0,0)">
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </g>
	//    </svg>

	if loc := viewBox.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<svg width="100%" height="100%"` +
			svg[loc[1]:]
	}

	if loc := graphId.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<script type="text/ecmascript"><![CDATA[` + svgPanJS + `]]></script>` +
			`<g id="viewport" transform="scale(0.5,0.5) translate(0,0)">` +
			svg[loc[0]:]
	}

	if loc := svgClose.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`</g>` +
			svg[loc[0]:]
	}

	return svg
}
260617
func _() {
	var _ Event = (*Absolute)(nil)        // assert *Absolute implements Event
	var _ Event = (*FAbsolute)(nil)       // assert *FAbsolute implements Event
	var _ Event = (*Gauge)(nil)           // assert *Gauge implements Event
	var _ Event = (*FGauge)(nil)          // assert *FGauge implements Event
	var _ Event = (*GaugeDelta)(nil)      // assert *GaugeDelta implements Event
	var _ Event = (*FGaugeDelta)(nil)     // assert *FGaugeDelta implements Event
	var _ Event = (*Increment)(nil)       // assert *Increment implements Event
	var _ Event = (*PrecisionTiming)(nil) // assert *PrecisionTiming implements Event
	var _ Event = (*Timing)(nil)          // assert *Timing implements Event
	var _ Event = (*Total)(nil)           // assert *Total implements Event
}
535580
func generateLabelString(source, key, value string) string {
	return fmt.Sprintf("%s:%s=%s", source, key, value)
}
755113
func layoutPlotElts(elts []plotElt) layout.Element {
	// Add padding elements to each subplot.
	//
	// TODO: Should there be padding between labels and the plot?
	for _, elt := range elts {
		elt, ok := elt.(*eltSubplot)
		if !ok {
			continue
		}
		x, y := elt.xPath[0], elt.yPath[0]
		elts = append(elts,
			newEltPadding('t', x, y),
			newEltPadding('r', x, y),
			newEltPadding('b', x, y),
			newEltPadding('l', x, y),
		)
	}

	// Construct the global element grid from coordinate paths by
	// sorting the sets of X paths and Y paths to each leaf and
	// computing a global (x,y) for each leaf from these orders.
	type eltPos struct {
		x, y, xSpan, ySpan int
	}
	flat := map[plotElt]eltPos{}
	dir := func(get func(plotElt) (p, p2 eltPath), set func(p *eltPos, pos, span int)) {
		var paths eltPaths
		for _, elt := range elts {
			p, p2 := get(elt)
			paths = append(paths, p)
			if p2 != nil {
				paths = append(paths, p2)
			}
		}
		sort.Sort(paths)
		paths = paths.nub()
		for _, elt := range elts {
			p, p2 := get(elt)
			pos, span := paths.find(p), 1
			if p2 != nil {
				span = paths.find(p2) - pos + 1
			}
			eltPos := flat[elt]
			set(&eltPos, pos, span)
			flat[elt] = eltPos
		}
	}
	dir(func(e plotElt) (p, p2 eltPath) {
		p, _, p2, _ = e.paths()
		return
	}, func(p *eltPos, pos, span int) {
		p.x, p.xSpan = pos, span
	})
	dir(func(e plotElt) (p, p2 eltPath) {
		_, p, _, p2 = e.paths()
		return
	}, func(p *eltPos, pos, span int) {
		p.y, p.ySpan = pos, span
	})

	// Construct the grid layout.
	l := new(layout.Grid)
	for elt, pos := range flat {
		l.Add(elt, pos.x, pos.y, pos.xSpan, pos.ySpan)
	}
	return l
}
867459
func SVGLoad(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "SVGLoad", Listener: listener}
}
1097432
func (p Polygon) String() string {
	compiled, _ := p.Compile(&postgres.PostGres{}, aspect.Params())
	return compiled
}