1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* read.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines to convert a string (legal ascii representation of node) back
|
|
|
|
* to nodes
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/nodes/read.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* HISTORY
|
1997-09-07 07:04:48 +02:00
|
|
|
* AUTHOR DATE MAJOR EVENT
|
|
|
|
* Andrew Yu Nov 2, 1994 file creation
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-10-31 11:22:13 +01:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include <ctype.h>
|
1999-07-16 07:00:38 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "nodes/pg_list.h"
|
|
|
|
#include "nodes/readfuncs.h"
|
2004-01-07 22:12:56 +01:00
|
|
|
#include "nodes/value.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
|
|
|
|
/* Static state for pg_strtok */
|
|
|
|
static char *pg_strtok_ptr = NULL;
|
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
|
|
|
* stringToNode -
|
1999-05-19 18:46:12 +02:00
|
|
|
* returns a Node with a given legal ASCII representation
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
void *
|
1996-07-09 08:22:35 +02:00
|
|
|
stringToNode(char *str)
|
|
|
|
{
|
2001-01-07 02:08:48 +01:00
|
|
|
char *save_strtok;
|
1997-09-08 04:41:22 +02:00
|
|
|
void *retval;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* We save and restore the pre-existing state of pg_strtok. This makes the
|
|
|
|
* world safe for re-entrant invocation of stringToNode, without incurring
|
|
|
|
* a lot of notational overhead by having to pass the next-character
|
|
|
|
* pointer around through all the readfuncs.c code.
|
2001-01-07 02:08:48 +01:00
|
|
|
*/
|
|
|
|
save_strtok = pg_strtok_ptr;
|
|
|
|
|
|
|
|
pg_strtok_ptr = str; /* point pg_strtok at the string to read */
|
|
|
|
|
2004-08-29 07:07:03 +02:00
|
|
|
retval = nodeRead(NULL, 0); /* do the reading */
|
2001-01-07 02:08:48 +01:00
|
|
|
|
|
|
|
pg_strtok_ptr = save_strtok;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return retval;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* the lisp token parser
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2000-01-14 01:53:21 +01:00
|
|
|
/*
|
2001-01-07 02:08:48 +01:00
|
|
|
* pg_strtok --- retrieve next "token" from a string.
|
2000-01-14 01:53:21 +01:00
|
|
|
*
|
|
|
|
* Works kinda like strtok, except it never modifies the source string.
|
|
|
|
* (Instead of storing nulls into the string, the length of the token
|
|
|
|
* is returned to the caller.)
|
|
|
|
* Also, the rules about what is a token are hard-wired rather than being
|
|
|
|
* configured by passing a set of terminating characters.
|
|
|
|
*
|
2001-01-07 02:08:48 +01:00
|
|
|
* The string is assumed to have been initialized already by stringToNode.
|
2000-01-14 01:53:21 +01:00
|
|
|
*
|
|
|
|
* The rules for tokens are:
|
2000-04-12 19:17:23 +02:00
|
|
|
* * Whitespace (space, tab, newline) always separates tokens.
|
|
|
|
* * The characters '(', ')', '{', '}' form individual tokens even
|
|
|
|
* without any whitespace around them.
|
|
|
|
* * Otherwise, a token is all the characters up to the next whitespace
|
|
|
|
* or occurrence of one of the four special characters.
|
|
|
|
* * A backslash '\' can be used to quote whitespace or one of the four
|
|
|
|
* special characters, so that it is treated as a plain token character.
|
|
|
|
* Backslashes themselves must also be backslashed for consistency.
|
|
|
|
* Any other character can be, but need not be, backslashed as well.
|
|
|
|
* * If the resulting token is '<>' (with no backslash), it is returned
|
|
|
|
* as a non-NULL pointer to the token but with length == 0. Note that
|
|
|
|
* there is no other way to get a zero-length token.
|
2000-01-14 01:53:21 +01:00
|
|
|
*
|
|
|
|
* Returns a pointer to the start of the next token, and the length of the
|
2000-04-12 19:17:23 +02:00
|
|
|
* token (including any embedded backslashes!) in *length. If there are
|
2000-01-14 01:53:21 +01:00
|
|
|
* no more tokens, NULL and 0 are returned.
|
|
|
|
*
|
|
|
|
* NOTE: this routine doesn't remove backslashes; the caller must do so
|
|
|
|
* if necessary (see "debackslash").
|
|
|
|
*
|
|
|
|
* NOTE: prior to release 7.0, this routine also had a special case to treat
|
2000-04-12 19:17:23 +02:00
|
|
|
* a token starting with '"' as extending to the next '"'. This code was
|
2000-01-14 01:53:21 +01:00
|
|
|
* broken, however, since it would fail to cope with a string containing an
|
|
|
|
* embedded '"'. I have therefore removed this special case, and instead
|
2000-04-12 19:17:23 +02:00
|
|
|
* introduced rules for using backslashes to quote characters. Higher-level
|
2000-01-14 01:53:21 +01:00
|
|
|
* code should add backslashes to a string constant to ensure it is treated
|
|
|
|
* as a single token.
|
|
|
|
*/
|
|
|
|
char *
|
2001-01-07 02:08:48 +01:00
|
|
|
pg_strtok(int *length)
|
2000-01-14 01:53:21 +01:00
|
|
|
{
|
|
|
|
char *local_str; /* working pointer to string */
|
|
|
|
char *ret_str; /* start of token to return */
|
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
local_str = pg_strtok_ptr;
|
2000-01-14 01:53:21 +01:00
|
|
|
|
|
|
|
while (*local_str == ' ' || *local_str == '\n' || *local_str == '\t')
|
|
|
|
local_str++;
|
|
|
|
|
|
|
|
if (*local_str == '\0')
|
|
|
|
{
|
|
|
|
*length = 0;
|
2001-01-07 02:08:48 +01:00
|
|
|
pg_strtok_ptr = local_str;
|
2000-01-14 01:53:21 +01:00
|
|
|
return NULL; /* no more tokens */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now pointing at start of next token.
|
|
|
|
*/
|
|
|
|
ret_str = local_str;
|
|
|
|
|
|
|
|
if (*local_str == '(' || *local_str == ')' ||
|
|
|
|
*local_str == '{' || *local_str == '}')
|
|
|
|
{
|
|
|
|
/* special 1-character token */
|
|
|
|
local_str++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Normal token, possibly containing backslashes */
|
|
|
|
while (*local_str != '\0' &&
|
|
|
|
*local_str != ' ' && *local_str != '\n' &&
|
|
|
|
*local_str != '\t' &&
|
|
|
|
*local_str != '(' && *local_str != ')' &&
|
|
|
|
*local_str != '{' && *local_str != '}')
|
|
|
|
{
|
|
|
|
if (*local_str == '\\' && local_str[1] != '\0')
|
|
|
|
local_str += 2;
|
|
|
|
else
|
|
|
|
local_str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*length = local_str - ret_str;
|
|
|
|
|
|
|
|
/* Recognize special case for "empty" token */
|
|
|
|
if (*length == 2 && ret_str[0] == '<' && ret_str[1] == '>')
|
|
|
|
*length = 0;
|
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
pg_strtok_ptr = local_str;
|
2000-01-14 01:53:21 +01:00
|
|
|
|
|
|
|
return ret_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* debackslash -
|
|
|
|
* create a palloc'd string holding the given token.
|
|
|
|
* any protective backslashes in the token are removed.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
debackslash(char *token, int length)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
char *result = palloc(length + 1);
|
|
|
|
char *ptr = result;
|
2000-01-14 01:53:21 +01:00
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
if (*token == '\\' && length > 1)
|
|
|
|
token++, length--;
|
|
|
|
*ptr++ = *token++;
|
|
|
|
length--;
|
|
|
|
}
|
|
|
|
*ptr = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#define RIGHT_PAREN (1000000 + 1)
|
1997-09-07 07:04:48 +02:00
|
|
|
#define LEFT_PAREN (1000000 + 2)
|
2004-05-06 16:01:33 +02:00
|
|
|
#define LEFT_BRACE (1000000 + 3)
|
2004-08-29 07:07:03 +02:00
|
|
|
#define OTHER_TOKEN (1000000 + 4)
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nodeTokenType -
|
1997-09-07 07:04:48 +02:00
|
|
|
* returns the type of the node token contained in token.
|
|
|
|
* It returns one of the following valid NodeTags:
|
2000-10-31 11:22:13 +01:00
|
|
|
* T_Integer, T_Float, T_String, T_BitString
|
1997-09-07 07:04:48 +02:00
|
|
|
* and some of its own:
|
2004-05-06 16:01:33 +02:00
|
|
|
* RIGHT_PAREN, LEFT_PAREN, LEFT_BRACE, OTHER_TOKEN
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Assumption: the ascii representation is legal
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static NodeTag
|
1996-07-09 08:22:35 +02:00
|
|
|
nodeTokenType(char *token, int length)
|
|
|
|
{
|
2000-01-14 01:53:21 +01:00
|
|
|
NodeTag retval;
|
2000-02-21 19:47:12 +01:00
|
|
|
char *numptr;
|
|
|
|
int numlen;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
2000-02-21 19:47:12 +01:00
|
|
|
* Check if the token is a number
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2000-02-21 19:47:12 +01:00
|
|
|
numptr = token;
|
|
|
|
numlen = length;
|
|
|
|
if (*numptr == '+' || *numptr == '-')
|
|
|
|
numptr++, numlen--;
|
2000-12-03 21:45:40 +01:00
|
|
|
if ((numlen > 0 && isdigit((unsigned char) *numptr)) ||
|
2005-10-15 04:49:52 +02:00
|
|
|
(numlen > 1 && *numptr == '.' && isdigit((unsigned char) numptr[1])))
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Yes. Figure out whether it is integral or float; this requires
|
2005-10-15 04:49:52 +02:00
|
|
|
* both a syntax check and a range check. strtol() can do both for us.
|
|
|
|
* We know the token will end at a character that strtol will stop at,
|
|
|
|
* so we do not need to modify the string.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
long val;
|
|
|
|
char *endptr;
|
2001-03-22 18:41:47 +01:00
|
|
|
|
2000-02-21 19:47:12 +01:00
|
|
|
errno = 0;
|
2001-03-22 18:41:47 +01:00
|
|
|
val = strtol(token, &endptr, 10);
|
|
|
|
if (endptr != token + length || errno == ERANGE
|
|
|
|
#ifdef HAVE_LONG_INT_64
|
2001-10-25 07:50:21 +02:00
|
|
|
/* if long > 32 bits, check for overflow of int4 */
|
2001-03-22 18:41:47 +01:00
|
|
|
|| val != (long) ((int32) val)
|
|
|
|
#endif
|
2001-10-25 07:50:21 +02:00
|
|
|
)
|
2000-02-21 19:47:12 +01:00
|
|
|
return T_Float;
|
|
|
|
return T_Integer;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-01-14 01:53:21 +01:00
|
|
|
/*
|
2001-01-07 02:08:48 +01:00
|
|
|
* these three cases do not need length checks, since pg_strtok() will
|
2000-04-12 19:17:23 +02:00
|
|
|
* always treat them as single-byte tokens
|
2000-01-14 01:53:21 +01:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
else if (*token == '(')
|
|
|
|
retval = LEFT_PAREN;
|
|
|
|
else if (*token == ')')
|
|
|
|
retval = RIGHT_PAREN;
|
|
|
|
else if (*token == '{')
|
2004-05-06 16:01:33 +02:00
|
|
|
retval = LEFT_BRACE;
|
2000-04-12 19:17:23 +02:00
|
|
|
else if (*token == '\"' && length > 1 && token[length - 1] == '\"')
|
2000-01-14 01:53:21 +01:00
|
|
|
retval = T_String;
|
2000-10-31 14:59:53 +01:00
|
|
|
else if (*token == 'b')
|
2000-10-31 11:22:13 +01:00
|
|
|
retval = T_BitString;
|
2000-01-14 01:53:21 +01:00
|
|
|
else
|
2004-05-06 16:01:33 +02:00
|
|
|
retval = OTHER_TOKEN;
|
1998-09-01 05:29:17 +02:00
|
|
|
return retval;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-14 01:53:21 +01:00
|
|
|
* nodeRead -
|
|
|
|
* Slightly higher-level reader.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-14 01:53:21 +01:00
|
|
|
* This routine applies some semantic knowledge on top of the purely
|
2001-01-07 02:08:48 +01:00
|
|
|
* lexical tokenizer pg_strtok(). It can read
|
2000-01-14 01:53:21 +01:00
|
|
|
* * Value token nodes (integers, floats, or strings);
|
2002-11-25 19:12:12 +01:00
|
|
|
* * General nodes (via parseNodeString() from readfuncs.c);
|
2004-05-08 23:21:18 +02:00
|
|
|
* * Lists of the above;
|
|
|
|
* * Lists of integers or OIDs.
|
2004-05-06 16:01:33 +02:00
|
|
|
* The return value is declared void *, not Node *, to avoid having to
|
|
|
|
* cast it explicitly in callers that assign to fields of different types.
|
|
|
|
*
|
|
|
|
* External callers should always pass NULL/0 for the arguments. Internally
|
|
|
|
* a non-NULL token may be passed when the upper recursion level has already
|
|
|
|
* scanned the first token of a node's representation.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-01-07 02:08:48 +01:00
|
|
|
* We assume pg_strtok is already initialized with a string to read (hence
|
|
|
|
* this should only be invoked from within a stringToNode operation).
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
void *
|
2004-05-06 16:01:33 +02:00
|
|
|
nodeRead(char *token, int tok_len)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2004-05-06 16:01:33 +02:00
|
|
|
Node *result;
|
2000-01-14 01:53:21 +01:00
|
|
|
NodeTag type;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2004-05-06 16:01:33 +02:00
|
|
|
if (token == NULL) /* need to read a token? */
|
|
|
|
{
|
|
|
|
token = pg_strtok(&tok_len);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2004-05-06 16:01:33 +02:00
|
|
|
if (token == NULL) /* end of input */
|
|
|
|
return NULL;
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
type = nodeTokenType(token, tok_len);
|
|
|
|
|
2010-01-18 23:19:34 +01:00
|
|
|
switch ((int) type)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2004-05-06 16:01:33 +02:00
|
|
|
case LEFT_BRACE:
|
|
|
|
result = parseNodeString();
|
2001-01-07 02:08:48 +01:00
|
|
|
token = pg_strtok(&tok_len);
|
|
|
|
if (token == NULL || token[0] != '}')
|
2003-07-23 01:30:39 +02:00
|
|
|
elog(ERROR, "did not find '}' at end of input node");
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
case LEFT_PAREN:
|
|
|
|
{
|
2004-05-06 16:01:33 +02:00
|
|
|
List *l = NIL;
|
|
|
|
|
2004-05-08 23:21:18 +02:00
|
|
|
/*----------
|
|
|
|
* Could be an integer list: (i int int ...)
|
|
|
|
* or an OID list: (o int int ...)
|
|
|
|
* or a list of nodes/values: (node node ...)
|
|
|
|
*----------
|
|
|
|
*/
|
|
|
|
token = pg_strtok(&tok_len);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "unterminated List structure");
|
|
|
|
if (tok_len == 1 && token[0] == 'i')
|
2004-05-06 16:01:33 +02:00
|
|
|
{
|
2004-05-08 23:21:18 +02:00
|
|
|
/* List of integers */
|
|
|
|
for (;;)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
int val;
|
|
|
|
char *endptr;
|
2004-05-08 23:21:18 +02:00
|
|
|
|
|
|
|
token = pg_strtok(&tok_len);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "unterminated List structure");
|
|
|
|
if (token[0] == ')')
|
|
|
|
break;
|
|
|
|
val = (int) strtol(token, &endptr, 10);
|
|
|
|
if (endptr != token + tok_len)
|
|
|
|
elog(ERROR, "unrecognized integer: \"%.*s\"",
|
|
|
|
tok_len, token);
|
2004-05-31 01:40:41 +02:00
|
|
|
l = lappend_int(l, val);
|
2004-05-08 23:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (tok_len == 1 && token[0] == 'o')
|
|
|
|
{
|
|
|
|
/* List of OIDs */
|
|
|
|
for (;;)
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
Oid val;
|
|
|
|
char *endptr;
|
2004-05-08 23:21:18 +02:00
|
|
|
|
|
|
|
token = pg_strtok(&tok_len);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "unterminated List structure");
|
|
|
|
if (token[0] == ')')
|
|
|
|
break;
|
|
|
|
val = (Oid) strtoul(token, &endptr, 10);
|
|
|
|
if (endptr != token + tok_len)
|
|
|
|
elog(ERROR, "unrecognized OID: \"%.*s\"",
|
|
|
|
tok_len, token);
|
2004-05-31 01:40:41 +02:00
|
|
|
l = lappend_oid(l, val);
|
2004-05-08 23:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* List of other node types */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* We have already scanned next token... */
|
|
|
|
if (token[0] == ')')
|
|
|
|
break;
|
|
|
|
l = lappend(l, nodeRead(token, tok_len));
|
|
|
|
token = pg_strtok(&tok_len);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "unterminated List structure");
|
|
|
|
}
|
2004-05-06 16:01:33 +02:00
|
|
|
}
|
|
|
|
result = (Node *) l;
|
|
|
|
break;
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
case RIGHT_PAREN:
|
2004-05-06 16:01:33 +02:00
|
|
|
elog(ERROR, "unexpected right parenthesis");
|
2004-08-29 07:07:03 +02:00
|
|
|
result = NULL; /* keep compiler happy */
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
2004-05-06 16:01:33 +02:00
|
|
|
case OTHER_TOKEN:
|
2000-01-14 01:53:21 +01:00
|
|
|
if (tok_len == 0)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2004-05-06 16:01:33 +02:00
|
|
|
/* must be "<>" --- represents a null pointer */
|
|
|
|
result = NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-06 16:01:33 +02:00
|
|
|
elog(ERROR, "unrecognized token: \"%.*s\"", tok_len, token);
|
|
|
|
result = NULL; /* keep compiler happy */
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
case T_Integer:
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* we know that the token terminates on a char atol will stop at
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
2004-05-06 16:01:33 +02:00
|
|
|
result = (Node *) makeInteger(atol(token));
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
2000-02-21 19:47:12 +01:00
|
|
|
case T_Float:
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
char *fval = (char *) palloc(tok_len + 1);
|
2000-02-21 19:47:12 +01:00
|
|
|
|
|
|
|
memcpy(fval, token, tok_len);
|
|
|
|
fval[tok_len] = '\0';
|
2004-05-06 16:01:33 +02:00
|
|
|
result = (Node *) makeFloat(fval);
|
2000-02-21 19:47:12 +01:00
|
|
|
}
|
|
|
|
break;
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_String:
|
2000-02-21 19:47:12 +01:00
|
|
|
/* need to remove leading and trailing quotes, and backslashes */
|
2004-05-06 16:01:33 +02:00
|
|
|
result = (Node *) makeString(debackslash(token + 1, tok_len - 2));
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
2000-10-31 11:22:13 +01:00
|
|
|
case T_BitString:
|
2001-03-22 05:01:46 +01:00
|
|
|
{
|
|
|
|
char *val = palloc(tok_len);
|
|
|
|
|
|
|
|
/* skip leading 'b' */
|
2006-09-27 20:40:10 +02:00
|
|
|
memcpy(val, token + 1, tok_len - 1);
|
2001-03-22 05:01:46 +01:00
|
|
|
val[tok_len - 1] = '\0';
|
2004-05-06 16:01:33 +02:00
|
|
|
result = (Node *) makeBitString(val);
|
2001-03-22 05:01:46 +01:00
|
|
|
break;
|
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
2003-07-23 01:30:39 +02:00
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) type);
|
2004-08-29 07:07:03 +02:00
|
|
|
result = NULL; /* keep compiler happy */
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2004-05-06 16:01:33 +02:00
|
|
|
return (void *) result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|