Skip to content

Commit

Permalink
fiddling with the monitors of the ParserGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 3, 2024
1 parent d54b389 commit d8f37bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/org/rascalmpl/interpreter/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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{
Expand Down
20 changes: 12 additions & 8 deletions src/org/rascalmpl/repl/TerminalProgressBarMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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())
+ " "
;
Expand All @@ -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 " ";

Check warning on line 162 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L162

Added line #L162 was not covered by tests
}

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 " ";

Check warning on line 170 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L170

Added line #L170 was not covered by tests
}

@Override
Expand Down Expand Up @@ -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();
}
}

/**
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/org/rascalmpl/values/RascalFunctionValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private ParserGenerator getParserGenerator() {

private Class<IGTD<IConstructor, ITree, ISourceLocation>> 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);
Expand All @@ -118,7 +118,7 @@ protected Class<IGTD<IConstructor, ITree, ISourceLocation>> getParserClass(IMap

protected void writeParserClass(IMap grammar, ISourceLocation target) throws IOException {
getParserGenerator().writeNewParser(
new NullRascalMonitor(),
ctx.getEvaluator().getMonitor(),

Check warning on line 121 in src/org/rascalmpl/values/RascalFunctionValueFactory.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/values/RascalFunctionValueFactory.java#L121

Added line #L121 was not covered by tests
URIUtil.rootLocation("parser-generator"),
"$GENERATED_PARSER$" + Math.abs(grammar.hashCode()),
grammar,
Expand Down

0 comments on commit d8f37bc

Please sign in to comment.