Lines Matching refs:p
68 p := &parser{
71 p.mk.filename = filename
72 p.outStmts = &p.mk.stmts
73 return p
76 func (p *parser) srcpos() srcpos {
78 filename: p.mk.filename,
79 lineno: p.lineno,
83 func (p *parser) addStatement(stmt ast) {
84 *p.outStmts = append(*p.outStmts, stmt)
87 p.inRecipe = true
89 p.inRecipe = false
93 func (p *parser) readLine() []byte {
94 if !p.linenoFixed {
95 p.lineno = p.elineno + 1
98 for !p.done {
99 buf, err := p.rd.ReadBytes('\n')
100 if !p.linenoFixed {
101 p.elineno++
104 p.done = true
106 p.err = fmt.Errorf("readline %s: %v", p.srcpos(), err)
107 p.done = true
126 func newAssignAST(p *parser, lhsBytes []byte, rhsBytes []byte, op string) (*assignAST, error) {
136 if p != nil {
137 opt = p.defOpt
147 func (p *parser) handleDirective(line []byte, directives map[string]directiveFunc) bool {
150 d(p, data)
156 func (p *parser) handleRuleOrAssign(line []byte) {
166 if p.handleAssign(line) {
171 p.parseMaybeRule(rline, semi)
175 func (p *parser) handleAssign(line []byte) bool {
185 p.parseAssign(aline, i)
189 p.parseAssign(aline, i+1)
196 func (p *parser) parseAssign(line []byte, sep int) {
204 glog.V(1).Infof("parseAssign %s op:%q opt:%s", line, op, p.defOpt)
207 aast, err := newAssignAST(p, lhs, rhs, string(op))
209 p.err = err
212 aast.srcpos = p.srcpos()
213 p.addStatement(aast)
216 func (p *parser) parseMaybeRule(line, semi []byte) {
218 p.err = p.srcpos().errorf("*** missing rule before commands.")
222 p.err = p.srcpos().errorf("*** commands commence before first target.")
246 p.err = p.srcpos().error(err)
259 p.err = p.srcpos().error(err)
269 assign.srcpos = p.srcpos()
275 p.err = p.srcpos().error(err)
285 rast.srcpos = p.srcpos()
287 p.addStatement(rast)
290 func (p *parser) parseInclude(op string, line []byte) {
296 iast.srcpos = p.srcpos()
297 p.addStatement(iast)
300 func (p *parser) parseIfdef(op string, data []byte) {
303 p.err = p.srcpos().error(err)
310 iast.srcpos = p.srcpos()
311 p.addStatement(iast)
312 p.ifStack = append(p.ifStack, ifState{ast: iast, numNest: p.numIfNest})
313 p.outStmts = &iast.trueStmts
316 func (p *parser) parseTwoQuotes(s []byte) (string, string, []byte, bool) {
340 func (p *parser) parseEq(s []byte) (string, string, []byte, bool) {
368 return p.parseTwoQuotes(s)
371 func (p *parser) parseIfeq(op string, data []byte) {
372 lhsBytes, rhsBytes, extra, ok := p.parseEq(data)
374 p.err = p.srcpos().errorf(`*** invalid syntax in conditional.`)
379 warnNoPrefix(p.srcpos(), `extraneous text after %q directive`, op)
384 p.err = p.srcpos().error(err)
389 p.err = p.srcpos().error(err)
398 iast.srcpos = p.srcpos()
399 p.addStatement(iast)
400 p.ifStack = append(p.ifStack, ifState{ast: iast, numNest: p.numIfNest})
401 p.outStmts = &iast.trueStmts
404 func (p *parser) checkIfStack(curKeyword string) error {
405 if len(p.ifStack) == 0 {
406 return p.srcpos().errorf(`*** extraneous %q.`, curKeyword)
411 func (p *parser) parseElse(data []byte) {
412 err := p.checkIfStack("else")
414 p.err = err
417 state := &p.ifStack[len(p.ifStack)-1]
419 p.err = p.srcpos().errorf(`*** only one "else" per conditional.`)
423 p.outStmts = &state.ast.falseStmts
435 p.numIfNest = state.numNest + 1
436 if p.handleDirective(nextIf, ifDirectives) {
437 p.numIfNest = 0
440 p.numIfNest = 0
441 warnNoPrefix(p.srcpos(), "extraneous text after `else' directive")
445 func (p *parser) parseEndif(data []byte) {
446 err := p.checkIfStack("endif")
448 p.err = err
451 state := p.ifStack[len(p.ifStack)-1]
453 p.ifStack = p.ifStack[0 : len(p.ifStack)-1]
454 if len(p.ifStack) == 0 {
455 p.outStmts = &p.mk.stmts
457 state := p.ifStack[len(p.ifStack)-1]
459 p.outStmts = &state.ast.falseStmts
461 p.outStmts = &state.ast.trueStmts
466 warnNoPrefix(p.srcpos(), "extraneous text after `endif' directive")
471 func (p *parser) parseDefine(data []byte) {
472 p.defineVar = nil
473 p.inDef = nil
474 p.defineVar = append(p.defineVar, trimSpaceBytes(data)...)
478 func (p *parser) parseVpath(data []byte) {
483 p.err = p.srcpos().errorf("parse error %q: %v", string(vline), err)
489 vast.srcpos = p.srcpos()
490 p.addStatement(vast)
516 func includeDirective(p *parser, data []byte) {
517 p.parseInclude("include", data)
520 func sincludeDirective(p *parser, data []byte) {
521 p.parseInclude("-include", data)
524 func ifdefDirective(p *parser, data []byte) {
525 p.parseIfdef("ifdef", data)
528 func ifndefDirective(p *parser, data []byte) {
529 p.parseIfdef("ifndef", data)
532 func ifeqDirective(p *parser, data []byte) {
533 p.parseIfeq("ifeq", data)
536 func ifneqDirective(p *parser, data []byte) {
537 p.parseIfeq("ifneq", data)
540 func elseDirective(p *parser, data []byte) {
541 p.parseElse(data)
544 func endifDirective(p *parser, data []byte) {
545 p.parseEndif(data)
548 func defineDirective(p *parser, data []byte) {
549 p.parseDefine(data)
552 func overrideDirective(p *parser, data []byte) {
553 p.defOpt = "override"
558 if p.handleDirective(data, defineDirective) {
563 if p.handleAssign(data) {
566 p.defOpt = ""
570 p.handleRuleOrAssign(line)
574 func handleExport(p *parser, data []byte, export bool) (hasEqual bool) {
589 east.srcpos = p.srcpos()
591 p.addStatement(east)
595 func exportDirective(p *parser, data []byte) {
596 p.defOpt = "export"
601 if p.handleDirective(data, defineDirective) {
605 if !handleExport(p, data, true) {
611 p.handleAssign(data)
614 func unexportDirective(p *parser, data []byte) {
615 handleExport(p, data, false)
619 func vpathDirective(p *parser, data []byte) {
620 p.parseVpath(data)
623 func (p *parser) parse() (mk makefile, err error) {
624 for !p.done {
625 line := p.readLine()
627 glog.Infof("%s: %q", p.srcpos(), line)
629 if p.defineVar != nil {
630 p.processDefine(line)
631 if p.err != nil {
632 return makefile{}, p.err
636 p.defOpt = ""
637 if p.inRecipe {
640 cast.srcpos = p.srcpos()
641 p.addStatement(cast)
645 p.parseLine(line)
646 if p.err != nil {
647 return makefile{}, p.err
650 return p.mk, p.err
653 func (p *parser) parseLine(line []byte) {
671 if p.handleDirective(dline, makeDirectives) {
677 p.handleRuleOrAssign(line)
680 func (p *parser) processDefine(line []byte) {
689 if !p.isEndef(line) {
690 p.inDef = append(p.inDef, line...)
691 if p.inDef == nil {
692 p.inDef = []byte{}
696 if p.inDef[len(p.inDef)-1] == '\n' {
697 p.inDef = p.inDef[:len(p.inDef)-1]
699 glog.V(1).Infof("multilineAssign %q %q", p.defineVar, p.inDef)
700 aast, err := newAssignAST(p, p.defineVar, p.inDef, "=")
702 p.err = p.srcpos().errorf("assign error %q=%q: %v", p.defineVar, p.inDef, err)
705 aast.srcpos = p.srcpos()
706 aast.srcpos.lineno -= bytes.Count(p.inDef, []byte{'\n'})
707 p.addStatement(aast)
708 p.defineVar = nil
709 p.inDef = nil
713 func (p *parser) isEndef(line []byte) bool {
722 warnNoPrefix(p.srcpos(), `extraneous text after "endef" directive`)