diff options
| author | Ben Culkin <scorpress@gmail.com> | 2023-11-08 19:16:08 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2023-11-08 19:16:08 -0500 |
| commit | 37da63640924937b90ea8c1a6a0c6e7318788ed5 (patch) | |
| tree | 48fdab14e7034055bd6bf77498497d7778d16df0 | |
Initial commit
23 files changed, 357 insertions, 0 deletions
diff --git a/winot/.project b/winot/.project new file mode 100644 index 0000000..8bb7fcd --- /dev/null +++ b/winot/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>winot</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + </natures> +</projectDescription> diff --git a/winot/.settings/org.eclipse.m2e.core.prefs b/winot/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/winot/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/winot/pom.xml b/winot/pom.xml new file mode 100644 index 0000000..e92bc4d --- /dev/null +++ b/winot/pom.xml @@ -0,0 +1,12 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.ashardalon</groupId> + <artifactId>winot</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>pom</packaging> + <name>winot</name> + <modules> + <module>winot-core</module> + </modules> +</project> diff --git a/winot/winot-core/.classpath b/winot/winot-core/.classpath new file mode 100644 index 0000000..b6a7afa --- /dev/null +++ b/winot/winot-core/.classpath @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="test" value="true"/> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> + <attributes> + <attribute name="test" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/winot/winot-core/.project b/winot/winot-core/.project new file mode 100644 index 0000000..ca9ebc6 --- /dev/null +++ b/winot/winot-core/.project @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>winot-core</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + </natures> +</projectDescription> diff --git a/winot/winot-core/.settings/org.eclipse.jdt.core.prefs b/winot/winot-core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d089a9b --- /dev/null +++ b/winot/winot-core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/winot/winot-core/.settings/org.eclipse.m2e.core.prefs b/winot/winot-core/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/winot/winot-core/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/winot/winot-core/pom.xml b/winot/winot-core/pom.xml new file mode 100644 index 0000000..71ac2c5 --- /dev/null +++ b/winot/winot-core/pom.xml @@ -0,0 +1,29 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.ashardalon</groupId> + <artifactId>winot</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>winot-core</artifactId> + <name>Core for Winot language</name> + <description>Contains the core for using the Winot language +</description> + <dependencies> + <dependency> + <groupId>bjc</groupId> + <artifactId>BJC-Utils2</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>bjc</groupId> + <artifactId>JPratt</artifactId> + <version>0.0.2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>io.github.bculkin2442</groupId> + <artifactId>esodata</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/winot/winot-core/src/main/java/com/ashardalon/winot/core/TokenType.java b/winot/winot-core/src/main/java/com/ashardalon/winot/core/TokenType.java new file mode 100644 index 0000000..5387328 --- /dev/null +++ b/winot/winot-core/src/main/java/com/ashardalon/winot/core/TokenType.java @@ -0,0 +1,32 @@ +package com.ashardalon.winot.core; + +/** + * Represents the types of tokens + * @author bjcul + * + */ +public enum TokenType { + // Utility tokens. Don't represent actual language symbols + /** + * Terminal token. Represents end-of-input + */ + TERMINAL, + /** + * Raw token. Hasn't been fully processed yet + */ + RAW, + // Represent operators + /** + * 'def' special-object initiator + */ + DEF, + // Represent literals of various types + /** + * Double-quoted string. + */ + DQ_STR, + /** + * A literal token + */ + LITERAL +} diff --git a/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotApp.java b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotApp.java new file mode 100644 index 0000000..019ce49 --- /dev/null +++ b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotApp.java @@ -0,0 +1,57 @@ +package com.ashardalon.winot.core; + +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + +import bjc.data.*; +import bjc.pratt.*; +import bjc.pratt.commands.InitialCommand; +import bjc.pratt.commands.impls.InitialCommands; +import bjc.pratt.tokens.*; +import bjc.utils.cli.StreamTerminal; +import bjc.utils.parserutils.*; +import bjc.utils.parserutils.splitter.*; + +/** + * Main class for Winot + * + * @author bjcul + */ +public class WinotApp { + /** + * Main method for Winot + * + * @param args Currently unused CLI args + */ + public static void main(String[] args) { + ConfigurableTokenSplitter baseSplitter = new ConfigurableTokenSplitter(true); + baseSplitter.addMultiDelimiters(" "); + baseSplitter.compile(); + + ExcludingTokenSplitter exclSplitter = new ExcludingTokenSplitter(baseSplitter); + + FilteredTokenSplitter filtSplitter = new FilteredTokenSplitter(exclSplitter, (tok) -> !tok.equals("")); + + WinotContext state = new WinotContext(); + + PrattParser<TokenType, String, WinotContext> parser = new PrattParser<>(); + + parser.addInitialCommand(TokenType.LITERAL, InitialCommands.leaf()); + parser.addInitialCommand(TokenType.DQ_STR, InitialCommands.leaf()); + parser.addInitialCommand(TokenType.RAW, InitialCommands.fail()); + + // using 'var' because otherwise the type is some 40+ characters involving repeating the command type twice + // Also, have to specify args to 'branch' since the compiler can't guess them otherwise + var defBuilder = InitialCommands.<TokenType, String, WinotContext>branch(); + InitialCommand<TokenType, String, WinotContext> defCommand = defBuilder.add(TokenType.DEF, null).build(); + parser.addInitialCommand(TokenType.DEF, defCommand); + + StreamTerminal terminal = new StreamTerminal(new InputStreamReader(System.in), + new OutputStreamWriter(System.out), "/", null); + IntHolder comNo = new IntHolder(); + terminal.setMode(new WinotMainMode(terminal, comNo, parser, state, filtSplitter)); + + terminal.addOutput("0 > "); + terminal.run(); + } +} diff --git a/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotContext.java b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotContext.java new file mode 100644 index 0000000..87cacdf --- /dev/null +++ b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotContext.java @@ -0,0 +1,5 @@ +package com.ashardalon.winot.core; + +public class WinotContext { + +} diff --git a/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotMainMode.java b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotMainMode.java new file mode 100644 index 0000000..ce8b9ef --- /dev/null +++ b/winot/winot-core/src/main/java/com/ashardalon/winot/core/WinotMainMode.java @@ -0,0 +1,67 @@ +package com.ashardalon.winot.core; + +import java.util.Iterator; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; + +import bjc.data.*; +import bjc.pratt.PrattParser; +import bjc.pratt.commands.CommandResult; +import bjc.pratt.tokens.*; +import bjc.utils.cli.StreamTerminal; +import bjc.utils.parserutils.ParserException; +import bjc.utils.parserutils.TokenUtils; +import bjc.utils.parserutils.splitter.FilteredTokenSplitter; + +final class WinotMainMode implements Consumer<String> { + private final StreamTerminal terminal; + private final IntHolder comNo; + private final PrattParser<TokenType, String, WinotContext> parser; + private final WinotContext state; + private final FilteredTokenSplitter filtSplitter; + + WinotMainMode(StreamTerminal terminal, IntHolder comNo, PrattParser<TokenType, String, WinotContext> parser, + WinotContext state, FilteredTokenSplitter filtSplitter) { + this.terminal = terminal; + this.comNo = comNo; + this.parser = parser; + this.state = state; + this.filtSplitter = filtSplitter; + } + + @Override + public void accept(String str) { + List<String> rawTokens = TokenUtils.removeDQuotedStrings(str); + ValueToggle<TokenType> strToggle = new ValueToggle<>(TokenType.DQ_STR, TokenType.RAW); + Function<String, Token<TokenType, String>> tokenzer = (strang) -> { + return new SimpleToken<>(strToggle.get(), strang); + }; + TransformIterator<String, + Token<TokenType, String>> rawItr = new TransformIterator<>(rawTokens.iterator(), tokenzer); + FlatMapIterator<Token<TokenType, String>, + Token<TokenType, String>> mapItr = new FlatMapIterator<>(rawItr, (tok) -> { + if (tok.getKey() == TokenType.RAW) { + Iterator<String> tknItr = filtSplitter.split(tok.getValue()).toIterable().iterator(); + Function<String, Token<TokenType, String>> literizer = (tokn) -> { + return new SimpleToken<>(TokenType.LITERAL, tokn); + }; + TransformIterator<String, + Token<TokenType, String>> transf = new TransformIterator<>(tknItr, literizer); + return transf; + } + return new SingleIterator<>(tok); + }); + SimpleTokenStream<TokenType, + String> sts = new SimpleTokenStream<>(mapItr, new SimpleToken<>(TokenType.TERMINAL, "")); + try { + // Prime token stream + sts.next(); + CommandResult<TokenType, String> result = parser.parseExpression(0, sts, state, true); + terminal.addOutput(result.toString() + "\n"); + } catch (ParserException pex) { + terminal.addOutput(pex.toString() + "\n"); + } + terminal.addOutput(String.format("%d > ", comNo.incr())); + } +}
\ No newline at end of file diff --git a/winot/winot-core/src/main/java/com/ashardalon/winot/core/package-info.java b/winot/winot-core/src/main/java/com/ashardalon/winot/core/package-info.java new file mode 100644 index 0000000..57f99a6 --- /dev/null +++ b/winot/winot-core/src/main/java/com/ashardalon/winot/core/package-info.java @@ -0,0 +1,6 @@ +/** + * Core for the Winot language + * @author bjcul + * + */ +package com.ashardalon.winot.core;
\ No newline at end of file diff --git a/winot/winot-core/src/main/java/module-info.java b/winot/winot-core/src/main/java/module-info.java new file mode 100644 index 0000000..96194a7 --- /dev/null +++ b/winot/winot-core/src/main/java/module-info.java @@ -0,0 +1,10 @@ +/** + * Core module for the Winot language + * @author bjcul + * + */ +module com.ashardalon.winot.core { + requires bjc.utils; + requires jpratt; + requires esodata; +}
\ No newline at end of file diff --git a/winot/winot-core/target/classes/META-INF/MANIFEST.MF b/winot/winot-core/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0276670 --- /dev/null +++ b/winot/winot-core/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: bjcul +Build-Jdk: 18.0.1 +Created-By: Maven Integration for Eclipse + diff --git a/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.properties b/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.properties new file mode 100644 index 0000000..242b22b --- /dev/null +++ b/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Wed Oct 25 19:34:06 EDT 2023 +artifactId=winot-core +groupId=com.ashardalon +m2e.projectLocation=C\:\\Users\\bjcul\\eclipse-workspace\\winot\\winot-core +m2e.projectName=winot-core +version=0.0.1-SNAPSHOT diff --git a/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.xml b/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.xml new file mode 100644 index 0000000..71ac2c5 --- /dev/null +++ b/winot/winot-core/target/classes/META-INF/maven/com.ashardalon/winot-core/pom.xml @@ -0,0 +1,29 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.ashardalon</groupId> + <artifactId>winot</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>winot-core</artifactId> + <name>Core for Winot language</name> + <description>Contains the core for using the Winot language +</description> + <dependencies> + <dependency> + <groupId>bjc</groupId> + <artifactId>BJC-Utils2</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>bjc</groupId> + <artifactId>JPratt</artifactId> + <version>0.0.2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>io.github.bculkin2442</groupId> + <artifactId>esodata</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + </dependencies> +</project>
\ No newline at end of file diff --git a/winot/winot-core/target/classes/com/ashardalon/winot/core/TokenType.class b/winot/winot-core/target/classes/com/ashardalon/winot/core/TokenType.class Binary files differnew file mode 100644 index 0000000..cd5d9e7 --- /dev/null +++ b/winot/winot-core/target/classes/com/ashardalon/winot/core/TokenType.class diff --git a/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotApp.class b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotApp.class Binary files differnew file mode 100644 index 0000000..a2fc97d --- /dev/null +++ b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotApp.class diff --git a/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotContext.class b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotContext.class Binary files differnew file mode 100644 index 0000000..15ae22b --- /dev/null +++ b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotContext.class diff --git a/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotMainMode.class b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotMainMode.class Binary files differnew file mode 100644 index 0000000..90a0570 --- /dev/null +++ b/winot/winot-core/target/classes/com/ashardalon/winot/core/WinotMainMode.class diff --git a/winot/winot-core/target/classes/com/ashardalon/winot/core/package-info.class b/winot/winot-core/target/classes/com/ashardalon/winot/core/package-info.class Binary files differnew file mode 100644 index 0000000..54aba6e --- /dev/null +++ b/winot/winot-core/target/classes/com/ashardalon/winot/core/package-info.class diff --git a/winot/winot-core/target/classes/module-info.class b/winot/winot-core/target/classes/module-info.class Binary files differnew file mode 100644 index 0000000..254dd2c --- /dev/null +++ b/winot/winot-core/target/classes/module-info.class |
