main commit

This commit is contained in:
2024-03-05 01:48:29 +02:00
parent bb9057805a
commit 6d6aa1678f
15 changed files with 452 additions and 12 deletions

7
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

2
.idea/misc.xml generated
View File

@@ -8,7 +8,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -13,5 +13,5 @@
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@@ -0,0 +1,3 @@
grammar HelloWorld;
start: 'Hello, World!' EOF;

View File

@@ -1,19 +1,30 @@
package org.lumijiez;
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.lumijiez.parser.HelloWorldBaseListener;
import org.lumijiez.parser.HelloWorldLexer;
import org.lumijiez.parser.HelloWorldParser;
public class Main {
public static void main(String[] args) {
// Press Alt+Enter with your caret at the highlighted text to see how
// IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
String input = "Hello, World!";
CharStream inputStream = CharStreams.fromString(input);
HelloWorldLexer lexer = new HelloWorldLexer(inputStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
HelloWorldParser parser = new HelloWorldParser(tokenStream);
// Press Shift+F10 or click the green arrow button in the gutter to run the code.
for (int i = 1; i <= 5; i++) {
ParseTreeWalker walker = new ParseTreeWalker();
MyListener listener = new MyListener();
walker.walk(listener, parser.start());
}
// Press Shift+F9 to start debugging your code. We have set one breakpoint
// for you, but you can always add more by pressing Ctrl+F8.
System.out.println("i = " + i);
static class MyListener extends HelloWorldBaseListener {
@Override
public void enterStart(HelloWorldParser.StartContext ctx) {
System.out.println("Parsed: " + ctx.getText());
}
}
}

View File

@@ -0,0 +1,14 @@
token literal names:
null
'Hello, World!'
token symbolic names:
null
null
rule names:
start
atn:
[4, 1, 1, 6, 2, 0, 7, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 0, 2, 1, 0, 0, 0, 2, 3, 5, 1, 0, 0, 3, 4, 5, 0, 0, 1, 4, 1, 1, 0, 0, 0, 0]

View File

@@ -0,0 +1,2 @@
T__0=1
'Hello, World!'=1

View File

@@ -0,0 +1,51 @@
package org.lumijiez.parser;// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link HelloWorldListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
@SuppressWarnings("CheckReturnValue")
public class HelloWorldBaseListener implements HelloWorldListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStart(HelloWorldParser.StartContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStart(HelloWorldParser.StartContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@@ -0,0 +1,21 @@
package org.lumijiez.parser;// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link HelloWorldVisitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
@SuppressWarnings("CheckReturnValue")
public class HelloWorldBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements HelloWorldVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStart(HelloWorldParser.StartContext ctx) { return visitChildren(ctx); }
}

View File

@@ -0,0 +1,20 @@
token literal names:
null
'Hello, World!'
token symbolic names:
null
null
rule names:
T__0
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[4, 0, 1, 17, 6, -1, 2, 0, 7, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 16, 0, 1, 1, 0, 0, 0, 1, 3, 1, 0, 0, 0, 3, 4, 5, 72, 0, 0, 4, 5, 5, 101, 0, 0, 5, 6, 5, 108, 0, 0, 6, 7, 5, 108, 0, 0, 7, 8, 5, 111, 0, 0, 8, 9, 5, 44, 0, 0, 9, 10, 5, 32, 0, 0, 10, 11, 5, 87, 0, 0, 11, 12, 5, 111, 0, 0, 12, 13, 5, 114, 0, 0, 13, 14, 5, 108, 0, 0, 14, 15, 5, 100, 0, 0, 15, 16, 5, 33, 0, 0, 16, 2, 1, 0, 0, 0, 1, 0, 0]

View File

@@ -0,0 +1,123 @@
package org.lumijiez.parser;// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"})
public class HelloWorldLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static String[] modeNames = {
"DEFAULT_MODE"
};
private static String[] makeRuleNames() {
return new String[] {
"T__0"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'Hello, World!'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public HelloWorldLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "HelloWorld.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getChannelNames() { return channelNames; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\u0004\u0000\u0001\u0011\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0001"+
"\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+
"\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+
"\u0000\u0001\u0000\u0000\u0000\u0001\u0001\u0001\u0001\u0000\u0000\u0010"+
"\u0000\u0001\u0001\u0000\u0000\u0000\u0001\u0003\u0001\u0000\u0000\u0000"+
"\u0003\u0004\u0005H\u0000\u0000\u0004\u0005\u0005e\u0000\u0000\u0005\u0006"+
"\u0005l\u0000\u0000\u0006\u0007\u0005l\u0000\u0000\u0007\b\u0005o\u0000"+
"\u0000\b\t\u0005,\u0000\u0000\t\n\u0005 \u0000\u0000\n\u000b\u0005W\u0000"+
"\u0000\u000b\f\u0005o\u0000\u0000\f\r\u0005r\u0000\u0000\r\u000e\u0005"+
"l\u0000\u0000\u000e\u000f\u0005d\u0000\u0000\u000f\u0010\u0005!\u0000"+
"\u0000\u0010\u0002\u0001\u0000\u0000\u0000\u0001\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@@ -0,0 +1,2 @@
T__0=1
'Hello, World!'=1

View File

@@ -0,0 +1,19 @@
package org.lumijiez.parser;// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link HelloWorldParser}.
*/
public interface HelloWorldListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link HelloWorldParser#start}.
* @param ctx the parse tree
*/
void enterStart(HelloWorldParser.StartContext ctx);
/**
* Exit a parse tree produced by {@link HelloWorldParser#start}.
* @param ctx the parse tree
*/
void exitStart(HelloWorldParser.StartContext ctx);
}

View File

@@ -0,0 +1,149 @@
// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
package org.lumijiez.parser;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class HelloWorldParser extends Parser {
static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1;
public static final int
RULE_start = 0;
private static String[] makeRuleNames() {
return new String[] {
"start"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'Hello, World!'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "HelloWorld.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public HelloWorldParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class StartContext extends ParserRuleContext {
public TerminalNode EOF() { return getToken(HelloWorldParser.EOF, 0); }
public StartContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_start; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HelloWorldListener ) ((HelloWorldListener)listener).enterStart(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HelloWorldListener ) ((HelloWorldListener)listener).exitStart(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HelloWorldVisitor ) return ((HelloWorldVisitor<? extends T>)visitor).visitStart(this);
else return visitor.visitChildren(this);
}
}
public final StartContext start() throws RecognitionException {
StartContext _localctx = new StartContext(_ctx, getState());
enterRule(_localctx, 0, RULE_start);
try {
enterOuterAlt(_localctx, 1);
{
setState(2);
match(T__0);
setState(3);
match(EOF);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\u0001\u0006\u0002\u0000\u0007\u0000\u0001\u0000\u0001\u0000"+
"\u0001\u0000\u0001\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0004\u0000"+
"\u0002\u0001\u0000\u0000\u0000\u0002\u0003\u0005\u0001\u0000\u0000\u0003"+
"\u0004\u0005\u0000\u0000\u0001\u0004\u0001\u0001\u0000\u0000\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@@ -0,0 +1,18 @@
package org.lumijiez.parser;// Generated from D:/Source/JavaProjects/dsl-formal-requirements/src/grammars/HelloWorld.g4 by ANTLR 4.13.1
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link HelloWorldParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface HelloWorldVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by {@link HelloWorldParser#start}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitStart(HelloWorldParser.StartContext ctx);
}