From 9150d93f9c5d772a6e368839e48dab7647e36cd2 Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Thu, 31 Oct 1996 17:05:21 +0000 Subject: [PATCH] New file. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1882 72102866-910b-0410-8b05-ffd578937521 --- Source/stringsfile.l | 148 +++++++++++++++++++++++++++++++++++++++++++ Source/stringsfile.y | 130 +++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 Source/stringsfile.l create mode 100644 Source/stringsfile.y 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; +}