Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jun 24, 2023
1 parent 6ff61f6 commit 74a2d98
Show file tree
Hide file tree
Showing 24 changed files with 489 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4476,29 +4476,35 @@ final public void closed_pattern() throws ParseException {
}

final public void literal_pattern() throws ParseException {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
case MINUS:
case DECNUMBER:
case HEXNUMBER:
case OCTNUMBER:
case BINNUMBER:
case FLOAT:
case COMPLEX:
signed_number();
/*@bgen(jjtree) literal_pattern */
SimpleNode jjtn000 = builder.openNode( JJTLITERAL_PATTERN);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
try {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
case MINUS:
case DECNUMBER:
case HEXNUMBER:
case OCTNUMBER:
case BINNUMBER:
case FLOAT:
case COMPLEX:
signed_number();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
jj_consume_token(PLUS);
case MINUS:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
jj_consume_token(PLUS);
SimpleNode jjtn001 = builder.openNode( JJTADD_2OP);
boolean jjtc001 = true;
jjtree.openNodeScope(jjtn001);
jjtreeOpenNodeScope(jjtn001);
try {
signed_number();
} catch (Throwable jjte001) {
try {
signed_number();
} catch (Throwable jjte001) {
if (jjtc001) {
jjtree.clearNodeScope(jjtn001);
jjtc001 = false;
Expand All @@ -4512,22 +4518,22 @@ final public void literal_pattern() throws ParseException {
{if (true) throw (ParseException)jjte001;}
}
{if (true) throw (Error)jjte001;}
} finally {
} finally {
if (jjtc001) {
jjtree.closeNodeScope(jjtn001, 2);
jjtreeCloseNodeScope(jjtn001);
}
}
break;
case MINUS:
jj_consume_token(MINUS);
}
break;
case MINUS:
jj_consume_token(MINUS);
SimpleNode jjtn002 = builder.openNode( JJTSUB_2OP);
boolean jjtc002 = true;
jjtree.openNodeScope(jjtn002);
jjtreeOpenNodeScope(jjtn002);
try {
signed_number();
} catch (Throwable jjte002) {
try {
signed_number();
} catch (Throwable jjte002) {
if (jjtc002) {
jjtree.clearNodeScope(jjtn002);
jjtc002 = false;
Expand All @@ -4541,55 +4547,75 @@ final public void literal_pattern() throws ParseException {
{if (true) throw (ParseException)jjte002;}
}
{if (true) throw (Error)jjte002;}
} finally {
} finally {
if (jjtc002) {
jjtree.closeNodeScope(jjtn002, 2);
jjtreeCloseNodeScope(jjtn002);
}
}
break;
default:
jj_la1[95] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
break;
default:
jj_la1[95] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
jj_la1[96] = jj_gen;
;
}
break;
case SINGLE_STRING:
case SINGLE_STRING2:
case TRIPLE_STRING:
case TRIPLE_STRING2:
case SINGLE_BSTRING:
case SINGLE_BSTRING2:
case TRIPLE_BSTRING:
case TRIPLE_BSTRING2:
case SINGLE_FSTRING:
case SINGLE_FSTRING2:
case TRIPLE_FSTRING:
case TRIPLE_FSTRING2:
case SINGLE_USTRING:
case SINGLE_USTRING2:
case TRIPLE_USTRING:
case TRIPLE_USTRING2:
String();
break;
case NONE:
jj_consume_token(NONE);
break;
case TRUE:
jj_consume_token(TRUE);
break;
case FALSE:
jj_consume_token(FALSE);
break;
default:
jj_la1[96] = jj_gen;
;
jj_la1[97] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
{if (true) throw (RuntimeException)jjte000;}
}
if (jjte000 instanceof ParseException) {
{if (true) throw (ParseException)jjte000;}
}
{if (true) throw (Error)jjte000;}
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
break;
case SINGLE_STRING:
case SINGLE_STRING2:
case TRIPLE_STRING:
case TRIPLE_STRING2:
case SINGLE_BSTRING:
case SINGLE_BSTRING2:
case TRIPLE_BSTRING:
case TRIPLE_BSTRING2:
case SINGLE_FSTRING:
case SINGLE_FSTRING2:
case TRIPLE_FSTRING:
case TRIPLE_FSTRING2:
case SINGLE_USTRING:
case SINGLE_USTRING2:
case TRIPLE_USTRING:
case TRIPLE_USTRING2:
String();
break;
case NONE:
jj_consume_token(NONE);
break;
case TRUE:
jj_consume_token(TRUE);
break;
case FALSE:
jj_consume_token(FALSE);
break;
default:
jj_la1[97] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import org.python.pydev.parser.jython.ast.Match;
import org.python.pydev.parser.jython.ast.MatchAs;
import org.python.pydev.parser.jython.ast.MatchClass;
import org.python.pydev.parser.jython.ast.MatchKeyword;
import org.python.pydev.parser.jython.ast.MatchKeyVal;
import org.python.pydev.parser.jython.ast.MatchMapping;
import org.python.pydev.parser.jython.ast.MatchOr;
import org.python.pydev.parser.jython.ast.MatchSequence;
import org.python.pydev.parser.jython.ast.MatchValue;
import org.python.pydev.parser.jython.ast.Name;
import org.python.pydev.parser.jython.ast.NameTok;
import org.python.pydev.parser.jython.ast.NameTokType;
import org.python.pydev.parser.jython.ast.NamedExpr;
import org.python.pydev.parser.jython.ast.NonLocal;
import org.python.pydev.parser.jython.ast.Pass;
Expand Down Expand Up @@ -617,41 +618,69 @@ public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
addAndReportException(patternType.class.getName());
return getDefaultInvalidPattern();

case JJTLITERAL_PATTERN:
return new MatchValue((exprType) securePop(exprType.class));

case JJTCLOSED_PATTERN:
popSurplus(arity, 2);
if (arity == 1) {
return stack.popNode();
return securePop(patternType.class);
} else if (arity == 2) {
MatchClass classPattern = (MatchClass) securePop(MatchClass.class);
exprType cls = (exprType) securePop(exprType.class);
return new MatchClass(cls, classPattern.args);
SimpleNode cls = stack.popNode();
if (cls instanceof exprType) {
classPattern.cls = (exprType) cls;
return classPattern;
} else if (cls instanceof MatchValue) {
MatchValue matchValue = (MatchValue) cls;
classPattern.cls = matchValue.value;
return classPattern;
}
}
addAndReportException(exprType.class.getName());
return getDefaultInvalidExpr();

case JJTKEY_VALUE_PATTERN:
popSurplus(arity, 2);
if (arity == 1) {
// This means we got into the double_star_pattern()
// and we just have a Name there. This is the '**rest'
Name doubleStarName = (Name) securePop(Name.class);
return makeNameTok(NameTok.PatternMappingRest, doubleStarName);
}

if (arity == 2) {
patternType pattern = (patternType) securePop(patternType.class);
exprType arg = (exprType) securePop(exprType.class);
return new MatchKeyword(arg, pattern);
MatchValue arg = (MatchValue) securePop(MatchValue.class);

// We want the expr in the MatchValue. As we're removing the MatchValue itself
// we need to copy what it had before.
this.addSpecialsAndClearOriginal(arg, arg.value);

MatchKeyVal matchKeyword = new MatchKeyVal(arg.value, pattern);
return matchKeyword;
}
addAndReportException(exprType.class.getName());
return getDefaultInvalidExpr();

case JJTMAPPING_PATTERN:
if (arity > 0) {
exprType[] keys = new exprType[arity];
patternType[] patterns = new patternType[arity];
java.util.List<patternType> lst = new ArrayList<>();
NameTokType rest = null;
for (int i = arity - 1; i >= 0; i--) {
MatchKeyword pattern = (MatchKeyword) securePop(MatchKeyword.class);
keys[i] = pattern.arg;
patterns[i] = pattern.value;
SimpleNode found = stack.popNode();
if (found instanceof MatchKeyVal) {
lst.add((MatchKeyVal) found);
} else {
if (found instanceof NameTok) {
rest = (NameTokType) found;
}
}
}
return new MatchMapping(keys, patterns);
return new MatchMapping(lst.toArray(new patternType[0]), rest);
}
addAndReportException(MatchKeyword.class.getName());
return new MatchMapping(new exprType[0], new patternType[0]);
addAndReportException(MatchKeyVal.class.getName());
return new MatchMapping(new patternType[0], null);

case JJTLIST_PATTERN:
return createMatchSequence(arity, enclosingType.LIST);
Expand All @@ -664,16 +693,17 @@ public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
if (isPeekedNodeWildcardPattern()) {
return new MatchValue(makeName(Name.Pattern));
}
return stack.popNode();
return new MatchValue((exprType) securePop(exprType.class));
} else if (arity >= 2) {
SimpleNode peekedNode = stack.peekNode();
if (peekedNode instanceof patternType) {
popSurplus(arity, 2);
patternType pattern = (patternType) securePop(patternType.class);
Name arg = makeName(Name.Artificial);
return new MatchKeyword(arg, pattern);
return new MatchKeyVal(arg, pattern);
} else {
return popMatchAttributeInMatch(arity);
Attribute attr = popMatchAttributeInMatch(arity);
return new MatchValue(attr);
}
}
addAndReportException(Attribute.class.getName());
Expand Down Expand Up @@ -808,8 +838,8 @@ private SimpleNode getDefaultInvalidNode(Class<? extends SimpleNode> cls) throws
return new Suite(getDefaultBody());
} else if (MatchClass.class.equals(cls)) {
return new MatchClass(getDefaultInvalidExpr(), null);
} else if (MatchKeyword.class.equals(cls)) {
return new MatchKeyword(getDefaultInvalidExpr(), getDefaultInvalidPattern());
} else if (MatchKeyVal.class.equals(cls)) {
return new MatchKeyVal(getDefaultInvalidExpr(), getDefaultInvalidPattern());
}
throw new Exception("Could not find any invalid default node for " + cls.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ void closed_pattern() : {}
// | wildcard_pattern() "_" is matched as a regular Name
}

void literal_pattern() #void : {}
void literal_pattern() : {}
{
signed_number() (
<PLUS> signed_number() #add_2op(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ void closed_pattern() : {}
// | wildcard_pattern() "_" is matched as a regular Name
}

void literal_pattern() #void : {}
void literal_pattern() : {}
{
signed_number() (
<PLUS> signed_number() #add_2op(2)
Expand Down
Loading

0 comments on commit 74a2d98

Please sign in to comment.