From d8f37bc6d655d04602e3d86a85ba55fdf9f2e053 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 3 Apr 2024 09:32:25 +0200 Subject: [PATCH] fiddling with the monitors of the ParserGenerator --- src/org/rascalmpl/interpreter/Evaluator.java | 3 ++- .../rascal/grammar/definition/Priorities.rsc | 2 +- .../repl/TerminalProgressBarMonitor.java | 20 +++++++++++-------- .../values/RascalFunctionValueFactory.java | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/org/rascalmpl/interpreter/Evaluator.java b/src/org/rascalmpl/interpreter/Evaluator.java index dc8b1f97fb5..bca88ef08a6 100755 --- a/src/org/rascalmpl/interpreter/Evaluator.java +++ b/src/org/rascalmpl/interpreter/Evaluator.java @@ -99,6 +99,7 @@ import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener; import org.rascalmpl.parser.uptr.UPTRNodeFactory; import org.rascalmpl.parser.uptr.action.NoActionExecutor; +import org.rascalmpl.repl.TerminalProgressBarMonitor; import org.rascalmpl.uri.URIResolverRegistry; import org.rascalmpl.uri.URIUtil; import org.rascalmpl.values.RascalFunctionValueFactory; @@ -812,7 +813,7 @@ public ParserGenerator getParserGenerator() { synchronized (self) { if (parserGenerator == null) { - parserGenerator = new ParserGenerator(getMonitor(), getStdErr(), classLoaders, getValueFactory(), config); + parserGenerator = new ParserGenerator(getMonitor(), (monitor instanceof TerminalProgressBarMonitor) ? (OutputStream) getMonitor() : getStdErr(), classLoaders, getValueFactory(), config); } } } diff --git a/src/org/rascalmpl/library/lang/rascal/grammar/definition/Priorities.rsc b/src/org/rascalmpl/library/lang/rascal/grammar/definition/Priorities.rsc index b492d3734d8..be2e8c156ad 100644 --- a/src/org/rascalmpl/library/lang/rascal/grammar/definition/Priorities.rsc +++ b/src/org/rascalmpl/library/lang/rascal/grammar/definition/Priorities.rsc @@ -14,6 +14,7 @@ import Set; import List; import IO; import util::Maybe; +import util::Monitor; import lang::rascal::grammar::definition::Productions; import lang::rascal::grammar::definition::Symbols; @@ -25,7 +26,6 @@ data Associativity = prio(); public alias Extracted = rel[Production father, Associativity rule, Production child]; public alias DoNotNest = rel[Production father, int position, Production child]; - @synopsis{Extract which productions are not to be nested under which other productions, at given recursive positions in the parents' defining symbols list.} @description{ diff --git a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java index 2c3d563e62a..b8bf70126a1 100644 --- a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java +++ b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java @@ -68,7 +68,7 @@ private class ProgressBar { private int current = 0; private int previousWidth = 0; private int doneWidth = 0; - private final int barWidth = lineWidth - "☐ ".length() - " ?🕐 00:00:00.000 ".length(); + private final int barWidth = lineWidth - "☐ ".length() - " 🕐 00:00:00.000 ".length(); private final Instant startTime; private Duration duration; private String message = ""; @@ -148,7 +148,7 @@ else if (barWidth <= 3) { // we can print the clock for good measure + ANSI.lightBackground() + backPart + ANSI.noBackground() - + " " + threadLabel() + clock + " " + + " " + threadLabel() + " " + clock + " " + String.format("%d:%02d:%02d.%03d", duration.toHoursPart(), duration.toMinutes(), duration.toSecondsPart(), duration.toMillisPart()) + " " ; @@ -159,15 +159,15 @@ else if (barWidth <= 3) { // we can print the clock for good measure private String threadLabel() { String name = Thread.currentThread().getName(); if (name.isEmpty()) { - return "?"; + return " "; } char last = name.charAt(name.length() - 1); if (Character.isDigit(last)) { - return "" + last; + return new String(Character.toChars(((last - '0') + "⑴ ".codePointAt(0)))); } - return "T"; + return " "; } @Override @@ -330,9 +330,13 @@ public synchronized void jobTodo(String name, int work) { @Override public synchronized void warning(String message, ISourceLocation src) { - eraseBars(); + if (bars.size() > 0) { + eraseBars(); + } writer.println(("[WARNING] " + src + ": " + message)); - printBars(); + if (bars.size() > 0) { + printBars(); + } } /** @@ -359,7 +363,7 @@ public synchronized void write(byte[] b) throws IOException { */ @Override public synchronized void write(byte[] b, int off, int len) throws IOException { - if (bars.size() > 0) { + if (bars.size() > 0) { eraseBars(); out.write(b, off, len); printBars(); diff --git a/src/org/rascalmpl/values/RascalFunctionValueFactory.java b/src/org/rascalmpl/values/RascalFunctionValueFactory.java index 9e496b66c46..268d049479f 100644 --- a/src/org/rascalmpl/values/RascalFunctionValueFactory.java +++ b/src/org/rascalmpl/values/RascalFunctionValueFactory.java @@ -105,7 +105,7 @@ private ParserGenerator getParserGenerator() { private Class> generateParser(IMap grammar) { try { - return getParserGenerator().getNewParser(new NullRascalMonitor(), URIUtil.rootLocation("parser-generator"), "$GENERATED_PARSER$" + Math.abs(grammar.hashCode()), grammar); + return getParserGenerator().getNewParser(ctx.getEvaluator().getMonitor(), URIUtil.rootLocation("parser-generator"), "$GENERATED_PARSER$" + Math.abs(grammar.hashCode()), grammar); } catch (ExceptionInInitializerError e) { throw new ImplementationError(e.getMessage(), e); @@ -118,7 +118,7 @@ protected Class> getParserClass(IMap protected void writeParserClass(IMap grammar, ISourceLocation target) throws IOException { getParserGenerator().writeNewParser( - new NullRascalMonitor(), + ctx.getEvaluator().getMonitor(), URIUtil.rootLocation("parser-generator"), "$GENERATED_PARSER$" + Math.abs(grammar.hashCode()), grammar,