Created
June 2, 2017 20:49
-
-
Save wking/ac0298774c58d448cb9a37913a9da4c8 to your computer and use it in GitHub Desktop.
ABNF with APG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone git://github.com/ldthomas/apg-6.3.git | |
$ cd apg-6.3 | |
$ ./configure | |
$ make | |
$ cat <<EOF >>ref.abnf | |
> ref = component *("/" component) | |
> component = alphanum *(separator alphanum) | |
> alphanum = 1*(ALPHA / DIGIT) | |
> separator = "--" / "-" / "." / "_" / ":" / "@" / "+" | |
> ALPHA = %x41-5A / %x61-7A | |
> DIGIT = %x30-39 | |
> EOF | |
$ ./apg /in:ref.abnf /C:ref | |
… | |
*** C parser generated | |
ref.h | |
ref.c | |
$ cat main.c | |
$ cat <<EOF >>main.c | |
> #include <stdio.h> | |
> #include "Apg.h" | |
> #include "ref.h" | |
> | |
> int main(void) { | |
> apg_achar s[100]; | |
> fgets(s, 100, stdin); | |
> void *parser = vpParserCtor(vpParserInit_ref, NULL); | |
> vTraceCtor(parser); | |
> apg_uint rc = uiParserSyntaxAnalysis(parser, RULE_REF_REF, s, strnlen(s, 100), NULL); | |
> vTraceDtor(parser); | |
> vParserDtor(parser); | |
> if (rc) { | |
> printf("success\n"); | |
> } else { | |
> printf("failure\n"); | |
> } | |
> return !rc; | |
> } | |
> EOF | |
$ cc -D_APG_CFG_TRACE -o ref main.c ref.c ApgLib/*.c -I ApgLib | |
$ echo -n foo/bar--baz | ./ref | grep ':M:.*component\|success\|failure' | |
76: 3: 2:M:--RNM(component):3:foo | |
210: 81: 2:M:--RNM(component):8:bar--baz | |
success | |
$ echo -n ~foo | ./ref | grep ':M:.*component\|success\|failure' | |
failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment