diff --git a/Source/stringsfile.l b/Source/stringsfile.l new file mode 100644 index 000000000..bcf3eb836 --- /dev/null +++ b/Source/stringsfile.l @@ -0,0 +1,148 @@ +%{ +#include +#include +#include "stringsfile.tab.h" + +#ifdef sfwrap +#undef sfwrap +#endif + +int sfwrap() +{ +return 1; +} + +%} + + +quote \" +semicolen \; +equals \= +label [a-zA-Z][a-zA-Z0-9_]* +quoted [^"]*\" +whitespace [ \t\n] +startComment \/\* +endComment \*\/ + + +%x QUOTE COMMENT + + +%% + +{endComment} { BEGIN INITIAL; } + +. ; + +{quoted} { + if (sfleng == 1) + { + BEGIN INITIAL; + sflval.obj = [[[NSString alloc] init] autorelease]; + return QUOTED; + } + + if (sftext[sfleng - 2] == '\\') + yymore(); + else + { + BEGIN INITIAL; + sflval.obj = [[[NSString alloc] initWithCString: sftext length: sfleng - 1] autorelease]; + return QUOTED; + } + } + +{quote} {BEGIN QUOTE;} + +{startComment} {BEGIN COMMENT;} + +{label} { + sflval.obj = [NSString stringWithCString: sftext]; + return LABEL; + } + +{semicolen} {return SEMICOLEN;} + +{equals} {return EQUALS;} + +{whitespace}+ ; + + +. { return ERROR; } + +%% + +%{ +#include +#include +#include "stringsfile.tab.h" + +#ifdef sfwrap +#undef sfwrap +#endif + +int sfwrap() +{ +return 1; +} + +%} + + +quote \" +semicolen \; +equals \= +label [a-zA-Z][a-zA-Z0-9_]* +quoted [^"]*\" +whitespace [ \t\n] +startComment \/\* +endComment \*\/ + + +%x QUOTE COMMENT + + +%% + +{endComment} { BEGIN INITIAL; } + +. ; + +{quoted} { + if (sfleng == 1) + { + BEGIN INITIAL; + sflval.obj = [[[NSString alloc] init] autorelease]; + return QUOTED; + } + + if (sftext[sfleng - 2] == '\\') + yymore(); + else + { + BEGIN INITIAL; + sflval.obj = [[[NSString alloc] initWithCString: sftext length: sfleng - 1] autorelease]; + return QUOTED; + } + } + +{quote} {BEGIN QUOTE;} + +{startComment} {BEGIN COMMENT;} + +{label} { + sflval.obj = [NSString stringWithCString: sftext]; + return LABEL; + } + +{semicolen} {return SEMICOLEN;} + +{equals} {return EQUALS;} + +{whitespace}+ ; + + +. { return ERROR; } + +%% + diff --git a/Source/stringsfile.y b/Source/stringsfile.y new file mode 100644 index 000000000..3ce8a594c --- /dev/null +++ b/Source/stringsfile.y @@ -0,0 +1,130 @@ + +%{ +#include +#include +#include +static NSMutableDictionary *properties; + +%} + + +%token QUOTED LABEL +%token SEMICOLEN EQUALS ERROR + +%union { + id obj; +} + +%type value + +%% + +file: asignments + { + return 1; + } + | error + { + return 0; + } + | ERROR + { + return 0; + }; + + +asignments: asignment + | asignments asignment + ; + +asignment: value EQUALS value SEMICOLEN + { + [(NSMutableDictionary *)properties setObject: $3 forKey: (NSString *) $1]; + } + ; + +value: LABEL + { + $$ = $1; + } + | QUOTED + { + $$ = $1; + }; + +%% + +int sferror(char *s) +{ + return 0; +} + +sfSetDict(NSMutableDictionary *aDict) +{ + properties = aDict; +} + +%{ +#include +#include +#include +static NSMutableDictionary *properties; + +%} + + +%token QUOTED LABEL +%token SEMICOLEN EQUALS ERROR + +%union { + id obj; +} + +%type value + +%% + +file: asignments + { + return 1; + } + | error + { + return 0; + } + | ERROR + { + return 0; + }; + + +asignments: asignment + | asignments asignment + ; + +asignment: value EQUALS value SEMICOLEN + { + [(NSMutableDictionary *)properties setObject: $3 forKey: (NSString *) $1]; + } + ; + +value: LABEL + { + $$ = $1; + } + | QUOTED + { + $$ = $1; + }; + +%% + +int sferror(char *s) +{ + return 0; +} + +sfSetDict(NSMutableDictionary *aDict) +{ + properties = aDict; +}