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:
parent
c7493bbdd0
commit
3812d91390
14 changed files with 187 additions and 78 deletions
|
|
@ -132,17 +132,13 @@ func toCaseInsensitive(headers: HttpHeaders, s: string): string {.inline.} =
|
|||
func newHttpHeaders*(titleCase=false): HttpHeaders =
|
||||
## Returns a new `HttpHeaders` object. if `titleCase` is set to true,
|
||||
## headers are passed to the server in title case (e.g. "Content-Length")
|
||||
new result
|
||||
result.table = newTable[string, seq[string]]()
|
||||
result.isTitleCase = titleCase
|
||||
result = HttpHeaders(table: newTable[string, seq[string]](), isTitleCase: titleCase)
|
||||
|
||||
func newHttpHeaders*(keyValuePairs:
|
||||
openArray[tuple[key: string, val: string]], titleCase=false): HttpHeaders =
|
||||
## Returns a new `HttpHeaders` object from an array. if `titleCase` is set to true,
|
||||
## headers are passed to the server in title case (e.g. "Content-Length")
|
||||
new result
|
||||
result.table = newTable[string, seq[string]]()
|
||||
result.isTitleCase = titleCase
|
||||
result = HttpHeaders(table: newTable[string, seq[string]](), isTitleCase: titleCase)
|
||||
|
||||
for pair in keyValuePairs:
|
||||
let key = result.toCaseInsensitive(pair.key)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -261,10 +261,7 @@ proc newStringTable*(mode: StringTableMode): owned(StringTableRef) {.
|
|||
## See also:
|
||||
## * `newStringTable(keyValuePairs) proc
|
||||
## <#newStringTable,varargs[tuple[string,string]],StringTableMode>`_
|
||||
new(result)
|
||||
result.mode = mode
|
||||
result.counter = 0
|
||||
newSeq(result.data, startSize)
|
||||
result = StringTableRef(mode: mode, counter: 0, data: newSeq[KeyValuePair](startSize))
|
||||
|
||||
proc newStringTable*(keyValuePairs: varargs[string],
|
||||
mode: StringTableMode): owned(StringTableRef) {.
|
||||
|
|
|
|||
|
|
@ -624,7 +624,7 @@ iterator splitLines*(s: string, keepEol = false): string =
|
|||
##
|
||||
## Every `character literal <manual.html#lexical-analysis-character-literals>`_
|
||||
## newline combination (CR, LF, CR-LF) is supported. The result strings
|
||||
## contain no trailing end of line characters unless parameter `keepEol`
|
||||
## contain no trailing end of line characters unless the parameter `keepEol`
|
||||
## is set to `true`.
|
||||
##
|
||||
## Example:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue