alternative, much simpler algorithm for strict func checking (#21066)

* alternative, much simpler algorithm for strict func checking

* forgot to git add new compiler module

* new spec is incredibly simple to describe

* fixes bigints regression

* typos

* closes #16305; closes #17387; closes #20863
This commit is contained in:
Andreas Rumpf 2022-12-11 16:58:50 +01:00 • committed by GitHub
commit 3812d91390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 187 additions and 78 deletions

View file

@ -168,8 +168,9 @@ func charSet*(s: set[char]): Peg {.rtl, extern: "npegs$1".} =
## constructs a PEG from a character set `s`
assert '\0' notin s
result = Peg(kind: pkCharChoice)
new(result.charChoice)
result.charChoice[] = s
{.cast(noSideEffect).}:
new(result.charChoice)
result.charChoice[] = s
func len(a: Peg): int {.inline.} = return a.sons.len
func add(d: var Peg, s: Peg) {.inline.} = add(d.sons, s)
@ -1823,9 +1824,7 @@ type
skip: Peg
func pegError(p: PegParser, msg: string, line = -1, col = -1) =
var e: ref EInvalidPeg
new(e)
e.msg = errorStr(p, msg, line, col)
var e = (ref EInvalidPeg)(msg: errorStr(p, msg, line, col))
raise e
func getTok(p: var PegParser) =
@ -1909,7 +1908,8 @@ func primary(p: var PegParser): Peg =
getTok(p)
elif not arrowIsNextTok(p):
var nt = getNonTerminal(p, p.tok.literal)
incl(nt.flags, ntUsed)
{.cast(noSideEffect).}:
incl(nt.flags, ntUsed)
result = nonterminal(nt).token(p)
getTok(p)
else:
@ -2002,12 +2002,14 @@ func parseRule(p: var PegParser): NonTerminal =
result = getNonTerminal(p, p.tok.literal)
if ntDeclared in result.flags:
pegError(p, "attempt to redefine: " & result.name)
result.line = getLine(p)
result.col = getColumn(p)
{.cast(noSideEffect).}:
result.line = getLine(p)
result.col = getColumn(p)
getTok(p)
eat(p, tkArrow)
result.rule = parseExpr(p)
incl(result.flags, ntDeclared) # NOW inlining may be attempted
{.cast(noSideEffect).}:
result.rule = parseExpr(p)
incl(result.flags, ntDeclared) # NOW inlining may be attempted
else:
pegError(p, "rule expected, but found: " & p.tok.literal)