diff --git a/docs/Diplomamunka_Szabo_Tamas.docx b/docs/Diplomamunka_Szabo_Tamas.docx index 493bcbf..e876aea 100644 Binary files a/docs/Diplomamunka_Szabo_Tamas.docx and b/docs/Diplomamunka_Szabo_Tamas.docx differ diff --git a/grammar-selector/Selector.g4 b/grammar-selector/Selector.g4 index 1e87bc3..493fc37 100644 --- a/grammar-selector/Selector.g4 +++ b/grammar-selector/Selector.g4 @@ -1,52 +1,26 @@ grammar Selector; -init : selectors +init : '[' selectors ']' ; selectors : selector (',' selector)* ; selector : statement - | selector operator selector - ; + | statement operator selector + ; -attribute : '[' ID '=' ID ']' +attribute : '[' Property=ID '=' Value=ID ']' ; operator : '>' - | '+' - ; - -statement : baseStatement attribute* ; -baseStatement : Statement=WHILE - | Statement=FOREACH - | Statement=FUNCTION - | Statement=IF - | Statement=TRUE_STATEMENT - | Statement=ELSE_STATEMENT - | Statement=BODY - | Statement=EXPRESSION - | Statement=VARIABLE - | Statement=ALL +statement : Selector=ID Attributes=attribute* ; - -WHILE : 'while'; -FOREACH : 'foreach'; -FUNCTION : 'function'; -IF : 'if'; -TRUE_STATEMENT : 'else-if'; -ELSE_STATEMENT : 'else'; -BODY : 'body'; -EXPRESSION : 'expression'; -VARIABLE : 'variable'; -DECLARATION : 'declaration'; -ALL : '*'; - -ID : '@'? (LETTER|'_') (LETTER|'_'|'-'|[0-9])*; +ID : ('@'? (LETTER|'_') (LETTER|'_'|'-'|[0-9])*) | '*'; fragment LETTER : [a-zA-Z]; diff --git a/grammar-selector/example.txt b/grammar-selector/example.txt index c85d59b..db25419 100644 --- a/grammar-selector/example.txt +++ b/grammar-selector/example.txt @@ -1 +1 @@ -if[condition=true][attribute=not-null] > body > if > body + while \ No newline at end of file +[if > sequence > sequence] \ No newline at end of file diff --git a/grammar-selector/src/Selector.tokens b/grammar-selector/src/Selector.tokens index 1a97789..7a54d52 100644 --- a/grammar-selector/src/Selector.tokens +++ b/grammar-selector/src/Selector.tokens @@ -1,37 +1,13 @@ -FUNCTION=9 -NEWLINE=20 -VARIABLE=15 -WHILE=7 -T__1=5 -ALL=17 -T__0=6 -T__3=3 -T__2=4 -WHITESPACE=19 -TRUE_STATEMENT=11 -FOREACH=8 -ELSE_STATEMENT=12 -BODY=13 -ID=18 -DECLARATION=16 -EXPRESSION=14 -T__5=1 -IF=10 -T__4=2 -'foreach'=8 -'else-if'=11 -'else'=12 -'>'=2 -'expression'=14 -'='=6 -'if'=10 -'*'=17 -'['=5 -'while'=7 -'body'=13 -'+'=4 +WHITESPACE=7 +NEWLINE=8 +ID=6 +T__1=4 +T__0=5 +T__3=2 +T__2=3 +T__4=1 +'='=5 +'['=4 ','=3 -'function'=9 -'variable'=15 -'declaration'=16 +'>'=2 ']'=1 diff --git a/grammar-selector/src/SelectorBaseListener.class b/grammar-selector/src/SelectorBaseListener.class index 6ec5078..9175af9 100644 Binary files a/grammar-selector/src/SelectorBaseListener.class and b/grammar-selector/src/SelectorBaseListener.class differ diff --git a/grammar-selector/src/SelectorBaseListener.java b/grammar-selector/src/SelectorBaseListener.java index 0d430bc..6d8b2ac 100644 --- a/grammar-selector/src/SelectorBaseListener.java +++ b/grammar-selector/src/SelectorBaseListener.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.NotNull; @@ -13,117 +13,104 @@ public class SelectorBaseListener implements SelectorListener { /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterStatement(@NotNull SelectorParser.StatementContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitStatement(@NotNull SelectorParser.StatementContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterSelector(@NotNull SelectorParser.SelectorContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitSelector(@NotNull SelectorParser.SelectorContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterSelectors(@NotNull SelectorParser.SelectorsContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitSelectors(@NotNull SelectorParser.SelectorsContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx) { } - - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterAttribute(@NotNull SelectorParser.AttributeContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitAttribute(@NotNull SelectorParser.AttributeContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterInit(@NotNull SelectorParser.InitContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitInit(@NotNull SelectorParser.InitContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterOperator(@NotNull SelectorParser.OperatorContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitOperator(@NotNull SelectorParser.OperatorContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void enterEveryRule(@NotNull ParserRuleContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void exitEveryRule(@NotNull ParserRuleContext ctx) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void visitTerminal(@NotNull TerminalNode node) { } /** * {@inheritDoc} - * - *

The default implementation does nothing.

+ *

+ * The default implementation does nothing. */ @Override public void visitErrorNode(@NotNull ErrorNode node) { } } \ No newline at end of file diff --git a/grammar-selector/src/SelectorBaseVisitor.class b/grammar-selector/src/SelectorBaseVisitor.class index 2087f26..5314431 100644 Binary files a/grammar-selector/src/SelectorBaseVisitor.class and b/grammar-selector/src/SelectorBaseVisitor.class differ diff --git a/grammar-selector/src/SelectorBaseVisitor.java b/grammar-selector/src/SelectorBaseVisitor.java index e8f8c8f..fbd3521 100644 --- a/grammar-selector/src/SelectorBaseVisitor.java +++ b/grammar-selector/src/SelectorBaseVisitor.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; @@ -13,57 +13,49 @@ public class SelectorBaseVisitor extends AbstractParseTreeVisitor implements SelectorVisitor { /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitStatement(@NotNull SelectorParser.StatementContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitSelector(@NotNull SelectorParser.SelectorContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitSelectors(@NotNull SelectorParser.SelectorsContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx) { return visitChildren(ctx); } - - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitAttribute(@NotNull SelectorParser.AttributeContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitInit(@NotNull SelectorParser.InitContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

+ *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. */ @Override public T visitOperator(@NotNull SelectorParser.OperatorContext ctx) { return visitChildren(ctx); } } \ No newline at end of file diff --git a/grammar-selector/src/SelectorLexer.class b/grammar-selector/src/SelectorLexer.class index 91afebe..6999b79 100644 Binary files a/grammar-selector/src/SelectorLexer.class and b/grammar-selector/src/SelectorLexer.class differ diff --git a/grammar-selector/src/SelectorLexer.java b/grammar-selector/src/SelectorLexer.java index e910ed4..cfafea0 100644 --- a/grammar-selector/src/SelectorLexer.java +++ b/grammar-selector/src/SelectorLexer.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.Token; @@ -14,23 +14,18 @@ public class SelectorLexer extends Lexer { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, WHILE=7, FOREACH=8, FUNCTION=9, - IF=10, TRUE_STATEMENT=11, ELSE_STATEMENT=12, BODY=13, EXPRESSION=14, VARIABLE=15, - DECLARATION=16, ALL=17, ID=18, WHITESPACE=19, NEWLINE=20; + T__4=1, T__3=2, T__2=3, T__1=4, T__0=5, ID=6, WHITESPACE=7, NEWLINE=8; public static String[] modeNames = { "DEFAULT_MODE" }; public static final String[] tokenNames = { "", - "']'", "'>'", "','", "'+'", "'['", "'='", "'while'", "'foreach'", "'function'", - "'if'", "'else-if'", "'else'", "'body'", "'expression'", "'variable'", - "'declaration'", "'*'", "ID", "WHITESPACE", "NEWLINE" + "']'", "'>'", "','", "'['", "'='", "ID", "WHITESPACE", "NEWLINE" }; public static final String[] ruleNames = { - "T__5", "T__4", "T__3", "T__2", "T__1", "T__0", "WHILE", "FOREACH", "FUNCTION", - "IF", "TRUE_STATEMENT", "ELSE_STATEMENT", "BODY", "EXPRESSION", "VARIABLE", - "DECLARATION", "ALL", "ID", "LETTER", "WHITESPACE", "NEWLINE" + "T__4", "T__3", "T__2", "T__1", "T__0", "ID", "LETTER", "WHITESPACE", + "NEWLINE" }; @@ -48,64 +43,52 @@ public SelectorLexer(CharStream input) { @Override public String[] getRuleNames() { return ruleNames; } - @Override - public String getSerializedATN() { return _serializedATN; } - @Override public String[] getModeNames() { return modeNames; } @Override public ATN getATN() { return _ATN; } + @Override + public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { + switch (ruleIndex) { + case 7: WHITESPACE_action((RuleContext)_localctx, actionIndex); break; + + case 8: NEWLINE_action((RuleContext)_localctx, actionIndex); break; + } + } + private void WHITESPACE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 0: skip(); break; + } + } + private void NEWLINE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 1: skip(); break; + } + } + public static final String _serializedATN = - "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\26\u00a5\b\1\4\2"+ - "\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4"+ - "\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+ - "\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\3\2\3\2\3\3\3\3\3\4\3\4"+ - "\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3"+ - "\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\f\3\f"+ - "\3\f\3\f\3\f\3\f\3\f\3\f\3\r\3\r\3\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16"+ - "\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\20\3\20\3\20"+ - "\3\20\3\20\3\20\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\21"+ - "\3\21\3\21\3\21\3\21\3\22\3\22\3\23\5\23\u0089\n\23\3\23\3\23\5\23\u008d"+ - "\n\23\3\23\3\23\7\23\u0091\n\23\f\23\16\23\u0094\13\23\3\24\3\24\3\25"+ - "\6\25\u0099\n\25\r\25\16\25\u009a\3\25\3\25\3\26\5\26\u00a0\n\26\3\26"+ - "\3\26\3\26\3\26\2\2\27\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27"+ - "\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\2)\25+\26\3\2\5\5\2//\62;aa\4"+ - "\2C\\c|\4\2\13\13\"\"\u00a9\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3"+ - "\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2"+ - "\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37"+ - "\3\2\2\2\2!\3\2\2\2\2#\3\2\2\2\2%\3\2\2\2\2)\3\2\2\2\2+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2vw\7n\2\2wx\7g\2\2x \3\2\2\2yz\7f\2\2z{\7g\2\2{|\7e\2\2|}\7n\2"+ - "\2}~\7c\2\2~\177\7t\2\2\177\u0080\7c\2\2\u0080\u0081\7v\2\2\u0081\u0082"+ - "\7k\2\2\u0082\u0083\7q\2\2\u0083\u0084\7p\2\2\u0084\"\3\2\2\2\u0085\u0086"+ - "\7,\2\2\u0086$\3\2\2\2\u0087\u0089\7B\2\2\u0088\u0087\3\2\2\2\u0088\u0089"+ - "\3\2\2\2\u0089\u008c\3\2\2\2\u008a\u008d\5\'\24\2\u008b\u008d\7a\2\2\u008c"+ - "\u008a\3\2\2\2\u008c\u008b\3\2\2\2\u008d\u0092\3\2\2\2\u008e\u0091\5\'"+ - "\24\2\u008f\u0091\t\2\2\2\u0090\u008e\3\2\2\2\u0090\u008f\3\2\2\2\u0091"+ - "\u0094\3\2\2\2\u0092\u0090\3\2\2\2\u0092\u0093\3\2\2\2\u0093&\3\2\2\2"+ - "\u0094\u0092\3\2\2\2\u0095\u0096\t\3\2\2\u0096(\3\2\2\2\u0097\u0099\t"+ - "\4\2\2\u0098\u0097\3\2\2\2\u0099\u009a\3\2\2\2\u009a\u0098\3\2\2\2\u009a"+ - "\u009b\3\2\2\2\u009b\u009c\3\2\2\2\u009c\u009d\b\25\2\2\u009d*\3\2\2\2"+ - "\u009e\u00a0\7\17\2\2\u009f\u009e\3\2\2\2\u009f\u00a0\3\2\2\2\u00a0\u00a1"+ - "\3\2\2\2\u00a1\u00a2\7\f\2\2\u00a2\u00a3\3\2\2\2\u00a3\u00a4\b\26\2\2"+ - "\u00a4,\3\2\2\2\t\2\u0088\u008c\u0090\u0092\u009a\u009f\3\b\2\2"; + "\3\uacf5\uee8c\u4f5d\u8b0d\u4a45\u78bd\u1b2f\u3378\2\n@\b\1\4\2\t\2\4"+ + "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\3\2\3\2"+ + "\3\3\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\2\2<=\7\f\2"+ + "\2=>\3\2\2\2>?\b\n\3\2?\24\3\2\2\2\n\2 $(*.\65:"; public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + ATNSimulator.deserialize(_serializedATN.toCharArray()); static { _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { diff --git a/grammar-selector/src/SelectorLexer.tokens b/grammar-selector/src/SelectorLexer.tokens index 1a97789..7a54d52 100644 --- a/grammar-selector/src/SelectorLexer.tokens +++ b/grammar-selector/src/SelectorLexer.tokens @@ -1,37 +1,13 @@ -FUNCTION=9 -NEWLINE=20 -VARIABLE=15 -WHILE=7 -T__1=5 -ALL=17 -T__0=6 -T__3=3 -T__2=4 -WHITESPACE=19 -TRUE_STATEMENT=11 -FOREACH=8 -ELSE_STATEMENT=12 -BODY=13 -ID=18 -DECLARATION=16 -EXPRESSION=14 -T__5=1 -IF=10 -T__4=2 -'foreach'=8 -'else-if'=11 -'else'=12 -'>'=2 -'expression'=14 -'='=6 -'if'=10 -'*'=17 -'['=5 -'while'=7 -'body'=13 -'+'=4 +WHITESPACE=7 +NEWLINE=8 +ID=6 +T__1=4 +T__0=5 +T__3=2 +T__2=3 +T__4=1 +'='=5 +'['=4 ','=3 -'function'=9 -'variable'=15 -'declaration'=16 +'>'=2 ']'=1 diff --git a/grammar-selector/src/SelectorListener.class b/grammar-selector/src/SelectorListener.class index a2e8849..7d2fbfd 100644 Binary files a/grammar-selector/src/SelectorListener.class and b/grammar-selector/src/SelectorListener.class differ diff --git a/grammar-selector/src/SelectorListener.java b/grammar-selector/src/SelectorListener.java index 54b763d..4d38cac 100644 --- a/grammar-selector/src/SelectorListener.java +++ b/grammar-selector/src/SelectorListener.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.tree.ParseTreeListener; @@ -40,17 +40,6 @@ public interface SelectorListener extends ParseTreeListener { */ void exitSelectors(@NotNull SelectorParser.SelectorsContext ctx); - /** - * Enter a parse tree produced by {@link SelectorParser#baseStatement}. - * @param ctx the parse tree - */ - void enterBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx); - /** - * Exit a parse tree produced by {@link SelectorParser#baseStatement}. - * @param ctx the parse tree - */ - void exitBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx); - /** * Enter a parse tree produced by {@link SelectorParser#attribute}. * @param ctx the parse tree diff --git a/grammar-selector/src/SelectorParser$AttributeContext.class b/grammar-selector/src/SelectorParser$AttributeContext.class index 4cbc136..9ecd3c1 100644 Binary files a/grammar-selector/src/SelectorParser$AttributeContext.class and b/grammar-selector/src/SelectorParser$AttributeContext.class differ diff --git a/grammar-selector/src/SelectorParser$BaseStatementContext.class b/grammar-selector/src/SelectorParser$BaseStatementContext.class index 6179551..45b70f7 100644 Binary files a/grammar-selector/src/SelectorParser$BaseStatementContext.class and b/grammar-selector/src/SelectorParser$BaseStatementContext.class differ diff --git a/grammar-selector/src/SelectorParser$InitContext.class b/grammar-selector/src/SelectorParser$InitContext.class index 3e279b9..062ba7f 100644 Binary files a/grammar-selector/src/SelectorParser$InitContext.class and b/grammar-selector/src/SelectorParser$InitContext.class differ diff --git a/grammar-selector/src/SelectorParser$OperatorContext.class b/grammar-selector/src/SelectorParser$OperatorContext.class index fbbb546..69a803a 100644 Binary files a/grammar-selector/src/SelectorParser$OperatorContext.class and b/grammar-selector/src/SelectorParser$OperatorContext.class differ diff --git a/grammar-selector/src/SelectorParser$SelectorContext.class b/grammar-selector/src/SelectorParser$SelectorContext.class index 249183c..9596000 100644 Binary files a/grammar-selector/src/SelectorParser$SelectorContext.class and b/grammar-selector/src/SelectorParser$SelectorContext.class differ diff --git a/grammar-selector/src/SelectorParser$SelectorsContext.class b/grammar-selector/src/SelectorParser$SelectorsContext.class index 4324c05..fd52a5f 100644 Binary files a/grammar-selector/src/SelectorParser$SelectorsContext.class and b/grammar-selector/src/SelectorParser$SelectorsContext.class differ diff --git a/grammar-selector/src/SelectorParser$StatementContext.class b/grammar-selector/src/SelectorParser$StatementContext.class index 4a833fa..b75e502 100644 Binary files a/grammar-selector/src/SelectorParser$StatementContext.class and b/grammar-selector/src/SelectorParser$StatementContext.class differ diff --git a/grammar-selector/src/SelectorParser.class b/grammar-selector/src/SelectorParser.class index b48cf47..7f4aee0 100644 Binary files a/grammar-selector/src/SelectorParser.class and b/grammar-selector/src/SelectorParser.class differ diff --git a/grammar-selector/src/SelectorParser.java b/grammar-selector/src/SelectorParser.java index c9748c3..f084bfd 100644 --- a/grammar-selector/src/SelectorParser.java +++ b/grammar-selector/src/SelectorParser.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; import org.antlr.v4.runtime.*; @@ -14,20 +14,15 @@ public class SelectorParser extends Parser { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, WHILE=7, FOREACH=8, FUNCTION=9, - IF=10, TRUE_STATEMENT=11, ELSE_STATEMENT=12, BODY=13, EXPRESSION=14, VARIABLE=15, - DECLARATION=16, ALL=17, ID=18, WHITESPACE=19, NEWLINE=20; + T__4=1, T__3=2, T__2=3, T__1=4, T__0=5, ID=6, WHITESPACE=7, NEWLINE=8; public static final String[] tokenNames = { - "", "']'", "'>'", "','", "'+'", "'['", "'='", "'while'", "'foreach'", - "'function'", "'if'", "'else-if'", "'else'", "'body'", "'expression'", - "'variable'", "'declaration'", "'*'", "ID", "WHITESPACE", "NEWLINE" + "", "']'", "'>'", "','", "'['", "'='", "ID", "WHITESPACE", "NEWLINE" }; public static final int RULE_init = 0, RULE_selectors = 1, RULE_selector = 2, RULE_attribute = 3, - RULE_operator = 4, RULE_statement = 5, RULE_baseStatement = 6; + RULE_operator = 4, RULE_statement = 5; public static final String[] ruleNames = { - "init", "selectors", "selector", "attribute", "operator", "statement", - "baseStatement" + "init", "selectors", "selector", "attribute", "operator", "statement" }; @Override @@ -39,9 +34,6 @@ public class SelectorParser extends Parser { @Override public String[] getRuleNames() { return ruleNames; } - @Override - public String getSerializedATN() { return _serializedATN; } - @Override public ATN getATN() { return _ATN; } @@ -78,7 +70,9 @@ public final InitContext init() throws RecognitionException { try { enterOuterAlt(_localctx, 1); { - setState(14); selectors(); + setState(12); match(4); + setState(13); selectors(); + setState(14); match(1); } } catch (RecognitionException re) { @@ -125,7 +119,7 @@ public final SelectorsContext selectors() throws RecognitionException { try { enterOuterAlt(_localctx, 1); { - setState(16); selector(0); + setState(16); selector(); setState(21); _errHandler.sync(this); _la = _input.LA(1); @@ -133,7 +127,7 @@ public final SelectorsContext selectors() throws RecognitionException { { { setState(17); match(3); - setState(18); selector(0); + setState(18); selector(); } } setState(23); @@ -157,14 +151,11 @@ public static class SelectorContext extends ParserRuleContext { public StatementContext statement() { return getRuleContext(StatementContext.class,0); } - public SelectorContext selector(int i) { - return getRuleContext(SelectorContext.class,i); - } public OperatorContext operator() { return getRuleContext(OperatorContext.class,0); } - public List selector() { - return getRuleContexts(SelectorContext.class); + public SelectorContext selector() { + return getRuleContext(SelectorContext.class,0); } public SelectorContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); @@ -186,46 +177,26 @@ public T accept(ParseTreeVisitor visitor) { } public final SelectorContext selector() throws RecognitionException { - return selector(0); - } - - private SelectorContext selector(int _p) throws RecognitionException { - ParserRuleContext _parentctx = _ctx; - int _parentState = getState(); - SelectorContext _localctx = new SelectorContext(_ctx, _parentState); - SelectorContext _prevctx = _localctx; - int _startState = 4; - enterRecursionRule(_localctx, 4, RULE_selector, _p); + SelectorContext _localctx = new SelectorContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_selector); try { - int _alt; - enterOuterAlt(_localctx, 1); - { - { - setState(25); statement(); - } - _ctx.stop = _input.LT(-1); - setState(33); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,1,_ctx); - while ( _alt!=2 && _alt!=-1 ) { - if ( _alt==1 ) { - if ( _parseListeners!=null ) triggerExitRuleEvent(); - _prevctx = _localctx; - { - { - _localctx = new SelectorContext(_parentctx, _parentState); - pushNewRecursionContext(_localctx, _startState, RULE_selector); - setState(27); - if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)"); - setState(28); operator(); - setState(29); selector(0); - } - } + setState(29); + switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(24); statement(); } - setState(35); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,1,_ctx); - } + break; + + case 2: + enterOuterAlt(_localctx, 2); + { + setState(25); statement(); + setState(26); operator(); + setState(27); selector(); + } + break; } } catch (RecognitionException re) { @@ -234,12 +205,14 @@ private SelectorContext selector(int _p) throws RecognitionException { _errHandler.recover(this, re); } finally { - unrollRecursionContexts(_parentctx); + exitRule(); } return _localctx; } public static class AttributeContext extends ParserRuleContext { + public Token Property; + public Token Value; public List ID() { return getTokens(SelectorParser.ID); } public TerminalNode ID(int i) { return getToken(SelectorParser.ID, i); @@ -269,11 +242,11 @@ public final AttributeContext attribute() throws RecognitionException { try { enterOuterAlt(_localctx, 1); { - setState(36); match(5); - setState(37); match(ID); - setState(38); match(6); - setState(39); match(ID); - setState(40); match(1); + setState(31); match(4); + setState(32); ((AttributeContext)_localctx).Property = match(ID); + setState(33); match(5); + setState(34); ((AttributeContext)_localctx).Value = match(ID); + setState(35); match(1); } } catch (RecognitionException re) { @@ -310,16 +283,10 @@ public T accept(ParseTreeVisitor visitor) { public final OperatorContext operator() throws RecognitionException { OperatorContext _localctx = new OperatorContext(_ctx, getState()); enterRule(_localctx, 8, RULE_operator); - int _la; try { enterOuterAlt(_localctx, 1); { - setState(42); - _la = _input.LA(1); - if ( !(_la==2 || _la==4) ) { - _errHandler.recoverInline(this); - } - consume(); + setState(37); match(2); } } catch (RecognitionException re) { @@ -334,15 +301,15 @@ public final OperatorContext operator() throws RecognitionException { } public static class StatementContext extends ParserRuleContext { + public Token Selector; + public AttributeContext Attributes; public List attribute() { return getRuleContexts(AttributeContext.class); } + public TerminalNode ID() { return getToken(SelectorParser.ID, 0); } public AttributeContext attribute(int i) { return getRuleContext(AttributeContext.class,i); } - public BaseStatementContext baseStatement() { - return getRuleContext(BaseStatementContext.class,0); - } public StatementContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); } @@ -365,138 +332,24 @@ public T accept(ParseTreeVisitor visitor) { public final StatementContext statement() throws RecognitionException { StatementContext _localctx = new StatementContext(_ctx, getState()); enterRule(_localctx, 10, RULE_statement); + int _la; try { - int _alt; enterOuterAlt(_localctx, 1); { - setState(44); baseStatement(); - setState(48); + setState(39); ((StatementContext)_localctx).Selector = match(ID); + setState(43); _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,2,_ctx); - while ( _alt!=2 && _alt!=-1 ) { - if ( _alt==1 ) { - { - { - setState(45); attribute(); - } - } - } - setState(50); - _errHandler.sync(this); - _alt = getInterpreter().adaptivePredict(_input,2,_ctx); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class BaseStatementContext extends ParserRuleContext { - public Token Statement; - public TerminalNode ELSE_STATEMENT() { return getToken(SelectorParser.ELSE_STATEMENT, 0); } - public TerminalNode WHILE() { return getToken(SelectorParser.WHILE, 0); } - public TerminalNode BODY() { return getToken(SelectorParser.BODY, 0); } - public TerminalNode IF() { return getToken(SelectorParser.IF, 0); } - public TerminalNode ALL() { return getToken(SelectorParser.ALL, 0); } - public TerminalNode VARIABLE() { return getToken(SelectorParser.VARIABLE, 0); } - public TerminalNode EXPRESSION() { return getToken(SelectorParser.EXPRESSION, 0); } - public TerminalNode FUNCTION() { return getToken(SelectorParser.FUNCTION, 0); } - public TerminalNode TRUE_STATEMENT() { return getToken(SelectorParser.TRUE_STATEMENT, 0); } - public TerminalNode FOREACH() { return getToken(SelectorParser.FOREACH, 0); } - public BaseStatementContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_baseStatement; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof SelectorListener ) ((SelectorListener)listener).enterBaseStatement(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof SelectorListener ) ((SelectorListener)listener).exitBaseStatement(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof SelectorVisitor ) return ((SelectorVisitor)visitor).visitBaseStatement(this); - else return visitor.visitChildren(this); - } - } - - public final BaseStatementContext baseStatement() throws RecognitionException { - BaseStatementContext _localctx = new BaseStatementContext(_ctx, getState()); - enterRule(_localctx, 12, RULE_baseStatement); - try { - setState(61); - switch (_input.LA(1)) { - case WHILE: - enterOuterAlt(_localctx, 1); - { - setState(51); ((BaseStatementContext)_localctx).Statement = match(WHILE); - } - break; - case FOREACH: - enterOuterAlt(_localctx, 2); - { - setState(52); ((BaseStatementContext)_localctx).Statement = match(FOREACH); - } - break; - case FUNCTION: - enterOuterAlt(_localctx, 3); - { - setState(53); ((BaseStatementContext)_localctx).Statement = match(FUNCTION); - } - break; - case IF: - enterOuterAlt(_localctx, 4); - { - setState(54); ((BaseStatementContext)_localctx).Statement = match(IF); - } - break; - case TRUE_STATEMENT: - enterOuterAlt(_localctx, 5); - { - setState(55); ((BaseStatementContext)_localctx).Statement = match(TRUE_STATEMENT); - } - break; - case ELSE_STATEMENT: - enterOuterAlt(_localctx, 6); - { - setState(56); ((BaseStatementContext)_localctx).Statement = match(ELSE_STATEMENT); - } - break; - case BODY: - enterOuterAlt(_localctx, 7); - { - setState(57); ((BaseStatementContext)_localctx).Statement = match(BODY); - } - break; - case EXPRESSION: - enterOuterAlt(_localctx, 8); + _la = _input.LA(1); + while (_la==4) { { - setState(58); ((BaseStatementContext)_localctx).Statement = match(EXPRESSION); - } - break; - case VARIABLE: - enterOuterAlt(_localctx, 9); { - setState(59); ((BaseStatementContext)_localctx).Statement = match(VARIABLE); + setState(40); ((StatementContext)_localctx).Attributes = attribute(); } - break; - case ALL: - enterOuterAlt(_localctx, 10); - { - setState(60); ((BaseStatementContext)_localctx).Statement = match(ALL); } - break; - default: - throw new NoViableAltException(this); + setState(45); + _errHandler.sync(this); + _la = _input.LA(1); + } } } catch (RecognitionException re) { @@ -510,40 +363,21 @@ public final BaseStatementContext baseStatement() throws RecognitionException { return _localctx; } - public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { - switch (ruleIndex) { - case 2: return selector_sempred((SelectorContext)_localctx, predIndex); - } - return true; - } - private boolean selector_sempred(SelectorContext _localctx, int predIndex) { - switch (predIndex) { - case 0: return precpred(_ctx, 1); - } - return true; - } - public static final String _serializedATN = - "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\26B\4\2\t\2\4\3\t"+ - "\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\3\2\3\2\3\3\3\3\3\3\7\3\26"+ - "\n\3\f\3\16\3\31\13\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\7\4\"\n\4\f\4\16\4%"+ - "\13\4\3\5\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\7\3\7\7\7\61\n\7\f\7\16\7\64\13"+ - "\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\5\b@\n\b\3\b\2\3\6\t\2\4\6"+ - "\b\n\f\16\2\3\4\2\4\4\6\6F\2\20\3\2\2\2\4\22\3\2\2\2\6\32\3\2\2\2\b&\3"+ - "\2\2\2\n,\3\2\2\2\f.\3\2\2\2\16?\3\2\2\2\20\21\5\4\3\2\21\3\3\2\2\2\22"+ - "\27\5\6\4\2\23\24\7\5\2\2\24\26\5\6\4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+ + "\2\2\16\17\7\6\2\2\17\20\5\4\3\2\20\21\7\3\2\2\21\3\3\2\2\2\22\27\5\6"+ + "\4\2\23\24\7\5\2\2\24\26\5\6\4\2\25\23\3\2\2\2\26\31\3\2\2\2\27\25\3\2"+ + "\2\2\27\30\3\2\2\2\30\5\3\2\2\2\31\27\3\2\2\2\32 \5\f\7\2\33\34\5\f\7"+ + "\2\34\35\5\n\6\2\35\36\5\6\4\2\36 \3\2\2\2\37\32\3\2\2\2\37\33\3\2\2\2"+ + " \7\3\2\2\2!\"\7\6\2\2\"#\7\b\2\2#$\7\7\2\2$%\7\b\2\2%&\7\3\2\2&\t\3\2"+ + "\2\2\'(\7\4\2\2(\13\3\2\2\2)-\7\b\2\2*,\5\b\5\2+*\3\2\2\2,/\3\2\2\2-+"+ + "\3\2\2\2-.\3\2\2\2.\r\3\2\2\2/-\3\2\2\2\5\27\37-"; public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + ATNSimulator.deserialize(_serializedATN.toCharArray()); static { _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { diff --git a/grammar-selector/src/SelectorVisitor.class b/grammar-selector/src/SelectorVisitor.class index 81f65f4..317c7c4 100644 Binary files a/grammar-selector/src/SelectorVisitor.class and b/grammar-selector/src/SelectorVisitor.class differ diff --git a/grammar-selector/src/SelectorVisitor.java b/grammar-selector/src/SelectorVisitor.java index 2327df9..49df775 100644 --- a/grammar-selector/src/SelectorVisitor.java +++ b/grammar-selector/src/SelectorVisitor.java @@ -1,4 +1,4 @@ -// Generated from ../Selector.g4 by ANTLR 4.2 +// Generated from ../Selector.g4 by ANTLR 4.1 import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.tree.ParseTreeVisitor; @@ -31,13 +31,6 @@ public interface SelectorVisitor extends ParseTreeVisitor { */ T visitSelectors(@NotNull SelectorParser.SelectorsContext ctx); - /** - * Visit a parse tree produced by {@link SelectorParser#baseStatement}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitBaseStatement(@NotNull SelectorParser.BaseStatementContext ctx); - /** * Visit a parse tree produced by {@link SelectorParser#attribute}. * @param ctx the parse tree diff --git a/grammar-selector/src/TreeSelectorLexer.class b/grammar-selector/src/TreeSelectorLexer.class new file mode 100644 index 0000000..9a6963f Binary files /dev/null and b/grammar-selector/src/TreeSelectorLexer.class differ diff --git a/grammar-selector/src/TreeSelectorLexer.java b/grammar-selector/src/TreeSelectorLexer.java new file mode 100644 index 0000000..9a19ab5 --- /dev/null +++ b/grammar-selector/src/TreeSelectorLexer.java @@ -0,0 +1,128 @@ +// Generated from ../Selector.g4 by ANTLR 4.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"}) +public class TreeSelectorLexer extends Lexer { + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + T__4=1, T__3=2, T__2=3, T__1=4, T__0=5, WHILE=6, FOREACH=7, FUNCTION=8, + SEQUENCE=9, IF=10, BODY=11, EXPRESSION=12, VARIABLE=13, DECLARATION=14, + ALL=15, ID=16, WHITESPACE=17, NEWLINE=18; + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + public static final String[] tokenNames = { + "", + "']'", "'>'", "','", "'['", "'='", "'while'", "'foreach'", "'function'", + "'sequence'", "'if'", "'body'", "'expression'", "'variable'", "'declaration'", + "'*'", "ID", "WHITESPACE", "NEWLINE" + }; + public static final String[] ruleNames = { + "T__4", "T__3", "T__2", "T__1", "T__0", "WHILE", "FOREACH", "FUNCTION", + "SEQUENCE", "IF", "BODY", "EXPRESSION", "VARIABLE", "DECLARATION", "ALL", + "ID", "LETTER", "WHITESPACE", "NEWLINE" + }; + + + public TreeSelectorLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "Selector.g4"; } + + @Override + public String[] getTokenNames() { return tokenNames; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + @Override + public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { + switch (ruleIndex) { + case 17: WHITESPACE_action((RuleContext)_localctx, actionIndex); break; + + case 18: NEWLINE_action((RuleContext)_localctx, actionIndex); break; + } + } + private void WHITESPACE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 0: skip(); break; + } + } + private void NEWLINE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 1: skip(); break; + } + } + + public static final String _serializedATN = + "\3\uacf5\uee8c\u4f5d\u8b0d\u4a45\u78bd\u1b2f\u3378\2\24\u009b\b\1\4\2"+ + "\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4"+ + "\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+ + "\t\22\4\23\t\23\4\24\t\24\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7"+ + "\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3"+ + "\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13"+ + "\3\f\3\f\3\f\3\f\3\f\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\16"+ + "\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3\17\3\17"+ + "\3\17\3\17\3\17\3\17\3\17\3\17\3\20\3\20\3\21\5\21\177\n\21\3\21\3\21"+ + "\5\21\u0083\n\21\3\21\3\21\7\21\u0087\n\21\f\21\16\21\u008a\13\21\3\22"+ + "\3\22\3\23\6\23\u008f\n\23\r\23\16\23\u0090\3\23\3\23\3\24\5\24\u0096"+ + "\n\24\3\24\3\24\3\24\3\24\2\25\3\3\1\5\4\1\7\5\1\t\6\1\13\7\1\r\b\1\17"+ + "\t\1\21\n\1\23\13\1\25\f\1\27\r\1\31\16\1\33\17\1\35\20\1\37\21\1!\22"+ + "\1#\2\1%\23\2\'\24\3\3\2\5\5\2//\62;aa\4\2C\\c|\4\2\13\13\"\"\u009f\2"+ + "\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2"+ + "\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2"+ + "\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2\2%\3\2\2"+ + "\2\2\'\3\2\2\2\3)\3\2\2\2\5+\3\2\2\2\7-\3\2\2\2\t/\3\2\2\2\13\61\3\2\2"+ + "\2\r\63\3\2\2\2\179\3\2\2\2\21A\3\2\2\2\23J\3\2\2\2\25S\3\2\2\2\27V\3"+ + "\2\2\2\31[\3\2\2\2\33f\3\2\2\2\35o\3\2\2\2\37{\3\2\2\2!~\3\2\2\2#\u008b"+ + "\3\2\2\2%\u008e\3\2\2\2\'\u0095\3\2\2\2)*\7_\2\2*\4\3\2\2\2+,\7@\2\2,"+ + "\6\3\2\2\2-.\7.\2\2.\b\3\2\2\2/\60\7]\2\2\60\n\3\2\2\2\61\62\7?\2\2\62"+ + "\f\3\2\2\2\63\64\7y\2\2\64\65\7j\2\2\65\66\7k\2\2\66\67\7n\2\2\678\7g"+ + "\2\28\16\3\2\2\29:\7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\2\u008f\u0090\3\2\2\2\u0090\u008e\3\2\2\2\u0090\u0091\3\2"+ + "\2\2\u0091\u0092\3\2\2\2\u0092\u0093\b\23\2\2\u0093&\3\2\2\2\u0094\u0096"+ + "\7\17\2\2\u0095\u0094\3\2\2\2\u0095\u0096\3\2\2\2\u0096\u0097\3\2\2\2"+ + "\u0097\u0098\7\f\2\2\u0098\u0099\3\2\2\2\u0099\u009a\b\24\3\2\u009a(\3"+ + "\2\2\2\t\2~\u0082\u0086\u0088\u0090\u0095"; + public static final ATN _ATN = + ATNSimulator.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); + } + } +} \ No newline at end of file diff --git a/grammar-selector/src/TreeSelectorLexer.tokens b/grammar-selector/src/TreeSelectorLexer.tokens new file mode 100644 index 0000000..58f6185 --- /dev/null +++ b/grammar-selector/src/TreeSelectorLexer.tokens @@ -0,0 +1,33 @@ +FUNCTION=8 +SEQUENCE=9 +NEWLINE=18 +VARIABLE=13 +WHILE=6 +T__1=4 +ALL=15 +T__0=5 +T__3=2 +T__2=3 +WHITESPACE=17 +FOREACH=7 +BODY=11 +ID=16 +DECLARATION=14 +EXPRESSION=12 +IF=10 +T__4=1 +'foreach'=7 +'>'=2 +'expression'=12 +'='=5 +'if'=10 +'*'=15 +'['=4 +'while'=6 +'body'=11 +','=3 +'function'=8 +'variable'=13 +'declaration'=14 +']'=1 +'sequence'=9 diff --git a/project/MetaCode/MetaCode.Compiler.Tests/MetaCode.Compiler.Tests.csproj b/project/MetaCode/MetaCode.Compiler.Tests/MetaCode.Compiler.Tests.csproj index add23a6..665fcf1 100644 --- a/project/MetaCode/MetaCode.Compiler.Tests/MetaCode.Compiler.Tests.csproj +++ b/project/MetaCode/MetaCode.Compiler.Tests/MetaCode.Compiler.Tests.csproj @@ -53,6 +53,7 @@ + diff --git a/project/MetaCode/MetaCode.Compiler.Tests/TreeSelectorTestFixture.cs b/project/MetaCode/MetaCode.Compiler.Tests/TreeSelectorTestFixture.cs new file mode 100644 index 0000000..1646224 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler.Tests/TreeSelectorTestFixture.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.Services; +using MetaCode.Compiler.Visitors; +using NUnit.Framework; + +namespace MetaCode.Compiler.Tests +{ + [TestFixture] + public class TreeSelectorTestFixture + { + private Node ParseWithAbstractTreeVisitor(MetaCodeCompiler compiler, string source) + { + return compiler.ParseWithVisitor(source, () => new AbstractTreeVisitor(CompilerService.Instance)); + } + + public MetaCodeCompiler Compiler { get; set; } + + [SetUp] + public void Setup() + { + Compiler = new MetaCodeCompiler(); + } + + [Test] + public void StatementTest() + { + // GIVEN + var underTest = new TreeSelectorCompiler(); + var selectorDefinition = @" + [ * > if > sequence > variable[name = c] + while[condition] > *] + "; + + var source = @" + if (not ((50 + 4) > 10)) + var c : number = a * a; + while (true) do + var d : number = a * a; + skip; + end; + writeline(false); + skip; + else + writeline(10 + a); + end; + "; + + // WHEN + var selectors = underTest.Parse(selectorDefinition); + var tree = ParseWithAbstractTreeVisitor(Compiler, source); + + foreach (var selector in selectors) + { + var result = selector.SelectNode(tree); + } + + // THEN + Assert.AreEqual(1, selectors.Count()); + } + } +} diff --git a/project/MetaCode/MetaCode.Compiler.Tests/TypeDeclarationAnalyzerTestFixture.cs b/project/MetaCode/MetaCode.Compiler.Tests/TypeDeclarationAnalyzerTestFixture.cs index ab2bf48..c769d55 100644 --- a/project/MetaCode/MetaCode.Compiler.Tests/TypeDeclarationAnalyzerTestFixture.cs +++ b/project/MetaCode/MetaCode.Compiler.Tests/TypeDeclarationAnalyzerTestFixture.cs @@ -60,37 +60,23 @@ public void MacroDeclarationTest() { // GIVEN var source = @" - implicit macro inline(tree: { if > body }, tree2: { * }) do - writeline('Hello World!'); - var a : array = [1, 2, 3, 4]; - - foreach (var value : number in [12 + 8, 3, 4, 5]) do - writeline(value); + implicit macro inline(tree: { * > if }) do + foreach (var t : any in tree) do + writeline(find(t, '{ if[condition] }')); end; + end; - var index : number = 0; - writeline('Testing while statement ...'); - - while (index < 5) - writeline(index = index + 1); - - writeline('done'); - - macro replace( - __value__ = 'tree', - if (__value__ == null) - error('Hello World!'); - end - ); + if (24 > 42) + skip; + end; - /*if (not ((50 + 4) > 10)) - var c : number = a * a; - writeline(false); - skip; - else - writeline(10 + a); - end;*/ + if (24 > 42) + skip; end; + + if (24 > 42) + skip; + end; "; var compilerService = new CompilerService(); diff --git a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.dll b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.dll index 59ff86f..24ad3bc 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.dll and b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.dll differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.pdb b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.pdb index eae6dad..7d60220 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.pdb and b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.Tests.pdb differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.dll b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.dll index 90302e6..5e50db8 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.dll and b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.dll differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.pdb b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.pdb index a844c48..26a4ca0 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.pdb and b/project/MetaCode/MetaCode.Compiler.Tests/bin/Debug/MetaCode.Compiler.pdb differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache index d94f665..4d64c8c 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache and b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.dll b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.dll index 59ff86f..24ad3bc 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.dll and b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.dll differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.pdb b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.pdb index eae6dad..7d60220 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.pdb and b/project/MetaCode/MetaCode.Compiler.Tests/obj/Debug/MetaCode.Compiler.Tests.pdb differ diff --git a/project/MetaCode/MetaCode.Compiler.Tests/obj/Release/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache b/project/MetaCode/MetaCode.Compiler.Tests/obj/Release/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache index c80423c..f634dc5 100644 Binary files a/project/MetaCode/MetaCode.Compiler.Tests/obj/Release/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache and b/project/MetaCode/MetaCode.Compiler.Tests/obj/Release/MetaCode.Compiler.Tests.csprojResolveAssemblyReference.cache differ diff --git a/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/CallExpressionNodeBase.cs b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/CallExpressionNodeBase.cs index 65b3b20..c071ef4 100644 --- a/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/CallExpressionNodeBase.cs +++ b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/CallExpressionNodeBase.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using MetaCode.Compiler.AbstractSyntaxTree.Statements; using MetaCode.Core; namespace MetaCode.Compiler.AbstractSyntaxTree.Expressions @@ -26,12 +25,4 @@ protected CallExpressionNodeBase(string name, IEnumerable actualParameter public IEnumerable ActualParameters { get; internal set; } public IdentifierExpressionNode FunctionName { get; set; } } - - public class MacroCallExpressionNode : CallExpressionNodeBase - { - public MacroCallExpressionNode(string name, IEnumerable actualParameters) - : base(name, actualParameters) - { - } - } } \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/MacroCallExpressionNode.cs b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/MacroCallExpressionNode.cs new file mode 100644 index 0000000..3035dca --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Expressions/MacroCallExpressionNode.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.AbstractSyntaxTree.Expressions +{ + public class MacroCallExpressionNode : CallExpressionNodeBase + { + public MacroCallExpressionNode(string name, IEnumerable actualParameters) + : base(name, actualParameters) + { + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Visitors/MacroInterpreter.cs b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Visitors/MacroInterpreter.cs index 6ffefd6..e6ffd61 100644 --- a/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Visitors/MacroInterpreter.cs +++ b/project/MetaCode/MetaCode.Compiler/AbstractSyntaxTree/Visitors/MacroInterpreter.cs @@ -16,6 +16,7 @@ using MetaCode.Compiler.Helpers; using MetaCode.Compiler.Interpreter; using MetaCode.Compiler.Services; +using MetaCode.Compiler.Visitors; using MetaCode.Core; namespace MetaCode.Compiler.AbstractSyntaxTree.Visitors @@ -29,6 +30,8 @@ public class MacroInterpreter : TreeVisitorBase private bool _isInInterpreterMode; + private CompilationUnit _root; + public MacroInterpreter(CompilerService compilerService) { if (compilerService == null) @@ -41,6 +44,51 @@ public MacroInterpreter(CompilerService compilerService) _interpreterContext = new InterpreterContext(compilerService); Initialize(); + InitializeNativeFunctions(); + } + + private void InitializeNativeFunctions() + { + _interpreterContext.DeclareNativeFunction("toSyntaxTree", new Func(value => + { + var compiler = new MetaCodeCompiler(); + return compiler.ParseWithVisitor(value.ToString(), () => new AbstractTreeVisitor(CompilerService.Instance)); + })); + + _interpreterContext.DeclareNativeFunction("find", new Func((tree, filter) => + { + if (!(tree is Node) && !(tree is string)) + throw new Exception("The first parameter must be a node or string!"); + + if (!filter.Is()) + throw new Exception("The second parameter must be a string!"); + + var treeSelectorCompiler = new TreeSelectorCompiler(); + var selectors = treeSelectorCompiler.Parse(filter.ToString()); + var result = new List(); + + foreach (var selector in selectors) + { + if (tree is Node) + result.AddRange(selector.SelectNode(tree.As())); + else + { + var compiler = new MetaCodeCompiler(); + var node = compiler.ParseWithVisitor( + tree.ToString(), + () => new AbstractTreeVisitor(CompilerService.Instance)); + + result.AddRange(selector.SelectNode(node)); + } + } + + return result; + })); + + _interpreterContext.DeclareNativeMacroFunction("replace", args => + { + return args.First(); + }); } private void Initialize() @@ -48,6 +96,8 @@ private void Initialize() this. DefaultVisitor((visitor, node) => { + node.Is(unit => _root = unit); + foreach (var child in node.Children) visitor.VisitChild(child); return this; @@ -55,6 +105,20 @@ private void Initialize() .If((visitor, node) => { _isInInterpreterMode = true; + + var treeSelector = new TreeSelectorCompiler(); + + foreach (var parameter in node.FormalParameters) + { + var selectors = treeSelector.Parse(parameter.Selector); + var value = new List(); + + foreach (var selector in selectors) + value.AddRange(selector.SelectNode(_root)); + + _interpreterContext.DeclareVariable(parameter.Name, value); + } + foreach (var child in node.Children) visitor.VisitChild(child); _isInInterpreterMode = false; @@ -260,6 +324,17 @@ private void Initialize() return this; }) + .If((visitor, node) => + { + if (!_isInInterpreterMode) + return this; + + var name = node.FunctionName.Name; + var result = _interpreterContext.InvokeMacroFunction(name, node.ActualParameters); + _expressionStack.Push(result); + + return this; + }) .If((visitor, node) => { if (!_isInInterpreterMode) @@ -269,7 +344,7 @@ private void Initialize() foreach (var param in node.ActualParameters) visitor.VisitChild(param); - List parameters = new List(); + var parameters = new List(); for (int i = 0; i < node.ActualParameters.Count(); i++) parameters.Add(_expressionStack.Pop()); diff --git a/project/MetaCode/MetaCode.Compiler/Grammar/TreeSelector.g4 b/project/MetaCode/MetaCode.Compiler/Grammar/TreeSelector.g4 index 1042c18..f932494 100644 --- a/project/MetaCode/MetaCode.Compiler/Grammar/TreeSelector.g4 +++ b/project/MetaCode/MetaCode.Compiler/Grammar/TreeSelector.g4 @@ -1,52 +1,26 @@ grammar TreeSelector; -init : '[' selectors ']' +init : '{' selectors '}' ; selectors : selector (',' selector)* ; -selector : statement - | selector operator selector +selector : Parent=statement (Operator=OPERATOR? Child=selector)? ; -attribute : '[' ID '=' ID ']' +attribute : '[' Property=ID ('=' Value=ID)? ']' ; -operator : '>' +OPERATOR : '>' | '+' ; -statement : baseStatement attribute* +statement : Selector=ID Attributes=attribute* ; -baseStatement : Statement=WHILE - | Statement=FOREACH - | Statement=FUNCTION - | Statement=IF - | Statement=TRUE_STATEMENT - | Statement=ELSE_STATEMENT - | Statement=BODY - | Statement=EXPRESSION - | Statement=VARIABLE - | Statement=ALL - ; - - -WHILE : 'while'; -FOREACH : 'foreach'; -FUNCTION : 'function'; -IF : 'if'; -TRUE_STATEMENT : 'else-if'; -ELSE_STATEMENT : 'else'; -BODY : 'body'; -EXPRESSION : 'expression'; -VARIABLE : 'variable'; -DECLARATION : 'declaration'; -ALL : '*'; - -ID : '@'? (LETTER|'_') (LETTER|'_'|'-'|[0-9])*; +ID : ('@'? (LETTER|'_') (LETTER|'_'|'-'|[0-9])*) | '*'; fragment LETTER : [a-zA-Z]; diff --git a/project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContext.cs b/project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContextBase.cs similarity index 78% rename from project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContext.cs rename to project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContextBase.cs index a2baa13..b3ad599 100644 --- a/project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContext.cs +++ b/project/MetaCode/MetaCode.Compiler/Interpreter/FunctionContextBase.cs @@ -2,11 +2,11 @@ namespace MetaCode.Compiler.Interpreter { - public abstract class FunctionContext + public abstract class FunctionContextBase { public string Name { get; protected set; } - protected FunctionContext(string name) + protected FunctionContextBase(string name) { if (string.IsNullOrWhiteSpace(name)) ThrowHelper.ThrowException("The 'name' is blank!"); diff --git a/project/MetaCode/MetaCode.Compiler/Interpreter/InterpreterContext.cs b/project/MetaCode/MetaCode.Compiler/Interpreter/InterpreterContext.cs index e7ad170..9e6d05a 100644 --- a/project/MetaCode/MetaCode.Compiler/Interpreter/InterpreterContext.cs +++ b/project/MetaCode/MetaCode.Compiler/Interpreter/InterpreterContext.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using MetaCode.Compiler.AbstractSyntaxTree; using MetaCode.Compiler.Services; using MetaCode.Core; @@ -13,7 +14,8 @@ public class InterpreterContext public CompilerService CompilerService { get; protected set; } private readonly Stack> _variables; - private readonly Stack> _functions; + private readonly Stack> _functions; + private readonly Stack> _macros; public InterpreterContext(CompilerService compilerService) { @@ -22,7 +24,8 @@ public InterpreterContext(CompilerService compilerService) CompilerService = compilerService; _variables = new Stack>(); - _functions = new Stack>(); + _functions = new Stack>(); + _macros = new Stack>(); InitializeFunctions(); @@ -32,7 +35,7 @@ public InterpreterContext(CompilerService compilerService) private InterpreterContext InitializeFunctions() { _functions.Clear(); - _functions.Push(new Dictionary() + _functions.Push(new Dictionary() { {"write", new NativeFunctionContext("write", new Action(Console.Write))}, {"writeline", new NativeFunctionContext("writeline", new Action(Console.WriteLine))} @@ -44,7 +47,8 @@ private InterpreterContext InitializeFunctions() public InterpreterContext PushBlock() { _variables.Push(new Dictionary()); - _functions.Push(new Dictionary()); + _functions.Push(new Dictionary()); + _macros.Push(new Dictionary()); return this; } @@ -52,17 +56,34 @@ public InterpreterContext PopBlock() { _variables.Pop(); _functions.Pop(); + _macros.Pop(); return this; } - private FunctionContext GetFunction(string name) + private MacroContextBase GetMacroFunction(string name) + { + if (string.IsNullOrWhiteSpace(name)) + ThrowHelper.ThrowException("The 'name' is blank!"); + + foreach (var block in _macros.Reverse()) + { + MacroContextBase result; + + if (block.TryGetValue(name, out result)) + return result; + } + + throw new Exception(string.Format("Macro ({0}) not found!", name)); + } + + private FunctionContextBase GetFunction(string name) { if (string.IsNullOrWhiteSpace(name)) ThrowHelper.ThrowException("The 'name' is blank!"); foreach (var block in _functions.Reverse()) { - FunctionContext result; + FunctionContextBase result; if (block.TryGetValue(name, out result)) return result; @@ -101,6 +122,20 @@ public InterpreterContext DeclareNativeFunction(string name, Delegate function) return this; } + public InterpreterContext DeclareNativeMacroFunction(string name, Func function) + { + if (string.IsNullOrWhiteSpace(name)) + ThrowHelper.ThrowException("The 'name' is blank!"); + + if (function == null) + ThrowHelper.ThrowArgumentNullException(() => function); + + _macros.First() + .Add(name, new NativeMacroContext(name, function)); + + return this; + } + public object InvokeFunction(string name, IEnumerable args) { if (string.IsNullOrWhiteSpace(name)) @@ -110,6 +145,15 @@ public object InvokeFunction(string name, IEnumerable args) return function.Invoke(args.ToArray()); } + public object InvokeMacroFunction(string name, IEnumerable args) + { + if (string.IsNullOrWhiteSpace(name)) + ThrowHelper.ThrowException("The 'name' is blank!"); + + var macro = GetMacroFunction(name); + return macro.Invoke(args.ToArray()); + } + public object GetValueOfVariable(string name) { if (string.IsNullOrWhiteSpace(name)) diff --git a/project/MetaCode/MetaCode.Compiler/Interpreter/MacroContextBase.cs b/project/MetaCode/MetaCode.Compiler/Interpreter/MacroContextBase.cs new file mode 100644 index 0000000..f725f2d --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Interpreter/MacroContextBase.cs @@ -0,0 +1,38 @@ +using System; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Core; + +namespace MetaCode.Compiler.Interpreter +{ + public abstract class MacroContextBase + { + public string Name { get; protected set; } + + public MacroContextBase(string name) + { + if (string.IsNullOrWhiteSpace(name)) + ThrowHelper.ThrowException("The 'name' is blank!"); + + Name = name; + } + + public abstract object Invoke(Node[] parameters); + } + + public class NativeMacroContext : MacroContextBase + { + public Func MacroFunction { get; set; } + + public NativeMacroContext(string name, Func macroFunction) : base(name) + { + if (macroFunction == null) + ThrowHelper.ThrowArgumentNullException(() => macroFunction); + MacroFunction = macroFunction; + } + + public override object Invoke(Node[] parameters) + { + return MacroFunction(parameters); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Interpreter/NativeFunctionContext.cs b/project/MetaCode/MetaCode.Compiler/Interpreter/NativeFunctionContext.cs index b2a3779..6405772 100644 --- a/project/MetaCode/MetaCode.Compiler/Interpreter/NativeFunctionContext.cs +++ b/project/MetaCode/MetaCode.Compiler/Interpreter/NativeFunctionContext.cs @@ -3,7 +3,7 @@ namespace MetaCode.Compiler.Interpreter { - public class NativeFunctionContext : FunctionContext + public class NativeFunctionContext : FunctionContextBase { public Delegate Function { get; protected set; } diff --git a/project/MetaCode/MetaCode.Compiler/MetaCode.Compiler.csproj b/project/MetaCode/MetaCode.Compiler/MetaCode.Compiler.csproj index 53e230c..2531007 100644 --- a/project/MetaCode/MetaCode.Compiler/MetaCode.Compiler.csproj +++ b/project/MetaCode/MetaCode.Compiler/MetaCode.Compiler.csproj @@ -55,6 +55,7 @@ + @@ -136,8 +137,9 @@ MetaCode.g4 - + + @@ -162,19 +164,32 @@ + + + + + + - + + + + + + + + - + diff --git a/project/MetaCode/MetaCode.Compiler/MetaCodeCompiler.cs b/project/MetaCode/MetaCode.Compiler/MetaCodeCompiler.cs index cb536fa..ac50ede 100644 --- a/project/MetaCode/MetaCode.Compiler/MetaCodeCompiler.cs +++ b/project/MetaCode/MetaCode.Compiler/MetaCodeCompiler.cs @@ -5,8 +5,8 @@ using System.Threading.Tasks; using Antlr4.Runtime; using MetaCode.Compiler.Grammar; -using MetaCode.Compiler.Visitors; using MetaCode.Core; +using AttributeVisitor = MetaCode.Compiler.Visitors.AttributeVisitor; namespace MetaCode.Compiler { diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/AnySelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/AnySelector.cs new file mode 100644 index 0000000..b4474bd --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/AnySelector.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MetaCode.Compiler.AbstractSyntaxTree; + +namespace MetaCode.Compiler.Selectors +{ + public class AnySelector : NodeSelector + { + protected override bool FilterNode(Node node) + { + return true; + } + } +} diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/BranchingSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/BranchingSelector.cs new file mode 100644 index 0000000..cc330e3 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/BranchingSelector.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class BranchingSelector : NodeSelector + { + protected override Node ModifyNodeSelection(Node node) + { + var branching = node as IfStatementNode; + var result = node; + + TryGetAttribute("condition", attribute => + { + result = branching.ConditionExpression; + }); + + TryGetAttribute("true-statement", attribute => + { + result = branching.TrueStatementNode; + }); + + TryGetAttribute("false-statement", attribute => + { + result = branching.FalseStatementNode; + }); + + return result; + } + + protected override bool FilterNode(Node node) + { + return (node is IfStatementNode); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/DelegateSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/DelegateSelector.cs new file mode 100644 index 0000000..493593b --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/DelegateSelector.cs @@ -0,0 +1,23 @@ +using System; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Core; + +namespace MetaCode.Compiler.Selectors +{ + public class DelegateSelector : NodeSelector + { + public Predicate Filter { get; protected set; } + + public DelegateSelector(Predicate filter) + { + if (filter == null) + ThrowHelper.ThrowArgumentNullException(() => filter); + Filter = filter; + } + + protected override bool FilterNode(Node node) + { + return Filter(node); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/ForeachSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/ForeachSelector.cs new file mode 100644 index 0000000..9f78c50 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/ForeachSelector.cs @@ -0,0 +1,30 @@ +using System; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class ForeachSelector : NodeSelector + { + protected override bool FilterNode(Node node) + { + Func filter = () => node is ForeachLoopStatementNode; + + TryGetAttribute("loop-variable", attribute => + { + var result = filter(); + var loop = node as ForeachLoopStatementNode; + filter = () => result && loop.LoopVariable.Name == attribute.Value; + }); + + TryGetAttribute("loop-variable-type", attribute => + { + var result = filter(); + var loop = node as ForeachLoopStatementNode; + filter = () => result && loop.LoopVariableType.Type == attribute.Value; + }); + + return filter(); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/FunctionCallSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/FunctionCallSelector.cs new file mode 100644 index 0000000..13767a5 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/FunctionCallSelector.cs @@ -0,0 +1,25 @@ +using System; +using System.Linq; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Expressions; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class FunctionCallSelector : NodeSelector + { + protected override bool FilterNode(Node node) + { + Func filter = () => (node is FunctionCallExpressionNode); + + TryGetAttribute("name", attribute => + { + var function = node as FunctionCallExpressionNode; + var result = filter(); + filter = () => result && function.FunctionName.Name == attribute.Value; + }); + + return filter(); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/FunctionDeclarationSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/FunctionDeclarationSelector.cs new file mode 100644 index 0000000..16fb8dd --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/FunctionDeclarationSelector.cs @@ -0,0 +1,23 @@ +using System; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class FunctionDeclarationSelector : NodeSelector + { + protected override bool FilterNode(Node node) + { + Func filter = () => (node is FunctionDeclarationStatementNode); + + TryGetAttribute("name", attribute => + { + var function = node as FunctionDeclarationStatementNode; + var result = filter(); + filter = () => result && function.FunctionName == attribute.Value; + }); + + return filter(); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelector.cs index 324d775..d7b71f2 100644 --- a/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelector.cs +++ b/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelector.cs @@ -1,13 +1,70 @@ using System; +using System.CodeDom; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; +using System.Security.Permissions; using System.Text; using System.Threading.Tasks; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.Selectors.Operators; +using MetaCode.Core; namespace MetaCode.Compiler.Selectors { public abstract class NodeSelector { - public IEnumerable Attributes { get; protected set; } + private List _attributes; + + public IEnumerable Attributes + { + get { return _attributes; } + set { _attributes = (value ?? new List()).ToList(); } + } + + protected bool TryGetAttribute(string name, Action func) + { + if (func == null) + ThrowHelper.ThrowArgumentNullException(() => func); + + var result = _attributes.FirstOrDefault(attribute => attribute.Name == name); + + if (result != null) + func(result); + + return result != null; + } + + protected NodeSelector() + { + _attributes = new List(); + } + + protected abstract bool FilterNode(Node node); + + protected virtual Node ModifyNodeSelection(Node node) + { + return node; + } + + public NodeSelector Child { get; set; } + + public NodeSelectorOperator Operator { get; set; } + + public IEnumerable SelectNode(Node node) + { + if (node == null) + ThrowHelper.ThrowArgumentNullException(() => node); + + if (!FilterNode(node)) + return new Node[0]; + + var modifiedNode = ModifyNodeSelection(node); + + if (Child == null) + return new[] { modifiedNode }; + + return Operator.Iterate(modifiedNode, child => Child.SelectNode(child)); + } } } diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelectorAttribute.cs b/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelectorAttribute.cs index 4ae9f95..861ed08 100644 --- a/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelectorAttribute.cs +++ b/project/MetaCode/MetaCode.Compiler/Selectors/NodeSelectorAttribute.cs @@ -14,7 +14,7 @@ public NodeSelectorAttribute(string name, string value) ThrowHelper.ThrowException("The name is blank!"); if (string.IsNullOrWhiteSpace(value)) - ThrowHelper.ThrowException("The value is blank!"); + value = string.Empty; Name = name; Value = value; diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseChildrenOperator.cs b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseChildrenOperator.cs new file mode 100644 index 0000000..7444db1 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseChildrenOperator.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using MetaCode.Compiler.AbstractSyntaxTree; + +namespace MetaCode.Compiler.Selectors.Operators +{ + public class ChooseChildrenOperator : NodeSelectorOperator + { + public override IEnumerable Iterate(Node node, Func> func) + { + var result = new List(); + + foreach (var child in node.Children) + { + result.AddRange(func(child)); + } + return result; + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseDirectChildOperator.cs b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseDirectChildOperator.cs new file mode 100644 index 0000000..b53fd94 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseDirectChildOperator.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using MetaCode.Compiler.AbstractSyntaxTree; + +namespace MetaCode.Compiler.Selectors.Operators +{ + public class ChooseDirectChildOperator : NodeSelectorOperator + { + public override IEnumerable Iterate(Node node, Func> func) + { + var result = new List(); + + foreach (var child in node.Children) + result.AddRange(func(child)); + + return result; + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseNeighbourOperator.cs b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseNeighbourOperator.cs new file mode 100644 index 0000000..7c9b9ca --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/ChooseNeighbourOperator.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MetaCode.Compiler.AbstractSyntaxTree; + +namespace MetaCode.Compiler.Selectors.Operators +{ + public class ChooseNeighbourOperator : NodeSelectorOperator + { + public override IEnumerable Iterate(Node node, Func> func) + { + var children = node.Parent + .Children + .Where(child => child != node) + .ToArray(); + + var result = new List { node }; + + foreach (var child in children) + result.AddRange(func(child)); + + return result; + } + } + +} diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/Operators/NodeSelectorOperator.cs b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/NodeSelectorOperator.cs new file mode 100644 index 0000000..f67f5c0 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/Operators/NodeSelectorOperator.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using MetaCode.Compiler.AbstractSyntaxTree; + +namespace MetaCode.Compiler.Selectors.Operators +{ + public abstract class NodeSelectorOperator + { + public abstract IEnumerable Iterate(Node node, Func> func); + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/SelectorOperation.cs b/project/MetaCode/MetaCode.Compiler/Selectors/SelectorOperation.cs deleted file mode 100644 index 84e62cb..0000000 --- a/project/MetaCode/MetaCode.Compiler/Selectors/SelectorOperation.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MetaCode.Compiler.Selectors -{ - public abstract class SelectorOperation - { - - } -} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/SequenceSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/SequenceSelector.cs new file mode 100644 index 0000000..8ced92d --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/SequenceSelector.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class SequenceSelector : NodeSelector + { + protected override bool FilterNode(Node node) + { + Func filter = () => (node is BlockStatementNode); + + TryGetAttribute("length", attribute => + { + var block = node as BlockStatementNode; + int value = 0; + if (!int.TryParse(attribute.Value, out value)) + throw new Exception("Invalid value of length property!"); + + filter = () => filter() && block.Children.Count() == value; + }); + + return filter(); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/VariableDeclarationSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/VariableDeclarationSelector.cs new file mode 100644 index 0000000..1a09a8d --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/VariableDeclarationSelector.cs @@ -0,0 +1,55 @@ +using System; +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class VariableDeclarationSelector : NodeSelector + { + protected override Node ModifyNodeSelection(Node node) + { + var variable = node as VariableDeclarationStatementNode; + var result = node; + + TryGetAttribute("identifier", attribute => + { + result = variable.Identifier; + }); + + TryGetAttribute("initial-value", attribute => + { + result = variable.InitialValue; + }); + + TryGetAttribute("type", attribute => + { + result = variable.VariableType; + }); + + return base.ModifyNodeSelection(node); + } + + protected override bool FilterNode(Node node) + { + Func filter = () => (node is VariableDeclarationStatementNode); + + TryGetAttribute("name", attribute => + { + var result = filter(); + filter = () => result && + (node as VariableDeclarationStatementNode).VariableName == attribute.Value; + }); + + TryGetAttribute("type", attribute => + { + var result = filter(); + + filter = + () => result && + (node as VariableDeclarationStatementNode).VariableType.Type == attribute.Value; + }); + + return filter(); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Selectors/WhileSelector.cs b/project/MetaCode/MetaCode.Compiler/Selectors/WhileSelector.cs new file mode 100644 index 0000000..764ace8 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Selectors/WhileSelector.cs @@ -0,0 +1,31 @@ +using MetaCode.Compiler.AbstractSyntaxTree; +using MetaCode.Compiler.AbstractSyntaxTree.Statements; + +namespace MetaCode.Compiler.Selectors +{ + public class WhileSelector : NodeSelector + { + protected override Node ModifyNodeSelection(Node node) + { + var statement = node as WhileLoopStatementNode; + var result = node; + + TryGetAttribute("body", attribute => + { + result = statement.Body; + }); + + TryGetAttribute("condition", attribute => + { + result = statement.Condition; + }); + + return result; + } + + protected override bool FilterNode(Node node) + { + return (node is WhileLoopStatementNode); + } + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/TreeSelectorCompiler.cs b/project/MetaCode/MetaCode.Compiler/TreeSelectorCompiler.cs new file mode 100644 index 0000000..a1c31d3 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/TreeSelectorCompiler.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Antlr4.Runtime; +using MetaCode.Compiler.Grammar; +using MetaCode.Compiler.Selectors; +using MetaCode.Compiler.Visitors.TreeSelector; + +namespace MetaCode.Compiler +{ + public class TreeSelectorCompiler + { + public IEnumerable Parse(string source) + { + var inputStream = new AntlrInputStream(source); + var lexer = new TreeSelectorLexer(inputStream); + var commonTokenStream = new CommonTokenStream(lexer); + var parser = new TreeSelectorParser(commonTokenStream); + var context = parser.init(); + var visitor = new TreeSelectorVisitor(); + return visitor.VisitInit(context); + } + + } +} \ No newline at end of file diff --git a/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelector/NodeSelectorVisitor.cs b/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelector/NodeSelectorVisitor.cs new file mode 100644 index 0000000..73e6888 --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelector/NodeSelectorVisitor.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using MetaCode.Compiler.Commons.Declarations; +using MetaCode.Compiler.Grammar; +using MetaCode.Compiler.Selectors; +using MetaCode.Compiler.Selectors.Operators; + +namespace MetaCode.Compiler.Visitors.TreeSelector +{ + public partial class NodeSelectorVisitor : TreeSelectorBaseVisitor + { + protected AttributeVisitor _AttributeVisitor { get; set; } + + protected readonly Dictionary> _Selectors; + + protected readonly Dictionary> _Operators; + + public NodeSelectorVisitor() + { + _AttributeVisitor = new AttributeVisitor(); + + _Selectors = new Dictionary> + { + { "*", () => new AnySelector() }, + { "if", () => new BranchingSelector() }, + { "foreach", () => new ForeachSelector() }, + { "while", () => new WhileSelector() }, + { "sequence", () => new SequenceSelector() }, + { "variable", () => new VariableDeclarationSelector() }, + { "function", () => new FunctionDeclarationSelector() }, + { "function-call", () => new FunctionCallSelector() }, + }; + + _Operators = new Dictionary> + { + { ">", () => new ChooseDirectChildOperator() }, + { "+", () => new ChooseNeighbourOperator() } + }; + } + + public override NodeSelector VisitSelector(TreeSelectorParser.SelectorContext context) + { + var parent = context.Parent.Accept(this); + + if (context.Operator != null) + { + var op = context.Operator.Text; + Func selectorOperator = null; + if (!_Operators.TryGetValue(op, out selectorOperator)) + throw new Exception("Invalid operator!"); + + parent.Operator = selectorOperator(); + } + else + parent.Operator = new ChooseChildrenOperator(); + + if (context.Child != null) + parent.Child = context.Child.Accept(this); + + return parent; + } + + public override NodeSelector VisitStatement(TreeSelectorParser.StatementContext context) + { + var selectorText = context.Selector.Text; + + var attributes = context.attribute() + .Select(attribute => _AttributeVisitor.VisitAttribute(attribute)) + .ToArray(); + + Func result; + if (!_Selectors.TryGetValue(selectorText, out result)) + throw new Exception("Invalid selector!"); + + var selector = result(); + selector.Attributes = attributes; + + return selector; + } + } + + public class TreeSelectorVisitor : TreeSelectorBaseVisitor> + { + protected NodeSelectorVisitor _NodeSelectorVisitor { get; set; } + + public TreeSelectorVisitor() + { + _NodeSelectorVisitor = new NodeSelectorVisitor(); + } + + public override IEnumerable VisitInit(TreeSelectorParser.InitContext context) + { + return context.selectors().Accept(this); + } + + public override IEnumerable VisitSelectors(TreeSelectorParser.SelectorsContext context) + { + return context + .selector() + .Select(selector => _NodeSelectorVisitor.VisitSelector(selector)) + .ToArray(); + } + } + + public class AttributeVisitor : TreeSelectorBaseVisitor + { + public override NodeSelectorAttribute VisitAttribute(TreeSelectorParser.AttributeContext context) + { + var property = context.Property.Text; + var value = string.Empty; + + if (context.Value != null) + value = context.Value.Text; + + return new NodeSelectorAttribute(property, value); + } + } +} diff --git a/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelectorVisitor.cs b/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelectorVisitor.cs deleted file mode 100644 index 45aa3b8..0000000 --- a/project/MetaCode/MetaCode.Compiler/Visitors/TreeSelectorVisitor.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MetaCode.Compiler.Grammar; - -namespace MetaCode.Compiler.Visitors -{ - public partial class TreeSelectorVisitor : TreeSelectorBaseVisitor - { - } -} diff --git a/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.dll b/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.dll index 90302e6..5e50db8 100644 Binary files a/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.dll and b/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.dll differ diff --git a/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.pdb b/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.pdb index a844c48..26a4ca0 100644 Binary files a/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.pdb and b/project/MetaCode/MetaCode.Compiler/bin/Debug/MetaCode.Compiler.pdb differ diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.dll b/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.dll index 90302e6..5e50db8 100644 Binary files a/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.dll and b/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.dll differ diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.pdb b/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.pdb index a844c48..26a4ca0 100644 Binary files a/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.pdb and b/project/MetaCode/MetaCode.Compiler/obj/Debug/MetaCode.Compiler.pdb differ diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.cs new file mode 100644 index 0000000..d82437e --- /dev/null +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.cs @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// ANTLR Version: 4.2-SNAPSHOT +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +// Generated from E:\Development\Projects\MetaCode\project\MetaCode\MetaCode.Compiler\Grammar\TreeSelector.g4 by ANTLR 4.2-SNAPSHOT + +// Unreachable code detected +#pragma warning disable 0162 +// The variable '...' is assigned but its value is never used +#pragma warning disable 0219 +// Missing XML comment for publicly visible type or member '...' +#pragma warning disable 1591 + +namespace MetaCode.Compiler.Grammar { +using Antlr4.Runtime; +using Antlr4.Runtime.Atn; +using Antlr4.Runtime.Misc; +using DFA = Antlr4.Runtime.Dfa.DFA; + +[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.2-SNAPSHOT")] +[System.CLSCompliant(false)] +public partial class SelectorLexer : Lexer { + public const int + T__4=1, T__3=2, T__2=3, T__1=4, T__0=5, ID=6, WHITESPACE=7, NEWLINE=8; + public static string[] modeNames = { + "DEFAULT_MODE" + }; + + public static readonly string[] tokenNames = { + "", + "']'", "'>'", "','", "'['", "'='", "ID", "WHITESPACE", "NEWLINE" + }; + public static readonly string[] ruleNames = { + "T__4", "T__3", "T__2", "T__1", "T__0", "ID", "LETTER", "WHITESPACE", + "NEWLINE" + }; + + + public SelectorLexer(ICharStream input) + : base(input) + { + _interp = new LexerATNSimulator(this,_ATN); + } + + public override string GrammarFileName { get { return "TreeSelector.g4"; } } + + public override string[] TokenNames { get { return tokenNames; } } + + public override string[] RuleNames { get { return ruleNames; } } + + public override string[] ModeNames { get { return modeNames; } } + + public override string SerializedAtn { get { return _serializedATN; } } + + public static readonly string _serializedATN = + "\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x2\n@\b\x1\x4\x2\t"+ + "\x2\x4\x3\t\x3\x4\x4\t\x4\x4\x5\t\x5\x4\x6\t\x6\x4\a\t\a\x4\b\t\b\x4\t"+ + "\t\t\x4\n\t\n\x3\x2\x3\x2\x3\x3\x3\x3\x3\x4\x3\x4\x3\x5\x3\x5\x3\x6\x3"+ + "\x6\x3\a\x5\a!\n\a\x3\a\x3\a\x5\a%\n\a\x3\a\x3\a\a\a)\n\a\f\a\xE\a,\v"+ + "\a\x3\a\x5\a/\n\a\x3\b\x3\b\x3\t\x6\t\x34\n\t\r\t\xE\t\x35\x3\t\x3\t\x3"+ + "\n\x5\n;\n\n\x3\n\x3\n\x3\n\x3\n\x2\x2\x2\v\x3\x2\x3\x5\x2\x4\a\x2\x5"+ + "\t\x2\x6\v\x2\a\r\x2\b\xF\x2\x2\x11\x2\t\x13\x2\n\x3\x2\x5\x5\x2//\x32"+ + ";\x61\x61\x4\x2\x43\\\x63|\x4\x2\v\v\"\"\x45\x2\x3\x3\x2\x2\x2\x2\x5\x3"+ + "\x2\x2\x2\x2\a\x3\x2\x2\x2\x2\t\x3\x2\x2\x2\x2\v\x3\x2\x2\x2\x2\r\x3\x2"+ + "\x2\x2\x2\x11\x3\x2\x2\x2\x2\x13\x3\x2\x2\x2\x3\x15\x3\x2\x2\x2\x5\x17"+ + "\x3\x2\x2\x2\a\x19\x3\x2\x2\x2\t\x1B\x3\x2\x2\x2\v\x1D\x3\x2\x2\x2\r."+ + "\x3\x2\x2\x2\xF\x30\x3\x2\x2\x2\x11\x33\x3\x2\x2\x2\x13:\x3\x2\x2\x2\x15"+ + "\x16\a_\x2\x2\x16\x4\x3\x2\x2\x2\x17\x18\a@\x2\x2\x18\x6\x3\x2\x2\x2\x19"+ + "\x1A\a.\x2\x2\x1A\b\x3\x2\x2\x2\x1B\x1C\a]\x2\x2\x1C\n\x3\x2\x2\x2\x1D"+ + "\x1E\a?\x2\x2\x1E\f\x3\x2\x2\x2\x1F!\a\x42\x2\x2 \x1F\x3\x2\x2\x2 !\x3"+ + "\x2\x2\x2!$\x3\x2\x2\x2\"%\x5\xF\b\x2#%\a\x61\x2\x2$\"\x3\x2\x2\x2$#\x3"+ + "\x2\x2\x2%*\x3\x2\x2\x2&)\x5\xF\b\x2\')\t\x2\x2\x2(&\x3\x2\x2\x2(\'\x3"+ + "\x2\x2\x2),\x3\x2\x2\x2*(\x3\x2\x2\x2*+\x3\x2\x2\x2+/\x3\x2\x2\x2,*\x3"+ + "\x2\x2\x2-/\a,\x2\x2. \x3\x2\x2\x2.-\x3\x2\x2\x2/\xE\x3\x2\x2\x2\x30\x31"+ + "\t\x3\x2\x2\x31\x10\x3\x2\x2\x2\x32\x34\t\x4\x2\x2\x33\x32\x3\x2\x2\x2"+ + "\x34\x35\x3\x2\x2\x2\x35\x33\x3\x2\x2\x2\x35\x36\x3\x2\x2\x2\x36\x37\x3"+ + "\x2\x2\x2\x37\x38\b\t\x2\x2\x38\x12\x3\x2\x2\x2\x39;\a\xF\x2\x2:\x39\x3"+ + "\x2\x2\x2:;\x3\x2\x2\x2;<\x3\x2\x2\x2<=\a\f\x2\x2=>\x3\x2\x2\x2>?\b\n"+ + "\x2\x2?\x14\x3\x2\x2\x2\n\x2 $(*.\x35:\x3\b\x2\x2"; + public static readonly ATN _ATN = + new ATNDeserializer().Deserialize(_serializedATN.ToCharArray()); +} +} // namespace MetaCode.Compiler.Grammar diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.tokens b/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.tokens index b5f69a0..7a54d52 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.tokens +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/SelectorLexer.tokens @@ -1,2 +1,13 @@ -WS=1 -' '=1 +WHITESPACE=7 +NEWLINE=8 +ID=6 +T__1=4 +T__0=5 +T__3=2 +T__2=3 +T__4=1 +'='=5 +'['=4 +','=3 +'>'=2 +']'=1 diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelector.tokens b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelector.tokens index 1a97789..8db65c0 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelector.tokens +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelector.tokens @@ -1,37 +1,16 @@ -FUNCTION=9 -NEWLINE=20 -VARIABLE=15 -WHILE=7 +WHITESPACE=9 +NEWLINE=10 +ID=8 +OPERATOR=7 T__1=5 -ALL=17 T__0=6 T__3=3 -T__2=4 -WHITESPACE=19 -TRUE_STATEMENT=11 -FOREACH=8 -ELSE_STATEMENT=12 -BODY=13 -ID=18 -DECLARATION=16 -EXPRESSION=14 T__5=1 -IF=10 +T__2=4 T__4=2 -'foreach'=8 -'else-if'=11 -'else'=12 -'>'=2 -'expression'=14 -'='=6 -'if'=10 -'*'=17 -'['=5 -'while'=7 -'body'=13 -'+'=4 +'}'=6 +'='=5 +'['=4 ','=3 -'function'=9 -'variable'=15 -'declaration'=16 +'{'=2 ']'=1 diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseListener.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseListener.cs index 3219bd0..05c7a6a 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseListener.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseListener.cs @@ -72,19 +72,6 @@ public virtual void EnterSelectors([NotNull] TreeSelectorParser.SelectorsContext /// The parse tree. public virtual void ExitSelectors([NotNull] TreeSelectorParser.SelectorsContext context) { } - /// - /// Enter a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void EnterBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context) { } - /// - /// Exit a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void ExitBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context) { } - /// /// Enter a parse tree produced by . /// The default implementation does nothing. @@ -111,19 +98,6 @@ public virtual void EnterInit([NotNull] TreeSelectorParser.InitContext context) /// The parse tree. public virtual void ExitInit([NotNull] TreeSelectorParser.InitContext context) { } - /// - /// Enter a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void EnterOperator([NotNull] TreeSelectorParser.OperatorContext context) { } - /// - /// Exit a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void ExitOperator([NotNull] TreeSelectorParser.OperatorContext context) { } - /// /// The default implementation does nothing. public virtual void EnterEveryRule([NotNull] ParserRuleContext context) { } diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseVisitor.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseVisitor.cs index 1c980f1..c526084 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseVisitor.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorBaseVisitor.cs @@ -65,17 +65,6 @@ public partial class TreeSelectorBaseVisitor : AbstractParseTreeVisitor< /// The visitor result. public virtual Result VisitSelectors([NotNull] TreeSelectorParser.SelectorsContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context) { return VisitChildren(context); } - /// /// Visit a parse tree produced by . /// @@ -97,16 +86,5 @@ public partial class TreeSelectorBaseVisitor : AbstractParseTreeVisitor< /// The parse tree. /// The visitor result. public virtual Result VisitInit([NotNull] TreeSelectorParser.InitContext context) { return VisitChildren(context); } - - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitOperator([NotNull] TreeSelectorParser.OperatorContext context) { return VisitChildren(context); } } } // namespace MetaCode.Compiler.Grammar diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.cs index 0d1d5e6..9d32266 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.cs @@ -27,23 +27,20 @@ namespace MetaCode.Compiler.Grammar { [System.CLSCompliant(false)] public partial class TreeSelectorLexer : Lexer { public const int - T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, WHILE=7, FOREACH=8, FUNCTION=9, - IF=10, TRUE_STATEMENT=11, ELSE_STATEMENT=12, BODY=13, EXPRESSION=14, VARIABLE=15, - DECLARATION=16, ALL=17, ID=18, WHITESPACE=19, NEWLINE=20; + T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, OPERATOR=7, ID=8, WHITESPACE=9, + NEWLINE=10; public static string[] modeNames = { "DEFAULT_MODE" }; public static readonly string[] tokenNames = { "", - "']'", "'>'", "','", "'+'", "'['", "'='", "'while'", "'foreach'", "'function'", - "'if'", "'else-if'", "'else'", "'body'", "'expression'", "'variable'", - "'declaration'", "'*'", "ID", "WHITESPACE", "NEWLINE" + "']'", "'{'", "','", "'['", "'='", "'}'", "OPERATOR", "ID", "WHITESPACE", + "NEWLINE" }; public static readonly string[] ruleNames = { - "T__5", "T__4", "T__3", "T__2", "T__1", "T__0", "WHILE", "FOREACH", "FUNCTION", - "IF", "TRUE_STATEMENT", "ELSE_STATEMENT", "BODY", "EXPRESSION", "VARIABLE", - "DECLARATION", "ALL", "ID", "LETTER", "WHITESPACE", "NEWLINE" + "T__5", "T__4", "T__3", "T__2", "T__1", "T__0", "OPERATOR", "ID", "LETTER", + "WHITESPACE", "NEWLINE" }; @@ -64,64 +61,34 @@ public TreeSelectorLexer(ICharStream input) public override string SerializedAtn { get { return _serializedATN; } } public static readonly string _serializedATN = - "\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x2\x16\xA5\b\x1\x4"+ - "\x2\t\x2\x4\x3\t\x3\x4\x4\t\x4\x4\x5\t\x5\x4\x6\t\x6\x4\a\t\a\x4\b\t\b"+ - "\x4\t\t\t\x4\n\t\n\x4\v\t\v\x4\f\t\f\x4\r\t\r\x4\xE\t\xE\x4\xF\t\xF\x4"+ - "\x10\t\x10\x4\x11\t\x11\x4\x12\t\x12\x4\x13\t\x13\x4\x14\t\x14\x4\x15"+ - "\t\x15\x4\x16\t\x16\x3\x2\x3\x2\x3\x3\x3\x3\x3\x4\x3\x4\x3\x5\x3\x5\x3"+ - "\x6\x3\x6\x3\a\x3\a\x3\b\x3\b\x3\b\x3\b\x3\b\x3\b\x3\t\x3\t\x3\t\x3\t"+ - "\x3\t\x3\t\x3\t\x3\t\x3\n\x3\n\x3\n\x3\n\x3\n\x3\n\x3\n\x3\n\x3\n\x3\v"+ - "\x3\v\x3\v\x3\f\x3\f\x3\f\x3\f\x3\f\x3\f\x3\f\x3\f\x3\r\x3\r\x3\r\x3\r"+ - "\x3\r\x3\xE\x3\xE\x3\xE\x3\xE\x3\xE\x3\xF\x3\xF\x3\xF\x3\xF\x3\xF\x3\xF"+ - "\x3\xF\x3\xF\x3\xF\x3\xF\x3\xF\x3\x10\x3\x10\x3\x10\x3\x10\x3\x10\x3\x10"+ - "\x3\x10\x3\x10\x3\x10\x3\x11\x3\x11\x3\x11\x3\x11\x3\x11\x3\x11\x3\x11"+ - "\x3\x11\x3\x11\x3\x11\x3\x11\x3\x11\x3\x12\x3\x12\x3\x13\x5\x13\x89\n"+ - "\x13\x3\x13\x3\x13\x5\x13\x8D\n\x13\x3\x13\x3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x30\x32"+ + "\x36=\x42\x3\b\x2\x2"; public static readonly ATN _ATN = new ATNDeserializer().Deserialize(_serializedATN.ToCharArray()); } diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.tokens b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.tokens index 1a97789..8db65c0 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.tokens +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorLexer.tokens @@ -1,37 +1,16 @@ -FUNCTION=9 -NEWLINE=20 -VARIABLE=15 -WHILE=7 +WHITESPACE=9 +NEWLINE=10 +ID=8 +OPERATOR=7 T__1=5 -ALL=17 T__0=6 T__3=3 -T__2=4 -WHITESPACE=19 -TRUE_STATEMENT=11 -FOREACH=8 -ELSE_STATEMENT=12 -BODY=13 -ID=18 -DECLARATION=16 -EXPRESSION=14 T__5=1 -IF=10 +T__2=4 T__4=2 -'foreach'=8 -'else-if'=11 -'else'=12 -'>'=2 -'expression'=14 -'='=6 -'if'=10 -'*'=17 -'['=5 -'while'=7 -'body'=13 -'+'=4 +'}'=6 +'='=5 +'['=4 ','=3 -'function'=9 -'variable'=15 -'declaration'=16 +'{'=2 ']'=1 diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorListener.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorListener.cs index 989c991..4a0f522 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorListener.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorListener.cs @@ -62,17 +62,6 @@ public interface ITreeSelectorListener : IParseTreeListener { /// The parse tree. void ExitSelectors([NotNull] TreeSelectorParser.SelectorsContext context); - /// - /// Enter a parse tree produced by . - /// - /// The parse tree. - void EnterBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context); - /// - /// Exit a parse tree produced by . - /// - /// The parse tree. - void ExitBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context); - /// /// Enter a parse tree produced by . /// @@ -94,16 +83,5 @@ public interface ITreeSelectorListener : IParseTreeListener { /// /// The parse tree. void ExitInit([NotNull] TreeSelectorParser.InitContext context); - - /// - /// Enter a parse tree produced by . - /// - /// The parse tree. - void EnterOperator([NotNull] TreeSelectorParser.OperatorContext context); - /// - /// Exit a parse tree produced by . - /// - /// The parse tree. - void ExitOperator([NotNull] TreeSelectorParser.OperatorContext context); } } // namespace MetaCode.Compiler.Grammar diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorParser.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorParser.cs index c63f7c8..a555e31 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorParser.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorParser.cs @@ -29,20 +29,17 @@ namespace MetaCode.Compiler.Grammar { [System.CLSCompliant(false)] public partial class TreeSelectorParser : Parser { public const int - T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, WHILE=7, FOREACH=8, FUNCTION=9, - IF=10, TRUE_STATEMENT=11, ELSE_STATEMENT=12, BODY=13, EXPRESSION=14, VARIABLE=15, - DECLARATION=16, ALL=17, ID=18, WHITESPACE=19, NEWLINE=20; + T__5=1, T__4=2, T__3=3, T__2=4, T__1=5, T__0=6, OPERATOR=7, ID=8, WHITESPACE=9, + NEWLINE=10; public static readonly string[] tokenNames = { - "", "']'", "'>'", "','", "'+'", "'['", "'='", "'while'", "'foreach'", - "'function'", "'if'", "'else-if'", "'else'", "'body'", "'expression'", - "'variable'", "'declaration'", "'*'", "ID", "WHITESPACE", "NEWLINE" + "", "']'", "'{'", "','", "'['", "'='", "'}'", "OPERATOR", "ID", + "WHITESPACE", "NEWLINE" }; public const int RULE_init = 0, RULE_selectors = 1, RULE_selector = 2, RULE_attribute = 3, - RULE_operator = 4, RULE_statement = 5, RULE_baseStatement = 6; + RULE_statement = 4; public static readonly string[] ruleNames = { - "init", "selectors", "selector", "attribute", "operator", "statement", - "baseStatement" + "init", "selectors", "selector", "attribute", "statement" }; public override string GrammarFileName { get { return "TreeSelector.g4"; } } @@ -89,9 +86,9 @@ public InitContext init() { try { EnterOuterAlt(_localctx, 1); { - State = 14; Match(5); - State = 15; selectors(); - State = 16; Match(1); + State = 10; Match(2); + State = 11; selectors(); + State = 12; Match(6); } } catch (RecognitionException re) { @@ -140,18 +137,18 @@ public SelectorsContext selectors() { try { EnterOuterAlt(_localctx, 1); { - State = 18; selector(0); - State = 23; + State = 14; selector(); + State = 19; _errHandler.Sync(this); _la = _input.La(1); while (_la==3) { { { - State = 19; Match(3); - State = 20; selector(0); + State = 15; Match(3); + State = 16; selector(); } } - State = 25; + State = 21; _errHandler.Sync(this); _la = _input.La(1); } @@ -169,18 +166,16 @@ public SelectorsContext selectors() { } public partial class SelectorContext : ParserRuleContext { + public StatementContext Parent; + public IToken Operator; + public SelectorContext Child; public StatementContext statement() { return GetRuleContext(0); } - public SelectorContext selector(int i) { - return GetRuleContext(i); - } - public OperatorContext @operator() { - return GetRuleContext(0); - } - public IReadOnlyList selector() { - return GetRuleContexts(); + public SelectorContext selector() { + return GetRuleContext(0); } + public ITerminalNode OPERATOR() { return GetToken(TreeSelectorParser.OPERATOR, 0); } public SelectorContext(ParserRuleContext parent, int invokingState) : base(parent, invokingState) { @@ -203,46 +198,29 @@ public override TResult Accept(IParseTreeVisitor visitor) { [RuleVersion(0)] public SelectorContext selector() { - return selector(0); - } - - private SelectorContext selector(int _p) { - ParserRuleContext _parentctx = _ctx; - int _parentState = State; - SelectorContext _localctx = new SelectorContext(_ctx, _parentState); - SelectorContext _prevctx = _localctx; - int _startState = 4; - EnterRecursionRule(_localctx, 4, RULE_selector, _p); + SelectorContext _localctx = new SelectorContext(_ctx, State); + EnterRule(_localctx, 4, RULE_selector); + int _la; try { - int _alt; EnterOuterAlt(_localctx, 1); { - { - State = 27; statement(); - } - _ctx.stop = _input.Lt(-1); - State = 35; - _errHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(_input,1,_ctx); - while ( _alt!=2 && _alt!=-1 ) { - if ( _alt==1 ) { - if ( _parseListeners!=null ) TriggerExitRuleEvent(); - _prevctx = _localctx; - { + State = 22; _localctx.Parent = statement(); + State = 27; + _la = _input.La(1); + if (_la==OPERATOR || _la==ID) { + { + State = 24; + _la = _input.La(1); + if (_la==OPERATOR) { { - _localctx = new SelectorContext(_parentctx, _parentState); - PushNewRecursionContext(_localctx, _startState, RULE_selector); - State = 29; - if (!(Precpred(_ctx, 1))) throw new FailedPredicateException(this, "Precpred(_ctx, 1)"); - State = 30; @operator(); - State = 31; selector(2); + State = 23; _localctx.Operator = Match(OPERATOR); } - } } - State = 37; - _errHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(_input,1,_ctx); + + State = 26; _localctx.Child = selector(); + } } + } } catch (RecognitionException re) { @@ -251,12 +229,14 @@ private SelectorContext selector(int _p) { _errHandler.Recover(this, re); } finally { - UnrollRecursionContexts(_parentctx); + ExitRule(); } return _localctx; } public partial class AttributeContext : ParserRuleContext { + public IToken Property; + public IToken Value; public IReadOnlyList ID() { return GetTokens(TreeSelectorParser.ID); } public ITerminalNode ID(int i) { return GetToken(TreeSelectorParser.ID, i); @@ -285,62 +265,22 @@ public override TResult Accept(IParseTreeVisitor visitor) { public AttributeContext attribute() { AttributeContext _localctx = new AttributeContext(_ctx, State); EnterRule(_localctx, 6, RULE_attribute); - try { - EnterOuterAlt(_localctx, 1); - { - State = 38; Match(5); - State = 39; Match(ID); - State = 40; Match(6); - State = 41; Match(ID); - State = 42; Match(1); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.ReportError(this, re); - _errHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class OperatorContext : ParserRuleContext { - public OperatorContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int GetRuleIndex() { return RULE_operator; } - public override void EnterRule(IParseTreeListener listener) { - ITreeSelectorListener typedListener = listener as ITreeSelectorListener; - if (typedListener != null) typedListener.EnterOperator(this); - } - public override void ExitRule(IParseTreeListener listener) { - ITreeSelectorListener typedListener = listener as ITreeSelectorListener; - if (typedListener != null) typedListener.ExitOperator(this); - } - public override TResult Accept(IParseTreeVisitor visitor) { - ITreeSelectorVisitor typedVisitor = visitor as ITreeSelectorVisitor; - if (typedVisitor != null) return typedVisitor.VisitOperator(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public OperatorContext @operator() { - OperatorContext _localctx = new OperatorContext(_ctx, State); - EnterRule(_localctx, 8, RULE_operator); int _la; try { EnterOuterAlt(_localctx, 1); { - State = 44; + State = 29; Match(4); + State = 30; _localctx.Property = Match(ID); + State = 33; _la = _input.La(1); - if ( !(_la==2 || _la==4) ) { - _errHandler.RecoverInline(this); + if (_la==5) { + { + State = 31; Match(5); + State = 32; _localctx.Value = Match(ID); + } } - Consume(); + + State = 35; Match(1); } } catch (RecognitionException re) { @@ -355,15 +295,15 @@ public OperatorContext @operator() { } public partial class StatementContext : ParserRuleContext { + public IToken Selector; + public AttributeContext Attributes; public IReadOnlyList attribute() { return GetRuleContexts(); } + public ITerminalNode ID() { return GetToken(TreeSelectorParser.ID, 0); } public AttributeContext attribute(int i) { return GetRuleContext(i); } - public BaseStatementContext baseStatement() { - return GetRuleContext(0); - } public StatementContext(ParserRuleContext parent, int invokingState) : base(parent, invokingState) { @@ -387,141 +327,25 @@ public override TResult Accept(IParseTreeVisitor visitor) { [RuleVersion(0)] public StatementContext statement() { StatementContext _localctx = new StatementContext(_ctx, State); - EnterRule(_localctx, 10, RULE_statement); + EnterRule(_localctx, 8, RULE_statement); + int _la; try { - int _alt; EnterOuterAlt(_localctx, 1); { - State = 46; baseStatement(); - State = 50; + State = 37; _localctx.Selector = Match(ID); + State = 41; _errHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(_input,2,_ctx); - while ( _alt!=2 && _alt!=-1 ) { - if ( _alt==1 ) { - { - { - State = 47; attribute(); - } - } - } - State = 52; - _errHandler.Sync(this); - _alt = Interpreter.AdaptivePredict(_input,2,_ctx); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.ReportError(this, re); - _errHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class BaseStatementContext : ParserRuleContext { - public IToken Statement; - public ITerminalNode ELSE_STATEMENT() { return GetToken(TreeSelectorParser.ELSE_STATEMENT, 0); } - public ITerminalNode WHILE() { return GetToken(TreeSelectorParser.WHILE, 0); } - public ITerminalNode BODY() { return GetToken(TreeSelectorParser.BODY, 0); } - public ITerminalNode IF() { return GetToken(TreeSelectorParser.IF, 0); } - public ITerminalNode ALL() { return GetToken(TreeSelectorParser.ALL, 0); } - public ITerminalNode VARIABLE() { return GetToken(TreeSelectorParser.VARIABLE, 0); } - public ITerminalNode EXPRESSION() { return GetToken(TreeSelectorParser.EXPRESSION, 0); } - public ITerminalNode FUNCTION() { return GetToken(TreeSelectorParser.FUNCTION, 0); } - public ITerminalNode TRUE_STATEMENT() { return GetToken(TreeSelectorParser.TRUE_STATEMENT, 0); } - public ITerminalNode FOREACH() { return GetToken(TreeSelectorParser.FOREACH, 0); } - public BaseStatementContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int GetRuleIndex() { return RULE_baseStatement; } - public override void EnterRule(IParseTreeListener listener) { - ITreeSelectorListener typedListener = listener as ITreeSelectorListener; - if (typedListener != null) typedListener.EnterBaseStatement(this); - } - public override void ExitRule(IParseTreeListener listener) { - ITreeSelectorListener typedListener = listener as ITreeSelectorListener; - if (typedListener != null) typedListener.ExitBaseStatement(this); - } - public override TResult Accept(IParseTreeVisitor visitor) { - ITreeSelectorVisitor typedVisitor = visitor as ITreeSelectorVisitor; - if (typedVisitor != null) return typedVisitor.VisitBaseStatement(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public BaseStatementContext baseStatement() { - BaseStatementContext _localctx = new BaseStatementContext(_ctx, State); - EnterRule(_localctx, 12, RULE_baseStatement); - try { - State = 63; - switch (_input.La(1)) { - case WHILE: - EnterOuterAlt(_localctx, 1); - { - State = 53; _localctx.Statement = Match(WHILE); - } - break; - case FOREACH: - EnterOuterAlt(_localctx, 2); - { - State = 54; _localctx.Statement = Match(FOREACH); - } - break; - case FUNCTION: - EnterOuterAlt(_localctx, 3); - { - State = 55; _localctx.Statement = Match(FUNCTION); - } - break; - case IF: - EnterOuterAlt(_localctx, 4); - { - State = 56; _localctx.Statement = Match(IF); - } - break; - case TRUE_STATEMENT: - EnterOuterAlt(_localctx, 5); - { - State = 57; _localctx.Statement = Match(TRUE_STATEMENT); - } - break; - case ELSE_STATEMENT: - EnterOuterAlt(_localctx, 6); - { - State = 58; _localctx.Statement = Match(ELSE_STATEMENT); - } - break; - case BODY: - EnterOuterAlt(_localctx, 7); + _la = _input.La(1); + while (_la==4) { { - State = 59; _localctx.Statement = Match(BODY); - } - break; - case EXPRESSION: - EnterOuterAlt(_localctx, 8); { - State = 60; _localctx.Statement = Match(EXPRESSION); + State = 38; _localctx.Attributes = attribute(); } - break; - case VARIABLE: - EnterOuterAlt(_localctx, 9); - { - State = 61; _localctx.Statement = Match(VARIABLE); } - break; - case ALL: - EnterOuterAlt(_localctx, 10); - { - State = 62; _localctx.Statement = Match(ALL); - } - break; - default: - throw new NoViableAltException(this); + State = 43; + _errHandler.Sync(this); + _la = _input.La(1); + } } } catch (RecognitionException re) { @@ -535,45 +359,24 @@ public BaseStatementContext baseStatement() { return _localctx; } - public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) { - switch (ruleIndex) { - case 2: return selector_sempred((SelectorContext)_localctx, predIndex); - } - return true; - } - private bool selector_sempred(SelectorContext _localctx, int predIndex) { - switch (predIndex) { - case 0: return Precpred(_ctx, 1); - } - return true; - } - public static readonly string _serializedATN = - "\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x3\x16\x44\x4\x2\t"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6\x2\x2\x2\a\x2\x2\x4"+ + "\x2\x6\x2\b\x2\n\x2\x2\x2.\x2\f\x3\x2\x2\x2\x4\x10\x3\x2\x2\x2\x6\x18"+ + "\x3\x2\x2\x2\b\x1F\x3\x2\x2\x2\n\'\x3\x2\x2\x2\f\r\a\x4\x2\x2\r\xE\x5"+ + "\x4\x3\x2\xE\xF\a\b\x2\x2\xF\x3\x3\x2\x2\x2\x10\x15\x5\x6\x4\x2\x11\x12"+ + "\a\x5\x2\x2\x12\x14\x5\x6\x4\x2\x13\x11\x3\x2\x2\x2\x14\x17\x3\x2\x2\x2"+ + "\x15\x13\x3\x2\x2\x2\x15\x16\x3\x2\x2\x2\x16\x5\x3\x2\x2\x2\x17\x15\x3"+ + "\x2\x2\x2\x18\x1D\x5\n\x6\x2\x19\x1B\a\t\x2\x2\x1A\x19\x3\x2\x2\x2\x1A"+ + "\x1B\x3\x2\x2\x2\x1B\x1C\x3\x2\x2\x2\x1C\x1E\x5\x6\x4\x2\x1D\x1A\x3\x2"+ + "\x2\x2\x1D\x1E\x3\x2\x2\x2\x1E\a\x3\x2\x2\x2\x1F \a\x6\x2\x2 #\a\n\x2"+ + "\x2!\"\a\a\x2\x2\"$\a\n\x2\x2#!\x3\x2\x2\x2#$\x3\x2\x2\x2$%\x3\x2\x2\x2"+ + "%&\a\x3\x2\x2&\t\x3\x2\x2\x2\'+\a\n\x2\x2(*\x5\b\x5\x2)(\x3\x2\x2\x2*"+ + "-\x3\x2\x2\x2+)\x3\x2\x2\x2+,\x3\x2\x2\x2,\v\x3\x2\x2\x2-+\x3\x2\x2\x2"+ + "\a\x15\x1A\x1D#+"; public static readonly ATN _ATN = new ATNDeserializer().Deserialize(_serializedATN.ToCharArray()); } diff --git a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorVisitor.cs b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorVisitor.cs index d13c33c..c106323 100644 --- a/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorVisitor.cs +++ b/project/MetaCode/MetaCode.Compiler/obj/Debug/TreeSelectorVisitor.cs @@ -51,13 +51,6 @@ public interface ITreeSelectorVisitor : IParseTreeVisitor { /// The visitor result. Result VisitSelectors([NotNull] TreeSelectorParser.SelectorsContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitBaseStatement([NotNull] TreeSelectorParser.BaseStatementContext context); - /// /// Visit a parse tree produced by . /// @@ -71,12 +64,5 @@ public interface ITreeSelectorVisitor : IParseTreeVisitor { /// The parse tree. /// The visitor result. Result VisitInit([NotNull] TreeSelectorParser.InitContext context); - - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitOperator([NotNull] TreeSelectorParser.OperatorContext context); } } // namespace MetaCode.Compiler.Grammar diff --git a/project/MetaCode/MetaCode.sln.DotSettings.user b/project/MetaCode/MetaCode.sln.DotSettings.user index 22fef31..c0984ac 100644 --- a/project/MetaCode/MetaCode.sln.DotSettings.user +++ b/project/MetaCode/MetaCode.sln.DotSettings.user @@ -5,4 +5,4 @@ <Session><Elements><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.MyVisitorCompilerTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeHelperTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareFunctionTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareFunctionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareVariableTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareVariableTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorVisitConstantShouldParseStringTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorVisitConstantShouldParseStringTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorVisitStatementsTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorVisitStatementsTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorVisitWhileTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorVisitWhileTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.MyVisitorCompilerTestFixture.MyVisitorTest" ParentId="MetaCode.Compiler.Tests.MyVisitorCompilerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.MyVisitorCompilerTestFixture" MethodName="MyVisitorTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeHelperTestFixture.TypeHelperIsEnumerableShouldReturnTrueTest" ParentId="MetaCode.Compiler.Tests.TypeHelperTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TypeHelperTestFixture" MethodName="TypeHelperIsEnumerableShouldReturnTrueTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /></Elements></Session> True AbstractTreeVisitorVisitWhileTest - <Session><Elements><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareFunctionTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareFunctionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareVariableTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareVariableTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorVisitWhileTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorVisitWhileTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.AttributeDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="AttributeDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.BlockTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="BlockTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ConstantTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ConstantTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture.CustomVisitorGraphConverterTest" ParentId="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.CustomVisitorTestFixture" MethodName="CustomVisitorGraphConverterTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture.CustomVisitorTest" ParentId="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.CustomVisitorTestFixture" MethodName="CustomVisitorTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionCallExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionCallExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionDeclarationWithAttributeTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionDeclarationWithAttributeTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.MacroCallExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="MacroCallExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture.MacroDeclarationTest" ParentId="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" MethodName="MacroDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.MemberExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="MemberExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ObjectDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ObjectDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ProcedureDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ProcedureDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture.VariableDeclarationTest" ParentId="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" MethodName="VariableDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture.WrongAdditionTypeTest" ParentId="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" MethodName="WrongAdditionTypeTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /></Elements></Session> \ No newline at end of file + <Session><Elements><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TreeSelectorTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestFixtureElement" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareFunctionTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareFunctionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorDeclareVariableTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorDeclareVariableTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture.AbstractTreeVisitorVisitWhileTest" ParentId="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.AbstractTreeVisitorTestFixture" MethodName="AbstractTreeVisitorVisitWhileTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.AttributeDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="AttributeDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.BlockTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="BlockTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ConstantTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ConstantTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture.CustomVisitorGraphConverterTest" ParentId="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.CustomVisitorTestFixture" MethodName="CustomVisitorGraphConverterTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.CustomVisitorTestFixture.CustomVisitorTest" ParentId="MetaCode.Compiler.Tests.CustomVisitorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.CustomVisitorTestFixture" MethodName="CustomVisitorTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionCallExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionCallExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.FunctionDeclarationWithAttributeTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="FunctionDeclarationWithAttributeTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.MacroCallExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="MacroCallExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture.MacroDeclarationTest" ParentId="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" MethodName="MacroDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.MemberExpressionTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="MemberExpressionTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ObjectDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ObjectDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.SyntaxTreeTestFixture.ProcedureDeclarationTest" ParentId="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.SyntaxTreeTestFixture" MethodName="ProcedureDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TreeSelectorTestFixture.StatementTest" ParentId="MetaCode.Compiler.Tests.TreeSelectorTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TreeSelectorTestFixture" MethodName="StatementTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture.VariableDeclarationTest" ParentId="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.TypeDeclarationAnalyzerTestFixture" MethodName="VariableDeclarationTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /><UnitTestElement Provider="nUnit" Id="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture.WrongAdditionTypeTest" ParentId="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" type="NUnitTestElement" TypeName="MetaCode.Compiler.Tests.ExpressionTypeAnalyzerTestFixture" MethodName="WrongAdditionTypeTest" Project="FCAF7D34-A84D-4870-A77B-9BB8EF342B20" /></Elements></Session> \ No newline at end of file diff --git a/project/MetaCode/MetaCode.v12.suo b/project/MetaCode/MetaCode.v12.suo index 05076c3..f2bda56 100644 Binary files a/project/MetaCode/MetaCode.v12.suo and b/project/MetaCode/MetaCode.v12.suo differ