Skip to content

Commit

Permalink
Get rid of DetailValue & related
Browse files Browse the repository at this point in the history
Closes #205
  • Loading branch information
raph-amiard committed Mar 26, 2024
1 parent 07175d7 commit 857d49b
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 405 deletions.
16 changes: 8 additions & 8 deletions lkql/build/railroad-diagrams/pattern_arg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 4 additions & 29 deletions lkql/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,29 +955,6 @@ class NodeKindPattern(NodePattern):
kind_name = Field(type=Identifier)


@abstract
class DetailValue(LkqlNode):
"""
Root node class for pattern data values.
Pattern data values can be expressions or patterns.
"""
pass


class DetailExpr(DetailValue):
"""
Expression pattern data value.
"""
expr_value = Field(type=Expr)


class DetailPattern(DetailValue):
"""
Pattern pattern data value
"""
pattern_value = Field(type=BasePattern)


@abstract
class NodePatternDetail(LkqlNode):
"""
Expand All @@ -991,15 +968,15 @@ class NodePatternField(NodePatternDetail):
Access to a field in a node pattern.
"""
identifier = Field(type=Identifier)
expected_value = Field(type=DetailValue)
expected_value = Field(type=BasePattern)


class NodePatternProperty(NodePatternDetail):
"""
Access to a property in a node pattern.
"""
call = Field(type=FunCall)
expected_value = Field(type=DetailValue)
expected_value = Field(type=BasePattern)


class NodePatternSelector(NodePatternDetail):
Expand Down Expand Up @@ -1162,12 +1139,10 @@ class Tuple(Expr):

pattern_arg=Or(
NodePatternSelector(G.selector_call, "is", G.pattern),
NodePatternField(G.id, "is", c(), G.detail_value),
NodePatternProperty(G.fun_call, "is", c(), G.detail_value)
NodePatternField(G.id, "is", c(), G.pattern),
NodePatternProperty(G.fun_call, "is", c(), G.pattern)
),

detail_value=Or(DetailPattern(G.pattern), DetailExpr(G.expr)),

selector_call=SelectorCall(
Identifier(Or(
Token.Identifier(match_text="any"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,18 +951,6 @@ public Void visit(Liblkqllang.NodeKindPattern nodeKindPattern) {
return null;
}

@Override
public Void visit(Liblkqllang.DetailExpr detailExpr) {
traverseChildren(detailExpr);
return null;
}

@Override
public Void visit(Liblkqllang.DetailPattern detailPattern) {
traverseChildren(detailPattern);
return null;
}

@Override
public Void visit(Liblkqllang.NodePatternDetailList nodePatternDetailList) {
traverseChildren(nodePatternDetailList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,36 +1654,6 @@ public LKQLNode visit(Liblkqllang.NodeKindPattern nodeKindPattern) {
return new NodeKindPattern(loc(nodeKindPattern), nodeKindPattern.fKindName().getText());
}

/**
* Visit a detail expression node.
*
* @param detailExpr The detail expression node from Langkit.
* @return The detail expression node for Truffle.
*/
@Override
public LKQLNode visit(Liblkqllang.DetailExpr detailExpr) {
// Translate the detail expression fields
final Expr expr = (Expr) detailExpr.fExprValue().accept(this);

// Return the new detail expression node
return DetailExprNodeGen.create(loc(detailExpr), expr);
}

/**
* Visit a detail pattern node.
*
* @param detailPattern The detail pattern node from Langkit
* @return The detail pattern node for Truffle.
*/
@Override
public LKQLNode visit(Liblkqllang.DetailPattern detailPattern) {
// Translate the detail pattern fields
final BasePattern pattern = (BasePattern) detailPattern.fPatternValue().accept(this);

// Return the new detail pattern node
return new DetailPattern(loc(detailPattern), pattern);
}

/**
* Visit a node pattern field node.
*
Expand All @@ -1694,7 +1664,7 @@ public LKQLNode visit(Liblkqllang.DetailPattern detailPattern) {
public LKQLNode visit(Liblkqllang.NodePatternField nodePatternField) {
// Translate the node pattern detail fields
final String name = nodePatternField.fIdentifier().getText();
final DetailValue expected = (DetailValue) nodePatternField.fExpectedValue().accept(this);
final BasePattern expected = (BasePattern) nodePatternField.fExpectedValue().accept(this);

// Return the new node pattern field detail
return NodePatternFieldNodeGen.create(loc(nodePatternField), name, expected);
Expand All @@ -1711,8 +1681,8 @@ public LKQLNode visit(Liblkqllang.NodePatternProperty nodePatternProperty) {
// Translate the node pattern detail fields
final String propertyName = nodePatternProperty.fCall().fName().getText();
final ArgList argList = (ArgList) nodePatternProperty.fCall().fArguments().accept(this);
final DetailValue expected =
(DetailValue) nodePatternProperty.fExpectedValue().accept(this);
final BasePattern expected =
(BasePattern) nodePatternProperty.fExpectedValue().accept(this);

// Return the new node pattern property detail
return NodePatternPropertyNodeGen.create(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 857d49b

Please sign in to comment.