From 9ecfa63f5841f9e19d0df18fd68fc43777b8ca08 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sat, 30 Jan 2021 12:27:10 -0800 Subject: [PATCH] init: SDF3/Statix project as initialized by Spoofax --- .gitignore | 11 +++ .mvn/extensions.xml | 8 +++ .mvn/jvm.config | 1 + .mvn/maven.config | 1 + .mvn/settings.xml | 69 +++++++++++++++++++ README.md | 18 +++++ editor/Analysis.esv | 24 +++++++ editor/Main.esv | 13 ++++ editor/Syntax.esv | 27 ++++++++ metaborg.yaml | 43 ++++++++++++ pom.xml | 64 +++++++++++++++++ .../fostr/strategies/InteropRegisterer.java | 10 +++ .../strategies/fostr/strategies/Main.java | 9 +++ syntax/Common.sdf3 | 50 ++++++++++++++ syntax/fostr.sdf3 | 17 +++++ trans/analysis.str | 46 +++++++++++++ trans/fostr.str | 16 +++++ trans/outline.str | 15 ++++ trans/pp.str | 49 +++++++++++++ trans/statics.stx | 24 +++++++ 20 files changed, 515 insertions(+) create mode 100644 .gitignore create mode 100644 .mvn/extensions.xml create mode 100644 .mvn/jvm.config create mode 100644 .mvn/maven.config create mode 100644 .mvn/settings.xml create mode 100644 README.md create mode 100644 editor/Analysis.esv create mode 100644 editor/Main.esv create mode 100644 editor/Syntax.esv create mode 100644 metaborg.yaml create mode 100644 pom.xml create mode 100644 src/main/strategies/fostr/strategies/InteropRegisterer.java create mode 100644 src/main/strategies/fostr/strategies/Main.java create mode 100644 syntax/Common.sdf3 create mode 100644 syntax/fostr.sdf3 create mode 100644 trans/analysis.str create mode 100644 trans/fostr.str create mode 100644 trans/outline.str create mode 100644 trans/pp.str create mode 100644 trans/statics.stx diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0d8774 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/.cache +/bin +/src-gen +/target + +/.classpath +/.project +/.settings +/.factorypath + +/.polyglot.metaborg.yaml diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 0000000..878ae8b --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,8 @@ + + + + org.metaborg + spoofax-maven-plugin-pomless + 2.6.0-SNAPSHOT + + diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 0000000..67bd169 --- /dev/null +++ b/.mvn/jvm.config @@ -0,0 +1 @@ +-Xmx512m diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 0000000..6998b70 --- /dev/null +++ b/.mvn/maven.config @@ -0,0 +1 @@ +--global-settings .mvn/settings.xml diff --git a/.mvn/settings.xml b/.mvn/settings.xml new file mode 100644 index 0000000..9a31c2a --- /dev/null +++ b/.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/README.md b/README.md new file mode 100644 index 0000000..2c62c8a --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# fostr Language Specification + +## Using Statix for multi-file analysis + +By default the project is configured to analyze all files of your language in +isolation -- single-file analysis. It is also possible to configure the project +such that all files are analyzed together, and files can refer to each other -- +multi-file analysis. + +To enable multi-file analysis, do the following: +1. Uncomment the `(multifile)` option in `editor/Analysis.esv` +2. Uncomment the multi-file definition, and comment the single-file version, of + `editor-analyze` in `trans/analysis.str`. + +NB. When working in an IDE such as Eclipse, it is necessary to _restart the IDE_ +after switching from single-file to multi-file analysis or vice versa. Failure to +do so will result in exceptions during analysis. + diff --git a/editor/Analysis.esv b/editor/Analysis.esv new file mode 100644 index 0000000..ba43800 --- /dev/null +++ b/editor/Analysis.esv @@ -0,0 +1,24 @@ +module Analysis + +imports + + statix/Menus + +language + + // see README.md for details on how to switch to multi-file analysis + + observer : editor-analyze (constraint) // (multifile) + +references + + reference _ : editor-resolve + + hover _ : editor-hover + +menus + + menu: "Analysis" (openeditor) + + action: "Show pre-analyzed AST" = debug-show-pre-analyzed (source) + action: "Show analyzed AST" = debug-show-analyzed diff --git a/editor/Main.esv b/editor/Main.esv new file mode 100644 index 0000000..116630c --- /dev/null +++ b/editor/Main.esv @@ -0,0 +1,13 @@ +module Main + +imports + + Syntax + Analysis + +language + + extensions : fos + + provider : target/metaborg/stratego.ctree + provider : target/metaborg/stratego.jar diff --git a/editor/Syntax.esv b/editor/Syntax.esv new file mode 100644 index 0000000..aad195c --- /dev/null +++ b/editor/Syntax.esv @@ -0,0 +1,27 @@ +module Syntax + +imports + + libspoofax/color/default + completion/colorer/fostr-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/metaborg.yaml b/metaborg.yaml new file mode 100644 index 0000000..b1f5407 --- /dev/null +++ b/metaborg.yaml @@ -0,0 +1,43 @@ +--- +id: org.studioinfinity:fostr:0.1.0-SNAPSHOT +name: fostr +dependencies: + compile: + - org.metaborg:org.metaborg.meta.lang.esv:${metaborgVersion} + - org.metaborg:org.metaborg.meta.lang.template:${metaborgVersion} + - org.metaborg:statix.lang:${metaborgVersion} + - org.metaborg:sdf3.ext.statix:${metaborgVersion} + - org.metaborg:dynsem:${metaborgVersion} + source: + - org.metaborg:meta.lib.spoofax:${metaborgVersion} + - org.metaborg:statix.runtime:${metaborgVersion} +pardonedLanguages: +- EditorService +- Stratego-Sugar +- SDF +language: + sdf: + pretty-print: fostr + sdf2table: java + placeholder: + prefix: "$" + stratego: + format: ctree + args: + - -la + - stratego-lib + - -la + - stratego-sglr + - -la + - stratego-gpp + - -la + - stratego-xtc + - -la + - stratego-aterm + - -la + - stratego-sdf + - -la + - strc +exports: +- language: ATerm + directory: src-gen/statix diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f990159 --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + org.studioinfinity + fostr + 0.1.0-SNAPSHOT + spoofax-language + + + org.metaborg + parent.language + 2.6.0-SNAPSHOT + + + + + 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/src/main/strategies/fostr/strategies/InteropRegisterer.java b/src/main/strategies/fostr/strategies/InteropRegisterer.java new file mode 100644 index 0000000..315ae76 --- /dev/null +++ b/src/main/strategies/fostr/strategies/InteropRegisterer.java @@ -0,0 +1,10 @@ +package fostr.strategies; + +import org.strategoxt.lang.JavaInteropRegisterer; +import org.strategoxt.lang.Strategy; + +public class InteropRegisterer extends JavaInteropRegisterer { + public InteropRegisterer() { + super(new Strategy[] { }); + } +} diff --git a/src/main/strategies/fostr/strategies/Main.java b/src/main/strategies/fostr/strategies/Main.java new file mode 100644 index 0000000..b2f6e9c --- /dev/null +++ b/src/main/strategies/fostr/strategies/Main.java @@ -0,0 +1,9 @@ +package fostr.strategies; + +import org.strategoxt.lang.Context; + +public class Main { + public static void init(Context context) { + + } +} diff --git a/syntax/Common.sdf3 b/syntax/Common.sdf3 new file mode 100644 index 0000000..2786c4a --- /dev/null +++ b/syntax/Common.sdf3 @@ -0,0 +1,50 @@ +module Common + +lexical sorts + ID INT STRING + STRING_CHAR BACKSLASH_CHAR + COMMENT_CHAR INSIDE_COMMENT + NEWLINE_EOF EOF + +lexical syntax + + ID = [a-zA-Z] [a-zA-Z0-9]* + INT = "-"? [0-9]+ + STRING = "\"" STRING_CHAR* "\"" + STRING_CHAR = ~[\\\"\n] + STRING_CHAR = "\\\"" + STRING_CHAR = BACKSLASH_CHAR + BACKSLASH_CHAR = "\\" + LAYOUT = [\ \t\n\r] + COMMENT_CHAR = [\*] + LAYOUT = "/*" INSIDE_COMMENT* "*/" + INSIDE_COMMENT = ~[\*] + INSIDE_COMMENT = COMMENT_CHAR + LAYOUT = "//" ~[\n\r]* NEWLINE_EOF + NEWLINE_EOF = [\n\r] + NEWLINE_EOF = EOF + EOF = + +lexical restrictions + + // Ensure greedy matching for lexicals + + COMMENT_CHAR -/- [\/] + INT -/- [0-9] + ID -/- [a-zA-Z0-9\_] + + // EOF may not be followed by any char + + EOF -/- ~[] + + // Backslash chars in strings may not be followed by " + + BACKSLASH_CHAR -/- [\"] + +context-free restrictions + + // Ensure greedy matching for comments + + LAYOUT? -/- [\ \t\n\r] + LAYOUT? -/- [\/].[\/] + LAYOUT? -/- [\/].[\*] diff --git a/syntax/fostr.sdf3 b/syntax/fostr.sdf3 new file mode 100644 index 0000000..01493a0 --- /dev/null +++ b/syntax/fostr.sdf3 @@ -0,0 +1,17 @@ +module fostr + +imports + + Common + +context-free start-symbols + + Start + +context-free sorts + + Start + +context-free syntax + + Start.Empty = <> diff --git a/trans/analysis.str b/trans/analysis.str new file mode 100644 index 0000000..75a5b1e --- /dev/null +++ b/trans/analysis.str @@ -0,0 +1,46 @@ +module analysis + +imports + + statixruntime + statix/api + + pp + injections/- + + libspoofax/term/origin + +rules // Analysis + + // single-file analysis + editor-analyze = stx-editor-analyze(pre-analyze, post-analyze|"statics", "programOk") + + // see README.md for details on how to switch to multi-file analysis + // multi-file analysis +// editor-analyze = stx-editor-analyze(pre-analyze, post-analyze|"statics", "projectOk", "fileOk") + + pre-analyze = origin-track-forced(explicate-injections-fostr-Start) + post-analyze = origin-track-forced(implicate-injections-fostr-Start) + +rules // Editor Services + + editor-resolve = stx-editor-resolve + + editor-hover = stx-editor-hover + +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 pre-analyzed abstract syntax ATerm of a selection. + debug-show-pre-analyzed: (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 diff --git a/trans/fostr.str b/trans/fostr.str new file mode 100644 index 0000000..3b56116 --- /dev/null +++ b/trans/fostr.str @@ -0,0 +1,16 @@ +module fostr + +imports + + completion/completion + pp + outline + analysis + +rules // Debugging + + debug-show-aterm: + (node, _, _, path, project-path) -> (filename, result) + with + filename := path + ; result := node diff --git a/trans/outline.str b/trans/outline.str new file mode 100644 index 0000000..485cf8e --- /dev/null +++ b/trans/outline.str @@ -0,0 +1,15 @@ +module outline + +imports + + signatures/fostr-sig + libspoofax/editor/outline + +rules + + editor-outline: + (_, _, ast, path, project-path) -> outline + where + outline := ast + + to-outline-label = fail diff --git a/trans/pp.str b/trans/pp.str new file mode 100644 index 0000000..dee8afc --- /dev/null +++ b/trans/pp.str @@ -0,0 +1,49 @@ +module pp + +imports + + libstratego-gpp + libspoofax/sdf/pp + libspoofax/editor/refactoring/- + pp/fostr-parenthesize + pp/fostr-pp + +rules + + editor-format: + (node, _, ast, path, project-path) -> (filename, result) + with + ext := path + ; filename := path + ; result := node + +rules + + pp-fostr-string = + parenthesize-fostr + ; prettyprint-fostr-start-symbols + ; !V([], ) + ; box2text-string(|120) + + pp-partial-fostr-string = + parenthesize-fostr + ; prettyprint-fostr + ; !V([], ) + ; box2text-string(|120) + + pp-partial-fostr-string(|sort) = + parenthesize-fostr + ; prettyprint-fostr(|sort) + ; !V([], ) + ; box2text-string(|120) + + pp-debug : + ast -> result + with + result := ast + <+ ast + ; result := "" + +rules + + construct-textual-change = construct-textual-change(pp-partial-fostr-string, parenthesize, override-reconstruction, resugar) diff --git a/trans/statics.stx b/trans/statics.stx new file mode 100644 index 0000000..a0b0c6d --- /dev/null +++ b/trans/statics.stx @@ -0,0 +1,24 @@ +module statics + +// see README.md for details on how to switch to multi-file analysis + +rules // single-file entry point + + programOk : Start + + programOk(Empty()). + +rules // multi-file entry point + + projectOk : scope + + projectOk(s). + + fileOk : scope * Start + + fileOk(s, Empty()). + +signature + + sorts Start constructors + Empty : Start