This commit is contained in:
Araq 2015-09-10 08:53:58 +02:00
commit d7a472743b
6 changed files with 26 additions and 18 deletions

View file

@ -92,10 +92,15 @@ proc parsePipe(filename: string, inputStream: PLLStream): PNode =
var line = newStringOfCap(80) var line = newStringOfCap(80)
discard llStreamReadLine(s, line) discard llStreamReadLine(s, line)
var i = utf8Bom(line) var i = utf8Bom(line)
var linenumber = 1
if containsShebang(line, i): if containsShebang(line, i):
discard llStreamReadLine(s, line) discard llStreamReadLine(s, line)
i = 0 i = 0
if line[i] == '#' and line[i+1] == '!': inc linenumber
if line[i] == '#' and line[i+1] in {'?', '!'}:
if line[i+1] == '!':
message(newLineInfo(filename, linenumber, 1),
warnDeprecated, "use '#?' instead; '#!'")
inc(i, 2) inc(i, 2)
while line[i] in Whitespace: inc(i) while line[i] in Whitespace: inc(i)
var q: TParser var q: TParser

View file

@ -4,12 +4,12 @@ Short description of Nim's modules
============== ========================================================== ============== ==========================================================
Module Description Module Description
============== ========================================================== ============== ==========================================================
nim main module: parses the command line and calls nim main module: parses the command line and calls
``main.MainCommand`` ``main.MainCommand``
main implements the top-level command dispatching main implements the top-level command dispatching
nimconf implements the config file reader nimconf implements the config file reader
syntaxes dispatcher for the different parsers and filters syntaxes dispatcher for the different parsers and filters
filter_tmpl standard template filter (``#! stdtempl``) filter_tmpl standard template filter (``#? stdtempl``)
lexbase buffer handling of the lexical analyser lexbase buffer handling of the lexical analyser
lexer lexical analyser lexer lexical analyser
parser Nim's parser parser Nim's parser

View file

@ -8,9 +8,9 @@ A `Source Code Filter` transforms the input character stream to an in-memory
output stream before parsing. A filter can be used to provide templating output stream before parsing. A filter can be used to provide templating
systems or preprocessors. systems or preprocessors.
To use a filter for a source file the *shebang* notation is used:: To use a filter for a source file the ``#?`` notation is used::
#! stdtmpl(subsChar = '$', metaChar = '#') #? stdtmpl(subsChar = '$', metaChar = '#')
#proc generateXML(name, age: string): string = #proc generateXML(name, age: string): string =
# result = "" # result = ""
<xml> <xml>
@ -20,7 +20,8 @@ To use a filter for a source file the *shebang* notation is used::
As the example shows, passing arguments to a filter can be done As the example shows, passing arguments to a filter can be done
just like an ordinary procedure call with named or positional arguments. The just like an ordinary procedure call with named or positional arguments. The
available parameters depend on the invoked filter. available parameters depend on the invoked filter. Before version 0.12.0 of
the language ``#!`` was used instead of ``#?``.
Pipe operator Pipe operator
@ -28,7 +29,7 @@ Pipe operator
Filters can be combined with the ``|`` pipe operator:: Filters can be combined with the ``|`` pipe operator::
#! strip(startswith="<") | stdtmpl #? strip(startswith="<") | stdtmpl
#proc generateXML(name, age: string): string = #proc generateXML(name, age: string): string =
# result = "" # result = ""
<xml> <xml>
@ -104,7 +105,7 @@ Parameters and their defaults:
Example:: Example::
#! stdtmpl | standard #? stdtmpl | standard
#proc generateHTMLPage(title, currentTab, content: string, #proc generateHTMLPage(title, currentTab, content: string,
# tabs: openArray[string]): string = # tabs: openArray[string]): string =
# result = "" # result = ""
@ -172,7 +173,7 @@ produces ``$``.
The template engine is quite flexible. It is easy to produce a procedure that The template engine is quite flexible. It is easy to produce a procedure that
writes the template code directly to a file:: writes the template code directly to a file::
#! stdtmpl(emit="f.write") | standard #? stdtmpl(emit="f.write") | standard
#proc writeHTMLPage(f: File, title, currentTab, content: string, #proc writeHTMLPage(f: File, title, currentTab, content: string,
# tabs: openArray[string]) = # tabs: openArray[string]) =
<head><title>$title</title></head> <head><title>$title</title></head>

View file

@ -68,13 +68,13 @@ Strong spaces
------------- -------------
The number of spaces preceding a non-keyword operator affects precedence The number of spaces preceding a non-keyword operator affects precedence
if the experimental parser directive ``#!strongSpaces`` is used. Indentation if the experimental parser directive ``#?strongSpaces`` is used. Indentation
is not used to determine the number of spaces. If 2 or more operators have the is not used to determine the number of spaces. If 2 or more operators have the
same number of preceding spaces the precedence table applies, so ``1 + 3 * 4`` same number of preceding spaces the precedence table applies, so ``1 + 3 * 4``
is still parsed as ``1 + (3 * 4)``, but ``1+3 * 4`` is parsed as ``(1+3) * 4``: is still parsed as ``1 + (3 * 4)``, but ``1+3 * 4`` is parsed as ``(1+3) * 4``:
.. code-block:: nim .. code-block:: nim
#! strongSpaces #? strongSpaces
if foo+4 * 4 == 8 and b&c | 9 ++ if foo+4 * 4 == 8 and b&c | 9 ++
bar: bar:
echo "" echo ""
@ -86,7 +86,7 @@ Furthermore whether an operator is used a prefix operator is affected by the
number of spaces: number of spaces:
.. code-block:: nim .. code-block:: nim
#! strongSpaces #? strongSpaces
echo $foo echo $foo
# is parsed as # is parsed as
echo($foo) echo($foo)
@ -95,7 +95,7 @@ This also affects whether ``[]``, ``{}``, ``()`` are parsed as constructors
or as accessors: or as accessors:
.. code-block:: nim .. code-block:: nim
#! strongSpaces #? strongSpaces
echo (1,2) echo (1,2)
# is parsed as # is parsed as
echo((1,2)) echo((1,2))

View file

@ -1,5 +1,5 @@
#! stdtmpl | standard #? stdtmpl | standard
#proc generateHTMLPage(c: var TConfigData, currentTab, content, rss: string): string = #proc generateHTMLPage(c: var TConfigData, currentTab, content, rss: string): string =
# result = "" # result = ""
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -23,7 +23,7 @@
# if t != "index" and t != "community" and t != "news": # if t != "index" and t != "community" and t != "news":
# let name = c.tabs[i].key # let name = c.tabs[i].key
# if currentTab == t: # if currentTab == t:
<a class="active" <a class="active"
# else: # else:
<a <a
# end if # end if
@ -104,7 +104,7 @@ p.greet() <span class="cmt"># or greet(p)</span>
<span class="cmt"># declare a C procedure..</span> <span class="cmt"># declare a C procedure..</span>
<span class="kwd">proc</span> <span class="def">unsafeScanf</span>(f: <span class="typ">File</span>, s: <span class="typ">cstring</span>) <span class="kwd">proc</span> <span class="def">unsafeScanf</span>(f: <span class="typ">File</span>, s: <span class="typ">cstring</span>)
<span class="tab"> </span>{.varargs, <span class="tab"> </span>{.varargs,
<span class="tab"> </span>importc: <span class="val">"fscanf"</span>, <span class="tab"> </span>importc: <span class="val">"fscanf"</span>,
<span class="tab end"> </span>header: <span class="val">"&lt;stdio.h&gt;"</span>.} <span class="tab end"> </span>header: <span class="val">"&lt;stdio.h&gt;"</span>.}
<span class="cmt"># ..and use it...</span> <span class="cmt"># ..and use it...</span>
@ -191,7 +191,7 @@ runForever()
</div> </div>
</div> </div>
</footer> </footer>
# if currentTab == "index": # if currentTab == "index":
<script src="assets/index.js"></script> <script src="assets/index.js"></script>
# end if # end if

View file

@ -71,6 +71,8 @@ News
are likely to break as well. are likely to break as well.
- Base methods now need to be annotated with the ``base`` pragma. This makes - Base methods now need to be annotated with the ``base`` pragma. This makes
multi methods less error-prone to use with the effect system. multi methods less error-prone to use with the effect system.
- Nim's parser directive ``#!`` is now ``#?`` in order to produce no conflicts
with Unix's ``#!``.
Library Additions Library Additions