Skip to content

Commit

Permalink
Align duplicated parts of lexing rules
Browse files Browse the repository at this point in the history
This isn't the first time we have issues with these being out of sync.  Hopefully, maintenance will become easier now with the duplicated part being a substring of the full lexing rules.
  • Loading branch information
henrikt-ma committed Jan 26, 2021
1 parent 41833ac commit 46c5526
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions chapters/lexicalstructure.tex
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ \subsection{Identifiers}\label{identifiers}
The redundant escapes (\lstinline!'\?'! and \lstinline!'\"'!) are the same as the corresponding non-escaped variants (\lstinline!'?'! and \lstinline!'"'!), but are only for use in Modelica source code.
A full BNF definition of the Modelica syntax and lexical units is available in \cref{modelica-concrete-syntax}.

% For easy maintenance, the lexing rules below should be a substring of the full lexing rules in \cref{lexical-conventions}.
\begin{lstlisting}[language=grammar]
IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT
IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT
Q-IDENT = "'" { Q-CHAR | S-ESCAPE } "'"
NONDIGIT = "_" | letters "a" $\ldots$ "z" | letters "A" $\ldots$ "Z"
DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$\mbox{\textdollar}$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "=" | "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " " | """
S-ESCAPE = "\'" | "\"" | "\?" | "\\" | "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$\mbox{\textdollar}$" | "%" | "&" | "(" | ")"
| "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "="
| "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " " | """
S-ESCAPE = "\'" | "\"" | "\?" | "\\"
| "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
\end{lstlisting}

\subsection{Names}\label{names}
Expand Down
7 changes: 4 additions & 3 deletions chapters/syntax.tex
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ \section{Lexical conventions}\label{lexical-conventions}
The following lexical units are defined (the ones in boldface are the
ones used in the grammar, the rest are just internal to the definition
of other lexical units):
% Beware that the first lines of the lexing rules below are duplicated in \cref{identifiers}, and must be kept in sync.
\begin{lstlisting}[language=grammar]
IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT
Q-IDENT = "'" { Q-CHAR | S-ESCAPE } "'"
NONDIGIT = "_" | letters "a" $\ldots$ "z" | letters "A" $\ldots$ "Z"
STRING = """ { S-CHAR | S-ESCAPE } """
S-CHAR = see below
DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$\mbox{\textdollar}$" | "%" | "&" | "(" | ")"
| "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "="
| "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " " | """
S-ESCAPE = "\'" | "\"" | "\?" | "\\"
| "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
STRING = """ { S-CHAR | S-ESCAPE } """
S-CHAR = see below
UNSIGNED-INTEGER = DIGIT { DIGIT }
UNSIGNED-REAL =
UNSIGNED-INTEGER "." [ UNSIGNED-INTEGER ]
Expand Down

0 comments on commit 46c5526

Please sign in to comment.