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

Bugfix 3375: Fix bug when pasing .interp file #3419

Merged
merged 8 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,4 @@ YYYY/MM/DD, github id, Full name, email
2021/10/10, tools4origins, Erwan Guyomarc'h, [email protected]
2021/10/19, jcking, Justin King, [email protected]
2021/10/31, skef, Skef Iterum, [email protected]
2021/12/25, Tinker1024, Tinker1024, [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
token literal names:
null
'='
'*'
'/'
'+'
'-'
'('
')'
null
null
null
null

token symbolic names:
null
null
null
null
null
null
null
null
ID
INT
NEWLINE
WS

rule names:
T__0
T__1
T__2
T__3
T__4
T__5
T__6
ID
INT
NEWLINE
WS

channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN

mode names:
DEFAULT_MODE

atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 61, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 6, 9, 41, 10, 9, 13, 9, 14, 9, 42, 3, 10, 6, 10, 46, 10, 10, 13, 10, 14, 10, 47, 3, 11, 5, 11, 51, 10, 11, 3, 11, 3, 11, 3, 12, 6, 12, 56, 10, 12, 13, 12, 14, 12, 57, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 5, 4, 2, 67, 92, 99, 124, 3, 2, 50, 59, 4, 2, 11, 11, 34, 34, 2, 64, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 31, 3, 2, 2, 2, 11, 33, 3, 2, 2, 2, 13, 35, 3, 2, 2, 2, 15, 37, 3, 2, 2, 2, 17, 40, 3, 2, 2, 2, 19, 45, 3, 2, 2, 2, 21, 50, 3, 2, 2, 2, 23, 55, 3, 2, 2, 2, 25, 26, 7, 63, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 44, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 49, 2, 2, 30, 8, 3, 2, 2, 2, 31, 32, 7, 45, 2, 2, 32, 10, 3, 2, 2, 2, 33, 34, 7, 47, 2, 2, 34, 12, 3, 2, 2, 2, 35, 36, 7, 42, 2, 2, 36, 14, 3, 2, 2, 2, 37, 38, 7, 43, 2, 2, 38, 16, 3, 2, 2, 2, 39, 41, 9, 2, 2, 2, 40, 39, 3, 2, 2, 2, 41, 42, 3, 2, 2, 2, 42, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 18, 3, 2, 2, 2, 44, 46, 9, 3, 2, 2, 45, 44, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 45, 3, 2, 2, 2, 47, 48, 3, 2, 2, 2, 48, 20, 3, 2, 2, 2, 49, 51, 7, 15, 2, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 12, 2, 2, 53, 22, 3, 2, 2, 2, 54, 56, 9, 4, 2, 2, 55, 54, 3, 2, 2, 2, 56, 57, 3, 2, 2, 2, 57, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 60, 8, 12, 2, 2, 60, 24, 3, 2, 2, 2, 7, 2, 42, 47, 50, 57, 3, 8, 2, 2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
token symbolic names:
null
null
null
null
null
null
null
null
ID
INT
NEWLINE
WS

token literal names:
null
'='
'*'
'/'
'+'
'-'
'('
')'
null
null
null
null

rule names:
T__0
T__1
T__2
T__3
T__4
T__5
T__6
ID
INT
NEWLINE
WS

channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN

mode names:
DEFAULT_MODE

atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 61, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 6, 9, 41, 10, 9, 13, 9, 14, 9, 42, 3, 10, 6, 10, 46, 10, 10, 13, 10, 14, 10, 47, 3, 11, 5, 11, 51, 10, 11, 3, 11, 3, 11, 3, 12, 6, 12, 56, 10, 12, 13, 12, 14, 12, 57, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 5, 4, 2, 67, 92, 99, 124, 3, 2, 50, 59, 4, 2, 11, 11, 34, 34, 2, 64, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 31, 3, 2, 2, 2, 11, 33, 3, 2, 2, 2, 13, 35, 3, 2, 2, 2, 15, 37, 3, 2, 2, 2, 17, 40, 3, 2, 2, 2, 19, 45, 3, 2, 2, 2, 21, 50, 3, 2, 2, 2, 23, 55, 3, 2, 2, 2, 25, 26, 7, 63, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 44, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 49, 2, 2, 30, 8, 3, 2, 2, 2, 31, 32, 7, 45, 2, 2, 32, 10, 3, 2, 2, 2, 33, 34, 7, 47, 2, 2, 34, 12, 3, 2, 2, 2, 35, 36, 7, 42, 2, 2, 36, 14, 3, 2, 2, 2, 37, 38, 7, 43, 2, 2, 38, 16, 3, 2, 2, 2, 39, 41, 9, 2, 2, 2, 40, 39, 3, 2, 2, 2, 41, 42, 3, 2, 2, 2, 42, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 18, 3, 2, 2, 2, 44, 46, 9, 3, 2, 2, 45, 44, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 45, 3, 2, 2, 2, 47, 48, 3, 2, 2, 2, 48, 20, 3, 2, 2, 2, 49, 51, 7, 15, 2, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 12, 2, 2, 53, 22, 3, 2, 2, 2, 54, 56, 9, 4, 2, 2, 55, 54, 3, 2, 2, 2, 56, 57, 3, 2, 2, 2, 57, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 60, 8, 12, 2, 2, 60, 24, 3, 2, 2, 2, 7, 2, 42, 47, 50, 57, 3, 8, 2, 2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.antlr.v4.test.runtime.java;

import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNSerializer;
import org.antlr.v4.runtime.misc.InterpreterDataReader;
import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class TestInterpreterDataReader {

@Test
public void testParseFile() throws NoSuchFieldException, IllegalAccessException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
// pay attention to the path where the InterpDataReaderTest.interp is stored.
final URL stuff = loader.getResource("org/antlr/v4/test/runtime/InterpDataReaderTest.interp");
Assert.assertNotNull(stuff);

InterpreterDataReader.InterpreterData interpreterData = InterpreterDataReader.parseFile(stuff.getPath());
Field atnField = interpreterData.getClass().getDeclaredField("atn");
Field vocabularyField = interpreterData.getClass().getDeclaredField("vocabulary");
Field ruleNamesField = interpreterData.getClass().getDeclaredField("ruleNames");
Field channelsField = interpreterData.getClass().getDeclaredField("channels");
Field modesField = interpreterData.getClass().getDeclaredField("modes");

atnField.setAccessible(true);
vocabularyField.setAccessible(true);
ruleNamesField.setAccessible(true);
channelsField.setAccessible(true);
modesField.setAccessible(true);

ATN atn = (ATN) atnField.get(interpreterData);
Vocabulary vocabulary = (Vocabulary) vocabularyField.get(interpreterData);
List<String> ruleNames = castList(ruleNamesField.get(interpreterData), String.class);
List<String> channels = castList(channelsField.get(interpreterData), String.class);
List<String> modes = castList(modesField.get(interpreterData), String.class);

char[] atnChars = ATNSerializer.getSerializedAsChars(atn);
Assert.assertTrue(atnChars.length > 0);
Assert.assertNotNull(vocabulary);
Assert.assertEquals(11, ruleNames.size());
Assert.assertEquals(2, channels.size());
Assert.assertEquals(1, modes.size());
}

@Test
public void testParseFileError() {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final URL stuff = loader.getResource("org/antlr/v4/test/runtime/InterpDataReaderTest2.interp");
Assert.assertNotNull(stuff);

try {
InterpreterDataReader.InterpreterData interpreterData = InterpreterDataReader.parseFile(stuff.getPath());
} catch (Exception e) {
Assert.assertEquals(e.getClass(), RuntimeException.class);
Assert.assertEquals(e.getMessage(), "Unexpected data entry");
}
}

private <T> List<T> castList(Object obj, Class<T> clazz) {
List<T> result = new ArrayList<T>();
if (obj instanceof List<?>) {
for (Object o : (List<?>) obj) {
result.add(clazz.cast(o));
}
return result;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static InterpreterData parseFile(String fileName) {
result.ruleNames.add(line);
}

line = br.readLine();
if ( line.equals("channel names:") ) { // Additional lexer data.
result.channels = new ArrayList<String>();
while ((line = br.readLine()) != null) {
Expand Down