Skip to content

Instantly share code, notes, and snippets.

@rofl0r
Created October 16, 2020 00:21
Show Gist options
  • Save rofl0r/16702d4b509038fc6f3fe8acacdf4573 to your computer and use it in GitHub Desktop.
Save rofl0r/16702d4b509038fc6f3fe8acacdf4573 to your computer and use it in GitHub Desktop.
// re2c $INPUT -o $OUTPUT
#include <assert.h>
#include <stdint.h>
#include <unistd.h>
/*!maxnmatch:re2c*/
static const uint64_t ERROR = ~0lu;
struct match {
size_t so, eo;
};
static uint64_t lex(const char *YYCURSOR, struct match matches[])
{
const char *YYMARKER;
const char *yypmatch[YYMAXNMATCH * 2];
const char *start = YYCURSOR;
uint32_t yynmatch;
/*!stags:re2c format = 'const char *@@;'; */
/*!re2c
re2c:yyfill:enable = 0;
re2c:flags:posix-captures = 1;
re2c:define:YYCTYPE = char;
ip = ((([0-9]{1,3})[.]){3}[0-9]{1,3}) ;
[ \t]* ("") [ \t]+ ((( ip ([/][0-9]+){0,1} )|(((([0-9a-f:]{2,39}))|(([0-9a-f:]{0,29}[:]((([0-9]{1,3})[.]){3}[0-9]{1,3}))))([/][0-9]+){0,1}))|([-a-z0-9._]+))[ \t\n]*[\x00] {
for(size_t x = 0; x < yynmatch; x++) {
matches[x].so = yypmatch[x*2] - start;
matches[x].eo = yypmatch[x*2+1] - start;
}
return yynmatch;
}
* { return ERROR; }
*/
}
int main()
{
struct match matches[YYMAXNMATCH];
uint64_t mno = lex(" 127.0.0.1/24", matches);
return mno;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment