diff --git a/src/main/java/org/jabref/logic/bst/BstEntry.java b/src/main/java/org/jabref/logic/bst/BstEntry.java index 89571de80469..c0aaf2c08a7e 100644 --- a/src/main/java/org/jabref/logic/bst/BstEntry.java +++ b/src/main/java/org/jabref/logic/bst/BstEntry.java @@ -9,12 +9,15 @@ public class BstEntry { public final BibEntry entry; - public final Map localStrings = new HashMap<>(); - + // ENTRY: First sub list public final Map fields = new HashMap<>(); + // ENTRY: Second sub list public final Map localIntegers = new HashMap<>(); + // ENTRY: Third sub list + public final Map localStrings = new HashMap<>(); + public BstEntry(BibEntry e) { this.entry = e; } diff --git a/src/main/java/org/jabref/logic/bst/BstVMVisitor.java b/src/main/java/org/jabref/logic/bst/BstVMVisitor.java index d2955e3fa16c..5a0eddb03238 100644 --- a/src/main/java/org/jabref/logic/bst/BstVMVisitor.java +++ b/src/main/java/org/jabref/logic/bst/BstVMVisitor.java @@ -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; } @@ -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; } diff --git a/src/main/java/org/jabref/logic/util/TestEntry.java b/src/main/java/org/jabref/logic/util/TestEntry.java index a7f80218992a..89a4df422e05 100644 --- a/src/main/java/org/jabref/logic/util/TestEntry.java +++ b/src/main/java/org/jabref/logic/util/TestEntry.java @@ -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; @@ -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; }