Skip to content
Permalink
Browse files

Add exceedingly basic support for annotations. They do nothing yet.

  • Loading branch information...
LadyCailin committed Mar 1, 2019
1 parent a1b5c5e commit d776c66e924d2b0215949590b2c8ae7eb942c4da
@@ -335,3 +335,5 @@ ASALocalRun/

.checkstyle

# MethodScript
persistence.db
BIN -320 KB persistence.db
Binary file not shown.
@@ -145,6 +145,7 @@ public static TokenStream lex(String script, File file, boolean inPureMScript, b
boolean inMultiline = false;
boolean inSmartComment = false;
boolean inFileOptions = false;
boolean inAnnotation = false;
int fileOptionsLineNumberStart = 1;

StringBuilder buf = new StringBuilder();
@@ -278,7 +279,7 @@ public static TokenStream lex(String script, File file, boolean inPureMScript, b
}

// If we are in a comment, add the character to the buffer.
if(inComment) {
if(inComment || (inAnnotation && c != '}')) {
buf.append(c);
continue;
}
@@ -488,6 +489,14 @@ public static TokenStream lex(String script, File file, boolean inPureMScript, b
break;
}
case '}': {
if(inAnnotation) {
// Eventually, this will no longer be a comment type, but for now, we just want
// to totally ignore annotations, as if they were comments.
inAnnotation = false;
token = new Token(/*TType.ANNOTATION*/TType.COMMENT, "@{" + buf.toString() + "}", target);
buf = new StringBuilder();
break;
}
token = new Token(TType.RCURLY_BRACKET, "}", target);
break;
}
@@ -571,6 +580,14 @@ public static TokenStream lex(String script, File file, boolean inPureMScript, b
token = new Token(TType.WHITESPACE, "\t", target);
break;
}
case '@': {
if(c2 == '{') {
inAnnotation = true;
i++;
continue;
}
break matched;
}
default: {
// No match was found at this point, so continue matching below.
break matched;
@@ -94,7 +94,8 @@
KEYWORD(TokenVariant.KEYWORD),
FILE_OPTIONS_START(TokenVariant.SEPARATOR, TokenVariant.FILE_OPTION),
FILE_OPTIONS_STRING(TokenVariant.FILE_OPTION),
FILE_OPTIONS_END(TokenVariant.SEPARATOR, TokenVariant.FILE_OPTION);
FILE_OPTIONS_END(TokenVariant.SEPARATOR, TokenVariant.FILE_OPTION),
ANNOTATION(TokenVariant.COMMENT);

private final Set<TokenVariant> variants = EnumSet.noneOf(TokenVariant.class);

@@ -118,14 +118,14 @@ Our unit test code that tests the add method might look like this:

<%CODE|
// Note the TestSuite annotation here, which adds the test class to the framework
@{TestSuite}
@{TestSuite(allowSideEffects: true)}
public class CalculatorTest {

// The Test annotation tells the framework that this method is a test method
@{Test}
public void testAdd() {
// assert([message], expected, actual)
assert("Add is broken!", 4.0, new Calculator().add(2, 2));
assert("Add is broken!", 4.0, new Calculator()->add(2, 2));
}
}
%>
@@ -267,6 +267,7 @@ memory based implementation, the actual persistence.ini file is completely ignor
{{function|write}} go to a memory backed VFS, and http_request is blocked from making actual http calls (the function
may be mocked to simulate a web request, however.)


However, there may be legitimate reasons to allow side effects. This is allowed by using the allowSideEffects parameter
of the @{TestSuite} annotation. This is false by default, but if set to true, then for that test suite only, none of
the external restrictions are enforced (persistence network, read/write, http_request). Additionally, within the test

0 comments on commit d776c66

Please sign in to comment.
You can’t perform that action at this time.