pegs/re =~ warns about scope rule change; improved docs

This commit is contained in:
Araq
2013-05-08 15:49:04 +02:00
parent 9fc98cefda
commit 44c4b945eb
4 changed files with 19 additions and 9 deletions

View File

@@ -735,12 +735,10 @@ However, this cannot be done for mutually recursive procedures:
proc even(n: int): bool
proc odd(n: int): bool =
if n == 1: return true
else: return even(n-1)
n == 1 or even(n-1)
proc even(n: int): bool =
if n == 0: return true
else: return odd(n-1)
n == 0 or odd(n-1)
Here ``odd`` depends on ``even`` and vice versa. Thus ``even`` needs to be
introduced to the compiler before it is completely defined. The syntax for
@@ -750,6 +748,9 @@ procedure's body.
Later versions of the language may get rid of the need for forward
declarations.
The example also shows that a proc's body can consist of a single expression
whose value is then returned implicitly.
Iterators
=========
@@ -848,7 +849,7 @@ procedure; the length never counts the terminating zero. Accessing the
terminating zero is no error and often leads to simpler code:
.. code-block:: nimrod
if s[i] == 'a' and s[i+1] == 'b' and s[i+2] == '\0':
if s[i] == 'a' and s[i+1] == 'b':
# no need to check whether ``i < len(s)``!
...
@@ -1168,7 +1169,7 @@ subdivided in height levels accessed through their integer index:
echo len(tower) # --> 10
echo len(tower[1]) # --> 4
echo repr(tower) # --> [[slowBlink, mediumBlink, ...more output..
# The following lines don't compile due to type mistmatch errors
# The following lines don't compile due to type mismatch errors
#tower[north][east] = on
#tower[0][1] = on

View File

@@ -242,6 +242,7 @@ template `=~` *(s: string, pattern: TRegEx): expr =
bind maxSubPatterns
when not definedInScope(matches):
var matches {.inject.}: array[0..maxSubPatterns-1, string]
{.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".}
match(s, pattern, matches)
# ------------------------- more string handling ------------------------------

View File

@@ -870,6 +870,7 @@ template `=~`*(s: string, pattern: TPeg): bool =
bind maxSubpatterns
when not definedInScope(matches):
var matches {.inject.}: array[0..maxSubpatterns-1, string]
{.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".}
match(s, pattern, matches)
# ------------------------- more string handling ------------------------------
@@ -1718,6 +1719,7 @@ when isMainModule:
assert match("_______ana", peg"A <- 'ana' / . A")
assert match("abcs%%%", peg"A <- ..A / .A / '%'")
var matches: array[0..maxSubpatterns-1, string]
if "abc" =~ peg"{'a'}'bc' 'xyz' / {\ident}":
assert matches[0] == "abc"
else:
@@ -1742,8 +1744,6 @@ when isMainModule:
else:
assert false
when not definedInScope(matches):
var matches: array[0..maxSubpatterns-1, string]
if match("abcdefg", peg"c {d} ef {g}", matches, 2):
assert matches[0] == "d"
assert matches[1] == "g"

View File

@@ -30,7 +30,7 @@ Library Additions
- ``system.fields`` and ``system.fieldPairs`` support ``object`` too; they
used to only support tuples.
- Added ``system.CurrentSourcePath`` returning the full file-system path of
the current source file
the current source file.
Changes affecting backwards compatibility
@@ -39,6 +39,12 @@ Changes affecting backwards compatibility
- ``shared`` is a keyword now.
- Deprecated ``sockets.recvLine`` and ``asyncio.recvLine``, added
``readLine`` instead.
- The way indentation is handled in the parser changed significantly. However,
this affects very little (if any) real world code.
- The expression/statement unification has been implemented. Again this
only affects edge cases and no known real world code.
- The scope rules of ``if`` statements will change in 0.9.4. This affects the
``=~`` pegs/re templates.
Compiler Additions
@@ -74,6 +80,8 @@ Language Additions
- Overloading based on ASTs has been implemented.
- Generics are now supported for multi methods.
- Objects can be initialized via an *object constructor expression*.
- There is a new syntactic construct ``(;)`` unifying expressions and
statements.
2012-09-23 Version 0.9.0 released