Skip to content
/ jflex Public
forked from jflex-de/jflex

Commit

Permalink
Merge branch 'master' into test-fileutil
Browse files Browse the repository at this point in the history
  • Loading branch information
regisd committed Oct 16, 2018
2 parents b386bd2 + 4f6a96b commit d4899d3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 88 deletions.
1 change: 0 additions & 1 deletion jflex/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//cup",
"//third_party/com/google/auto_value",
"//third_party/org/apache/ant",
],
)
Expand Down
2 changes: 1 addition & 1 deletion jflex/examples/cup-lcalc/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#JFlex with cup
# JFlex with cup

This directory contains a small example of integration
between JFlex and [CUP][cup].
Expand Down
5 changes: 0 additions & 5 deletions jflex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
<artifactId>ant</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
32 changes: 23 additions & 9 deletions jflex/src/main/java/jflex/IntPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

package jflex;

import com.google.auto.value.AutoValue;

/**
* Simple pair of integers.
*
Expand All @@ -19,16 +17,32 @@
* @author Gerwin Klein
* @version JFlex 1.7.1-SNAPSHOT
*/
@AutoValue
abstract class IntPair {
final class IntPair {

abstract int start();
int start;
int end;

abstract int end();
IntPair(int start, int end) {
this.start = start;
this.end = end;
}

public int xxx;
@Override
public int hashCode() {
return end + (start << 8);
}

@Override
public boolean equals(Object o) {
if (o instanceof IntPair) {
IntPair p = (IntPair) o;
return start == p.start && end == p.end;
}
return false;
}

static IntPair create(int start, int end) {
return new AutoValue_IntPair(start, end);
@Override
public String toString() {
return "(" + start + "," + end + ")";
}
}
92 changes: 46 additions & 46 deletions jflex/src/main/java/jflex/NFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ public void addRegExp(int regExpNum) {
if (lexStates.isEmpty()) lexStates = scanner.states.getInclusiveStates();

for (Integer stateNum : lexStates) {
if (!regExps.isBOL(regExpNum)) addEpsilonTransition(2 * stateNum, nfa.start());
if (!regExps.isBOL(regExpNum)) addEpsilonTransition(2 * stateNum, nfa.start);

addEpsilonTransition(2 * stateNum + 1, nfa.start());
addEpsilonTransition(2 * stateNum + 1, nfa.start);
}

if (regExps.getLookAhead(regExpNum) != null) {
Action a = regExps.getAction(regExpNum);

if (a.lookAhead() == Action.FINITE_CHOICE) {
insertLookAheadChoices(nfa.end(), a, regExps.getLookAhead(regExpNum));
insertLookAheadChoices(nfa.end, a, regExps.getLookAhead(regExpNum));
// remove the original action from the collection: it will never
// be matched directly, only its copies will.
scanner.actions.remove(a);
Expand All @@ -175,33 +175,33 @@ public void addRegExp(int regExpNum) {

IntPair look = insertNFA(r2);

addEpsilonTransition(nfa.end(), look.start());
addEpsilonTransition(nfa.end, look.start);

action[look.end()] = a;
isFinal[look.end()] = true;
action[look.end] = a;
isFinal[look.end] = true;

if (a.lookAhead() == Action.GENERAL_LOOK) {
// base forward pass
IntPair forward = insertNFA(r1);
// lookahead backward pass
IntPair backward = insertNFA(r2.rev(macros));

isFinal[forward.end()] = true;
action[forward.end()] = new Action(Action.FORWARD_ACTION);
isFinal[forward.end] = true;
action[forward.end] = new Action(Action.FORWARD_ACTION);

isFinal[backward.end()] = true;
action[backward.end()] = new Action(Action.BACKWARD_ACTION);
isFinal[backward.end] = true;
action[backward.end] = new Action(Action.BACKWARD_ACTION);

int entry = 2 * (regExps.getLookEntry(regExpNum) + numLexStates);
addEpsilonTransition(entry, forward.start());
addEpsilonTransition(entry + 1, backward.start());
addEpsilonTransition(entry, forward.start);
addEpsilonTransition(entry + 1, backward.start);

a.setEntryState(entry);
}
}
} else {
action[nfa.end()] = regExps.getAction(regExpNum);
isFinal[nfa.end()] = true;
action[nfa.end] = regExps.getAction(regExpNum);
isFinal[nfa.end] = true;
}
}

Expand All @@ -228,11 +228,11 @@ private void insertLookAheadChoices(int baseEnd, Action a, RegExp lookAhead) {
// termination case
IntPair look = insertNFA(lookAhead);

addEpsilonTransition(baseEnd, look.start());
addEpsilonTransition(baseEnd, look.start);

Action x = a.copyChoice(len);
action[look.end()] = x;
isFinal[look.end()] = true;
action[look.end] = x;
isFinal[look.end] = true;

// add new copy to the collection of known actions such that
// it can be checked for the NEVER_MATCH warning.
Expand Down Expand Up @@ -701,7 +701,7 @@ private IntPair insertStringNFA(boolean caseless, String str) {
pos += Character.charCount(ch);
}

return IntPair.create(start, i + start);
return new IntPair(start, i + start);
}

private void insertClassNFA(List<Interval> intervals, int start, int end) {
Expand Down Expand Up @@ -732,7 +732,7 @@ private IntPair complement(IntPair nfa) {
Out.debug("NFA is :" + Out.NL + this);
}

int dfaStart = nfa.end() + 1;
int dfaStart = nfa.end + 1;

// FIXME: only need epsilon closure of states reachable from nfa.start
epsilonFill();
Expand All @@ -745,7 +745,7 @@ private IntPair complement(IntPair nfa) {

StateSet currentState, newState;

newState = epsilon[nfa.start()];
newState = epsilon[nfa.start];
dfaStates.put(newState, numDFAStates);
dfaList.add(newState);

Expand Down Expand Up @@ -822,7 +822,7 @@ private IntPair complement(IntPair nfa) {
currentDFAState = dfaStart + s;

// if it was not a final state, it is now in the complement
if (!currentState.isElement(nfa.end())) addEpsilonTransition(currentDFAState, end);
if (!currentState.isElement(nfa.end)) addEpsilonTransition(currentDFAState, end);

// all inputs not present (formerly leading to an implicit error)
// now lead to an explicit (final) state accepting everything.
Expand All @@ -841,7 +841,7 @@ private IntPair complement(IntPair nfa) {
if (Options.DEBUG) {
Out.debug("complement finished, nfa (" + start + "," + end + ") is now :" + this);
}
return IntPair.create(start, end);
return new IntPair(start, end);
}

// "global" data for use in method removeDead only:
Expand Down Expand Up @@ -962,7 +962,7 @@ public IntPair insertNFA(RegExp regExp) {

insertCCLNFA(regExp, start, end);

return IntPair.create(start, end);
return new IntPair(start, end);
}

switch (regExp.type) {
Expand All @@ -972,59 +972,59 @@ public IntPair insertNFA(RegExp regExp) {
nfa1 = insertNFA(r.r1);
nfa2 = insertNFA(r.r2);

start = nfa2.end() + 1;
end = nfa2.end() + 2;
start = nfa2.end + 1;
end = nfa2.end + 2;

addEpsilonTransition(start, nfa1.start());
addEpsilonTransition(start, nfa2.start());
addEpsilonTransition(nfa1.end(), end);
addEpsilonTransition(nfa2.end(), end);
addEpsilonTransition(start, nfa1.start);
addEpsilonTransition(start, nfa2.start);
addEpsilonTransition(nfa1.end, end);
addEpsilonTransition(nfa2.end, end);

return IntPair.create(start, end);
return new IntPair(start, end);

case sym.CONCAT:
r = (RegExp2) regExp;

nfa1 = insertNFA(r.r1);
nfa2 = insertNFA(r.r2);

addEpsilonTransition(nfa1.end(), nfa2.start());
addEpsilonTransition(nfa1.end, nfa2.start);

return IntPair.create(nfa1.start(), nfa2.end());
return new IntPair(nfa1.start, nfa2.end);

case sym.STAR:
nfa1 = insertNFA((RegExp) ((RegExp1) regExp).content);

start = nfa1.end() + 1;
end = nfa1.end() + 2;
start = nfa1.end + 1;
end = nfa1.end + 2;

addEpsilonTransition(nfa1.end(), end);
addEpsilonTransition(start, nfa1.start());
addEpsilonTransition(nfa1.end, end);
addEpsilonTransition(start, nfa1.start);

addEpsilonTransition(start, end);
addEpsilonTransition(nfa1.end(), nfa1.start());
addEpsilonTransition(nfa1.end, nfa1.start);

return IntPair.create(start, end);
return new IntPair(start, end);

case sym.PLUS:
nfa1 = insertNFA((RegExp) ((RegExp1) regExp).content);

start = nfa1.end() + 1;
end = nfa1.end() + 2;
start = nfa1.end + 1;
end = nfa1.end + 2;

addEpsilonTransition(nfa1.end(), end);
addEpsilonTransition(start, nfa1.start());
addEpsilonTransition(nfa1.end, end);
addEpsilonTransition(start, nfa1.start);

addEpsilonTransition(nfa1.end(), nfa1.start());
addEpsilonTransition(nfa1.end, nfa1.start);

return IntPair.create(start, end);
return new IntPair(start, end);

case sym.QUESTION:
nfa1 = insertNFA((RegExp) ((RegExp1) regExp).content);

addEpsilonTransition(nfa1.start(), nfa1.end());
addEpsilonTransition(nfa1.start, nfa1.end);

return IntPair.create(nfa1.start(), nfa1.end());
return new IntPair(nfa1.start, nfa1.end);

case sym.BANG:
return complement(insertNFA((RegExp) ((RegExp1) regExp).content));
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
15 changes: 0 additions & 15 deletions third_party/com/google/auto_value/BUILD

This file was deleted.

5 changes: 0 additions & 5 deletions third_party/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ def third_party_deps():
repository = "https://jcenter.bintray.com/",
sha1 = "9746af1a485e50cf18dcb232489032a847067066",
)
native.maven_jar(
name = "com_google_auto_value_auto_value",
artifact = "com.google.auto.value:auto-value:jar:1.4.1",
repository = "http://jcenter.bintray.com/",
)
native.maven_jar(
name = "com_google_guava_guava",
artifact = "com.google.guava:guava:jar:26.0-jre",
Expand Down

0 comments on commit d4899d3

Please sign in to comment.