allow multi-line expressions using the dot operator

this enables parsing of expressions like:

``` Nimrod
s.items
  .map(proc (x): auto = x * 2)
  .filter do (x) -> auto:
    return x % 2 == 0
  .group_by((x) => x.length)
```
This commit is contained in:
Zahary Karadjov 2014-03-15 10:50:14 +02:00
commit 7080d02af4
2 changed files with 17 additions and 8 deletions

View file

@ -101,6 +101,7 @@ type
base10, # base10 is listed as the first element,
# so that it is the correct default value
base2, base8, base16
TToken* = object # a Nimrod token
tokType*: TTokType # the type of the token
indent*: int # the indentation; != -1 if the token has been
@ -121,8 +122,9 @@ type
indentAhead*: int # if > 0 an indendation has already been read
# this is needed because scanning comments
# needs so much look-ahead
currLineIndent*: int
strongSpaces*: bool
var gLinesCompiled*: int # all lines that have been compiled
@ -206,6 +208,7 @@ proc openLexer(lex: var TLexer, fileIdx: int32, inputstream: PLLStream) =
openBaseLexer(lex, inputstream)
lex.fileIdx = fileidx
lex.indentAhead = - 1
lex.currLineIndent = 0
inc(lex.lineNumber, inputstream.lineOffset)
proc closeLexer(lex: var TLexer) =
@ -709,6 +712,7 @@ proc skip(L: var TLexer, tok: var TToken) =
tok.strongSpaceA = 0
if buf[pos] > ' ':
tok.indent = indent
L.currLineIndent = indent
break
else:
break # EndOfFile also leaves the loop
@ -718,6 +722,7 @@ proc rawGetTok(L: var TLexer, tok: var TToken) =
fillToken(tok)
if L.indentAhead >= 0:
tok.indent = L.indentAhead
L.currLineIndent = L.indentAhead
L.indentAhead = -1
else:
tok.indent = -1
@ -827,5 +832,5 @@ proc rawGetTok(L: var TLexer, tok: var TToken) =
tok.tokType = tkInvalid
lexMessage(L, errInvalidToken, c & " (\\" & $(ord(c)) & ')')
inc(L.bufpos)
dummyIdent = getIdent("")