Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BST VM to Antlr4 #8934

Merged
merged 43 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
07a9ccb
migrate to antlr4
calixtus May 25, 2022
08c6a77
apply ide suggestions
calixtus May 25, 2022
7a33e9f
Refactor
calixtus May 26, 2022
7327061
Introduce BstVM, wip
calixtus May 26, 2022
bb9be35
read, entry, sort wip
calixtus May 27, 2022
ad63426
functions visitor
calixtus Jun 8, 2022
56b45c8
bstEntryContext
calixtus Jun 10, 2022
c30fe48
function, identifier, stackitem, exception
calixtus Jun 10, 2022
9d076e2
reorder
calixtus Jun 10, 2022
3e80d20
execute, iterate, reverse
calixtus Jun 10, 2022
377ad26
removed old vm, prepared test architecture
calixtus Jun 10, 2022
3eb676c
fixed parser
calixtus Jun 11, 2022
220679c
fixed stringscommand
calixtus Jun 12, 2022
018c3d6
fixed macrocommand
calixtus Jun 12, 2022
472dcfb
fixed functioncommand
calixtus Jun 12, 2022
a9f31aa
added exception handling for functions
calixtus Jun 12, 2022
f748f8d
testVisitEntryCommand
calixtus Jun 13, 2022
1ffb6ab
testVisitReadCommand
calixtus Jun 13, 2022
51cc276
reorder and cleanup
calixtus Jun 13, 2022
a6a3a70
testdata cleanup
calixtus Jun 13, 2022
b95957a
fix function call
calixtus Jun 20, 2022
ceba234
fixed call.type
calixtus Jun 25, 2022
cb6ce40
Merge remote-tracking branch 'upstream/main' into update_vm_antlr4
calixtus Jun 25, 2022
6c663c8
Merge remote-tracking branch 'upstream/main' into update_vm_antlr4
calixtus Jun 25, 2022
ce508cc
wip if
calixtus Jun 25, 2022
424e168
wip if
calixtus Jun 27, 2022
b91006d
addedTests
calixtus Jun 27, 2022
9726f3b
finally fixed if
calixtus Jun 28, 2022
9e85491
Merge remote-tracking branch 'origin/main' into update_vm_antlr4
koppor Jul 4, 2022
637048e
wip tests
calixtus Jul 12, 2022
7dc202b
stylistic issues
calixtus Jul 12, 2022
4569dc7
Reworded
calixtus Jul 15, 2022
951f20d
Improved error logging
calixtus Jul 18, 2022
ce070ac
Fix error msg
calixtus Jul 18, 2022
824ae7f
wip
calixtus Jul 18, 2022
5f2f240
Merge remote-tracking branch 'upstream/main' into update_vm_antlr4
calixtus Jul 22, 2022
ff4ca80
Fixed tests
calixtus Aug 1, 2022
501349f
Fixed tests
calixtus Aug 1, 2022
30d49c7
Removed TestVM
calixtus Aug 1, 2022
d210e6a
Added reverse test
calixtus Aug 1, 2022
39fe3f2
Added visitStackitem test
calixtus Aug 1, 2022
881a4d9
Added bbl tests
calixtus Aug 1, 2022
8bca717
clean up
calixtus Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.11'
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