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

Add meta variables to SDF3 Stratego mix syntax test #65

Open
wants to merge 14 commits 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
11 changes: 8 additions & 3 deletions org.metaborg.sdf3.meta.integrationtest/editor/Main.esv
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ menus

menu: "Transform"

action: "Swap (abstract syntax)" = swap-editor-abstract-syntax (source)
action: "Swap (concrete syntax)" = swap-editor-concrete-syntax (source)
action: "Swap (concrete syntax simple)" = swap-editor-concrete-syntax-simple (source)
action: "Swap exps (abstract syntax)" = editor-action-swap-exps-abstract-syntax (source)
action: "Swap exps (concrete syntax)" = editor-action-swap-exps-concrete-syntax (source)
action: "Swap exps (concrete syntax simple)" = editor-action-swap-exps-concrete-syntax-simple (source)
action: "Swap exps (concrete syntax var)" = editor-action-swap-exps-concrete-syntax-var (source)
action: "Reverse stmts (concrete syntax varlist)" = editor-action-reverse-stmts-concrete-syntax-varlist (source)
action: "Surround stmts (concrete syntax varlist)" = editor-action-surround-stmts-concrete-syntax-varlist (source)
action: "Surround stmts 2 (concrete syntax varlist)" = editor-action-surround-stmts-concrete-syntax-varlist2 (source)
action: "Surround stmts (concrete syntax list fromterm)" = editor-action-surround-stmts-concrete-syntax-list-fromterm (source)
35 changes: 34 additions & 1 deletion org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,45 @@ imports

context-free start-symbols

StrategoLang-Module
Module

context-free sorts

Module StmtListMeta

context-free syntax

Module = StrategoLang-Module

StrategoLang-PreTerm.ToTerm = <|[ <Stmt> ]|>
StrategoLang-PreTerm.ToTerm = <stmt |[ <Stmt> ]|>

StrategoLang-PreTerm.ToTerm = <|[ <Start> ]|>
StrategoLang-PreTerm.ToTerm = <program |[ <Start> ]|>

Exp.FromTerm = [~[StrategoLang-Term]]
Exp.FromTerm = [~exp:[StrategoLang-Term]]

StmtListMeta.FromTerm = [~*[StrategoLang-Term]]

Stmt+ = StmtListMeta
Stmt+.Conc = Stmt+ StmtListMeta

context-free syntax // meta variables

Exp.meta-var = ExpVar

StmtListMeta.meta-listvar = StmtListVar

lexical sorts

ExpVar StmtListVar

lexical syntax

ExpVar = 'exp' [0-9]*
StmtListVar = 'stmt' [0-9]* '*'

lexical restrictions

ExpVar -/- [0-9]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ context-free sorts

context-free syntax

Start.Program = Stmt
Start.Program = Stmt+
Stmt.Stmt = [[Exp];]
Exp.Add = [[Exp] + [Exp]]
Exp.Var = VAR
16 changes: 13 additions & 3 deletions org.metaborg.sdf3.meta.integrationtest/test/swap.spt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ language sdf3-meta-integrationtest

start symbol Start

test swap [[x + y;]] transform "Transform -> Swap (abstract syntax)" to [[y + x;]]
test swap [[x + y;]] transform "Transform -> Swap exps (abstract syntax)" to [[y + x;]]

test swap [[x + y;]] transform "Transform -> Swap (concrete syntax)" to [[y + x;]]
test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax)" to [[y + x;]]

test swap [[x + y;]] transform "Transform -> Swap (concrete syntax simple)" to [[y + x;]]
test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax simple)" to [[y + x;]]

test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax var)" to [[y + x;]]

test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]]

test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[a; x; y; b;]]

test swap [[x; y;]] transform "Transform -> Surround stmts 2 (concrete syntax varlist)" to [[y; x; a; x; y; x; y; b; y; x;]]

test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax list fromterm)" to [[a; x; y; b;]]
51 changes: 40 additions & 11 deletions org.metaborg.sdf3.meta.integrationtest/trans/swap.str
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,49 @@ imports

rules

swap-editor-abstract-syntax = swap-editor(swap-exp-abstract-syntax|)
swap-editor-concrete-syntax = swap-editor(swap-exp-concrete-syntax|)
swap-editor-concrete-syntax-simple = swap-editor(swap-exp-concrete-syntax-simple|)

swap-editor(swap-exp|):
(_, _, ast, path, _) -> (path, <topdown(try(swap-exp))> ast)

swap-exp-abstract-syntax:
editor-action-swap-exps-abstract-syntax = editor-action(swap-exps-abstract-syntax)
editor-action-swap-exps-concrete-syntax = editor-action(swap-exps-concrete-syntax)
editor-action-swap-exps-concrete-syntax-simple = editor-action(swap-exps-concrete-syntax-simple)
editor-action-swap-exps-concrete-syntax-var = editor-action(swap-exps-concrete-syntax-var)
editor-action-reverse-stmts-concrete-syntax-varlist = editor-action(reverse-stmts-concrete-syntax-varlist)
editor-action-surround-stmts-concrete-syntax-varlist = editor-action(surround-stmts-concrete-syntax-varlist)
editor-action-surround-stmts-concrete-syntax-varlist2 = editor-action(surround-stmts-concrete-syntax-varlist2)
editor-action-surround-stmts-concrete-syntax-list-fromterm = editor-action(surround-stmts-concrete-syntax-list-fromterm)

editor-action(s):
(_, _, ast, path, _) -> (path, <oncetd(s)> ast)

swap-exps-abstract-syntax:
Add(e1, e2) -> Add(e2, e1)

swap-exp-concrete-syntax:
swap-exps-concrete-syntax:
stmt |[ ~exp:e1 + ~exp:e2 ; ]| ->
stmt |[ ~exp:e2 + ~exp:e1 ; ]|

swap-exp-concrete-syntax-simple:
swap-exps-concrete-syntax-simple:
|[ ~e1 + ~e2 ; ]| ->
|[ ~e2 + ~e1 ; ]|
|[ ~e2 + ~e1 ; ]|

swap-exps-concrete-syntax-var:
|[ exp + exp2 ; ]| ->
|[ exp2 + exp ; ]|

reverse-stmts-concrete-syntax-varlist:
|[ stmt1* ]| ->
|[ stmt2* ]|
where stmt2* := <reverse> stmt1*

surround-stmts-concrete-syntax-varlist:
|[ stmt1* ]| ->
program |[ a; stmt1* b; ]|
where stmt2* := <reverse> stmt1*

surround-stmts-concrete-syntax-varlist2:
|[ stmt1* ]| ->
program |[ stmt2* a; stmt1* stmt1* b; stmt2* ]|
where stmt2* := <reverse> stmt1*

surround-stmts-concrete-syntax-list-fromterm:
|[ ~*stmt1* ]| ->
program |[ a; ~*stmt1* b; ]|
where stmt2* := <reverse> stmt1*
14 changes: 14 additions & 0 deletions sdf3.stratego2.integrationtest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.cache
/bin
/src-gen
/target

/.classpath
/.project
/.settings
/.factorypath

/.polyglot.metaborg.yaml

/trans/foo.tbl
/trans/table-foo.bin
8 changes: 8 additions & 0 deletions sdf3.stratego2.integrationtest/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.metaborg</groupId>
<artifactId>spoofax-maven-plugin-pomless</artifactId>
<version>2.6.0-SNAPSHOT</version>
</extension>
</extensions>
23 changes: 23 additions & 0 deletions sdf3.stratego2.integrationtest/editor/Main.esv
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Main

language

extensions : s3mit

// provider : target/metaborg/stratego.ctree

table : target/metaborg/sdf.tbl
start symbols : Start

menus

menu: "Transform"

action: "Swap exps (abstract syntax)" = editor-action-swap-exps-abstract-syntax (source)
action: "Swap exps (concrete syntax)" = editor-action-swap-exps-concrete-syntax (source)
action: "Swap exps (concrete syntax simple)" = editor-action-swap-exps-concrete-syntax-simple (source)
action: "Swap exps (concrete syntax var)" = editor-action-swap-exps-concrete-syntax-var (source)
action: "Reverse stmts (concrete syntax varlist)" = editor-action-reverse-stmts-concrete-syntax-varlist (source)
action: "Surround stmts (concrete syntax varlist)" = editor-action-surround-stmts-concrete-syntax-varlist (source)
action: "Surround stmts 2 (concrete syntax varlist)" = editor-action-surround-stmts-concrete-syntax-varlist2 (source)
action: "Surround stmts (concrete syntax list fromterm)" = editor-action-surround-stmts-concrete-syntax-list-fromterm (source)
39 changes: 39 additions & 0 deletions sdf3.stratego2.integrationtest/metaborg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: org.metaborg:sdf3.stratego2.integrationtest:2.6.0-SNAPSHOT
name: sdf3-stratego2-integrationtest
dependencies:
compile:
- org.metaborg:org.metaborg.meta.lang.esv:${metaborgVersion}
- org.metaborg:org.metaborg.meta.lang.template:${metaborgVersion}
- org.metaborg:org.metaborg.meta.lang.spt:${metaborgVersion}
- org.metaborg:stratego.lang:${metaborgVersion}
source:
- org.metaborg:meta.lib.spoofax:${metaborgVersion}
- org.metaborg:stratego.lang:${metaborgVersion}
- org.metaborg:strategolib:${metaborgVersion}
pardonedLanguages:
- EditorService
- Stratego-Sugar
- SDF
language:
sdf:
pretty-print: sdf3-stratego2-integrationtest
version: sdf3
sdf2table: java
sdf-meta:
- foo
placeholder:
prefix: "$"
stratego:
format: jar
args:
- -la
- stratego-sglr
- -la
- stratego-xtc
- -la
- stratego-aterm
- -la
- stratego-sdf
- -la
- strc
64 changes: 64 additions & 0 deletions sdf3.stratego2.integrationtest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<modelVersion>4.0.0</modelVersion>
<artifactId>sdf3.stratego2.integrationtest</artifactId>
<packaging>spoofax-language</packaging>

<parent>
<groupId>org.metaborg</groupId>
<artifactId>parent.language</artifactId>
<version>2.6.0-SNAPSHOT</version>
<relativePath>../../releng/parent/java</relativePath>
</parent>

<dependencies>
<!-- compile -->
<dependency>
<groupId>org.metaborg</groupId>
<artifactId>org.metaborg.meta.lang.esv</artifactId>
<version>${metaborg-version}</version>
<type>spoofax-language</type>
</dependency>
<dependency>
<groupId>org.metaborg</groupId>
<artifactId>org.metaborg.meta.lang.spt</artifactId>
<version>${metaborg-version}</version>
<type>spoofax-language</type>
<scope>test</scope>
</dependency>

<!-- source -->
<dependency>
<groupId>org.metaborg</groupId>
<artifactId>meta.lib.spoofax</artifactId>
<version>${metaborg-version}</version>
<type>spoofax-language</type>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.metaborg</groupId>
<artifactId>spoofax-maven-plugin</artifactId>
<version>${metaborg-version}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<languageUnderTest>org.metaborg:sdf3.stratego2.integrationtest:${metaborg-version}</languageUnderTest>
</configuration>
</plugin>
</plugins>
</build>
</project>
51 changes: 51 additions & 0 deletions sdf3.stratego2.integrationtest/syntax/foo.sdf3
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module foo

imports

StrategoLang/import-namespaced
StrategoLang/core/modules-namespaced
StrategoLang/sugar/terms-namespaced
thesyntax

context-free start-symbols

Module

context-free sorts

Module StmtListMeta

context-free syntax

Module = StrategoLang-Module

StrategoLang-PreTerm.ToTerm = <stmt |[ <Stmt> ]|>
StrategoLang-PreTerm.ToTerm = <program |[ <Start> ]|>

Exp.FromTerm = [~[StrategoLang-Term]]
Exp.FromTerm = [~exp:[StrategoLang-Term]]

StmtListMeta.FromTerm = [~*[StrategoLang-Term]]

Stmt+ = StmtListMeta
Stmt+.Conc = Stmt+ StmtListMeta

context-free syntax // meta variables

Exp.meta-var = ExpVar

StmtListMeta.meta-listvar = StmtListVar

lexical sorts

ExpVar StmtListVar

lexical syntax

ExpVar = 'exp' [0-9]*
StmtListVar = 'stmt' [0-9]* '*'
Var = ExpVar {reject}

lexical restrictions

ExpVar -/- [0-9]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module sdf3-stratego2-integrationtest

imports
thesyntax

context-free start-symbols

Start
21 changes: 21 additions & 0 deletions sdf3.stratego2.integrationtest/syntax/thesyntax.sdf3
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module thesyntax

lexical sorts
VAR

lexical syntax
LAYOUT = [\t\ \n\r]
VAR = [a-z]+

context-free restrictions
LAYOUT? -/- [\ \t\n\r]

context-free sorts
Start Stmt Exp

context-free syntax

Start.Program = Stmt+
Stmt.Stmt = [[Exp];]
Exp.Add = [[Exp] + [Exp]]
Exp.Var = VAR
Loading