commit 42da98a13213ca59f1c306c2e33b603ebead258f Author: Peter <43498358+Petersmit27@users.noreply.github.com> Date: Wed Nov 1 09:24:46 2023 +0100 init commit again diff --git a/IBAF-Editor/.gitignore b/IBAF-Editor/.gitignore new file mode 100644 index 0000000..d0d8774 --- /dev/null +++ b/IBAF-Editor/.gitignore @@ -0,0 +1,11 @@ +/.cache +/bin +/src-gen +/target + +/.classpath +/.project +/.settings +/.factorypath + +/.polyglot.metaborg.yaml diff --git a/IBAF-Editor/.mvn/extensions.xml b/IBAF-Editor/.mvn/extensions.xml new file mode 100644 index 0000000..eadd583 --- /dev/null +++ b/IBAF-Editor/.mvn/extensions.xml @@ -0,0 +1,8 @@ + + + + org.metaborg + spoofax-maven-plugin-pomless + 2.5.18 + + diff --git a/IBAF-Editor/.mvn/jvm.config b/IBAF-Editor/.mvn/jvm.config new file mode 100644 index 0000000..67bd169 --- /dev/null +++ b/IBAF-Editor/.mvn/jvm.config @@ -0,0 +1 @@ +-Xmx512m diff --git a/IBAF-Editor/.mvn/maven.config b/IBAF-Editor/.mvn/maven.config new file mode 100644 index 0000000..6998b70 --- /dev/null +++ b/IBAF-Editor/.mvn/maven.config @@ -0,0 +1 @@ +--global-settings .mvn/settings.xml diff --git a/IBAF-Editor/.mvn/settings.xml b/IBAF-Editor/.mvn/settings.xml new file mode 100644 index 0000000..9a31c2a --- /dev/null +++ b/IBAF-Editor/.mvn/settings.xml @@ -0,0 +1,69 @@ + + + + + add-metaborg-release-repos + + + metaborg-release-repo + https://artifacts.metaborg.org/content/repositories/releases/ + + true + + + false + + + + + + metaborg-release-repo + https://artifacts.metaborg.org/content/repositories/releases/ + + true + + + false + + + + + + + add-metaborg-snapshot-repos + + + metaborg-snapshot-repo + https://artifacts.metaborg.org/content/repositories/snapshots/ + + false + + + true + + + + + + metaborg-snapshot-repo + https://artifacts.metaborg.org/content/repositories/snapshots/ + + false + + + true + + + + + + + + add-metaborg-release-repos + add-metaborg-snapshot-repos + + diff --git a/IBAF-Editor/README.md b/IBAF-Editor/README.md new file mode 100644 index 0000000..35c25a6 --- /dev/null +++ b/IBAF-Editor/README.md @@ -0,0 +1,2 @@ +# IBAF Language Specification + diff --git a/IBAF-Editor/editor/Analysis.esv b/IBAF-Editor/editor/Analysis.esv new file mode 100644 index 0000000..4bd2bbe --- /dev/null +++ b/IBAF-Editor/editor/Analysis.esv @@ -0,0 +1,10 @@ +module Analysis + +imports + + nabl2/Menus + nabl2/References + +language + + observer : editor-analyze (constraint) diff --git a/IBAF-Editor/editor/Main.esv b/IBAF-Editor/editor/Main.esv new file mode 100644 index 0000000..657306d --- /dev/null +++ b/IBAF-Editor/editor/Main.esv @@ -0,0 +1,15 @@ +module Main + +imports + Menus + Syntax + Analysis + Refactoring + +language + + extensions : iba + +// Add this provider when switching Stratego to interpreted mode: +// provider : target/metaborg/stratego.ctree + provider : target/metaborg/stratego.jar diff --git a/IBAF-Editor/editor/Menus.esv b/IBAF-Editor/editor/Menus.esv new file mode 100644 index 0000000..de3d3f2 --- /dev/null +++ b/IBAF-Editor/editor/Menus.esv @@ -0,0 +1,7 @@ +module Menus + +menus + + menu: "Generation" (openeditor) (realtime) + + action: "Generate Funcons" = generate-fct diff --git a/IBAF-Editor/editor/Refactoring.esv b/IBAF-Editor/editor/Refactoring.esv new file mode 100644 index 0000000..1018718 --- /dev/null +++ b/IBAF-Editor/editor/Refactoring.esv @@ -0,0 +1,7 @@ +module Refactoring + +menus + + menu: "Refactoring" + + action: "Rename" = rename-menu-action \ No newline at end of file diff --git a/IBAF-Editor/editor/Syntax.esv b/IBAF-Editor/editor/Syntax.esv new file mode 100644 index 0000000..629f9ee --- /dev/null +++ b/IBAF-Editor/editor/Syntax.esv @@ -0,0 +1,27 @@ +module Syntax + +imports + + libspoofax/color/default + completion/colorer/IBAF-cc-esv + +language + + table : target/metaborg/sdf.tbl + start symbols : Start + + line comment : "//" + block comment : "/*" * "*/" + fences : [ ] ( ) { } + +menus + + menu: "Syntax" (openeditor) + + action: "Format" = editor-format (source) + action: "Show parsed AST" = debug-show-aterm (source) + +views + + outline view: editor-outline (source) + expand to level: 3 diff --git a/IBAF-Editor/lib/StrategoMix.def b/IBAF-Editor/lib/StrategoMix.def new file mode 100644 index 0000000..f96d1c8 --- /dev/null +++ b/IBAF-Editor/lib/StrategoMix.def @@ -0,0 +1,937 @@ +definition +module Stratego-Sugar-Overlays +imports + Stratego-Core-Identifiers + Stratego-Sugar-Terms + +exports + sorts Overlay + context-free syntax + Id "=" Term -> Overlay {cons("OverlayNoArgs")} + Id "(" {Id ","}* ")" "=" Term -> Overlay {cons("Overlay")} + +module Stratego-Sugar-DynamicRules +imports + Stratego-Core-Identifiers + Stratego-Sugar-Strategies + Stratego-Sugar-Rules + +exports + + sorts ScopeLabels + context-free syntax + + "{|" ScopeLabels ":" Strategy "|}" -> Strategy {cons("DynRuleScope")} + + {DynRuleScopeId ","}* -> ScopeLabels + "~" Term -> ScopeLabels {cons("ScopeLabels")} + + sorts DynRuleDef DynRuleId DynRuleScopeId RuleDec + context-free syntax + + "rules" "(" DynRuleDef* ")" -> Strategy {cons("GenDynRules")} + + Id "+" Term -> DynRuleDef {cons("AddScopeLabel")} + DynRuleId ":-" Term -> DynRuleDef {cons("UndefineDynRule")} + DynRuleId ":" Rule -> DynRuleDef {cons("SetDynRule")} + DynRuleId ":+" Rule -> DynRuleDef {cons("AddDynRule")} + DynRuleId ":" Term -> DynRuleDef {cons("SetDynRuleMatch")} + + DynRuleId ":=" Term -> DynRuleDef {cons("DynRuleAssign")} + DynRuleId ":+=" Term -> DynRuleDef {cons("DynRuleAssignAdd")} + + DynRuleId ":" Rule "depends" "on" Term -> DynRuleDef {cons("SetDynRuleDepends")} + + RuleDec "." Term -> DynRuleId {cons("LabeledDynRuleId")} + RuleDec "+" Term -> DynRuleId {cons("AddLabelDynRuleId")} + RuleDec -> DynRuleId {cons("DynRuleId")} + + Id "." Term -> DynRuleScopeId {cons("LabeledDynRuleScopeId")} + Id -> DynRuleScopeId {cons("DynRuleScopeId")} + + context-free syntax + + Id -> RuleDec {cons("RDecNoArgs")} + Id "(" {Typedid ","}* ")" -> RuleDec {cons("RDec")} + Id "(" {Typedid ","}* + "|" {Typedid ","}* ")" -> RuleDec {cons("RDecT")} + + sorts RuleNames + context-free syntax + {Id ","}* -> RuleNames + "~" Term -> RuleNames {cons("RuleNames")} + + "/" RuleNames "\\*" Strategy -> Strategy {cons("DynRuleIntersectFix")} + + syntax + %% no space after RuleNames + "\\" "/*" + -> {cons("DynRuleUnionFix")} + + %% 1 space after RuleNames + "\\" " /*" + -> {cons("DynRuleUnionFix")} + + %% no space after RuleNames + "/" "\\" + "/*" + -> {cons("DynRuleIntersectUnionFix")} + + %% 1 space after RuleNames + "/" "\\" + " /*" + -> {cons("DynRuleIntersectUnionFix")} + + + context-free syntax + Strategy "/" RuleNames"\\" Strategy -> Strategy {cons("DynRuleIntersect"),right} + Strategy "\\" RuleNames "/" Strategy -> Strategy {cons("DynRuleUnion"),right} + + Strategy "/" RuleNames "\\" + RuleNames "/" Strategy -> Strategy {cons("DynRuleIntersectUnion"),right} + + priorities + -> {cons("BA")} + > { + + %% no space after RuleNames + "\\" "/*" + -> {cons("DynRuleUnionFix")} + + %% 1 space after RuleNames + "\\" " /*" + -> {cons("DynRuleUnionFix")} + + %% no space after RuleNames + "/" "\\" + "/*" + -> {cons("DynRuleIntersectUnionFix")} + + %% 1 space after RuleNames + "/" "\\" + " /*" + -> {cons("DynRuleIntersectUnionFix")} + + } + > "=>" -> {cons("AM")} + + context-free priorities + StrategyAngle Term -> Strategy {cons("BA")} + > "/" RuleNames "\\*" Strategy -> Strategy {cons("DynRuleIntersectFix")} + > Strategy "=>" Term -> Strategy {cons("AM")} + > Strategy "/" RuleNames "\\" Strategy -> Strategy {cons("DynRuleIntersect"),right} + > Strategy "\\" RuleNames "/" Strategy -> Strategy {cons("DynRuleUnion"),right} + > Strategy "/" RuleNames "\\" + RuleNames "/" Strategy -> Strategy {cons("DynRuleIntersectUnion"),right} + > Strategy ";" Strategy -> Strategy {cons("Seq"),right} + +module Stratego-Sugar-Rules +imports Stratego-Sugar-Strategies +exports + + sorts RuleDef + context-free syntax + Id ":" Rule -> RuleDef {cons("RDefNoArgs")} + + Anno+ RuleDef -> Def {cons("AnnoDef")} + + Id "(" {Typedid ","}* ")" ":" Rule -> RuleDef {cons("RDef")} + + Id "(" {Typedid ","}* + "|" {Typedid ","}* ")" ":" Rule -> RuleDef {cons("RDefT")} + + %% Rule definition with pattern matched term parameters + Id "(" {Typedid ","}* + "|" {Term ","}* ")" ":" Rule -> RuleDef {cons("RDefP"), avoid} + + sorts Rule RuleCond + context-free syntax + Term "->" Term -> Rule {cons("RuleNoCond")} %% backward comp. + Term "->" Term "where" Strategy -> Rule {cons("Rule")} %% backward comp. + Term "->" Term RuleCond+ -> Rule {cons("Rule"), avoid} + + "where" Strategy -> RuleCond {cons("WhereClause")} + "with" Strategy -> RuleCond {cons("WithClause")} + +module Stratego-Sugar-Strategies +imports + Stratego-Core-Strategies + Stratego-Sugar-Terms + Stratego-Sugar-Constants + Stratego-Sugar-Signatures + +exports + context-free syntax + Id "=" Strategy -> StrategyDef {cons("SDefNoArgs")} + Id "(" {Typedid ","}* ")" "=" Strategy -> StrategyDef {cons("SDef")} + + %% Strategy definition with pattern matched term parameters + Id "(" {Typedid ","}* "|" {Term ","}* ")" "=" Strategy -> StrategyDef {cons("SDefP"), avoid} + + context-free syntax + ID -> Typedid {cons("DefaultVarDec")} + + sorts Rule + + sorts StrategyParen StrategyCurly StrategyAngle + context-free syntax + + %% Abstraction + + SVar "(" {Strategy ","}* ")" -> Strategy {cons("Call")} + + %% Match and build + + "{" Strategy "}" -> Strategy {cons("ScopeDefault")} + + %%"<" Strategy ">" Term -> Strategy {cons("BA")} + StrategyAngle Term -> Strategy {cons("BA")} + "<" Strategy ">" -> StrategyAngle {bracket} %% {cons("AngleStrat")} + + %% Combinators + + Strategy "<+" Strategy -> Strategy {cons("LChoice"),right} + + "rec" Id "(" Strategy ")" -> Strategy {cons("Rec")} + + "not" "(" Strategy ")" -> Strategy {cons("Not")} + "where" "(" Strategy ")" -> Strategy {cons("Where")} + "with" "(" Strategy ")" -> Strategy {cons("With"), prefer} + "test" "(" Strategy ")" -> Strategy {cons("Test")} + + %% Primitives + + "prim" "(" String ")" -> Strategy {cons("PrimNoArgs")} + "prim" "(" String "," {Term ","}* ")" -> Strategy {cons("Prim")} + + %% Congruence operators + + String -> Strategy {cons("StrCong")} + Int -> Strategy {cons("IntCong")} + Real -> Strategy {cons("RealCong")} + Char -> Strategy {cons("CharCong")} + + String "(" {Strategy ","}* ")" -> Strategy {cons("CongQ")} + + %%"(" {Strategy ","}* ")" -> Strategy {cons("TupleCong"),avoid} + + Strategy StrategyCurly -> Strategy {cons("AnnoCong")} + + "{" Strategy "}" -> StrategyCurly {cons("StrategyCurly")} + + "(" ")" -> Strategy {cons("EmptyTupleCong")} + "(" Strategy ")" -> Strategy {bracket} + "(" Strategy "," {Strategy ","}+ ")" -> Strategy {cons("TupleCong")} + +%% Mod -> Strategy {cons("ModCongNoArgs")} +%% Mod "(" {Strategy ","}* ")" -> Strategy {cons("ModCong")} +%% Id "^" Id -> Mod {cons("Mod")} + "[" {Strategy ","}* "]" -> Strategy {cons("ListCongNoTail")} + "[" {Strategy ","}* "|" Strategy "]" -> Strategy {cons("ListCong")} + +%% Strategy "#" "(" StrategyInj ")" -> Strategy {cons("ExplodeCong")} +%% Strategy "#" "(" Strategy ")" -> Strategy {cons("ExplodeCong")} + Strategy "#" StrategyParen -> Strategy {cons("ExplodeCong")} + + %% Syntactic sugar sugar + + sorts SwitchCase + context-free syntax + + SVar -> Strategy {cons("CallNoArgs")} + "\\" Rule "\\" -> Strategy {cons("LRule")} + "(" Rule ")" -> Strategy {cons("SRule")} + Strategy "+" Strategy -> Strategy {cons("Choice"),right} + Strategy "+>" Strategy -> Strategy {cons("RChoice"),right} + + "proceed" "(" {Strategy "," }+ ")" -> Strategy {cons("Proceed"), prefer} + + "if" Strategy "then" Strategy + "else" Strategy "end" -> Strategy {cons("CondChoice")} + "if" Strategy "then" Strategy "end" -> Strategy {cons("IfThen")} + + "switch" Strategy SwitchCase* "end" -> Strategy {cons("SwitchChoiceNoOtherwise")} + "switch" Strategy SwitchCase* + "otherwise" ":" Strategy "end" -> Strategy {cons("SwitchChoice")} + + "case" Strategy ":" Strategy -> SwitchCase {cons("SwitchCase")} + + Strategy "=>" Term -> Strategy {cons("AM")} + + Term ":=" Term -> Strategy {cons("Assign")} + + %% Priorities + + context-free priorities + { Strategy StrategyCurly -> Strategy + Strategy "#" StrategyParen -> Strategy + } + > { "!" Term -> Strategy + "?" Term -> Strategy + } + > StrategyAngle Term -> Strategy + > Strategy "=>" Term -> Strategy + > Strategy ";" Strategy -> Strategy + > {right: + Strategy "+" Strategy -> Strategy + Strategy "<+" Strategy -> Strategy + Strategy "+>" Strategy -> Strategy + + Strategy "<" StrategyMid + "+" Strategy -> Strategy + } + + context-free priorities + Strategy -> StrategyMid + > Strategy "+" Strategy -> Strategy + + context-free priorities + { Strategy StrategyCurly -> Strategy + Strategy "#" StrategyParen -> Strategy + } + .> Term ":=" Term -> Strategy + + +module Stratego-Sugar-Terms +imports + Stratego-Core-Terms + Stratego-Sugar-Strategies + +exports + sorts LID + context-free syntax + LId -> LID {cons("ListVar")} + LID -> Var {cons("Var")} + LID -> ID + + context-free syntax + "_" PreTerm -> PreTerm {cons("BuildDefaultPT")} + "_" Term -> Term {cons("BuildDefault"),prefer} + + Char -> PreTerm {cons("Char")} + + PreTerm "{" {Term ","}* "}" -> Term {cons("AnnoList")} + PreTerm -> Term {cons("NoAnnoList")} + + "<" Strategy ">" Term -> PreTerm {cons("App")} + "<" Strategy ">" Term -> Term {cons("App"),prefer} + + StrategyAngle -> PreTerm {cons("RootApp")} + StrategyAngle -> Term {cons("RootApp"),prefer} + + "(" {Term ","}* ")" -> PreTerm {cons("Tuple")} + "[" {Term ","}* "]" -> PreTerm {cons("List")} + "[" {Term ","}* "|" Term "]" -> PreTerm {cons("ListTail")} + + context-free priorities + Term "#" "(" Term ")" -> PreTerm {cons("Explode")} + > PreTerm "{" {Term ","}* "}" -> Term {cons("AnnoList")} + > Var "@" Term -> Term {cons("As")} + +module Stratego-Sugar-Signatures +imports + Stratego-Core-Signatures + Stratego-Sugar-Constants + +exports + + sorts Sort + context-free syntax + "[" {Sort ","}* "]" -> Sort {cons("SortList")} + "[" {Sort ","}* "|" Sort "]" -> Sort {cons("SortListTl")} + "(" {Sort ","}* ")" -> Sort {cons("SortTuple")} + + sorts Kind + context-free syntax + "*" -> Kind {cons("Star")} + "**" -> Kind {cons("StarStar")} + +module Stratego-Core-Signatures +imports + Stratego-Core-Identifiers + Stratego-Core-Constants +exports + sorts Sdecl + context-free syntax + "sorts" Sort* -> Sdecl {cons("Sorts")} + "constructors" Opdecl* -> Sdecl {cons("Constructors")} + + sorts Sort + context-free syntax + LCID -> Sort {cons("SortVar")} + UCID -> Sort {cons("SortNoArgs")} + Id "(" {Sort ","}* ")" -> Sort {cons("Sort")} + + sorts Opdecl + context-free syntax + Id ":" Type -> Opdecl {cons("OpDecl")} + String ":" Type -> Opdecl {cons("OpDeclQ")} + ":" Type -> Opdecl {cons("OpDeclInj")} + + context-free syntax + "external" Id ":" Type -> Opdecl {cons("ExtOpDecl")} + "external" String ":" Type -> Opdecl {cons("ExtOpDeclQ")} + "external" ":" Type -> Opdecl {cons("ExtOpDeclInj")} + + sorts Type ArgType ConstType FunType RetType + context-free syntax + Sort -> ConstType {cons("ConstType")} + {ArgType "*"}+ "->" RetType -> FunType {cons("FunType")} + "(" Type ")" -> ArgType {bracket} + ConstType -> ArgType + Type -> RetType + FunType -> RetType {reject} + + FunType -> Type + ConstType -> Type + + %%% + %% Restriction is required for the Sort* in Sdecl: List(a) is + %% ambiguous. + %%% + context-free restrictions + Sort -/- [\(] + +module Stratego-Core-Terms +imports + Stratego-Core-Identifiers + Stratego-Core-Constants + +exports + sorts ID Var Wld + context-free syntax + Id -> Var {cons("Var")} + Id -> ID + %% ":" Var -> Var {cons("SeqVar")} + + sorts Term PreTerm + context-free syntax + Var -> PreTerm + Var -> Term {prefer} + + "_" -> Wld {cons("Wld")} + Wld -> PreTerm + Wld -> Term {prefer} + + Int -> PreTerm {cons("Int")} + Real -> PreTerm {cons("Real")} + String -> PreTerm {cons("Str")} + + Id "(" {Term ","}* ")" -> PreTerm {cons("Op")} + String "(" {Term ","}* ")" -> PreTerm {cons("OpQ")} + Term "#" "(" Term ")" -> PreTerm {cons("Explode")} + + PreTerm "{^" PreTerm "}" -> Term {cons("Anno")} + + Var "@" Term -> Term {cons("As"),prefer} + Var "@" PreTerm -> PreTerm {cons("As")} + + context-free priorities + Term "#" "(" Term ")" -> PreTerm {cons("Explode")} + > Var "@" Term -> Term {cons("As")} + +module Stratego-Core-Strategies +imports + Stratego-Core-Terms + Stratego-Core-Constants + Stratego-Core-Signatures + +exports + sorts Def + context-free syntax + StrategyDef -> Def + Id -> SVar {cons("SVar")} + "let" Def* "in" Strategy "end" -> Strategy {cons("Let")} + SVar "(" {Strategy ","}* "|" {Term ","}* ")" -> Strategy {cons("CallT")} + + "call" "(" Term "|" {Strategy ","}* "|" {Term ","}* ")" -> Strategy {cons("CallDynamic")} + + + sorts StrategyDef + context-free syntax + Id "(" {Typedid ","}* + "|" {Typedid ","}* ")" "=" Strategy -> StrategyDef {cons("SDefT")} + + Anno+ StrategyDef -> Def {cons("AnnoDef")} + + "external" + Id "(" {Typedid ","}* + "|" {Typedid ","}* ")" "=" Strategy -> StrategyDef {cons("ExtSDefInl")} + + "external" + Id "(" {Typedid ","}* + "|" {Typedid ","}* ")" -> StrategyDef {cons("ExtSDef")} + + "external" + EmptyId "(" {Typedid ","}* + "|" {Typedid ","}* ")" -> StrategyDef {cons("ExtSDef")} + + + sorts EmptyId + lexical syntax + + -> EmptyId + + sorts Anno + context-free syntax + "extend" -> Anno {cons("Extend")} + "override" -> Anno {cons("Override")} + "internal" -> Anno {cons("Internal")} +%% "sealed" -> Anno {cons("Sealed")} +%% "extensible" -> Anno {cons("Extensible")} +%% "overridable" -> Anno {cons("Overridable")} + + lexical syntax + + "extend" -> Keyword + "override" -> Keyword + "internal" -> Keyword + "sealed" -> Keyword + "extensible" -> Keyword + "overridable" -> Keyword + + lexical restrictions + + "extend" + "override" + "internal" + "sealed" + "extensible" + "overridable" -/- [a-zA-Z0-9\'\-\_] + + sorts Typedid + context-free syntax + ID ":" Type -> Typedid {cons("VarDec")} + + + sorts Strategy SVar StrategyParen StrategyMid + context-free syntax + "(" Strategy ")" -> StrategyParen {cons("ParenStrat")} + + "fail" -> Strategy {cons("Fail")} + "id" -> Strategy {cons("Id")} + + "proceed" "(" {Strategy ","}* "|" {Term ","}* ")" -> Strategy {cons("ProceedT"), prefer} + "proceed" -> Strategy {cons("ProceedNoArgs"), prefer} + + %% Match and build + + "?" Term -> Strategy {cons("Match")} + "!" Term -> Strategy {cons("Build")} + "{" {ID ","}* ":" Strategy "}" -> Strategy {cons("Scope")} + + %% Combinators + + Strategy ";" Strategy -> Strategy {cons("Seq"),right} + Strategy "<" StrategyMid + "+" Strategy -> Strategy {cons("GuardedLChoice"),right} + Strategy -> StrategyMid + + %% Primitives + + "prim" "(" String "," {Strategy ","}* "|" {Term ","}*")" -> Strategy {cons("PrimT")} + + %% Traversal + + "some" "(" Strategy ")" -> Strategy {cons("Some")} + "one" "(" Strategy ")" -> Strategy {cons("One")} + "all" "(" Strategy ")" -> Strategy {cons("All")} + + %% Priorities + + context-free priorities + { "!" Term -> Strategy {cons("Build")} + "?" Term -> Strategy {cons("Match")} + } + > Strategy ";" Strategy -> Strategy {cons("Seq"),right} + > {right: + Strategy "<" StrategyMid + "+" Strategy -> Strategy {cons("GuardedLChoice"),right} + } + + context-free syntax + "import-term" "(" ModName ")" -> Strategy {cons("ImportTerm")} + +module Stratego-Core-Modules +imports + Stratego-Core-Identifiers + Stratego-Core-Strategies + Stratego-Core-Signatures + +exports + sorts Module + context-free syntax + "module" ModName Decl* -> Module {cons("Module")} + "specification" Decl* -> Module {cons("Specification")} + + sorts Decl + context-free syntax + "imports" ImportModName* -> Decl {cons("Imports")} + "strategies" Def* -> Decl {cons("Strategies")} + "signature" Sdecl* -> Decl {cons("Signature")} + + sorts ImportModName + context-free syntax + ModName -> ImportModName {cons("Import")} + syntax + "/" "-" -> {cons("ImportWildcard")} + +module Stratego-Sugar-Modules +imports + Stratego-Core-Modules + Stratego-Sugar-Strategies + Stratego-Sugar-Signatures + Stratego-Sugar-Overlays + Stratego-Sugar-Rules + +exports + + sorts Decl Def + context-free syntax + "rules" Def* -> Decl {cons("Rules")} + "overlays" Overlay* -> Decl {cons("Overlays")} + + RuleDef -> Def + + +module Stratego-Sugar-StringQuotations +exports + + sorts + StringQuotation + StringQuotedPart1 StringQuotedChars1 DollarOpen1 DollarClose1 QuotedBracket1 Dollar1 + StringQuotedPart2 StringQuotedChars2 DollarOpen2 DollarClose2 QuotedBracket2 Dollar2 + StringQuotedPart3 StringQuotedChars3 DollarOpen3 DollarClose3 QuotedBracket3 Dollar3 + StringQuotedPart4 StringQuotedChars4 DollarOpen4 DollarClose4 QuotedBracket4 Dollar4 + Padding + + context-free syntax + + StringQuotation -> PreTerm + + syntax + + StringQuotation -> + + "$" "[" Padding StringQuotedPart1* "]" -> StringQuotation {cons("StringQuotation1") } + Padding "[" "]" -> StringQuotedPart1 {cons("StringEscape1")} + -> StringQuotedPart1 {cons("QStr")} + -> StringQuotedPart1 {cons("QDollar")} + "$" "$" -> StringQuotedPart1 {cons("QBr")} + ~[\[\]\$]+ -> + [\[\]] -> + "$" -> + + "$" "{" Padding StringQuotedPart2* "}" -> StringQuotation {cons("StringQuotation2") } + Padding "{" "}" -> StringQuotedPart2 {cons("StringEscape2")} + -> StringQuotedPart2 {cons("QStr")} + -> StringQuotedPart2 {cons("QDollar")} + "$" "$" -> StringQuotedPart2 {cons("QBr")} + ~[\{\}\$]+ -> + [\{\}] -> + "$" -> + + "$" "(" Padding StringQuotedPart3* ")" -> StringQuotation {cons("StringQuotation3") } + Padding "(" ")" -> StringQuotedPart3 {cons("StringEscape3")} + -> StringQuotedPart3 {cons("QStr")} + -> StringQuotedPart3 {cons("QDollar")} + "$" "$" -> StringQuotedPart3 {cons("QBr")} + ~[\(\)\$]+ -> + [\(\)] -> + "$" -> + + "$" "<" Padding StringQuotedPart4* ">" -> StringQuotation {cons("StringQuotation4") } + Padding "<" ">" -> StringQuotedPart4 {cons("StringEscape4")} + -> StringQuotedPart4 {cons("QStr")} + -> StringQuotedPart4 {cons("QDollar")} + "$" "$" -> StringQuotedPart4 {cons("QBr")} + ~[\<\>\$]+ -> + [\<\>] -> + "$" -> + + %% Padding is a dummy lexical that will contain the indentation prefix of every quotation + -> Padding + -> {indentpadding} + + lexical restrictions + + StringQuotedChars1 -/- ~[\[\]\$] + StringQuotedChars2 -/- ~[\{\}\$] + StringQuotedChars3 -/- ~[\(\)\$] + StringQuotedChars4 -/- ~[\<\>\$] + Dollar1 -/- [\[\]] . [\$] + Dollar2 -/- [\{\}] . [\$] + Dollar3 -/- [\(\)] . [\$] + Dollar4 -/- [\<\>] . [\$] + +module Stratego-Core-Constants +exports + sorts Int Real String StrChar + lexical syntax + [\-]? [0-9]+ -> Int + [\-]? [0-9]+ [\.] [0-9]+ -> Real + "\"" StrChar* "\"" -> String + ~[\"\\] -> StrChar + [\\] [\"tnr\\] -> StrChar + + +module Stratego-Sugar-Constants +imports + Stratego-Core-Identifiers + Stratego-Core-Constants + Stratego-Sugar-StringQuotations +exports + sorts Char CharChar + lexical syntax + "'" CharChar "'" -> Char + ~[\'] -> CharChar + [\\] [\'ntr\ ] -> CharChar + Char -> Id {reject} + +module Stratego-Core-Identifiers +exports + sorts ModName ModNamePart + lexical syntax + {ModNamePart "/"}+ -> ModName + [a-zA-Z\.\_] [a-zA-Z0-9\'\.\-\_]* -> ModNamePart + lexical restrictions + ModName -/- [a-zA-Z0-9\'\.\-\_] + lexical syntax + "imports" -> ModName {reject} + "overlays" -> ModName {reject} + "rules" -> ModName {reject} + "signature" -> ModName {reject} + "strategies" -> ModName {reject} + + sorts Id LId LCID UCID Wld + lexical syntax + [a-zA-Z\_] [a-zA-Z0-9\'\-\_]* -> Id + [a-zA-Z\_] [a-zA-Z0-9\'\-\_]* "*" -> LId + [\'] [a-z]+ -> Id + + [a-z] [a-zA-Z0-9\'\-\_]* -> LCID + [A-Z] [a-zA-Z0-9\'\-\_]* -> UCID + + lexical restrictions + Id -/- [a-zA-Z0-9\'\_\*] + Id -/- [\-].~[\>] + LId -/- [a-zA-Z0-9\'\-\_] + LCID -/- [a-zA-Z0-9\'\-\_] + UCID -/- [a-zA-Z0-9\'\-\_] + + lexical syntax + "_" -> Id {reject} + "'" -> Id {reject} + + Keyword -> Id {reject} + Keyword -> LId {reject} + Keyword -> LCID {reject} + Keyword -> UCID {reject} + + lexical restrictions + "all" + "case" %% not reserved kw + "constructors" + "else" %% not reserved kw + "end" %% not reserved kw + "external" %% not reserved kw + "fail" + "id" + "if" %% not reserved kw + "in" + "imports" %% not reserved kw + "let" + "module" + "not" + "one" + "overlays" + "otherwise" %% not reserved kw + "prim" + "rec" %% not reserved kw + "rules" + "script" + "signature" + "some" + "sorts" + "strategies" + "stratego" + "switch" %% not reserved kw + "test" + "then" %% not reserved kw + "where" + "import-term" + -/- [a-zA-Z0-9\'\-\_] + + context-free restrictions + Wld -/- [a-zA-Z0-9\'\-\_] + + sorts Keyword + lexical syntax + "all" -> Keyword + "constructors" -> Keyword + "fail" -> Keyword + "id" -> Keyword + "in" -> Keyword + "let" -> Keyword + "module" -> Keyword + "not" -> Keyword + "one" -> Keyword + "overlays" -> Keyword + "prim" -> Keyword + "rules" -> Keyword + "script" -> Keyword + "signature" -> Keyword + "some" -> Keyword + "sorts" -> Keyword + "strategies" -> Keyword + "stratego" -> Keyword + "test" -> Keyword + "where" -> Keyword + "import-term" -> Keyword + + +module Stratego-Core-Layout +exports + sorts Ws ShortCom LongCom CommChar Asterisk Eof + lexical syntax + [\t\ \n\r] -> Ws + + "//" ~[\n]* ([\n] | Eof) -> ShortCom + "/*" CommChar* "*/" -> LongCom + -> Eof + + ~[\*] -> CommChar + + "*" -> Asterisk + Asterisk -> CommChar + + lexical restrictions + Asterisk -/- [\/] + Eof -/- ~[] + + lexical syntax + ShortCom -> LAYOUT + LongCom -> LAYOUT + Ws -> LAYOUT + + context-free restrictions + LAYOUT? -/- [\ \t\n\r] + LAYOUT? -/- [\/].[\*] + LAYOUT? -/- [\/].[\/] + +module Stratego-Sugar-Layout +imports Stratego-Core-Layout +%%exports +%% sorts VeryLongCom Eof VLCchar Backslash +%% lexical syntax +%% "\\end{code}" VLCchar* "\\begin{code}" -> VeryLongCom +%% "\\begin{code}" -> VeryLongCom +%% "\\end{code}" VLCchar* Eof -> VeryLongCom +%% "\\literate" VLCchar* "\\begin{code}" -> VeryLongCom +%% ~[\\] -> VLCchar +%% Backslash -> VLCchar +%% [\\] -> Backslash + +%% lexical restrictions +%% Backslash -/- [b].[e].[g].[i].[n].[\{].[c].[o].[d].[e].[\}] +%% Eof -/- ~[] + +%% lexical syntax +%% VeryLongCom -> LAYOUT + + + +module Stratego-Sugar +imports + Stratego-Sugar-Layout + Stratego-Core-Identifiers + Stratego-Sugar-Constants + Stratego-Sugar-Modules + Stratego-Sugar-Signatures + Stratego-Sugar-Terms + Stratego-Sugar-Strategies + Stratego-Sugar-Rules + Stratego-Sugar-DynamicRules + Stratego-Sugar-Overlays + +hiddens + context-free start-symbols Module + +module Stratego +imports Stratego-Sugar +hiddens + context-free start-symbols Module + +module StrategoMix[Ctx0] +imports Stratego + [ RuleNames => RuleNames[[Ctx0]] + RuleDec => RuleDec[[Ctx0]] + DynRuleScopeId => DynRuleScopeId[[Ctx0]] + DynRuleId => DynRuleId[[Ctx0]] + DynRuleDef => DynRuleDef[[Ctx0]] + ScopeLabels => ScopeLabels[[Ctx0]] + RuleCond => RuleCond[[Ctx0]] + Rule => Rule[[Ctx0]] + RuleDef => RuleDef[[Ctx0]] + Overlay => Overlay[[Ctx0]] + SwitchCase => SwitchCase[[Ctx0]] + StrategyCurly => StrategyCurly[[Ctx0]] + StrategyAngle => StrategyAngle[[Ctx0]] + Kind => Kind[[Ctx0]] + LID => LID[[Ctx0]] + ImportModName => ImportModName[[Ctx0]] + Decl => Decl[[Ctx0]] + Module => Module[[Ctx0]] + StrategyParen => StrategyParen[[Ctx0]] + Typedid => Typedid[[Ctx0]] + Anno => Anno[[Ctx0]] + EmptyId => EmptyId[[Ctx0]] + StrategyDef => StrategyDef[[Ctx0]] + SVar => SVar[[Ctx0]] + Def => Def[[Ctx0]] + Type => Type[[Ctx0]] + RetType => RetType[[Ctx0]] + ArgType => ArgType[[Ctx0]] + FunType => FunType[[Ctx0]] + ConstType => ConstType[[Ctx0]] + Opdecl => Opdecl[[Ctx0]] + Sort => Sort[[Ctx0]] + Sdecl => Sdecl[[Ctx0]] + Wld => Wld[[Ctx0]] + ID => ID[[Ctx0]] + Var => Var[[Ctx0]] + CharChar => CharChar[[Ctx0]] + Char => Char[[Ctx0]] + Padding => Padding[[Ctx0]] + Dollar4 => Dollar4[[Ctx0]] + QuotedBracket4 => QuotedBracket4[[Ctx0]] + StringQuotedChars4 => StringQuotedChars4[[Ctx0]] + StringQuotedPart4 => StringQuotedPart4[[Ctx0]] + Dollar3 => Dollar3[[Ctx0]] + QuotedBracket3 => QuotedBracket3[[Ctx0]] + StringQuotedChars3 => StringQuotedChars3[[Ctx0]] + StringQuotedPart3 => StringQuotedPart3[[Ctx0]] + Dollar2 => Dollar2[[Ctx0]] + QuotedBracket2 => QuotedBracket2[[Ctx0]] + StringQuotedChars2 => StringQuotedChars2[[Ctx0]] + StringQuotedPart2 => StringQuotedPart2[[Ctx0]] + Dollar1 => Dollar1[[Ctx0]] + QuotedBracket1 => QuotedBracket1[[Ctx0]] + StringQuotedChars1 => StringQuotedChars1[[Ctx0]] + StringQuotedPart1 => StringQuotedPart1[[Ctx0]] + StringQuotation => StringQuotation[[Ctx0]] + StrChar => StrChar[[Ctx0]] + String => String[[Ctx0]] + Real => Real[[Ctx0]] + Int => Int[[Ctx0]] + Keyword => Keyword[[Ctx0]] + UCID => UCID[[Ctx0]] + LCID => LCID[[Ctx0]] + LId => LId[[Ctx0]] + Id => Id[[Ctx0]] + ModNamePart => ModNamePart[[Ctx0]] + ModName => ModName[[Ctx0]] + PreTerm => PreTerm[[Ctx0]] + Term => Term[[Ctx0]] + StrategyMid => StrategyMid[[Ctx0]] + Strategy => Strategy[[Ctx0]] ] diff --git a/IBAF-Editor/metaborg.yaml b/IBAF-Editor/metaborg.yaml new file mode 100644 index 0000000..9c8e5f4 --- /dev/null +++ b/IBAF-Editor/metaborg.yaml @@ -0,0 +1,42 @@ +--- +id: org.example:IBAF-Editor:0.1.0-SNAPSHOT +name: IBAF +dependencies: + compile: + - org.metaborg:org.metaborg.meta.lang.esv:${metaborgVersion} + - org.metaborg:org.metaborg.meta.lang.template:${metaborgVersion} + - org.metaborg:org.metaborg.meta.nabl2.lang:${metaborgVersion} + source: + - org.metaborg:meta.lib.spoofax:${metaborgVersion} + - org.metaborg:org.metaborg.meta.nabl2.shared:${metaborgVersion} + - org.metaborg:org.metaborg.meta.nabl2.runtime:${metaborgVersion} +pardonedLanguages: +- EditorService +- Stratego-Sugar +- SDF +language: + sdf: + enabled: true + pretty-print: IBAF + sdf2table: java + placeholder: + prefix: "$" + stratego: + enabled: true + format: jar + args: + - -la + - stratego-lib + - -la + - stratego-gpp + - -la + - stratego-sglr + - -la + - stratego-xtc + - -la + - stratego-aterm + - -la + - stratego-sdf + - -la + - strc +exports: diff --git a/IBAF-Editor/pom.xml b/IBAF-Editor/pom.xml new file mode 100644 index 0000000..314a67c --- /dev/null +++ b/IBAF-Editor/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + org.example + IBAF-Editor + 0.1.0-SNAPSHOT + spoofax-language + + + org.metaborg + parent.language + 2.5.18 + + + + + metaborg-release-repo + https://artifacts.metaborg.org/content/repositories/releases/ + + true + + + false + + + + metaborg-snapshot-repo + https://artifacts.metaborg.org/content/repositories/snapshots/ + + false + + + true + + + + + + + metaborg-release-repo + https://artifacts.metaborg.org/content/repositories/releases/ + + true + + + false + + + + metaborg-snapshot-repo + https://artifacts.metaborg.org/content/repositories/snapshots/ + + false + + + true + + + + diff --git a/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/InteropRegisterer.java b/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/InteropRegisterer.java new file mode 100644 index 0000000..13b4603 --- /dev/null +++ b/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/InteropRegisterer.java @@ -0,0 +1,10 @@ +package IBAF_Editor.strategies; + +import org.strategoxt.lang.JavaInteropRegisterer; +import org.strategoxt.lang.Strategy; + +public class InteropRegisterer extends JavaInteropRegisterer { + public InteropRegisterer() { + super(new Strategy[] { }); + } +} diff --git a/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/Main.java b/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/Main.java new file mode 100644 index 0000000..18a4d92 --- /dev/null +++ b/IBAF-Editor/src/main/strategies/IBAF_Editor/strategies/Main.java @@ -0,0 +1,9 @@ +package IBAF_Editor.strategies; + +import org.strategoxt.lang.Context; + +public class Main { + public static void init(Context context) { + + } +} diff --git a/IBAF-Editor/syntax/Funcons-pp.sdf3 b/IBAF-Editor/syntax/Funcons-pp.sdf3 new file mode 100644 index 0000000..8019bb1 --- /dev/null +++ b/IBAF-Editor/syntax/Funcons-pp.sdf3 @@ -0,0 +1,9 @@ +module Funcons-pp + +imports Funcons + +context-free syntax + + FCT.FCTAppComp = < + <{NAME " "}+> + > // for pp only diff --git a/IBAF-Editor/syntax/Funcons.sdf3 b/IBAF-Editor/syntax/Funcons.sdf3 new file mode 100644 index 0000000..e7b49a1 --- /dev/null +++ b/IBAF-Editor/syntax/Funcons.sdf3 @@ -0,0 +1,87 @@ +module Funcons + +context-free start-symbols + Start + +context-free syntax + Start = FCT {avoid} + + FCT-SEQ.FCTSequence = < + , + > {right} + FCT-SEQ.FCTEmpty = + FCT-SEQ = FCT + + FCT.FCTInt = + INT + FCT.FCTFloat = + FLOAT + FCT.FCTChar = + CHAR + FCT.FCTString = + STRING + FCT.FCTDoubleQuoted = + <\\"\\"> + FCT.FCTVar + = VAR + FCT.FCTName + = NAME + FCT.FCTApp = < + > +// FCT.FCTSemantics = SEM-NAME PHRASE-FCT FCT? + FCT.FCTTyped = < + : > {non-assoc} + FCT.FCTComplement = < + ~ > + FCT.FCTComputes = < + =\> > {non-assoc} + FCT.FCTPostfix = < + > + FCT.FCTUnion = < + | <{FCT " | "}+> > + FCT.FCTIntersect = < + & <{FCT " & "}+> > + FCT.FCTGroup = < + () > + FCT.FCTList = < + [] > + FCT.FCTSet = < + {} > + FCT.FCTMap = < + {<{FCT-POINT ",\n"}*>} > + + FCT-POINT.Point = < + |-\> > + + FCT-Quoted.FCTQuotedEmpty = + +lexical syntax + INT = "-"? [0-9]+ + FLOAT = "-"? [0-9]+ "." [0-9]+ + CHAR = "'" ~[] "'" + STRING = "\"" STRING-CHAR* "\"" + STRING-CHAR = ~[\"\n] | "\\\"" | BACKSLASH + BACKSLASH = "\\" + NAME = [a-z] [a-zA-Z0-9\-]* + VAR = [A-Z] [a-zA-Z]* ([\-] [a-zA-Z]+)* SUFFIX? POSTFIX? + SUFFIX = [0-9]+ | [\']+ | ([0-9]+ [\']+) + POSTFIX = "*" | "+" | "?" + + LAYOUT = [\ \t\n\r] + LAYOUT = "/*" (~[\*] | STAR)* "*/" + STAR = "*" + LAYOUT = "//" ~[\n\r]* ([\n\r] | EOF) + EOF = + +lexical restrictions + INT -/- [0-9] + FLOAT -/- [0-9] + NAME -/- [a-zA-Z0-9\-] + BACKSLASH -/- [\"] + STAR -/- [\/] + EOF -/- ~[] + +context-free restrictions + LAYOUT? -/- [\ \t\n\r] + LAYOUT? -/- [\/].[\/] + LAYOUT? -/- [\/].[\*] diff --git a/IBAF-Editor/syntax/IBAF.sdf3 b/IBAF-Editor/syntax/IBAF.sdf3 new file mode 100644 index 0000000..219625a --- /dev/null +++ b/IBAF-Editor/syntax/IBAF.sdf3 @@ -0,0 +1,12 @@ +module IBAF + +imports + IBAF-Start + +context-free start-symbols + + Start + +context-free syntax + + Start = L-start diff --git a/IBAF-Editor/syntax/Stratego-IBAF.sdf b/IBAF-Editor/syntax/Stratego-IBAF.sdf new file mode 100644 index 0000000..f8fb2fc --- /dev/null +++ b/IBAF-Editor/syntax/Stratego-IBAF.sdf @@ -0,0 +1,11 @@ +module Stratego-IBAF + +imports + Stratego + IBAF +exports context-free syntax + Module -> Start + "|[" FCT-SEQ "]|" -> Term {cons("ToTerm"),prefer} + + variables + "START" -> L-start {prefer} diff --git a/IBAF-Editor/syntax/cbs-gen/IBAF-Start.sdf3 b/IBAF-Editor/syntax/cbs-gen/IBAF-Start.sdf3 new file mode 100644 index 0000000..e7f3d6c --- /dev/null +++ b/IBAF-Editor/syntax/cbs-gen/IBAF-Start.sdf3 @@ -0,0 +1,72 @@ +module IBAF-Start + +imports + + Funcons + +// Language "IBAFlang" + +lexical syntax // Language + LEX-int = ( [0-9] )+ + LEX-id = ( [a-z] ) ( [a-z] | [0-9] )* + +syntax // Language + +context-free syntax // Language + L-start.L-start--L-exp = + L-exp + + L-exp.L-exp--L-int = + L-int + L-exp.L-exp--L-id = + L-id + L-exp.L-exp--R-lambda-L-id-DOT-L-exp = + "lambda" L-id "." L-exp + L-exp.L-exp--L-exp-LPAREN-L-exp-RPAREN = + L-exp "(" L-exp ")" + L-exp.L-exp--R-let-L-id-EQUALS-L-exp-R-in-L-exp = + "let" L-id "=" L-exp "in" L-exp + L-exp.L-exp--LPAREN-L-exp-RPAREN = + "(" L-exp ")" + + L-int.LEX-int = + LEX-int + L-id.LEX-id = + LEX-id + +context-free syntax // Semantics + FCT.T-start = + "start" "[:" L-start ":]" + FCT.T-eval = + "eval" "[:" L-exp ":]" + FCT-Quoted.L-int = L-int + FCT.T-int = + "int" "[:" L-int ":]" + FCT-Quoted.L-id = L-id + FCT.T-id = + "id" "[:" L-id ":]" + +context-free syntax // Desugaring + +variables // Meta-variables + L-start = "(:START" [1-9]? ":)" {prefer} + L-start? = "(:START" [1-9]? "?:)" {prefer} + L-start* = "(:START" [1-9]? "*:)" {prefer} + L-start+ = "(:START" [1-9]? "+:)" {prefer} + L-exp = "(:E" [1-9]? ":)" {prefer} + L-exp? = "(:E" [1-9]? "?:)" {prefer} + L-exp* = "(:E" [1-9]? "*:)" {prefer} + L-exp+ = "(:E" [1-9]? "+:)" {prefer} + L-int = "(:N" [1-9]? ":)" {prefer} + L-int? = "(:N" [1-9]? "?:)" {prefer} + L-int* = "(:N" [1-9]? "*:)" {prefer} + L-int+ = "(:N" [1-9]? "+:)" {prefer} + L-id = "(:X" [1-9]? ":)" {prefer} + L-id? = "(:X" [1-9]? "?:)" {prefer} + L-id* = "(:X" [1-9]? "*:)" {prefer} + L-id+ = "(:X" [1-9]? "+:)" {prefer} + +// SDF comments + +sorts // ASTs + T-start diff --git a/IBAF-Editor/trans/analysis.str b/IBAF-Editor/trans/analysis.str new file mode 100644 index 0000000..fc97a5e --- /dev/null +++ b/IBAF-Editor/trans/analysis.str @@ -0,0 +1,34 @@ +module analysis + +imports + libstratego-lib + +imports + + nabl2/api + nabl2/runtime + + statics + + pp + +rules // Analysis + + editor-analyze = nabl2-analyze(id) + +rules // Debugging + + // Prints the abstract syntax ATerm of a selection. + debug-show-aterm: (selected, _, _, path, project-path) -> (filename, result) + with filename := path + ; result := selected + + // Prints the analyzed annotated abstract syntax ATerm of a selection. + debug-show-analyzed: (selected, _, _, path, project-path) -> (filename, result) + with filename := path + ; result := selected + +rules // Rename refactoring + + // change last strategy argument to id if multi-file analysis is enabled + rename-menu-action = nabl2-rename-action(construct-textual-change, editor-analyze, fail) diff --git a/IBAF-Editor/trans/cbs-gen/IBAF-Start.meta b/IBAF-Editor/trans/cbs-gen/IBAF-Start.meta new file mode 100644 index 0000000..3a139d3 --- /dev/null +++ b/IBAF-Editor/trans/cbs-gen/IBAF-Start.meta @@ -0,0 +1 @@ +Meta([Syntax("Stratego-IBAF")]) \ No newline at end of file diff --git a/IBAF-Editor/trans/cbs-gen/IBAF-Start.str b/IBAF-Editor/trans/cbs-gen/IBAF-Start.str new file mode 100644 index 0000000..efdf17a --- /dev/null +++ b/IBAF-Editor/trans/cbs-gen/IBAF-Start.str @@ -0,0 +1,53 @@ +module IBAF-Start + +imports + libstratego-gpp + signatures/- + pp/IBAF-parenthesize + pp/IBAF-pp + +imports + + +// Language "IBAFlang" + +rules +to-funcons: + |[ start[: (:E:) :] ]| -> + |[ initialise-binding finalise-failing eval[: (:E:) :] ]| +to-funcons: + |[ eval[: (:N:) :] ]| -> + |[ int[: (:N:) :] ]| +to-funcons: + |[ eval[: (:X:) :] ]| -> + |[ bound id[: (:X:) :] ]| +to-funcons: + |[ eval[: lambda(:X:).(:E:) :] ]| -> + |[ function closure scope (bind (id[: (:X:) :], + given), + eval[: (:E:) :]) ]| +to-funcons: + |[ eval[: (:E1:)((:E2:)) :] ]| -> + |[ apply (eval[: (:E1:) :], + eval[: (:E2:) :]) ]| +to-funcons: + |[ eval[: let(:X:)=(:E1:)in(:E2:) :] ]| -> + |[ scope (bind (id[: (:X:) :], + eval[: (:E1:) :]), + eval[: (:E2:) :]) ]| +to-funcons: + |[ eval[: ((:E:)) :] ]| -> + |[ eval[: (:E:) :] ]| +to-funcons-lex: + FCTDoubleQuoted(L-int(LEX-int(str))) -> + FCTString( str) +to-funcons: + |[ int[: (:N:) :] ]| -> + |[ decimal \"(:N:)\" ]| +to-funcons-lex: + FCTDoubleQuoted(L-id(LEX-id(str))) -> + FCTString( str) +to-funcons: + |[ id[: (:X:) :] ]| -> + |[ \"(:X:)\" ]| + diff --git a/IBAF-Editor/trans/generate.meta b/IBAF-Editor/trans/generate.meta new file mode 100644 index 0000000..d59eeb6 --- /dev/null +++ b/IBAF-Editor/trans/generate.meta @@ -0,0 +1 @@ +Meta([Syntax("Stratego-IBAF")]) diff --git a/IBAF-Editor/trans/generate.str b/IBAF-Editor/trans/generate.str new file mode 100644 index 0000000..9498461 --- /dev/null +++ b/IBAF-Editor/trans/generate.str @@ -0,0 +1,118 @@ +module generate + +imports + libstratego-gpp + signatures/- + pp/IBAF-parenthesize + pp/IBAF-pp + pp/Funcons-pp-pp + cbs-gen/IBAF-Start + +rules // Builder + + // Generates a funcon term for selected AST. + generate-fct: + (selected, position, ast, path, project-path) -> (filename, result) + where path + with + filename := path; + funcons := selected; + result := funcons + + generate-fct: + (selected, position, ast, path, project-path) -> None() + where path + + prettyprint-IBAF-string = + parenthesize-IBAF + ; prettyprint-IBAF-Start + ; !V([], ) + ; box2text-string(|80) + + to-funcons-start: START -> |[ start[: START :] ]| + + to-funcons-top = + to-funcons-start; + innermost(to-desugared <+ to-funcons <+ to-funcons-default); + bottomup(try(to-funcons-lex)); + innermost(to-funcons-sequences <+ to-funcons-groups); + innermost(to-funcons-apps) + + to-funcons = fail + + to-funcons-default = fail + + to-desugared = fail + +// Funcons involved in simplification rules: + +rules + + to-funcons-sequences: + FCTSequence(FCTEmpty(),seq) -> seq + + to-funcons-sequences: + FCTSequence(seq,FCTEmpty()) -> seq + + to-funcons-sequences: + FCTApp("sequential",FCTGroup(FCTSequence(fct,FCTApp("sequential",FCTGroup(seq))))) -> + FCTApp("sequential",FCTGroup(FCTSequence(fct,seq))) + + to-funcons-groups: + FCTGroup(FCTGroup(seq)) -> FCTGroup(seq) + + to-funcons-apps: + FCTApp(f1,FCTApp(f2,fct)) -> FCTAppComp([f1,f2],fct) + + to-funcons-apps: + FCTApp(f,FCTAppComp(fs,fct)) -> FCTAppComp([f|fs],fct) + + to-funcons-apps: + FCTApp(f,FCTGroup(seq)) -> FCTAppComp([f],FCTGroup(seq)) + +rules + + to-funcons-lex: + FCTString(str) -> FCTString( str) + + to-funcons-lex = ?FCTInt(_) + + to-funcons-lex = ?FCTChar(_) + + to-funcons-lex: FCTApp("integer-add",FCTGroup(FCTSequence(FCTInt(s),FCTInt(t)))) -> + FCTInt(( s, t)) + + to-funcons-lex: FCTApp("string-append",FCTGroup(FCTSequence(FCTString(str1),FCTString(str2)))) -> + FCTString( [ str1, str2]) + + to-funcons-lex: FCTApp("string-append",FCTGroup(FCTSequence(FCTString(str1),FCTSequence(FCTString(str2),FCTString(str3))))) -> + FCTString( + [ str1, str2, str3]) + // generalise to nested sequences + + to-funcons-lex: FCTList(seq) -> + FCTString( l) + where + seq; + l := (seq, []) + + + // l accumulates a list of strings, initially []: + to-funcons-string-list: (FCTSequence(seq1, seq2), l) -> + (seq1, (seq2, l)) + + to-funcons-string-list: (FCTEmpty(), l) -> l + + // 'C': + to-funcons-string-list: (FCTString(str), l) -> + [str | l] + + // ascii-character("C"): + to-funcons-string-list: + (FCTApp("ascii-character", FCTGroup(FCTString(str))), l) -> + [str | l] + + // ascii-character("\C"): + to-funcons-string-list: + (FCTApp("ascii-character", FCTApp("list-to-string", FCTList(seq))), l) -> + (seq, l) diff --git a/IBAF-Editor/trans/ibaf.str b/IBAF-Editor/trans/ibaf.str new file mode 100644 index 0000000..45c333d --- /dev/null +++ b/IBAF-Editor/trans/ibaf.str @@ -0,0 +1,21 @@ +module ibaf + +imports + libstratego-lib + +imports + completion/completion + pp + outline + analysis + +imports + generate + +rules // Debugging + + debug-show-aterm: + (node, _, _, path, project-path) -> (filename, result) + with + filename := path + ; result := node diff --git a/IBAF-Editor/trans/outline.str b/IBAF-Editor/trans/outline.str new file mode 100644 index 0000000..f4bee27 --- /dev/null +++ b/IBAF-Editor/trans/outline.str @@ -0,0 +1,18 @@ +module outline + +imports + libstratego-lib + +imports + + signatures/IBAF-sig + libspoofax/editor/outline + +rules + + editor-outline: + (_, _, ast, path, project-path) -> outline + where + outline := ast + + to-outline-label = fail diff --git a/IBAF-Editor/trans/pp.str b/IBAF-Editor/trans/pp.str new file mode 100644 index 0000000..f4e5d63 --- /dev/null +++ b/IBAF-Editor/trans/pp.str @@ -0,0 +1,52 @@ +module pp + +imports + libstratego-lib + +imports + + libstratego-gpp + libspoofax/sdf/pp + libspoofax/editor/refactoring/- + pp/IBAF-parenthesize + pp/IBAF-pp + +rules + + editor-format: + (node, _, ast, path, project-path) -> (filename, result) + with + ext := path + ; filename := path + ; result := node + +rules + + pp-IBAF-string = + parenthesize-IBAF + ; prettyprint-IBAF-start-symbols + ; !V([], ) + ; box2text-string(|120) + + pp-partial-IBAF-string = + parenthesize-IBAF + ; prettyprint-IBAF + ; !V([], ) + ; box2text-string(|120) + + pp-partial-IBAF-string(|sort) = + parenthesize-IBAF + ; prettyprint-IBAF(|sort) + ; !V([], ) + ; box2text-string(|120) + + pp-debug : + ast -> result + with + result := ast + <+ ast + ; result := "" + +rules + + construct-textual-change = construct-textual-change(pp-partial-IBAF-string, parenthesize, override-reconstruction, resugar) diff --git a/IBAF-Editor/trans/statics.nabl2 b/IBAF-Editor/trans/statics.nabl2 new file mode 100644 index 0000000..31c9b78 --- /dev/null +++ b/IBAF-Editor/trans/statics.nabl2 @@ -0,0 +1,12 @@ +module statics + +imports + + signatures/- + +rules + + init ^ (s) := new s. + + [[ _ ^ (s) ]]. + diff --git a/IBAF-cbs/.project b/IBAF-cbs/.project new file mode 100644 index 0000000..a850148 --- /dev/null +++ b/IBAF-cbs/.project @@ -0,0 +1,17 @@ + + + IBAF-cbs + + + + + + org.metaborg.spoofax.eclipse.builder + + + + + + org.metaborg.spoofax.eclipse.nature + + diff --git a/IBAF-cbs/Funcons-beta b/IBAF-cbs/Funcons-beta new file mode 120000 index 0000000..02b90f3 --- /dev/null +++ b/IBAF-cbs/Funcons-beta @@ -0,0 +1 @@ +/home/peter/cbs-all/CBS-beta/Funcons-beta \ No newline at end of file diff --git a/IBAF-cbs/IBAF/IBAF-Start/IBAF-Start.cbs b/IBAF-cbs/IBAF/IBAF-Start/IBAF-Start.cbs new file mode 100644 index 0000000..9985ea3 --- /dev/null +++ b/IBAF-cbs/IBAF/IBAF-Start/IBAF-Start.cbs @@ -0,0 +1,47 @@ +Language "IBAFlang" + +Syntax START:start ::= exp + +Semantics start[[ _:start ]] : =>values + +Rule start[[ E ]] = + initialise-binding finalise-failing eval[[ E ]] + +Syntax E:exp ::= int + | id + | 'lambda' id '.' exp + | exp '(' exp ')' + | 'let' id '=' exp 'in' exp + | '(' exp ')' + +Semantics eval[[ _:exp ]] : => values + +Rule eval[[ N ]] = int[[ N ]] + +Rule eval[[ X ]] = bound id[[ X ]] + +Rule eval[[ 'lambda' X '.' E ]] = + function closure + scope( bind( id[[ X ]], given ), + eval[[ E ]] ) + +Rule eval[[ E1 '(' E2 ')' ]] = + apply( eval[[ E1 ]], eval[[ E2 ]] ) + +Rule eval[[ 'let' X '=' E1 'in' E2 ]] = + scope( bind( id[[ X ]], eval[[ E1 ]] ), + eval[[ E2 ]] ) + +Rule eval[[ '(' E ')' ]] = eval[[ E ]] + + +Lexis N:int ::= ('0'-'9')+ + +Semantics int[[ N:int ]] : => integers + = decimal \"N\" + + +Lexis X:id ::= ('a'-'z') ('a'-'z'|'0'-'9')* + +Semantics id[[ X:id ]] : => identifiers + = \"X\" \ No newline at end of file diff --git a/IBAF-cbs/target/analysis/org.example_CBS_0.1.0-SNAPSHOT/constraint b/IBAF-cbs/target/analysis/org.example_CBS_0.1.0-SNAPSHOT/constraint new file mode 100644 index 0000000..a0326fe Binary files /dev/null and b/IBAF-cbs/target/analysis/org.example_CBS_0.1.0-SNAPSHOT/constraint differ