File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
csep.tests/src/csep/tests Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change
1
+ package csep.tests
2
+
3
+ import org.junit.Test
4
+
5
+ class ClassTest extends ParserTestBase {
6
+
7
+ @Test
8
+ def void testBasic () {
9
+ ok(' ' '
10
+ class NicePerson extends Person
11
+ firstName: "John"
12
+ lastName: "Doe"
13
+
14
+ introduce: -> print "I am #{firstName} #{lastName}"
15
+
16
+ greet: (other) ->
17
+ print "Hello #{other}"
18
+ ' ' ' )
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -56,4 +56,18 @@ class MissingFeaturesTest extends ParserTestBase {
56
56
' ' ' )
57
57
ok(' a = readInfo() while true' )
58
58
}
59
+
60
+ @Test
61
+ def void testClass () {
62
+ // deeply nested class name
63
+ shouldBeOk(' class a.b.c' )
64
+ // class declaration as expression
65
+ shouldBeOk(' c = class extends Foo' )
66
+ // class declaration as expression
67
+ shouldBeOk(' class A extends B extends C' )
68
+ // class name as property
69
+ shouldBeOk(' class "str".length' )
70
+ // class extends any expression
71
+ shouldBeOk(' class A extends 3' )
72
+ }
59
73
}
Original file line number Diff line number Diff line change @@ -17,14 +17,23 @@ Line:
17
17
18
18
Stmt:
19
19
ReturnStmt |
20
- ThrowStmt;
20
+ ThrowStmt |
21
+ ClassDeclaration;
21
22
22
23
ReturnStmt:
23
24
RETURN exp=Expression;
24
25
25
26
ThrowStmt:
26
27
THROW exp=Expression;
27
28
29
+ ClassDeclaration:
30
+ {ClassDeclaration}
31
+ CLASS (
32
+ body=Block |
33
+ (EXTENDS extend=Expression body=Block?) |
34
+ (name=(Id | Property) (EXTENDS extend=Expression)? body=Block)
35
+ )?;
36
+
28
37
Expression:
29
38
Postfix;
30
39
@@ -324,7 +333,7 @@ terminal RETURN: 'return';
324
333
terminal RPAREN: ')';
325
334
terminal STATEMENT: 'dummy STATEMENT';
326
335
terminal STRING: '"' (('a'..'z') | ' ')* '"';
327
- terminal SUPER: 'dummy SUPER ';
336
+ terminal SUPER: 'super ';
328
337
terminal SWITCH: 'dummy SWITCH';
329
338
terminal TERMINATOR: '\n'+;
330
339
terminal THEN: 'dummy THEN';
You can’t perform that action at this time.
0 commit comments