Skip to content

Commit

Permalink
Merge branch 'feature/antlr-support' of github.com:specs-feup/anyweav…
Browse files Browse the repository at this point in the history
…er into feature/antlr-support
  • Loading branch information
lm-sousa committed Aug 1, 2024
2 parents 9914fae + 9850e58 commit 38c45b3
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 10 deletions.
6 changes: 6 additions & 0 deletions AnyAst/resources/pt/up/fe/specs/anycompiler/srl-ast.json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GenericAnyNode: STREAM::store: {args=[outputStream], id=node::1, type=STREAM::store}
GenericAnyNode: OP::+: {id=node::2, type=OP::+}
GenericAnyNode: STREAM::load: {args=[S2], id=node::3, type=STREAM::load}
GenericAnyNode: OP::*: {id=node::4, type=OP::*}
GenericAnyNode: STREAM::load: {args=[S1], id=node::5, type=STREAM::load}
GenericAnyNode: INPUT::VALUE: {args=[mult_factor], id=node::6, type=INPUT::VALUE}
8 changes: 6 additions & 2 deletions AnyAst/test/pt/up/fe/specs/anycompiler/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@

package pt.up.fe.specs.anycompiler;


import org.junit.Assert;
import org.junit.Test;
import pt.up.fe.specs.anycompiler.parsers.JsonParser;
import pt.up.fe.specs.util.SpecsIo;
import pt.up.fe.specs.util.SpecsStrings;

public class JsonParserTest {

@Test
public void testSrlAst() {
var code = SpecsIo.getResource(() -> "pt/up/fe/specs/anycompiler/srl-ast.json");
var code = SpecsIo.getResource("pt/up/fe/specs/anycompiler/srl-ast.json");
var parser = new JsonParser("type", "children", true);
var ast = parser.parse(code);
System.out.println("AST:" + ast.toTree());

Assert.assertTrue(SpecsStrings.check(SpecsIo.getResource("pt/up/fe/specs/anycompiler/srl-ast.json.txt"), ast.toTree()));
}
}
16 changes: 8 additions & 8 deletions AnyWeaver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ sourceSets {
}
}

/*

test {
java {
srcDir 'test'
}
java {
srcDir 'test'
}

resources {
srcDir 'resources'
}
resources {
srcDir 'test-resources'
}
}
*/


}

Expand Down
7 changes: 7 additions & 0 deletions AnyWeaver/test-resources/anyweaver/test/weaver/Srl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
laraImport("weaver.Query");

for (const l of Query.search("STREAM::load")) {
console.log(l.getValue("args"));
}

console.log("Hello")
30 changes: 30 additions & 0 deletions AnyWeaver/test-resources/anyweaver/test/weaver/src/srl-ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"node::1": {
"type": "STREAM::store",
"args": ["outputStream"],
"children": ["node::2"]
},
"node::2": {
"type": "OP::+",
"children": ["node::3", "node::4"]
},
"node::3": {
"type": "STREAM::load",
"args": ["S2"],
"children": []
},
"node::4": {
"type": "OP::*",
"children": ["node::5", "node::6"]
},
"node::5": {
"type": "STREAM::load",
"args": ["S1"],
"children": []
},
"node::6": {
"type": "INPUT::VALUE",
"args": ["mult_factor"],
"children": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pt.up.fe.specs.anycompiler.weaver;


import org.lara.interpreter.tester.WeaverTester;

public class AnyWeaverTester extends WeaverTester<AnyWeaver, AnyWeaverTester> {

public AnyWeaverTester(String basePackage) {
super(AnyWeaver.class, basePackage);

// Set custom settings
//getCustomData().
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright 2016 SPeCS.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License. under the License.
*/

package pt.up.fe.specs.anycompiler.weaver.tests;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
import pt.up.fe.specs.anycompiler.weaver.AnyWeaverTester;
import pt.up.fe.specs.util.SpecsSystem;

public class AnyWeaverTest {

@BeforeClass
public static void setupOnce() {
SpecsSystem.programStandardInit();
AnyWeaverTester.clean();
}

@After
public void tearDown() {
AnyWeaverTester.clean();
}

private static AnyWeaverTester newTester() {
return new AnyWeaverTester("anyweaver/test/weaver/")
.setSrcPackage("src/")
.setResultPackage("results/");
}

@Test
public void testBasic() {
newTester().test("Srl.js", "srl-ast.json");
}


}

0 comments on commit 38c45b3

Please sign in to comment.