Use readable escape sequences (#17241)

This commit is contained in:
Clyybber 2021-03-03 07:15:07 +01:00 • committed by GitHub
commit 507873be25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 68 deletions

View file

@ -147,11 +147,11 @@ proc llStreamReadLine*(s: PLLStream, line: var string): bool =
of llsString: of llsString:
while s.rd < s.s.len: while s.rd < s.s.len:
case s.s[s.rd] case s.s[s.rd]
of '\x0D': of '\r':
inc(s.rd) inc(s.rd)
if s.s[s.rd] == '\x0A': inc(s.rd) if s.s[s.rd] == '\n': inc(s.rd)
break break
of '\x0A': of '\n':
inc(s.rd) inc(s.rd)
break break
else: else:

View file

@ -103,7 +103,7 @@ proc initGeneralTokenizer*(g: var GeneralTokenizer, buf: cstring) =
g.state = low(TokenClass) g.state = low(TokenClass)
g.lang = low(SourceLanguage) g.lang = low(SourceLanguage)
var pos = 0 # skip initial whitespace: var pos = 0 # skip initial whitespace:
while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) while g.buf[pos] in {' ', '\t'..'\r'}: inc(pos)
g.pos = pos g.pos = pos
proc initGeneralTokenizer*(g: var GeneralTokenizer, buf: string) = proc initGeneralTokenizer*(g: var GeneralTokenizer, buf: string) =
@ -194,7 +194,7 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
g.state = gtNone g.state = gtNone
else: inc(pos) else: inc(pos)
break break
of '\0', '\x0D', '\x0A': of '\0', '\r', '\n':
g.state = gtNone g.state = gtNone
break break
of '\"': of '\"':
@ -204,9 +204,9 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
else: inc(pos) else: inc(pos)
else: else:
case g.buf[pos] case g.buf[pos]
of ' ', '\x09'..'\x0D': of ' ', '\t'..'\r':
g.kind = gtWhitespace g.kind = gtWhitespace
while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) while g.buf[pos] in {' ', '\t'..'\r'}: inc(pos)
of '#': of '#':
g.kind = gtComment g.kind = gtComment
inc(pos) inc(pos)
@ -243,7 +243,7 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
else: else:
inc pos inc pos
else: else:
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
of 'a'..'z', 'A'..'Z', '_', '\x80'..'\xFF': of 'a'..'z', 'A'..'Z', '_', '\x80'..'\xFF':
var id = "" var id = ""
while g.buf[pos] in SymChars + {'_'}: while g.buf[pos] in SymChars + {'_'}:
@ -267,7 +267,7 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
else: else:
g.kind = gtRawData g.kind = gtRawData
inc(pos) inc(pos)
while not (g.buf[pos] in {'\0', '\x0A', '\x0D'}): while not (g.buf[pos] in {'\0', '\n', '\r'}):
if g.buf[pos] == '"' and g.buf[pos+1] != '"': break if g.buf[pos] == '"' and g.buf[pos+1] != '"': break
inc(pos) inc(pos)
if g.buf[pos] == '\"': inc(pos) if g.buf[pos] == '\"': inc(pos)
@ -302,7 +302,7 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
g.kind = gtCharLit g.kind = gtCharLit
while true: while true:
case g.buf[pos] case g.buf[pos]
of '\0', '\x0D', '\x0A': of '\0', '\r', '\n':
break break
of '\'': of '\'':
inc(pos) inc(pos)
@ -330,7 +330,7 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) =
g.kind = gtStringLit g.kind = gtStringLit
while true: while true:
case g.buf[pos] case g.buf[pos]
of '\0', '\x0D', '\x0A': of '\0', '\r', '\n':
break break
of '\"': of '\"':
inc(pos) inc(pos)
@ -436,7 +436,7 @@ proc clikeNextToken(g: var GeneralTokenizer, keywords: openArray[string],
g.state = gtNone g.state = gtNone
else: inc(pos) else: inc(pos)
break break
of '\0', '\x0D', '\x0A': of '\0', '\r', '\n':
g.state = gtNone g.state = gtNone
break break
of '\"': of '\"':
@ -446,14 +446,14 @@ proc clikeNextToken(g: var GeneralTokenizer, keywords: openArray[string],
else: inc(pos) else: inc(pos)
else: else:
case g.buf[pos] case g.buf[pos]
of ' ', '\x09'..'\x0D': of ' ', '\t'..'\r':
g.kind = gtWhitespace g.kind = gtWhitespace
while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) while g.buf[pos] in {' ', '\t'..'\r'}: inc(pos)
of '/': of '/':
inc(pos) inc(pos)
if g.buf[pos] == '/': if g.buf[pos] == '/':
g.kind = gtComment g.kind = gtComment
while not (g.buf[pos] in {'\0', '\x0A', '\x0D'}): inc(pos) while not (g.buf[pos] in {'\0', '\n', '\r'}): inc(pos)
elif g.buf[pos] == '*': elif g.buf[pos] == '*':
g.kind = gtLongComment g.kind = gtLongComment
var nested = 0 var nested = 0
@ -593,9 +593,9 @@ proc javaNextToken(g: var GeneralTokenizer) =
proc yamlPlainStrLit(g: var GeneralTokenizer, pos: var int) = proc yamlPlainStrLit(g: var GeneralTokenizer, pos: var int) =
g.kind = gtStringLit g.kind = gtStringLit
while g.buf[pos] notin {'\0', '\x09'..'\x0D', ',', ']', '}'}: while g.buf[pos] notin {'\0', '\t'..'\r', ',', ']', '}'}:
if g.buf[pos] == ':' and if g.buf[pos] == ':' and
g.buf[pos + 1] in {'\0', '\x09'..'\x0D', ' '}: g.buf[pos + 1] in {'\0', '\t'..'\r', ' '}:
break break
inc(pos) inc(pos)
@ -608,14 +608,14 @@ proc yamlPossibleNumber(g: var GeneralTokenizer, pos: var int) =
while g.buf[pos] in {'0'..'9'}: inc(pos) while g.buf[pos] in {'0'..'9'}: inc(pos)
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
if g.kind == gtNone: if g.kind == gtNone:
if g.buf[pos] in {'\0', '\x09'..'\x0D', ' ', ',', ']', '}'}: if g.buf[pos] in {'\0', '\t'..'\r', ' ', ',', ']', '}'}:
g.kind = gtDecNumber g.kind = gtDecNumber
elif g.buf[pos] == '.': elif g.buf[pos] == '.':
inc(pos) inc(pos)
if g.buf[pos] notin {'0'..'9'}: yamlPlainStrLit(g, pos) if g.buf[pos] notin {'0'..'9'}: yamlPlainStrLit(g, pos)
else: else:
while g.buf[pos] in {'0'..'9'}: inc(pos) while g.buf[pos] in {'0'..'9'}: inc(pos)
if g.buf[pos] in {'\0', '\x09'..'\x0D', ' ', ',', ']', '}'}: if g.buf[pos] in {'\0', '\t'..'\r', ' ', ',', ']', '}'}:
g.kind = gtFloatNumber g.kind = gtFloatNumber
if g.kind == gtNone: if g.kind == gtNone:
if g.buf[pos] in {'e', 'E'}: if g.buf[pos] in {'e', 'E'}:
@ -624,13 +624,13 @@ proc yamlPossibleNumber(g: var GeneralTokenizer, pos: var int) =
if g.buf[pos] notin {'0'..'9'}: yamlPlainStrLit(g, pos) if g.buf[pos] notin {'0'..'9'}: yamlPlainStrLit(g, pos)
else: else:
while g.buf[pos] in {'0'..'9'}: inc(pos) while g.buf[pos] in {'0'..'9'}: inc(pos)
if g.buf[pos] in {'\0', '\x09'..'\x0D', ' ', ',', ']', '}'}: if g.buf[pos] in {'\0', '\t'..'\r', ' ', ',', ']', '}'}:
g.kind = gtFloatNumber g.kind = gtFloatNumber
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
while g.buf[pos] notin {'\0', ',', ']', '}', '\x0A', '\x0D'}: while g.buf[pos] notin {'\0', ',', ']', '}', '\n', '\r'}:
inc(pos) inc(pos)
if g.buf[pos] notin {'\x09'..'\x0D', ' ', ',', ']', '}'}: if g.buf[pos] notin {'\t'..'\r', ' ', ',', ']', '}'}:
yamlPlainStrLit(g, pos) yamlPlainStrLit(g, pos)
break break
# theoretically, we would need to parse indentation (like with block scalars) # theoretically, we would need to parse indentation (like with block scalars)
@ -699,13 +699,13 @@ proc yamlNextToken(g: var GeneralTokenizer) =
while g.buf[pos] in {' ', '\t'}: inc(pos) while g.buf[pos] in {' ', '\t'}: inc(pos)
of '#': of '#':
g.kind = gtComment g.kind = gtComment
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
of '\x0A', '\x0D': discard of '\n', '\r': discard
else: else:
# illegal here. just don't parse a block scalar # illegal here. just don't parse a block scalar
g.kind = gtNone g.kind = gtNone
g.state = gtOther g.state = gtOther
if g.buf[pos] in {'\x0A', '\x0D'} and g.state == gtCommand: if g.buf[pos] in {'\n', '\r'} and g.state == gtCommand:
g.state = gtLongStringLit g.state = gtLongStringLit
elif g.state == gtLongStringLit: elif g.state == gtLongStringLit:
# beware, this is the only token where we actually have to parse # beware, this is the only token where we actually have to parse
@ -714,10 +714,10 @@ proc yamlNextToken(g: var GeneralTokenizer) =
g.kind = gtLongStringLit g.kind = gtLongStringLit
# first, we have to find the parent indentation of the block scalar, so that # first, we have to find the parent indentation of the block scalar, so that
# we know when to stop # we know when to stop
assert g.buf[pos] in {'\x0A', '\x0D'} assert g.buf[pos] in {'\n', '\r'}
var lookbehind = pos - 1 var lookbehind = pos - 1
var headerStart = -1 var headerStart = -1
while lookbehind >= 0 and g.buf[lookbehind] notin {'\x0A', '\x0D'}: while lookbehind >= 0 and g.buf[lookbehind] notin {'\n', '\r'}:
if headerStart == -1 and g.buf[lookbehind] in {'|', '>'}: if headerStart == -1 and g.buf[lookbehind] in {'|', '>'}:
headerStart = lookbehind headerStart = lookbehind
dec(lookbehind) dec(lookbehind)
@ -728,12 +728,12 @@ proc yamlNextToken(g: var GeneralTokenizer) =
# when the header is alone in a line, this line does not show the parent's # when the header is alone in a line, this line does not show the parent's
# indentation, so we must go further. search the first previous line with # indentation, so we must go further. search the first previous line with
# non-whitespace content. # non-whitespace content.
while lookbehind >= 0 and g.buf[lookbehind] in {'\x0A', '\x0D'}: while lookbehind >= 0 and g.buf[lookbehind] in {'\n', '\r'}:
dec(lookbehind) dec(lookbehind)
while lookbehind >= 0 and while lookbehind >= 0 and
g.buf[lookbehind] in {' ', '\t'}: dec(lookbehind) g.buf[lookbehind] in {' ', '\t'}: dec(lookbehind)
# now, find the beginning of the line... # now, find the beginning of the line...
while lookbehind >= 0 and g.buf[lookbehind] notin {'\x0A', '\x0D'}: while lookbehind >= 0 and g.buf[lookbehind] notin {'\n', '\r'}:
dec(lookbehind) dec(lookbehind)
# ... and its indentation # ... and its indentation
indentation = 1 indentation = 1
@ -741,7 +741,7 @@ proc yamlNextToken(g: var GeneralTokenizer) =
if lookbehind == -1: indentation = 0 # top level if lookbehind == -1: indentation = 0 # top level
elif g.buf[lookbehind + 1] == '-' and g.buf[lookbehind + 2] == '-' and elif g.buf[lookbehind + 1] == '-' and g.buf[lookbehind + 2] == '-' and
g.buf[lookbehind + 3] == '-' and g.buf[lookbehind + 3] == '-' and
g.buf[lookbehind + 4] in {'\x09'..'\x0D', ' '}: g.buf[lookbehind + 4] in {'\t'..'\r', ' '}:
# this is a document start, therefore, we are at top level # this is a document start, therefore, we are at top level
indentation = 0 indentation = 0
# because lookbehind was at newline char when calculating indentation, we're # because lookbehind was at newline char when calculating indentation, we're
@ -749,7 +749,7 @@ proc yamlNextToken(g: var GeneralTokenizer) =
let parentIndentation = indentation - 1 let parentIndentation = indentation - 1
# find first content # find first content
while g.buf[pos] in {' ', '\x0A', '\x0D'}: while g.buf[pos] in {' ', '\n', '\r'}:
if g.buf[pos] == ' ': inc(indentation) if g.buf[pos] == ' ': inc(indentation)
else: indentation = 0 else: indentation = 0
inc(pos) inc(pos)
@ -766,12 +766,12 @@ proc yamlNextToken(g: var GeneralTokenizer) =
if (indentation < minIndentation and g.buf[pos] == '#') or if (indentation < minIndentation and g.buf[pos] == '#') or
(indentation == 0 and g.buf[pos] == '.' and g.buf[pos + 1] == '.' and (indentation == 0 and g.buf[pos] == '.' and g.buf[pos + 1] == '.' and
g.buf[pos + 2] == '.' and g.buf[pos + 2] == '.' and
g.buf[pos + 3] in {'\0', '\x09'..'\x0D', ' '}): g.buf[pos + 3] in {'\0', '\t'..'\r', ' '}):
# comment after end of block scalar, or end of document # comment after end of block scalar, or end of document
break break
minIndentation = min(indentation, minIndentation) minIndentation = min(indentation, minIndentation)
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
while g.buf[pos] in {' ', '\x0A', '\x0D'}: while g.buf[pos] in {' ', '\n', '\r'}:
if g.buf[pos] == ' ': inc(indentation) if g.buf[pos] == ' ': inc(indentation)
else: indentation = 0 else: indentation = 0
inc(pos) inc(pos)
@ -780,27 +780,27 @@ proc yamlNextToken(g: var GeneralTokenizer) =
elif g.state == gtOther: elif g.state == gtOther:
# gtOther means 'inside YAML document' # gtOther means 'inside YAML document'
case g.buf[pos] case g.buf[pos]
of ' ', '\x09'..'\x0D': of ' ', '\t'..'\r':
g.kind = gtWhitespace g.kind = gtWhitespace
while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) while g.buf[pos] in {' ', '\t'..'\r'}: inc(pos)
of '#': of '#':
g.kind = gtComment g.kind = gtComment
inc(pos) inc(pos)
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
of '-': of '-':
inc(pos) inc(pos)
if g.buf[pos] in {'\0', ' ', '\x09'..'\x0D'}: if g.buf[pos] in {'\0', ' ', '\t'..'\r'}:
g.kind = gtPunctuation g.kind = gtPunctuation
elif g.buf[pos] == '-' and elif g.buf[pos] == '-' and
(pos == 1 or g.buf[pos - 2] in {'\x0A', '\x0D'}): # start of line (pos == 1 or g.buf[pos - 2] in {'\n', '\r'}): # start of line
inc(pos) inc(pos)
if g.buf[pos] == '-' and g.buf[pos + 1] in {'\0', '\x09'..'\x0D', ' '}: if g.buf[pos] == '-' and g.buf[pos + 1] in {'\0', '\t'..'\r', ' '}:
inc(pos) inc(pos)
g.kind = gtKeyword g.kind = gtKeyword
else: yamlPossibleNumber(g, pos) else: yamlPossibleNumber(g, pos)
else: yamlPossibleNumber(g, pos) else: yamlPossibleNumber(g, pos)
of '.': of '.':
if pos == 0 or g.buf[pos - 1] in {'\x0A', '\x0D'}: if pos == 0 or g.buf[pos - 1] in {'\n', '\r'}:
inc(pos) inc(pos)
for i in 1..2: for i in 1..2:
if g.buf[pos] != '.': break if g.buf[pos] != '.': break
@ -812,12 +812,12 @@ proc yamlNextToken(g: var GeneralTokenizer) =
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
of '?': of '?':
inc(pos) inc(pos)
if g.buf[pos] in {'\0', ' ', '\x09'..'\x0D'}: if g.buf[pos] in {'\0', ' ', '\t'..'\r'}:
g.kind = gtPunctuation g.kind = gtPunctuation
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
of ':': of ':':
inc(pos) inc(pos)
if g.buf[pos] in {'\0', '\x09'..'\x0D', ' ', '\'', '\"'} or if g.buf[pos] in {'\0', '\t'..'\r', ' ', '\'', '\"'} or
(pos > 0 and g.buf[pos - 2] in {'}', ']', '\"', '\''}): (pos > 0 and g.buf[pos - 2] in {'}', ']', '\"', '\''}):
g.kind = gtPunctuation g.kind = gtPunctuation
else: yamlPlainStrLit(g, pos) else: yamlPlainStrLit(g, pos)
@ -836,7 +836,7 @@ proc yamlNextToken(g: var GeneralTokenizer) =
inc(pos) inc(pos)
if g.buf[pos] == '<': if g.buf[pos] == '<':
# literal tag (e.g. `!<tag:yaml.org,2002:str>`) # literal tag (e.g. `!<tag:yaml.org,2002:str>`)
while g.buf[pos] notin {'\0', '>', '\x09'..'\x0D', ' '}: inc(pos) while g.buf[pos] notin {'\0', '>', '\t'..'\r', ' '}: inc(pos)
if g.buf[pos] == '>': inc(pos) if g.buf[pos] == '>': inc(pos)
else: else:
while g.buf[pos] in {'A'..'Z', 'a'..'z', '0'..'9', '-'}: inc(pos) while g.buf[pos] in {'A'..'Z', 'a'..'z', '0'..'9', '-'}: inc(pos)
@ -845,17 +845,17 @@ proc yamlNextToken(g: var GeneralTokenizer) =
# prefixed tag (e.g. `!!str`) # prefixed tag (e.g. `!!str`)
inc(pos) inc(pos)
while g.buf[pos] notin while g.buf[pos] notin
{'\0', '\x09'..'\x0D', ' ', ',', '[', ']', '{', '}'}: inc(pos) {'\0', '\t'..'\r', ' ', ',', '[', ']', '{', '}'}: inc(pos)
of '\0', '\x09'..'\x0D', ' ': discard of '\0', '\t'..'\r', ' ': discard
else: else:
# local tag (e.g. `!nim:system:int`) # local tag (e.g. `!nim:system:int`)
while g.buf[pos] notin {'\0', '\x09'..'\x0D', ' '}: inc(pos) while g.buf[pos] notin {'\0', '\t'..'\r', ' '}: inc(pos)
of '&': of '&':
g.kind = gtLabel g.kind = gtLabel
while g.buf[pos] notin {'\0', '\x09'..'\x0D', ' '}: inc(pos) while g.buf[pos] notin {'\0', '\t'..'\r', ' '}: inc(pos)
of '*': of '*':
g.kind = gtReference g.kind = gtReference
while g.buf[pos] notin {'\0', '\x09'..'\x0D', ' '}: inc(pos) while g.buf[pos] notin {'\0', '\t'..'\r', ' '}: inc(pos)
of '|', '>': of '|', '>':
# this can lead to incorrect tokenization when | or > appear inside flow # this can lead to incorrect tokenization when | or > appear inside flow
# content. checking whether we're inside flow content is not # content. checking whether we're inside flow content is not
@ -871,18 +871,18 @@ proc yamlNextToken(g: var GeneralTokenizer) =
# outside document # outside document
case g.buf[pos] case g.buf[pos]
of '%': of '%':
if pos == 0 or g.buf[pos - 1] in {'\x0A', '\x0D'}: if pos == 0 or g.buf[pos - 1] in {'\n', '\r'}:
g.kind = gtDirective g.kind = gtDirective
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
else: else:
g.state = gtOther g.state = gtOther
yamlPlainStrLit(g, pos) yamlPlainStrLit(g, pos)
of ' ', '\x09'..'\x0D': of ' ', '\t'..'\r':
g.kind = gtWhitespace g.kind = gtWhitespace
while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) while g.buf[pos] in {' ', '\t'..'\r'}: inc(pos)
of '#': of '#':
g.kind = gtComment g.kind = gtComment
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos) while g.buf[pos] notin {'\0', '\n', '\r'}: inc(pos)
of '\0': g.kind = gtEof of '\0': g.kind = gtEof
else: else:
g.kind = gtNone g.kind = gtNone

View file

@ -311,27 +311,27 @@ proc getBracket(L: var Lexer, tok: var Token) =
proc getIndentAux(L: var Lexer, start: int): int = proc getIndentAux(L: var Lexer, start: int): int =
var pos = start var pos = start
# skip the newline (but include it in the token!) # skip the newline (but include it in the token!)
if L.buf[pos] == '\x0D': if L.buf[pos] == '\r':
if L.buf[pos + 1] == '\x0A': inc pos, 2 if L.buf[pos + 1] == '\n': inc pos, 2
else: inc pos else: inc pos
elif L.buf[pos] == '\x0A': elif L.buf[pos] == '\n':
inc pos inc pos
if L.skipPounds: if L.skipPounds:
if L.buf[pos] == '#': inc pos if L.buf[pos] == '#': inc pos
if L.buf[pos] == '#': inc pos if L.buf[pos] == '#': inc pos
while true: while true:
case L.buf[pos] case L.buf[pos]
of ' ', '\x0B', '\x0C': of ' ', '\v', '\f':
inc pos inc pos
inc result inc result
of '\x09': of '\t':
inc pos inc pos
result = result - (result mod 8) + 8 result = result - (result mod 8) + 8
else: else:
break # EndOfFile also leaves the loop break # EndOfFile also leaves the loop
if L.buf[pos] == '\0': if L.buf[pos] == '\0':
result = 0 result = 0
elif L.buf[pos] == '\x0A' or L.buf[pos] == '\x0D': elif L.buf[pos] == '\n' or L.buf[pos] == '\r':
# look at the next line for proper indentation: # look at the next line for proper indentation:
result = getIndentAux(L, pos) result = getIndentAux(L, pos)
L.bufpos = pos # no need to set back buf L.bufpos = pos # no need to set back buf
@ -355,12 +355,12 @@ proc rawGetTok(L: var Lexer, tok: var Token) =
case c case c
of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '0'..'9': of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '0'..'9':
getThing(L, tok, SymChars) getThing(L, tok, SymChars)
of ' ', '\x09', '\x0B', '\x0C': of ' ', '\t', '\v', '\f':
getThing(L, tok, {' ', '\x09'}) getThing(L, tok, {' ', '\t'})
tok.kind = tkWhite tok.kind = tkWhite
if L.buf[L.bufpos] in {'\x0D', '\x0A'}: if L.buf[L.bufpos] in {'\r', '\n'}:
rawGetTok(L, tok) # ignore spaces before \n rawGetTok(L, tok) # ignore spaces before \n
of '\x0D', '\x0A': of '\r', '\n':
getIndent(L, tok) getIndent(L, tok)
L.adornmentLine = false L.adornmentLine = false
of '!', '\"', '#', '$', '%', '&', '\'', '*', '+', ',', '-', '.', of '!', '\"', '#', '$', '%', '&', '\'', '*', '+', ',', '-', '.',
@ -1769,7 +1769,7 @@ proc parseSimpleTable(p: var RstParser): PRstNode =
if currentTok(p).kind == tkIndent: inc p.idx if currentTok(p).kind == tkIndent: inc p.idx
if tokEnd(p) <= cols[0]: break if tokEnd(p) <= cols[0]: break
if currentTok(p).kind in {tkEof, tkAdornment}: break if currentTok(p).kind in {tkEof, tkAdornment}: break
for j in countup(1, high(row)): row[j].add('\x0A') for j in countup(1, high(row)): row[j].add('\n')
a = newRstNode(rnTableRow) a = newRstNode(rnTableRow)
for j in countup(0, high(row)): for j in countup(0, high(row)):
initParser(q, p.s) initParser(q, p.s)

View file

@ -48,8 +48,8 @@ proc getTerminal(): PTerminal {.inline.} =
result = gTerm result = gTerm
const const
fgPrefix = "\x1b[38;2;" fgPrefix = "\e[38;2;"
bgPrefix = "\x1b[48;2;" bgPrefix = "\e[48;2;"
ansiResetCode* = "\e[0m" ansiResetCode* = "\e[0m"
stylePrefix = "\e[" stylePrefix = "\e["

View file

@ -918,7 +918,7 @@ iterator lines*(filename: string): string {.tags: [ReadIOEffect].} =
## proc transformLetters(filename: string) = ## proc transformLetters(filename: string) =
## var buffer = "" ## var buffer = ""
## for line in filename.lines: ## for line in filename.lines:
## buffer.add(line.replace("a", "0") & '\x0A') ## buffer.add(line.replace("a", "0") & '\n')
## writeFile(filename, buffer) ## writeFile(filename, buffer)
var f = open(filename, bufSize=8000) var f = open(filename, bufSize=8000)
try: try: