Skip to content

Commit

Permalink
WIP: more tracing (and fix of identifier resolution)
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph <[email protected]>
  • Loading branch information
koppor and Siedlerchr committed May 19, 2024
1 parent d1499b0 commit e6791e9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/logic/bst/BstEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ public class BstEntry {

public final BibEntry entry;

public final Map<String, String> localStrings = new HashMap<>();

// ENTRY: First sub list
public final Map<String, String> fields = new HashMap<>();

// ENTRY: Second sub list
public final Map<String, Integer> localIntegers = new HashMap<>();

// ENTRY: Third sub list
public final Map<String, String> localStrings = new HashMap<>();

public BstEntry(BibEntry e) {
this.entry = e;
}
Expand Down
35 changes: 24 additions & 11 deletions src/main/java/org/jabref/logic/bst/BstVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,20 @@ public Integer visitExecuteCommand(BstParser.ExecuteCommandContext ctx) {
String name = bstFunction.getText();
LOGGER.trace("Executing function {}", name);
visit(bstFunction);
LOGGER.trace("Finished executing function {}", name);

return BstVM.TRUE;
}

@Override
public Integer visitIterateCommand(BstParser.IterateCommandContext ctx) {
LOGGER.trace("EXECUTE {}", ctx.bstFunction().getText());
String name = ctx.bstFunction().getText();
LOGGER.trace("Executing {}", name);
for (BstEntry entry : bstVMContext.entries()) {
this.selectedBstEntry = entry;
visit(ctx.bstFunction());
}

LOGGER.trace("Finished executing {}", name);
return BstVM.TRUE;
}

Expand Down Expand Up @@ -195,48 +197,59 @@ public Integer visitIdentifier(BstParser.IdentifierContext ctx) {
}

protected void resolveIdentifier(String name, ParserRuleContext ctx) {
LOGGER.trace("Resolving name {} at resolveIdentifier", name);
LOGGER.trace("Stack: {}", bstVMContext.stack());
if (selectedBstEntry != null) {
LOGGER.trace("selectedBstEntry is available");
if (selectedBstEntry.fields.containsKey(name)) {
LOGGER.trace("entry fields {}", name);
bstVMContext.stack().push(selectedBstEntry.fields.get(name));
return;
}
if (selectedBstEntry.localStrings.containsKey(name)) {
LOGGER.trace("entry local strings {}", name);
bstVMContext.stack().push(selectedBstEntry.localStrings.get(name));
return;
}
if (selectedBstEntry.localIntegers.containsKey(name)) {
LOGGER.trace("entry local integers {}", name);
bstVMContext.stack().push(selectedBstEntry.localIntegers.get(name));
return;
}
}

if (bstVMContext.strings().containsKey(name)) {
LOGGER.trace("global strings {}", name);
bstVMContext.stack().push(bstVMContext.strings().get(name));
return;
}
if (bstVMContext.integers().containsKey(name)) {
LOGGER.trace("global integers {}", name);
bstVMContext.stack().push(bstVMContext.integers().get(name));
return;
}
if (bstVMContext.functions().containsKey(name)) {
bstVMContext.functions().get(name).execute(this, ctx);
LOGGER.trace("functions {}", name);
bstVMContext.functions().get(name).execute(this, ctx, selectedBstEntry);
return;
}

LOGGER.warn("No matching identifier found: {}", name);
throw new BstVMException("No matching identifier found: " + name);
}

private static int count = 0;

@Override
public Integer visitBstFunction(BstParser.BstFunctionContext ctx) {
count++;
LOGGER.trace("Count: {}", count);
if (count > 1_000)
throw new RuntimeException("Count greater than threshold");
String name = ctx.getChild(0).getText();
if (bstVMContext.functions().containsKey(name)) {
LOGGER.trace("Function '{}' found", name);
bstVMContext.functions().get(name).execute(this, ctx, selectedBstEntry);
} else {
LOGGER.trace("Function '{}' not found", name);
visit(ctx.getChild(0));
}

LOGGER.trace("Resolving name {} at visitBstFunction", name);
// bstVMContext.functions().get(name).execute(this, ctx, selectedBstEntry);
resolveIdentifier(name, ctx);
return BstVM.TRUE;
}

Expand Down
48 changes: 23 additions & 25 deletions src/main/java/org/jabref/logic/util/TestEntry.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jabref.logic.util;

import java.util.Arrays;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
Expand All @@ -12,30 +10,30 @@ private TestEntry() {
}

public static BibEntry getTestEntry() {
BibEntry entry = new BibEntry(StandardEntryType.Article);
entry.setCitationKey("Smith2016");
entry.setField(StandardField.AUTHOR, "Smith, Bill and Jones, Bob and Williams, Jeff");
entry.setField(StandardField.EDITOR, "Taylor, Phil");
entry.setField(StandardField.TITLE, "Title of the test entry");
entry.setField(StandardField.NUMBER, "3");
entry.setField(StandardField.VOLUME, "34");
entry.setField(StandardField.ISSUE, "7");
entry.setField(StandardField.YEAR, "2016");
BibEntry entry = new BibEntry(StandardEntryType.Article)
.withCitationKey("Smith2016");
//entry.setField(StandardField.AUTHOR, "Smith, Bill and Jones, Bob and Williams, Jeff");
//entry.setField(StandardField.EDITOR, "Taylor, Phil");
//entry.setField(StandardField.TITLE, "Title of the test entry");
//entry.setField(StandardField.NUMBER, "3");
//entry.setField(StandardField.VOLUME, "34");
//entry.setField(StandardField.ISSUE, "7");
//entry.setField(StandardField.YEAR, "2016");
entry.setField(StandardField.PAGES, "45--67");
entry.setField(StandardField.MONTH, "July");
entry.setField(StandardField.FILE, ":testentry.pdf:PDF");
entry.setField(StandardField.JOURNAL, "BibTeX Journal");
entry.setField(StandardField.PUBLISHER, "JabRef Publishing");
entry.setField(StandardField.ADDRESS, "Trondheim");
entry.setField(StandardField.URL, "https://github.com/JabRef");
entry.setField(StandardField.DOI, "10.1001/bla.blubb");
entry.setField(StandardField.ABSTRACT,
"This entry describes a test scenario which may be useful in JabRef. By providing a test entry it is possible to see how certain things will look in this graphical BIB-file mananger.");
entry.setField(StandardField.COMMENT, "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et " +
"dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. " +
"Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non " +
"proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
entry.putKeywords(Arrays.asList("KeyWord1", "KeyWord2", "KeyWord3", "Keyword4"), ';');
//entry.setField(StandardField.MONTH, "July");
//entry.setField(StandardField.FILE, ":testentry.pdf:PDF");
//entry.setField(StandardField.JOURNAL, "BibTeX Journal");
//entry.setField(StandardField.PUBLISHER, "JabRef Publishing");
//entry.setField(StandardField.ADDRESS, "Trondheim");
//entry.setField(StandardField.URL, "https://github.com/JabRef");
//entry.setField(StandardField.DOI, "10.1001/bla.blubb");
//entry.setField(StandardField.ABSTRACT,
// "This entry describes a test scenario which may be useful in JabRef. By providing a test entry it is possible to see how certain things will look in this graphical BIB-file mananger.");
//entry.setField(StandardField.COMMENT, "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et " +
// "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. " +
// "Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non " +
// "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
//entry.putKeywords(Arrays.asList("KeyWord1", "KeyWord2", "KeyWord3", "Keyword4"), ';');

return entry;
}
Expand Down

0 comments on commit e6791e9

Please sign in to comment.