xo-reader: + docs scaffold
This commit is contained in:
parent
0adba354f1
commit
a0b6a85297
8 changed files with 151 additions and 3 deletions
45
docs/example.rst
Normal file
45
docs/example.rst
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
.. _examples:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
See ``xo-reader/examples`` for built examples
|
||||
|
||||
.. code-block:: cpp
|
||||
:linenos:
|
||||
|
||||
#include "xo/reader/reader.h"
|
||||
|
||||
int
|
||||
main() {
|
||||
using namespace xo::scm;
|
||||
using namespace std;
|
||||
|
||||
reader rdr;
|
||||
rdr.begin_translation_unit();
|
||||
|
||||
bool eof = false;
|
||||
while (!eof) {
|
||||
auto input = ins.read_some();
|
||||
|
||||
eof = ins.eof();
|
||||
|
||||
for (auto rem = input; !rem.empty();) {
|
||||
// res: (parsed-expr, used)
|
||||
auto [expr, rem2] = rdr.read_expr(rem, eof);
|
||||
|
||||
if (expr) {
|
||||
cout << expr << endl;
|
||||
}
|
||||
|
||||
rem = rem.suffix_after(rem2);
|
||||
}
|
||||
}
|
||||
|
||||
if (rdr.has_prefix()) {
|
||||
cout << "error: unparsed input after expression" << endl;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue