From 8eac78f8ef26542f426a13d5b34f8b426b2c884b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 26 Feb 2019 18:40:37 +0100 Subject: [PATCH] d: tests: use fewer global variables * tests/calc.at: Move 'input' into the scanner. --- tests/calc.at | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/calc.at b/tests/calc.at index 252f8ae0..24230293 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -50,12 +50,8 @@ AT_D_IF([m4_pushdef([AT_CALC_MAIN], semantic_value result = 0; int count = 0; - if (args.length == 2) - input = File (args[1], "r"); - else - input = stdin; - - CalcLexer l = new CalcLexer (); + File input = args.length == 2 ? File (args[1], "r") : stdin; + CalcLexer l = new CalcLexer (input); YYParser p = new YYParser (l); int status = !p.parse (); return status; @@ -121,9 +117,15 @@ main (int argc, const char **argv) ]])]) AT_D_IF([m4_pushdef([AT_CALC_LEX], -[[File input; +[[class CalcLexer : Lexer +{ -class CalcLexer : Lexer { + this (File i) + { + input = i; + } + + File input; int prev_char = -1; @@ -871,4 +873,4 @@ AT_CHECK_CALC([%skeleton "lalr1.d"]) m4_define([AT_CHECK_CALC_LALR1_D], [AT_CHECK_CALC([%language "D" $1], [$2])]) -AT_CHECK_CALC_LALR1_D([]) \ No newline at end of file +AT_CHECK_CALC_LALR1_D([])