// BuildParser builds the PEG parser using the provider grammar. The code is
// written to the specified w.
494552
func BuildParser(w io.Writer, g *ast.Grammar, opts ...Option) error {
	b := &builder{w: w, recvName: "c"}
	b.setOptions(opts)
	return b.buildParser(g)
}
783366
func newParser(filename string, b []byte, opts ...Option) *parser {
	p := &parser{
		filename: filename,
		errs:     new(errList),
		data:     b,
		pt:       savepoint{position: position{line: 1}},
		recover:  true,
	}
	p.setOptions(opts)
	return p
}
322446
func (b *Builder) Build() (abbrev, aranges, frame, info, line, pubnames, ranges, str, loc []byte, err error) {
	b.TagClose()

	if len(b.tagStack) > 0 {
		err = fmt.Errorf("unbalanced TagOpen/TagClose %d", len(b.tagStack))
		return
	}

	abbrev = b.makeAbbrevTable()
	info = b.info.Bytes()
	binary.LittleEndian.PutUint32(info, uint32(len(info)-4))
	loc = b.loc.Bytes()

	return
}
1333959
func (p *Parser) Parse(filename string, r io.Reader) (*ast.Grammar, error) {
	p.errs.reset()
	p.s.Init(filename, r, p.errs.add)

	g := p.grammar()
	return g, p.errs.err()
}
1241193
func Parse(pkg *genbase.PackageInfo, typeInfos genbase.TypeInfos) (*BuildSource, error) {
	bu := &BuildSource{
		g:         genbase.NewGenerator(pkg),
		pkg:       pkg,
		typeInfos: typeInfos,
	}

	bu.g.AddImport("google.golang.org/appengine/datastore", "")
	bu.g.AddImport("github.com/favclip/qbg/qbgutils", "")

	for _, typeInfo := range typeInfos {
		err := bu.parseStruct(typeInfo)
		if err != nil {
			return nil, err
		}
	}

	return bu, nil
}
906665
func NewConfigurationParserFromReader(settings io.Reader) *ConfigurationParser {
	is := InstallationSettings{}
	b, _ := ioutil.ReadAll(settings)
	if err := json.Unmarshal(b, &is); err != nil {
		lo.G.Error("Unmarshal installation settings error", err)
	}
	
    is.SetPGDumpUtilVersions()
	return &ConfigurationParser{
		InstallationSettings: is,
	}
}
1010001
func tagOptionParser(doc *p2.Parser, start *p2.Token, arguments *p2.Parser) (p2.INodeTag, *p2.Error) {
	var field string
	typeToken := arguments.MatchType(p2.TokenIdentifier)
	if typeToken != nil {
		field = typeToken.Val
	} else if sToken := arguments.MatchType(p2.TokenString); nil != sToken {
		field = sToken.Val
	} else {
		return nil, arguments.Error("Expected an identifier or string.", nil)
	}

	expr, err := arguments.ParseExpression()
	if err != nil {
		return nil, err
	}

	var v *tagOptionNode
	if sToken := arguments.MatchType(p2.TokenString); nil != sToken {
		v = &tagOptionNode{Pongo2BaseTag: Pongo2BaseTag{field: field},
			value: expr,
			label: sToken.Val}
	} else {
		return nil, arguments.Error("Expected an string.", nil)
	}
	return &INodeImplied{Exec: func(ctx *p2.ExecutionContext, w p2.TemplateWriter) *p2.Error {
		return v.Execute(ctx, w)
	}}, nil
}
801786
func NewParser(renderer blackfriday.Renderer) *parser {
	p := new(parser)
	p.r = renderer

	p.inlineCallback['='] = generateVerbatim
	p.inlineCallback['~'] = generateCode
	p.inlineCallback['/'] = generateEmphasis
	p.inlineCallback['_'] = generateUnderline
	p.inlineCallback['*'] = generateBold
	p.inlineCallback['+'] = generateStrikethrough
	p.inlineCallback['['] = generateLinkOrImg

	return p
}
535550
func BuildXML(params interface{}, e *xml.Encoder) error {
	return buildXML(params, e, false)
}
699784
func GetParser(buf []byte) Parser {
	for _, p := range parsers() {
		b := bytes.NewBuffer(buf)
		if p.Init(b) {
			return p
		}
	}

	return nil
}
1013639
func parse(input string) (*PKGBUILD, error) {
	var pkgbuild *PKGBUILD
	var next item

	lexer := lex(input)
Loop:
	for {
		token := lexer.nextItem()

		// strip arch from source_arch like constructs
		witharch := strings.SplitN(token.val, "_", 2)
		if len(witharch) == 2 {
			found := false
			for _, arch := range pkgbuild.Arch {
				if arch == witharch[1] {
					token.val = witharch[0]
					found = true
					break
				}
			}

			if !found {
				return nil, fmt.Errorf("unsupported arch for variable: %s", token.val)
			}
		}

		switch token.typ {
		case itemPkgbase:
			next = lexer.nextItem()
			pkgbuild = &PKGBUILD{Epoch: 0, Pkgbase: next.val}
		case itemPkgname:
			next = lexer.nextItem()
			pkgbuild.Pkgnames = append(pkgbuild.Pkgnames, next.val)
		case itemPkgver:
			next = lexer.nextItem()
			version, err := parseVersion(next.val)
			if err != nil {
				return nil, err
			}
			pkgbuild.Pkgver = version
		case itemPkgrel:
			next = lexer.nextItem()
			rel, err := parseVersion(next.val)
			if err != nil {
				return nil, err
			}
			pkgbuild.Pkgrel = rel
		case itemPkgdir:
			next = lexer.nextItem()
			pkgbuild.Pkgdir = next.val
		case itemEpoch:
			next = lexer.nextItem()
			epoch, err := strconv.ParseInt(next.val, 10, 0)
			if err != nil {
				return nil, err
			}

			if epoch < 0 {
				return nil, fmt.Errorf("invalid epoch: %d", epoch)
			}
			pkgbuild.Epoch = int(epoch)
		case itemPkgdesc:
			next = lexer.nextItem()
			pkgbuild.Pkgdesc = next.val
		case itemArch:
			next = lexer.nextItem()
			pkgbuild.Arch = append(pkgbuild.Arch, next.val)
		case itemURL:
			next = lexer.nextItem()
			pkgbuild.URL = next.val
		case itemLicense:
			next = lexer.nextItem()
			pkgbuild.License = append(pkgbuild.License, next.val)
		case itemGroups:
			next = lexer.nextItem()
			pkgbuild.Groups = append(pkgbuild.Groups, next.val)
		case itemDepends:
			next = lexer.nextItem()
			deps, err := parseDependency(next.val, pkgbuild.Depends)
			if err != nil {
				return nil, err
			}
			pkgbuild.Depends = deps
		case itemOptdepends:
			next = lexer.nextItem()
			pkgbuild.Optdepends = append(pkgbuild.Optdepends, next.val)
		case itemMakedepends:
			next = lexer.nextItem()
			deps, err := parseDependency(next.val, pkgbuild.Makedepends)
			if err != nil {
				return nil, err
			}
			pkgbuild.Makedepends = deps
		case itemCheckdepends:
			next = lexer.nextItem()
			deps, err := parseDependency(next.val, pkgbuild.Checkdepends)
			if err != nil {
				return nil, err
			}
			pkgbuild.Checkdepends = deps
		case itemProvides:
			next = lexer.nextItem()
			pkgbuild.Provides = append(pkgbuild.Provides, next.val)
		case itemConflicts:
			next = lexer.nextItem()
			pkgbuild.Conflicts = append(pkgbuild.Conflicts, next.val)
		case itemReplaces:
			next = lexer.nextItem()
			pkgbuild.Replaces = append(pkgbuild.Replaces, next.val)
		case itemBackup:
			next = lexer.nextItem()
			pkgbuild.Backup = append(pkgbuild.Backup, next.val)
		case itemOptions:
			next = lexer.nextItem()
			pkgbuild.Options = append(pkgbuild.Options, next.val)
		case itemInstall:
			next = lexer.nextItem()
			pkgbuild.Install = next.val
		case itemChangelog:
			next = lexer.nextItem()
			pkgbuild.Changelog = next.val
		case itemSource:
			next = lexer.nextItem()
			pkgbuild.Source = append(pkgbuild.Source, next.val)
		case itemNoextract:
			next = lexer.nextItem()
			pkgbuild.Noextract = append(pkgbuild.Noextract, next.val)
		case itemMd5sums:
			next = lexer.nextItem()
			pkgbuild.Md5sums = append(pkgbuild.Md5sums, next.val)
		case itemSha1sums:
			next = lexer.nextItem()
			pkgbuild.Sha1sums = append(pkgbuild.Sha1sums, next.val)
		case itemSha224sums:
			next = lexer.nextItem()
			pkgbuild.Sha224sums = append(pkgbuild.Sha224sums, next.val)
		case itemSha256sums:
			next = lexer.nextItem()
			pkgbuild.Sha256sums = append(pkgbuild.Sha256sums, next.val)
		case itemSha384sums:
			next = lexer.nextItem()
			pkgbuild.Sha384sums = append(pkgbuild.Sha384sums, next.val)
		case itemSha512sums:
			next = lexer.nextItem()
			pkgbuild.Sha512sums = append(pkgbuild.Sha512sums, next.val)
		case itemValidpgpkeys:
			next = lexer.nextItem()
			pkgbuild.Validpgpkeys = append(pkgbuild.Validpgpkeys, next.val)
		case itemEndSplit:
		case itemError:
			return nil, fmt.Errorf(token.val)
		case itemEOF:
			break Loop
		default:
			return nil, fmt.Errorf("invalid variable: %s", token.val)
		}
	}
	return pkgbuild, nil
}
1224464
func NewParser() *Parser {
	fp := Parser{
		rp: &rss.Parser{},
		ap: &atom.Parser{},
	}
	return &fp
}
1342397
func Parse(pkg *genbase.PackageInfo, typeInfos genbase.TypeInfos, opts *ParseOptions) (*BuildSource, error) {
	bu := &BuildSource{
		g:         genbase.NewGenerator(pkg),
		pkg:       pkg,
		typeInfos: typeInfos,
	}

	if opts != nil {
		for _, tagName := range opts.TranscriptTagNames {
			if tagName == "json" {
				return nil, ErrInvalidTranscriptTags
			}
		}

		bu.transcriptTagNames = opts.TranscriptTagNames
		bu.noOmitempty = opts.NoOmitempty
		bu.noOmitemptyFieldTypes = opts.NoOmitemptyFieldTypes
	}

	bu.g.AddImport("encoding/json", "")

	for _, typeInfo := range typeInfos {
		err := bu.parseStruct(typeInfo)
		if err != nil {
			return nil, err
		}
	}

	return bu, nil
}
377740
func NewParser(scanner *Scanner, ob ...Observer) (*Parser, error) {
	return NewParserWithStorage(scanner, nil, ob...)
}
345184
func RegisterFlagParser(name string, creator FlagParserCreator) {
	if _, ok := parserCreators[name]; ok {
		panic("RegisterFlagParser has registered: " + name)
	}
	parserCreators[name] = creator
}
1189238
func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*builder.Result, error) {
	defer b.imageSources.Unmount()

	stages, metaArgs, err := instructions.Parse(dockerfile.AST)
	if err != nil {
		if instructions.IsUnknownInstruction(err) {
			buildsFailed.WithValues(metricsUnknownInstructionError).Inc()
		}
		return nil, errdefs.InvalidParameter(err)
	}
	if b.options.Target != "" {
		targetIx, found := instructions.HasStage(stages, b.options.Target)
		if !found {
			buildsFailed.WithValues(metricsBuildTargetNotReachableError).Inc()
			return nil, errdefs.InvalidParameter(errors.Errorf("failed to reach build target %s in Dockerfile", b.options.Target))
		}
		stages = stages[:targetIx+1]
	}

	// Add 'LABEL' command specified by '--label' option to the last stage
	buildLabelOptions(b.options.Labels, stages)

	dockerfile.PrintWarnings(b.Stderr)
	dispatchState, err := b.dispatchDockerfileWithCancellation(stages, metaArgs, dockerfile.EscapeToken, source)
	if err != nil {
		return nil, err
	}
	if dispatchState.imageID == "" {
		buildsFailed.WithValues(metricsDockerfileEmptyError).Inc()
		return nil, errors.New("No image was generated. Is your Dockerfile empty?")
	}
	return &builder.Result{ImageID: dispatchState.imageID, FromImage: dispatchState.baseImage}, nil
}
1211759
func NewParser(options ...func(*Parser)) *Parser {
	p := &Parser{helperBuf: new(bytes.Buffer)}
	for _, opt := range options {
		opt(p)
	}
	return p
}