OPTIONS
-------
+.. ./gh-pages-gen/src/manual/options/options_list.rst
+
``-? -h --help``
- Invoke a short help.
+ Show a short help screen:
``-b --bit-vectors``
- Implies ``-s``. Use bit vectors as well in the
- attempt to coax better code out of the compiler. Most useful for
- specifications with more than a few keywords (e.g. for most programming
+ Implies ``-s``. Use bit vectors as well to try to
+ coax better code out of the compiler. Most useful for
+ specifications with more than a few keywords (e.g., for most programming
languages).
``-c --conditions``
- Used to support (f)lex-like condition support.
+ Used for (f)lex-like condition support.
``-d --debug-output``
Creates a parser that dumps information about
- the current position and in which state the parser is while parsing the
- input. This is useful to debug parser issues and states. If you use this
- switch you need to define a macro ``YYDEBUG`` that is called like a
+ the current position and the state the parser is in.
+ This is useful to debug parser issues and states. If you use this
+ switch, you need to define a ``YYDEBUG`` macro, which will be called like a
function with two parameters: ``void YYDEBUG (int state, char current)``.
The first parameter receives the state or ``-1`` and the second parameter
receives the input at the current cursor.
``-D --emit-dot``
- Emit Graphviz dot data. It can then be processed
- with e.g. ``dot -Tpng input.dot > output.png``. Please note that
+ Emit Graphviz dot data, which can then be processed
+ with e.g., ``dot -Tpng input.dot > output.png``. Please note that
scanners with many states may crash dot.
``-e --ecb``
Generate a parser that supports EBCDIC. The generated
- code can deal with any character up to 0xFF. In this mode ``re2c`` assumes
+ code can deal with any character up to 0xFF. In this mode, ``re2c`` assumes
that input character size is 1 byte. This switch is incompatible with
``-w``, ``-x``, ``-u`` and ``-8``.
``-F --flex-syntax``
Partial support for flex syntax. When this flag
- is active then named definitions must be surrounded by curly braces and
+ is active, named definitions must be surrounded by curly braces and
can be defined without an equal sign and the terminating semi colon.
- Instead names are treated as direct double quoted strings.
+ Instead, names are treated as direct double quoted strings.
``-g --computed-gotos``
Generate a scanner that utilizes GCC's
- computed goto feature. That is ``re2c`` generates jump tables whenever a
- decision is of a certain complexity (e.g. a lot of if conditions are
- otherwise necessary). This is only useable with GCC and produces output
- that cannot be compiled with any other compiler. Note that this implies
- ``-b`` and that the complexity threshold can be configured using the
- inplace configuration ``cgoto:threshold``.
+ computed goto feature. That is, ``re2c`` generates jump tables whenever a
+ decision is of a certain complexity (e.g., a lot of if conditions are
+ otherwise necessary). This is only usable with compilers that support this feature.
+ Note that this implies ``-b`` and that the complexity threshold can be configured
+ using the inplace configuration ``cgoto:threshold``.
``-i --no-debug-info``
Do not output ``#line`` information. This is
``-r --reusable``
Allows reuse of scanner definitions with ``/*!use:re2c */`` after ``/*!rules:re2c */``.
- In this mode no ``/*!re2c */`` block and exactly one ``/*!rules:re2c */`` must be present.
- The rules are being saved and used by every ``/*!use:re2c */`` block that follows.
+ In this mode, no ``/*!re2c */`` block and exactly one ``/*!rules:re2c */`` must be present.
+ The rules are saved and used by every ``/*!use:re2c */`` block that follows.
These blocks can contain inplace configurations, especially ``re2c:flags:e``,
``re2c:flags:w``, ``re2c:flags:x``, ``re2c:flags:u`` and ``re2c:flags:8``.
That way it is possible to create the same scanner multiple times for
``--no-generation-date``
Suppress date output in the generated file.
+``--no-version``
+ Suppress version output in the generated file.
+
``--no-generation-date``
Suppress version output in the generated file.
[\\x00-\\xFF][\\x00-\\xFF].
``--dfa-minimization <table | moore>``
- Internal algorithm used by re2c to minimize DFA (defaults to ``moore``).
- Both table filling and Moore's algorithms should produce identical DFA (up to states relabelling).
- Table filling algorithm is much simpler and slower; it serves as a reference implementation.
+ Internal algorithm used by re2c to minimize the DFA (defaults to ``moore``).
+ Both table filling and Moore's algorithms should produce the same DFA (up to states relabelling).
+ The table filling algorithm is much simpler and slower; it serves as a reference implementation.
``-1 --single-pass``
Deprecated and does nothing (single pass is by default now).
+.. ./gh-pages-gen/src/manual/warnings/warnings_general.rst
+
``-W``
Turn on all warnings.
``-Werror``
- Turn warnings into errors. Note that this option along
- doesn't turn on any warnings, it only affects those warnings that have
+ Turn warnings into errors. Note that this option alone
+ doesn't turn on any warnings; it only affects those warnings that have
been turned on so far or will be turned on later.
``-W<warning>``
- Turn on individual ``warning``.
+ Turn on a ``warning``.
``-Wno-<warning>``
- Turn off individual ``warning``.
+ Turn off a ``warning``.
``-Werror-<warning>``
- Turn on individual ``warning`` and treat it as error (this implies ``-W<warning>``).
+ Turn on a ``warning`` and treat it as an error (this implies ``-W<warning>``).
``-Wno-error-<warning>``
- Don't treat this particular ``warning`` as error. This doesn't turn off
+ Don't treat this particular ``warning`` as an error. This doesn't turn off
the warning itself.
+.. ./gh-pages-gen/src/manual/warnings/warnings_list.rst
+
``-Wcondition-order``
Warn if the generated program makes implicit
assumptions about condition numbering. One should use either ``-t, --type-header`` option or
character class makes no sense: it should always fail. However, for
backwards compatibility reasons ``re2c`` allows empty character class and
treats it as empty string. Use ``--empty-class`` option to change default
- behaviour.
+ behavior.
``-Wmatch-empty-string``
Warn if regular expression in a rule is
``-Wswapped-range``
Warn if range lower bound is greater that upper
- bound. Default ``re2c`` behaviour is to silently swap range bounds.
+ bound. Default ``re2c`` behavior is to silently swap range bounds.
``-Wundefined-control-flow``
Warn if some input strings cause undefined
default rule ``*`` (this rule has the lowest priority, matches any code unit and consumes
exactly one code unit).
+``-Wunreachable-rules``
+ Warn about rules that are shadowed by other rules and will never match.
+
``-Wuseless-escape``
Warn if a symbol is escaped when it shouldn't be.
By default re2c silently ignores escape, but this may as well indicate a
typo or an error in escape sequence.
-
-
INTERFACE CODE
--------------
+.. ./gh-pages-gen/src/manual/syntax/syntax.rst #Interface
+
+
The user must supply interface code either in the form of C/C++ code
(macros, functions, variables, etc.) or in the form of ``INPLACE CONFIGURATIONS``.
Which symbols must be defined and which are optional
-depends on a particular use case.
+depends on the particular use case.
``YYCONDTYPE``
- In ``-c`` mode you can use ``-t`` to generate a file that
+ In ``-c`` mode, you can use ``-t`` to generate a file that
contains the enumeration used as conditions. Each of the values refers
to a condition of a rule set.
``YYCTYPE``
Type used to hold an input symbol (code unit). Usually
- ``char`` or ``unsigned char`` for ASCII, EBCDIC and UTF-8, ``unsigned short``
- for UTF-16 or UCS-2 and ``unsigned int`` for UTF-32.
+ ``char`` or ``unsigned char`` for ASCII, EBCDIC or UTF-8, or *unsigned short*
+ for UTF-16 or UCS-2, or ``unsigned int`` for UTF-32.
``YYCURSOR``
l-value of type ``YYCTYPE *`` that points to the current input symbol. The generated code advances
``YYDEBUG (state, current)``
This is only needed if the ``-d`` flag was
- specified. It allows one to easily debug the generated parser by calling a
+ specified. It allows to easily debug the generated parser by calling a
user defined function for every state. The function should have the
following signature: ``void YYDEBUG (int state, char current)``. The first
parameter receives the state or -1 and the second parameter receives the
``YYFILL (n)``
The generated code "calls"" ``YYFILL (n)`` when the
buffer needs (re)filling: at least ``n`` additional characters should be
- provided. ``YYFILL (n)`` should adjust ``YYCURSOR``, ``YYLIMIT``, ``YYMARKER``
+ provided. ``YYFILL (n)`` should adjust ``YYCURSOR``, ``YYLIMIT``, ``YYMARKER``,
and ``YYCTXMARKER`` as needed. Note that for typical programming languages
``n`` will be the length of the longest keyword plus one. The user can
place a comment of the form ``/*!max:re2c*/`` to insert ``YYMAXFILL`` definition that is set to the maximum
``YYGETCONDITION ()``
This define is used to get the condition prior to
- entering the scanner code when using ``-c`` switch. The value must be
+ entering the scanner code when using the ``-c`` switch. The value must be
initialized with a value from the enumeration ``YYCONDTYPE`` type.
``YYGETSTATE ()``
instance of ``YYFILL (n)`` that is about to be called. Should the user
wish to save the state of the scanner and have ``YYFILL (n)`` return to
the caller, all he has to do is store that unique identifier in a
- variable. Later, when the scannered is called again, it will call
+ variable. Later, when the scanner is called again, it will call
``YYGETSTATE ()`` and resume execution right where it left off. The
generated code will contain both ``YYSETSTATE (s)`` and ``YYGETSTATE`` even
- if ``YYFILL (n)`` is being disabled.
-
-
+ if ``YYFILL (n)`` is disabled.
SYNTAX
------
RULES
~~~~~
-Rules consist of a regular expression (see ``REGULAR EXPRESSIONS``) along with a block of C/C++ code
-that is to be executed when the associated regular expression is
+.. ./gh-pages-gen/src/manual/syntax/syntax.rst #RULES
+
+Each rule consist of a regular expression (see ``REGULAR EXPRESSIONS``) accompanied with a block of C/C++ code
+which is to be executed when the associated regular expression is
matched. You can either start the code with an opening curly brace or
-the sequence ``:=``. When the code with a curly brace then ``re2c`` counts the brace depth
-and stops looking for code automatically. Otherwise curly braces are not
+the sequence ``:=``. If you use an opening curly brace, ``re2c`` will count brace depth
+and stop looking for code automatically. Otherwise, curly braces are not
allowed and ``re2c`` stops looking for code at the first line that does
not begin with whitespace. If two or more rules overlap, the first rule
is preferred.
``regular-expression := C/C++ code``
-There is one special rule: default rule ``*``
+There is one special rule: the default rule (``*``)
``* { C/C++ code }``
``* := C/C++ code``
-Note that default rule ``*`` differs from ``[^]``: default rule has the lowest priority,
-matches any code unit (either valid or invalid) and always consumes one character;
-while ``[^]`` matches any valid code point (not code unit) and can consume multiple
-code units. In fact, when variable-length encoding is used, ``*``
-is the only possible way to match invalid input character (see ``ENCODINGS`` for details).
-
-If ``-c`` is active then each regular expression is preceded by a list
-of comma separated condition names. Besides normal naming rules there
-are two special cases: ``<*>`` (such rules are merged to all conditions)
-and ``<>`` (such the rule cannot have an associated regular expression,
-its code is merged to all actions). Non empty rules may further more specify the new
-condition. In that case ``re2c`` will generate the necessary code to
+Note that the default rule (``*``) differs from ``[^]``: the default rule has the lowest priority,
+matches any code unit (either valid or invalid) and always consumes exactly one character.
+``[^]``, on the other hand, matches any valid code point (not the same as a code unit) and can consume multiple
+code units. In fact, when a variable-length encoding is used, ``*``
+is the only possible way to match an invalid input character.
+
+
+If ``-c`` is active, then each regular expression is preceded by a list
+of comma-separated condition names. Besides the normal naming rules, there
+are two special cases: ``<*>`` (these rules are merged to all conditions)
+and ``<>`` (these rules cannot have an associated regular expression;
+their code is merged to all actions). Non-empty rules may furthermore specify the new
+condition. In that case, ``re2c`` will generate the necessary code to
change the condition automatically. Rules can use ``:=>`` as a shortcut
to automatically generate code that not only sets the
new condition state but also continues execution with the new state. A
shortcut rule should not be used in a loop where there is code between
the start of the loop and the ``re2c`` block unless ``re2c:cond:goto``
-is changed to ``continue``. If code is necessary before all rules (though not simple jumps) you
-can doso by using ``<!>`` pseudo-rules.
+is changed to ``continue``. If some code is needed before all rules (though not before simple jumps), you
+can insert it with ``<!>`` pseudo-rules.
``<condition-list> regular-expression { C/C++ code }``
INPLACE CONFIGURATIONS
~~~~~~~~~~~~~~~~~~~~~~
+.. ./gh-pages-gen/src/manual/syntax/syntax.rst #Configurations
+
+
``re2c:condprefix = yyc;``
- Allows one to specify the prefix used for
- condition labels. That is this text is prepended to any condition label
+ Allows to specify the prefix used for
+ condition labels. That is, the text to be prepended to condition labels
in the generated output file.
``re2c:condenumprefix = yyc;``
- Allows one to specify the prefix used for
- condition values. That is this text is prepended to any condition enum
- value in the generated output file.
+ Allows to specify the prefix used for
+ condition values. That is this text is prepended to condition enum
+ values in the generated output file.
``re2c:cond:divider = "/* *********************************** */";``
- Allows one to customize the devider for condition blocks. You can use ``@@``
+ Allows to customize the divider for condition blocks. You can use ``@@``
to put the name of the condition or customize the placeholder using
``re2c:cond:divider@cond``.
replaced with the condition name in ``re2c:cond:divider``.
``re2c:cond:goto = "goto @@;";``
- Allows one to customize the condition goto statements used with ``:=>`` style rules. You can use ``@@``
- to put the name of the condition or ustomize the placeholder using
+ Allows to customize the condition goto statements used with ``:=>`` style rules. You can use ``@@``
+ to put the name of the condition or customize the placeholder using
``re2c:cond:goto@cond``. You can also change this to ``continue;``, which
would allow you to continue with the next loop cycle including any code
- between loop start and re2c block.
+ between your loop start and your re2c block.
``re2c:cond:goto@cond = @@;``
- Spcifies the placeholder that will be replaced with the condition label in ``re2c:cond:goto``.
+ Specifies the placeholder that will be replaced with the condition label in ``re2c:cond:goto``.
``re2c:indent:top = 0;``
- Specifies the minimum number of indentation to
- use. Requires a numeric value greater than or equal zero.
+ Specifies the minimum amount of indentation to
+ use. Requires a numeric value greater than or equal to zero.
``re2c:indent:string = "\t";``
Specifies the string to use for indentation. Requires a string that should
- contain only whitespace unless you need this for external tools. The easiest
- way to specify spaces is to enclude them in single or double quotes.
- If you do not want any indentation at all you can simply set this to "".
+ contain only whitespace unless you need something else for external tools. The easiest
+ way to specify spaces is to enclose them in single or double quotes.
+ If you do not want any indentation at all, you can simply set this to "".
``re2c:yych:conversion = 0;``
- When this setting is non zero, then ``re2c`` automatically generates
+ When this setting is non zero, ``re2c`` automatically generates
conversion code whenever yych gets read. In this case the type must be
defined using ``re2c:define:YYCTYPE``.
``re2c:yych:emit = 1;``
- Generation of ``yych`` can be suppressed by setting this to 0.
+ The generation of *yych* can be suppressed by setting this to 0.
``re2c:yybm:hex = 0;``
- If set to zero then a decimal table is being used else a hexadecimal table will be generated.
+ If set to zero, a decimal table will be used. Otherwise, a hexadecimal table will be generated.
``re2c:yyfill:enable = 1;``
- Set this to zero to suppress generation of ``YYFILL (n)``. When using this be sure to verify that the generated
- scanner does not read behind input. Allowing this behavior might
- introduce sever security issues to you programs.
+ Set this to zero to suppress the generation of ``YYFILL (n)``. When using this, be sure to verify that the generated
+ scanner does not read behind the end of your input, as allowing such behavior might
+ introduce several security issues to your program.
``re2c:yyfill:check = 1;``
- This can be set 0 to suppress output of the
- pre condition using ``YYCURSOR`` and ``YYLIMIT`` which becomes useful when
+ This can be set to 0 to suppress the generations of
+ ``YYCURSOR`` and ``YYLIMIT`` based precondition checks. This option is useful when
``YYLIMIT + YYMAXFILL`` is always accessible.
``re2c:define:YYFILL = "YYFILL";``
- Substitution for ``YYFILL``. Note
- that by default ``re2c`` generates argument in braces and semicolon after
+ Define a substitution for ``YYFILL``. Note that by default,
+ ``re2c`` generates an argument in parentheses and a semicolon after
``YYFILL``. If you need to make ``YYFILL`` an arbitrary statement rather
- than a call, set ``re2c:define:YYFILL:naked`` to non-zero and use
- ``re2c:define:YYFILL@len`` to denote formal parameter inside of ``YYFILL``
+ than a call, set ``re2c:define:YYFILL:naked`` to a non-zero value and use
+ ``re2c:define:YYFILL@len`` to set a placeholder for the formal parameter inside of your ``YYFILL``
body.
``re2c:define:YYFILL@len = "@@";``
Any occurrence of this text
- inside of ``YYFILL`` will be replaced with the actual argument.
+ inside of a ``YYFILL`` call will be replaced with the actual argument.
``re2c:yyfill:parameter = 1;``
- Controls argument in braces after
- ``YYFILL``. If zero, argument is omitted. If non-zero, argument is
- generated unless ``re2c:define:YYFILL:naked`` is set to non-zero.
+ Controls the argument in the parentheses that follow ``YYFILL``. If zero, the argument is omitted.
+ If non-zero, the argument is generated unless ``re2c:define:YYFILL:naked`` is set to non-zero.
``re2c:define:YYFILL:naked = 0;``
- Controls argument in braces and
- semicolon after ``YYFILL``. If zero, both argument and semicolon are
- omitted. If non-zero, argument is generated unless
- ``re2c:yyfill:parameter`` is set to zero and semicolon is generated
+ Controls the argument in the parentheses after ``YYFILL`` and
+ the following semicolon. If zero, both the argument and the semicolon are
+ omitted. If non-zero, the argument is generated unless
+ ``re2c:yyfill:parameter`` is set to zero; the semicolon is generated
unconditionally.
``re2c:startlabel = 0;``
- If set to a non zero integer then the start
- label of the next scanner blocks will be generated even if not used by
- the scanner itself. Otherwise the normal ``yy0`` like start label is only
- being generated if needed. If set to a text value then a label with that
+ If set to a non zero integer, then the start
+ label of the next scanner block will be generated even if it isn't used by
+ the scanner itself. Otherwise, the normal ``yy0``-like start label is only
+ generated if needed. If set to a text value, then a label with that
text will be generated regardless of whether the normal start label is
- being used or not. This setting is being reset to 0 after a start
- label has been generated.
+ used or not. This setting is reset to 0 after a start label has been generated.
+ If set to a non zero integer, then the start
``re2c:labelprefix = "yy";``
- Allows one to change the prefix of numbered
- labels. The default is ``yy`` and can be set any string that is a valid
- label.
+ Allows to change the prefix of numbered
+ labels. The default is ``yy``. Can be set any string that is valid in
+ a label name.
``re2c:state:abort = 0;``
- When not zero and switch ``-f`` is active then
+ When not zero and the ``-f`` switch is active, then
the ``YYGETSTATE`` block will contain a default case that aborts and a -1
- case is used for initialization.
+ case will be used for initialization.
``re2c:state:nextlabel = 0;``
Used when ``-f`` is active to control
whether the ``YYGETSTATE`` block is followed by a ``yyNext:`` label line.
- Instead of using ``yyNext`` you can usually also use configuration
+ Instead of using ``yyNext``, you can usually also use configuration
``startlabel`` to force a specific start label or default to ``yy0`` as
- start label. Instead of using a dedicated label it is often better to
+ a start label. Instead of using a dedicated label, it is often better to
separate the ``YYGETSTATE`` code from the actual scanner code by placing a
``/*!getstate:re2c*/`` comment.
``re2c:cgoto:threshold = 9;``
- When ``-g`` is active this value specifies
- the complexity threshold that triggers generation of jump tables rather
- than using nested if's and decision bitfields. The threshold is compared
- against a calculated estimation of if-s needed where every used bitmap
+ When ``-g`` is active, this value specifies
+ the complexity threshold that triggers the generation of jump tables rather
+ than nested ifs and decision bitfields. The threshold is compared
+ against a calculated estimation of ifs needed where every used bitmap
divides the threshold by 2.
``re2c:yych:conversion = 0;``
- When the input uses signed characters and
- ``-s`` or ``-b`` switches are in effect re2c allows one to automatically convert
+ When input uses signed characters and the
+ ``-s`` or ``-b`` switches are in effect, re2c allows automatic conversion
to the unsigned character type that is then necessary for its internal
- single character. When this setting is zero or an empty string the
- conversion is disabled. Using a non zero number the conversion is taken
- from ``YYCTYPE``. If that is given by an inplace configuration that value
- is being used. Otherwise it will be ``(YYCTYPE)`` and changes to that
- configuration are no longer possible. When this setting is a string the
- braces must be specified. Now assuming your input is a ``char *``
- buffer and you are using above mentioned switches you can set
+ single character. When this setting is zero or an empty string, the
+ conversion is disabled. If a non zero number is used, the conversion is taken
+ from ``YYCTYPE``. If ``YYCTYPE`` is overridden by an inplace configuration setting, that setting is
+ is used instead of a ``YYCTYPE`` cast. Otherwise, it will be ``(YYCTYPE)`` and changes to that
+ configuration are no longer possible. When this setting is a string, it must contain the casting
+ parentheses. Now assuming your input is a ``char *`` buffer and you are using the above mentioned switches, you can set
``YYCTYPE`` to ``unsigned char`` and this setting to either 1 or ``(unsigned char)``.
``re2c:define:YYCONDTYPE = "YYCONDTYPE";``
Enumeration used for condition support with ``-c`` mode.
``re2c:define:YYCTXMARKER = "YYCTXMARKER";``
- Allows one to overwrite the
- define ``YYCTXMARKER`` and thus avoiding it by setting the value to the
- actual code needed.
+ Replaces the ``YYCTXMARKER`` placeholder with the specified identifier.
``re2c:define:YYCTYPE = "YYCTYPE";``
- Allows one to overwrite the define
- ``YYCTYPE`` and thus avoiding it by setting the value to the actual code
- needed.
+ Replaces the ``YYCTYPE`` placeholder with the specified type.
``re2c:define:YYCURSOR = "YYCURSOR";``
- Allows one to overwrite the define
- ``YYCURSOR`` and thus avoiding it by setting the value to the actual code
- needed.
+ Replaces the ``YYCURSOR`` placeholder with the specified identifier.
``re2c:define:YYDEBUG = "YYDEBUG";``
- Allows one to overwrite the define
- ``YYDEBUG`` and thus avoiding it by setting the value to the actual code
- needed.
+ Replaces the ``YYDEBUG`` placeholder with the specified identifier.
``re2c:define:YYGETCONDITION = "YYGETCONDITION";``
Substitution for
- ``YYGETCONDITION``. Note that by default ``re2c`` generates braces after
+ ``YYGETCONDITION``. Note that by default, ``re2c`` generates parentheses after
``YYGETCONDITION``. Set ``re2c:define:YYGETCONDITION:naked`` to non-zero to
- omit braces.
+ omit the parentheses.
``re2c:define:YYGETCONDITION:naked = 0;``
- Controls braces after
- ``YYGETCONDITION``. If zero, braces are omitted. If non-zero, braces are
+ Controls the parentheses after
+ ``YYGETCONDITION``. If zero, the parentheses are omitted. If non-zero, the parentheses are
generated.
``re2c:define:YYSETCONDITION = "YYSETCONDITION";``
Substitution for
- ``YYSETCONDITION``. Note that by default ``re2c`` generates argument in
- braces and semicolon after ``YYSETCONDITION``. If you need to make
+ ``YYSETCONDITION``. Note that by default, ``re2c``, generates an argument in
+ parentheses followed by a semicolon after ``YYSETCONDITION``. If you need to make
``YYSETCONDITION`` an arbitrary statement rather than a call, set
``re2c:define:YYSETCONDITION:naked`` to non-zero and use
- ``re2c:define:YYSETCONDITION@cond`` to denote formal parameter inside of
+ ``re2c:define:YYSETCONDITION@cond`` to denote the formal parameter inside of the
``YYSETCONDITION`` body.
``re2c:define:YYSETCONDITION@cond = "@@";``
argument.
``re2c:define:YYSETCONDITION:naked = 0;``
- Controls argument in braces
- and semicolon after ``YYSETCONDITION``. If zero, both argument and
- semicolon are omitted. If non-zero, both argument and semicolon are
+ Controls the argument in parentheses
+ and the semicolon after ``YYSETCONDITION``. If zero, both the argument and
+ the semicolon are omitted. If non-zero, both the argument and the semicolon are
generated.
``re2c:define:YYGETSTATE = "YYGETSTATE";``
Substitution for
- ``YYGETSTATE``. Note that by default ``re2c`` generates braces after
+ ``YYGETSTATE``. Note that by default, ``re2c`` generates parentheses after
``YYGETSTATE``. Set ``re2c:define:YYGETSTATE:naked`` to non-zero to omit
- braces.
+ the parentheses.
``re2c:define:YYGETSTATE:naked = 0;``
- Controls braces after
- ``YYGETSTATE``. If zero, braces are omitted. If non-zero, braces are
+ Controls the parentheses that follow
+ ``YYGETSTATE``. If zero, the parentheses are omitted. If non-zero, they are
generated.
``re2c:define:YYSETSTATE = "YYSETSTATE";``
Substitution for
- ``YYSETSTATE``. Note that by default ``re2c`` generates argument in braces
- and semicolon after ``YYSETSTATE``. If you need to make ``YYSETSTATE`` an
+ ``YYSETSTATE``. Note that by default, ``re2c`` generates an argument in parentheses
+ followed by a semicolon after ``YYSETSTATE``. If you need to make ``YYSETSTATE`` an
arbitrary statement rather than a call, set
``re2c:define:YYSETSTATE:naked`` to non-zero and use
``re2c:define:YYSETSTATE@cond`` to denote formal parameter inside of
- ``YYSETSTATE`` body.
+ your ``YYSETSTATE`` body.
``re2c:define:YYSETSTATE@state = "@@";``
Any occurrence of this text
inside of ``YYSETSTATE`` will be replaced with the actual argument.
``re2c:define:YYSETSTATE:naked = 0;``
- Controls argument in braces and
- semicolon after ``YYSETSTATE``. If zero, both argument and semicolon are
- omitted. If non-zero, both argument and semicolon are generated.
+ Controls the argument in parentheses and the
+ semicolon after ``YYSETSTATE``. If zero, both argument and the semicolon are
+ omitted. If non-zero, both the argument and the semicolon are generated.
``re2c:define:YYLIMIT = "YYLIMIT";``
- Allows one to overwrite the define
- ``YYLIMIT`` and thus avoiding it by setting the value to the actual code
+ Replaces the ``YYLIMIT`` placeholder with the specified identifier.
needed.
``re2c:define:YYMARKER = "YYMARKER";``
- Allows one to overwrite the define
- ``YYMARKER`` and thus avoiding it by setting the value to the actual code
- needed.
+ Replaces the ``YYMARKER`` placeholder with the specified identifier.
``re2c:label:yyFillLabel = "yyFillLabel";``
- Allows one to overwrite the name of the label ``yyFillLabel``.
+ Overrides the name of the ``yyFillLabel`` label.
``re2c:label:yyNext = "yyNext";``
- Allows one to overwrite the name of the label ``yyNext``.
+ Overrides the name of the ``yyNext`` label.
``re2c:variable:yyaccept = yyaccept;``
- Allows one to overwrite the name of the variable ``yyaccept``.
+ Overrides the name of the ``yyaccept`` variable.
``re2c:variable:yybm = "yybm";``
- Allows one to overwrite the name of the variable ``yybm``.
+ Overrides the name of the ``yybm`` variable.
``re2c:variable:yych = "yych";``
- Allows one to overwrite the name of the variable ``yych``.
+ Overrides the name of the ``yych`` variable.
``re2c:variable:yyctable = "yyctable";``
- When both ``-c`` and ``-g`` are active then ``re2c`` uses this variable to generate a static jump table
+ When both ``-c`` and ``-g`` are active, ``re2c`` will use this variable to generate a static jump table
for ``YYGETCONDITION``.
``re2c:variable:yystable = "yystable";``
Deprecated.
``re2c:variable:yytarget = "yytarget";``
- Allows one to overwrite the name of the variable ``yytarget``.
-
REGULAR EXPRESSIONS
~~~~~~~~~~~~~~~~~~~
+.. ./gh-pages-gen/src/manual/syntax/syntax.rst #Regular expressions
+
+
``"foo"``
literal string ``"foo"``. ANSI-C escape sequences can be used.
``'foo'``
- literal string ``"foo"`` (characters [a-zA-Z] treated
- case-insensitive). ANSI-C escape sequences can be used.
+ literal string ``"foo"`` (case insensitive for characters [a-zA-Z]).
+ ANSI-C escape sequences can be used.
``[xyz]``
- character class; in this case, regular expression matches either ``x``, ``y``, or ``z``.
+ character class; in this case, the regular expression matches ``x``, ``y``, or ``z``.
``[abj-oZ]``
- character class with a range in it; matches ``a``, ``b``, any letter from ``j`` through ``o`` or ``Z``.
+ character class with a range in it; matches ``a``, ``b``, any letter from ``j`` through ``o``, or ``Z``.
``[^class]``
inverted character class.
``r`` followed by ``s`` (concatenation).
``r | s``
- either ``r`` or ``s`` (alternative).
+ ``r`` or ``s`` (alternative).
``r`` / ``s``
``r`` but only if it is followed by ``s``. Note that ``s`` is not
part of the matched text. This type of regular expression is called
- "trailing context". Trailing context can only be the end of a rule
- and not part of a named definition.
+ "trailing context". Trailing context can only be at the end of a rule
+ and cannot be part of a named definition.
``r{n}``
matches ``r`` exactly ``n`` times.
match any character except newline.
``name``
- matches named definition as specified by ``name`` only if ``-F`` is
+ matches a named definition as specified by ``name`` only if ``-F`` is
off. If ``-F`` is active then this behaves like it was enclosed in double
quotes and matches the string "name".
Hexadecimal characters from 0x10000 to 0xFFFFffff are defined by backslash, an upper cased ``\U``
and eight hexadecimal digits (e.g. ``\U12345678``).
-The only portable "any" rule is the default rule ``*``.
-
+The only portable "any" rule is the default rule, ``*``.
SCANNER WITH STORABLE STATES
Typically, if there is a preprocessor ahead of the scanner in the
stream, or for that matter any other procedural source of data, the
-scanner cannot "ask" for more data unless both scanner and source
-live in a separate threads.
+scanner cannot "ask" for more data unless both the scanner and the source
+live in separate threads.
-The ``-f`` flag is useful for just this situation: it lets users design
-scanners that work in a "push" model, i.e. where data is fed to the
+The ``-f`` flag is useful for exactly for situations like that: it lets users design
+scanners that work in a "push" model, i.e., a model where data is fed to the
scanner chunk by chunk. When the scanner runs out of data to consume, it
-just stores its state, and return to the caller. When more input data is
+stores its state and returns to the caller. When more input data is
fed to the scanner, it resumes operations exactly where it left off.
Changes needed compared to the "pull" model:
-* User has to supply macros ``YYSETSTATE ()`` and ``YYGETSTATE (state)``.
+* The user has to supply macros named ``YYSETSTATE ()`` and ``YYGETSTATE (state)``.
-* The ``-f`` option inhibits declaration of ``yych`` and ``yyaccept``. So the
- user has to declare these. Also the user has to save and restore these.
- In the example ``examples/push_model/push.re`` these are declared as
- fields of the (C++) class of which the scanner is a method, so they do
- not need to be saved/restored explicitly. For C they could e.g. be made
- macros that select fields from a structure passed in as parameter.
+* The ``-f`` option inhibits declaration of ``yych`` and ``yyaccept``, so the
+ user has to declare them. Also the user has to save and restore them.
+ In the ``examples/push_model/push.re`` example, these are declared as
+ fields of a (C++) class of which the scanner is a method, so they do
+ not need to be saved/restored explicitly. For C, they could, e.g., be made
+ macros that select fields from a structure passed in as a parameter.
Alternatively, they could be declared as local variables, saved with
- ``YYFILL (n)`` when it decides to return and restored at entry to the
+ ``YYFILL (n)`` when it decides to return and restore upon entering the
function. Also, it could be more efficient to save the state from
``YYFILL (n)`` because ``YYSETSTATE (state)`` is called unconditionally.
- ``YYFILL (n)`` however does not get ``state`` as parameter, so we would have
+ ``YYFILL (n)`` however does not get ``state`` as a parameter, so we would have
to store state in a local variable by ``YYSETSTATE (state)``.
* Modify ``YYFILL (n)`` to return (from the function calling it) if more input is needed.
-* Modify caller to recognise if more input is needed and respond appropriately.
+* Modify the caller to recognize if more input is needed and respond appropriately.
* The generated code will contain a switch block that is used to
- restores the last state by jumping behind the corrspoding ``YYFILL (n)``
- call. This code is automatically generated in the epilog of the first ``/*!re2c */``
+ restores the last state by jumping behind the corresponding ``YYFILL (n)``
+ call. This code is automatically generated in the epilogue of the first ``/*!re2c */``
block. It is possible to trigger generation of the ``YYGETSTATE ()``
block earlier by placing a ``/*!getstate:re2c*/`` comment. This is especially useful when the scanner code should be
wrapped inside a loop.
-Please see ``examples/push_model/push.re`` for "push" model scanner. The
-generated code can be tweaked using inplace configurations ``state:abort``
+Please see ``examples/push_model/push.re`` for an example of a "push" model scanner. The
+generated code can be tweaked with inplace configurations ``state:abort``
and ``state:nextlabel``.
SCANNER WITH CONDITION SUPPORT
------------------------------
+.. ./gh-pages-gen/src/manual/features/conditions/conditions.rst
+
You can precede regular expressions with a list of condition names when
-using the ``-c`` switch. In this case ``re2c`` generates scanner blocks for
-each conditon. Where each of the generated blocks has its own
+using the ``-c`` switch. ``re2c`` will then generate a scanner block for
+each condition, and each of the generated blocks will have its own
precondition. The precondition is given by the interface define
``YYGETCONDITON()`` and must be of type ``YYCONDTYPE``.
There are two special rule types. First, the rules of the condition ``<*>``
-are merged to all conditions (note that they have lower priority than
-other rules of that condition). And second the empty condition list
-allows one to provide a code block that does not have a scanner part.
-Meaning it does not allow any regular expression. The condition value
+are merged to all conditions (note that they have a lower priority than
+other rules of that condition). And second, the empty condition list
+allows to provide a code block that does not have a scanner part,
+meaning it does not allow any regular expression. The condition value
referring to this special block is always the one with the enumeration
value 0. This way the code of this special rule can be used to
initialize a scanner. It is in no way necessary to have these rules: but
sometimes it is helpful to have a dedicated uninitialized condition
state.
-Non empty rules allow one to specify the new condition, which makes them
-transition rules. Besides generating calls for the define
-``YYSETCONDTITION`` no other special code is generated.
+Non empty rules allow to specify the new condition, which makes them
+transition rules. Besides generating calls for the
+``YYSETCONDTITION`` define, no other special code is generated.
-There is another kind of special rules that allow one to prepend code to any
+There is another kind of special rules that allows to prepend code to any
code block of all rules of a certain set of conditions or to all code
blocks to all rules. This can be helpful when some operation is common
-among rules. For instance this can be used to store the length of the
+among rules. For instance, this can be used to store the length of the
scanned string. These special setup rules start with an exclamation mark
followed by either a list of conditions ``<! condition, ... >`` or a star
``<!*>``. When ``re2c`` generates the code for a rule whose state does not have a
-setup rule and a star'd setup rule is present, than that code will be
+setup rule and a starred setup rule is present, that code will be
used as setup code.
-
ENCODINGS
---------
+.. ./gh-pages-gen/src/manual/features/encodings/encodings.rst
+
+
``re2c`` supports the following encodings: ASCII (default), EBCDIC (``-e``),
UCS-2 (``-w``), UTF-16 (``-x``), UTF-32 (``-u``) and UTF-8 (``-8``).
See also inplace configuration ``re2c:flags``.
-The following concepts should be clarified when talking about encoding.
-Code point is an abstract number, which represents single encoding
-symbol. Code unit is the smallest unit of memory, which is used in the
+The following concepts should be clarified when talking about encodings.
+A *code point* is an abstract number that represents a single symbol.
+A *code unit* is the smallest unit of memory, which is used in the
encoded text (it corresponds to one character in the input stream). One
-or more code units can be needed to represent a single code point,
-depending on the encoding. In fixed-length encoding, each code point
-is represented with equal number of code units. In variable-length
-encoding, different code points can be represented with different number
+or more code units may be needed to represent a single code point,
+depending on the encoding. In a *fixed-length* encoding, each code point
+is represented with an equal number of code units. In *variable-length*
+encodings, different code points can be represented with different number
of code units.
-ASCII
- is a fixed-length encoding. Its code space includes 0x100
- code points, from 0 to 0xFF. One code point is represented with exactly one
- 1-byte code unit, which has the same value as the code point. Size of
+* ASCII is a fixed-length encoding. Its code space includes 0x100
+ code points, from 0 to 0xFF. A code point is represented with exactly one
+ 1-byte code unit, which has the same value as the code point. The size of
``YYCTYPE`` must be 1 byte.
-EBCDIC
- is a fixed-length encoding. Its code space includes 0x100
- code points, from 0 to 0xFF. One code point is represented with exactly
- one 1-byte code unit, which has the same value as the code point. Size
+* EBCDIC is a fixed-length encoding. Its code space includes 0x100
+ code points, from 0 to 0xFF. A code point is represented with exactly
+ one 1-byte code unit, which has the same value as the code point. The size
of ``YYCTYPE`` must be 1 byte.
-UCS-2
- is a fixed-length encoding. Its code space includes 0x10000
+* UCS-2 is a fixed-length encoding. Its code space includes 0x10000
code points, from 0 to 0xFFFF. One code point is represented with
exactly one 2-byte code unit, which has the same value as the code
- point. Size of ``YYCTYPE`` must be 2 bytes.
+ point. The size of ``YYCTYPE`` must be 2 bytes.
-UTF-16
- is a variable-length encoding. Its code space includes all
+* UTF-16 is a variable-length encoding. Its code space includes all
Unicode code points, from 0 to 0xD7FF and from 0xE000 to 0x10FFFF. One
- code point is represented with one or two 2-byte code units. Size of
+ code point is represented with one or two 2-byte code units. The size of
``YYCTYPE`` must be 2 bytes.
-UTF-32
- is a fixed-length encoding. Its code space includes all
+* UTF-32 is a fixed-length encoding. Its code space includes all
Unicode code points, from 0 to 0xD7FF and from 0xE000 to 0x10FFFF. One
- code point is represented with exactly one 4-byte code unit. Size of
+ code point is represented with exactly one 4-byte code unit. The size of
``YYCTYPE`` must be 4 bytes.
-UTF-8
- is a variable-length encoding. Its code space includes all
+* UTF-8 is a variable-length encoding. Its code space includes all
Unicode code points, from 0 to 0xD7FF and from 0xE000 to 0x10FFFF. One
- code point is represented with sequence of one, two, three or four
+ code point is represented with sequence of one, two, three, or four
1-byte code units. Size of ``YYCTYPE`` must be 1 byte.
In Unicode, values from range 0xD800 to 0xDFFF (surrogates) are not
-valid Unicode code points, any encoded sequence of code units, that
+valid Unicode code points. Any encoded sequence of code units that
would map to Unicode code points in the range 0xD800-0xDFFF, is
ill-formed. The user can control how ``re2c`` treats such ill-formed
-sequences with ``--encoding-policy <policy>`` flag (see ``OPTIONS``
-for full explanation).
-
-For some encodings, there are code units, that never occur in valid
-encoded stream (e.g. 0xFF byte in UTF-8). If the generated scanner must
-check for invalid input, the only true way to do so is to use default
-rule ``*``. Note, that full range rule ``[^]`` won't catch invalid code units when variable-length encoding is used
-(``[^]`` means "all valid code points", while default rule ``*`` means "all possible code units").
+sequences with the ``--encoding-policy <policy>`` flag.
+For some encodings, there are code units that never occur in a valid
+encoded stream (e.g., 0xFF byte in UTF-8). If the generated scanner must
+check for invalid input, the only correct way to do so is to use the default
+rule (``*``). Note that the full range rule (``[^]``) won't catch invalid code units when a variable-length encoding is used
+(``[^]`` means "any valid code point", whereas the default rule (``*``) means "any possible code unit").
GENERIC INPUT API
-----------------
-``re2c`` usually operates on input using pointer-like primitives
-``YYCURSOR``, ``YYMARKER``, ``YYCTXMARKER`` and ``YYLIMIT``.
+.. ./gh-pages-gen/src/manual/features/generic_api/generic_api.rst
+
+``re2c`` usually operates on input with pointer-like primitives
+``YYCURSOR``, ``YYMARKER``, ``YYCTXMARKER``, and ``YYLIMIT``.
-Generic input API (enabled with ``--input custom`` switch) allows one to
-customize input operations. In this mode, ``re2c`` will express all
+The generic input API (enabled with the ``--input custom`` switch) allows
+customizing input operations. In this mode, ``re2c`` will express all
operations on input in terms of the following primitives:
+---------------------+-----------------------------------------------------+
| ``YYPEEK ()`` | get current input character |
+---------------------+-----------------------------------------------------+
- | ``YYSKIP ()`` | advance to the next character |
+ | ``YYSKIP ()`` | advance to next character |
+---------------------+-----------------------------------------------------+
- | ``YYBACKUP ()`` | backup current input position |
+ | ``YYBACKUP ()`` | back up current input position |
+---------------------+-----------------------------------------------------+
- | ``YYBACKUPCTX ()`` | backup current input position for trailing context |
+ | ``YYBACKUPCTX ()`` | back up current input position for trailing context |
+---------------------+-----------------------------------------------------+
| ``YYRESTORE ()`` | restore current input position |
+---------------------+-----------------------------------------------------+
SEE ALSO
--------
-You can find more information about ``re2c`` on the website: http://re2c.org.
+You can find more information about ``re2c`` at: http://re2c.org.
See also: flex(1), lex(1), quex (http://quex.sourceforge.net).