Skip to content

Commit

Permalink
APREPRO: Better handline of double-brace noecho
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Sep 12, 2024
1 parent 12e0766 commit 590d97b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/seacas/libraries/aprepro_lib/apr_aprepro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#endif

namespace {
const std::string version_short{"6.33"};
const std::string version_short{"6.34"};
const std::string version_date{"(2024/09/12)"};
const std::string version_string = version_short + " " + version_date;

Expand Down
19 changes: 11 additions & 8 deletions packages/seacas/libraries/aprepro_lib/apr_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ typedef unsigned int flex_uint32_t;
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START (((yy_start)-1) / 2)
#define YY_START (((yy_start) - 1) / 2)
#define YYSTATE YY_START

/* Action number for EOF rule of a given start state. */
Expand Down Expand Up @@ -1020,7 +1020,7 @@ int loop_lvl = 0;
std::fstream *tmp_file;
const char *temp_f;

#if defined __NVCC__
#if defined __NVCC__
#pragma diag_suppress code_is_unreachable
#endif

Expand Down Expand Up @@ -1562,10 +1562,7 @@ YY_DECL
YY_BREAK
case 21:
/* rule 21 can match eol */
YY_RULE_SETUP
{ /* Do not increment line count */
;
}
YY_RULE_SETUP { /* Do not increment line count */ ; }
YY_BREAK

case 22:
Expand Down Expand Up @@ -2131,6 +2128,12 @@ YY_DECL
BEGIN(END_CASE_SKIP);
else
BEGIN(if_state[if_lvl]);
unput('}');
unput('O');
unput('H');
unput('C');
unput('E');
unput('{');
return (token::RBRACE);
}
YY_BREAK
Expand Down Expand Up @@ -2356,8 +2359,8 @@ YY_DECL

default: YY_FATAL_ERROR("fatal flex scanner internal error--no action found");
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */
/* %ok-for-header */

Expand Down
10 changes: 8 additions & 2 deletions packages/seacas/libraries/aprepro_lib/aprepro.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- Mode: c++ -*- */
s"}/* -*- Mode: c++ -*- */
/*
* Copyright(C) 1999-2023 National Technology & Engineering Solutions
* Copyright(C) 1999-2024 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand Down Expand Up @@ -697,6 +697,12 @@ integer {D}+({E})?
BEGIN(END_CASE_SKIP);
else
BEGIN(if_state[if_lvl]);
unput('}');
unput('O');
unput('H');
unput('C');
unput('E');
unput('{');
return(token::RBRACE);
}

Expand Down
40 changes: 30 additions & 10 deletions packages/seacas/libraries/aprepro_lib/strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ int main(int, char **)
{
SEAMS::Aprepro aprepro;

aprepro.ap_options.warning_msg=false;
aprepro.ap_options.warning_msg = false;

std::vector<std::string> strings = build_strings();
bool result = aprepro.parse_strings(strings, "My list of strings");
bool result = aprepro.parse_strings(strings, "My list of strings");
if (result) {
std::string res_str = aprepro.parsing_results().str();
std::cout << res_str;
}
aprepro.clear_results();
}

std::vector<std::string> build_strings()
std::vector<std::string> build_strings()
{
std::vector<std::string> strings;

Expand Down Expand Up @@ -61,7 +61,8 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"({pmin = min(0.5, 1.0)} {nmin = min(-0.5, -1.0)} $ Should be 0.5, -1)");
strings.emplace_back(R"({pmax = max(0.5, 1.0)} {nmax = max(-0.5, -1.0)} $ Should be 1.0, -0.5)");
strings.emplace_back(R"({zero = 0} {sign(0.5, zero) + sign(0.5, -zero)} $ Should be 0 1)");
strings.emplace_back(R"({nonzero = 1} {sign(0.5, nonzero) + sign(0.5, -nonzero)} $ Should be 1 0)");
strings.emplace_back(
R"({nonzero = 1} {sign(0.5, nonzero) + sign(0.5, -nonzero)} $ Should be 1 0)");
strings.emplace_back(R"({dim(5.5, 4.5)} {dim(4.5, 5.5)} $ Should be 1 0)");
strings.emplace_back(R"()");
strings.emplace_back(R"({ifyes = 1} {ifno = 0})");
Expand Down Expand Up @@ -109,7 +110,8 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"($ Lines a, b, c, d, 1, 4, 6, 7 should be echoed)");
strings.emplace_back(R"($ Check line counting -- should be on line 78: )");
strings.emplace_back(R"( )");
strings.emplace_back(R"($ ========================================================================)");
strings.emplace_back(
R"($ ========================================================================)");
strings.emplace_back(R"($ Test string if lines)");
strings.emplace_back(R"({if("Greg")})");
strings.emplace_back(R"( This line should be echoed ("greg"))");
Expand All @@ -125,7 +127,8 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"({endif})");
strings.emplace_back(R"()");
strings.emplace_back(R"()");
strings.emplace_back(R"($ ========================================================================)");
strings.emplace_back(
R"($ ========================================================================)");
strings.emplace_back(R"($ Test if lines)");
strings.emplace_back(R"({if(sqrt(4) == 2)})");
strings.emplace_back(R"( This line should be echoed. (a))");
Expand Down Expand Up @@ -176,7 +179,8 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"( good)");
strings.emplace_back(R"( make sure it is still good)");
strings.emplace_back(R"({endif})");
strings.emplace_back(R"($ ========================================================================)");
strings.emplace_back(
R"($ ========================================================================)");
strings.emplace_back(R"($ Test switch)");
strings.emplace_back(R"({switch(PI)})");
strings.emplace_back(R"(This is in a switch, but prior to any case, it should not run)");
Expand Down Expand Up @@ -210,16 +214,25 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"()");
strings.emplace_back(R"($ Test looping - print sin, cos from 0 to 90 by 5)");
strings.emplace_back(R"({Loop(19, _angle, 0, 5)})");
strings.emplace_back(R"({_angle} {_sa=sind(_angle)} {_ca=cosd(_angle)} {hypot(_sa, _ca)} )");
strings.emplace_back(
R"({_angle} {_sa=sind(_angle)} {_ca=cosd(_angle)} {hypot(_sa, _ca)} )");
strings.emplace_back(R"({EndLoop})");
strings.emplace_back(R"()");
strings.emplace_back(R"($$$$ Test formatting and string concatenation)");
strings.emplace_back(R"({_SAVE = _FORMAT})");
strings.emplace_back(R"({loop(20)})");
strings.emplace_back(R"({IO(__loop_1+1)} Using the format {_FORMAT = "%." // tostring(__loop_1+1) // "g"}, PI = {PI})");
strings.emplace_back(
R"({IO(__loop_1+1)} Using the format {_FORMAT = "%." // tostring(__loop_1+1) // "g"}, PI = {PI})");
strings.emplace_back(R"({endloop})");
strings.emplace_back(R"(Reset format to default: {_FORMAT = _SAVE})");
strings.emplace_back(R"()");
strings.emplace_back(
R"($$$$ Test formatting using the `format` function. _FORMAT is not modified)");
strings.emplace_back(R"({loop(20)}")");
strings.emplace_back(
R"({__loop_1+1} Using the format {_f = "%." // tostring(__loop_1+1) // "f"}, PI = {format(PI,_f)})");
strings.emplace_back(R"({endloop})");
strings.emplace_back(R"()");
strings.emplace_back(R"($$$$ Test string rescanning and executing)");
strings.emplace_back(R"({ECHO(OFF)})");
strings.emplace_back(R"({Test = ' This is line 1: {a = atan2(0,-1)})");
Expand Down Expand Up @@ -278,9 +291,16 @@ std::vector<std::string> build_strings()
strings.emplace_back(R"({list1 ='51,52,53,54,61,62,63,64'})");
strings.emplace_back(R"({list2 ='71,72,73,74,81,82,83,84'})");
strings.emplace_back(R"({loop(8, _i, 1)})");
strings.emplace_back(R"(Word {_i} of list1 and list2 are {get_word(_i,list1,',')} and {get_word(_i,list2,',')})");
strings.emplace_back(
R"(Word {_i} of list1 and list2 are {get_word(_i,list1,',')} and {get_word(_i,list2,',')})");
strings.emplace_back(R"({endloop})");
strings.emplace_back(R"()");
strings.emplace_back(R"($$$$ Test double brace echo off/on)");
strings.emplace_back(R"(Nothing further on line: {{"not echoed"}})");
strings.emplace_back(
R"(Noecho followed by non-parsing output: {{"not echoed"}}This should be echoed)");
strings.emplace_back(
R"(Echo, noecho setting variable, then echo that variable: {e="echo"}+{{d="echo"}}+{d})");
strings.emplace_back(R"($End of test file)");

return strings;
Expand Down
9 changes: 9 additions & 0 deletions packages/seacas/libraries/aprepro_lib/test.inp_app
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ $$$$ Test formatting and string concatenation
{endloop}
Reset format to default: {_FORMAT = _SAVE}

$$$$ Test formatting using the `format` function. _FORMAT is not modified
{loop(20)}
{__loop_1+1} Using the format {_f = "%." // tostring(__loop_1+1) // "f"}, PI = {format(PI,_f)}
{endloop}

$$$$ Test string rescanning and executing
{ECHO(OFF)}
{Test = ' This is line 1: {a = atan2(0,-1)}
Expand Down Expand Up @@ -257,4 +262,8 @@ This should not be echoed
{loop(undefined)}
This should not be echoed
{endloop}
$$$$ Test double brace echo off/on
Nothing further on line: {{"not echoed"}}
Noecho followed by non-parsing output: {{"not echoed"}}This should be echoed
Echo, noecho setting variable, then echo that variable: {e="echo"}+{{d="echo"}}+{d}
$End of test file
42 changes: 34 additions & 8 deletions packages/seacas/libraries/aprepro_lib/test_standard.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $
Test number representations
1 1 1 1 1
1 1 1 1 1

Test assign statements:
5 5 $ Should print 5 5
10 10 $ Should print 10 10
Expand Down Expand Up @@ -38,18 +38,18 @@ correct
correct

$ Test ifdef lines
This line should be echoed. (a)
This line should be echoed. (a)
This line should be echoed. (b)
This line should be echoed. (c)
This line should be echoed. (d)
This line should be echoed. (c)
This line should be echoed. (d)

$ Test ifdef - else lines
This line should be echoed. (1)
This line should be echoed (4)
This line should be echoed. (1)
This line should be echoed (4)

$ Test ifndef - else lines
This line should be echoed (6)
This line should be echoed. (7)
This line should be echoed (6)
This line should be echoed. (7)
$ Lines a, b, c, d, 1, 4, 6, 7 should be echoed
$ Check line counting -- should be on line 78:

Expand Down Expand Up @@ -133,6 +133,28 @@ $$$$ Test formatting and string concatenation
20 Using the format %.20g, PI = 3.141592653589793116
Reset format to default: %.10g

$$$$ Test formatting using the `format` function. _FORMAT is not modified
1 Using the format %.1f, PI = 3.1
2 Using the format %.2f, PI = 3.14
3 Using the format %.3f, PI = 3.142
4 Using the format %.4f, PI = 3.1416
5 Using the format %.5f, PI = 3.14159
6 Using the format %.6f, PI = 3.141593
7 Using the format %.7f, PI = 3.1415927
8 Using the format %.8f, PI = 3.14159265
9 Using the format %.9f, PI = 3.141592654
10 Using the format %.10f, PI = 3.1415926536
11 Using the format %.11f, PI = 3.14159265359
12 Using the format %.12f, PI = 3.141592653590
13 Using the format %.13f, PI = 3.1415926535898
14 Using the format %.14f, PI = 3.14159265358979
15 Using the format %.15f, PI = 3.141592653589793
16 Using the format %.16f, PI = 3.1415926535897931
17 Using the format %.17f, PI = 3.14159265358979312
18 Using the format %.18f, PI = 3.141592653589793116
19 Using the format %.19f, PI = 3.1415926535897931160
20 Using the format %.20f, PI = 3.14159265358979311600

$$$$ Test string rescanning and executing

Original String:
Expand Down Expand Up @@ -198,4 +220,8 @@ Word 6 of list1 and list2 are 62 and 82
Word 7 of list1 and list2 are 63 and 83
Word 8 of list1 and list2 are 64 and 84

$$$$ Test double brace echo off/on
Nothing further on line:
Noecho followed by non-parsing output: This should be echoed
Echo, noecho setting variable, then echo that variable: echo++echo
$End of test file

0 comments on commit 590d97b

Please sign in to comment.