removed the undocumented #? strongSpaces parsing mode
This commit is contained in:
parent
25cb2e0c70
commit
1fa22d4cfe
4 changed files with 13 additions and 101 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
your previous annotations with `parallel for`.
|
your previous annotations with `parallel for`.
|
||||||
|
|
||||||
- The `unchecked` pragma was removed, instead use `system.UncheckedArray`.
|
- The `unchecked` pragma was removed, instead use `system.UncheckedArray`.
|
||||||
|
- The undocumented ``#? strongSpaces`` parsing mode has been removed.
|
||||||
|
|
||||||
|
|
||||||
#### Breaking changes in the standard library
|
#### Breaking changes in the standard library
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ type
|
||||||
TParser* = object # A TParser object represents a file that
|
TParser* = object # A TParser object represents a file that
|
||||||
# is being parsed
|
# is being parsed
|
||||||
currInd: int # current indentation level
|
currInd: int # current indentation level
|
||||||
firstTok, strongSpaces: bool # Has the first token been read?
|
firstTok: bool # Has the first token been read?
|
||||||
# Is strongSpaces on?
|
|
||||||
hasProgress: bool # some while loop requires progress ensurance
|
hasProgress: bool # some while loop requires progress ensurance
|
||||||
lex*: TLexer # The lexer that is used for parsing
|
lex*: TLexer # The lexer that is used for parsing
|
||||||
tok*: TToken # The current token
|
tok*: TToken # The current token
|
||||||
|
|
@ -102,8 +101,7 @@ proc getTok(p: var TParser) =
|
||||||
emitTok(p.em, p.lex, p.tok)
|
emitTok(p.em, p.lex, p.tok)
|
||||||
|
|
||||||
proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream,
|
proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream,
|
||||||
cache: IdentCache; config: ConfigRef;
|
cache: IdentCache; config: ConfigRef) =
|
||||||
strongSpaces=false) =
|
|
||||||
## Open a parser, using the given arguments to set up its internal state.
|
## Open a parser, using the given arguments to set up its internal state.
|
||||||
##
|
##
|
||||||
initToken(p.tok)
|
initToken(p.tok)
|
||||||
|
|
@ -112,13 +110,11 @@ proc openParser*(p: var TParser, fileIdx: FileIndex, inputStream: PLLStream,
|
||||||
openEmitter(p.em, cache, config, fileIdx)
|
openEmitter(p.em, cache, config, fileIdx)
|
||||||
getTok(p) # read the first token
|
getTok(p) # read the first token
|
||||||
p.firstTok = true
|
p.firstTok = true
|
||||||
p.strongSpaces = strongSpaces
|
|
||||||
p.emptyNode = newNode(nkEmpty)
|
p.emptyNode = newNode(nkEmpty)
|
||||||
|
|
||||||
proc openParser*(p: var TParser, filename: AbsoluteFile, inputStream: PLLStream,
|
proc openParser*(p: var TParser, filename: AbsoluteFile, inputStream: PLLStream,
|
||||||
cache: IdentCache; config: ConfigRef;
|
cache: IdentCache; config: ConfigRef) =
|
||||||
strongSpaces=false) =
|
openParser(p, fileInfoIdx(config, filename), inputStream, cache, config)
|
||||||
openParser(p, fileInfoIdx(config, filename), inputStream, cache, config, strongSpaces)
|
|
||||||
|
|
||||||
proc closeParser(p: var TParser) =
|
proc closeParser(p: var TParser) =
|
||||||
## Close a parser, freeing up its resources.
|
## Close a parser, freeing up its resources.
|
||||||
|
|
@ -798,7 +794,7 @@ proc parseOperators(p: var TParser, headNode: PNode,
|
||||||
limit: int, mode: TPrimaryMode): PNode =
|
limit: int, mode: TPrimaryMode): PNode =
|
||||||
result = headNode
|
result = headNode
|
||||||
# expand while operators have priorities higher than 'limit'
|
# 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
|
let modeB = if mode == pmTypeDef: pmTypeDesc else: mode
|
||||||
# the operator itself must not start on a new line:
|
# the operator itself must not start on a new line:
|
||||||
# progress guaranteed
|
# progress guaranteed
|
||||||
|
|
@ -815,7 +811,7 @@ proc parseOperators(p: var TParser, headNode: PNode,
|
||||||
addSon(a, result)
|
addSon(a, result)
|
||||||
addSon(a, b)
|
addSon(a, b)
|
||||||
result = a
|
result = a
|
||||||
opPrec = getPrecedence(p.tok, p.strongSpaces)
|
opPrec = getPrecedence(p.tok, false)
|
||||||
|
|
||||||
proc simpleExprAux(p: var TParser, limit: int, mode: TPrimaryMode): PNode =
|
proc simpleExprAux(p: var TParser, limit: int, mode: TPrimaryMode): PNode =
|
||||||
result = primary(p, mode)
|
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
|
# XXX for now the builtin 'parseStmt/Expr' functions do not know about strong
|
||||||
# spaces...
|
# spaces...
|
||||||
parser.lex.errorHandler = errorHandler
|
parser.lex.errorHandler = errorHandler
|
||||||
openParser(parser, AbsoluteFile filename, stream, cache, config, false)
|
openParser(parser, AbsoluteFile filename, stream, cache, config)
|
||||||
|
|
||||||
result = parser.parseAll
|
result = parser.parseAll
|
||||||
closeParser(parser)
|
closeParser(parser)
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ type
|
||||||
TFilterKind* = enum
|
TFilterKind* = enum
|
||||||
filtNone, filtTemplate, filtReplace, filtStrip
|
filtNone, filtTemplate, filtReplace, filtStrip
|
||||||
TParserKind* = enum
|
TParserKind* = enum
|
||||||
skinStandard, skinStrongSpaces, skinEndX
|
skinStandard, skinEndX
|
||||||
|
|
||||||
const
|
const
|
||||||
parserNames*: array[TParserKind, string] = ["standard", "strongspaces",
|
parserNames*: array[TParserKind, string] = ["standard",
|
||||||
"endx"]
|
"endx"]
|
||||||
filterNames*: array[TFilterKind, string] = ["none", "stdtmpl", "replace",
|
filterNames*: array[TFilterKind, string] = ["none", "stdtmpl", "replace",
|
||||||
"strip"]
|
"strip"]
|
||||||
|
|
@ -34,14 +34,14 @@ template config(p: TParsers): ConfigRef = p.parser.lex.config
|
||||||
|
|
||||||
proc parseAll*(p: var TParsers): PNode =
|
proc parseAll*(p: var TParsers): PNode =
|
||||||
case p.skin
|
case p.skin
|
||||||
of skinStandard, skinStrongSpaces:
|
of skinStandard:
|
||||||
result = parser.parseAll(p.parser)
|
result = parser.parseAll(p.parser)
|
||||||
of skinEndX:
|
of skinEndX:
|
||||||
internalError(p.config, "parser to implement")
|
internalError(p.config, "parser to implement")
|
||||||
|
|
||||||
proc parseTopLevelStmt*(p: var TParsers): PNode =
|
proc parseTopLevelStmt*(p: var TParsers): PNode =
|
||||||
case p.skin
|
case p.skin
|
||||||
of skinStandard, skinStrongSpaces:
|
of skinStandard:
|
||||||
result = parser.parseTopLevelStmt(p.parser)
|
result = parser.parseTopLevelStmt(p.parser)
|
||||||
of skinEndX:
|
of skinEndX:
|
||||||
internalError(p.config, "parser to implement")
|
internalError(p.config, "parser to implement")
|
||||||
|
|
@ -153,9 +153,7 @@ proc openParsers*(p: var TParsers, fileIdx: FileIndex, inputstream: PLLStream;
|
||||||
else: s = inputstream
|
else: s = inputstream
|
||||||
case p.skin
|
case p.skin
|
||||||
of skinStandard, skinEndX:
|
of skinStandard, skinEndX:
|
||||||
parser.openParser(p.parser, fileIdx, s, cache, config, false)
|
parser.openParser(p.parser, fileIdx, s, cache, config)
|
||||||
of skinStrongSpaces:
|
|
||||||
parser.openParser(p.parser, fileIdx, s, cache, config, true)
|
|
||||||
|
|
||||||
proc closeParsers*(p: var TParsers) =
|
proc closeParsers*(p: var TParsers) =
|
||||||
parser.closeParser(p.parser)
|
parser.closeParser(p.parser)
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue