Compare commits

..
96 Commits
Author SHA1 Message Date
Ulya Trofimovich 9682dcd2b2 Github Actions: try 'oracle-openjdk' as 'redhat' has no macOS support. 2026-09-06 22:07:26 +01:00
Ulya Trofimovich 745a042652 Github Actions: also fix JDK version.
Pick the most recent one supported by 'redhat' distribution: 21.
2026-09-06 21:49:30 +01:00
Ulya Trofimovich b1720e831c Github Actions: fix infra error with setup-java@v6.
Pick 'redhat' distribution that packages OpenJDK, as the previously used
'adopt' distribution is no longer supported with setup-java@v6.
2026-09-06 21:44:31 +01:00
dependabot[bot] 1022a1cb0f Actions(deps): Bump actions/setup-java from 5 to 6
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 5 to 6.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-31 21:03:12 +01:00
Ulya Trofimovich e485c5d572 Release 4.6. 2026-08-29 22:26:02 +01:00
Ulya Trofimovich 957bc5359b Update CHANGELOG for release 4.6. 2026-08-29 22:15:34 +01:00
Ulya Trofimovich c117b7d1c9 Revert "Avoid new features added in 4.0 in C/C++ examples."
This reverts commit 5cea17c8fe.

Reason for revert: enough time has passed and most distributions have
updated to re2c version 4.0 or higher.

This fixes bug #507 "Update C/C++ examples".
2026-08-29 21:20:36 +01:00
Chun Pong Lam bda3544af9 Add Zig computed-continue optimization 2026-08-26 14:46:23 +01:00
dependabot[bot] dcc7411099 Actions(deps): Bump actions/setup-python from 6 to 7
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6 to 7.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-20 19:47:54 +01:00
94xhn 9baaabbf4a Fix negative char2class[] index on high-byte input in libre2c DFA matchers
lib/regexec_dfa.cc (regexec_dfa(), regparse_dfa()) and
lib/regexec_dfa_multipass.cc (forward_pass(), shared by
regexec_dfa_multipass<>, regparse_dfa_multipass<>, and
regtstring_dfa_multipass<>) read the next input character as
`*p++` into a plain `int32_t`/`chr`, then use it directly to index
`preg->char2class[]`. On platforms where `char` is signed (the
default for x86/x64), any input byte >= 0x80 sign-extends to a
negative value, so `char2class[c]` reads before the start of the
257-element `size_t` array allocated in regcomp() -- an
out-of-bounds heap read (observed to segfault in a minimal
regcomp()/regexec() reproduction with a high-byte input string).

Fix by reading the byte through `static_cast<uint8_t>(...)` before
using it as an index, matching the pattern already used for the
same purpose in the NFA matchers (regexec_nfa_leftmost.cc,
regexec_nfa_leftmost_trie.cc, regexec_nfa_posix.cc,
regexec_nfa_posix_trie.cc). The `== 0` end-of-input check is
unaffected since 0 is unchanged by the cast.

Verified: rebuilt libre2c (RE2C_BUILD_LIBS=ON) and confirmed
test_libre2c passes before and after the change; a targeted
regcomp()/regexec() check over all 254 non-newline byte values
0x01-0xFF segfaults on the pre-fix code and passes cleanly after
the fix.
2026-07-19 22:51:50 +01:00
dependabot[bot] f1a46ca73a Actions(deps): Bump actions/cache from 5 to 6
Bumps [actions/cache](https://github.com/actions/cache) from 5 to 6.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-29 21:09:51 +01:00
dependabot[bot] fccdffc979 Actions(deps): Bump actions/checkout from 6 to 7
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-24 21:49:44 +01:00
Ulya Trofimovich ae610e4ecf CMakePresets.json: update VS version.
The former VS 17 2022 version is no longer supported by Github Actions.
2026-06-23 21:17:58 +01:00
Ryan Carsten Schmidt 86137ce914 Use std::max_align_t instead of max_align_t.
Fixes build with old versions of clang.
2026-04-24 21:26:36 +01:00
Ulya Trofimovich c028cdd42b TDFA paper: apply corrections by Lisa Felidae. 2026-03-29 22:09:29 +01:00
Ulya Trofimovich 8a44906f5c Release 4.5.1. 2026-03-27 21:29:04 +00:00
Ulya Trofimovich 3122b9a415 Update CHANGELOG for release 4.5.1. 2026-03-27 21:09:25 +00:00
Ulya Trofimovich 2ab394e9d5 Docs: mention the new include files for Unicode blocks and properties. 2026-03-27 21:06:50 +00:00
Ulya Trofimovich e63ad223f5 Add missing include files to the distribution.
This fixes #573.
2026-03-27 21:01:55 +00:00
Ulya Trofimovich 3e3b91d75a Release 4.5. 2026-03-23 20:55:16 +00:00
Ulya Trofimovich 7059b54eb9 Update CHANGELOG for release 4.5. 2026-03-22 22:39:16 +00:00
Ulya Trofimovich c88a723fc4 Remove obsolete Unicode files generator. 2026-03-22 22:22:51 +00:00
Ulya Trofimovich 44d56c2804 Implement Unicode case mapping for case-insensitive string literals.
Do this for all Unicode encodings (UTF8, UTF16 and UTF32), and also for UCS2.

This addresses bug #235 "Unicode character classes".
2026-03-22 22:22:51 +00:00
Ulya Trofimovich 4685c639cd Clean up Unicode generator using tags instead of blocks. 2026-03-22 22:22:51 +00:00
Ulya Trofimovich 6a71463d6d Add derived Unicode properties to include/unicode_properties.re. 2026-03-22 22:22:51 +00:00
Ulya Trofimovich 79596e186d Generate include file for Unicode properties.
This partially addresses bug #235 "Unicode character classes".
2026-03-22 22:22:51 +00:00
Ulya Trofimovich 94d1ceb2e9 Update Unicode files to the latest standard. 2026-03-22 22:22:51 +00:00
Ulya Trofimovich e4ba9a90b2 Remove Unicode category tests for encoding policies "fail" and "substitute".
They mostly duplicate the "ignore" policy (except for the categories that
include surrogates). These policies are also covered by the Unicode block tests.
2026-03-22 22:22:50 +00:00
Ulya Trofimovich fce0e9cbd1 Implement generation of Unicode categories tests in the new generator. 2026-03-22 22:22:50 +00:00
Ulya Trofimovich 8fcbced4e4 Clean up Unicode generator code (split large functions). 2026-03-22 22:22:50 +00:00
Ulya Trofimovich 92a98bcf1e Implement generation of Unicode blocks tests in the new generator.
Tests have changed due to the changes in the Unicode standard - the old test
were generated using Haskell "Charset" library, which supports unknown version
of Blocks.txt (none of the existing version matches exactly, but Unicode 4.0 is
somewhat close). There are also other changes in the tests, mostly
simplification and cleanup of the generated code.
2026-03-22 22:22:50 +00:00
Ulya Trofimovich a76b9f592c Use uint16_t for UTF-16 code points in utf16::{lead,trail}_surr.
Previously uint32_t was used to avoid static_cast on 16-bit results of
arithmetic operations on 32-bit values.
2026-03-22 22:22:50 +00:00
Ulya Trofimovich c30687f0f1 Use uint8_t for UTF-8 code points in utf8::rune_to_bytes.
Previously uint32_t was used to avoid static_cast on 8-bit results of
arithmetic operations on 32-bit values.
2026-03-22 22:22:50 +00:00
Ulya Trofimovich dd05aab240 Implement new generator for unicode_blocks.re.
The new generator is based on the official Blocks.txt file from the unicode.org
website. The generated result has changed; it's unclear why some of the blocks
are missing in the Haskell "Charset" library - most likely the library was not
updated for Unicode 15.1.0 (although the categories' definitions correspond to
Unicode 15.1.0).

This partially addresses bug #235 "Unicode character classes".
2026-03-22 22:22:50 +00:00
Ulya Trofimovich 5b0e960177 Add Unicode include file unicode_blocks.re.
Don't use it in auto generated tests, because that creates a problem with
include paths: they are relative to the test directory, which makes the
error messages different based on the build directory (so the tests fail).

Use the old generator based on haskell "Charset" library in order to avoid
changes in the generated code - the library has some discrepancies with
https://unicode.org/Public/15.1.0/ucd/Blocks.txt.

Update test results - the changes have been verified with
test/__run_unicode_tests.sh.

This partially addresses bug #235 "Unicode character classes".
2026-03-22 22:22:50 +00:00
Ulya Trofimovich 04e7048069 Implement new generator for unicode_categories.re.
The new generator is based on the official UnicodeData.txt file from the
unicode.org website. After some experimentation, I found that the the
Unicode standard supported by the previously used Haskell "Charset" library
is 15.1.0, so this is the version used in the new generator. The generated
include file unicode_categories.re is identical to the old one, which
verifies correctness of the new generator.

This partially addresses bug #235 "Unicode character classes".
2026-03-22 22:22:50 +00:00
Ulya Trofimovich a92dad12d8 Render characters compactly in Unicode header and tests.
Previously edge cases like 0xFF were rendered as \u0ff rather than \xff.

The difference in the generated files was verified with:
  `git diff --word-diff=color --word-diff-regex='-?\\[a-zA-Z0-9]+'`
2026-03-22 22:22:50 +00:00
Ulya Trofimovich 0011cab9f9 Render one-character ranges compactly in Unicode header and tests.
Previously even if lower and upper characters were the same, the range
would still be rendered with a dash rather than a single character.
This commit removes useless duplication.

The difference in the generated files was verified with:
  `git diff --word-diff=color --word-diff-regex='-?\\[a-zA-Z0-9]+'`
2026-03-22 22:22:50 +00:00
Ulya Trofimovich f1694c513f Regenerate Unicode tests and include header to support a newer standard.
Regenerate files using haskell script test/encodings/unicode_groups.hs
that is based on Data.Charset library (charser-0.3.12 package). The
script generates tests in test/unicode directory inplace and include
file unicode_categories.re.inc that needs to be copied to
include/unicode_categories.re.

Update test results. As there are substantial changes in the standard,
updates are also nontrivial. They have been verified with
test/__run_unicode_tests.sh.

The example for C was werified with examples/c/__run_all.sh scripts.
2026-03-22 22:22:50 +00:00
dependabot[bot] 55802e3b40 Actions(deps): Bump actions/upload-artifact from 6 to 7
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-02 11:13:01 +00:00
Ulya Trofimovich 18fc5091b9 Add tests for #571. 2026-02-03 21:48:21 +00:00
Ulya Trofimovich febeb97793 Fix null pointer dereference when actions are used without rules.
Null pointer dereference happened because the root TNFA state was null:
there were no rules for a block, but determinization still happened.

In this case re2c should emit an error and never even attempt
determinization. It was properly handled for blocks with start
conditions, but not for normal blocks.

This addresses #571 "[Bug] Segmentation Fault (NULL Dereference) in
re2c::closure_leftmost_dfs during determinization".
2026-02-03 21:33:11 +00:00
Ulya Trofimovich 04f1424210 TDFA paper: apply corrections by https://github.com/Raekye. 2026-01-16 21:50:29 +00:00
Ulya Trofimovich 1f8d826558 TDFA paper: apply corrections by Lisa Felidae. 2026-01-16 21:50:29 +00:00
Ulya Trofimovich 1dc02f7b70 Dot: use "dashed" style for non-consuming states.
This addresses bug #569 "Invalid DFA in -D output".
2025-12-28 14:12:10 +00:00
Gui Andrade 37350f906c [re2c.bzl] Always pass --no-generation-date
This prevents non-deterministic file generation which can cause a lot of issues in Bazel.
2025-12-23 21:00:53 +00:00
Ulya Trofimovich 8c758c7649 Release 4.4. 2025-12-20 20:36:43 +00:00
Ulya Trofimovich d46322fb89 Update CHANGELOG for release 4.4. 2025-12-20 13:14:52 +00:00
Ulya Trofimovich 5811f5ad65 Docs: add description of YYEND, code:yyend and .yyfill.enable. 2025-12-17 22:56:50 +00:00
Ulya Trofimovich ee0b1f6daf Docs: regenerate following recent changes in examples. 2025-12-17 21:53:03 +00:00
Ulya Trofimovich 82915e38ba Add tests for generalized $.
Note: for Haskell and monadic lexers in general I considered adding `yyend`
variable in order to allow monadic YYEND (similar to the existing `yyfill`
variable). However, this is not yet useful even for Haskell, because it's always
easy to store the end in a record field and define YYEND as a simple non-monadic
comparison expression. It won't be late to add `yyend` variable later in a
backwards compatible way (if the variable is empty, generate code the old way,
otherwise do it the new way), therefore I decided to postpone `yyend`addition
until such time when it's needed.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 67f50f6907 Allow tags after $ in regular expressions.
This is necessary in order to accommodate negative tags, which are added at the
end of the other alternative (the one that doesn't have tags). During TNFA
construction $ is moved past negative tags and placed immediately before the
final TNFA state. This ensures that there are no tags on the $-transition and we
don't have to append tag operations to incoming transitions when getting rid of
the $-transitions in TDFA.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich bc5c3022d1 Rework detection of shadowed end-of-input rules.
Do it right after TDFA construction. This is only strictly necessary for
self-shadowed rules, but it's better to handle all end-of-input rules
together (especially since the previous analysis was still a hack in
the reversed-TDFA structure).
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 827682202e Fix handling of self-shadowed end-of-input rules.
Also, add tests for generalized end-of-input symbol $ and tags.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 6fcfa14e15 Fix YYEND generation for "bounds checks with padding" method.
Generate YYEND before YYFILL. This order is makes sense because YYEND should be
faster than YYFILL. In fact, it is the only possible order, as YYFILL may not
return if it's impossible to supply enough input characters.

Don't generate YYEND on transition in the case of "sentinel with bounds checks"
method; instead, generate it in state. This doesn't make any difference on the
tests because YYEND is only needed in the "end" states that have a single
transition.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 0b5185c03a Allow $ to be used with any end-of-input handling method.
Prevously end-of-input symbol $ was only allowed with "sentinel with
bounds check" method (when `re2c:eof` configuration is set to a
nonnegative value). This commit removes the above restriction and
enables YYEND checks for all end-of-input handling methods. Code
generation is not quite right yet, as in some of the cases YYEND checks
are emitted after YYFILL, while they should go before it.

Internally the main challengege was adding $-transitions in TDFA for all
end-of-input handling methods, and to hide them when necessary depending
on the method. E.g. -Wunreachable-rules analysis must ignore them except
for the $-final states, unless "sentinel with bounds checks" method is
used.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 07d6f5f7f5 Initial implementation of YYEND check.
For the moment, YYEND is only supported for the "bounds checks with sentinel"
end-of-input handling method (the case of `re2c:eof` configuration). In this
case states that have transitions on symbos do not need YYEND check, as they
have the sentinel transition with YYLESSTHAN / YYFILL pair.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich ab2d4b2504 Change default implementation of YYEND to be like YYLESSTHAN.
Namely, use `YYLIMIT <= YYCURSOR` rather than `YYLIMIT == YYCURSOR`.

The goal is to bridge the gap between YYEND and YYLESSTHAN in the case
of `re2c:eof`. $-final states that have outgoing transitions defer the
end of input check until matching `re2c:eof` symbol range on transition
(and then use YYLESSTHAN in the same way as non-$-final state would do).
But $-final states that are terminal (have no outgoing transitions on
symbols) use YYEND.

We can only bridge this gap in simple / record (not generic) API, and
only if YYFILL is disabled. Otherwise it has to be YYEND and YYLESSTHAN
as macros, and the distinction remains.

This commit does not compromise correctness of the generated code, as
YYCURSOR cannot read past YYLIMIT in a correct lexer, so if it was
correct before this commit it will be as correct after it.
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 299bfc7fe0 Add a new API primitive YYEND.
Also, add the corresponding syntax file configuration `code:yyend` and
syntax file conditional `.yyfill.enable`.

The new API primitive will be used in the implementation of generalized
$ (the end of input symbol). If YYFILL is disabled, and the API used is
either simple or record (not generic API), then YYEND defaults to a
comparison `YYCURSOR == YYLIMIT`, otherwise it remains a macro to be
defined by the user.

We don't use a combination of YYLESSTHAN and YYFILL instead of the new
primitive for a number of reasons:

  - Using YYEND allows us to unify all codegen cases instead of having
    many different implementations based on YYFILL, storable state,
    generic API, etc.

  - Involving YYFILL would add runtime overhead: a possible function
    call instead of a simple inplace check, useless reiteration via
    YYFILL label (which is currently not even generated in these states)
2025-12-17 21:44:14 +00:00
Ulya Trofimovich 2ad0561e4f Move re2c:yyfill config in syntax files closer to the yyfill group. 2025-12-17 21:44:14 +00:00
Ulya Trofimovich 59677b5eb4 Change precedence for conflicting end of input rules.
This change breaks backwards compatibility. This is intentional, following
a period when -Wdeprecate-eof-rule has been a warning by default, now the
default is an error (-Werror-deprecate-eof-rule).

There are code generation changes: end of input rule is now handled as a
normal rue with positional precedence / inheritance order (it is no longer
a special rule like the default rule *). The changes in the code can be
observed with -Wno-error-deprecate-eof-rule (applied to the tests).
2025-12-17 21:44:14 +00:00
dependabot[bot] 82bfcce637 Actions(deps): Bump actions/cache from 4 to 5
Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-15 20:52:09 +00:00
dependabot[bot] 6eb9718a67 Actions(deps): Bump actions/upload-artifact from 5 to 6
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-15 09:54:01 +00:00
Ulya Trofimovich 5513aff4c0 Revert "Go backend: add test for signed YYCTYPE."
This reverts commit b0d740994c.

Reason for revert: don't keep signed YYCTYPE examples for languages
that don't allow the user to do the incorrect thing (Go, Swift forbid
comparison of signed 8-bit type to literals that overflow it, like 0xFF;
Python, JS, OCaml don't even have a signed 8-bit type).
2025-12-09 21:55:02 +00:00
Ulya Trofimovich 43c7512c31 V backend: add test for signed YYCTYPE.
There's no need to fix examples, as they use `u8` and `u32`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-08 21:40:40 +00:00
Ulya Trofimovich 28cca31af9 V backend: more updates in the examples/tests for the new version of V. 2025-12-08 21:21:11 +00:00
Ulya Trofimovich e98dbd359a V backend: specify type in variable initializer.
The code without exact types in variable initializers used to compile
in older versions of V, but not anymore.
2025-12-08 20:39:53 +00:00
Ulya Trofimovich eece38b1e6 Zig backend: add test for signed YYCTYPE.
There's no need to fix examples, as they use `u8` and `u32`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-07 13:51:57 +00:00
Ulya Trofimovich 7553c68cb4 Zig backend: port one remaining test to ZIg 0.15. 2025-12-07 13:38:06 +00:00
Ulya Trofimovich 69ffc41706 Zig backend: port examples to Zig 0.15.
This fixes bug #565 "Migrate Zig examples to Zig 0.15".
2025-12-06 22:48:16 +00:00
Ulya Trofimovich 1a26160b69 Java backend: make YYCTYPE/YYPEEK work correctly with signed bytes.
Use `int` instead of `byte` for `YYCTYPE`, as `byte` is signed and therefore
incapable of holding the full range of literals generated by re2c (e.g. 0xFF).

use `Byte.toUnsignedInt` in YYPEEK in order to convert correctly from signed
bytes to `yych` of type `int`. Add a test that demonstrates the need for this.

Using `char` is fine, as it is 2-byte in Java and thus capable of holding
ASCII and UTF-8 range used in the examples.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-03 22:17:28 +00:00
Ulya Trofimovich 0b7572c30d Haskell backend: use unsigned YYCTYPE in examples. Add a test.
Only one example required fixing `Int` -> `Word`, others use `Word8`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-02 22:14:51 +00:00
Ulya Trofimovich 5393573711 Rust backend: add test for signed YYCTYPE.
The generated code compiles only with `#[allow(overflowing_literals)]`,
and it requires `re2c:yych:conversion = 1`.

There's no need to fix examples, as they use `u8` and `u32`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-02 21:32:45 +00:00
Ulya Trofimovich b0d740994c Go backend: add test for signed YYCTYPE.
The generated code for the test does not compile - Go rejects it:
    signed_yyctype.go:34:9: cannot use yyinput[yycursor] (value of type byte)
                            as int8 value in assignment
    signed_yyctype.go:35:14: 0xFF (untyped int constant 255) overflows int8

There's no need to fix examples, as they use `byte` (which is unsigned
8-bit type) or `uint32`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-02 21:28:17 +00:00
Ulya Trofimovich e2ee1bfa9d D backend: add test for signed YYCTYPE.
There's no need to fix examples, as they use `char` (which is unsigned
8-bit type according to https://dlang.org/spec/type.html#basic-data-types)
or `uint8_t`/`uint32_t`.

This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-12-02 21:23:30 +00:00
Ulya Trofimovich 600717ad6a Fix CHANGELOG formatting. 2025-12-01 22:59:46 +00:00
Ulya Trofimovich af13e1d896 Release 4.3.1. 2025-12-01 22:53:31 +00:00
Ulya Trofimovich f760dccc55 Update CHANGELOG for release 4.3.1. 2025-12-01 22:28:01 +00:00
Ulya Trofimovich 9d76662c22 Regenerate docs. 2025-12-01 22:15:42 +00:00
Ulya Trofimovich 5ed46a79a1 release.sh: Add option --ignore-examples.
This is needed as a last resort to allow releasing re2c on a system where some
of the language toolchains are broken (as it becomes excessively hard to keep
them all working and to keep the examples up to date for languages that don't
care about backwards compatibility, such as Zig).
2025-12-01 22:13:08 +00:00
Ulya Trofimovich dcf934fb33 Allow tags after $ in regular expressions.
This addresses bug #564 "End of input ($) rule deemed invalid when Posix
captures enabled". It is needed t allow implicit capture tags after $ in a
regexp, which was inadvertently forbidden in release 4.3.

It will also be necessary in order to accommodate negative tags added at the
end of alternatives that don't have tags.

During TNFA construction $ is moved past negative tags and placed immediately
before the final TNFA state. This ensures that there are no tags on the
$-transition and we don't have to append tag operations to incoming transitions
when getting rid of the $-transitions in TDFA.
2025-12-01 21:07:53 +00:00
Ulya Trofimovich 55487d4ab8 Fix YYCTYPE to be unsigned in the examples for C/C++. Add a test.
This addresses bug #561 "Incorrectness with ASCII signedness and range
(in C/C++)".
2025-11-26 22:47:09 +00:00
dependabot[bot] 59de285996 Actions(deps): Bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-24 10:57:38 +00:00
Ulya Trofimovich da7d8fe924 Use ptrdiff_t instead of non-standard ssize_t.
This fixes the build on windows.
2025-11-20 22:04:41 +00:00
Ulya Trofimovich 325db7adfd Rework handling of conditions that have no rules.
This addresses bug #560 'Illformed C/C++ code due to missing "final"
conditions in generated enumeration'.

After much discussion (see the bug) it was decided that aborting in the initial
state dispatch for conditions without rules doesn't play well with the existing
configuration `re2c:cond:abort`. Some language backends (notably, C/C++ backend)
have it disabled by default, so the general-case default (no abort) would be at
odds with the special-case default for empty conditionss (abort).

This commit takes a different approach: always raise an error on conditions
without rules, but before doing that check if there are any `<*>` rules that
can be merged to them.
2025-11-20 21:21:25 +00:00
Ulya Trofimovich ccb1d45431 Revert "Always explicitly initialize condition enum members."
This reverts commit 34f6e5269f.

Reason for revert: to make sure we don't break existing code, e.g. if
the numeric constants are incompatible with the user-defined enum type.
2025-11-17 22:48:43 +00:00
Ulya Trofimovich deaabdd4ca Fix check for conditions with the same name in goto/label mode.
This check should not compare condition numbers in goto/label mode,
as conditions get renumbered anyway. Previously it used to work because
all numbers were set to zero in goto/label mode, but it was broken by
a recent commit 8a4e4ebd54.

This addresses bug #560 'Illformed C/C++ code due to missing "final"
conditions in generated enumeration'.
2025-11-15 22:37:48 +00:00
Ulya Trofimovich 550451d8b4 Check for conditions that have no rules.
Check that all conditions referenced by `=>` and `:=>` exist (have rules).
In the case of `:=>`, raise an error on non-existent conditions (because
the autogenerated semantic action would go to a nonexistent condition start
label). In the case of `=>` add the nonexistent condition to condition enum
(the user may want to set condition variable and return from the lexer to
handle it in user code), but make the initial dispatch abort on it (in case
it was a typo).

This addresses bug #560 'Illformed C/C++ code due to missing "final"
conditions in generated enumeration'.
2025-11-13 22:51:24 +00:00
Ulya Trofimovich 34f6e5269f Always explicitly initialize condition enum members.
Historically in goto/label mode conditions weren't assigned explicit
numeric identifiers - the numbers were assigned implicitly based on
position in the condition enumeration. This affected language backends
for C/C++, D, Go, V (those supporting goto/label model).

In loop/switch and rec/func modes condition numbers correspond to TDFA
state indices, so they are not consecutive and require explicit
initializers.

This commit makes the enumeration always have explcit initializers
regardless of the code model. The generated initializers are backwards
compatible (identical to the implicitly assigned ones).
2025-11-12 22:32:02 +00:00
Ulya Trofimovich 8a4e4ebd54 Unify handling of numeric condition identifiers across code models.
Historically in goto/label mode conditions aren't assigned explicit
numeric identifiers - the numbers are assigned implicitly based on
position in the condition enumeration. However, this correlation is
erroneous: there's no guarantee that the languages that support `goto`
also have enums with implicit numbers.

For now, keep the erroneous correlation (to avoid changing the generated
code), but move it from re2c code to syntax file definitions.
2025-11-12 21:10:34 +00:00
dependabot[bot] 79831797ff Actions(deps): Bump actions/upload-artifact from 4 to 5
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-27 12:32:46 +00:00
dependabot[bot] 0bfddb867b Actions(deps): Bump actions/setup-python from 5 to 6
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5 to 6.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-08 11:35:27 +01:00
Alexey Abramov 7563ecaec0 Use maximum alignment to ensure compatibility across all architectures. 2025-08-31 12:22:56 +01:00
dependabot[bot] e74cef8655 Actions(deps): Bump actions/setup-java from 4 to 5
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4 to 5.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-25 21:00:13 +01:00
dependabot[bot] 26f01b60ee Actions(deps): Bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 15:46:44 +01:00
Stefan A. Haubenthal 6662452bde Fixed minor typos 2025-08-04 06:19:13 +01:00
1278 changed files with 297849 additions and 369586 deletions
+7 -5
View File
@@ -33,18 +33,20 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: '3.8'
- name: Setup Java
uses: actions/setup-java@v4
uses: actions/setup-java@v6
with:
distribution: 'adopt'
java-version: '24'
# One of the distributions that packages OpenJDK, see
# https://github.com/marketplace/actions/setup-java-jdk#supported-distributions
distribution: 'oracle-openjdk'
java-version: '26'
- name: Setup Common Prerequisites
run: |
+4 -4
View File
@@ -36,11 +36,11 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup apt cache (Linux)
if: startsWith(runner.os, 'Linux')
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: /var/cache/apt
key: ${{ runner.os }}-apt-cache-${{ matrix.os }}-${{ github.sha }}
@@ -69,7 +69,7 @@ jobs:
esac
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: 3.x
architecture: x64
@@ -155,7 +155,7 @@ jobs:
- name: Archive test artifacts
# Run this step only if tests failed (otherwise there is nothing to upload).
if: failure()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
# To ensure that jobs don't overwrite existing artifacts,
# use a different name per job.
+5 -5
View File
@@ -62,11 +62,11 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Setup chocolatey Cache (Windows)
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-chocolatey-${{ matrix.os }}-${{ github.sha }}
@@ -76,7 +76,7 @@ jobs:
- name: Setup apt cache (Linux)
if: startsWith(runner.os, 'Linux')
uses: actions/cache@v4
uses: actions/cache@v6
with:
path: /var/cache/apt
key: ${{ runner.os }}-apt-cache-${{ matrix.os }}-${{ github.sha }}
@@ -105,7 +105,7 @@ jobs:
esac
- name: Setup Python
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: 3.x
architecture: x64
@@ -165,7 +165,7 @@ jobs:
- name: Archive test artifacts
# Run this step only if tests failed (otherwise there is nothing to upload).
if: failure()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
# To ensure that jobs don't overwrite existing artifacts,
# use a different name per job.
+63
View File
@@ -2,6 +2,69 @@ Changelog
=========
4.6 (2026-08-29)
~~~~~~~~~~~~~~~~
- Added support for Zig labeled continue optimization.
(`#580 <https://github.com/skvadrik/re2c/pull/580>`_).
- Updated C/C++ examples to use re2c features available in version 4.0 or higher.
4.5.1 (2026-03-27)
~~~~~~~~~~~~~~~~~~
- Added missing include files to the distribution
(`#573 <https://github.com/skvadrik/re2c/issues/573>`_).
- Updated the documentation to mention the new include files.
4.5 (2026-03-23)
~~~~~~~~~~~~~~~~
- Migrated include files to Unicode 17.0.0 standard.
- Added Unicode include files:
+ `include/unicode_blocks.re <https://github.com/skvadrik/re2c/blob/master/include/unicode_blocks.re>`_
+ `include/unicode_properties.re <https://github.com/skvadrik/re2c/blob/master/include/unicode_properties.re>`_
- Implemented Unicode case mapping for case-insensitive string literals
(`#235 <https://github.com/skvadrik/re2c/issues/235>`_).
- Fixed `#571 <https://github.com/skvadrik/re2c/issues/571>`_
(segmentation fault on erroneous input during determinization).
- Updated paper `A closer look at TDFA <https://arxiv.org/abs/2206.01398>`_
(applied corrections by Lisa Felidae).
4.4 (2025-12-20)
~~~~~~~~~~~~~~~~
- Added generalized end-of-input symbol ``$``
(`#525 <https://github.com/skvadrik/re2c/issues/525>`_).
This change may break old code with conflicitng end-of-input rules,
as they now have position-based precedence. The broken cases were
reported with ``-Wdeprecated-eof-rule`` since version 4.3.
4.3.1 (2025-12-01)
~~~~~~~~~~~~~~~~~~
- Fixed bugs:
+ `#560 <https://github.com/skvadrik/re2c/issues/560>`_
(allow conditions that have no rules except for default rule)
+ `#561 <https://github.com/skvadrik/re2c/issues/561>`_
(use unsigned character type in C/C++ examples)
+ `#564 <https://github.com/skvadrik/re2c/issues/564>`_
(fix broken end of input rule $ with captures)
4.3 (2025-06-30)
~~~~~~~~~~~~~~~~
+5 -1
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(re2c VERSION 4.3 HOMEPAGE_URL "https://re2c.org/")
project(re2c VERSION 4.6 HOMEPAGE_URL "https://re2c.org/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -230,6 +230,7 @@ set(re2c_sources
src/encoding/ebcdic.cc
src/encoding/enc.cc
src/encoding/range_suffix.cc
src/encoding/unicode_casemap.cc
src/encoding/utf8.cc
src/encoding/utf16.cc
src/msg/msg.cc
@@ -470,7 +471,9 @@ if(RE2C_IS_ROOT_PROJECT)
include/syntax/swift
include/syntax/v
include/syntax/zig
include/unicode_blocks.re
include/unicode_categories.re
include/unicode_properties.re
DESTINATION "${RE2C_STDLIB_DIR}")
# rebuild all re2c sources using newly built re2c
@@ -598,6 +601,7 @@ if (RE2C_BUILD_LIBS)
src/nfa/re_to_nfa.cc
src/encoding/enc.cc
src/encoding/range_suffix.cc
src/encoding/unicode_casemap.cc
src/encoding/ebcdic.cc
src/encoding/utf16.cc
src/encoding/utf8.cc
+1 -1
View File
@@ -308,7 +308,7 @@
{
"name": "windows-config-base",
"hidden": true,
"generator": "Visual Studio 17 2022",
"generator": "Visual Studio 18 2026",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
+4 -1
View File
@@ -104,6 +104,7 @@ re2c_SRC = \
src/encoding/ebcdic.cc \
src/encoding/enc.cc \
src/encoding/range_suffix.cc \
src/encoding/unicode_casemap.cc \
src/encoding/utf8.cc \
src/encoding/utf16.cc \
src/msg/msg.cc \
@@ -628,7 +629,9 @@ dist_stdlib_DATA = \
include/syntax/swift \
include/syntax/v \
include/syntax/zig \
include/unicode_categories.re
include/unicode_blocks.re \
include/unicode_categories.re \
include/unicode_properties.re
BAZELFILES := \
BUILD.bazel \
+1
View File
@@ -99,6 +99,7 @@ libre2c_la_SRC = \
src/nfa/re_to_nfa.cc \
src/encoding/enc.cc \
src/encoding/range_suffix.cc \
src/encoding/unicode_casemap.cc \
src/encoding/ebcdic.cc \
src/encoding/utf16.cc \
src/encoding/utf8.cc \
+1 -1
View File
@@ -23,7 +23,7 @@ def _re2c_impl(ctx):
tools = [ctx.executable._re2c_tool],
inputs = ctx.files.srcs + ctx.files.data,
command = """
"{re2c}" "{src}" -o "{out}" {re2c_args} {includes}
"{re2c}" --no-generation-date "{src}" -o "{out}" {re2c_args} {includes}
""".format(
re2c = ctx.executable._re2c_tool.path,
src = srcs[0].path,
+93 -60
View File
@@ -56,11 +56,10 @@ decimal number:
// re2c $INPUT \-o $OUTPUT \-i \-\-case\-ranges
#include <assert.h>
int lex(const char *s) {
const char *YYCURSOR = s;
int lex(const char* YYCURSOR) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
[1\-9][0\-9]* { return 0; }
* { return 1; }
@@ -87,11 +86,10 @@ In the output re2c replaced the block in the middle with the generated code:
// re2c $INPUT \-o $OUTPUT \-i \-\-case\-ranges
#include <assert.h>
int lex(const char *s) {
const char *YYCURSOR = s;
int lex(const char* YYCURSOR) {
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case \(aq1\(aq ... \(aq9\(aq: goto yy2;
@@ -821,6 +819,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -931,6 +932,7 @@ This API contains primitives for generic operations:
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYEND\fP\&.
Generic API supports two styles that determine the form in which the
primitives should be defined:
.nf
@@ -962,6 +964,7 @@ API can be defined in terms of pointers \fBcursor\fP, \fBlimit\fP,
re2c:YYRESTORECTX = \(dqcursor = ctxmarker;\(dq;
re2c:YYRESTORETAG = \(dqcursor = ${tag};\(dq;
re2c:YYLESSTHAN = \(dqlimit \- cursor < @@{len}\(dq;
re2c:YYEND = \(dqlimit == cursor\(dq;
re2c:YYSTAGP = \(dq@@{tag} = cursor;\(dq;
re2c:YYSTAGN = \(dq@@{tag} = NULL;\(dq;
re2c:YYSHIFT = \(dqcursor += @@{shift};\(dq;
@@ -996,6 +999,7 @@ generic API can be defined in terms of pointers \fBcursor\fP, \fBlimit\fP,
#define YYRESTORECTX() cursor = ctxmarker
#define YYRESTORETAG(tag) cursor = tag
#define YYLESSTHAN(len) limit \- cursor < len
#define YYEND() limit == cursor
#define YYSTAGP(tag) tag = cursor
#define YYSTAGN(tag) tag = NULL
#define YYSHIFT(shift) cursor += shift
@@ -1073,6 +1077,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1256,7 +1268,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1393,6 +1405,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1730,7 +1748,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1994,12 +2012,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2237,6 +2258,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2303,6 +2328,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2338,6 +2367,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2c version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -2460,7 +2492,7 @@ static int lex(const char *YYCURSOR) {
for (;;) {
/*!re2c
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:yyfill:enable = 0;
* { return \-1; }
@@ -2516,7 +2548,7 @@ static int lex(const char *str, unsigned int len) {
for (;;) {
/*!re2c
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:yyfill:enable = 0;
re2c:eof = 0;
@@ -2588,8 +2620,8 @@ static int lex(const char *str, unsigned int len) {
loop:
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYFILL = \(dqgoto fail;\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYFILL = \(dqgoto fail;\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -2654,11 +2686,11 @@ static int lex(const char *str, unsigned int len) {
for (;;) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:api = custom;
re2c:api = generic;
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYPEEK = \(dqcur < lim ? *cur : 0\(dq; // fake null
re2c:define:YYSKIP = \(dq++cur;\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYPEEK = \(dqcur < lim ? *cur : 0\(dq; // fake null
re2c:YYSKIP = \(dq++cur;\(dq;
* { count = \-1; break; }
[\ex00] { break;; }
@@ -2813,11 +2845,11 @@ loop:
in\->tok = in\->cur;
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = in\->cur;
re2c:define:YYMARKER = in\->mar;
re2c:define:YYLIMIT = in\->lim;
re2c:define:YYFILL = \(dqfill(in) == 0\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYCURSOR = in\->cur;
re2c:YYMARKER = in\->mar;
re2c:YYLIMIT = in\->lim;
re2c:YYFILL = \(dqfill(in) == 0\(dq;
re2c:eof = 0;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -2960,10 +2992,10 @@ loop:
in\->tok = in\->cur;
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = in\->cur;
re2c:define:YYLIMIT = in\->lim;
re2c:define:YYFILL = \(dqif (fill(in, @@) != 0) return \-1;\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYCURSOR = in\->cur;
re2c:YYLIMIT = in\->lim;
re2c:YYFILL = \(dqif (fill(in, @@) != 0) return \-1;\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -3051,7 +3083,7 @@ static uint64_t parse_u32(const char *s) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
end = \(dq\ex00\(dq;
@@ -3213,9 +3245,9 @@ static uint64_t parse_u32(const char *s) {
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYGETCONDITION = \(dqc\(dq;
re2c:define:YYSETCONDITION = \(dqc = @@;\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYGETCOND = \(dqc\(dq;
re2c:YYSETCOND = \(dqc = @@;\(dq;
re2c:yyfill:enable = 0;
<*> * { return ERROR; }
@@ -3353,13 +3385,13 @@ static Status lex(State *st, unsigned int *recv) {
st\->tok = st\->cur;
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = \(dqchar\(dq;
re2c:define:YYCURSOR = \(dqst\->cur\(dq;
re2c:define:YYMARKER = \(dqst\->mar\(dq;
re2c:define:YYLIMIT = \(dqst\->lim\(dq;
re2c:define:YYGETSTATE = \(dqst\->state\(dq;
re2c:define:YYSETSTATE = \(dqst\->state = @@;\(dq;
re2c:define:YYFILL = \(dqreturn WAITING;\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYCURSOR = \(dqst\->cur\(dq;
re2c:YYMARKER = \(dqst\->mar\(dq;
re2c:YYLIMIT = \(dqst\->lim\(dq;
re2c:YYGETSTATE = \(dqst\->state\(dq;
re2c:YYSETSTATE = \(dqst\->state = @@;\(dq;
re2c:YYFILL = \(dqreturn WAITING;\(dq;
re2c:eof = 0;
packet = [a\-z]+[;];
@@ -3508,7 +3540,7 @@ static What lex(const char *s) {
const char *YYCURSOR = s, *YYMARKER;
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
!use:fish;
!use:colors;
@@ -3549,7 +3581,7 @@ int main() {
static int lex_utf8(const uint8_t *s) {
const uint8_t *YYCURSOR = s, *YYMARKER;
/*!use:re2c
re2c:define:YYCTYPE = uint8_t;
re2c:YYCTYPE = uint8_t;
re2c:encoding:utf8 = 1;
*/
}
@@ -3557,7 +3589,7 @@ static int lex_utf8(const uint8_t *s) {
static int lex_utf32(const uint32_t *s) {
const uint32_t *YYCURSOR = s, *YYMARKER;
/*!use:re2c
re2c:define:YYCTYPE = uint32_t;
re2c:YYCTYPE = uint32_t;
re2c:encoding:utf32 = 1;
*/
}
@@ -3702,7 +3734,7 @@ static int lex(const char *str, SemVer *ver) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:tags = 1;
num = [0\-9]+;
@@ -3809,11 +3841,11 @@ static bool lex(Input &in, std::vector<SemVer> &vers) {
/*!re2c
re2c:eof = 0;
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = in.cur;
re2c:define:YYMARKER = in.mar;
re2c:define:YYLIMIT = in.lim;
re2c:define:YYFILL = \(dqfill(in) == 0\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYCURSOR = in.cur;
re2c:YYMARKER = in.mar;
re2c:YYLIMIT = in.lim;
re2c:YYFILL = \(dqfill(in) == 0\(dq;
re2c:tags:expression = \(dqin.@@\(dq;
num = [0\-9]+;
@@ -3896,7 +3928,7 @@ static int lex(const char *str, SemVer *ver) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:captvars = 1;
num = [0\-9]+;
@@ -3999,11 +4031,11 @@ static bool parse(const char *str, Ver &ver) {
/*!re2c
re2c:api:style = free\-form;
re2c:define:YYCTYPE = char;
re2c:define:YYSTAGP = \(dq@@ = YYCURSOR;\(dq;
re2c:define:YYSTAGN = \(dq@@ = NULL;\(dq;
re2c:define:YYMTAGP = \(dqadd_mtag(mt, @@, YYCURSOR);\(dq;
re2c:define:YYMTAGN = \(dqadd_mtag(mt, @@, NULL);\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYSTAGP = \(dq@@ = YYCURSOR;\(dq;
re2c:YYSTAGN = \(dq@@ = NULL;\(dq;
re2c:YYMTAGP = \(dqadd_mtag(mt, @@, YYCURSOR);\(dq;
re2c:YYMTAGN = \(dqadd_mtag(mt, @@, NULL);\(dq;
re2c:yyfill:enable = 0;
re2c:tags = 1;
@@ -4075,8 +4107,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2c definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2c definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
@@ -4100,7 +4133,7 @@ Below is an example of a lexer for UTF8 encoded Unicode identifiers.
static int lex(const char *s) {
const char *YYCURSOR = s, *YYMARKER;
/*!re2c
re2c:define:YYCTYPE = \(aqunsigned char\(aq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:yyfill:enable = 0;
// Simplified \(dqUnicode Identifier and Pattern Syntax\(dq
@@ -4184,7 +4217,7 @@ float { return OK; }
Result lex(const char *s) {
const char *YYCURSOR = s, *YYMARKER;
/*!re2c
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:yyfill:enable = 0;
* { return FAIL; }
@@ -4242,8 +4275,8 @@ long lex(LexerState* st) {
/*!re2c
re2c:header = \(dqlexer/state.h\(dq;
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = \(dqst\->cur\(dq;
re2c:YYCTYPE = \(dqunsigned char\(dq;
re2c:YYCURSOR = \(dqst\->cur\(dq;
re2c:tags = 1;
re2c:tags:expression = \(dqst\->@@\(dq;
+41 -8
View File
@@ -815,6 +815,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -922,7 +925,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -991,6 +995,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1174,7 +1186,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1311,6 +1323,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1648,7 +1666,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1912,12 +1930,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2155,6 +2176,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2221,6 +2246,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2256,6 +2285,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2d version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -3965,8 +3997,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2d definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2d definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+43 -8
View File
@@ -822,6 +822,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -932,7 +935,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
Generic API supports two styles that determine the form in which the
primitives should be defined:
.nf
@@ -964,6 +968,7 @@ API can be defined in terms of integer variables \fBcursor\fP, \fBlimit\fP,
re2c:YYRESTORECTX = \(dqcursor = ctxmarker\(dq;
re2c:YYRESTORETAG = \(dqcursor = ${tag}\(dq;
re2c:YYLESSTHAN = \(dqlimit \- cursor < @@{len}\(dq;
re2c:YYEND = \(dqlimit == cursor\(dq;
re2c:YYSTAGP = \(dq@@{tag} = cursor\(dq;
re2c:YYSTAGN = \(dq@@{tag} = \-1\(dq;
re2c:YYSHIFT = \(dqcursor += @@{shift}\(dq;
@@ -997,6 +1002,7 @@ YYRESTORE := func() { cursor = marker }
YYBACKUPCTX := func() { ctxmarker = cursor }
YYRESTORECTX := func() { cursor = ctxmarker }
YYLESSTHAN := func(n int) bool { return limit\-cursor < n }
YYEND := func(n int) bool { return limit == cursor }
YYSHIFT := func(n int) { cursor += n }
.ft P
.fi
@@ -1071,6 +1077,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1254,7 +1268,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1391,6 +1405,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1728,7 +1748,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1992,12 +2012,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2235,6 +2258,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2301,6 +2328,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2336,6 +2367,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2go version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -4116,8 +4150,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2go definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2go definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+43 -10
View File
@@ -843,6 +843,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -942,7 +945,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -1011,6 +1015,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1194,7 +1206,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1331,6 +1343,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1668,7 +1686,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1932,12 +1950,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2175,6 +2196,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2241,6 +2266,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2276,6 +2305,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2hs version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -3517,9 +3549,9 @@ data State a = State {
%}
%{use
re2c:YYFN = [\(dqlex32;Maybe Int\(dq, \(dqState{..};State (Array Int Int)\(dq];
re2c:YYFN = [\(dqlex32;Maybe Int\(dq, \(dqState{..};State (Array Int Word)\(dq];
re2c:encoding:utf32 = 1;
re2c:YYCTYPE = Int;
re2c:YYCTYPE = Word;
%}
main :: IO ()
@@ -4019,8 +4051,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2hs definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2hs definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+65 -31
View File
@@ -856,6 +856,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -964,7 +967,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -1033,6 +1037,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1216,7 +1228,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1353,6 +1365,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1690,7 +1708,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1954,12 +1972,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2197,6 +2218,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2263,6 +2288,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2298,6 +2327,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2java version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -2539,10 +2571,10 @@ class Main {
/*!max:re2c*/
// Expects yymaxfill\-padded string.
static int lex(String str) {
static int lex(byte[] str) {
// Pad string with yymaxfill zeroes at the end.
byte[] yyinput = new byte[str.length() + YYMAXFILL];
System.arraycopy(str.getBytes(), 0, yyinput, 0, str.length());
byte[] yyinput = new byte[str.length + YYMAXFILL];
System.arraycopy(str, 0, yyinput, 0, str.length);
int yycursor = 0;
int yylimit = yyinput.length;
@@ -2550,15 +2582,15 @@ class Main {
loop: while (true) {
/*!re2c
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dqyyinput[yycursor]\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dqByte.toUnsignedInt(yyinput[yycursor])\(dq;
re2c:YYFILL = \(dqreturn \-1;\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
[\ex00] {
// Check that it is the sentinel, not some unexpected null.
return (yycursor \- 1 == str.length()) ? count : \-1;
return (yycursor \- 1 == str.length) ? count : \-1;
}
str { count += 1; continue loop; }
[ ]+ { continue loop; }
@@ -2568,10 +2600,10 @@ class Main {
}
public static void main(String []args) {
assert lex(\(dq\(dq) == 0;
assert lex(\(dq\(aqqu\e0tes\(aq \(aqare\(aq \(aqfine: \e\e\(aq\(aq \(dq) == 3;
assert lex(\(dq\(aqunterminated\e\e\(aq\(dq) == \-1;
assert lex(\(dq\(aqunexpected \e00 null\e\e\(aq\(dq) == \-1;
assert lex(\(dq\(dq.getBytes()) == 0;
assert lex(\(dq\(aqqu\e0tes\(aq \(aqare\(aq \(aqfine: \e\e\(aq\(aq \(dq.getBytes()) == 3;
assert lex(\(dq\(aqunterminated\e\e\(aq\(dq.getBytes()) == \-1;
assert lex(\(dq\(aqunexpected \e00 null\e\e\(aq\(dq.getBytes()) == \-1;
}
};
@@ -2606,8 +2638,9 @@ class Main {
loop: while (true) {
/*!re2c
re2c:api = generic;
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dq(yycursor < yyinput.length) ? yyinput[yycursor] : 0\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dq(yycursor < yyinput.length)\(dq
\(dq ? Byte.toUnsignedInt(yyinput[yycursor]) : 0\(dq;
re2c:YYSKIP = \(dqyycursor += 1;\(dq;
re2c:yyfill:enable = 0;
@@ -2771,8 +2804,8 @@ class Lexer {
loop: while (true) {
token = yycursor;
/*!re2c
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dqyyinput[yycursor]\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dqByte.toUnsignedInt(yyinput[yycursor])\(dq;
re2c:YYFILL = \(dqfill() == 0\(dq;
re2c:eof = 0;
@@ -2919,8 +2952,8 @@ class Lexer {
loop: while (true) {
token = yycursor;
/*!re2c
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dqyyinput[yycursor]\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dqByte.toUnsignedInt(yyinput[yycursor])\(dq;
re2c:YYFILL = \(dqif (fill(@@) != 0) { return \-2; }\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -3351,13 +3384,13 @@ class Lexer {
}
private static Status lex(State yyrecord) {
byte yych;
int yych;
loop: while (true) {
yyrecord.token = yyrecord.yycursor;
/*!re2c
re2c:api = record;
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dqyyrecord.yyinput[yyrecord.yycursor]\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dqByte.toUnsignedInt(yyrecord.yyinput[yyrecord.yycursor])\(dq;
re2c:YYFILL = \(dqreturn Status.WAITING;\(dq;
re2c:eof = 0;
@@ -3541,7 +3574,7 @@ class Main {
int yycursor = 0;
int yymarker = 0;
/*!use:re2c
re2c:YYCTYPE = \(dqint\(dq; // should be \(gabyte\(ga, but it\(aqs signed in Java
re2c:YYCTYPE = \(dqint\(dq; // Java lacks unsigned 8\-bit integer type
re2c:encoding:utf8 = 1;
*/
}
@@ -3825,8 +3858,8 @@ class Lexer {
loop: while (true) {
token = yycursor;
/*!re2c
re2c:YYCTYPE = \(dqbyte\(dq;
re2c:YYPEEK = \(dqyyinput[yycursor]\(dq;
re2c:YYCTYPE = \(dqint\(dq;
re2c:YYPEEK = \(dqByte.toUnsignedInt(yyinput[yycursor])\(dq;
re2c:YYFILL = \(dqfill() == 0\(dq;
re2c:eof = 0;
re2c:tags = 1;
@@ -3861,7 +3894,7 @@ class Lexer {
// Run the lexer.
Optional<ArrayList<SemVer>> vers = lexer.lex();
// Check resuts.
// Check results.
assert vers.isPresent() && vers.get().size() == BUFSIZE;
SemVer v = new SemVer(1, 22, 333);
for (int i = 0; i < BUFSIZE; ++i) {
@@ -4047,8 +4080,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2java definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2java definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+41 -8
View File
@@ -848,6 +848,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -956,7 +959,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -1025,6 +1029,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1208,7 +1220,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1345,6 +1357,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1682,7 +1700,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1946,12 +1964,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2189,6 +2210,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2255,6 +2280,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2290,6 +2319,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2js version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -3849,8 +3881,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2js definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2js definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+41 -8
View File
@@ -832,6 +832,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -929,7 +932,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -998,6 +1002,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1181,7 +1193,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1318,6 +1330,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1655,7 +1673,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1919,12 +1937,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2162,6 +2183,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2228,6 +2253,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2263,6 +2292,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2ocaml version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -3982,8 +4014,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2ocaml definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2ocaml definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+41 -8
View File
@@ -821,6 +821,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -929,7 +932,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -998,6 +1002,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1181,7 +1193,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1318,6 +1330,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1655,7 +1673,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1919,12 +1937,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2162,6 +2183,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2228,6 +2253,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2263,6 +2292,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2py version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -3860,8 +3892,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2py definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2py definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+42 -8
View File
@@ -836,6 +836,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -946,7 +949,8 @@ This API contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
For example, if the input is a byte slice \fBbuffer: &[u8]\fP, variables
\fBcursor\fP, \fBlimit\fP, \fBmarker\fP and \fBctxmarker\fP of type \fBusize\fP
represent input positions, and a constant \fBNONE\fP represents invalid
@@ -965,6 +969,7 @@ position, then generic API can be defined as follows:
re2c:YYRESTORECTX = \(dqcursor = ctxmarker;\(dq;
re2c:YYRESTORETAG = \(dqcursor = @@{tag};\(dq;
re2c:YYLESSTHAN = \(dqlimit \- cursor < @@{len}\(dq;
re2c:YYEND = \(dqlimit == cursor\(dq;
re2c:YYSTAGP = \(dq@@{tag} = cursor;\(dq;
re2c:YYSTAGN = \(dq@@{tag} = NONE;\(dq;
re2c:YYSHIFT = \(dqcursor = (cursor as isize + @@{shift}) as usize;\(dq;
@@ -1042,6 +1047,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1225,7 +1238,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1362,6 +1375,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1699,7 +1718,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1963,12 +1982,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2206,6 +2228,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2272,6 +2298,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2307,6 +2337,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2rust version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -4099,8 +4132,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2rust definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2rust definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+42 -8
View File
@@ -822,6 +822,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -930,7 +933,8 @@ This API contains the following primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
For example, if the input is a zero\-terminated array of bytes
\fBbuffer: [UInt8]\fP, variables \fBcursor\fP, \fBlimit\fP, \fBmarker\fP and
\fBctxmarker\fP of type \fBInt\fP represent input positions, and \fB\-1\fP
@@ -949,6 +953,7 @@ represents invalid positions, then a generic API can be defined as follows:
re2c:YYRESTORECTX = \(dqcursor = ctxmarker\(dq;
re2c:YYRESTORETAG = \(dqcursor = ${tag}\(dq;
re2c:YYLESSTHAN = \(dqlimit \- cursor < @@{len}\(dq;
re2c:YYEND = \(dqlimit == cursor\(dq;
re2c:YYSTAGP = \(dq@@{tag} = cursor\(dq;
re2c:YYSTAGN = \(dq@@{tag} = \-1\(dq;
re2c:YYSHIFT = \(dqcursor += @@{shift}\(dq;
@@ -1026,6 +1031,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1209,7 +1222,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1346,6 +1359,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1683,7 +1702,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1947,12 +1966,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2190,6 +2212,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2256,6 +2282,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2291,6 +2321,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2swift version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -4084,8 +4117,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2swift definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2swift definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+52 -18
View File
@@ -84,7 +84,7 @@ In the output re2v replaced the block in the middle with the generated code:
fn lex(yyinput string) {
mut yycursor := 0
mut yych := 0
mut yych := u8(0)
yych = yyinput[yycursor]
match yych {
0x31...0x39 { unsafe { goto yy2 } }
@@ -813,6 +813,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -921,7 +924,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -990,6 +994,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1173,7 +1185,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1310,6 +1322,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1647,7 +1665,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1911,12 +1929,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2154,6 +2175,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2220,6 +2245,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2255,6 +2284,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2v version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -2745,7 +2777,7 @@ fn main() {
}
// Run the lexer.
n := lex(mut st)
n := lex(mut &st)
if n != count { panic(\(dqexpected $count, got $n\(dq) }
// Cleanup: remove input file.
@@ -2895,7 +2927,7 @@ fn main() {
}
// Run the lexer.
n := lex(mut st)
n := lex(mut &st)
if n != count { panic(\(dqexpected $count, got $n\(dq) }
// Cleanup: remove input file.
@@ -3311,7 +3343,7 @@ fn test(expect Status, packets []string) {
mut send := 0
mut recv := 0
for {
status = lex(mut st, mut &recv)
status = lex(mut &st, mut &recv)
if status == .lex_end {
break
} else if status == .lex_waiting {
@@ -3321,7 +3353,7 @@ fn test(expect Status, packets []string) {
fw.flush()
send += 1
}
status = fill(mut st)
status = fill(mut &st)
log.debug(\(dqfilled buffer $st.yyinput, status $status\(dq)
if status != .lex_ready {
break
@@ -3770,7 +3802,7 @@ fn main() {
// Run the lexer.
expect := []SemVer{len: bufsize, init: SemVer{1, 22, 333}}
result := parse(mut st) or { panic(\(dqparse failed\(dq) }
result := parse(mut &st) or { panic(\(dqparse failed\(dq) }
if result != expect { panic(\(dqerror\(dq) }
// Cleanup: remove input file.
@@ -3873,7 +3905,7 @@ struct MtagElem {
type MtagTrie = []MtagElem
// Append a single value to an m\-tag history.
fn add_mtag(mut trie &MtagTrie, mtag int, value int) int {
fn add_mtag(mut trie MtagTrie, mtag int, value int) int {
trie = arrays.concat(trie, MtagElem{value, mtag})
return trie.len \- 1
}
@@ -3912,7 +3944,8 @@ fn s2n(s string) int { // convert pre\-parsed string to number
fn parse(yyinput string) ?[]int {
mut yycursor, mut yymarker := 0, 0
mut trie := []MtagElem{}
// mut trie := []MtagElem{}
mut trie := MtagTrie{}
// Final tag variables available in semantic action.
/*!svars:re2c format = \(aqmut @@ := tag_none\en\(aq; */
@@ -3925,8 +3958,8 @@ fn parse(yyinput string) ?[]int {
/*!re2c
re2c:tags = 1;
re2c:yyfill:enable = 0;
re2c:YYMTAGP = \(dq@@ = add_mtag(mut &trie, @@, yycursor)\(dq;
re2c:YYMTAGN = \(dq@@ = add_mtag(mut &trie, @@, tag_none)\(dq;
re2c:YYMTAGP = \(dq@@ = add_mtag(mut trie, @@, yycursor)\(dq;
re2c:YYMTAGN = \(dq@@ = add_mtag(mut trie, @@, tag_none)\(dq;
num = [0\-9]+;
@@ -4001,8 +4034,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2v definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2v definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+98 -61
View File
@@ -836,6 +836,9 @@ variable named \fBstag\fP\&.
.B \fB#mtag\fP
An \fIm\-tag\fP: saves all input positions at which \fB#mtag\fP matches in a
variable named \fBmtag\fP\&.
.TP
.B \fB$\fP
End of input.
.UNINDENT
.sp
Character classes and string literals may contain the following escape
@@ -944,7 +947,8 @@ It contains primitives for generic operations:
\fBYYSHIFT\fP,
\fBYYSHIFTSTAG\fP,
\fBYYSHIFTMTAG\fP,
\fBYYLESSTHAN\fP\&.
\fBYYLESSTHAN\fP,
\fBYYEND\fP\&.
.UNINDENT
.sp
Here is a full list of API primitives that may be used by the generated code in
@@ -1013,6 +1017,14 @@ A generic API primitive with one variable \fBlen\fP\&.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if there are less than \fBlen\fP input characters left.
.TP
.B \fBYYEND\fP
A generic API primitive with no variables.
It should be defined as an r\-value of boolean type that equals \fBtrue\fP if
and only if the \fIlogical\fP end of input has been reached (excluding any
padding or sentinel symbols). \fBYYEND\fP is used to implement \fB$\fP symbol in
regular expressions. It differs from \fBYYLESSTHAN\fP, which is used to ensure
that the lexer won\(aqt read past the end of buffer.
.TP
.B \fBYYPEEK\fP
A generic API primitive with no variables.
It should be defined as an r\-value of type \fBYYCTYPE\fP that is equal to the
@@ -1196,7 +1208,7 @@ Show help message.
.TP
.B \fB\-\-api <simple | record | generic>\fP
Specify the API used by the generated code to interface with used\-defined
code. Option \fBsimple\fP shold be used in simple cases when there\(aqs no need
code. Option \fBsimple\fP should be used in simple cases when there\(aqs no need
for buffer refilling and storing lexer state. Option \fBrecord\fP should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option \fBgeneric\fP should be used in complex cases when the other two APIs
@@ -1333,6 +1345,12 @@ variable \fByystate\fP\&. Transitions between states update \fByystate\fP to the
case label of the destination state and continue execution to the head of
the loop.
.TP
.B \fB\-\-computed\-continue\fP
This option requires the \fB\-\-loop\-switch\fP code model. It uses computed
\fBcontinue\fP statements to select the next switch case directly, enabling
jump\-table optimization similar to \fB\-\-computed\-gotos\fP in the goto/label
code model.
.TP
.B \fB\-\-nested\-ifs \-s\fP
Use nested \fBif\fP statements instead of \fBswitch\fP statements in conditional
jumps. This usually results in more efficient code with non\-optimizing
@@ -1670,7 +1688,7 @@ A list of supported codegen targets with possible elements \fBcode\fP,
.B \fBsupported_features\fP
A list of supported features with possible elements \fBnested\-ifs\fP,
\fBbitmaps\fP, \fBcomputed\-gotos\fP, \fBcase\-ranges\fP, \fBmonadic\fP, \fBunsafe\fP,
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP\&.
\fBtags\fP, \fBcaptures\fP, \fBcaptvars\fP, \fBcomputed\-continue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
@@ -1934,12 +1952,15 @@ Default switch case.
.TP
.B \fBcode:loop\fP
A loop that runs forever (unless interrupted from the loop body).
Supported variables: \fBlabel\fP (loop label), \fBstmt\fP (a list variable
that expands to all statements in the loop body).
Supported variables: \fBlabel\fP (loop label), \fBval\fP (initial state),
\fBvar\fP (state variable), \fBstate\fP (a list variable that expands to all
state names) and \fBstmt\fP (a list variable that expands to all statements
in the loop body or the current state).
.TP
.B \fBcode:continue\fP
Continue statement. Supported variables: \fBlabel\fP (label from which to
continue execution).
continue execution), \fBval\fP (value passed to a labeled switch) and \fBvar\fP
(state variable).
.TP
.B \fBcode:goto\fP
Goto statement. Supported variables: \fBlabel\fP (label of the jump
@@ -2177,6 +2198,10 @@ Supported variables: \fBYYLESSTHAN\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP,
\fBneed\fP (the number of code units to check against). Conditional:
\fB\&.many\fP (true if the \fBneed\fP is more than one).
.TP
.B \fBcode:yyend\fP
\fBYYEND\fP expression, possibly specialized for different APIs.
Supported variables: \fBYYEND\fP, \fBYYCURSOR\fP, \fBYYLIMIT\fP\&.
.TP
.B \fBcode:yybm_filter\fP
Condition that is used to filter out \fByych\fP values that are not
covered by the \fByybm\fP table (used with \fB\-\-bitmaps\fP option).
@@ -2243,6 +2268,10 @@ True if case ranges feature is enabled (\fB\-\-case\-ranges\fP or
True if the relative form of computed \fBgoto\fP is used
(\fB\-\-computed\-gotos\-relative\fP or \fBre2c:cgoto:relative = 1\fP).
.TP
.B \fB\&.computed_continue\fP
True if loop/switch model uses labeled\-switch transitions
(\fB\-\-computed\-continue\fP).
.TP
.B \fB\&.code_model.goto_label\fP
True if code model based on goto/label is used (\fB\-\-goto\-label\fP).
.TP
@@ -2278,6 +2307,9 @@ languages that have \(dqunsafe\(dq feature.
.B \fB\&.version\fP
True if the generated fingerprint should contain re2zig version.
.TP
.B \fB\&.yyfill.enable\fP
True if \fBYYFILL\fP is enabled (\fBre2c:yyfill:enable = 1\fP).
.TP
.B \fB\&.yyfn.throw\fP
True if \fBre2c:yyfn:throw\fP configuration is defined to a nonempty string.
.UNINDENT
@@ -2699,6 +2731,7 @@ const std = @import(\(dqstd\(dq);
const bufsize = 4095;
const State = struct {
file: *std.Io.Reader,
yyinput: [bufsize + 1]u8,
yycursor: usize,
yymarker: usize,
@@ -2707,7 +2740,7 @@ const State = struct {
eof: bool
};
fn fill(st: *State, file: anytype) i32 {
fn fill(st: *State) i32 {
if (st.eof) { return \-1; } // unexpected EOF
// Error: lexeme too long. In real life can reallocate a larger buffer.
@@ -2722,7 +2755,7 @@ fn fill(st: *State, file: anytype) i32 {
st.token = 0;
// Fill free space at the end of buffer with new data from file.
st.yylimit += file.read(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yylimit += st.file.readSliceShort(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yyinput[st.yylimit] = 0; // append sentinel symbol
// If read less than expected, this is the end of input.
@@ -2731,14 +2764,14 @@ fn fill(st: *State, file: anytype) i32 {
return 0;
}
fn lex(yyrecord: *State, file: anytype) i32 {
fn lex(yyrecord: *State) i32 {
var count: i32 = 0;
loop: while (true) {
yyrecord.token = yyrecord.yycursor;
%{
re2c:api = record;
re2c:eof = 0;
re2c:YYFILL = \(dqfill(yyrecord, file) == 0\(dq;
re2c:YYFILL = \(dqfill(yyrecord) == 0\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -2762,10 +2795,12 @@ test {
fw.close();
// Prepare lexer state: all offsets are at the end of buffer.
var fr = try std.fs.cwd().openFile(fname, .{ .mode = .read_only});
// Normally file would be part of the state struct, but BufferedReader type is unclear.
var br = std.io.bufferedReader(fr.reader());
// Use unbuffered reader \- lexer does its own buffering.
const zerobuf: [0]u8 = undefined;
var fr = try std.fs.cwd().openFile(fname, .{.mode = .read_only});
var reader = fr.reader(&zerobuf);
var st = State{
.file = &reader.interface,
.yyinput = undefined,
.yycursor = bufsize,
.yymarker = bufsize,
@@ -2777,7 +2812,7 @@ test {
st.yyinput[st.yylimit] = 0;
// Run the lexer.
try std.testing.expectEqual(lex(&st, &br), count);
try std.testing.expectEqual(lex(&st), count);
// Cleanup: remove input file.
fr.close();
@@ -2844,6 +2879,7 @@ const std = @import(\(dqstd\(dq);
const bufsize = 4096;
const State = struct {
file: *std.Io.Reader,
yyinput: [bufsize + yymaxfill]u8,
yycursor: usize,
yymarker: usize,
@@ -2852,7 +2888,7 @@ const State = struct {
eof: bool
};
fn fill(st: *State, need: usize, file: anytype) i32 {
fn fill(st: *State, need: usize) i32 {
if (st.eof) { return \-1; } // unexpected EOF
// Error: lexeme too long. In real life can reallocate a larger buffer.
@@ -2867,7 +2903,7 @@ fn fill(st: *State, need: usize, file: anytype) i32 {
st.token = 0;
// Fill free space at the end of buffer with new data from file.
st.yylimit += file.read(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yylimit += st.file.readSliceShort(st.yyinput[st.yylimit..bufsize]) catch 0;
// If read less than expected, this is the end of input.
if (st.yylimit < bufsize) {
@@ -2879,13 +2915,13 @@ fn fill(st: *State, need: usize, file: anytype) i32 {
return 0;
}
fn lex(yyrecord: *State, file: anytype) i32 {
fn lex(yyrecord: *State) i32 {
var count: i32 = 0;
loop: while (true) {
yyrecord.token = yyrecord.yycursor;
%{
re2c:api = record;
re2c:YYFILL = \(dq{ if (fill(yyrecord, @@, file) != 0) return \-2; }\(dq;
re2c:YYFILL = \(dq{ if (fill(yyrecord, @@) != 0) return \-2; }\(dq;
str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq];
@@ -2913,10 +2949,12 @@ test {
// Prepare lexer state: all offsets are at the end of buffer.
// This immediately triggers YYFILL, as the YYLESSTHAN condition is true.
var fr = try std.fs.cwd().openFile(fname, .{ .mode = .read_only});
// Normally file would be part of the state struct, but BufferedReader type is unclear.
var br = std.io.bufferedReader(fr.reader());
// Use unbuffered reader \- lexer does its own buffering.
const zerobuf: [0]u8 = undefined;
var fr = try std.fs.cwd().openFile(fname, .{.mode = .read_only});
var reader = fr.reader(&zerobuf);
var st = State{
.file = &reader.interface,
.yyinput = undefined,
.yycursor = bufsize,
.yymarker = bufsize,
@@ -2927,7 +2965,7 @@ test {
@memset(st.yyinput[st.yylimit..st.yylimit + yymaxfill], 0); // zero\-padding at the end
// Run the lexer.
try std.testing.expectEqual(lex(&st, &br), count);
try std.testing.expectEqual(lex(&st), count);
// Cleanup: remove input file.
fr.close();
@@ -3268,6 +3306,7 @@ const Status = enum {
const bufsize = 10;
const State = struct {
file: std.fs.File.Reader,
yyinput: [bufsize + 1]u8,
yycursor: usize,
yymarker: usize,
@@ -3277,7 +3316,7 @@ const State = struct {
received: usize,
};
fn fill(st: *State, file: anytype) Status {
fn fill(st: *State) Status {
// Error: lexeme too long. In real life can reallocate a larger buffer.
if (st.token < 1) { return Status.big_packet; }
@@ -3290,7 +3329,7 @@ fn fill(st: *State, file: anytype) Status {
st.token = 0;
// Fill free space at the end of buffer with new data from file.
st.yylimit += file.read(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yylimit += st.file.interface.readSliceShort(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yyinput[st.yylimit] = 0; // append sentinel symbol
return Status.ready;
@@ -3321,10 +3360,10 @@ fn run(expect: Status, packets: []const []const u8) !void {
var fr = try std.fs.cwd().openFile(fname, .{ .mode = .read_only});
// Initialize lexer state: \(gastate\(ga value is \-1, all offsets are at the end
// of buffer. Normally file would be part of the state, but BufferedReader
// type is unclear.
var br = std.io.bufferedReader(fr.reader());
// of buffer. Use unbuffered reader \- lexer does its own buffering.
const zerobuf: [0]u8 = undefined;
var st = State{
.file = fr.reader(&zerobuf),
.yyinput = undefined,
.yycursor = bufsize,
.yymarker = bufsize,
@@ -3351,7 +3390,7 @@ fn run(expect: Status, packets: []const []const u8) !void {
try fw.writeAll(packets[send]);
send += 1;
}
status = fill(&st, &br);
status = fill(&st);
std.log.debug(\(dqfilled buffer [{s}], status {}\(dq, .{st.yyinput, status});
if (status != Status.ready) {
break;
@@ -3702,6 +3741,7 @@ fn s2n(str: []const u8) u32 { // convert a pre\-parsed string to a number
}
const State = struct {
file: *std.Io.Reader,
yyinput: [bufsize + 1]u8,
yycursor: usize,
yymarker: usize,
@@ -3713,7 +3753,7 @@ const State = struct {
eof: bool
};
fn fill(st: *State, file: anytype) i32 {
fn fill(st: *State) i32 {
if (st.eof) { return \-1; } // unexpected EOF
// Error: lexeme too long. In real life can reallocate a larger buffer.
@@ -3732,7 +3772,7 @@ fn fill(st: *State, file: anytype) i32 {
st.token = 0;
// Fill free space at the end of buffer with new data from file.
st.yylimit += file.read(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yylimit += st.file.readSliceShort(st.yyinput[st.yylimit..bufsize]) catch 0;
st.yyinput[st.yylimit] = 0; // append sentinel symbol
// If read less than expected, this is the end of input.
@@ -3741,8 +3781,8 @@ fn fill(st: *State, file: anytype) i32 {
return 0;
}
fn parse(st: *State, file: anytype) !std.ArrayList(SemVer) {
var vers = std.ArrayList(SemVer).init(std.testing.allocator);
fn parse(st: *State) !std.ArrayList(SemVer) {
var vers = try std.ArrayList(SemVer).initCapacity(std.testing.allocator, 0);
// Final tag variables available in semantic action.
%{svars format = \(dqvar @@: usize = 0;\en\(dq; %}
@@ -3754,12 +3794,12 @@ fn parse(st: *State, file: anytype) !std.ArrayList(SemVer) {
re2c:eof = 0;
re2c:tags = 1;
re2c:yyrecord = st;
re2c:YYFILL = \(dqfill(st, file) == 0\(dq;
re2c:YYFILL = \(dqfill(st) == 0\(dq;
num = [0\-9]+;
num @t1 \(dq.\(dq @t2 num @t3 (\(dq.\(dq @t4 num)? [\en] {
try vers.append(SemVer {
try vers.append(std.testing.allocator, SemVer {
.major = s2n(st.yyinput[st.token..t1]),
.minor = s2n(st.yyinput[t2..t3]),
.patch = if (t4 == none) 0 else s2n(st.yyinput[t4..st.yycursor \- 1]),
@@ -3783,10 +3823,12 @@ test {
fw.close();
// Prepare lexer state: all offsets are at the end of buffer.
var fr = try std.fs.cwd().openFile(fname, .{ .mode = .read_only});
// Normally file would be part of the state struct, but BufferedReader type is unclear.
var br = std.io.bufferedReader(fr.reader());
// Use unbuffered reader \- lexer does its own buffering.
const zerobuf: [0]u8 = undefined;
var fr = try std.fs.cwd().openFile(fname, .{.mode = .read_only});
var reader = fr.reader(&zerobuf);
var st = State{
.file = &reader.interface,
.yyinput = undefined,
.yycursor = bufsize,
.yymarker = bufsize,
@@ -3799,16 +3841,14 @@ test {
st.yyinput[st.yylimit] = 0;
// Manually construct expected result.
var expect = std.ArrayList(SemVer).init(std.testing.allocator);
for (0..bufsize) |_| try expect.append(SemVer{.major = 1, .minor = 22, .patch = 333});
var expect = [_]SemVer{SemVer{.major = 1, .minor = 22, .patch = 333}} ** bufsize;
// Run the lexer.
var result = try parse(&st, &br);
try std.testing.expectEqualDeep(result, expect);
var result = try parse(&st);
try std.testing.expectEqualDeep(&expect, result.items);
// Cleanup: free memory and remove input file.
expect.deinit();
result.deinit();
result.deinit(std.testing.allocator);
fr.close();
try std.fs.cwd().deleteFile(fname);
}
@@ -3907,7 +3947,7 @@ const MtagElem = struct {
// Append a single value to an m\-tag history.
fn add_mtag(trie: *std.ArrayList(MtagElem), mtag: usize, value: usize) !usize {
try trie.append(MtagElem{.elem = value, .pred = mtag});
try trie.append(std.testing.allocator, MtagElem{.elem = value, .pred = mtag});
return trie.items.len \- 1;
}
@@ -3930,7 +3970,7 @@ fn unwind(trie: *std.ArrayList(MtagElem),
if (ex != none and ey != none) {
// Both tags are valid string indices, extract component.
try ver.append(s2n(str[ex..ey]));
try ver.append(std.testing.allocator, s2n(str[ex..ey]));
} else {
// Both tags are none (this corresponds to zero repetitions).
std.debug.assert(ex == none and ey == none);
@@ -3946,8 +3986,8 @@ fn s2n(str: []const u8) u32 { // convert a pre\-parsed string to a number
fn parse(yyinput: [:0]const u8) !std.ArrayList(u32) {
var yycursor: usize = 0;
var yymarker: usize = 0;
var mt = std.ArrayList(MtagElem).init(std.testing.allocator);
defer mt.deinit();
var mt = try std.ArrayList(MtagElem).initCapacity(std.testing.allocator, 0);
defer mt.deinit(std.testing.allocator);
// Final tag variables available in semantic action.
%{svars format = \(dqvar @@: usize = none;\(dq; %}
@@ -3966,8 +4006,8 @@ fn parse(yyinput: [:0]const u8) !std.ArrayList(u32) {
num = [0\-9]+;
@t1 num @t2 (\(dq.\(dq #t3 num #t4)* [\ex00] {
var ver = std.ArrayList(u32).init(std.testing.allocator);
try ver.append(s2n(yyinput[t1..t2]));
var ver = try std.ArrayList(u32).initCapacity(std.testing.allocator, 0);
try ver.append(std.testing.allocator, s2n(yyinput[t1..t2]));
try unwind(&mt, t3, t4, yyinput, &ver);
return ver;
}
@@ -3977,20 +4017,16 @@ fn parse(yyinput: [:0]const u8) !std.ArrayList(u32) {
test {
var result = try parse(\(dq1\(dq);
var expect = std.ArrayList(u32).init(std.testing.allocator);
try expect.appendSlice(&[_]u32{1});
try std.testing.expectEqualDeep(result, expect);
expect.deinit();
result.deinit();
var expect = [_]u32{1};
try std.testing.expectEqualDeep(&expect, result.items);
result.deinit(std.testing.allocator);
}
test {
var result = try parse(\(dq1.2.3.4.5.6.7\(dq);
var expect = std.ArrayList(u32).init(std.testing.allocator);
try expect.appendSlice(&[_]u32{1, 2, 3, 4, 5, 6, 7});
try std.testing.expectEqualDeep(result, expect);
expect.deinit();
result.deinit();
var expect = [_]u32{1, 2, 3, 4, 5, 6, 7};
try std.testing.expectEqualDeep(&expect, result.items);
result.deinit(std.testing.allocator);
}
test {
@@ -4046,8 +4082,9 @@ fixed\-length Unicode encoding with code space \fB[0\-0x10FFFF]\fP and 4\-byte c
points and code units.
.UNINDENT
.sp
Include file \fBinclude/unicode_categories.re\fP provides re2zig definitions for the
standard Unicode categories.
Include files \fBinclude/unicode_blocks.re\fP, \fBinclude/unicode_categories.re\fP
and \fBinclude/unicode_properties.re\fP provide re2zig definitions for blocks,
categories and properties described in the Unicode standard.
.sp
Option \fB\-\-input\-encoding\fP specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 4.3 */
/* Generated by re2c 4.6 */
#line 1 "../lib/lex.re"
#include <stdint.h>
#include <stdio.h>
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 4.3 */
/* Generated by re2c 4.6 */
#line 1 "../lib/test_helper.re"
#include "lib/test_helper.h"
+9 -3
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_C =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_C =
"re2c:YYCTYPE = \"YYCTYPE\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \"->yycursor\" : \"YYCURSOR\");\n"
"re2c:YYDEBUG = \"YYDEBUG\";\n"
"re2c:YYEND = \"YYEND\";\n"
"re2c:YYFILL = \"YYFILL\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"YYGETCONDITION\"; // historic default\n"
@@ -174,8 +175,8 @@ static constexpr const char* DEFAULT_SYNTAX_C =
"\n"
"code:enum =\n"
" \"enum \" type \" {\" nl indent\n"
" [elem{0:-2}: topindent elem (.init ? \" = \" init) \",\" nl]\n"
" [elem{-1}: topindent elem (.init ? \" = \" init) nl]\n"
" [elem{0:-2}: topindent elem (!.code_model.goto_label ? \" = \" init) \",\" nl]\n"
" [elem{-1}: topindent elem (!.code_model.goto_label ? \" = \" init) nl]\n"
" dedent \"};\" nl;\n"
"\n"
"code:enum_elem = name;\n"
@@ -451,6 +452,11 @@ static constexpr const char* DEFAULT_SYNTAX_C =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND (.api_style.functions ? \"()\")\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = yybm \"[\" offset \"+\" yych \"] & \" mask;\n"
+9 -3
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_D =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_D =
"re2c:YYCTYPE = \"YYChar\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -174,8 +175,8 @@ static constexpr const char* DEFAULT_SYNTAX_D =
"\n"
"code:enum =\n"
" \"enum \" type \" {\" nl indent\n"
" [elem{0:-2}: topindent elem (.init ? \" = \" init) \",\" nl]\n"
" [elem{-1}: topindent elem (.init ? \" = \" init) nl]\n"
" [elem{0:-2}: topindent elem (!.code_model.goto_label ? \" = \" init) \",\" nl]\n"
" [elem{-1}: topindent elem (!.code_model.goto_label ? \" = \" init) nl]\n"
" dedent \"};\" nl;\n"
"\n"
"code:enum_elem = type \".\" name;\n"
@@ -424,6 +425,11 @@ static constexpr const char* DEFAULT_SYNTAX_D =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+9 -3
View File
@@ -62,11 +62,11 @@ static constexpr const char* DEFAULT_SYNTAX_GO =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -122,6 +122,7 @@ static constexpr const char* DEFAULT_SYNTAX_GO =
"re2c:YYCTXMARKER = (.api.generic ? \"YYCTXMARKER\" : (.api.record ? yyrecord \".\") \"yyctxmarker\");\n"
"re2c:YYCURSOR = (.api.generic ? \"YYCURSOR\" : (.api.record ? yyrecord \".\") \"yycursor\");\n"
"re2c:YYDEBUG = \"YYDEBUG\";\n"
"re2c:YYEND = \"YYEND\";\n"
"re2c:YYFILL = \"YYFILL\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"YYGETCONDITION\"; // historic default\n"
@@ -175,8 +176,8 @@ static constexpr const char* DEFAULT_SYNTAX_GO =
"\n"
"code:enum =\n"
" \"const (\" nl indent\n"
" [elem{0}: topindent elem \" = \" (.init ? init : \"iota\") nl]\n"
" [elem{1:-1}: topindent elem (.init ? \" = \" init) nl]\n"
" [elem{0}: topindent elem \" = \" (!.code_model.goto_label ? init : \"iota\") nl]\n"
" [elem{1:-1}: topindent elem (!.code_model.goto_label ? \" = \" init) nl]\n"
" dedent \")\" nl;\n"
"\n"
"code:enum_elem = name;\n"
@@ -406,6 +407,11 @@ static constexpr const char* DEFAULT_SYNTAX_GO =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND (.api_style.functions ? \"()\")\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+7 -1
View File
@@ -62,11 +62,11 @@ static constexpr const char* DEFAULT_SYNTAX_HASKELL =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"yyfill\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"yyfill\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -122,6 +122,7 @@ static constexpr const char* DEFAULT_SYNTAX_HASKELL =
"re2c:YYCTXMARKER = \"_yyctxmarker\";\n"
"re2c:YYCURSOR = \"_yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = \"yygetaccept\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -415,6 +416,11 @@ static constexpr const char* DEFAULT_SYNTAX_HASKELL =
" ? YYCURSOR \" >= \" YYLIMIT // YYFILL check can only be used with EOF rule $\n"
" : YYLESSTHAN);\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYCURSOR \" >= \" YYLIMIT);\n"
"\n"
"code:yybm_filter = \"(\" yych \" .&. complement 0xFF) /= 0\";\n"
"\n"
"code:yybm_match = \"(\" yybm \" ! (\" offset \" + fromIntegral \" yych \") .&. \" mask \") /= 0\";\n"
+7 -1
View File
@@ -62,11 +62,11 @@ static constexpr const char* DEFAULT_SYNTAX_JAVA =
"re2c:yych:emit = 1;\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -122,6 +122,7 @@ static constexpr const char* DEFAULT_SYNTAX_JAVA =
"re2c:YYCTXMARKER = (.api.record ? yyrecord \".\") \"yyctxmarker\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -381,6 +382,11 @@ static constexpr const char* DEFAULT_SYNTAX_JAVA =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+7 -1
View File
@@ -62,11 +62,11 @@ static constexpr const char* DEFAULT_SYNTAX_JS =
"re2c:yych:emit = 1;\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -122,6 +122,7 @@ static constexpr const char* DEFAULT_SYNTAX_JS =
"re2c:YYCTXMARKER = (.api.record ? yyrecord \".\") \"yyctxmarker\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -384,6 +385,11 @@ static constexpr const char* DEFAULT_SYNTAX_JS =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") !== 0\";\n"
+7 -1
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_OCAML =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_OCAML =
"re2c:YYCTXMARKER = (.api.record ? yyrecord \".\") \"yyctxmarker\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -394,6 +395,11 @@ static constexpr const char* DEFAULT_SYNTAX_OCAML =
" : YYLIMIT \" <= \" YYCURSOR)\n"
" : YYLESSTHAN);\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" land ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \".(\" offset \" + Char.code \" yych \") land \" mask \") != 0\";\n"
+7 -1
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_PYTHON =
"re2c:yych:emit = 0;\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_PYTHON =
"re2c:YYCTXMARKER = (.api.record ? yyrecord \".\") \"yyctxmarker\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -389,6 +390,11 @@ static constexpr const char* DEFAULT_SYNTAX_PYTHON =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+7 -1
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_RUST =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"YYBM\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_RUST =
"re2c:YYCTXMARKER = (.api.generic ? \"YYCTXMARKER\" : (.api.record ? yyrecord \".\") \"yyctxmarker\");\n"
"re2c:YYCURSOR = (.api.generic ? \"YYCURSOR\" : (.api.record ? yyrecord \".\") \"yycursor\");\n"
"re2c:YYDEBUG = \"YYDEBUG\";\n"
"re2c:YYEND = \"YYEND\";\n"
"re2c:YYFILL = \"YYFILL\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"YYGETCONDITION\"; // historic default\n"
@@ -407,6 +408,11 @@ static constexpr const char* DEFAULT_SYNTAX_RUST =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \" as usize] & \" mask \") != 0\";\n"
+7 -1
View File
@@ -62,11 +62,11 @@ static constexpr const char* DEFAULT_SYNTAX_SWIFT =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_SWIFT =
"re2c:YYCTYPE = \"UInt8\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -409,6 +410,11 @@ static constexpr const char* DEFAULT_SYNTAX_SWIFT =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \" + Int(\" yych \")] & \" mask \") != 0\";\n"
+9 -3
View File
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_V =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_V =
"re2c:YYCTXMARKER = (.api.record ? yyrecord \".\") \"yyctxmarker\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -156,7 +157,7 @@ static constexpr const char* DEFAULT_SYNTAX_V =
"\n"
"// code templates --------------------------------------------------------------\n"
"\n"
"code:var_local = topindent \"mut \" name \" := \" init nl;\n"
"code:var_local = topindent \"mut \" name \" := \" type \"(\" init \")\" nl;\n"
"code:var_global = <undefined>;\n"
"\n"
"code:const_local = topindent \"const \" name \" = \" init nl;\n"
@@ -176,7 +177,7 @@ static constexpr const char* DEFAULT_SYNTAX_V =
"code:enum = (.code_model.loop_switch\n"
" ? [elem: \"const \" elem \" = \" init nl]\n"
" : \"enum \" type \" {\" nl\n"
" indent [elem: topindent elem (.init ? \" = \" init) nl] dedent\n"
" indent [elem: topindent elem (!.code_model.goto_label ? \" = \" init) nl] dedent\n"
" \"}\" nl);\n"
"\n"
"code:enum_elem = (!.code_model.loop_switch ? \".\") name;\n"
@@ -408,6 +409,11 @@ static constexpr const char* DEFAULT_SYNTAX_V =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+21 -6
View File
@@ -6,7 +6,7 @@ static constexpr const char* DEFAULT_SYNTAX_ZIG =
"supported_code_models = [\"loop-switch\", \"recursive-functions\"];\n"
"supported_targets = [\"code\", \"dot\"];\n"
"supported_features = [\"nested-ifs\", \"bitmaps\", \"case-ranges\",\n"
" \"tags\", \"captures\", \"captvars\"];\n"
" \"tags\", \"captures\", \"captvars\", \"computed-continue\"];\n"
"\n"
"\n"
"// language-specific options ---------------------------------------------------\n"
@@ -63,11 +63,11 @@ static constexpr const char* DEFAULT_SYNTAX_ZIG =
"re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);\n"
"re2c:yybm = \"yybm\";\n"
"re2c:yybm:hex = 0;\n"
"re2c:yyfill = \"\";\n"
"re2c:yystable = \"\"; // deprecated\n"
"re2c:header = \"\";\n"
"re2c:eof = -1;\n"
"re2c:sentinel = -1;\n"
"re2c:yyfill = \"\";\n"
"re2c:yyfill:enable = 1;\n"
"re2c:yyfill:parameter = 1;\n"
"re2c:yyfill:check = 1;\n"
@@ -123,6 +123,7 @@ static constexpr const char* DEFAULT_SYNTAX_ZIG =
"re2c:YYCTYPE = \"u8\";\n"
"re2c:YYCURSOR = (.api.record ? yyrecord \".\") \"yycursor\";\n"
"re2c:YYDEBUG = \"yydebug\";\n"
"re2c:YYEND = \"yyend\";\n"
"re2c:YYFILL = \"yyfill\";\n"
"re2c:YYGETACCEPT = sigil \"{var}\";\n"
"re2c:YYGETCOND = \"yygetcond\";\n"
@@ -220,12 +221,21 @@ static constexpr const char* DEFAULT_SYNTAX_ZIG =
"\n"
"code:switch_case_default = \"else\";\n"
"\n"
"code:loop =\n"
" topindent (.loop_label ? label \": \") \"while (true) {\" nl\n"
"code:loop = (.computed_continue\n"
" ? topindent var \": switch (@as(enum {\" nl\n"
" indent [state: topindent state \",\" nl] dedent\n"
" topindent \"}, .\" val \")) {\" nl\n"
" indent [state:\n"
" topindent \".\" state \" => {\" nl\n"
" indent [stmt: stmt] dedent\n"
" topindent \"},\" nl] dedent\n"
" topindent \"}\" nl\n"
" : topindent (.loop_label ? label \": \") \"while (true) {\" nl\n"
" indent [stmt: stmt] dedent\n"
" topindent \"}\" nl;\n"
" topindent \"}\" nl);\n"
"\n"
"code:continue = topindent \"continue\" (.loop_label ? \" :\" label) \";\" nl;\n"
"code:continue = topindent \"continue\"\n"
" (.computed_continue ? \" :\" var \" .\" val : (.loop_label ? \" :\" label)) \";\" nl;\n"
"\n"
"code:goto = topindent \"goto \" label \";\" nl;\n"
"\n"
@@ -422,6 +432,11 @@ static constexpr const char* DEFAULT_SYNTAX_ZIG =
" ? \"(\" YYLIMIT \" - \" YYCURSOR \") < \" need\n"
" : YYLIMIT \" <= \" YYCURSOR));\n"
"\n"
"code:yyend =\n"
" (.api.generic | .yyfill.enable\n"
" ? YYEND\n"
" : YYLIMIT \" <= \" YYCURSOR);\n"
"\n"
"code:yybm_filter = yych \" & ~0xFF\";\n"
"\n"
"code:yybm_match = \"(\" yybm \"[\" offset \"+\" yych \"] & \" mask \") != 0\";\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -177,6 +177,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -178,6 +178,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -177,6 +177,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -178,6 +178,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -176,6 +176,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+8 -1
View File
@@ -15,7 +15,7 @@ const char* help =
" --api <simple | record | generic>\n"
"\n"
" Specify the API used by the generated code to interface with used-\n"
" defined code. Option simple shold be used in simple cases when there's\n"
" defined code. Option simple should be used in simple cases when there's\n"
" no need for buffer refilling and storing lexer state. Option record\n"
" should be used when lexer state needs to be stored in a record (struct,\n"
" class, etc.). Option generic should be used in complex cases when the\n"
@@ -177,6 +177,13 @@ const char* help =
" to the case label of the destination state and continue execution to\n"
" the head of the loop.\n"
"\n"
" --computed-continue\n"
"\n"
" This option requires the --loop-switch code model. It uses computed\n"
" continue statements to select the next switch case directly, enabling\n"
" jump-table optimization similar to --computed-gotos in the goto/label\n"
" code model.\n"
"\n"
" --nested-ifs -s\n"
"\n"
" Use nested if statements instead of switch statements in conditional\n"
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 4.3 */
/* Generated by re2c 4.6 */
#line 1 "../src/msg/ver_to_vernum.re"
#include <stddef.h>
#include <stdint.h>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 4.3 */
/* Generated by re2c 4.6 */
#line 1 "../src/parse/lexer.re"
#include <ctype.h>
#include <stdint.h>
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 4.3 */
/* Generated by re2c 4.6 */
#ifndef _RE2C_PARSE_LEX_
#define _RE2C_PARSE_LEX_
+2 -2
View File
@@ -1225,7 +1225,7 @@ yyreduce:
case 14: /* rule: trailexpr TOKEN_CODE */
#line 112 "../src/parse/parser.ypp"
{
find_or_add_gram(grams, "").add_rule({(yyvsp[-1].regexp), (yyvsp[0].semact)});
find_or_add_gram(grams, "").rules.push_back({(yyvsp[-1].regexp), (yyvsp[0].semact)});
}
#line 1231 "src/parse/parser.cc"
break;
@@ -1266,7 +1266,7 @@ yyreduce:
#line 127 "../src/parse/parser.ypp"
{
for (const std::string& cond : ast.temp_condlist) {
find_or_add_gram(grams, cond).add_rule({(yyvsp[-1].regexp), (yyvsp[0].semact)});
find_or_add_gram(grams, cond).rules.push_back({(yyvsp[-1].regexp), (yyvsp[0].semact)});
}
ast.temp_condlist.clear();
}
+1 -1
View File
@@ -1,4 +1,4 @@
AC_INIT([re2c],[4.3],[re2c-general@lists.sourceforge.net])
AC_INIT([re2c],[4.6],[re2c-general@lists.sourceforge.net])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz dist-lzip no-dist-gzip])
AM_SILENT_RULES([yes])
+3
View File
@@ -41,6 +41,7 @@ program:
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYEND``.
Generic API supports two styles that determine the form in which the
primitives should be defined:
@@ -67,6 +68,7 @@ program:
re2c:YYRESTORECTX = "cursor = ctxmarker;";
re2c:YYRESTORETAG = "cursor = ${tag};";
re2c:YYLESSTHAN = "limit - cursor < @@{len}";
re2c:YYEND = "limit == cursor";
re2c:YYSTAGP = "@@{tag} = cursor;";
re2c:YYSTAGN = "@@{tag} = NULL;";
re2c:YYSHIFT = "cursor += @@{shift};";
@@ -93,6 +95,7 @@ program:
#define YYRESTORECTX() cursor = ctxmarker
#define YYRESTORETAG(tag) cursor = tag
#define YYLESSTHAN(len) limit - cursor < len
#define YYEND() limit == cursor
#define YYSTAGP(tag) tag = cursor
#define YYSTAGN(tag) tag = NULL
#define YYSHIFT(shift) cursor += shift
+2 -1
View File
@@ -38,4 +38,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+4 -1
View File
@@ -41,7 +41,8 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
Generic API supports two styles that determine the form in which the
primitives should be defined:
@@ -68,6 +69,7 @@ program:
re2c:YYRESTORECTX = "cursor = ctxmarker";
re2c:YYRESTORETAG = "cursor = ${tag}";
re2c:YYLESSTHAN = "limit - cursor < @@{len}";
re2c:YYEND = "limit == cursor";
re2c:YYSTAGP = "@@{tag} = cursor";
re2c:YYSTAGN = "@@{tag} = -1";
re2c:YYSHIFT = "cursor += @@{shift}";
@@ -93,4 +95,5 @@ program:
YYBACKUPCTX := func() { ctxmarker = cursor }
YYRESTORECTX := func() { cursor = ctxmarker }
YYLESSTHAN := func(n int) bool { return limit-cursor < n }
YYEND := func(n int) bool { return limit == cursor }
YYSHIFT := func(n int) { cursor += n }
+2 -1
View File
@@ -32,4 +32,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+2 -1
View File
@@ -39,4 +39,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+2 -1
View File
@@ -39,4 +39,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+2 -1
View File
@@ -30,4 +30,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+2 -1
View File
@@ -39,4 +39,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+3 -1
View File
@@ -41,7 +41,8 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
For example, if the input is a byte slice ``buffer: &[u8]``, variables
``cursor``, ``limit``, ``marker`` and ``ctxmarker`` of type ``usize``
represent input positions, and a constant ``NONE`` represents invalid
@@ -58,6 +59,7 @@ program:
re2c:YYRESTORECTX = "cursor = ctxmarker;";
re2c:YYRESTORETAG = "cursor = @@{tag};";
re2c:YYLESSTHAN = "limit - cursor < @@{len}";
re2c:YYEND = "limit == cursor";
re2c:YYSTAGP = "@@{tag} = cursor;";
re2c:YYSTAGN = "@@{tag} = NONE;";
re2c:YYSHIFT = "cursor = (cursor as isize + @@{shift}) as usize;";
+3 -1
View File
@@ -39,7 +39,8 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
For example, if the input is a zero-terminated array of bytes
``buffer: [UInt8]``, variables ``cursor``, ``limit``, ``marker`` and
``ctxmarker`` of type ``Int`` represent input positions, and ``-1``
@@ -56,6 +57,7 @@ program:
re2c:YYRESTORECTX = "cursor = ctxmarker";
re2c:YYRESTORETAG = "cursor = ${tag}";
re2c:YYLESSTHAN = "limit - cursor < @@{len}";
re2c:YYEND = "limit == cursor";
re2c:YYSTAGP = "@@{tag} = cursor";
re2c:YYSTAGN = "@@{tag} = -1";
re2c:YYSHIFT = "cursor += @@{shift}";
+2 -1
View File
@@ -39,4 +39,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+2 -1
View File
@@ -39,4 +39,5 @@ program:
``YYSHIFT``,
``YYSHIFTSTAG``,
``YYSHIFTMTAG``,
``YYLESSTHAN``.
``YYLESSTHAN``,
``YYEND``.
+8
View File
@@ -63,6 +63,14 @@ order to interface with the outer program.
It should be defined as an r-value of boolean type that equals ``true`` if
and only if there are less than ``len`` input characters left.
``YYEND``
A generic API primitive with no variables.
It should be defined as an r-value of boolean type that equals ``true`` if
and only if the *logical* end of input has been reached (excluding any
padding or sentinel symbols). ``YYEND`` is used to implement ``$`` symbol in
regular expressions. It differs from ``YYLESSTHAN``, which is used to ensure
that the lexer won't read past the end of buffer.
``YYPEEK``
A generic API primitive with no variables.
It should be defined as an r-value of type ``YYCTYPE`` that is equal to the
+7 -1
View File
@@ -4,7 +4,7 @@
``--api <simple | record | generic>``
Specify the API used by the generated code to interface with used-defined
code. Option ``simple`` shold be used in simple cases when there's no need
code. Option ``simple`` should be used in simple cases when there's no need
for buffer refilling and storing lexer state. Option ``record`` should be
used when lexer state needs to be stored in a record (struct, class, etc.).
Option ``generic`` should be used in complex cases when the other two APIs
@@ -141,6 +141,12 @@
case label of the destination state and continue execution to the head of
the loop.
``--computed-continue``
This option requires the ``--loop-switch`` code model. It uses computed
``continue`` statements to select the next switch case directly, enabling
jump-table optimization similar to ``--computed-gotos`` in the goto/label
code model.
``--nested-ifs -s``
Use nested ``if`` statements instead of ``switch`` statements in conditional
jumps. This usually results in more efficient code with non-optimizing
@@ -66,6 +66,9 @@
An *m-tag*: saves all input positions at which ``#mtag`` matches in a
variable named ``mtag``.
``$``
End of input.
Character classes and string literals may contain the following escape
sequences: ``\a``, ``\b``, ``\f``, ``\n``, ``\r``, ``\t``, ``\v``, ``\\``,
octal escapes ``\ooo`` and hexadecimal escapes ``\xhh``, ``\uhhhh`` and
+18 -5
View File
@@ -37,7 +37,7 @@ language configurations, inplace configurations and code templates.
``supported_features``
A list of supported features with possible elements ``nested-ifs``,
``bitmaps``, ``computed-gotos``, ``case-ranges``, ``monadic``, ``unsafe``,
``tags``, ``captures``, ``captvars``.
``tags``, ``captures``, ``captvars``, ``computed-continue``.
**Language configurations**
@@ -270,12 +270,15 @@ language configurations, inplace configurations and code templates.
``code:loop``
A loop that runs forever (unless interrupted from the loop body).
Supported variables: ``label`` (loop label), ``stmt`` (a list variable
that expands to all statements in the loop body).
Supported variables: ``label`` (loop label), ``val`` (initial state),
``var`` (state variable), ``state`` (a list variable that expands to all
state names) and ``stmt`` (a list variable that expands to all statements
in the loop body or the current state).
``code:continue``
Continue statement. Supported variables: ``label`` (label from which to
continue execution).
continue execution), ``val`` (value passed to a labeled switch) and ``var``
(state variable).
``code:goto``
Goto statement. Supported variables: ``label`` (label of the jump
@@ -513,6 +516,10 @@ language configurations, inplace configurations and code templates.
``need`` (the number of code units to check against). Conditional:
``.many`` (true if the ``need`` is more than one).
``code:yyend``
``YYEND`` expression, possibly specialized for different APIs.
Supported variables: ``YYEND``, ``YYCURSOR``, ``YYLIMIT``.
``code:yybm_filter``
Condition that is used to filter out ``yych`` values that are not
covered by the ``yybm`` table (used with ``--bitmaps`` option).
@@ -575,6 +582,10 @@ language configurations, inplace configurations and code templates.
True if the relative form of computed ``goto`` is used
(``--computed-gotos-relative`` or ``re2c:cgoto:relative = 1``).
``.computed_continue``
True if loop/switch model uses labeled-switch transitions
(``--computed-continue``).
``.code_model.goto_label``
True if code model based on goto/label is used (``--goto-label``).
@@ -610,6 +621,8 @@ language configurations, inplace configurations and code templates.
``.version``
True if the generated fingerprint should contain |re2c| version.
``.yyfill.enable``
True if ``YYFILL`` is enabled (``re2c:yyfill:enable = 1``).
``.yyfn.throw``
True if ``re2c:yyfn:throw`` configuration is defined to a nonempty string.
+3 -2
View File
@@ -38,8 +38,9 @@ The following encodings are supported:
fixed-length Unicode encoding with code space ``[0-0x10FFFF]`` and 4-byte code
points and code units.
Include file ``include/unicode_categories.re`` provides |re2c| definitions for the
standard Unicode categories.
Include files ``include/unicode_blocks.re``, ``include/unicode_categories.re``
and ``include/unicode_properties.re`` provide |re2c| definitions for blocks,
categories and properties described in the Unicode standard.
Option ``--input-encoding`` specifies source file encoding, which can be used to
enable Unicode literals in regular expressions. For example
@@ -466,7 +466,7 @@ Figure \ref{fig:tdfa} in section \ref{section_tdfa} shows an example of TNFA sim
\ElseIf {$e = e_1 \mid e_2$} {
$(\Sigma, T_2, Q_2, q_2, q_f, \Delta_2) = \retonfa (e_2, q_f)$ \;
$(\Sigma, T_2, Q'_2, q'_2, q_f, \Delta'_2) = \ntag (T_2, q_f)$ \;
$(\Sigma, T_1, Q_1, q_1, q'_2, \Delta_1) = \retonfa (e_2, q'_2)$ \;
$(\Sigma, T_1, Q_1, q_1, q'_2, \Delta_1) = \retonfa (e_1, q'_2)$ \;
$(\Sigma, T_1, Q'_1, q'_1, q_2, \Delta'_1) = \ntag (T_1, q_2)$ \;
$Q = Q_1 \cup Q'_1 \cup Q_2 \cup Q'_2 \cup \{q_0\}$ \;
$\Delta = \Delta_1 \cup \Delta'_1 \cup \Delta_2 \cup \Delta'_2 \cup \{ (q_0,1,\epsilon,q_1), (q_0,2,\epsilon,q'_1) \}$ \;
@@ -722,7 +722,6 @@ and $l$ is the new sequence constructed by the $\epsilon$-closure.
\nonl\Fn {$\underline{step \Xund on \Xund symbol \big( (X, P), a \big)} \smallskip$} {
$B:$ empty sequence of configurations \;
\BlankLine
\For {$(q, r, l) \in X$ ordered by $q$ in the order of $P$} {
\If {$\exists (q, a, p) \in \Delta \mid a \in \Sigma$} {
append $(p, r, l, \epsilon)$ to $B$
@@ -758,45 +757,44 @@ and $l$ is the new sequence constructed by the $\epsilon$-closure.
\nonl\Fn {$\underline{transition \Xund regops \big( C, R, V \big)} \smallskip$} {
$O:$ empty list of operations \;
\BlankLine
\For {each $(q, r, h, l) \in C$} {
\For {each tag $t \in T$} {
\If {$h_t = history(h, t) \neq \epsilon$} {
\If {$h_t = history(h, t) \neq \epsilon$ and \;
\quad\quad $(history(l, t) = \epsilon$ or $t$ is a multi-tag$)$} {
$v = regop \Xund rhs(r, h_t, t)$ \;
\BlankLine
\If {$V[t][v]$ is undefined } {
$i = max \{R\} + 1$ \;
$i = V[t][v]$ \;
\If {$i$ is undefined } {
$V[t][v] = i = max \{R\} + 1$ \;
$R = R \cup \{i\}$ \;
$V[t][v] = i$ \;
}
\If {operation $i \leftarrow v$ is not in $O$} {
append operation $i \leftarrow v$ to $O$ \;
}
\BlankLine
$r[t] = V[t][v]$ \;
$r[t] = i$ \;
}
}
}
\BlankLine
\Return $O$ \;
}
\vspace{2em}
\nonl\Fn {$\underline{final \Xund regops \big( R_f, r, l \big)} \smallskip$} {
$O:$ empty list of operations \;
\BlankLine
\For {each tag $t \in T$} {
\If {$l_t = history(l, t) \neq \epsilon$} {
append $R_f[t] \leftarrow regop \Xund rhs(r, l_t, t)$ to $O$ \;
} \Else {
append $R_f[t] \leftarrow r[t]$ to $O$ \;
}
}
\BlankLine
\Return $O$ \;
}
\vspace{2em}
\nonl\Fn {$\underline{regop \Xund rhs \big( r, h_t, t \big)} \smallskip$} {
\If {$t$ is a multi-valued tag} {
\lIf {$t$ is a multi-tag} {
\Return $r[t] \cdot h_t$
} \Else {
} \lElse {
\Return the last element of $h_t$
}
}
@@ -1380,7 +1378,7 @@ RE2C uses the following optimization passes for the number of repetitions $N=2$
\For {each operation in $b$} {
\If {copy or append $i \leftarrow j ...$ and $i \neq j$} {
$x = B[i], \; y = B[j]$ \;
\If {$x = -1$ and $y = -1$} {
\If {$x = -1$ and $y = -1$ and $\neg I[i][j]$} {
$B[i] = B[j] = i$ \;
$S[i] = \{i, j\}$ \;
} \ElseIf {$x \neq -1$ and $y = -1$} {
@@ -1412,6 +1410,9 @@ RE2C uses the following optimization passes for the number of repetitions $N=2$
\If {$\exists j$ in $G: B[j] = j$ and $\forall k \in S[j]: \neg I[i][k]$} {
$B[i] = j$ \;
$S[j] = S[j] \cup \{i\}$ \;
} \Else {
$B[i] = i$ \;
$S[i] = \{i\}$ \;
}
}
\BlankLine
@@ -268,17 +268,17 @@
\multicolumn{12}{c}{Interference} \\[0.3em]
& $r_1$ & $r_2$ & $r_3$ & $r_4$ & $r_5$ & $r_6$ & $r_7$ & $r_8$ & $r_9$ & $\!r_{10}\!$ & $\!r_{11}\!$ \\
\hline
$r_1$ & $.$ & $*$ & $*$ & $*$ & $*$ & $.$ & $.$ & $.$ & $.$ & $.$ & $.$ \\
$r_2$ & $*$ & $.$ & $*$ & $*$ & $*$ & $.$ & $*$ & $.$ & $.$ & $.$ & $.$ \\
$r_3$ & $*$ & $*$ & $.$ & $*$ & $*$ & $.$ & $*$ & $*$ & $.$ & $.$ & $.$ \\
$r_4$ & $*$ & $*$ & $*$ & $.$ & $*$ & $.$ & $*$ & $*$ & $*$ & $.$ & $.$ \\
$r_5$ & $*$ & $*$ & $*$ & $*$ & $.$ & $.$ & $*$ & $*$ & $*$ & $*$ & $.$ \\
$r_1$ & $.$ & $*$ & $*$ & $*$ & $*$ & $.$ & $.$ & $*$ & $*$ & $*$ & $*$ \\
$r_2$ & $*$ & $.$ & $*$ & $*$ & $*$ & $.$ & $.$ & $.$ & $*$ & $*$ & $*$ \\
$r_3$ & $*$ & $*$ & $.$ & $*$ & $*$ & $.$ & $.$ & $.$ & $.$ & $*$ & $*$ \\
$r_4$ & $*$ & $*$ & $*$ & $.$ & $*$ & $.$ & $.$ & $.$ & $.$ & $.$ & $*$ \\
$r_5$ & $*$ & $*$ & $*$ & $*$ & $.$ & $.$ & $.$ & $.$ & $.$ & $.$ & $.$ \\
$r_6$ & $.$ & $.$ & $.$ & $.$ & $.$ & $.$ & $*$ & $*$ & $.$ & $.$ & $.$ \\
$r_7$ & $.$ & $*$ & $*$ & $*$ & $*$ & $*$ & $.$ & $*$ & $*$ & $*$ & $*$ \\
$r_8$ & $.$ & $.$ & $*$ & $*$ & $*$ & $*$ & $*$ & $.$ & $*$ & $*$ & $*$ \\
$r_9$ & $.$ & $.$ & $.$ & $*$ & $*$ & $.$ & $*$ & $*$ & $.$ & $.$ & $*$ \\
$r_{10}$ & $.$ & $.$ & $.$ & $.$ & $*$ & $.$ & $*$ & $*$ & $.$ & $.$ & $*$ \\
$r_{11}$ & $.$ & $.$ & $.$ & $.$ & $.$ & $.$ & $*$ & $*$ & $*$ & $*$ & $.$ \\
$r_7$ & $.$ & $.$ & $.$ & $.$ & $.$ & $*$ & $.$ & $*$ & $*$ & $*$ & $*$ \\
$r_8$ & $*$ & $.$ & $.$ & $.$ & $.$ & $*$ & $*$ & $.$ & $*$ & $*$ & $*$ \\
$r_9$ & $*$ & $*$ & $.$ & $.$ & $.$ & $.$ & $*$ & $*$ & $.$ & $.$ & $*$ \\
$r_{10}$ & $*$ & $*$ & $*$ & $.$ & $.$ & $.$ & $*$ & $*$ & $.$ & $.$ & $*$ \\
$r_{11}$ & $*$ & $*$ & $*$ & $*$ & $.$ & $.$ & $*$ & $*$ & $*$ & $*$ & $.$ \\
\end{tabular}
$};
\end{scope}
@@ -307,8 +307,8 @@
\begin{aligned}
& \underline{live\!: r_1\, r_2\, r_3} \\[-0.5em]
& r_{1} \leftarrow r_{3} \\[-0.6em]
& r_{1} \leftarrow \pos \\[-0.6em]
& r_{2} \leftarrow \pos
& r_{2} \leftarrow \pos \\[-0.6em]
& r_{3} \leftarrow \pos
\end{aligned}
$};
\draw [rounded corners=0.5em] (x3.north west) rectangle (x3.south east);
+2 -3
View File
@@ -2,11 +2,10 @@
// re2c $INPUT -o $OUTPUT -i --case-ranges
#include <assert.h>
int lex(const char *s) {
const char *YYCURSOR = s;
int lex(const char* YYCURSOR) {
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case '1' ... '9': goto yy2;
+2 -3
View File
@@ -1,11 +1,10 @@
// re2c $INPUT -o $OUTPUT -i --case-ranges
#include <assert.h>
int lex(const char *s) {
const char *YYCURSOR = s;
int lex(const char* YYCURSOR) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = "unsigned char";
[1-9][0-9]* { return 0; }
* { return 1; }
+1 -1
View File
@@ -22,7 +22,7 @@ for f in $(find -name '*.re'); do
head -n $l "$ctest" > "$ctest".mod && mv "$ctest".mod "$ctest"
fi
g++ -fsanitize=leak -fsanitize=address -g -Wall -oexample "$ctest" \
g++ -fsanitize=leak -fsanitize=address -g -Wall -Wextra -oexample "$ctest" \
&& ./example 2>/dev/null || { echo "*** error ***"; exit 1; }
rm -f "$ctest" example
+5 -5
View File
@@ -14,7 +14,7 @@ static uint64_t parse_u32(const char *s) {
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case '0': goto yy2;
@@ -97,7 +97,7 @@ yy9:
bin:
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case 0x00: goto yy11;
@@ -119,7 +119,7 @@ yy13:
oct:
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case 0x00: goto yy15;
@@ -147,7 +147,7 @@ yy17:
dec:
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case 0x00: goto yy19;
@@ -177,7 +177,7 @@ yy21:
hex:
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case 0x00: goto yy23;
+1 -1
View File
@@ -13,7 +13,7 @@ static uint64_t parse_u32(const char *s) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = "unsigned char";
end = "\x00";
+1 -1
View File
@@ -21,7 +21,7 @@ static uint64_t parse_u32(const char *s) {
{
char yych;
unsigned char yych;
switch (c) {
case yycinit: goto yyc_init;
case yycbin: goto yyc_bin;
@@ -13,9 +13,9 @@ static uint64_t parse_u32(const char *s) {
/*!re2c
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYGETCONDITION = "c";
re2c:define:YYSETCONDITION = "c = @@;";
re2c:YYCTYPE = "unsigned char";
re2c:YYGETCOND = "c";
re2c:YYSETCOND = "c = @@;";
re2c:yyfill:enable = 0;
<*> * { return ERROR; }
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -7,7 +7,7 @@
static int lex(const char *s) {
const char *YYCURSOR = s, *YYMARKER;
/*!re2c
re2c:define:YYCTYPE = 'unsigned char';
re2c:YYCTYPE = "unsigned char";
re2c:yyfill:enable = 0;
// Simplified "Unicode Identifier and Pattern Syntax"
+1 -1
View File
@@ -11,7 +11,7 @@ static int lex(const char *YYCURSOR) {
#line 13 "c/eof/01_sentinel.c"
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case 0x00: goto yy1;
+1 -1
View File
@@ -7,7 +7,7 @@ static int lex(const char *YYCURSOR) {
for (;;) {
/*!re2c
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = "unsigned char";
re2c:yyfill:enable = 0;
* { return -1; }
+1 -1
View File
@@ -23,7 +23,7 @@ loop:
#line 25 "c/eof/02_bounds_checking.c"
{
char yych;
unsigned char yych;
if (YYLIMIT <= YYCURSOR) goto fail;
yych = *YYCURSOR;
switch (yych) {
+2 -2
View File
@@ -17,8 +17,8 @@ static int lex(const char *str, unsigned int len) {
loop:
/*!re2c
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYFILL = "goto fail;";
re2c:YYCTYPE = "unsigned char";
re2c:YYFILL = "goto fail;";
str = ['] ([^'\\] | [\\][^])* ['];
+1 -1
View File
@@ -12,7 +12,7 @@ static int lex(const char *str, unsigned int len) {
#line 14 "c/eof/03_eof_rule.c"
{
char yych;
unsigned char yych;
yych = *YYCURSOR;
switch (yych) {
case ' ': goto yy3;
+1 -1
View File
@@ -8,7 +8,7 @@ static int lex(const char *str, unsigned int len) {
for (;;) {
/*!re2c
re2c:define:YYCTYPE = char;
re2c:YYCTYPE = "unsigned char";
re2c:yyfill:enable = 0;
re2c:eof = 0;
+1 -1
View File
@@ -17,7 +17,7 @@ static int lex(const char *str, unsigned int len) {
#line 19 "c/eof/04_fake_sentinel.c"
{
char yych;
unsigned char yych;
yych = cur < lim ? *cur : 0;
switch (yych) {
case 0x00: goto yy1;
+4 -4
View File
@@ -14,11 +14,11 @@ static int lex(const char *str, unsigned int len) {
for (;;) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:api = custom;
re2c:api = generic;
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYPEEK = "cur < lim ? *cur : 0"; // fake null
re2c:define:YYSKIP = "++cur;";
re2c:YYCTYPE = "unsigned char";
re2c:YYPEEK = "cur < lim ? *cur : 0"; // fake null
re2c:YYSKIP = "++cur;";
* { count = -1; break; }
[\x00] { break;; }
+1 -1
View File
@@ -17,7 +17,7 @@ static int lex(const char *str, unsigned int len) {
#line 19 "c/eof/05_fake_sentinel_eof_rule.c"
{
char yych;
unsigned char yych;
yych = cur < lim ? *cur : 0;
switch (yych) {
case ' ': goto yy3;
+7 -7
View File
@@ -15,14 +15,14 @@ static int lex(const char *str, unsigned int len) {
/*!re2c
re2c:yyfill:enable = 0;
re2c:eof = 0;
re2c:api = custom;
re2c:api = generic;
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYLESSTHAN = "cur >= lim";
re2c:define:YYPEEK = "cur < lim ? *cur : 0"; // fake null
re2c:define:YYSKIP = "++cur;";
re2c:define:YYBACKUP = "mar = cur;";
re2c:define:YYRESTORE = "cur = mar;";
re2c:YYCTYPE = "unsigned char";
re2c:YYLESSTHAN = "cur >= lim";
re2c:YYPEEK = "cur < lim ? *cur : 0"; // fake null
re2c:YYSKIP = "++cur;";
re2c:YYBACKUP = "mar = cur;";
re2c:YYRESTORE = "cur = mar;";
str = ['] ([^'\\] | [\\][^])* ['];
+1 -1
View File
@@ -43,7 +43,7 @@ loop:
#line 45 "c/fill/01_fill.c"
{
char yych;
unsigned char yych;
yyFillLabel0:
yych = *in->cur;
switch (yych) {
+5 -5
View File
@@ -40,11 +40,11 @@ loop:
in->tok = in->cur;
/*!re2c
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = in->cur;
re2c:define:YYMARKER = in->mar;
re2c:define:YYLIMIT = in->lim;
re2c:define:YYFILL = "fill(in) == 0";
re2c:YYCTYPE = "unsigned char";
re2c:YYCURSOR = in->cur;
re2c:YYMARKER = in->mar;
re2c:YYLIMIT = in->lim;
re2c:YYFILL = "fill(in) == 0";
re2c:eof = 0;
str = ['] ([^'\\] | [\\][^])* ['];
+1 -1
View File
@@ -53,7 +53,7 @@ loop:
#line 55 "c/fill/02_fill.c"
{
char yych;
unsigned char yych;
if (in->lim <= in->cur) if (fill(in, 1) != 0) return -1;
yych = *in->cur;
switch (yych) {
+4 -4
View File
@@ -47,10 +47,10 @@ loop:
in->tok = in->cur;
/*!re2c
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = in->cur;
re2c:define:YYLIMIT = in->lim;
re2c:define:YYFILL = "if (fill(in, @@) != 0) return -1;";
re2c:YYCTYPE = "unsigned char";
re2c:YYCURSOR = in->cur;
re2c:YYLIMIT = in->lim;
re2c:YYFILL = "if (fill(in, @@) != 0) return -1;";
str = ['] ([^'\\] | [\\][^])* ['];
+1 -1
View File
@@ -12,7 +12,7 @@ static void convert_newlines(std::ifstream &in, std::ostringstream &out) {
#line 14 "c/generic_api/ifstream.c"
{
char yych;
unsigned char yych;
yych = in.peek();
switch (yych) {
case '\r': goto yy3;
+6 -6
View File
@@ -8,13 +8,13 @@ static void convert_newlines(std::ifstream &in, std::ostringstream &out) {
std::streampos mar;
for (;;) {
/*!re2c
re2c:api= custom;
re2c:api = generic;
re2c:api:style = free-form;
re2c:define:YYCTYPE = char;
re2c:define:YYPEEK = "in.peek()";
re2c:define:YYSKIP = "{ in.ignore(); if (in.eof()) return; }";
re2c:define:YYBACKUP = "mar = in.tellg();";
re2c:define:YYRESTORE = "in.seekg(mar);";
re2c:YYCTYPE = "unsigned char";
re2c:YYPEEK = "in.peek()";
re2c:YYSKIP = "{ in.ignore(); if (in.eof()) return; }";
re2c:YYBACKUP = "mar = in.tellg();";
re2c:YYRESTORE = "in.seekg(mar);";
re2c:yyfill:enable = 0;
* { out.put(yych); continue; }
+1 -1
View File
@@ -10,7 +10,7 @@ long lex(LexerState* st) {
const char *t;
{
char yych;
unsigned char yych;
goto yy0;
yy1:
++st->cur;
+2 -2
View File
@@ -15,8 +15,8 @@ long lex(LexerState* st) {
/*!re2c
re2c:header = "lexer/state.h";
re2c:yyfill:enable = 0;
re2c:define:YYCTYPE = char;
re2c:define:YYCURSOR = "st->cur";
re2c:YYCTYPE = "unsigned char";
re2c:YYCURSOR = "st->cur";
re2c:tags = 1;
re2c:tags:expression = "st->@@";

Some files were not shown because too many files have changed in this diff Show More