Skip to content

Commit

Permalink
streamlined progress reports of the parser generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 2, 2024
1 parent 9ccd0dc commit 12b394e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
30 changes: 15 additions & 15 deletions src/org/rascalmpl/library/lang/rascal/grammar/ParserGenerator.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,50 @@ str getParserMethodName(conditional(Symbol s, _)) = getParserMethodName(s);
default str getParserMethodName(Symbol s) = value2id(s);

public str newGenerate(str package, str name, Grammar gr) {
JOB = "Generating parser <package>.<name>";
jobStart("Generating parser <package>.<name>");
str src = "";
job("Generating parser <package>.<name>", void (void (str m, int w) worked) {
int uniqueItem = 1; // -1 and -2 are reserved by the SGTDBF implementation
int newItem() { uniqueItem += 1; return uniqueItem; };

jobStep(JOB, "expanding parameterized symbols");
worked("expanding parameterized symbols", 1);
gr = expandParameterizedSymbols(gr);

jobStep(JOB, "generating stubs for regular");
worked("generating stubs for regular", 1);
gr = makeRegularStubs(gr);

jobStep(JOB, "generating syntax for holes");
worked("generating syntax for holes", 1);
gr = addHoles(gr);

jobStep(JOB, "generating literals");
worked("generating literals", 1);
gr = literals(gr);

jobStep(JOB, "establishing production set");
worked("establishing production set", 1);
uniqueProductions = {p | /Production p := gr, prod(_,_,_) := p || regular(_) := p};
jobStep(JOB, "assigning unique ids to symbols");
worked("assigning unique ids to symbols", 1);
Production rewrite(Production p) =
visit (p) {
case Symbol s => s[id=newItem()]
};
beforeUniqueGr = gr;
gr.rules = (s : rewrite(gr.rules[s]) | s <- gr.rules);
jobStep(JOB, "generating item allocations");
worked("generating item allocations", 1);
newItems = generateNewItems(gr);
jobStep(JOB, "computing priority and associativity filter");
worked("computing priority and associativity filter", 1);
rel[int parent, int child] dontNest = computeDontNests(newItems, beforeUniqueGr, gr);
// this creates groups of children that forbidden below certain parents
rel[set[int] children, set[int] parents] dontNestGroups =
{<c,g[c]> | rel[set[int] children, int parent] g := {<dontNest[p],p> | p <- dontNest.parent}, c <- g.children};
//println("computing lookahead sets");
//println("computing lookahead sets", 1);
//gr = computeLookaheads(gr, extraLookaheads);
//println("optimizing lookahead automaton");
//println("optimizing lookahead automaton", 1);
//gr = compileLookaheads(gr);
jobStep(JOB, "printing the source code of the parser class");
worked("printing the source code of the parser class", 1);
src = "package <package>;
'
Expand Down Expand Up @@ -238,8 +238,8 @@ public str newGenerate(str package, str name, Grammar gr) {
' <for (Symbol nont <- (gr.rules.sort), isNonterminal(nont)) { >
' <generateParseMethod(newItems, gr.rules[unsetRec(nont)])><}>
'}";
jobEnd(JOB);
return src;
}, totalWork=9);
return src;
}
rel[int,int] computeDontNests(Items items, Grammar grammar, Grammar uniqueGrammar) {
Expand Down
16 changes: 8 additions & 8 deletions src/org/rascalmpl/library/util/Monitor.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ with a parameterized workload and the same label as the job name.
@pitfalls{
* additional work with ((jobTodo)) is still possible, but you have to repeat the right job label.
}
void job(str label, void (void (str message, int worked) step) block) {
void job(str label, void (void (str message, int worked) step) block, int totalWork=1) {
try {
jobStart(label);
jobStart(label, totalWork=totalWork);
block((str message, int worked) {
jobStep(label, message, work=worked);
});
Expand All @@ -81,9 +81,9 @@ with a parameterized workload and the same label as the job name.
@pitfalls{
* additional work with ((jobTodo)) is still possible, but you have to repeat the right job label.
}
void job(str label, void (void (int worked) step) block) {
void job(str label, void (void (int worked) step) block, int totalWork=1) {
try {
jobStart(label);
jobStart(label, totalWork=totalWork);
block((int worked) {
jobStep(label, label, work=worked);
});
Expand All @@ -108,9 +108,9 @@ with workload `1` and the same label as the job name.
@pitfalls{
* additional work with ((jobTodo)) is still possible, but you have to repeat the right job label.
}
void job(str label, void (void () step) block) {
void job(str label, void (void () step) block, int totalWork=1) {
try {
jobStart(label);
jobStart(label, totalWork=totalWork);
block(() {
jobStep(label, label, work=1);
});
Expand All @@ -128,9 +128,9 @@ void job(str label, void (void () step) block) {
* the block code does not need to remember to end the job with the same job name.
* the job is always properly ended, even when exceptions are thrown
}
void job(str label, void () block) {
void job(str label, void () block, int totalWork=1) {
try {
jobStart(label);
jobStart(label, totalWork=totalWork);
block();
}
catch x: {
Expand Down

0 comments on commit 12b394e

Please sign in to comment.