/usr/share/doc/re2c/manual/syntax
**Free-form** This style is enabled with ``re2c:api:style = free-form;`` configuration, and it is the default for the Go backend. Interface primitives should be defined as free-form pieces of code with interpolated variables of the form ``@@{name}`` or optionally just ``@@`` if there is only one variable. The ``@@`` text can be customized with the ``re2c:api:sigil`` configuration. In Go free-form style generic API can be defined in terms of integer variables ``cursor``, ``limit``, ``marker``, ``ctxmarker`` and a string (or a byte slice) ``data`` as follows: .. code-block:: go /*!re2c re2c:define:YYPEEK = "data[cursor]"; re2c:define:YYSKIP = "cursor++"; re2c:define:YYBACKUP = "marker = cursor"; re2c:define:YYRESTORE = "cursor = marker"; re2c:define:YYBACKUPCTX = "ctxmarker = cursor"; re2c:define:YYRESTORECTX = "cursor = ctxmarker"; re2c:define:YYRESTORETAG = "cursor = ${tag}"; re2c:define:YYLESSTHAN = "limit - cursor < @@{len}"; re2c:define:YYSTAGP = "@@{tag} = cursor"; re2c:define:YYSTAGN = "@@{tag} = -1"; re2c:define:YYSHIFT = "cursor += @@{shift}"; re2c:define:YYSHIFTSTAG = "@@{tag} += @@{shift}"; */ | **Function-like** This style is enabled with ``re2c:api:style = functions;`` configuration. Primitives should be defined as functions with parentheses, accepting the necessary number of arguments. This style can be used with the Go backend, but it is more restrictive than the free-form style and some primitives are problematic to define. Most of the primitives can be defined as closures in terms of integer variables ``cursor``, ``limit``, ``marker``, ``ctxmarker`` and a string (or a byte slice) ``data``: .. code-block:: go YYPEEK := func() byte { return data[cursor] } YYSKIP := func() { cursor++ } YYBACKUP := func() { marker = cursor } YYRESTORE := func() { cursor = marker } YYBACKUPCTX := func() { ctxmarker = cursor } YYRESTORECTX := func() { cursor = ctxmarker } YYLESSTHAN := func(n int) bool { return limit-cursor < n } YYSHIFT := func(n int) { cursor += n }
.
Edit
..
Edit
api1.rst_
Edit
api2_c.rst_
Edit
api2_go.rst_
Edit
api3.rst_
Edit
syntax.rst_
Edit