Skip to content

Commit

Permalink
Docs: move a few manual sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
skvadrik committed Oct 12, 2024
1 parent 669426e commit 28989c2
Show file tree
Hide file tree
Showing 20 changed files with 11,255 additions and 11,148 deletions.
8 changes: 5 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ re2c_SRC_DOC_EXT = \
doc/manual/api/api3.rst_ \
doc/manual/conditions/blocks.rst_ \
doc/manual/conditions/conditions.rst_ \
doc/manual/configurations/configurations.rst_ \
doc/manual/dot/dot.rst_ \
doc/manual/encodings/encodings.rst_ \
doc/manual/eof/01_sentinel.rst_ \
Expand All @@ -244,10 +243,10 @@ re2c_SRC_DOC_EXT = \
doc/manual/fill/fill.rst_ \
doc/manual/headers/headers.rst_ \
doc/manual/includes/includes.rst_ \
doc/manual/intro.rst_ \
doc/manual/options/debug.rst_ \
doc/manual/options/internal.rst_ \
doc/manual/options/options.rst_ \
doc/manual/regexps/regular_expressions.rst_ \
doc/manual/reuse/reuse.rst_ \
doc/manual/skeleton/skeleton.rst_ \
doc/manual/state/state.rst_ \
Expand All @@ -257,7 +256,10 @@ re2c_SRC_DOC_EXT = \
doc/manual/submatch/submatch_example_stags.rst_ \
doc/manual/submatch/submatch.rst_ \
doc/manual/synopsis.rst_ \
doc/manual/syntax/intro.rst_ \
doc/manual/syntax/blocks.rst_ \
doc/manual/syntax/directives.rst_ \
doc/manual/syntax/configurations.rst_ \
doc/manual/syntax/regular_expressions.rst_ \
doc/manual/syntax/syntax.rst_ \
doc/manual/warnings/warnings_general.rst_ \
doc/manual/warnings/warnings_list.rst_ \
Expand Down
2,123 changes: 1,066 additions & 1,057 deletions bootstrap/doc/re2c.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2d.1

Large diffs are not rendered by default.

2,117 changes: 1,063 additions & 1,054 deletions bootstrap/doc/re2go.1

Large diffs are not rendered by default.

1,975 changes: 992 additions & 983 deletions bootstrap/doc/re2hs.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2java.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2js.1

Large diffs are not rendered by default.

1,959 changes: 984 additions & 975 deletions bootstrap/doc/re2ocaml.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2py.1

Large diffs are not rendered by default.

2,037 changes: 1,023 additions & 1,014 deletions bootstrap/doc/re2rust.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2v.1

Large diffs are not rendered by default.

1,981 changes: 995 additions & 986 deletions bootstrap/doc/re2zig.1

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions doc/manpage.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ generate fast lexical analyzers for RE2C_LANG_NAME
:Manual section: 1

.. |re2c| replace:: RE2C_PROG
.. |lang_name| replace:: RE2C_LANG_NAME

SYNOPSIS
========
Expand All @@ -20,7 +21,7 @@ RE2C_DISCLAIMER
Introduction
============

.. include:: @top_srcdir@/doc/manual/syntax/intro.rst_
.. include:: @top_srcdir@/doc/manual/intro.rst_

Here is an example of a small program that checks if a given string contains a
decimal number:
Expand All @@ -40,6 +41,10 @@ Syntax
======

.. include:: @top_srcdir@/doc/manual/syntax/syntax.rst_
.. include:: @top_srcdir@/doc/manual/syntax/blocks.rst_
.. include:: @top_srcdir@/doc/manual/syntax/directives.rst_
.. include:: @top_srcdir@/doc/manual/syntax/regular_expressions.rst_
.. include:: @top_srcdir@/doc/manual/syntax/configurations.rst_

Program interface
=================
Expand Down Expand Up @@ -68,14 +73,6 @@ Warnings can be invividually enabled, disabled and turned into an error.
.. include:: @top_srcdir@/doc/manual/warnings/warnings_general.rst_
.. include:: @top_srcdir@/doc/manual/warnings/warnings_list.rst_

Configurations
==============
.. include:: @top_srcdir@/doc/manual/configurations/configurations.rst_

Regular expressions
===================
.. include:: @top_srcdir@/doc/manual/regexps/regular_expressions.rst_

Handling the end of input
=========================
.. include:: @top_srcdir@/doc/manual/eof/eof.rst_
Expand Down
6 changes: 6 additions & 0 deletions doc/manual/intro.rst_
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
|re2c| works as a preprocessor. It reads the input file (which is usually a
|lang_name| program, but can be anything) and looks for blocks of code enclosed
in special-form comments. The text outside of these blocks is copied verbatim
into the output file. The contents of the blocks are processed by |re2c|. It
translates them to code in the target language and outputs the generated code in
place of the block.
117 changes: 117 additions & 0 deletions doc/manual/syntax/blocks.rst_
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Blocks
------

Block start and end markers are either ``/*!re2c`` and ``*/`` (suitable for
languages that have C-style multiline comments), or ``%{`` and ``%}`` (suitable
for other languages). Blocks may have optional names that allow them to be
referenced in other parts of the program (named blocks were added in version
2.2). There are different kinds of blocks:

``/*!re2c[:<name>] ... */`` or ``%{[:<name>] ... %}``
A *global block* contains definitions, configurations, directives and rules.
|re2c| compiles regular expressions associated with each rule into a
deterministic finite automaton, encodes it in the form of conditional jumps
in the target language and replaces the block with the generated code. Names
and configurations defined in a global block are added to the global scope
and become visible to subsequent blocks. At the start of the program the
global scope is initialized with command-line `options`_.

``/*!local:re2c[:<name>] ... */`` or ``%{local[:<name>] ... %}``
A *local block* is like a global block, but the names and configurations in
it have local scope (they do not affect other blocks).

``/*!rules:re2c[:<name>] ... */`` or ``%{rules[:<name>] ... %}``
A *rules block* is like a local block, but it does not generate any code by
itself, nor does it add any definitions to the global scope -- it is meant
to be reused in other blocks. This is a way of sharing code (more details in
the `reusable blocks`_ section). Prior to |re2c| version 2.2 rules blocks
required ``-r --reusable`` option.

``/*!use:re2c[:<name>] ... */`` or ``%{use[:<name>] ... %}``
A use block that references a previously defined rules block. If the name is
specified, |re2c| looks for a rules blocks with this name. Otherwise the most
recent rules block is used (either a named or an unnamed one). A use block
can add definitions, configurations and rules of its own, which are added to
those of the referenced rules block. Prior to |re2c| version 2.2 use blocks
required ``-r --reusable`` option.

``/*!max:re2c[:<name1>[:<name2>...]] ... */`` or ``%{max[:<name1>[:<name2>...]] ... %}``
A directive that generates ``YYMAXFILL`` definition.
An optional list of block names specifies which blocks should be included
when computing ``YYMAXFILL`` value (if the list is empty, all blocks are
included).
By default the generated code is a macro-definition for C
(``#define YYMAXFILL <n>``), or a global variable for Go
(``var YYMAXFILL int = <n>``). It can be customized with an optional
configuration ``format`` that specifies a template string where ``@@{max}``
(or ``@@`` for short) is replaced with the numeric value of ``YYMAXFILL``.

``/*!maxnmatch:re2c[:<name1>[:<name2>...]] ... */`` or ``%{maxnmatch[:<name1>[:<name2>...]] ... %}``
A directive that generates ``YYMAXNMATCH`` definition (it requires
``-P --posix-captures`` option).
An optional list of block names specifies which blocks should be included
when computing ``YYMAXNMATCH`` value (if the list is empty, all blocks are
included).
By default the generated code is a macro-definition for C
(``#define YYMAXNMATCH <n>``), or a global variable for Go
(``var YYMAXNMATCH int = <n>``). It can be customized with an optional
configuration ``format`` that specifies a template string where ``@@{max}``
(or ``@@`` for short) is replaced with the numeric value of ``YYMAXNMATCH``.

``/*!stags:re2c[:<name1>[:<name2>...]] ... */``, ``/*!mtags:re2c[:<name1>[:<name2>...]] ... */`` or ``%{stags[:<name1>[:<name2>...]] ... %}``, ``%{mtags[:<name1>[:<name2>...]] ... %{``
Directives that specify a template piece of code that is expanded for each
s-tag/m-tag variable generated by |re2c|.
An optional list of block names specifies which blocks should be included
when computing the set of tag variables (if the list is empty, all blocks
are included).
There are two optional configurations: ``format`` and ``separator``.
Configuration ``format`` specifies a template string where ``@@{tag}`` (or
``@@`` for short) is replaced with the name of each tag variable.
Configuration ``separator`` specifies a piece of code used to join the
generated ``format`` pieces for different tag variables.

``/*!getstate:re2c[:<name1>[:<name2>...]] ... */`` or ``%{getstate[:<name1>[:<name2>...]] ... %}``
A directive that generates conditional dispatch on the lexer state (it
requires ``--storable-state`` option).
An optional list of block names specifies which blocks should be included in
the state dispatch. The default transition goes to the start label of the
first block on the list. If the list is empty, all blocks are included, and
the default transition goes to the first block in the file that has a start
label.
This directive is incompatible with the ``--loop-switch`` option and Rust,
as it requires cross-block transitions that are unsupported without the
``goto`` statement.

``/*!conditions:re2c[:<name1>[:<name2>...]] ... */``, ``/*!types:re2c... */`` or ``%{conditions[:<name1>[:<name2>...]] ... %}``, ``%{types... %}``
A directive that generates condition enumeration (it requires
``--conditions`` option).
An optional list of block names specifies which blocks should be included
when computing the set of conditions (if the list is empty, all blocks are
included).
By default the generated code is an enumeration ``YYCONDTYPE``. It can be
customized with optional configurations ``format`` and ``separator``.
Configuration ``format`` specifies a template string where ``@@{cond}`` (or
``@@`` for short) is replaced with the name of each condition, and
``@@{num}`` is replaced with a numeric index of that condition.
Configuration ``separator`` specifies a piece of code used to join the
generated ``format`` pieces for different conditions.

``/*!include:re2c <file> */`` or ``%{include <file> %}``
This directive allows one to include ``<file>``, which must be a double-quoted
file path. The contents of the file are literally substituted in place of
the directive, in the same way as ``#include`` works in C/C++. This
directive can be used together with the ``--depfile`` option to generate
build system dependencies on the included files.

``/*!header:re2c:on*/`` or ``%{header:on %}``
This directive marks the start of header file. Everything after it and up to
the following ``/*!header:re2c:off*/`` directive is processed by |re2c| and
written to the header file specified with ``-t --type-header`` option.

``/*!header:re2c:off*/`` or ``%{header:off %}``
This directive marks the end of header file started with
``/*!header:re2c:on*/``.

``/*!ignore:re2c ... */`` or ``%{ignore:re2c ... %}``
A block which contents are ignored and removed from the output file.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Configurations
--------------

``re2c:api``, ``re2c:flags:input``
Same as the ``--api`` option.
Expand Down
17 changes: 17 additions & 0 deletions doc/manual/syntax/directives.rst_
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Directives
----------

``!use:<name>;``
An in-block use directive that merges a previously defined rules block with
the specified name into the current block. Named definitions, configurations
and rules of the referenced block are added to the current ones. Conflicts
between overlapping rules and configurations are resolved in the usual way:
the first rule takes priority, and the latest configuration overrides the
preceding ones. One exception is the special rules ``*``, ``$`` and ``<!>``
for which a block-local definition always takes priority. A use directive
can be placed anywhere inside of a block, and multiple use directives are
allowed.

``!include <file>;``
This directive is the same as ``/*!include:re2c <file> */``, except that it
should be used inside of a |re2c| block.
6 changes: 0 additions & 6 deletions doc/manual/syntax/intro.rst_

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Regular expressions
-------------------

|re2c| uses the following syntax for regular expressions:

Expand Down
133 changes: 2 additions & 131 deletions doc/manual/syntax/syntax.rst_
Original file line number Diff line number Diff line change
@@ -1,134 +1,6 @@
A |re2c| program consists of a sequence of *blocks* intermixed with code in the
target language. Block start and end markers are either ``/*!re2c`` and ``*/``
(suitable for languages that have C-style multiline comments), or ``%{`` and
``%}`` (suitable for other languages). Blocks may have optional names that
allow them to be referenced in other parts of the program (named blocks were
added in version 2.2). There are different kinds of blocks:

``/*!re2c[:<name>] ... */`` or ``%{[:<name>] ... %}``
A *global block* contains definitions, configurations, directives and rules.
|re2c| compiles regular expressions associated with each rule into a
deterministic finite automaton, encodes it in the form of conditional jumps
in the target language and replaces the block with the generated code. Names
and configurations defined in a global block are added to the global scope
and become visible to subsequent blocks. At the start of the program the
global scope is initialized with command-line `options`_.

``/*!local:re2c[:<name>] ... */`` or ``%{local[:<name>] ... %}``
A *local block* is like a global block, but the names and configurations in
it have local scope (they do not affect other blocks).

``/*!rules:re2c[:<name>] ... */`` or ``%{rules[:<name>] ... %}``
A *rules block* is like a local block, but it does not generate any code by
itself, nor does it add any definitions to the global scope -- it is meant
to be reused in other blocks. This is a way of sharing code (more details in
the `reusable blocks`_ section). Prior to |re2c| version 2.2 rules blocks
required ``-r --reusable`` option.

``/*!use:re2c[:<name>] ... */`` or ``%{use[:<name>] ... %}``
A use block that references a previously defined rules block. If the name is
specified, |re2c| looks for a rules blocks with this name. Otherwise the most
recent rules block is used (either a named or an unnamed one). A use block
can add definitions, configurations and rules of its own, which are added to
those of the referenced rules block. Prior to |re2c| version 2.2 use blocks
required ``-r --reusable`` option.

``!use:<name>;``
An in-block use directive that merges a previously defined rules block with
the specified name into the current block. Named definitions, configurations
and rules of the referenced block are added to the current ones. Conflicts
between overlapping rules and configurations are resolved in the usual way:
the first rule takes priority, and the latest configuration overrides the
preceding ones. One exception is the special rules ``*``, ``$`` and ``<!>``
for which a block-local definition always takes priority. A use directive
can be placed anywhere inside of a block, and multiple use directives are
allowed.

``/*!max:re2c[:<name1>[:<name2>...]] ... */`` or ``%{max[:<name1>[:<name2>...]] ... %}``
A directive that generates ``YYMAXFILL`` definition.
An optional list of block names specifies which blocks should be included
when computing ``YYMAXFILL`` value (if the list is empty, all blocks are
included).
By default the generated code is a macro-definition for C
(``#define YYMAXFILL <n>``), or a global variable for Go
(``var YYMAXFILL int = <n>``). It can be customized with an optional
configuration ``format`` that specifies a template string where ``@@{max}``
(or ``@@`` for short) is replaced with the numeric value of ``YYMAXFILL``.

``/*!maxnmatch:re2c[:<name1>[:<name2>...]] ... */`` or ``%{maxnmatch[:<name1>[:<name2>...]] ... %}``
A directive that generates ``YYMAXNMATCH`` definition (it requires
``-P --posix-captures`` option).
An optional list of block names specifies which blocks should be included
when computing ``YYMAXNMATCH`` value (if the list is empty, all blocks are
included).
By default the generated code is a macro-definition for C
(``#define YYMAXNMATCH <n>``), or a global variable for Go
(``var YYMAXNMATCH int = <n>``). It can be customized with an optional
configuration ``format`` that specifies a template string where ``@@{max}``
(or ``@@`` for short) is replaced with the numeric value of ``YYMAXNMATCH``.

``/*!stags:re2c[:<name1>[:<name2>...]] ... */``, ``/*!mtags:re2c[:<name1>[:<name2>...]] ... */`` or ``%{stags[:<name1>[:<name2>...]] ... %}``, ``%{mtags[:<name1>[:<name2>...]] ... %{``
Directives that specify a template piece of code that is expanded for each
s-tag/m-tag variable generated by |re2c|.
An optional list of block names specifies which blocks should be included
when computing the set of tag variables (if the list is empty, all blocks
are included).
There are two optional configurations: ``format`` and ``separator``.
Configuration ``format`` specifies a template string where ``@@{tag}`` (or
``@@`` for short) is replaced with the name of each tag variable.
Configuration ``separator`` specifies a piece of code used to join the
generated ``format`` pieces for different tag variables.

``/*!getstate:re2c[:<name1>[:<name2>...]] ... */`` or ``%{getstate[:<name1>[:<name2>...]] ... %}``
A directive that generates conditional dispatch on the lexer state (it
requires ``--storable-state`` option).
An optional list of block names specifies which blocks should be included in
the state dispatch. The default transition goes to the start label of the
first block on the list. If the list is empty, all blocks are included, and
the default transition goes to the first block in the file that has a start
label.
This directive is incompatible with the ``--loop-switch`` option and Rust,
as it requires cross-block transitions that are unsupported without the
``goto`` statement.

``/*!conditions:re2c[:<name1>[:<name2>...]] ... */``, ``/*!types:re2c... */`` or ``%{conditions[:<name1>[:<name2>...]] ... %}``, ``%{types... %}``
A directive that generates condition enumeration (it requires
``--conditions`` option).
An optional list of block names specifies which blocks should be included
when computing the set of conditions (if the list is empty, all blocks are
included).
By default the generated code is an enumeration ``YYCONDTYPE``. It can be
customized with optional configurations ``format`` and ``separator``.
Configuration ``format`` specifies a template string where ``@@{cond}`` (or
``@@`` for short) is replaced with the name of each condition, and
``@@{num}`` is replaced with a numeric index of that condition.
Configuration ``separator`` specifies a piece of code used to join the
generated ``format`` pieces for different conditions.

``/*!include:re2c <file> */`` or ``%{include <file> %}``
This directive allows one to include ``<file>``, which must be a double-quoted
file path. The contents of the file are literally substituted in place of
the directive, in the same way as ``#include`` works in C/C++. This
directive can be used together with the ``--depfile`` option to generate
build system dependencies on the included files.

``!include <file>;``
This directive is the same as ``/*!include:re2c <file> */``, except that it
should be used inside of a |re2c| block.

``/*!header:re2c:on*/`` or ``%{header:on %}``
This directive marks the start of header file. Everything after it and up to
the following ``/*!header:re2c:off*/`` directive is processed by |re2c| and
written to the header file specified with ``-t --type-header`` option.

``/*!header:re2c:off*/`` or ``%{header:off %}``
This directive marks the end of header file started with
``/*!header:re2c:on*/``.

``/*!ignore:re2c ... */`` or ``%{ignore:re2c ... %}``
A block which contents are ignored and removed from the output file.

A block may contain the following kinds of statements:
target language. A block may contain *definitions*, *configurations*, *rules*
and *directives* in any order:

``<name> = <regular expression>;``
A *definition* binds a name to a regular expression. Names may contain
Expand Down Expand Up @@ -168,4 +40,3 @@ A block may contain the following kinds of statements:
block into the current one (see the `reusable blocks`_ section), and the
``!include`` directive allows one to include an outer file (see the
`include files`_ section).

0 comments on commit 28989c2

Please sign in to comment.