summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rulesexec.tex34
-rw-r--r--smurf.sty4
2 files changed, 32 insertions, 6 deletions
diff --git a/rulesexec.tex b/rulesexec.tex
index 127fe7e..3c70599 100644
--- a/rulesexec.tex
+++ b/rulesexec.tex
@@ -38,7 +38,7 @@ $$
\begin{cases}
\lambda & \text{als $s=\lambda$}\\
\parsepgm{s'} & \text{als $s=c~s'$ met $c$ whitespace}\\
- \parsestr{s'} & \text{als $s=\texttt{\char`\"}~s'$} \\
+ \parsestr{s'} & \text{als $s=\texttt{"}~s'$} \\
\StmCat:\parsepgm{s'} & \text{als $s=\texttt{+}~s'$} \\
\StmHead:\parsepgm{s'} & \text{als $s=\texttt{h}~s'$} \\
\StmTail:\parsepgm{s'} & \text{als $s=\texttt{t}~s'$} \\
@@ -58,14 +58,38 @@ Dit is in overeenkomst met de specificatie, maar op zich niet nodig.
$$
\parsestr s =
\begin{cases}
- \lambda:\parsepgm{s'} & \text{als $s=\texttt{\char`\"}~s'$} \\
- \texttt{\textbackslash}~k~\parsestr{s'} & \text{als $s=\texttt{\textbackslash}~k~s'$ met
- $k \in\Char$} \\
+ \lambda:\parsepgm{s'} & \text{als $s=\texttt{"}~s'$} \\
+ \unescape{c}~\parsestr{s'} & \text{als $s=\texttt{\textbackslash}~c~s'$
+ met $c \in\Char$} \\
c~\parsestr{s'} & \text{als $s=c~s'$ met $c
- \in\Char\setminus\{\texttt{\char`\",\textbackslash}\}$}\\
+ \in\Char\setminus\{\texttt{"},\texttt{\textbackslash}\}$}\\
\end{cases}
$$
Het tweede geval van $\parsestrop$ zorgt ervoor dat ge-escapete
aanhalingstekens de string niet beƫindigen.
+Hierbij gebruiken we $\unescapeop$ om bepaalde karakters te unescapen:
+
+$$
+ \unescape c =
+ \begin{cases}
+ \text{het LF-karakter} & \text{als $c=\texttt{n}$} \\
+ \texttt{"} & \text{als $c=\texttt{"}$} \\
+ \texttt{\textbackslash} & \text{als $c=\texttt{\textbackslash}$} \\
+ \texttt{\textbackslash~$c$} & \text{anderszins}
+ \end{cases}
+$$
+
+Het laatste alternatief geeft aan dat `ongeldige escape sequences' worden
+behandeld alsof de backslash er twee keer stond. Dit is in overeenstemming met
+het commentaar op de specificatie en met de Perl interpreter: %todo referentie
+\begin{quote}
+ This [the specification] does not specify the behaviour of invalid escape
+ sequences. The Perl interpreter treats invalid escape sequences as if the
+ backslash had occured twice - that is, \textbackslash X is treated as
+ \textbackslash\textbackslash X. For maximum compatibility, Smurf programs
+ should not rely on this behaviour and should always ensure valid escape
+ sequences are used.
+\end{quote}
+
diff --git a/smurf.sty b/smurf.sty
index 7d6b322..0bf2f53 100644
--- a/smurf.sty
+++ b/smurf.sty
@@ -3,11 +3,13 @@
% General
\def\isdef{\stackrel{\text{def}}{=}}
+% Parsing
\def\parsepgmop{\mathit{Parse}}
\def\parsepgm#1{\parsepgmop\left(#1\right)}
-
\def\parsestrop{\mathit{ParseStr}}
\def\parsestr#1{\parsestrop\left(#1\right)}
+\def\unescapeop{\mathit{unescape}}
+\def\unescape#1{\unescapeop\left(#1\right)}
% Types
\def\Pgm{\mathit{Pgm}}