X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/1f7d590d9c7b87442c8d8b6424ed4f769d377692..8d952432c8b961e4e0891eb78620615a8ae14f05:/doc/parsing.tex diff --git a/doc/parsing.tex b/doc/parsing.tex index 1c4c3cd..c04ab56 100644 --- a/doc/parsing.tex +++ b/doc/parsing.tex @@ -7,7 +7,7 @@ %%%----- Licensing notice --------------------------------------------------- %%% -%%% This file is part of the Sensble Object Design, an object system for C. +%%% This file is part of the Sensible Object Design, an object system for C. %%% %%% SOD is free software; you can redistribute it and/or modify %%% it under the terms of the GNU General Public License as published by @@ -40,8 +40,105 @@ parser is said to have \emph{failed}, and the result is a list of \emph{indicators}. Finally, the consumed flag is non-nil if the parser consumed any input items. +\begin{describe}{fun}{combine-parser-failures @ @> @} +\end{describe} + +\begin{describe}{fun}{parse-empty \&optional @ @> @} +\end{describe} + +\begin{describe}{fun} + {parse-fail @ \&optional @ @> @} +\end{describe} + %%%-------------------------------------------------------------------------- -\section{File locations} +\section{File locations} \label{sec:parsing.floc} + +\begin{describe}{cls}{file-location} +\end{describe} + +\begin{describe}{fun}{file-location-p @ @> @} +\end{describe} + +\begin{describe}{fun} + {make-file-location @ \&optional @ @ + @> @} +\end{describe} + +\begin{describe*} + {\dhead{fun}{file-location-filename @ @> @} + \dhead{fun}{file-location-line @ @> @} + \dhead{fun}{file-location-column @ @> @}} +\end{describe*} + +\begin{describe}{gf}{file-location @ @> @} + \begin{describe}{meth}{file-location (@ file-location) @> @} + \end{describe} + \begin{describe}{meth}{file-location (@ stream) @> @} + \end{describe} + \begin{describe}{meth}{file-location (@ t) @> @} + \end{describe} +\end{describe} + +\begin{describe}{cls}{condition-with-location (condition) \&key :location} +\end{describe} + +\begin{describe}{meth} + {file-location (@ condition-with-location) @> @} +\end{describe} + +\begin{describe*} + {\quad\=\quad\=\kill + \dhead{cls} + {error-with-location (condition-with-location error) \\ \> + \&key :location} + \dhead{cls} + {warning-with-location (condition-with-location warning) \\ \> + \&key :location} + \dhead{cls} + {enclosing-error-with-location + (enclosing-error-with-location error) \\ \> + \&key :condition :location} + \dhead{cls} + {enclosing-warning-with-location + (enclosing-condition-with-location warning) \\ \> + \&key :condition :location} + \dhead{cls} + {simple-condition-with-location + (condition-with-location simple-condition) \\ \> + \&key :format-control :format-arguments :location} + \dhead{cls} + {simple-error-with-location + (error-with-location simple-error) \\ \> + \&key :format-control :format-arguments :location} + \dhead{cls} + {simple-warning-with-location + (warning-with-location simple-warning) \\ \> + \&key :format-control :format-arguments :location}} +\end{describe*} + +\begin{describe}{fun} + {make-condition-with-location @ @ + @ \&rest @ + \nlret @} +\end{describe} + +\begin{describe*} + {\dhead{fun}{error-with-location @ @ \&rest @} + \dhead{fun}{cerror-with-location @ @ + @ \&rest @} + \dhead{fun}{cerror*-with-location @ @ \&rest @} + \dhead{fun}{warn-with-location @ @ \&rest @}} +\end{describe*} + +\begin{describe}{mac} + {with-default-error-location (@) @^* @
^* + @> @^*} +\end{describe} + +\begin{describe}{mac} + {count-and-report-errors () @^* @^* + @> @ @ @} +\end{describe} %%%-------------------------------------------------------------------------- \section{Scanners} \label{sec:parsing.scanner} @@ -120,7 +217,8 @@ the scanner and read that data again. Therefore it's possible to \end{describe} \begin{describe}{mac} - {with-scanner-place (@ @) @^* @> @^*} + {with-scanner-place (@ @) @^* @^* + @> @^*} Capture the @'s current position as a place, evaluate the @s as an implicit progn with the variable @ bound to the captured place. When control leaves the @s, the place is released. The return @@ -129,9 +227,10 @@ the scanner and read that data again. Therefore it's possible to \subsection{Scanner file-location protocol} \label{sec:parsing.scanner.floc} -Some scanners participate in the file-location protocol (\xref{sec:floc}). -They implement a method on @|file-location| which collects the necessary -information using scanner-specific functions described here. +Some scanners participate in the file-location protocol +(\xref{sec:parsing.floc}). They implement a method on @|file-location| which +collects the necessary information using scanner-specific functions described +here. \begin{describe}{fun}{scanner-file-location @ @> @} Return a @|file-location| object describing the current position of the @@ -147,32 +246,17 @@ information using scanner-specific functions described here. specialized methods on @|file-location|. \end{describe} -\begin{describe}{gf}{scanner-filename @ @> @} - Return the name of the file the scanner is currently processing, as a - string, or nil if the filename is not known. -\end{describe} - -\begin{describe}{meth}{scanner-filename (@ t) @> @} - Returns nil. -\end{describe} - -\begin{describe}{gf}{scanner-line @ @> @} - Return the line number of the @'s current position, as an integer, - or nil if the line number is not known. -\end{describe} +\begin{describe*} + {\dhead{gf}{scanner-filename @ @> @} + \dhead{gf}{scanner-line @ @> @} + \dhead{gf}{scanner-column @ @> @}} + Return the filename, line and column components of the @'s current + position, for use in assembling a @: see the + @|scanner-file-location| function. -\begin{describe}{meth}{scanner-line (@ t) @> @} - Returns nil. -\end{describe} - -\begin{describe}{gf}{scanner-column @ @> @} - Return the column number of the @'s current position, as an - integer, or nil if the column number is not known. -\end{describe} - -\begin{describe}{meth}{scanner-column (@ t) @> @} - Returns nil. -\end{describe} + There are default methods on all three generic functions which simply + return nil. +\end{describe*} \subsection{Character scanners} \label{sec:parsing.scanner.char} @@ -356,11 +440,347 @@ file-location protocols. \end{describe} %%%-------------------------------------------------------------------------- -\section{Parsing macros} +\section{Parsing syntax} -%%%-------------------------------------------------------------------------- +\begin{describe}{gf}{expand-parser-spec @ @ @> @} +\end{describe} + +\begin{describe}{gf} + {expand-parser-form @ @ @ @> @} +\end{describe} + +\begin{describe}{gf}{wrap-parser @ @ @> @} +\end{describe} + +\begin{describe}{mac} + {defparse @ (@[[ :context (@ @) @]] + @^*) \\ \ind + @[[ @^* @! @ @]] \\ + @^* \- + \nlret @} +\end{describe} + +\begin{describe}{mac} + {with-parser-context + (@ @{ @ @ @}^*) \\ \ind + @^* \\ + @^* \- + \nlret @^*} +\end{describe} + +\begin{describe}{lmac} + {parse @ @> @ @ @} +\end{describe} + +\begin{describe}{mac} + {parser @ + @[[ @^* @! @ @]] + @ + @> @} +\end{describe} + +\begin{describe}{gf}{parser-at-eof-p @ @> @} +\end{describe} + +\begin{describe}{gf}{parser-step @ @> @} +\end{describe} + +\begin{describe}{sym}{it} +\end{describe} + +\begin{describe}{mac} + {if-parse (@[[ \=:result @ @! + :expected @ @! \+ \\ + :consumedp @ @]]) \- \\ \ind\ind + @ \- \\ + @ \\ + @[@@] \- + \nlret @^*} +\end{describe} + +\begin{describe}{mac} + {when-parse (@[@@]) @ \\ \ind + @^* \- + \nlret @^*} +\end{describe} + +\begin{describe}{mac} + {cond-parse (@[[ \=:result @ @! + :expected @ @! \+ \\ + :consumedp @ @]]) \- \\ \ind + @{ (@ @^*) @}^* \- + \nlret @^*} +\end{describe} + +\begin{describe}{parse}{:eof} +\end{describe} + +\begin{describe}{parseform}{lisp @^*} +\end{describe} + +\begin{describe}{parseform}{label @} +\end{describe} + +\begin{describe}{parse}{t} +\end{describe} + +\begin{describe}{parseform}{t @} +\end{describe} + +\begin{describe}{parse}{nil} +\end{describe} + +\begin{describe}{parseform}{nil @} +\end{describe} + +\begin{describe}{parseform}{when @ @} +\end{describe} + +\begin{describe}{parseform} + {seq (@{ @ @! (@[@@] @) @}^*) \\ \ind + @^*} +\end{describe} + +\begin{describe}{parseform}{and @^*} +\end{describe} + +\begin{describe}{parseform}{or @^*} +\end{describe} + +\begin{describe}{parseform}{? @ @[@@]} +\end{describe} + +\begin{describe}{parseform} + {many (\=@ @ @ \+ \\ + @[[ \=:new @ @! :final @ @! \+ \\ + :min @ @! :max @ @! \\ + :commitp @ @]]) \-\- \\ \ind + @ @[@@]} +\end{describe} + +\begin{describe}{parseform} + {list (@[[ :min @ @! :max @ @! + :commitp @ @]])\\ \ind + @ @[@@]} +\end{describe} + +\begin{describe}{parseform} + {skip-many (@[[ :min @ @! :max @ @! + :commitp @ @]])\\ \ind + @ @[@@]} +\end{describe} + +\begin{describe}{fun}{call-pluggable-parser @ \&rest @} +\end{describe} + +\begin{describe}{parseform}{plug @ @^*} +\end{describe} + +\begin{describe}{fun} + {pluggable-parser-add @ @ @} +\end{describe} + +\begin{describe}{mac} + {define-pluggable-parser @ @ @ + @[[ @^* @! @ @]] + @^*} +\end{describe} + +\begin{describe}{gf}{parser-capture-place @ @> @} +\end{describe} + +\begin{describe}{gf}{parser-restore-place @ @ @> @} +\end{describe} + +\begin{describe}{gf}{parser-release-place @ @ @> @} +\end{describe} + +\begin{describe}{gf} + {parser-places-must-be-released-p @ @> @>} +\end{describe} + +\begin{describe}{mac} + {with-parser-place (@ @) + @[[ @^* @! @ @]] + @^*} +\end{describe} + +\begin{describe}{parseform}{peek @} +\end{describe} + +\begin{describe}{parseform}{commit} +\end{describe} + +\begin{describe}{cls}{character-parser-context () \&key} +\end{describe} + +\begin{describe}{gf}{parser-current-char @ @> @} +\end{describe} + +\begin{describe}{parseform} + {if-char (@[@@]) @ @ @} +\end{describe} + +\begin{describe}{parseform}{char @} +\end{describe} + +\begin{describe}[char]{parse}{@} +\end{describe} + +\begin{describe}[string]{parse}{@} +\end{describe} + +\begin{describe}{parse}{:any} +\end{describe} + +\begin{describe}{parseform}{satisfies @} +\end{describe} + +\begin{describe}{parseform}{not @} +\end{describe} + +\begin{describe}{parseform}{filter @} +\end{describe} + +\begin{describe}{parse}{:whitespace} +\end{describe} + +\begin{describe}{cls}{token-parser-context () \&key} +\end{describe} + +\begin{describe}{gf}{parser-token-type @ @> @} +\end{describe} + +\begin{describe}{gf}{parser-token-value @ @> @} +\end{describe} + +\begin{describe}{parseform}{token @ @[@@] @[:peekp @@]} +\end{describe} + +\begin{describe}[atom]{parse}{@} +\end{describe} + +\begin{describe}[string]{parse}{@} +\end{describe} + +\begin{describe}{cls}{scanner-context () \&key :scanner} +\end{describe} + +\begin{describe}{gf}{parse-scanner @ @> @} +\end{describe} + +\begin{describe}{cls} + {character-scanner-context (scanner-context character-parser-context) + \&key :scanner} +\end{describe} + +\begin{describe}{cls} + {token-scanner-context (scanner-context token-parser-context) + \&key :scanner} +\end{describe} + +\begin{describe}{gf}{push-operator @ @} +\end{describe} + +\begin{describe}{gf}{push-value @ @} +\end{describe} + +\begin{describe}{gf}{apply-operator @ @} +\end{describe} + +\begin{describe}{gf}{operator-push-action @ @} +\end{describe} + +\begin{describe}{parseform} + {expr \=(@[[ :nestedp @ @]]) \+ \\ + @ @ + @ @} +\end{describe} + +\begin{describe}{gf}{operator-left-precedence @ @> @} +\end{describe} + +\begin{describe}{gf}{operator-right-precedence @ @> @} +\end{describe} + +\begin{describe}{gf}{operator-associativity @ @> @} +\end{describe} + +\begin{describe}{cls}{prefix-operator () \&key} +\end{describe} + +\begin{describe}{cls}{simple-operator () \&key :name :function} +\end{describe} + +\begin{describe}{cls} + {simple-unary-operator (simple-operator) \&key :name :function} +\end{describe} + +\begin{describe*} + {\quad\=\kill + \dhead{cls}{simple-binary-operator (simple-operator) \\ \> + \&key :name :function :lprec :rprec :associativity} + \dhead{cls}{simple-postfix-operator (simple-unary-operator) \\ \> + \&key :name :function :lprec :rprec} + \dhead{cls}{simple-prefix-operator + (prefix-operator simple-unary-operator) \\ \> + \&key :name :function :rprec}} +\end{describe*} + +\begin{describe*} + {\dhead{mac}{preop @ (@ @) + @^* @^* + @> @} + \dhead{mac}{postop @ + (@ @ @[[ :rprec @ @]]) + @^* @^* + \nlret @} + \dhead{mac}{binop @ (@ @ @ @) + @^*@^* + @> @}} +\end{describe*} + +\begin{describe*} + {\dhead{cls}{parenthesis () \&key :tag} + \dhead{cls}{open-parenthesis (parenthesis prefix-operator) \&key :tag} + \dhead{cls}{close-parenthesis (parenthesis) \&key :tag}} +\end{describe*} + +\begin{describe*} + {\dhead{fun}{lparen @ @> @} + \dhead{fun}{rparen @ @> @}} +\end{describe*} + +%%%------------------------------------------------------------------------- \section{Lexical analyser} +\begin{describe}{cls} + {sod-token-scanner (token-scanner) + \&key :filename (:line 1) (:column 0) :char-scanner} +\end{describe} + +\begin{describe}{fun}{define-indicator @ @} +\end{describe} + +\begin{describe}{fun}{syntax-error @ @ \&key :continuep} +\end{describe} + +\begin{describe}{fun} + {lexer-error @ @ @} +\end{describe} + +\begin{describe}{parseform} + {skip-until (@[[ :keep-end @ @]]) @^*} +\end{describe} + +\begin{describe}{parseform}{error () @ @} +\end{describe} + +\begin{describe}{fun} + {scan-comment @ + @> @ @ @} +\end{describe} + %%%----- That's all, folks -------------------------------------------------- %%% Local variables: