Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func locFromTokenAST(begin *token, end ast.Node) ast.LocationRange {

// ---------------------------------------------------------------------------

const maxParseDepth = 500

type parser struct {
t Tokens
currT int
t Tokens
currT int
parseDepth int
}

func makeParser(t Tokens) *parser {
Expand Down Expand Up @@ -981,6 +984,14 @@ func (p *parser) parsingFailure(msg string, tok *token) (ast.Node, errors.Static
}

func (p *parser) parse(prec iast.Precedence) (ast.Node, errors.StaticError) {
p.parseDepth++
defer func() { p.parseDepth-- }()
if p.parseDepth > maxParseDepth {
return nil, errors.MakeStaticError(
fmt.Sprintf("Exceeded max parse depth of %d", maxParseDepth),
p.peek().loc)
}

begin := p.peek()

switch begin.kind {
Expand Down