Skip to content

Commit 407dc29

Browse files
committed
dot: fix parsing of IDs
closes #89
1 parent f5adfcb commit 407dc29

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

serialization/dot/src/main/javacc/DOT.jj

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,16 @@ TOKEN:
186186
| < COMMA: "," >
187187
| < EQUALS: "=" >
188188
| < EDGEOP: "--" | "->" >
189-
| < ID: <NUMERAL> | <LETTER> (<LETTER> | <NUMBER>)*>
190-
| < LETTER: ["a"-"z","A"-"Z","\200"-"\377","_"] >
191-
| < NUMBER: ["0"-"9"] >
192-
| < NUMERAL: ["-"]( ("."(<NUMBER>)+) | (<NUMBER>)+ ("." (<NUMBER>)+)?)>
189+
| < ALPHABETIC : <LETTER> (<LETTER> | <NUMBER>)*>
190+
| < NUMERAL: ("-")?( ("."(<NUMBER>)+) | (<NUMBER>)+ ("." (<NUMBER>)+)?)>
191+
| < #LETTER: ["a"-"z","A"-"Z","\200"-"\377","_"] >
192+
| < #NUMBER: ["0"-"9"] >
193193
}
194194

195195
SKIP:
196196
{
197197
< BEGIN_QID: "\"" > : IN_QID
198+
| < BEGIN_HTML: "<" > : IN_HTML
198199
}
199200

200201
<IN_QID> TOKEN:
@@ -207,6 +208,18 @@ SKIP:
207208
< END_QID: "\"" > : DEFAULT
208209
}
209210

211+
<IN_HTML> TOKEN:
212+
{
213+
// we don't check for well-matchedness of tags since we are only interested in finding the final >
214+
<HTML : ("<" (<CONTENT>)+ ">" | (<CONTENT>)+ )+ >
215+
| <#CONTENT : ~["<", ">"]>
216+
}
217+
218+
<IN_HTML> SKIP:
219+
{
220+
<END_HTML : ">" > : DEFAULT
221+
}
222+
210223
SKIP:
211224
{
212225
< BEGIN_LINE_COMMENT1: "//" > : IN_LINE_COMMENT
@@ -397,13 +410,15 @@ private void compass_pt():
397410
"n" | "ne" | "e" | "se" | "s" | "sw" | "w" | "nw" | "c" | "_"
398411
}
399412

400-
401413
private String identifier():
402414
{
403415
Token t;
404416
}
405417
{
406-
t=<ID> { return t.toString(); }
407-
| "\"\"" { return ""; }
418+
t=<ALPHABETIC> { return t.toString(); }
419+
| t=<NUMERAL> { return t.toString(); }
408420
| t=<QID> { return StringUtil.unescapeQuotes(t.toString()); }
421+
| t=<HTML> { return t.toString(); }
422+
| "\"\"" { return ""; }
423+
| "<>" { return ""; }
409424
}

serialization/dot/src/test/java/net/automatalib/serialization/dot/DOTDeserializationTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Comparator;
2626
import java.util.HashSet;
2727
import java.util.List;
28+
import java.util.Objects;
2829
import java.util.Queue;
2930
import java.util.Set;
3031

@@ -189,6 +190,15 @@ public void testDuplicateTransitions() throws IOException, FormatException {
189190
checkIsomorphism(dfa, parsed, dfa.getInputAlphabet());
190191
}
191192

193+
@Test
194+
public void testIDs() throws IOException, FormatException {
195+
final DFA<?, String> parsed =
196+
DOTParsers.dfa().readModel(DOTSerializationUtil.getResource(DOTSerializationUtil.ID_RESOURCE)).model;
197+
198+
Assert.assertEquals(parsed.size(), 6);
199+
Assert.assertTrue(parsed.accepts(Word.fromString("abcd").transform(Objects::toString)));
200+
}
201+
192202
private static <S1, S2, I, T1, T2, SP, TP> void checkIsomorphism(UniversalAutomaton<S1, I, T1, SP, TP> source,
193203
UniversalAutomaton<S2, I, T2, SP, TP> target,
194204
Alphabet<I> alphabet) {

serialization/dot/src/test/java/net/automatalib/serialization/dot/DOTSerializationUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
final class DOTSerializationUtil {
5858

59+
static final String ID_RESOURCE = "/id.dot";
5960
static final String EMPTY_RESOURCE = "/empty.dot";
6061
static final String DFA_RESOURCE = "/dfa.dot";
6162
static final String NFA_RESOURCE = "/nfa.dot";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
digraph g {
2+
3+
<<TABLE><TR><TD BGCOLOR="yellow">class</TD></TR><TR><TD BGCOLOR="lightblue">qualifier</TD></TR></TABLE>> [shape="doublecircle"];
4+
13 [shape="circle"];
5+
-5.13 [shape="circle"];
6+
"id with \" quotes" [shape="circle"];
7+
aLpHa_B3T1C [shape="doublecircle"];
8+
<> [label="empty"];
9+
"" [label="empty2"]; // same id as <>, so redundant!
10+
11+
13 -> -5.13 [label="a"];
12+
-5.13 -> "id with \" quotes" [label="b"];
13+
"id with \" quotes" -> aLpHa_B3T1C [label="c"];
14+
aLpHa_B3T1C -> <<TABLE><TR><TD BGCOLOR="yellow">class</TD></TR><TR><TD BGCOLOR="lightblue">qualifier</TD></TR></TABLE>> [label="d"];
15+
16+
__start0 [label="" shape="none" width="0" height="0"];
17+
__start0 -> 13;
18+
19+
}

0 commit comments

Comments
 (0)