MCPcopy Index your code
hub / github.com/adhocteam/pushup / parseCode

Method parseCode

parser.go:710–763  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

708}
709
710func (p *codeParser) parseCode() node {
711 // starting at the token just past the transSym indicating a transition from HTML
712 // parsing to Go code parsing
713 var e node
714 tok := p.peek().tok
715 lit := p.peek().lit
716 if tok == token.IF {
717 p.advance()
718 e = p.parseIfStmt()
719 } else if tok == token.IDENT && lit == "handler" {
720 p.advance()
721 e = p.parseHandlerKeyword()
722 // NOTE(paulsmith): there is a tricky bit here where an implicit
723 // expression in the form of an identifier token is next and we would
724 // not be able to distinguish it from a keyword. this is also a problem
725 // for name collisions because a user could create a variable named the
726 // same as a keyword and then later try to use it in an implicit
727 // expression, but it would be parsed with the keyword parsing flow
728 // (which probably would lead to an infinite loop because it wouldn't
729 // terminate and the user would be left with an unresponsive Pushup
730 // compiler). a fix could be to have a notion of allowed contexts in
731 // which a keyword block or an implicit expression could be used in the
732 // surrounding markup, and only parse for either depending on which
733 // context is current.
734 } else if tok == token.IDENT && lit == "section" {
735 p.advance()
736 e = p.parseSectionKeyword()
737 } else if tok == token.IDENT && lit == "partial" {
738 p.advance()
739 e = p.parsePartialKeyword()
740 } else if tok == token.LBRACE {
741 e = p.parseCodeBlock()
742 } else if tok == token.IMPORT {
743 p.advance()
744 e = p.parseImportKeyword()
745 } else if tok == token.FOR {
746 p.advance()
747 e = p.parseForStmt()
748 } else if tok == token.LPAREN {
749 p.advance()
750 e = p.parseExplicitExpression()
751 } else if tok == token.IDENT {
752 e = p.parseImplicitExpression()
753 } else if tok == token.INT || tok == token.FLOAT || tok == token.STRING {
754 p.errorf("Go integer, float, and string literals must be grouped by parens")
755 } else if tok == token.EOF {
756 p.errorf("unexpected EOF in code parser")
757 } else if tok == token.NOT || tok == token.REM || tok == token.AND || tok == token.CHAR {
758 p.errorf("invalid '%s' Go token while parsing code", tok.String())
759 } else {
760 p.errorf("expected Pushup keyword or expression, got %q", tok.String())
761 }
762 return e
763}
764
765func (p *codeParser) parseIfStmt() *nodeIf {
766 var stmt nodeIf

Callers 2

parseStmtBlockMethod · 0.95
transitionMethod · 0.80

Calls 13

peekMethod · 0.95
advanceMethod · 0.95
parseIfStmtMethod · 0.95
parseHandlerKeywordMethod · 0.95
parseSectionKeywordMethod · 0.95
parsePartialKeywordMethod · 0.95
parseCodeBlockMethod · 0.95
parseImportKeywordMethod · 0.95
parseForStmtMethod · 0.95
errorfMethod · 0.95

Tested by

no test coverage detected