removed the undocumented #? strongSpaces parsing mode

This commit is contained in:
Araq
2018-11-05 20:06:16 +01:00
committed by Andreas Rumpf
parent 25cb2e0c70
commit 1fa22d4cfe
4 changed files with 13 additions and 101 deletions

View File

@@ -19,6 +19,7 @@
your previous annotations with `parallel for`.
- The `unchecked` pragma was removed, instead use `system.UncheckedArray`.
- The undocumented ``#? strongSpaces`` parsing mode has been removed.
#### Breaking changes in the standard library

View File

@@ -37,8 +37,7 @@ type
TParser* = object # A TParser object represents a file that
# is being parsed
currInd: int # current indentation level
firstTok, strongSpaces: bool # Has the first token been read?
# Is strongSpaces on?
firstTok: bool # Has the first token been read?
hasProgress: bool # some while loop requires progress ensurance
lex*: TLexer # The lexer that is used for parsing
tok*: TToken # The current token
@@ -102,8 +101,7 @@ proc getTok(p: var TParser) =
emitTok(p.em, p.lex, p.tok)
proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream,
cache: IdentCache; config: ConfigRef;
strongSpaces=false) =
cache: IdentCache; config: ConfigRef) =
## Open a parser, using the given arguments to set up its internal state.
##
initToken(p.tok)
@@ -112,13 +110,11 @@ proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream,
openEmitter(p.em, cache, config, fileIdx)
getTok(p) # read the first token
p.firstTok = true
p.strongSpaces = strongSpaces
p.emptyNode = newNode(nkEmpty)
proc openParser*(p: var TParser, filename: AbsoluteFile, inputStream: PLLStream,
cache: IdentCache; config: ConfigRef;
strongSpaces=false) =
openParser(p, fileInfoIdx(config, filename), inputStream, cache, config, strongSpaces)
cache: IdentCache; config: ConfigRef) =
openParser(p, fileInfoIdx(config, filename), inputStream, cache, config)
proc closeParser(p: var TParser) =
## Close a parser, freeing up its resources.
@@ -798,7 +794,7 @@ proc parseOperators(p: var TParser, headNode: PNode,
limit: int, mode: TPrimaryMode): PNode =
result = headNode
# expand while operators have priorities higher than 'limit'
var opPrec = getPrecedence(p.tok, p.strongSpaces)
var opPrec = getPrecedence(p.tok, false)
let modeB = if mode == pmTypeDef: pmTypeDesc else: mode
# the operator itself must not start on a new line:
# progress guaranteed
@@ -815,7 +811,7 @@ proc parseOperators(p: var TParser, headNode: PNode,
addSon(a, result)
addSon(a, b)
result = a
opPrec = getPrecedence(p.tok, p.strongSpaces)
opPrec = getPrecedence(p.tok, false)
proc simpleExprAux(p: var TParser, limit: int, mode: TPrimaryMode): PNode =
result = primary(p, mode)
@@ -2239,7 +2235,7 @@ proc parseString*(s: string; cache: IdentCache; config: ConfigRef;
# XXX for now the builtin 'parseStmt/Expr' functions do not know about strong
# spaces...
parser.lex.errorHandler = errorHandler
openParser(parser, AbsoluteFile filename, stream, cache, config, false)
openParser(parser, AbsoluteFile filename, stream, cache, config)
result = parser.parseAll
closeParser(parser)

View File

@@ -17,10 +17,10 @@ type
TFilterKind* = enum
filtNone, filtTemplate, filtReplace, filtStrip
TParserKind* = enum
skinStandard, skinStrongSpaces, skinEndX
skinStandard, skinEndX
const
parserNames*: array[TParserKind, string] = ["standard", "strongspaces",
parserNames*: array[TParserKind, string] = ["standard",
"endx"]
filterNames*: array[TFilterKind, string] = ["none", "stdtmpl", "replace",
"strip"]
@@ -34,14 +34,14 @@ template config(p: TParsers): ConfigRef = p.parser.lex.config
proc parseAll*(p: var TParsers): PNode =
case p.skin
of skinStandard, skinStrongSpaces:
of skinStandard:
result = parser.parseAll(p.parser)
of skinEndX:
internalError(p.config, "parser to implement")
proc parseTopLevelStmt*(p: var TParsers): PNode =
case p.skin
of skinStandard, skinStrongSpaces:
of skinStandard:
result = parser.parseTopLevelStmt(p.parser)
of skinEndX:
internalError(p.config, "parser to implement")
@@ -153,9 +153,7 @@ proc openParsers*(p: var TParsers, fileIdx: FileIndex, inputstream: PLLStream;
else: s = inputstream
case p.skin
of skinStandard, skinEndX:
parser.openParser(p.parser, fileIdx, s, cache, config, false)
of skinStrongSpaces:
parser.openParser(p.parser, fileIdx, s, cache, config, true)
parser.openParser(p.parser, fileIdx, s, cache, config)
proc closeParsers*(p: var TParsers) =
parser.closeParser(p.parser)

View File

@@ -1,83 +0,0 @@
#? strongSpaces
discard """
output: '''35
true
true
4
true
1
false
77
(Field0: 1, Field1: 2, Field2: 2)
ha
true
tester args
all
all args
19
-3
false
-2
'''
"""
echo 2+5 * 5
# Keyword operators
echo 1 + 16 shl 1 == 1 + (16 shl 1)
echo 2 and 1 in {0, 30}
echo 2+2 * 2 shr 1
echo false or 2 and 1 in {0, 30}
proc `^`(a, b: int): int = a + b div 2
echo 19 mod 16 ^ 4 + 2 and 1
echo 18 mod 16 ^ 4 > 0
# echo $foo gotcha
let foo = 77
echo $foo
echo (1, 2, 2)
template `&`(a, b: int): int = a and b
template `|`(a, b: int): int = a - b
template `++`(a, b: int): bool = a + b == 8009
when true:
let b = 66
let c = 90
let bar = 8000
if foo+4 * 4 == 8 and b&c | 9 ++
bar:
echo "ho"
else:
echo "ha"
let booA = foo+4 * 4 - b&c | 9 +
bar
# is parsed as
let booB = ((foo+4)*4) - ((b&c) | 9) + bar
echo booA == booB
template `|`(a, b): untyped = (if a.len > 0: a else: b)
const
tester = "tester"
args = "args"
echo tester & " " & args|"all"
echo "all" | tester & " " & args
echo "all"|tester & " " & args
# Test arrow like operators. See also tests/macros/tclosuremacro.nim
proc `+->`(a, b: int): int = a + b*4
template `===>`(a, b: int): int = a - b shr 1
echo 3 +-> 2 + 2 and 4
var arrowed = 3+->2 + 2 and 4 # arrowed = 4
echo arrowed ===> 15
echo (2 * 3+->2) == (2*3 +-> 2)
echo arrowed ===> 2 + 3+->2