diff --git a/ase/cmd/awk/awk.c b/ase/cmd/awk/awk.c index a7c0d5b9..a7815819 100644 --- a/ase/cmd/awk/awk.c +++ b/ase/cmd/awk/awk.c @@ -877,7 +877,8 @@ static struct { ASE_T("argstomain"), ASE_AWK_ARGSTOMAIN }, { ASE_T("reset"), ASE_AWK_RESET }, { 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) diff --git a/ase/include/ase/awk/Awk.hpp b/ase/include/ase/awk/Awk.hpp index 1e0c0713..0278870b 100644 --- a/ase/include/ase/awk/Awk.hpp +++ b/ase/include/ase/awk/Awk.hpp @@ -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} */ @@ -548,6 +548,7 @@ public: OPT_BLOCKLESS = ASE_AWK_BLOCKLESS, OPT_BASEONE = ASE_AWK_BASEONE, OPT_STRIPSPACES = ASE_AWK_STRIPSPACES, + /** Support the nextofile statement */ OPT_NEXTOFILE = ASE_AWK_NEXTOFILE, /** Use CR+LF instead of LF for line breaking. */ @@ -563,7 +564,9 @@ public: /** Allows the assignment of a map value to a variable */ OPT_MAPTOVAR = ASE_AWK_MAPTOVAR, /** 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 diff --git a/ase/lib/awk/parse.c b/ase/lib/awk/parse.c index 216163d0..7fc791b5 100644 --- a/ase/lib/awk/parse.c +++ b/ase/lib/awk/parse.c @@ -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} */ @@ -521,9 +521,17 @@ static int parse (ase_awk_t* awk) while (1) { 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; goto exit_parse; @@ -592,6 +600,9 @@ exit_parse: static ase_awk_t* parse_progunit (ase_awk_t* awk) { /* + global xxx, xxxx; + BEGIN { action } + END { action } pattern { action } 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)) { - if (get_token(awk) == -1) - { - ase_awk_clrpt (awk, args); - return ASE_NULL; + do { + if (get_token(awk) == -1) + { + ase_awk_clrpt (awk, args); + return ASE_NULL; + } } + while (MATCH(awk,TOKEN_NEWLINE)); args_tail->next = parse_expression (awk, awk->token.line); 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.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) && (awk->parse.id.block == PARSE_PATTERN || awk->parse.id.block == PARSE_BEGIN ||