-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from pollyvolk/syntax
Fixes to #87
- Loading branch information
Showing
8 changed files
with
291 additions
and
5 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
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
161 changes: 161 additions & 0 deletions
161
src/test/resources/codegen/java/matcher_generator_extract_particular_type.txt
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,161 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Ivan Kniazkov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.uast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.cqfn.astranaut.core.Matcher; | ||
import org.cqfn.astranaut.core.Node; | ||
|
||
/** | ||
* Checks if the node matches some structure, and extracts the data and children. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public final class Matcher0 implements Matcher { | ||
/** | ||
* The instance. | ||
*/ | ||
public static final Matcher INSTANCE = new Matcher0(); | ||
|
||
/** | ||
* Expected node type. | ||
*/ | ||
private static final String EXPECTED_TYPE = "AAA"; | ||
|
||
/** | ||
* The number of the first hole. | ||
*/ | ||
private static final int FIRST_HOLE_ID = 1; | ||
|
||
/** | ||
* The number of the second hole. | ||
*/ | ||
private static final int SECOND_HOLE_ID = 2; | ||
|
||
/** | ||
* The index of the first child. | ||
*/ | ||
private static final int FIRST_CHILD_ID = 2; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
private Matcher0() { | ||
} | ||
|
||
@Override | ||
public boolean match(final Node node, | ||
final Map<Integer, List<Node>> children, | ||
final Map<Integer, String> data) { | ||
final boolean result = node.belongsToGroup(Matcher0.EXPECTED_TYPE) | ||
&& Matcher1.INSTANCE.match(node.getChild(0), children, data); | ||
if (result) { | ||
final int count = node.getChildCount(); | ||
final List<Node> list = new ArrayList<>(count - 1); | ||
for (int index = 1; index < count; index = index + 1) { | ||
final Node child = node.getChild(index); | ||
if ("CCC".equals(child.getTypeName())) { | ||
list.add(child); | ||
} | ||
} | ||
children.put(Matcher0.FIRST_HOLE_ID, list); | ||
children.put( | ||
Matcher0.SECOND_HOLE_ID, | ||
Collections.singletonList(node.getChild(Matcher0.FIRST_CHILD_ID)) | ||
); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Ivan Kniazkov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.uast; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.cqfn.astranaut.core.Matcher; | ||
import org.cqfn.astranaut.core.Node; | ||
|
||
/** | ||
* Checks if the node matches some structure, and extracts the data and children. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public final class Matcher1 implements Matcher { | ||
/** | ||
* The instance. | ||
*/ | ||
public static final Matcher INSTANCE = new Matcher1(); | ||
|
||
/** | ||
* Expected node type. | ||
*/ | ||
private static final String EXPECTED_TYPE = "BBB"; | ||
|
||
/** | ||
* Expected number of child nodes. | ||
*/ | ||
private static final int EXPECTED_COUNT = 0; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
private Matcher1() { | ||
} | ||
|
||
@Override | ||
public boolean match(final Node node, | ||
final Map<Integer, List<Node>> children, | ||
final Map<Integer, String> data) { | ||
return node.belongsToGroup(Matcher1.EXPECTED_TYPE) | ||
&& node.getChildCount() == Matcher1.EXPECTED_COUNT; | ||
} | ||
} |
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,40 @@ | ||
{ | ||
"root": { | ||
"type": "F", | ||
"children": [ | ||
{ | ||
"type": "BB", | ||
"children": [ | ||
{ | ||
"type": "B", | ||
"data": "1" | ||
}, | ||
{ | ||
"type": "B", | ||
"data": "2" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "B", | ||
"data": "0" | ||
}, | ||
{ | ||
"type": "C" | ||
}, | ||
{ | ||
"type": "DD", | ||
"children": [ | ||
{ | ||
"type": "D", | ||
"data": "1" | ||
}, | ||
{ | ||
"type": "D", | ||
"data": "2" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
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 @@ | ||
A(B#1, C, B<#2>, D#3) -> F(BB(#1), B<#2>, C, DD(#3)); |
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,30 @@ | ||
{ | ||
"root" : { | ||
"type" : "A", | ||
"children": [ | ||
{ | ||
"type": "B", | ||
"data": "1" | ||
}, | ||
{ | ||
"type": "B", | ||
"data": "2" | ||
}, | ||
{ | ||
"type": "C" | ||
}, | ||
{ | ||
"type": "B", | ||
"data": "0" | ||
}, | ||
{ | ||
"type": "D", | ||
"data": "1" | ||
}, | ||
{ | ||
"type": "D", | ||
"data": "2" | ||
} | ||
] | ||
} | ||
} |