Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support \p 1-char char classes without curly braces #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/org/joni/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,11 @@ private void fetchTokenFor_charProperty() {
unfetch();
}
}
token.setPropSingleChar(false);
} else if (syntax.op2EscPCharCharProperty()) {
token.type = TokenType.CHAR_PROPERTY;
token.setPropNot(c == 'P');
token.setPropSingleChar(true);
} else {
syntaxWarn(Warnings.INVALID_UNICODE_PROPERTY, (char)c);
}
Expand Down Expand Up @@ -1252,13 +1257,18 @@ private void possessiveCheck() {
protected final int fetchCharPropertyToCType() {
mark();

while (left()) {
int last = p;
if (token.getPropSingleChar()) {
fetch();
if (c == '}') {
return enc.propertyNameToCType(bytes, _p, last);
} else if (c == '(' || c == ')' || c == '{' || c == '|') {
throw new CharacterPropertyException(ERR_INVALID_CHAR_PROPERTY_NAME, bytes, _p, last);
return enc.propertyNameToCType(bytes, _p, p);
} else {
while (left()) {
int last = p;
fetch();
if (c == '}') {
return enc.propertyNameToCType(bytes, _p, last);
} else if (c == '(' || c == ')' || c == '{' || c == '|') {
throw new CharacterPropertyException(ERR_INVALID_CHAR_PROPERTY_NAME, bytes, _p, last);
}
}
}
newInternalException(ERR_PARSER_BUG);
Expand Down
7 changes: 6 additions & 1 deletion src/org/joni/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ public boolean op2QMarkLParenCondition() {
return isOp2(OP2_QMARK_LPAREN_CONDITION);
}

public boolean op2EscPCharCharProperty() {
return isOp2(OP2_ESC_P_BRACE_CHAR_PROPERTY);
}

/**
* BEHAVIOR
*
Expand Down Expand Up @@ -540,7 +544,8 @@ public boolean warnReduntantNestedRepeat() {
OP2_OPTION_PERL | OP2_PLUS_POSSESSIVE_REPEAT |
OP2_PLUS_POSSESSIVE_INTERVAL | OP2_CCLASS_SET_OP |
OP2_ESC_V_VTAB | OP2_ESC_U_HEX4 |
OP2_ESC_P_BRACE_CHAR_PROPERTY ),
OP2_ESC_P_BRACE_CHAR_PROPERTY |
OP2_ESC_P_CHAR_CHAR_PROPERTY),

( GNU_REGEX_BV | DIFFERENT_LEN_ALT_LOOK_BEHIND ),

Expand Down
7 changes: 7 additions & 0 deletions src/org/joni/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ boolean getPropNot() {
void setPropNot(boolean not) {
INT2 = not ? 1 : 0;
}

boolean getPropSingleChar() {
return INT3 != 0;
}
void setPropSingleChar(boolean singleChar) {
INT3 = singleChar ? 1 : 0;
}
}
1 change: 1 addition & 0 deletions src/org/joni/constants/SyntaxProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public interface SyntaxProperties {
final int OP2_ESC_H_XDIGIT = (1<<19); /* \h, \H */
final int OP2_INEFFECTIVE_ESCAPE = (1<<20); /* \ */
final int OP2_OPTION_ECMASCRIPT = (1<<21); /* EcmaScript quirks */
final int OP2_ESC_P_CHAR_CHAR_PROPERTY = (1<<22); /* \pX, \PX */

final int OP2_QMARK_LPAREN_CONDITION = (1<<29); /* (?(cond)yes...|no...) */

Expand Down