Skip to content

End of input ($) rule deemed invalid when Posix captures enabled #564

Description

@RadhiFadlillah

I have the following code:

func findDayYearPattern(input []byte) int {
	var count int
	var cursor, marker int
	input = append(input, byte(0)) // add terminating null
	limit := len(input) - 1        // lim points at the terminating null

	// Variable for capturing parentheses (twice the number of groups).
	/*!maxnmatch:re2c*/
	yypmatch := make([]int, YYMAXNMATCH*2)
	var yynmatch int
	_ = yynmatch

	// Autogenerated tag variables used by the lexer to track tag values.
	/*!stags:re2c format = 'var @@ int; _ = @@\n'; */

	for { /*!re2c
		re2c:posix-captures   = 1;
		re2c:case-insensitive = 1;
		re2c:eof              = 0;
		re2c:yyfill:enable    = 0;

		re2c:define:YYCTYPE     = byte;
		re2c:define:YYPEEK      = "input[cursor]";
		re2c:define:YYSKIP      = "cursor++";
		re2c:define:YYBACKUP    = "marker = cursor";
		re2c:define:YYRESTORE   = "cursor = marker";
		re2c:define:YYLESSTHAN  = "limit <= cursor";
		re2c:define:YYSTAGP     = "@@{tag} = cursor";
		re2c:define:YYSTAGN     = "@@{tag} = -1";
		re2c:define:YYSHIFTSTAG = "@@{tag} += @@{shift}";

		rxDay = ([0-3]?[0-9]);
		rxYear = (199[0-9]|20[0-3][0-9]);

		{rxDay} { count++; continue }
		{rxYear} { count++; continue }

		* { continue }
		$ { return count }
		*/
	}
}

Back in re2go version 3.1 this compiled nicely, but now in version 4.3 it failed with following message:

error: end of input marker $ in the middle of a rule is not supported

You can check it out here in the playground.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions