-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update OH parser version, add translation and specific exception support
- Loading branch information
1 parent
1039966
commit 8c3e79a
Showing
8 changed files
with
337 additions
and
89 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/bin/ | ||
/.classpath | ||
/.externalToolBuilders/ | ||
/.project |
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,8 @@ | ||
[main] | ||
host = https://www.transifex.com | ||
|
||
[conditionalresrtictionparser.messagesproperties] | ||
file_filter = src/main/resources/ch/poole/conditionalresrtictionparser/Messages_<lang>.properties | ||
source_file = src/main/resources/ch/poole/conditionalresrtictionparser/Messages.properties | ||
source_lang = en | ||
minimum_perc = 100 |
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
104 changes: 104 additions & 0 deletions
104
...main/java/ch/poole/conditionalrestrictionparser/ConditionalRestrictionParseException.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,104 @@ | ||
package ch.poole.conditionalrestrictionparser; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static ch.poole.conditionalrestrictionparser.I18n.tr; | ||
|
||
/** | ||
* Represents an exception when parsing the conditional restriction string | ||
* @author JOSM team, Simon Legner | ||
*/ | ||
public class ConditionalRestrictionParseException extends ParseException { | ||
|
||
private final int line; | ||
private final int column; | ||
private String encountered = null; | ||
private String expected = null; | ||
|
||
ConditionalRestrictionParseException(String message) { | ||
this(message, -1, -1); | ||
} | ||
|
||
ConditionalRestrictionParseException(String message, @Nullable Token token) { | ||
this(message, token != null ? token.beginLine : -1, token != null ? token.beginColumn : -1); | ||
} | ||
|
||
private ConditionalRestrictionParseException(String message, int line, int column) { | ||
super(message); | ||
this.line = line; | ||
this.column = column; | ||
} | ||
|
||
ConditionalRestrictionParseException(ParseException ex) { | ||
this(null, ex.currentToken); | ||
this.currentToken = ex.currentToken; | ||
this.expectedTokenSequences = ex.expectedTokenSequences; | ||
this.tokenImage = ex.tokenImage; | ||
setEncounteredExpected(); | ||
} | ||
|
||
/** | ||
* Returns the line number | ||
* @return the line number | ||
*/ | ||
public int getLine() { | ||
return line; | ||
} | ||
|
||
/** | ||
* Returns the column number | ||
* @return the column number | ||
*/ | ||
public int getColumn() { | ||
return column; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
final String message = encountered == null || encountered.isEmpty() | ||
? super.getMessage() | ||
: tr("exception_encountered", encountered); | ||
final String string = line >= 0 && column >= 0 | ||
? tr("exception_line_column", message, line, column) | ||
: message; | ||
final String appendix = expected == null || expected.isEmpty() | ||
? "" | ||
: EOL + tr("exception_expecting", expected); | ||
return string + appendix; | ||
} | ||
|
||
private void setEncounteredExpected() { | ||
// localized ch.poole.openinghoursparser.ParseException.initialise | ||
StringBuilder expected = new StringBuilder(); | ||
int maxSize = 0; | ||
for (int[] expectedTokenSequence : expectedTokenSequences) { | ||
if (maxSize < expectedTokenSequence.length) { | ||
maxSize = expectedTokenSequence.length; | ||
} | ||
for (int i : expectedTokenSequence) { | ||
expected.append(tokenImage[i]).append(' '); | ||
} | ||
if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) { | ||
expected.append("..."); | ||
} | ||
expected.append(EOL).append(" "); | ||
} | ||
this.expected = expected.toString().trim(); | ||
|
||
StringBuilder encountered = new StringBuilder(); | ||
Token tok = currentToken.next; | ||
for (int i = 0; i < maxSize; i++) { | ||
if (i != 0) encountered.append(" "); | ||
if (tok.kind == 0) { | ||
encountered.append(tokenImage[0]); | ||
break; | ||
} | ||
encountered.append(" ").append(tokenImage[tok.kind]); | ||
encountered.append(" \""); | ||
encountered.append(add_escapes(tok.image)); | ||
encountered.append(" \""); | ||
tok = tok.next; | ||
} | ||
this.encountered = encountered.toString(); | ||
} | ||
} |
Oops, something went wrong.