-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1672 from bhamiltoncx/code-point-transitions
New class CodePointTransitions to create SetTransitions for Unicode code points > U+FFFF
- Loading branch information
Showing
3 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
runtime/Java/src/org/antlr/v4/runtime/atn/CodePointTransitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. | ||
* Use of this file is governed by the BSD 3-clause license that | ||
* can be found in the LICENSE.txt file in the project root. | ||
*/ | ||
|
||
package org.antlr.v4.runtime.atn; | ||
|
||
import org.antlr.v4.runtime.misc.IntervalSet; | ||
|
||
/** | ||
* Utility class to create {@link AtomTransition}, {@link RangeTransition}, | ||
* and {@link SetTransition} appropriately based on the range of the input. | ||
* | ||
* To keep the serialized ATN size small, we only inline atom and | ||
* range transitions for Unicode code points <= U+FFFF. | ||
* | ||
* Whenever we encounter a Unicode code point > U+FFFF, we represent that | ||
* as a set transition (even if it is logically an atom or a range). | ||
*/ | ||
public abstract class CodePointTransitions { | ||
/** | ||
* If {@code codePoint} is <= U+FFFF, returns a new {@link AtomTransition}. | ||
* Otherwise, returns a new {@link SetTransition}. | ||
*/ | ||
public static Transition createWithCodePoint(ATNState target, int codePoint) { | ||
if (Character.isSupplementaryCodePoint(codePoint)) { | ||
return new SetTransition(target, IntervalSet.of(codePoint)); | ||
} else { | ||
return new AtomTransition(target, codePoint); | ||
} | ||
} | ||
|
||
/** | ||
* If {@code codePointFrom} and {@code codePointTo} are both | ||
* <= U+FFFF, returns a new {@link RangeTransition}. | ||
* Otherwise, returns a new {@link SetTransition}. | ||
*/ | ||
public static Transition createWithCodePointRange( | ||
ATNState target, | ||
int codePointFrom, | ||
int codePointTo) { | ||
if (Character.isSupplementaryCodePoint(codePointFrom) || | ||
Character.isSupplementaryCodePoint(codePointTo)) { | ||
return new SetTransition(target, IntervalSet.of(codePointFrom, codePointTo)); | ||
} else { | ||
return new RangeTransition(target, codePointFrom, codePointTo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters