Created
April 2, 2015 02:04
-
-
Save FlyingJester/4d35d3b425c7c1bce5bb to your computer and use it in GitHub Desktop.
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
| int FlareParseString_C_1(const char * const string, const char *old_start, size_t len, void(*parse_callback_)(const char *, size_t, enum FlareFormat_C, void *), void *arg_){ | |
| const char *at = string; | |
| unsigned skipped = 0; /* This will be used for term checking in case of UTF-8, non-ascii spaces. */ | |
| if(!((*string!='\0') && len)){ | |
| parse_callback_(old_start, string-old_start, e_c_normal, arg_); | |
| return 1; | |
| } | |
| if(memcmp(string, "//", FULLMETAL_MIN(2, len))==0){ | |
| at+=2; | |
| if(!FlareParseString_C_comment1(&at, &len)) | |
| return 0; | |
| parse_callback_(string, at-string, e_c_comment, arg_); | |
| } | |
| else if(memcmp(string, "/*", FULLMETAL_MIN(2, len))==0){ | |
| at+=2; | |
| if(!FlareParseString_C_comment2(&at, &len)) | |
| return 0; | |
| parse_callback_(string, at-string, e_c_comment, arg_); | |
| } | |
| else if(*string=='#'){ | |
| at++; | |
| if(!FlareParseString_C_preprocessor(&at, &len)) | |
| return 0; | |
| parse_callback_(string, at-string, e_c_comment, arg_); | |
| } | |
| else if(*string=='"'){ | |
| at++; | |
| if(!FlareParseString_C_stringliteral(&at, &len)) | |
| return 0; | |
| parse_callback_(string, at-string, e_c_stringliteral, arg_); | |
| } | |
| else if(*string=='\''){ | |
| at++; | |
| if(!FlareParseString_C_charliteral(&at, &len)) | |
| return 0; | |
| parse_callback_(string, at-string, e_c_charliteral, arg_); | |
| } /* Keywords */ | |
| else if(FlareTermSurroundedBySpaces(string, "char", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "short", 5, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "int", 3, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "long", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "unsigned", 8, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "signed", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "struct", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "void", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "int8_t", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "int16_t", 7, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "int32_t", 7, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "uint8_t", 7, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "uint16_t", 8, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "uint32_t", 8, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "size_t", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "float", 5, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "double", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "if", 2, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "else", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "do", 2, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "while", 5, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "for", 3, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "return", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "switch", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "continue", 8, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "break", 5, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "typedef", 7, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "default", 7, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "case", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "enum", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "goto", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "auto", 4, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "register", 8, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "inline", 6, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "const", 5, len, &skipped) || | |
| FlareTermSurroundedBySpaces(string, "static", 6, len, &skipped)){ | |
| const unsigned first_len = fl_utf8len(*string); | |
| at+=skipped; | |
| parse_callback_(string+first_len, skipped-first_len, e_c_keyword, arg_); | |
| } | |
| else{ | |
| at++; | |
| len--; | |
| goto ending; | |
| } | |
| assert(at!=string); | |
| if(string!=old_start){ | |
| parse_callback_(old_start, string-old_start, e_c_normal, arg_); | |
| } | |
| if(!((at[0]!='\0') && len)) return 1; | |
| len-=at-string; | |
| old_start = at; | |
| ending: | |
| return FlareParseString_C_1(at, old_start, len, parse_callback_, arg_); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment