-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new events like
leftParenthesis()
/rightParenthesis()
as…
… a replacement for `openGroup()` and `closeGroup()`. It is more efficient and allows to write clearer code.
- Loading branch information
Showing
8 changed files
with
233 additions
and
26 deletions.
There are no files selected for viewing
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,7 @@ | ||
# Upgrading from 1.x | ||
|
||
Tokenproducer 2.0 replaces the methods `openGroup()` and `closeGroup()` with | ||
`leftParenthesis()`/`rightParenthesis()` and others. Using the new event methods | ||
may allow you to write clearer code, although you can also have your old | ||
`TokenHandler` implementation inherit from the new `LegacyTokenHandler`, which | ||
is compatible with the 1.x API and provides a simpler upgrade path. |
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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/io/sf/carte/uparser/util/LegacyTokenHandler.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,73 @@ | ||
/* | ||
Copyright (c) 2017-2023, Carlos Amengual. | ||
Licensed under a BSD-style License. You can find the license here: | ||
https://css4j.github.io/LICENSE.txt | ||
*/ | ||
|
||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
package io.sf.carte.uparser.util; | ||
|
||
import io.sf.carte.uparser.TokenHandler; | ||
import io.sf.carte.uparser.TokenProducer; | ||
|
||
/** | ||
* A {@link TokenHandler} that is backwards-compatible with | ||
* {@code TokenProducer} 1.x. | ||
*/ | ||
public interface LegacyTokenHandler extends TokenHandler { | ||
|
||
@Override | ||
default void leftParenthesis(int index) { | ||
openGroup(index, TokenProducer.CHAR_LEFT_PAREN); | ||
} | ||
|
||
@Override | ||
default void leftSquareBracket(int index) { | ||
openGroup(index, TokenProducer.CHAR_LEFT_SQ_BRACKET); | ||
} | ||
|
||
@Override | ||
default void leftCurlyBracket(int index) { | ||
openGroup(index, TokenProducer.CHAR_LEFT_CURLY_BRACKET); | ||
} | ||
|
||
@Override | ||
default void rightParenthesis(int index) { | ||
closeGroup(index, TokenProducer.CHAR_RIGHT_PAREN); | ||
} | ||
|
||
@Override | ||
default void rightSquareBracket(int index) { | ||
closeGroup(index, TokenProducer.CHAR_RIGHT_SQ_BRACKET); | ||
} | ||
|
||
@Override | ||
default void rightCurlyBracket(int index) { | ||
closeGroup(index, TokenProducer.CHAR_RIGHT_CURLY_BRACKET); | ||
} | ||
|
||
/** | ||
* Called when one of these codepoints is found: (, [, { | ||
* | ||
* @param index | ||
* the index at which the codepoint was found. | ||
* @param codePoint | ||
* the found codepoint. | ||
*/ | ||
void openGroup(int index, int codePoint); | ||
|
||
/** | ||
* Called when one of these codepoints is found: ), ], } | ||
* | ||
* @param index | ||
* the index at which the codepoint was found. | ||
* @param codePoint | ||
* the found codepoint. | ||
*/ | ||
void closeGroup(int index, int codePoint); | ||
|
||
} |
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,4 @@ | ||
/** | ||
* Utility interfaces | ||
*/ | ||
package io.sf.carte.uparser.util; |
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 |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
*/ | ||
module io.sf.carte.tokenproducer { | ||
exports io.sf.carte.uparser; | ||
exports io.sf.carte.uparser.util; | ||
} |
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