Skip to content

raise_error_for_word_WS_word #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/antlr4/Cryptator.g4
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ expression returns [ICryptaNode node] //create recursively the tree of expressio
| e1=expression divORmul e2=expression {$node=new CryptaNode($divORmul.text, $e1.node, $e2.node);}
| e1=expression addORsub e2=expression {$node=new CryptaNode($addORsub.text, $e1.node, $e2.node);};



word : //additional token to simplify the passage in parameter
(SYMBOL|DIGIT)+;

Expand All @@ -58,12 +60,15 @@ sub : '-';

// Lexer Rules

ERROR : (SYMBOL|DIGIT)+ WHITESPACE (SYMBOL|DIGIT)+;

COMPARATOR : '=' | '!=' | '<' | '>' | '<=' | '>=';

SYMBOL : [a-zA-Z\u0080-\uFFFF] {};

DIGIT : [0-9] {};

WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ -> skip ;
AND : ';' | '&&';


AND : ';' | '&&';
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ -> skip ;
44 changes: 38 additions & 6 deletions src/test/java/cryptator/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
*/
package cryptator;

import static cryptator.TreeTest.testInorder;
import static cryptator.TreeTest.testPostorder;
import static cryptator.TreeTest.testPreorder;

import org.junit.Test;

import cryptator.parser.CryptaParserException;
import cryptator.parser.CryptaParserWrapper;
import cryptator.specs.ICryptaNode;
import org.junit.Test;

import static cryptator.TreeTest.*;

public class ParserTest {

Expand Down Expand Up @@ -125,6 +122,31 @@ public void testParserError7() throws CryptaParserException {
parser.parse("[send + more] >= money");
}

@Test(expected = CryptaParserException.class)
public void testParserError8() throws CryptaParserException {
parser.parse(" send more = money");
}

@Test(expected = CryptaParserException.class)
public void testParserError9() throws CryptaParserException {
parser.parse(" send more = money");
}

@Test(expected = CryptaParserException.class)
public void testParserError10() {
parser.parse("send+more='1000 1'");
}

@Test(expected = CryptaParserException.class)
public void testParserError11() {
parser.parse("send+more=\"1000 1\"");
}

@Test(expected = CryptaParserException.class)
public void testParserError12() {
parser.parse("send + more = '1000' money");
}

@Test
public void testParserAND() throws CryptaParserException {
final ICryptaNode node = parser.parse("send+more=money; d+e>=y");
Expand Down Expand Up @@ -246,6 +268,16 @@ public void testParserIntegerError2() throws CryptaParserException {
parser.parse("send + more >= money; 1 + '12a45' = 3");
}

@Test(expected = CryptaParserException.class)
public void testParserIntegerError3() throws CryptaParserException {
parser.parse("1000 1= 2");
}

@Test(expected = CryptaParserException.class)
public void testParserIntegerError4() throws CryptaParserException {
parser.parse("10aa00 1zx= 2");
}

@Test
public void testParserANDsymbol() throws CryptaParserException {
final ICryptaNode node = parser.parse("send+more=money && d+e>=y");
Expand Down