This commit is contained in:
hyung-hwan 2008-07-12 08:41:16 +00:00
parent fbfa20f040
commit e71d5af472
3 changed files with 40 additions and 10 deletions

View File

@ -877,7 +877,8 @@ static struct
{ ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN }, { ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN },
{ ASE_T("reset"), ASE_AWK_RESET }, { ASE_T("reset"), ASE_AWK_RESET },
{ ASE_T("maptovar"), ASE_AWK_MAPTOVAR }, { ASE_T("maptovar"), ASE_AWK_MAPTOVAR },
{ ASE_T("pablock"), ASE_AWK_PABLOCK } { ASE_T("pablock"), ASE_AWK_PABLOCK },
{ ASE_T("newline"), ASE_AWK_NEWLINE }
}; };
static void print_usage (const ase_char_t* argv0) static void print_usage (const ase_char_t* argv0)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.hpp 195 2008-06-06 13:01:55Z baconevi $ * $Id: Awk.hpp 240 2008-07-11 14:41:16Z baconevi $
* *
* {License} * {License}
*/ */
@ -548,6 +548,7 @@ public:
OPT_BLOCKLESS = ASE_AWK_BLOCKLESS, OPT_BLOCKLESS = ASE_AWK_BLOCKLESS,
OPT_BASEONE = ASE_AWK_BASEONE, OPT_BASEONE = ASE_AWK_BASEONE,
OPT_STRIPSPACES = ASE_AWK_STRIPSPACES, OPT_STRIPSPACES = ASE_AWK_STRIPSPACES,
/** Support the nextofile statement */ /** Support the nextofile statement */
OPT_NEXTOFILE = ASE_AWK_NEXTOFILE, OPT_NEXTOFILE = ASE_AWK_NEXTOFILE,
/** Use CR+LF instead of LF for line breaking. */ /** Use CR+LF instead of LF for line breaking. */
@ -563,7 +564,9 @@ public:
/** Allows the assignment of a map value to a variable */ /** Allows the assignment of a map value to a variable */
OPT_MAPTOVAR = ASE_AWK_MAPTOVAR, OPT_MAPTOVAR = ASE_AWK_MAPTOVAR,
/** Allows BEGIN, END, pattern-action blocks */ /** Allows BEGIN, END, pattern-action blocks */
OPT_PABLOCK = ASE_AWK_PABLOCK OPT_PABLOCK = ASE_AWK_PABLOCK,
/** Can terminate a statement with a new line */
OPT_NEWLINE = ASE_AWK_NEWLINE
}; };
// end of enum Option // end of enum Option

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 239 2008-07-11 11:07:17Z baconevi $ * $Id: parse.c 240 2008-07-11 14:41:16Z baconevi $
* *
* {License} * {License}
*/ */
@ -521,9 +521,17 @@ static int parse (ase_awk_t* awk)
while (1) while (1)
{ {
if (MATCH(awk,TOKEN_EOF)) break; if (MATCH(awk,TOKEN_EOF)) break;
if (MATCH(awk,TOKEN_NEWLINE)) continue; if (MATCH(awk,TOKEN_NEWLINE))
{
if (get_token(awk) == -1)
{
n = -1;
goto exit_parse;
}
continue;
}
if (parse_progunit (awk) == ASE_NULL) if (parse_progunit(awk) == ASE_NULL)
{ {
n = -1; n = -1;
goto exit_parse; goto exit_parse;
@ -592,6 +600,9 @@ exit_parse:
static ase_awk_t* parse_progunit (ase_awk_t* awk) static ase_awk_t* parse_progunit (ase_awk_t* awk)
{ {
/* /*
global xxx, xxxx;
BEGIN { action }
END { action }
pattern { action } pattern { action }
function name (parameter-list) { statement } function name (parameter-list) { statement }
*/ */
@ -4358,11 +4369,14 @@ static ase_awk_nde_t* parse_print (ase_awk_t* awk, ase_size_t line, int type)
while (MATCH(awk,TOKEN_COMMA)) while (MATCH(awk,TOKEN_COMMA))
{ {
if (get_token(awk) == -1) do {
{ if (get_token(awk) == -1)
ase_awk_clrpt (awk, args); {
return ASE_NULL; ase_awk_clrpt (awk, args);
return ASE_NULL;
}
} }
while (MATCH(awk,TOKEN_NEWLINE));
args_tail->next = parse_expression (awk, awk->token.line); args_tail->next = parse_expression (awk, awk->token.line);
if (args_tail->next == ASE_NULL) if (args_tail->next == ASE_NULL)
@ -4504,6 +4518,18 @@ static int get_token (ase_awk_t* awk)
awk->token.line = awk->src.lex.line; awk->token.line = awk->src.lex.line;
awk->token.column = awk->src.lex.column; awk->token.column = awk->src.lex.column;
/* TODO: move NEWLINE handling to skip_spaces??? */
/* TODO: change the following block of code */
if (awk->option & ASE_AWK_NEWLINE)
{
if (line > 0 && awk->token.line != line)
{
SET_TOKEN_TYPE (awk, TOKEN_NEWLINE);
return 0;
}
}
/* END TODO */
if (line != 0 && (awk->option & ASE_AWK_BLOCKLESS) && if (line != 0 && (awk->option & ASE_AWK_BLOCKLESS) &&
(awk->parse.id.block == PARSE_PATTERN || (awk->parse.id.block == PARSE_PATTERN ||
awk->parse.id.block == PARSE_BEGIN || awk->parse.id.block == PARSE_BEGIN ||