Skip to content

Commit

Permalink
Update BST VM to Antlr4 (#8934)
Browse files Browse the repository at this point in the history
* migrate to antlr4

* apply ide suggestions

* Refactor

* Introduce BstVM, wip

* read, entry, sort wip

* functions visitor

* bstEntryContext

* function, identifier, stackitem, exception

* reorder

* execute, iterate, reverse

* removed old vm, prepared test architecture

* fixed parser

* fixed stringscommand

* fixed macrocommand

* fixed functioncommand

* added exception handling for functions

* testVisitEntryCommand

* testVisitReadCommand

* reorder and cleanup

* testdata cleanup

* fix function call

* fixed call.type

* wip if

* wip if

* addedTests

* finally fixed if

* wip tests

* stylistic issues

* Reworded

* Improved error logging

* Fix error msg

* wip

* Fixed tests

* Fixed tests

* Removed TestVM

* Added reverse test

* Added visitStackitem test

* Added bbl tests

* clean up

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
  • Loading branch information
calixtus and koppor committed Aug 1, 2022
1 parent 02f51f7 commit 0a1e98b
Show file tree
Hide file tree
Showing 35 changed files with 2,971 additions and 2,698 deletions.
14 changes: 5 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ repositories {
}

configurations {
antlr3
antlr4
// TODO: Remove the following workaround for split error messages such as
// error: module java.xml.bind reads package javax.annotation from both jsr305 and java.annotation
Expand Down Expand Up @@ -139,9 +138,6 @@ dependencies {
implementation 'io.github.java-diff-utils:java-diff-utils:4.12'
implementation 'info.debatty:java-string-similarity:2.0.0'

antlr3 'org.antlr:antlr:3.5.3'
implementation 'org.antlr:antlr-runtime:3.5.3'

antlr4 'org.antlr:antlr4:4.9.3'
implementation 'org.antlr:antlr4-runtime:4.9.3'

Expand Down Expand Up @@ -273,14 +269,14 @@ task generateSource(dependsOn: ["generateBstGrammarSource",
}

tasks.register("generateBstGrammarSource", JavaExec) {
main = "org.antlr.Tool"
classpath = configurations.antlr3
main = "org.antlr.v4.Tool"
classpath = configurations.antlr4
group = "JabRef"
description = 'Generates BstLexer.java and BstParser.java from the Bst.g grammar file using antlr3.'
description = 'Generates BstLexer.java and BstParser.java from the Bst.g grammar file using antlr4.'

inputs.dir('src/main/antlr3/org/jabref/bst/')
inputs.dir('src/main/antlr4/org/jabref/bst/')
outputs.dir("src-gen/main/java/org/jabref/logic/bst/")
args = ["-o", "src-gen/main/java/org/jabref/logic/bst/" , "$projectDir/src/main/antlr3/org/jabref/bst/Bst.g" ]
args = ["-o", "src-gen/main/java/org/jabref/logic/bst/", "-visitor", "-no-listener", "-package", "org.jabref.logic.bst", "$projectDir/src/main/antlr4/org/jabref/bst/Bst.g4"]
}

tasks.register("generateSearchGrammarSource", JavaExec) {
Expand Down
96 changes: 0 additions & 96 deletions src/main/antlr3/org/jabref/bst/Bst.g

This file was deleted.

85 changes: 85 additions & 0 deletions src/main/antlr4/org/jabref/bst/Bst.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
grammar Bst;

// Lexer

STRINGS : 'STRINGS';
INTEGERS : 'INTEGERS';
FUNCTION : 'FUNCTION';
EXECUTE : 'EXECUTE';
SORT : 'SORT';
ITERATE : 'ITERATE';
REVERSE : 'REVERSE';
ENTRY : 'ENTRY';
READ : 'READ';
MACRO : 'MACRO';

GT : '>';
LT : '<';
EQUAL : '=';
ASSIGN : ':=';
ADD : '+';
SUB : '-';
CONCAT : '*';
LBRACE : '{';
RBRACE : '}';

fragment LETTER : ('a'..'z'|'A'..'Z'|'.'|'$');
fragment NUMERAL : ('0'..'9');

IDENTIFIER : LETTER (LETTER|NUMERAL|'_')*;
INTEGER : '#' ('+'|'-')? NUMERAL+;
QUOTED : '\'' IDENTIFIER;
STRING : '"' (~('"'))* '"';

WS: [ \r\n\t]+ -> skip;
LINE_COMMENT : '%' ~('\n'|'\r')* '\r'? '\n' -> skip;

// Parser

bstFile
: commands+ EOF
;

commands
: STRINGS ids=idListObl #stringsCommand
| INTEGERS ids=idListObl #integersCommand
| FUNCTION LBRACE id=identifier RBRACE function=stack #functionCommand
| MACRO LBRACE id=identifier RBRACE LBRACE repl=STRING RBRACE #macroCommand
| READ #readCommand
| EXECUTE LBRACE bstFunction RBRACE #executeCommand
| ITERATE LBRACE bstFunction RBRACE #iterateCommand
| REVERSE LBRACE bstFunction RBRACE #reverseCommand
| ENTRY idListOpt idListOpt idListOpt #entryCommand
| SORT #sortCommand
;

identifier
: IDENTIFIER
;

// Obligatory identifier list
idListObl
: LBRACE identifier+ RBRACE
;

// Optional identifier list
idListOpt
: LBRACE identifier* RBRACE
;

bstFunction
: LT | GT | EQUAL | ADD | SUB | ASSIGN | CONCAT
| identifier
;

stack
: LBRACE stackitem+ RBRACE
;

stackitem
: bstFunction
| STRING
| INTEGER
| QUOTED
| stack
;
1 change: 0 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
requires org.mariadb.jdbc;
uses org.mariadb.jdbc.credential.CredentialPlugin;
requires org.apache.commons.lang3;
requires antlr.runtime;
requires org.antlr.antlr4.runtime;
requires org.fxmisc.flowless;
requires org.apache.tika.core;
Expand Down
Loading

0 comments on commit 0a1e98b

Please sign in to comment.