modernc.org/rec

Command rec compiles a subset of Go regular expressions to Go code. Installation The numbers below are for the regexp matching input while starting at a different position on each invocation. The ASCII input is a byte sequence. Bytes 0x00 to 0xff are treated as unicode runes 0x00 to 0xff. This format is selected by flags not ending in utf8, for example '-match'. The ASCII input is slightly faster to process than Unicode input. The Unicode input format interprets the byte sequences as UTF-8 encoded. The UTF-8 input is selected by flags ending in utf8, for example '-matchutf8'. The Unicode input is slightly slower to process than ASCII input. To run the compiler, invoke something like This will write a Go function definition (source code of) to stdout. The function will return the same result as For the Lex* machines the arguments are regexps for one or more lexems, like Flags that amend behavior. Use -i to generate case insensitive machines. Use -pkg to wrap the resulting function(s) in a package declaration. For example invoking will write to stdout Use -import to add a list of comma separated import paths, applicable only with -pkg. For example invoking will write to stdout Use -rx to make the produced machine become method of the flag argument, which must be a valid Go indentifier optionally prefixed with a single star ('*') character. For example invoking will write to stdout All available machines are listed below. Use -lex=<name> to produce a function implementing an ASCII []byte lexer, returning an regexp index and matched length in bytes or (-1, 0) if no lexeme was recognized. Use -lexstring=<name> to produce a function implementing an ASCII string lexer, returning an regexp index and matched length in bytes or (-1, 0) if no lexeme was recognized. Use -lexutf8=<name> to produce a function implementing an UTF8 []byte lexer, returning an regexp index and matched length in bytes or (-1, 0) if no lexeme was recognized. Use -lexstringutf8=<name> to produce a function implementing an UTF8 string lexer, returning an regexp index and matched length in bytes or (-1, 0) if no lexeme was recognized. Use -match=<name> to produce a function returning the same result as except the Match machine interprets 's' as ASCII. Use -matchstring=<name> to produce a function returning the same result as except the Match machine interprets 's' as ASCII. Use -matchutf8=<name> to produce a function returning the same result as The machine interprets 's' as UTF-8 encoded text. Use -matchstringutf8=<name> to produce a function returning the same result as The machine interprets 's' as UTF-8 encoded text.


License
BSD-3-Clause
Install
go get modernc.org/rec