diff options
| author | Bruce Momjian | 1997-09-08 03:20:18 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1997-09-08 03:20:18 +0000 |
| commit | 23db70bf73ed913df0c8fda1e43ffe40b8980735 (patch) | |
| tree | d78b4b8c124370c1dd2d129033f2d41b87aec7c8 /src/backend/bootstrap | |
| parent | 319dbfa7364721d3343af03a7ce063c2a2c9d385 (diff) | |
Lex/yacc source cleanup like indent.
Diffstat (limited to 'src/backend/bootstrap')
| -rw-r--r-- | src/backend/bootstrap/bootparse.y | 418 | ||||
| -rw-r--r-- | src/backend/bootstrap/bootscanner.l | 120 |
2 files changed, 273 insertions, 265 deletions
diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index c27eabe969f..efc4078662c 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -2,13 +2,13 @@ /*------------------------------------------------------------------------- * * backendparse.y-- - * yacc parser grammer for the "backend" initialization program. + * yacc parser grammer for the "backend" initialization program. * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.4 1996/11/13 20:47:45 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.5 1997/09/08 03:19:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,11 +16,11 @@ #include "postgres.h" #include "catalog/pg_attribute.h" -#include "access/attnum.h" +#include "access/attnum.h" #include "nodes/pg_list.h" -#include "access/tupdesc.h" +#include "access/tupdesc.h" #include "storage/fd.h" -#include "catalog/pg_am.h" +#include "catalog/pg_am.h" #include "catalog/pg_class.h" #include "nodes/nodes.h" #include "rewrite/prs2lock.h" @@ -57,24 +57,27 @@ #include "miscadmin.h" -#define DO_START { StartTransactionCommand();\ - } +#define DO_START { \ + StartTransactionCommand();\ + } -#define DO_END { CommitTransactionCommand();\ - if (!Quiet) { EMITPROMPT; }\ - fflush(stdout); \ - } +#define DO_END { \ + CommitTransactionCommand();\ + if (!Quiet) { EMITPROMPT; }\ + fflush(stdout); \ + } int num_tuples_read = 0; static Oid objectid; %} -%union { - List *list; - IndexElem *ielem; - char *str; - int ival; +%union +{ + List *list; + IndexElem *ielem; + char *str; + int ival; } %type <list> arg_list @@ -84,7 +87,7 @@ static Oid objectid; %token <ival> CONST ID %token OPEN XCLOSE XCREATE INSERT_TUPLE -%token STRING XDEFINE +%token STRING XDEFINE %token XDECLARE INDEX ON USING XBUILD INDICES %token COMMA EQUALS LPAREN RPAREN %token OBJ_ID XBOOTSTRAP NULLVAL @@ -96,228 +99,233 @@ static Oid objectid; %% TopLevel: - Queries - | - ; + Queries + | + ; Queries: - Query - | Queries Query - ; + Query + | Queries Query + ; Query : - OpenStmt - | CloseStmt - | CreateStmt - | InsertStmt - | DeclareIndexStmt - | BuildIndsStmt - ; - -OpenStmt: - OPEN ident - { - DO_START; - boot_openrel(LexIDStr($2)); - DO_END; - } - ; + OpenStmt + | CloseStmt + | CreateStmt + | InsertStmt + | DeclareIndexStmt + | BuildIndsStmt + ; + +OpenStmt: + OPEN ident + { + DO_START; + boot_openrel(LexIDStr($2)); + DO_END; + } + ; CloseStmt: - XCLOSE ident %prec low - { - DO_START; - closerel(LexIDStr($2)); - DO_END; - } - | XCLOSE %prec high - { - DO_START; - closerel(NULL); - DO_END; - } - ; + XCLOSE ident %prec low + { + DO_START; + closerel(LexIDStr($2)); + DO_END; + } + | XCLOSE %prec high + { + DO_START; + closerel(NULL); + DO_END; + } + ; CreateStmt: - XCREATE optbootstrap ident LPAREN - { - DO_START; - numattr=(int)0; - } - typelist - { - if (!Quiet) putchar('\n'); - DO_END; - } - RPAREN - { - DO_START; - - if ($2) { - extern Relation reldesc; - TupleDesc tupdesc; - - if (reldesc) { - puts("create bootstrap: Warning, open relation"); - puts("exists, closing first"); - closerel(NULL); - } - if (DebugMode) - puts("creating bootstrap relation"); - tupdesc = CreateTupleDesc(numattr,attrtypes); - reldesc = heap_creatr(LexIDStr($3), - DEFAULT_SMGR, - tupdesc); - if (DebugMode) - puts("bootstrap relation created ok"); - } else { - Oid id; - TupleDesc tupdesc; - /* extern Oid heap_create();*/ - - tupdesc = CreateTupleDesc(numattr,attrtypes); - id = heap_create(LexIDStr($3), - NULL, - 'n', - DEFAULT_SMGR, - tupdesc); - if (!Quiet) - printf("CREATED relation %s with OID %d\n", - LexIDStr($3), id); - } - DO_END; - if (DebugMode) - puts("Commit End"); - } - ; + XCREATE optbootstrap ident LPAREN + { + DO_START; + numattr=(int)0; + } + typelist + { + if (!Quiet) + putchar('\n'); + DO_END; + } + RPAREN + { + DO_START; + + if ($2) + { + extern Relation reldesc; + TupleDesc tupdesc; + + if (reldesc) + { + puts("create bootstrap: Warning, open relation"); + puts("exists, closing first"); + closerel(NULL); + } + if (DebugMode) + puts("creating bootstrap relation"); + tupdesc = CreateTupleDesc(numattr,attrtypes); + reldesc = heap_creatr(LexIDStr($3), + DEFAULT_SMGR, + tupdesc); + if (DebugMode) + puts("bootstrap relation created ok"); + } + else + { + Oid id; + TupleDesc tupdesc; + /* extern Oid heap_create();*/ + + tupdesc = CreateTupleDesc(numattr,attrtypes); + id = heap_create(LexIDStr($3), + NULL, + 'n', + DEFAULT_SMGR, + tupdesc); + if (!Quiet) + printf("CREATED relation %s with OID %d\n", + LexIDStr($3), id); + } + DO_END; + if (DebugMode) + puts("Commit End"); + } + ; InsertStmt: - INSERT_TUPLE optoideq - { - DO_START; - if (DebugMode) - printf("tuple %d<", $2); - num_tuples_read = 0; - } - LPAREN tuplelist RPAREN - { - if (num_tuples_read != numattr) - elog(WARN,"incorrect number of values for tuple"); - if (reldesc == (Relation)NULL) { - elog(WARN,"must OPEN RELATION before INSERT\n"); - err_out(); - } - if (DebugMode) - puts("Insert Begin"); - objectid = $2; - InsertOneTuple(objectid); - if (DebugMode) - puts("Insert End"); - if (!Quiet) { putchar('\n'); } - DO_END; - if (DebugMode) - puts("Transaction End"); - } - ; + INSERT_TUPLE optoideq + { + DO_START; + if (DebugMode) + printf("tuple %d<", $2); + num_tuples_read = 0; + } + LPAREN tuplelist RPAREN + { + if (num_tuples_read != numattr) + elog(WARN,"incorrect number of values for tuple"); + if (reldesc == (Relation)NULL) + { + elog(WARN,"must OPEN RELATION before INSERT\n"); + err_out(); + } + if (DebugMode) + puts("Insert Begin"); + objectid = $2; + InsertOneTuple(objectid); + if (DebugMode) + puts("Insert End"); + if (!Quiet) + putchar('\n'); + DO_END; + if (DebugMode) + puts("Transaction End"); + } + ; DeclareIndexStmt: - XDECLARE INDEX ident ON ident USING ident LPAREN index_params RPAREN - { - List *params; + XDECLARE INDEX ident ON ident USING ident LPAREN index_params RPAREN + { + List *params; - DO_START; + DO_START; - params = lappend(NIL, (List*)$9); - DefineIndex(LexIDStr($5), - LexIDStr($3), - LexIDStr($7), - params, NIL, 0, 0, NIL); - DO_END; - } - ; + params = lappend(NIL, (List*)$9); + DefineIndex(LexIDStr($5), + LexIDStr($3), + LexIDStr($7), + params, NIL, 0, 0, NIL); + DO_END; + } + ; BuildIndsStmt: - XBUILD INDICES { build_indices(); } + XBUILD INDICES { build_indices(); } index_params: - index_on ident - { - IndexElem *n = (IndexElem*)$1; - n->class = LexIDStr($2); - $$ = n; - } + index_on ident + { + IndexElem *n = (IndexElem*)$1; + n->class = LexIDStr($2); + $$ = n; + } index_on: - ident - { - IndexElem *n = makeNode(IndexElem); - n->name = LexIDStr($1); - $$ = n; - } - | ident LPAREN arg_list RPAREN - { - IndexElem *n = makeNode(IndexElem); - n->name = LexIDStr($1); - n->args = (List*)$3; - $$ = n; - } + ident + { + IndexElem *n = makeNode(IndexElem); + n->name = LexIDStr($1); + $$ = n; + } + | ident LPAREN arg_list RPAREN + { + IndexElem *n = makeNode(IndexElem); + n->name = LexIDStr($1); + n->args = (List*)$3; + $$ = n; + } arg_list: - ident - { - $$ = lappend(NIL, makeString(LexIDStr($1))); - } - | arg_list COMMA ident - { - $$ = lappend((List*)$1, makeString(LexIDStr($3))); - } - + ident + { + $$ = lappend(NIL, makeString(LexIDStr($1))); + } + | arg_list COMMA ident + { + $$ = lappend((List*)$1, makeString(LexIDStr($3))); + } + optbootstrap: - XBOOTSTRAP { $$ = 1; } - | { $$ = 0; } - ; + XBOOTSTRAP { $$ = 1; } + | { $$ = 0; } + ; typelist: - typething - | typelist COMMA typething - ; + typething + | typelist COMMA typething + ; typething: - ident EQUALS ident - { - if(++numattr > MAXATTR) - elog(FATAL,"Too many attributes\n"); - DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1); - if (DebugMode) - printf("\n"); - } - ; + ident EQUALS ident + { + if(++numattr > MAXATTR) + elog(FATAL,"Too many attributes\n"); + DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1); + if (DebugMode) + printf("\n"); + } + ; optoideq: - OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3)); } - | { extern Oid newoid(); $$ = newoid(); } - ; + OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3)); } + | { extern Oid newoid(); $$ = newoid(); } + ; tuplelist: - tuple - | tuplelist tuple - | tuplelist COMMA tuple - ; + tuple + | tuplelist tuple + | tuplelist COMMA tuple + ; tuple: - ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); } - | const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); } - | NULLVAL - { InsertOneNull(num_tuples_read++); } - ; - + ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); } + | const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); } + | NULLVAL + { InsertOneNull(num_tuples_read++); } + ; + const : - CONST { $$=yylval.ival; } - ; + CONST { $$=yylval.ival; } + ; ident : - ID { $$=yylval.ival; } - ; + ID { $$=yylval.ival; } + ; %% - - diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l index f6cb8468724..54108fe5b66 100644 --- a/src/backend/bootstrap/bootscanner.l +++ b/src/backend/bootstrap/bootscanner.l @@ -2,13 +2,13 @@ /*------------------------------------------------------------------------- * * bootscanner.lex-- - * a lexical scanner for the bootstrap parser + * a lexical scanner for the bootstrap parser * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.6 1997/01/10 20:16:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.7 1997/09/08 03:19:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,7 +29,7 @@ #include "storage/fd.h" #include "catalog/pg_am.h" #include "catalog/pg_class.h" -#include "nodes/nodes.h" +#include "nodes/nodes.h" #include "rewrite/prs2lock.h" #include "access/skey.h" #include "access/strat.h" @@ -38,7 +38,7 @@ #include "nodes/primnodes.h" #include "utils/nabstime.h" -#include "access/htup.h" +#include "access/htup.h" #include "utils/tqual.h" #include "nodes/parsenodes.h" @@ -46,82 +46,82 @@ #include "bootstrap_tokens.h" -#define YY_NO_UNPUT +#define YY_NO_UNPUT /* some versions of lex define this as a macro */ #if defined(yywrap) #undef yywrap #endif /* yywrap */ -YYSTYPE yylval; -int yyline; /* keep track of the line number for error reporting */ +YYSTYPE yylval; +int yyline; /* keep track of the line number for error reporting */ %} -D [0-9] -oct \\{D}{D}{D} -Exp [Ee][-+]?{D}+ -id ([A-Za-z0-9_]|{oct}|\-)+ -sid \"([^\"])*\" -arrayid [A-Za-z0-9_]+\[{D}*\] +D [0-9] +oct \\{D}{D}{D} +Exp [Ee][-+]?{D}+ +id ([A-Za-z0-9_]|{oct}|\-)+ +sid \"([^\"])*\" +arrayid [A-Za-z0-9_]+\[{D}*\] %% -open { return(OPEN); } +open { return(OPEN); } -close { return(XCLOSE); } +close { return(XCLOSE); } -create { return(XCREATE); } +create { return(XCREATE); } -OID { return(OBJ_ID); } -bootstrap { return(XBOOTSTRAP); } -_null_ { return(NULLVAL); } +OID { return(OBJ_ID); } +bootstrap { return(XBOOTSTRAP); } +_null_ { return(NULLVAL); } -insert { return(INSERT_TUPLE); } +insert { return(INSERT_TUPLE); } -"," { return(COMMA); } -"=" { return(EQUALS); } -"(" { return(LPAREN); } -")" { return(RPAREN); } +"," { return(COMMA); } +"=" { return(EQUALS); } +"(" { return(LPAREN); } +")" { return(RPAREN); } -[\n] { yyline++; } -[\t] ; -" " ; +[\n] { yyline++; } +[\t] ; +" " ; ^\#[^\n]* ; /* drop everything after "#" for comments */ -"declare" { return(XDECLARE); } -"build" { return(XBUILD); } -"indices" { return(INDICES); } -"index" { return(INDEX); } -"on" { return(ON); } -"using" { return(USING); } -{arrayid} { - yylval.ival = EnterString(MapArrayTypeName((char*)yytext)); - return(ID); - } -{id} { - yylval.ival = EnterString(scanstr((char*)yytext)); - return(ID); - } -{sid} { - yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */ - yylval.ival = EnterString(scanstr((char*)yytext+1)); - yytext[strlen(yytext)] = '"'; /* restore quotes */ - return(ID); - } - -(-)?{D}+"."{D}*({Exp})? | -(-)?{D}*"."{D}+({Exp})? | -(-)?{D}+{Exp} { - yylval.ival = EnterString((char*)yytext); - return(CONST); - } - -. { - printf("syntax error %d : -> %s\n", yyline, yytext); - } +"declare" { return(XDECLARE); } +"build" { return(XBUILD); } +"indices" { return(INDICES); } +"index" { return(INDEX); } +"on" { return(ON); } +"using" { return(USING); } +{arrayid} { + yylval.ival = EnterString(MapArrayTypeName((char*)yytext)); + return(ID); + } +{id} { + yylval.ival = EnterString(scanstr((char*)yytext)); + return(ID); + } +{sid} { + yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */ + yylval.ival = EnterString(scanstr((char*)yytext+1)); + yytext[strlen(yytext)] = '"'; /* restore quotes */ + return(ID); + } + +(-)?{D}+"."{D}*({Exp})? | +(-)?{D}*"."{D}+({Exp})? | +(-)?{D}+{Exp} { + yylval.ival = EnterString((char*)yytext); + return(CONST); + } + +. { + printf("syntax error %d : -> %s\n", yyline, yytext); + } @@ -130,11 +130,11 @@ insert { return(INSERT_TUPLE); } int yywrap(void) { - return 1; + return 1; } void yyerror(const char *str) { - fprintf(stderr,"\tsyntax error %d : %s",yyline, str); + fprintf(stderr,"\tsyntax error %d : %s",yyline, str); } |
