From a7b63b6b15f325db94ece7ed37338970f829a055 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Tue, 29 Mar 2022 14:36:16 +0200 Subject: [PATCH 01/15] Add meta variables to SDF3 Stratego mix syntax test --- .../editor/Main.esv | 3 ++- .../syntax/foo.sdf3 | 12 ++++++++++++ org.metaborg.sdf3.meta.integrationtest/test/swap.spt | 4 +++- .../trans/swap.str | 7 ++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv index bb2b99314..4746d898d 100644 --- a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv +++ b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv @@ -15,4 +15,5 @@ menus 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) \ No newline at end of file + action: "Swap (concrete syntax simple)" = swap-editor-concrete-syntax-simple (source) + action: "Swap (concrete syntax var)" = swap-editor-concrete-syntax-var (source) \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index 85401e5c6..677f28a44 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -17,3 +17,15 @@ context-free syntax Exp.FromTerm = [~[StrategoLang-Term]] Exp.FromTerm = [~exp:[StrategoLang-Term]] + +// TODO: support variables section in SDF3 or document this as the way to write Stratego mix syntax + + Exp.meta-var = ExpVar + +lexical sorts + + ExpVar + +lexical syntax + + ExpVar = 'exp' [0-9]* diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index fb672e692..356ea81b1 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -8,4 +8,6 @@ test swap [[x + y;]] transform "Transform -> Swap (abstract syntax)" to [ test swap [[x + y;]] transform "Transform -> Swap (concrete syntax)" to [[y + x;]] -test swap [[x + y;]] transform "Transform -> Swap (concrete syntax simple)" to [[y + x;]] \ No newline at end of file +test swap [[x + y;]] transform "Transform -> Swap (concrete syntax simple)" to [[y + x;]] + +test swap [[x + y;]] transform "Transform -> Swap (concrete syntax var)" to [[y + x;]] \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 0fea0b7f5..65e9661cd 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -10,6 +10,7 @@ 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-concrete-syntax-var = swap-editor(swap-exp-concrete-syntax-var|) swap-editor(swap-exp|): (_, _, ast, path, _) -> (path, ast) @@ -23,4 +24,8 @@ rules swap-exp-concrete-syntax-simple: |[ ~e1 + ~e2 ; ]| -> - |[ ~e2 + ~e1 ; ]| \ No newline at end of file + |[ ~e2 + ~e1 ; ]| + + swap-exp-concrete-syntax-var: + |[ exp1 + exp2 ; ]| -> + |[ exp2 + exp1 ; ]| \ No newline at end of file From b2c0b47effb5b51069e266547e079d6d79216db0 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Tue, 29 Mar 2022 14:57:35 +0200 Subject: [PATCH 02/15] Failed attempt at meta list variables in mix syntax --- org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 | 9 +++++++++ .../syntax/thesyntax.sdf3 | 2 +- org.metaborg.sdf3.meta.integrationtest/trans/swap.str | 9 +++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index 677f28a44..a060068a6 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -15,12 +15,16 @@ context-free syntax StrategoLang-PreTerm.ToTerm = <|[ ]|> StrategoLang-PreTerm.ToTerm = ]|> + StrategoLang-PreTerm.ToTerm = <|[ ]|> + StrategoLang-PreTerm.ToTerm = ]|> + Exp.FromTerm = [~[StrategoLang-Term]] Exp.FromTerm = [~exp:[StrategoLang-Term]] // TODO: support variables section in SDF3 or document this as the way to write Stratego mix syntax Exp.meta-var = ExpVar + Stmt+.meta-list-var = StmtListVar lexical sorts @@ -29,3 +33,8 @@ lexical sorts lexical syntax ExpVar = 'exp' [0-9]* + StmtListVar = 'stmt' [0-9]* '*' + +lexical restrictions + + ExpVar -/- [0-9] \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/thesyntax.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/thesyntax.sdf3 index 3c2534959..2e57cf9f7 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/thesyntax.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/thesyntax.sdf3 @@ -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 \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 65e9661cd..74eeaf73e 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -27,5 +27,10 @@ rules |[ ~e2 + ~e1 ; ]| swap-exp-concrete-syntax-var: - |[ exp1 + exp2 ; ]| -> - |[ exp2 + exp1 ; ]| \ No newline at end of file + |[ exp + exp2 ; ]| -> + |[ exp2 + exp ; ]| + +// reverse-stmts-concrete: +// |[ stmt1* ]| -> +// |[ stmt2* ]| +// where stmt2* := stmt1* \ No newline at end of file From 062581420c7a17328738132f4d0a9747b816e46a Mon Sep 17 00:00:00 2001 From: Jasper Denkers Date: Tue, 5 Apr 2022 13:27:42 +0200 Subject: [PATCH 03/15] meta-listvar instead of meta-list-var as constructor for list meta-variables --- org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 | 2 +- org.metaborg.sdf3.meta.integrationtest/trans/swap.str | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index a060068a6..b60452313 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -24,7 +24,7 @@ context-free syntax // TODO: support variables section in SDF3 or document this as the way to write Stratego mix syntax Exp.meta-var = ExpVar - Stmt+.meta-list-var = StmtListVar + Stmt+.meta-listvar = StmtListVar lexical sorts diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 74eeaf73e..7101a9841 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -30,7 +30,7 @@ rules |[ exp + exp2 ; ]| -> |[ exp2 + exp ; ]| -// reverse-stmts-concrete: -// |[ stmt1* ]| -> -// |[ stmt2* ]| -// where stmt2* := stmt1* \ No newline at end of file + reverse-stmts-concrete: + |[ stmt1* ]| -> + |[ stmt2* ]| + where stmt2* := stmt1* \ No newline at end of file From ed74418c538d6f21ecf044de5b6a6ed92bdf0205 Mon Sep 17 00:00:00 2001 From: Jasper Denkers Date: Tue, 5 Apr 2022 13:29:56 +0200 Subject: [PATCH 04/15] Add test for lists meta-vars in concrete object syntax --- org.metaborg.sdf3.meta.integrationtest/editor/Main.esv | 3 ++- org.metaborg.sdf3.meta.integrationtest/test/swap.spt | 4 +++- org.metaborg.sdf3.meta.integrationtest/trans/swap.str | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv index 4746d898d..3bbd92a93 100644 --- a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv +++ b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv @@ -16,4 +16,5 @@ menus 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 (concrete syntax var)" = swap-editor-concrete-syntax-var (source) \ No newline at end of file + action: "Swap (concrete syntax var)" = swap-editor-concrete-syntax-var (source) + action: "Reverse stmts (concrete syntax varlist)" = reverse-editor-stmts-concrete-syntax-varlist (source) \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index 356ea81b1..d8c6981e2 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -10,4 +10,6 @@ test swap [[x + y;]] transform "Transform -> Swap (concrete syntax)" to [ test swap [[x + y;]] transform "Transform -> Swap (concrete syntax simple)" to [[y + x;]] -test swap [[x + y;]] transform "Transform -> Swap (concrete syntax var)" to [[y + x;]] \ No newline at end of file +test swap [[x + y;]] transform "Transform -> Swap (concrete syntax var)" to [[y + x;]] + +test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]] \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 7101a9841..e07a77071 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -11,6 +11,7 @@ rules swap-editor-concrete-syntax = swap-editor(swap-exp-concrete-syntax|) swap-editor-concrete-syntax-simple = swap-editor(swap-exp-concrete-syntax-simple|) swap-editor-concrete-syntax-var = swap-editor(swap-exp-concrete-syntax-var|) + reverse-editor-stmts-concrete-syntax-varlist = swap-editor(reverse-stmts-concrete|) swap-editor(swap-exp|): (_, _, ast, path, _) -> (path, ast) From c68e6a7d31358f8f42c7de581e0f05afe2b2e5fb Mon Sep 17 00:00:00 2001 From: Jasper Denkers Date: Tue, 5 Apr 2022 13:38:04 +0200 Subject: [PATCH 05/15] Rename/cleanup test strategies and actions to be more consistent --- .../editor/Main.esv | 10 ++++---- .../test/swap.spt | 8 +++---- .../trans/swap.str | 24 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv index 3bbd92a93..97a68d82e 100644 --- a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv +++ b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv @@ -13,8 +13,8 @@ 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 (concrete syntax var)" = swap-editor-concrete-syntax-var (source) - action: "Reverse stmts (concrete syntax varlist)" = reverse-editor-stmts-concrete-syntax-varlist (source) \ No newline at end of file + 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) \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index d8c6981e2..388024727 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -4,12 +4,12 @@ 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 (concrete syntax var)" 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;]] \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index e07a77071..4ac78a63a 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -7,31 +7,31 @@ 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-concrete-syntax-var = swap-editor(swap-exp-concrete-syntax-var|) - reverse-editor-stmts-concrete-syntax-varlist = swap-editor(reverse-stmts-concrete|) + 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) - swap-editor(swap-exp|): - (_, _, ast, path, _) -> (path, ast) + editor-action(s): + (_, _, ast, path, _) -> (path, ast) - swap-exp-abstract-syntax: + 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 ; ]| - swap-exp-concrete-syntax-var: + swap-exps-concrete-syntax-var: |[ exp + exp2 ; ]| -> |[ exp2 + exp ; ]| - reverse-stmts-concrete: + reverse-stmts-concrete-syntax-varlist: |[ stmt1* ]| -> |[ stmt2* ]| where stmt2* := stmt1* \ No newline at end of file From 76fd71b2a5bab0a1302464d81c5efd2e2457c802 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Tue, 5 Apr 2022 14:28:51 +0200 Subject: [PATCH 06/15] Add failing test with Conc --- .../editor/Main.esv | 11 ++++++----- .../test/swap.spt | 7 ++++++- .../trans/swap.str | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv index 97a68d82e..7c30e8b43 100644 --- a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv +++ b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv @@ -13,8 +13,9 @@ 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) \ No newline at end of file + 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) \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index 388024727..070e0a2a2 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -12,4 +12,9 @@ test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax simple)" 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;]] \ No newline at end of file +test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]] + +// This test will fail due to broken Conc generation, not sure why yet +test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[ + //a; + x; y; a;]] diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 4ac78a63a..7622444a9 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -7,11 +7,12 @@ imports rules - 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-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(s): (_, _, ast, path, _) -> (path, ast) @@ -34,4 +35,10 @@ rules reverse-stmts-concrete-syntax-varlist: |[ stmt1* ]| -> |[ stmt2* ]| - where stmt2* := stmt1* \ No newline at end of file + where stmt2* := stmt1* + + surround-stmts-concrete-syntax-varlist: + |[ stmt1* ]| -> + program |[ //a; // adding anything before the meta-listvar breaks parsing + stmt1* + a; ]| \ No newline at end of file From 47937bc37bbd24e2b68a3dcdaa6f0422a3e6c39b Mon Sep 17 00:00:00 2001 From: Jasper Denkers Date: Fri, 15 Apr 2022 10:22:11 +0200 Subject: [PATCH 07/15] Add missing list normalization rule for meta list var --- org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 | 1 + org.metaborg.sdf3.meta.integrationtest/test/swap.spt | 4 +--- org.metaborg.sdf3.meta.integrationtest/trans/swap.str | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index b60452313..4dd1ecbcb 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -25,6 +25,7 @@ context-free syntax Exp.meta-var = ExpVar Stmt+.meta-listvar = StmtListVar + Stmt+.Snoc = Stmt+ StmtListVar lexical sorts diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index 070e0a2a2..769ed6f53 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -15,6 +15,4 @@ test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax var)" test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]] // This test will fail due to broken Conc generation, not sure why yet -test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[ - //a; - x; y; a;]] +test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[a; x; y; a;]] diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 7622444a9..9d438cf3f 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -39,6 +39,4 @@ rules surround-stmts-concrete-syntax-varlist: |[ stmt1* ]| -> - program |[ //a; // adding anything before the meta-listvar breaks parsing - stmt1* - a; ]| \ No newline at end of file + program |[ a; stmt1* a; ]| From 9355c3c3426702754096acb93daa585bebb474f2 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Wed, 8 Mar 2023 18:14:55 +0100 Subject: [PATCH 08/15] We've settled on this as code that should work --- .../syntax/foo.sdf3 | 24 ++++++++++++++++--- .../test/swap.spt | 2 +- .../trans/swap.str | 6 ++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index 4dd1ecbcb..1e4e31244 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -10,6 +10,10 @@ context-free start-symbols StrategoLang-Module +context-free sorts + + StmtMLV + context-free syntax StrategoLang-PreTerm.ToTerm = <|[ ]|> @@ -24,12 +28,26 @@ context-free syntax // TODO: support variables section in SDF3 or document this as the way to write Stratego mix syntax Exp.meta-var = ExpVar - Stmt+.meta-listvar = StmtListVar - Stmt+.Snoc = Stmt+ StmtListVar + +/* + Stmt* = // Nil + Stmt* = Stmt+ // (injection) + Stmt+ = Stmt // Ins + Stmt+ = Stmt+ Stmt // Snoc + + // Stmt+ = Stmt Stmt+ // (would be Cons) + // Stmt+ = Stmt+ Stmt+ {right} // (old Conc rule before Snoc) +*/ + + + StmtMLV.meta-listvar = StmtListVar + + Stmt+ = StmtMLV + Stmt+.Conc = Stmt+ StmtMLV lexical sorts - ExpVar + ExpVar StmtListVar lexical syntax diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index 769ed6f53..515812d96 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -15,4 +15,4 @@ test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax var)" test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]] // This test will fail due to broken Conc generation, not sure why yet -test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[a; x; y; a;]] +test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[a; x; y; b;]] diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index 9d438cf3f..fd834c044 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -15,7 +15,7 @@ rules editor-action-surround-stmts-concrete-syntax-varlist = editor-action(surround-stmts-concrete-syntax-varlist) editor-action(s): - (_, _, ast, path, _) -> (path, ast) + (_, _, ast, path, _) -> (path, ast) swap-exps-abstract-syntax: Add(e1, e2) -> Add(e2, e1) @@ -38,5 +38,5 @@ rules where stmt2* := stmt1* surround-stmts-concrete-syntax-varlist: - |[ stmt1* ]| -> - program |[ a; stmt1* a; ]| + |[ stmt1* ]| -> + program |[ a; stmt1* b; ]| From f3c9705cbcc96562cbc8139effbc9afcd198eb0f Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Thu, 9 Mar 2023 15:29:28 +0100 Subject: [PATCH 09/15] More tests, for meta-listvar and for FromTerm as a sublist --- .../editor/Main.esv | 4 ++- .../syntax/foo.sdf3 | 31 +++++++------------ .../test/swap.spt | 7 +++-- .../trans/swap.str | 13 ++++++++ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv index 7c30e8b43..846b53479 100644 --- a/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv +++ b/org.metaborg.sdf3.meta.integrationtest/editor/Main.esv @@ -18,4 +18,6 @@ menus 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) \ No newline at end of file + 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) \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 index 1e4e31244..f74720305 100644 --- a/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 +++ b/org.metaborg.sdf3.meta.integrationtest/syntax/foo.sdf3 @@ -8,14 +8,16 @@ imports context-free start-symbols - StrategoLang-Module + Module context-free sorts - StmtMLV + Module StmtListMeta context-free syntax + Module = StrategoLang-Module + StrategoLang-PreTerm.ToTerm = <|[ ]|> StrategoLang-PreTerm.ToTerm = ]|> @@ -24,26 +26,17 @@ context-free syntax Exp.FromTerm = [~[StrategoLang-Term]] Exp.FromTerm = [~exp:[StrategoLang-Term]] + + StmtListMeta.FromTerm = [~*[StrategoLang-Term]] -// TODO: support variables section in SDF3 or document this as the way to write Stratego mix syntax - - Exp.meta-var = ExpVar - -/* - Stmt* = // Nil - Stmt* = Stmt+ // (injection) - Stmt+ = Stmt // Ins - Stmt+ = Stmt+ Stmt // Snoc + Stmt+ = StmtListMeta + Stmt+.Conc = Stmt+ StmtListMeta - // Stmt+ = Stmt Stmt+ // (would be Cons) - // Stmt+ = Stmt+ Stmt+ {right} // (old Conc rule before Snoc) -*/ +context-free syntax // meta variables - - StmtMLV.meta-listvar = StmtListVar - - Stmt+ = StmtMLV - Stmt+.Conc = Stmt+ StmtMLV + Exp.meta-var = ExpVar + + StmtListMeta.meta-listvar = StmtListVar lexical sorts diff --git a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt index 515812d96..e475e9278 100644 --- a/org.metaborg.sdf3.meta.integrationtest/test/swap.spt +++ b/org.metaborg.sdf3.meta.integrationtest/test/swap.spt @@ -14,5 +14,8 @@ test swap [[x + y;]] transform "Transform -> Swap exps (concrete syntax var)" test swap [[x; y;]] transform "Transform -> Reverse stmts (concrete syntax varlist)" to [[y; x;]] -// This test will fail due to broken Conc generation, not sure why yet -test swap [[x; y;]] transform "Transform -> Surround stmts (concrete syntax varlist)" to [[a; x; y; b;]] +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;]] \ No newline at end of file diff --git a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str index fd834c044..34b00b7da 100644 --- a/org.metaborg.sdf3.meta.integrationtest/trans/swap.str +++ b/org.metaborg.sdf3.meta.integrationtest/trans/swap.str @@ -13,6 +13,8 @@ rules 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, ast) @@ -40,3 +42,14 @@ rules surround-stmts-concrete-syntax-varlist: |[ stmt1* ]| -> program |[ a; stmt1* b; ]| + where stmt2* := stmt1* + + surround-stmts-concrete-syntax-varlist2: + |[ stmt1* ]| -> + program |[ stmt2* a; stmt1* stmt1* b; stmt2* ]| + where stmt2* := stmt1* + + surround-stmts-concrete-syntax-list-fromterm: + |[ ~*stmt1* ]| -> + program |[ a; ~*stmt1* b; ]| + where stmt2* := stmt1* From 32fe7b5bf87609146c8175b3c9c1267785a45f05 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Thu, 9 Mar 2023 16:25:44 +0100 Subject: [PATCH 10/15] Add Stratego 2 version of integrationtest. Does not parse sublists correctly to Conc, they become list elements instead --- sdf3.stratego2.integrationtest/.gitignore | 14 + .../.mvn/extensions.xml | 8 + .../editor/Main.esv | 23 ++ sdf3.stratego2.integrationtest/metaborg.yaml | 39 +++ sdf3.stratego2.integrationtest/pom.xml | 64 ++++ .../syntax/foo.sdf3 | 50 +++ .../sdf3-stratego2-integrationtest.sdf3 | 8 + .../syntax/thesyntax.sdf3 | 21 ++ sdf3.stratego2.integrationtest/test/swap.spt | 21 ++ .../trans/sdf3_stratego2_integrationtest.str2 | 5 + .../trans/swap.aterm | 284 ++++++++++++++++++ .../trans/swap.meta | 1 + .../trans/swap.str2 | 72 +++++ 13 files changed, 610 insertions(+) create mode 100644 sdf3.stratego2.integrationtest/.gitignore create mode 100644 sdf3.stratego2.integrationtest/.mvn/extensions.xml create mode 100644 sdf3.stratego2.integrationtest/editor/Main.esv create mode 100644 sdf3.stratego2.integrationtest/metaborg.yaml create mode 100644 sdf3.stratego2.integrationtest/pom.xml create mode 100644 sdf3.stratego2.integrationtest/syntax/foo.sdf3 create mode 100644 sdf3.stratego2.integrationtest/syntax/sdf3-stratego2-integrationtest.sdf3 create mode 100644 sdf3.stratego2.integrationtest/syntax/thesyntax.sdf3 create mode 100644 sdf3.stratego2.integrationtest/test/swap.spt create mode 100644 sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 create mode 100644 sdf3.stratego2.integrationtest/trans/swap.aterm create mode 100644 sdf3.stratego2.integrationtest/trans/swap.meta create mode 100644 sdf3.stratego2.integrationtest/trans/swap.str2 diff --git a/sdf3.stratego2.integrationtest/.gitignore b/sdf3.stratego2.integrationtest/.gitignore new file mode 100644 index 000000000..a0dffdd88 --- /dev/null +++ b/sdf3.stratego2.integrationtest/.gitignore @@ -0,0 +1,14 @@ +/.cache +/bin +/src-gen +/target + +/.classpath +/.project +/.settings +/.factorypath + +/.polyglot.metaborg.yaml + +/trans/foo.tbl +/trans/table-foo.bin \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/.mvn/extensions.xml b/sdf3.stratego2.integrationtest/.mvn/extensions.xml new file mode 100644 index 000000000..878ae8be4 --- /dev/null +++ b/sdf3.stratego2.integrationtest/.mvn/extensions.xml @@ -0,0 +1,8 @@ + + + + org.metaborg + spoofax-maven-plugin-pomless + 2.6.0-SNAPSHOT + + diff --git a/sdf3.stratego2.integrationtest/editor/Main.esv b/sdf3.stratego2.integrationtest/editor/Main.esv new file mode 100644 index 000000000..86a411000 --- /dev/null +++ b/sdf3.stratego2.integrationtest/editor/Main.esv @@ -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) \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/metaborg.yaml b/sdf3.stratego2.integrationtest/metaborg.yaml new file mode 100644 index 000000000..d239751fa --- /dev/null +++ b/sdf3.stratego2.integrationtest/metaborg.yaml @@ -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 diff --git a/sdf3.stratego2.integrationtest/pom.xml b/sdf3.stratego2.integrationtest/pom.xml new file mode 100644 index 000000000..3dba1393b --- /dev/null +++ b/sdf3.stratego2.integrationtest/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + sdf3.stratego2.integrationtest + spoofax-language + + + org.metaborg + parent.language + 2.6.0-SNAPSHOT + ../../releng/parent/java + + + + + + org.metaborg + org.metaborg.meta.lang.esv + ${metaborg-version} + spoofax-language + + + org.metaborg + org.metaborg.meta.lang.spt + ${metaborg-version} + spoofax-language + test + + + + + org.metaborg + meta.lib.spoofax + ${metaborg-version} + spoofax-language + provided + + + + + + + org.metaborg + spoofax-maven-plugin + ${metaborg-version} + + + test + + test + + + + + org.metaborg:sdf3.stratego2.integrationtest:${metaborg-version} + + + + + \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 new file mode 100644 index 000000000..56e1f5a41 --- /dev/null +++ b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 @@ -0,0 +1,50 @@ +module foo + +imports + + StrategoLang/import-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 = <|[ ]|> + StrategoLang-PreTerm.ToTerm = ]|> + StrategoLang-PreTerm.ToTerm = ]|> + + 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] diff --git a/sdf3.stratego2.integrationtest/syntax/sdf3-stratego2-integrationtest.sdf3 b/sdf3.stratego2.integrationtest/syntax/sdf3-stratego2-integrationtest.sdf3 new file mode 100644 index 000000000..aa79bd95e --- /dev/null +++ b/sdf3.stratego2.integrationtest/syntax/sdf3-stratego2-integrationtest.sdf3 @@ -0,0 +1,8 @@ +module sdf3-stratego2-integrationtest + +imports + thesyntax + +context-free start-symbols + + Start diff --git a/sdf3.stratego2.integrationtest/syntax/thesyntax.sdf3 b/sdf3.stratego2.integrationtest/syntax/thesyntax.sdf3 new file mode 100644 index 000000000..2e57cf9f7 --- /dev/null +++ b/sdf3.stratego2.integrationtest/syntax/thesyntax.sdf3 @@ -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 \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/test/swap.spt b/sdf3.stratego2.integrationtest/test/swap.spt new file mode 100644 index 000000000..c0996b456 --- /dev/null +++ b/sdf3.stratego2.integrationtest/test/swap.spt @@ -0,0 +1,21 @@ +module swap + +language sdf3-stratego2-integrationtest + +start symbol Start + +test swap [[x + y;]] transform "Transform -> Swap (abstract syntax)" to [[y + x;]] + +test swap [[x + y;]] transform "Transform -> Swap (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 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;]] \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 b/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 new file mode 100644 index 000000000..78f3a03c3 --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 @@ -0,0 +1,5 @@ +module sdf3_stratego2_integrationtest + +imports + + swap diff --git a/sdf3.stratego2.integrationtest/trans/swap.aterm b/sdf3.stratego2.integrationtest/trans/swap.aterm new file mode 100644 index 000000000..249d28dfa --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/swap.aterm @@ -0,0 +1,284 @@ +Module( + "swap" +, [ Imports([Import("strategolib"), ImportWildcard("signatures")]) + , Rules( + [ DefHasTypeNoArgs( + "swap-editor-abstract-syntax" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "swap-editor-abstract-syntax" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Exp")), CallNoArgs(SVar("swap-exps-abstract-syntax")))] + , [] + ) + ) + , DefHasTypeNoArgs( + "swap-editor-concrete-syntax" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax")))] + , [] + ) + ) + , DefHasTypeNoArgs( + "swap-editor-concrete-syntax-simple" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax-simple" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-simple")))] + , [] + ) + ) + , DefHasTypeNoArgs( + "swap-editor-concrete-syntax-var" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax-var" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-var")))] + , [] + ) + ) + , DefHasTypeNoArgs( + "reverse-editor-concrete-syntax-varlist" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "reverse-editor-concrete-syntax-varlist" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Start")), CallNoArgs(SVar("reverse-stmts-concrete-syntax-varlist")))] + , [] + ) + ) + , DefHasTypeNoArgs( + "surround-editor-concrete-syntax-varlist" + , FunNoArgsType( + TupleT( + DynT(Dyn()) + , [DynT(Dyn()), DynT(Dyn()), DynT(Dyn()), DynT(Dyn())] + ) + , TupleT(DynT(Dyn()), [DynT(Dyn())]) + ) + ) + , SDefNoArgs( + "surround-editor-concrete-syntax-varlist" + , CallT( + SVar("editor-action") + , [Seq(TypeTest(SortNoArgs("Start")), CallNoArgs(SVar("surround-stmts-concrete-syntax-varlist")))] + , [] + ) + ) + , DefHasTType( + "editor-action" + , [FunNoArgsType(DynT(Dyn()), DynT(Dyn()))] + , [] + , FunNoArgsType( + TupleT( + SortVar("a") + , [SortVar("b"), DynT(Dyn()), SortVar("d"), SortVar("e")] + ) + , TupleT(SortVar("d"), [DynT(Dyn())]) + ) + ) + , RDefT( + "editor-action" + , [DefaultVarDec("swap-exp")] + , [] + , Rule( + NoAnnoList( + Tuple( + [Wld(), Wld(), Var("ast"), Var("path"), Wld()] + ) + ) + , NoAnnoList( + Tuple( + [ Var("path") + , App( + Call(SVar("oncetd"), [CallNoArgs(SVar("swap-exp"))]) + , Var("ast") + ) + ] + ) + ) + , [] + ) + ) + , DefHasTypeNoArgs("swap-exps-abstract-syntax", FunNoArgsType(SortNoArgs("Exp"), SortNoArgs("Exp"))) + , RDefNoArgs( + "swap-exps-abstract-syntax" + , Rule( + NoAnnoList(Op("Add", [Var("e1"), Var("e2")])) + , NoAnnoList(Op("Add", [Var("e2"), Var("e1")])) + , [] + ) + ) + , DefHasTypeNoArgs("swap-exps-concrete-syntax", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , RDefNoArgs( + "swap-exps-concrete-syntax" + , Rule( + NoAnnoList( + ToTerm( + Stmt(Add(FromTerm(Var("e1")), FromTerm(Var("e2")))) + ) + ) + , NoAnnoList( + ToTerm( + Stmt(Add(FromTerm(Var("e2")), FromTerm(Var("e1")))) + ) + ) + , [] + ) + ) + , DefHasTypeNoArgs("swap-exps-concrete-syntax-simple", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , RDefNoArgs( + "swap-exps-concrete-syntax-simple" + , Rule( + NoAnnoList( + ToTerm( + Stmt(Add(FromTerm(Var("e1")), FromTerm(Var("e2")))) + ) + ) + , NoAnnoList( + ToTerm( + Stmt(Add(FromTerm(Var("e2")), FromTerm(Var("e1")))) + ) + ) + , [] + ) + ) + , DefHasTypeNoArgs("swap-exps-concrete-syntax-var", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , RDefNoArgs( + "swap-exps-concrete-syntax-var" + , Rule( + NoAnnoList(ToTerm(Stmt(Add(meta-var("exp"), meta-var("exp2"))))) + , NoAnnoList(ToTerm(Stmt(Add(meta-var("exp2"), meta-var("exp"))))) + , [] + ) + ) + , DefHasTypeNoArgs("reverse-stmts-concrete-syntax-varlist", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , RDefNoArgs( + "reverse-stmts-concrete-syntax-varlist" + , Rule( + NoAnnoList(ToTerm(Program([meta-listvar("stmt1*")]))) + , NoAnnoList(ToTerm(Program([meta-listvar("stmt2*")]))) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + ) + ) + ] + ) + ) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , RDefNoArgs( + "surround-stmts-concrete-syntax-varlist" + , Rule( + NoAnnoList(ToTerm(Program([meta-listvar("stmt1*")]))) + , NoAnnoList( + ToTerm( + Program( + [Stmt(Var("a")), meta-listvar("stmt1*"), Stmt(Var("b"))] + ) + ) + ) + , [] + ) + ) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist2", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , RDefNoArgs( + "surround-stmts-concrete-syntax-varlist2" + , Rule( + NoAnnoList(ToTerm(Program([meta-listvar("stmt1*")]))) + , NoAnnoList( + ToTerm( + Program( + [ meta-listvar("stmt2*") + , Stmt(Var("a")) + , meta-listvar("stmt1*") + , meta-listvar("stmt1*") + , Stmt(Var("b")) + , meta-listvar("stmt2*") + ] + ) + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + ) + ) + ] + ) + ) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-list-fromterm", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , RDefNoArgs( + "surround-stmts-concrete-syntax-list-fromterm" + , Rule( + NoAnnoList(ToTerm(Program([FromTerm(Var(ListVar("stmt1*")))]))) + , NoAnnoList( + ToTerm( + Program( + [ Stmt(Var("a")) + , FromTerm(Var(ListVar("stmt1*"))) + , Stmt(Var("b")) + ] + ) + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + ) + ) + ] + ) + ) + ] + ) + ] +) \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/trans/swap.meta b/sdf3.stratego2.integrationtest/trans/swap.meta new file mode 100644 index 000000000..19d432165 --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/swap.meta @@ -0,0 +1 @@ +Meta([Syntax("foo")]) \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/trans/swap.str2 b/sdf3.stratego2.integrationtest/trans/swap.str2 new file mode 100644 index 000000000..8b6b7b52d --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/swap.str2 @@ -0,0 +1,72 @@ +module swap + +imports + + strategolib + signatures/- + +rules + + swap-editor-abstract-syntax :: ? * ? * ? * ? * ? -> ? * ? + swap-editor-abstract-syntax = editor-action(is(Exp);swap-exps-abstract-syntax|) + + swap-editor-concrete-syntax :: ? * ? * ? * ? * ? -> ? * ? + swap-editor-concrete-syntax = editor-action(is(Stmt);swap-exps-concrete-syntax|) + + swap-editor-concrete-syntax-simple :: ? * ? * ? * ? * ? -> ? * ? + swap-editor-concrete-syntax-simple = editor-action(is(Stmt);swap-exps-concrete-syntax-simple|) + + swap-editor-concrete-syntax-var :: ? * ? * ? * ? * ? -> ? * ? + swap-editor-concrete-syntax-var = editor-action(is(Stmt);swap-exps-concrete-syntax-var|) + + reverse-editor-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? + reverse-editor-concrete-syntax-varlist = editor-action(is(Start);reverse-stmts-concrete-syntax-varlist|) + + surround-editor-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? + surround-editor-concrete-syntax-varlist = editor-action(is(Start);surround-stmts-concrete-syntax-varlist|) + + editor-action(? -> ?|) :: a * b * ? * d * e -> d * ? + editor-action(swap-exp|): + (_, _, ast, path, _) -> (path, ast) + + swap-exps-abstract-syntax :: Exp -> Exp + swap-exps-abstract-syntax: + Add(e1, e2) -> Add(e2, e1) + + swap-exps-concrete-syntax :: Stmt -> Stmt + swap-exps-concrete-syntax: + stmt |[ ~exp:e1 + ~exp:e2; ]| -> + stmt |[ ~exp:e2 + ~exp:e1; ]| + + swap-exps-concrete-syntax-simple :: Stmt -> Stmt + swap-exps-concrete-syntax-simple: + |[ ~e1 + ~e2; ]| -> + |[ ~e2 + ~e1; ]| + + swap-exps-concrete-syntax-var :: Stmt -> Stmt + swap-exps-concrete-syntax-var: + |[ exp + exp2 ; ]| -> + |[ exp2 + exp ; ]| + + reverse-stmts-concrete-syntax-varlist :: Start -> Start + reverse-stmts-concrete-syntax-varlist: + |[ stmt1* ]| -> + |[ stmt2* ]| + where stmt2* := stmt1* + + surround-stmts-concrete-syntax-varlist :: Start -> Start + surround-stmts-concrete-syntax-varlist: + |[ stmt1* ]| -> + program |[ a; stmt1* b; ]| + + surround-stmts-concrete-syntax-varlist2 :: Start -> Start + surround-stmts-concrete-syntax-varlist2: + |[ stmt1* ]| -> + program |[ stmt2* a; stmt1* stmt1* b; stmt2* ]| + where stmt2* := stmt1* + + surround-stmts-concrete-syntax-list-fromterm :: Start -> Start + surround-stmts-concrete-syntax-list-fromterm: + |[ ~*stmt1* ]| -> + program |[ a; ~*stmt1* b; ]| + where stmt2* := stmt1* From 2f1168feaa29a2fac0224ebb0a45e8d466fa53c0 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Thu, 9 Mar 2023 16:59:16 +0100 Subject: [PATCH 11/15] Commit forgotten changes of unambiguous mix syntax snippets --- sdf3.stratego2.integrationtest/syntax/foo.sdf3 | 2 +- sdf3.stratego2.integrationtest/trans/swap.str2 | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 index 56e1f5a41..9913c6459 100644 --- a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 +++ b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 @@ -18,7 +18,6 @@ context-free syntax Module = StrategoLang-Module - StrategoLang-PreTerm.ToTerm = <|[ ]|> StrategoLang-PreTerm.ToTerm = ]|> StrategoLang-PreTerm.ToTerm = ]|> @@ -44,6 +43,7 @@ lexical syntax ExpVar = 'exp' [0-9]* StmtListVar = 'stmt' [0-9]* '*' + Var = ExpVar {reject} lexical restrictions diff --git a/sdf3.stratego2.integrationtest/trans/swap.str2 b/sdf3.stratego2.integrationtest/trans/swap.str2 index 8b6b7b52d..4eb194e8c 100644 --- a/sdf3.stratego2.integrationtest/trans/swap.str2 +++ b/sdf3.stratego2.integrationtest/trans/swap.str2 @@ -40,33 +40,33 @@ rules swap-exps-concrete-syntax-simple :: Stmt -> Stmt swap-exps-concrete-syntax-simple: - |[ ~e1 + ~e2; ]| -> - |[ ~e2 + ~e1; ]| + stmt |[ ~e1 + ~e2; ]| -> + stmt |[ ~e2 + ~e1; ]| swap-exps-concrete-syntax-var :: Stmt -> Stmt swap-exps-concrete-syntax-var: - |[ exp + exp2 ; ]| -> - |[ exp2 + exp ; ]| + stmt |[ exp + exp2 ; ]| -> + stmt |[ exp2 + exp ; ]| reverse-stmts-concrete-syntax-varlist :: Start -> Start reverse-stmts-concrete-syntax-varlist: - |[ stmt1* ]| -> - |[ stmt2* ]| + program |[ stmt1* ]| -> + program |[ stmt2* ]| where stmt2* := stmt1* surround-stmts-concrete-syntax-varlist :: Start -> Start surround-stmts-concrete-syntax-varlist: - |[ stmt1* ]| -> + program |[ stmt1* ]| -> program |[ a; stmt1* b; ]| surround-stmts-concrete-syntax-varlist2 :: Start -> Start surround-stmts-concrete-syntax-varlist2: - |[ stmt1* ]| -> + program |[ stmt1* ]| -> program |[ stmt2* a; stmt1* stmt1* b; stmt2* ]| where stmt2* := stmt1* surround-stmts-concrete-syntax-list-fromterm :: Start -> Start surround-stmts-concrete-syntax-list-fromterm: - |[ ~*stmt1* ]| -> + program |[ ~*stmt1* ]| -> program |[ a; ~*stmt1* b; ]| where stmt2* := stmt1* From fc6a6699982b9e509f9597dd7dbf9e0336a601ab Mon Sep 17 00:00:00 2001 From: Jasper Denkers Date: Mon, 17 Jul 2023 11:33:29 +0200 Subject: [PATCH 12/15] Apply same fix as in other mix syntax integrationtest project (ab146a69) "Update mix syntax integrationtest to import module that defined Module start symbol" --- sdf3.stratego2.integrationtest/syntax/foo.sdf3 | 1 + 1 file changed, 1 insertion(+) diff --git a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 index 9913c6459..ae1672687 100644 --- a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 +++ b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 @@ -3,6 +3,7 @@ module foo imports StrategoLang/import-namespaced + StrategoLang/core/modules-namespaced StrategoLang/sugar/terms-namespaced thesyntax From ff18689e3f4490cc7da0b2eabbb480dc2d369856 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Wed, 29 Jan 2025 14:39:23 +0100 Subject: [PATCH 13/15] Workaround issue with Spoofax 2.5.22 trying to use 2.5.21 when the version isn't specified --- sdf3.stratego2.integrationtest/metaborg.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/sdf3.stratego2.integrationtest/metaborg.yaml b/sdf3.stratego2.integrationtest/metaborg.yaml index d239751fa..1ede80994 100644 --- a/sdf3.stratego2.integrationtest/metaborg.yaml +++ b/sdf3.stratego2.integrationtest/metaborg.yaml @@ -1,6 +1,7 @@ --- id: org.metaborg:sdf3.stratego2.integrationtest:2.6.0-SNAPSHOT name: sdf3-stratego2-integrationtest +metaborgVersion: 2.5.22 # temporary fix for bug in 2.5.22, remove once 2.5.23 is released dependencies: compile: - org.metaborg:org.metaborg.meta.lang.esv:${metaborgVersion} From 49f92fbd75698f01b369c0497b2c3e2102d5cdcb Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Fri, 31 Jan 2025 15:50:44 +0100 Subject: [PATCH 14/15] This version of the tests should work once the latest changes to Stratego 2 are released --- .../editor/Main.esv | 2 +- sdf3.stratego2.integrationtest/metaborg.yaml | 7 +- sdf3.stratego2.integrationtest/pom.xml | 24 + .../syntax/foo.sdf3 | 14 +- sdf3.stratego2.integrationtest/test/swap.spt | 6 +- sdf3.stratego2.integrationtest/trans/pp.str2 | 52 ++ .../trans/sdf3_stratego2_integrationtest.str2 | 2 + .../trans/swap.analyzed.aterm | 734 ++++++++++++++++++ .../trans/swap.aterm | 189 ++++- .../trans/swap.str2 | 35 +- 10 files changed, 1009 insertions(+), 56 deletions(-) create mode 100644 sdf3.stratego2.integrationtest/trans/pp.str2 create mode 100644 sdf3.stratego2.integrationtest/trans/swap.analyzed.aterm diff --git a/sdf3.stratego2.integrationtest/editor/Main.esv b/sdf3.stratego2.integrationtest/editor/Main.esv index 86a411000..8c54faef4 100644 --- a/sdf3.stratego2.integrationtest/editor/Main.esv +++ b/sdf3.stratego2.integrationtest/editor/Main.esv @@ -4,7 +4,7 @@ language extensions : s3mit -// provider : target/metaborg/stratego.ctree + provider : target/metaborg/stratego.jar table : target/metaborg/sdf.tbl start symbols : Start diff --git a/sdf3.stratego2.integrationtest/metaborg.yaml b/sdf3.stratego2.integrationtest/metaborg.yaml index 1ede80994..e8da3f9f2 100644 --- a/sdf3.stratego2.integrationtest/metaborg.yaml +++ b/sdf3.stratego2.integrationtest/metaborg.yaml @@ -1,17 +1,22 @@ --- id: org.metaborg:sdf3.stratego2.integrationtest:2.6.0-SNAPSHOT name: sdf3-stratego2-integrationtest -metaborgVersion: 2.5.22 # temporary fix for bug in 2.5.22, remove once 2.5.23 is released 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} + # Workaround to get Stratego 2 dialect to register before trans/swap.str2 is parsed + - org.metaborg:org.metaborg.meta.lang.stratego:${metaborgVersion} - org.metaborg:stratego.lang:${metaborgVersion} source: - org.metaborg:meta.lib.spoofax:${metaborgVersion} - org.metaborg:stratego.lang:${metaborgVersion} - org.metaborg:strategolib:${metaborgVersion} + - org.metaborg:gpp:${metaborgVersion} + java: + - org.metaborg:strategolib:${metaborgVersion} + - org.metaborg:gpp:${metaborgVersion} pardonedLanguages: - EditorService - Stratego-Sugar diff --git a/sdf3.stratego2.integrationtest/pom.xml b/sdf3.stratego2.integrationtest/pom.xml index 3dba1393b..079fe606e 100644 --- a/sdf3.stratego2.integrationtest/pom.xml +++ b/sdf3.stratego2.integrationtest/pom.xml @@ -23,6 +23,12 @@ ${metaborg-version} spoofax-language + + org.metaborg + org.metaborg.meta.lang.template + ${metaborg-version} + spoofax-language + org.metaborg org.metaborg.meta.lang.spt @@ -30,6 +36,12 @@ spoofax-language test + + org.metaborg + stratego.lang + ${metaborg-version} + spoofax-language + @@ -39,6 +51,18 @@ spoofax-language provided + + org.metaborg + strategolib + ${metaborg-version} + spoofax-language + + + org.metaborg + gpp + ${metaborg-version} + spoofax-language + diff --git a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 index ae1672687..438502791 100644 --- a/sdf3.stratego2.integrationtest/syntax/foo.sdf3 +++ b/sdf3.stratego2.integrationtest/syntax/foo.sdf3 @@ -13,7 +13,7 @@ context-free start-symbols context-free sorts - Module StmtListMeta + Module context-free syntax @@ -25,16 +25,13 @@ context-free syntax Exp.FromTerm = [~[StrategoLang-Term]] Exp.FromTerm = [~exp:[StrategoLang-Term]] - StmtListMeta.FromTerm = [~*[StrategoLang-Term]] - - Stmt+ = StmtListMeta - Stmt+.Conc = Stmt+ StmtListMeta + Stmt.FromTerm = [~[StrategoLang-Term]] context-free syntax // meta variables Exp.meta-var = ExpVar - - StmtListMeta.meta-listvar = StmtListVar + + Stmt.meta-listvar = StmtListVar lexical sorts @@ -44,8 +41,9 @@ lexical syntax ExpVar = 'exp' [0-9]* StmtListVar = 'stmt' [0-9]* '*' - Var = ExpVar {reject} + VAR = ExpVar {reject} lexical restrictions ExpVar -/- [0-9] + \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/test/swap.spt b/sdf3.stratego2.integrationtest/test/swap.spt index c0996b456..a2ca09944 100644 --- a/sdf3.stratego2.integrationtest/test/swap.spt +++ b/sdf3.stratego2.integrationtest/test/swap.spt @@ -4,11 +4,11 @@ language sdf3-stratego2-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;]] diff --git a/sdf3.stratego2.integrationtest/trans/pp.str2 b/sdf3.stratego2.integrationtest/trans/pp.str2 new file mode 100644 index 000000000..64ced1c7f --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/pp.str2 @@ -0,0 +1,52 @@ +module pp + +imports + strategolib + +imports + + gpp + libspoofax/sdf/pp + libspoofax/editor/refactoring/- + pp/sdf3-stratego2-integrationtest-parenthesize + pp/sdf3-stratego2-integrationtest-pp + +rules + editor-format :: ? * ? * ? * string * string -> string * ? + editor-format: + (node, _, ast, path, project-path) -> (filename, result) + with + ext := path + ; filename := path + ; result := node + +rules + + pp-sdf3-stratego2-integrationtest-string = + parenthesize-sdf3-stratego2-integrationtest + ; prettyprint-sdf3-stratego2-integrationtest-start-symbols + ; !V([], ) + ; box2text-string(|120) + + pp-partial-sdf3-stratego2-integrationtest-string = + parenthesize-sdf3-stratego2-integrationtest + ; prettyprint-sdf3-stratego2-integrationtest + ; !V([], ) + ; box2text-string(|120) + + pp-partial-sdf3-stratego2-integrationtest-string(|sort) = + parenthesize-sdf3-stratego2-integrationtest + ; prettyprint-sdf3-stratego2-integrationtest(|sort) + ; !V([], ) + ; box2text-string(|120) + + pp-debug : + ast -> result + with + result := ast + <+ ast + ; result := "" + +rules + + construct-textual-change = construct-textual-change(pp-partial-sdf3-stratego2-integrationtest-string, parenthesize, override-reconstruction, resugar) diff --git a/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 b/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 index 78f3a03c3..aec47855d 100644 --- a/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 +++ b/sdf3.stratego2.integrationtest/trans/sdf3_stratego2_integrationtest.str2 @@ -3,3 +3,5 @@ module sdf3_stratego2_integrationtest imports swap + completion/completion + pp diff --git a/sdf3.stratego2.integrationtest/trans/swap.analyzed.aterm b/sdf3.stratego2.integrationtest/trans/swap.analyzed.aterm new file mode 100644 index 000000000..41d28a1a5 --- /dev/null +++ b/sdf3.stratego2.integrationtest/trans/swap.analyzed.aterm @@ -0,0 +1,734 @@ +Module( + "swap" +, [ Imports([Import("strategolib"), ImportWildcard("signatures")]) + , Signature( + [ Constructors( + [ OpDecl( + "Conc" + , FunType( + [ ConstType(Sort("List", [SortVar("a")])) + , ConstType(Sort("List", [SortVar("a")])) + ] + , ConstType(Sort("List", [SortVar("a")])) + ) + ) + ] + ) + ] + ) + , Rules( + [ DefHasType( + "swap-editor-abstract-syntax" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "swap-editor-abstract-syntax" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Exp", [])) + , CallT(SVar("swap-exps-abstract-syntax"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "swap-editor-concrete-syntax" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Stmt", [])) + , CallT(SVar("swap-exps-concrete-syntax"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "swap-editor-concrete-syntax-simple" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax-simple" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Stmt", [])) + , CallT(SVar("swap-exps-concrete-syntax-simple"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "swap-editor-concrete-syntax-var" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "swap-editor-concrete-syntax-var" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Stmt", [])) + , CallT(SVar("swap-exps-concrete-syntax-var"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "reverse-editor-concrete-syntax-varlist" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "reverse-editor-concrete-syntax-varlist" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Start", [])) + , CallT(SVar("reverse-stmts-concrete-syntax-varlist"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "surround-editor-concrete-syntax-varlist" + , FunTType( + [] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + , DynT(Dyn()) + ] + ) + , Sort("Tuple", [DynT(Dyn()), DynT(Dyn())]) + ) + ) + ) + , SDefNoArgs( + "surround-editor-concrete-syntax-varlist" + , CallT( + SVar("editor-action") + , [ Seq( + TypeTest(Sort("Start", [])) + , CallT(SVar("surround-stmts-concrete-syntax-varlist"), [], []) + ) + ] + , [] + ) + ) + , DefHasType( + "editor-action" + , FunTType( + [FunTType([], [], FunNoArgsType(DynT(Dyn()), DynT(Dyn())))] + , [] + , FunNoArgsType( + Sort( + "Tuple" + , [ SortVar("a") + , SortVar("b") + , DynT(Dyn()) + , SortVar("d") + , SortVar("e") + ] + ) + , Sort("Tuple", [SortVar("d"), DynT(Dyn())]) + ) + ) + ) + , RDefT( + "editor-action" + , [DefaultVarDec("swap-exp")] + , [] + , Rule( + NoAnnoList( + Tuple( + [Wld(), Wld(), Var("ast"), Var("path"), Wld()] + ) + ) + , NoAnnoList( + Tuple( + [ Var("path") + , App( + CallT(SVar("oncetd"), [CallNoArgs(SVar("swap-exp"))], []) + , Var("ast") + ) + ] + ) + ) + , [] + ) + ) + , DefHasType( + "swap-exps-abstract-syntax" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Exp", []), Sort("Exp", [])) + ) + ) + , RDefNoArgs( + "swap-exps-abstract-syntax" + , Rule( + NoAnnoList(Op("Add", [Var("e1"), Var("e2")])) + , NoAnnoList(Op("Add", [Var("e2"), Var("e1")])) + , [] + ) + ) + , DefHasType( + "swap-exps-concrete-syntax" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Stmt", []), Sort("Stmt", [])) + ) + ) + , RDefNoArgs( + "swap-exps-concrete-syntax" + , Rule( + NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("e1"), Var("e2")]))] + ) + ) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("e2"), Var("e1")]))] + ) + ) + , [] + ) + ) + , DefHasType( + "swap-exps-concrete-syntax-simple" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Stmt", []), Sort("Stmt", [])) + ) + ) + , RDefNoArgs( + "swap-exps-concrete-syntax-simple" + , Rule( + NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("e1"), Var("e2")]))] + ) + ) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("e2"), Var("e1")]))] + ) + ) + , [] + ) + ) + , DefHasType( + "swap-exps-concrete-syntax-var" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Stmt", []), Sort("Stmt", [])) + ) + ) + , RDefNoArgs( + "swap-exps-concrete-syntax-var" + , Rule( + NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("exp"), Var("exp2")]))] + ) + ) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Add", [Var("exp2"), Var("exp")]))] + ) + ) + , [] + ) + ) + , DefHasType( + "reverse-stmts-abstract-syntax" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "reverse-stmts-abstract-syntax" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList(Op("Program", [Var(ListVar("stmt2*"))])) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(Sort("List", [Sort("Stmt", [])])) + , CallT(SVar("reverse"), [], []) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasType( + "reverse-stmts-concrete-syntax-varlist" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "reverse-stmts-concrete-syntax-varlist" + , Rule( + NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [Var(ListVar("stmt1*")), NoAnnoList(Op("Nil", []))] + ) + ) + ] + ) + ) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [Var(ListVar("stmt2*")), NoAnnoList(Op("Nil", []))] + ) + ) + ] + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(Sort("List", [Sort("Stmt", [])])) + , CallT(SVar("reverse"), [], []) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasType( + "surround-stmts-abstract-syntax" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "surround-stmts-abstract-syntax" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + List( + [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"a\""))]))] + ) + ) + , Var(ListVar("stmt1*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"b\""))]))] + ) + ) + ] + ) + ) + ] + ) + ) + , [] + ) + ) + , DefHasType( + "surround-stmts-concrete-syntax-varlist" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "surround-stmts-concrete-syntax-varlist" + , Rule( + NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [Var(ListVar("stmt1*")), NoAnnoList(Op("Nil", []))] + ) + ) + ] + ) + ) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [ NoAnnoList( + Op( + "Conc" + , [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("a"))]))] + ) + ) + , Var(ListVar("stmt1*")) + ] + ) + ) + , NoAnnoList( + Op( + "Cons" + , [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("b"))]))] + ) + ) + , NoAnnoList(Op("Nil", [])) + ] + ) + ) + ] + ) + ) + ] + ) + ) + , [] + ) + ) + , DefHasType( + "surround-stmts-abstract-syntax2" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "surround-stmts-abstract-syntax2" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + List( + [ Var(ListVar("stmt2*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"a\""))]))] + ) + ) + , Var(ListVar("stmt1*")) + , Var(ListVar("stmt1*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"b\""))]))] + ) + ) + , Var(ListVar("stmt2*")) + ] + ) + ) + ] + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(Sort("List", [Sort("Stmt", [])])) + , CallT(SVar("reverse"), [], []) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasType( + "surround-stmts-concrete-syntax-varlist2" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "surround-stmts-concrete-syntax-varlist2" + , Rule( + NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [Var(ListVar("stmt1*")), NoAnnoList(Op("Nil", []))] + ) + ) + ] + ) + ) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Conc" + , [ NoAnnoList( + Op( + "Conc" + , [ NoAnnoList( + Op( + "Conc" + , [ Var(ListVar("stmt2*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("a"))]))] + ) + ) + , Var(ListVar("stmt1*")) + ] + ) + ) + , Var(ListVar("stmt1*")) + ] + ) + ) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("b"))]))] + ) + ) + , Var(ListVar("stmt2*")) + ] + ) + ) + ] + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(Sort("List", [Sort("Stmt", [])])) + , CallT(SVar("reverse"), [], []) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasType( + "surround-stmts-concrete-syntax-list-fromterm" + , FunTType( + [] + , [] + , FunNoArgsType(Sort("Start", []), Sort("Start", [])) + ) + ) + , RDefNoArgs( + "surround-stmts-concrete-syntax-list-fromterm" + , Rule( + NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [Var(ListVar("stmt1*")), NoAnnoList(Op("Nil", []))] + ) + ) + ] + ) + ) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + Op( + "Cons" + , [ NoAnnoList( + Op( + "Conc" + , [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("a"))]))] + ) + ) + , Var(ListVar("stmt1*")) + ] + ) + ) + , NoAnnoList( + Op( + "Cons" + , [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("b"))]))] + ) + ) + , NoAnnoList(Op("Nil", [])) + ] + ) + ) + ] + ) + ) + ] + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(Sort("List", [Sort("Stmt", [])])) + , CallT(SVar("reverse"), [], []) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + ] + ) + ] +) \ No newline at end of file diff --git a/sdf3.stratego2.integrationtest/trans/swap.aterm b/sdf3.stratego2.integrationtest/trans/swap.aterm index 249d28dfa..faa9ce007 100644 --- a/sdf3.stratego2.integrationtest/trans/swap.aterm +++ b/sdf3.stratego2.integrationtest/trans/swap.aterm @@ -1,6 +1,21 @@ Module( "swap" , [ Imports([Import("strategolib"), ImportWildcard("signatures")]) + , Signature( + [ Constructors( + [ OpDecl( + "Conc" + , OpFunType( + [ ConstType(Sort("List", [SortVar("a")])) + , ConstType(Sort("List", [SortVar("a")])) + ] + , ConstType(Sort("List", [SortVar("a")])) + ) + ) + ] + ) + ] + ) , Rules( [ DefHasTypeNoArgs( "swap-editor-abstract-syntax" @@ -16,7 +31,7 @@ Module( "swap-editor-abstract-syntax" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Exp")), CallNoArgs(SVar("swap-exps-abstract-syntax")))] + , [Seq(TypeTest(SortTNoArgs("Exp")), CallNoArgs(SVar("swap-exps-abstract-syntax")))] , [] ) ) @@ -34,7 +49,7 @@ Module( "swap-editor-concrete-syntax" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax")))] + , [Seq(TypeTest(SortTNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax")))] , [] ) ) @@ -52,7 +67,7 @@ Module( "swap-editor-concrete-syntax-simple" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-simple")))] + , [Seq(TypeTest(SortTNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-simple")))] , [] ) ) @@ -70,7 +85,7 @@ Module( "swap-editor-concrete-syntax-var" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-var")))] + , [Seq(TypeTest(SortTNoArgs("Stmt")), CallNoArgs(SVar("swap-exps-concrete-syntax-var")))] , [] ) ) @@ -88,7 +103,7 @@ Module( "reverse-editor-concrete-syntax-varlist" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Start")), CallNoArgs(SVar("reverse-stmts-concrete-syntax-varlist")))] + , [Seq(TypeTest(SortTNoArgs("Start")), CallNoArgs(SVar("reverse-stmts-concrete-syntax-varlist")))] , [] ) ) @@ -106,7 +121,7 @@ Module( "surround-editor-concrete-syntax-varlist" , CallT( SVar("editor-action") - , [Seq(TypeTest(SortNoArgs("Start")), CallNoArgs(SVar("surround-stmts-concrete-syntax-varlist")))] + , [Seq(TypeTest(SortTNoArgs("Start")), CallNoArgs(SVar("surround-stmts-concrete-syntax-varlist")))] , [] ) ) @@ -116,10 +131,10 @@ Module( , [] , FunNoArgsType( TupleT( - SortVar("a") - , [SortVar("b"), DynT(Dyn()), SortVar("d"), SortVar("e")] + SortTVar("a") + , [SortTVar("b"), DynT(Dyn()), SortTVar("d"), SortTVar("e")] ) - , TupleT(SortVar("d"), [DynT(Dyn())]) + , TupleT(SortTVar("d"), [DynT(Dyn())]) ) ) , RDefT( @@ -145,7 +160,7 @@ Module( , [] ) ) - , DefHasTypeNoArgs("swap-exps-abstract-syntax", FunNoArgsType(SortNoArgs("Exp"), SortNoArgs("Exp"))) + , DefHasTypeNoArgs("swap-exps-abstract-syntax", FunNoArgsType(SortTNoArgs("Exp"), SortTNoArgs("Exp"))) , RDefNoArgs( "swap-exps-abstract-syntax" , Rule( @@ -154,7 +169,7 @@ Module( , [] ) ) - , DefHasTypeNoArgs("swap-exps-concrete-syntax", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , DefHasTypeNoArgs("swap-exps-concrete-syntax", FunNoArgsType(SortTNoArgs("Stmt"), SortTNoArgs("Stmt"))) , RDefNoArgs( "swap-exps-concrete-syntax" , Rule( @@ -171,7 +186,7 @@ Module( , [] ) ) - , DefHasTypeNoArgs("swap-exps-concrete-syntax-simple", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , DefHasTypeNoArgs("swap-exps-concrete-syntax-simple", FunNoArgsType(SortTNoArgs("Stmt"), SortTNoArgs("Stmt"))) , RDefNoArgs( "swap-exps-concrete-syntax-simple" , Rule( @@ -188,7 +203,7 @@ Module( , [] ) ) - , DefHasTypeNoArgs("swap-exps-concrete-syntax-var", FunNoArgsType(SortNoArgs("Stmt"), SortNoArgs("Stmt"))) + , DefHasTypeNoArgs("swap-exps-concrete-syntax-var", FunNoArgsType(SortTNoArgs("Stmt"), SortTNoArgs("Stmt"))) , RDefNoArgs( "swap-exps-concrete-syntax-var" , Rule( @@ -197,7 +212,28 @@ Module( , [] ) ) - , DefHasTypeNoArgs("reverse-stmts-concrete-syntax-varlist", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , DefHasTypeNoArgs("reverse-stmts-abstract-syntax", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) + , RDefNoArgs( + "reverse-stmts-abstract-syntax" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList(Op("Program", [Var(ListVar("stmt2*"))])) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(SortT("List", [SortTNoArgs("Stmt")])) + , CallNoArgs(SVar("reverse")) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasTypeNoArgs("reverse-stmts-concrete-syntax-varlist", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) , RDefNoArgs( "reverse-stmts-concrete-syntax-varlist" , Rule( @@ -206,13 +242,51 @@ Module( , [ WhereClause( Assign( Var(ListVar("stmt2*")) - , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + , App( + Seq( + TypeTest(SortT("List", [SortTNoArgs("Stmt")])) + , CallNoArgs(SVar("reverse")) + ) + , Var(ListVar("stmt1*")) + ) ) ) ] ) ) - , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , DefHasTypeNoArgs("surround-stmts-abstract-syntax", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) + , RDefNoArgs( + "surround-stmts-abstract-syntax" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + List( + [ NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"a\""))]))] + ) + ) + , Var(ListVar("stmt1*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"b\""))]))] + ) + ) + ] + ) + ) + ] + ) + ) + , [] + ) + ) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) , RDefNoArgs( "surround-stmts-concrete-syntax-varlist" , Rule( @@ -220,14 +294,61 @@ Module( , NoAnnoList( ToTerm( Program( - [Stmt(Var("a")), meta-listvar("stmt1*"), Stmt(Var("b"))] + [Conc(Stmt(Var("a")), meta-listvar("stmt1*")), Stmt(Var("b"))] ) ) ) , [] ) ) - , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist2", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , DefHasTypeNoArgs("surround-stmts-abstract-syntax2", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) + , RDefNoArgs( + "surround-stmts-abstract-syntax2" + , Rule( + NoAnnoList(Op("Program", [Var(ListVar("stmt1*"))])) + , NoAnnoList( + Op( + "Program" + , [ NoAnnoList( + List( + [ Var(ListVar("stmt2*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"a\""))]))] + ) + ) + , Var(ListVar("stmt1*")) + , Var(ListVar("stmt1*")) + , NoAnnoList( + Op( + "Stmt" + , [NoAnnoList(Op("Var", [NoAnnoList(Str("\"b\""))]))] + ) + ) + , Var(ListVar("stmt2*")) + ] + ) + ) + ] + ) + ) + , [ WhereClause( + Assign( + Var(ListVar("stmt2*")) + , App( + Seq( + TypeTest(SortT("List", [SortTNoArgs("Stmt")])) + , CallNoArgs(SVar("reverse")) + ) + , Var(ListVar("stmt1*")) + ) + ) + ) + ] + ) + ) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-varlist2", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) , RDefNoArgs( "surround-stmts-concrete-syntax-varlist2" , Rule( @@ -235,26 +356,33 @@ Module( , NoAnnoList( ToTerm( Program( - [ meta-listvar("stmt2*") - , Stmt(Var("a")) - , meta-listvar("stmt1*") - , meta-listvar("stmt1*") + Conc( + Conc( + Conc(meta-listvar("stmt2*"), Stmt(Var("a")), meta-listvar("stmt1*")) + , meta-listvar("stmt1*") + ) , Stmt(Var("b")) , meta-listvar("stmt2*") - ] + ) ) ) ) , [ WhereClause( Assign( Var(ListVar("stmt2*")) - , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + , App( + Seq( + TypeTest(SortT("List", [SortTNoArgs("Stmt")])) + , CallNoArgs(SVar("reverse")) + ) + , Var(ListVar("stmt1*")) + ) ) ) ] ) ) - , DefHasTypeNoArgs("surround-stmts-concrete-syntax-list-fromterm", FunNoArgsType(SortNoArgs("Start"), SortNoArgs("Start"))) + , DefHasTypeNoArgs("surround-stmts-concrete-syntax-list-fromterm", FunNoArgsType(SortTNoArgs("Start"), SortTNoArgs("Start"))) , RDefNoArgs( "surround-stmts-concrete-syntax-list-fromterm" , Rule( @@ -262,8 +390,7 @@ Module( , NoAnnoList( ToTerm( Program( - [ Stmt(Var("a")) - , FromTerm(Var(ListVar("stmt1*"))) + [ Conc(Stmt(Var("a")), FromTerm(Var(ListVar("stmt1*")))) , Stmt(Var("b")) ] ) @@ -272,7 +399,13 @@ Module( , [ WhereClause( Assign( Var(ListVar("stmt2*")) - , App(CallNoArgs(SVar("reverse")), Var(ListVar("stmt1*"))) + , App( + Seq( + TypeTest(SortT("List", [SortTNoArgs("Stmt")])) + , CallNoArgs(SVar("reverse")) + ) + , Var(ListVar("stmt1*")) + ) ) ) ] diff --git a/sdf3.stratego2.integrationtest/trans/swap.str2 b/sdf3.stratego2.integrationtest/trans/swap.str2 index 4eb194e8c..cbe37e22b 100644 --- a/sdf3.stratego2.integrationtest/trans/swap.str2 +++ b/sdf3.stratego2.integrationtest/trans/swap.str2 @@ -7,23 +7,29 @@ imports rules - swap-editor-abstract-syntax :: ? * ? * ? * ? * ? -> ? * ? - swap-editor-abstract-syntax = editor-action(is(Exp);swap-exps-abstract-syntax|) + editor-action-swap-exps-abstract-syntax :: ? * ? * ? * ? * ? -> ? * ? + editor-action-swap-exps-abstract-syntax = editor-action(is(Exp);swap-exps-abstract-syntax|) - swap-editor-concrete-syntax :: ? * ? * ? * ? * ? -> ? * ? - swap-editor-concrete-syntax = editor-action(is(Stmt);swap-exps-concrete-syntax|) + editor-action-swap-exps-concrete-syntax :: ? * ? * ? * ? * ? -> ? * ? + editor-action-swap-exps-concrete-syntax = editor-action(is(Stmt);swap-exps-concrete-syntax|) - swap-editor-concrete-syntax-simple :: ? * ? * ? * ? * ? -> ? * ? - swap-editor-concrete-syntax-simple = editor-action(is(Stmt);swap-exps-concrete-syntax-simple|) + editor-action-swap-exps-concrete-syntax-simple :: ? * ? * ? * ? * ? -> ? * ? + editor-action-swap-exps-concrete-syntax-simple = editor-action(is(Stmt);swap-exps-concrete-syntax-simple|) - swap-editor-concrete-syntax-var :: ? * ? * ? * ? * ? -> ? * ? - swap-editor-concrete-syntax-var = editor-action(is(Stmt);swap-exps-concrete-syntax-var|) + editor-action-swap-exps-concrete-syntax-var :: ? * ? * ? * ? * ? -> ? * ? + editor-action-swap-exps-concrete-syntax-var = editor-action(is(Stmt);swap-exps-concrete-syntax-var|) - reverse-editor-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? - reverse-editor-concrete-syntax-varlist = editor-action(is(Start);reverse-stmts-concrete-syntax-varlist|) + editor-action-reverse-stmts-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? + editor-action-reverse-stmts-concrete-syntax-varlist = editor-action(is(Start);reverse-stmts-concrete-syntax-varlist|) - surround-editor-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? - surround-editor-concrete-syntax-varlist = editor-action(is(Start);surround-stmts-concrete-syntax-varlist|) + editor-action-surround-stmts-concrete-syntax-varlist :: ? * ? * ? * ? * ? -> ? * ? + editor-action-surround-stmts-concrete-syntax-varlist = editor-action(is(Start);surround-stmts-concrete-syntax-varlist|) + + editor-action-surround-stmts-concrete-syntax-varlist2 :: ? * ? * ? * ? * ? -> ? * ? + editor-action-surround-stmts-concrete-syntax-varlist2 = editor-action(is(Start);surround-stmts-concrete-syntax-varlist2|) + + editor-action-surround-stmts-concrete-syntax-list-fromterm :: ? * ? * ? * ? * ? -> ? * ? + editor-action-surround-stmts-concrete-syntax-list-fromterm = editor-action(is(Start);surround-stmts-concrete-syntax-list-fromterm|) editor-action(? -> ?|) :: a * b * ? * d * e -> d * ? editor-action(swap-exp|): @@ -67,6 +73,5 @@ rules surround-stmts-concrete-syntax-list-fromterm :: Start -> Start surround-stmts-concrete-syntax-list-fromterm: - program |[ ~*stmt1* ]| -> - program |[ a; ~*stmt1* b; ]| - where stmt2* := stmt1* + program |[ ~stmt1* ]| -> + program |[ a; ~stmt1* b; ]| From b5c3c5bba5b6fecd023372bb2175ea6a705389f5 Mon Sep 17 00:00:00 2001 From: Jeff Smits Date: Fri, 31 Jan 2025 16:25:35 +0100 Subject: [PATCH 15/15] Error on variable sections in SDF3, since they're not supported --- .../trans/analysis/name-constraints.str | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/org.metaborg.meta.lang.template/trans/analysis/name-constraints.str b/org.metaborg.meta.lang.template/trans/analysis/name-constraints.str index 6aae9ae81..35275477f 100644 --- a/org.metaborg.meta.lang.template/trans/analysis/name-constraints.str +++ b/org.metaborg.meta.lang.template/trans/analysis/name-constraints.str @@ -428,3 +428,17 @@ rules where s'; ( ty*, ty'*) + +rules + + nabl-constraint(|ctx): + section@VariablesProductive(_) -> + where + msg := "The SDF2 variables section is no longer support, please write your own A.meta-var and A.meta-listvar definitions in context-free syntax"; + section + + nabl-constraint(|ctx): + section@LexVariablesProductive(_) -> + where + msg := "The SDF2 variables section is no longer support, please write your own A.meta-var and A.meta-listvar definitions in context-free syntax"; + section