remove obsolete comment
[sbp.git] / tests / java15.g
1
2 s = ws! CompilationUnit ws!
3
4 CompilationUnit =
5    CompilationUnit:: Package? Import* (InterfaceDecl|ClassDecl)*  /ws
6
7 Package = Annotations?! "package" PackageName ";" /ws
8
9 Annotations = ()
10
11 Import = "import"           TypeName       ";" /ws
12        | "import"          (TypeName ".*") ";" /ws
13        | "import" "static"  TypeName       ";" /ws
14        | "import" "static" (TypeName ".*") ";" /ws
15
16 TypeName      = Identifier +/ "."
17 PackageName   = Identifier +/ "."
18
19 Modifiers     = Modifiers:: ("public" | "protected" | "private") (ws! "abstract")?
20               | Modifiers:: "abstract"
21
22 ClassDecl     = Class::     Modifiers "class"     TypeDecl ClassBody /ws
23 InterfaceDecl = Interface:: Modifiers "interface" TypeDecl ClassBody /ws
24
25 TypeDecl =                   Identifier
26          | GenericTypeDecl:: Identifier "<" (TypeArg +/ comma) ">" /ws
27
28 TypeArg =                Identifier
29         | Extends::      Identifier "extends" Type  /ws
30         | Super::        Identifier "super"   Type  /ws
31         | Exist::        "?"
32         | ExistExtends:: "?" "extends" Type
33         | Intersect::    Identifier "&" Type
34
35 ClassBody = "{" (BodyDecl +/ ws) "}" /ws
36           | "{"     ws!          "}"
37
38 BodyDecl = FieldDecl | MethodDecl | ClassDecl | InterfaceDecl
39
40 FieldDecl  = Field::  Modifiers Type Identifier ";" /ws
41 MethodDecl = Method:: MethodHeader (";" | MethodBody) /ws
42
43 MethodHeader  = MethodHeader:: Modifiers Type Identifier Args /ws
44 MethodBody    = "{" "}" /ws
45
46 Args = "(" (Arg+/comma) ")" /ws
47      | "(" ws! ")"
48 Arg = Arg:: Type Identifier /ws
49
50 Type        = BareType | GenericType | ArrayType
51 BareType    = Type::        TypeName | "boolean" | "int" | "double" | "float" | "char" | "short" | "long" | "void"
52 GenericType = GenericType:: TypeName "<" (Type+/comma) ">" /ws
53 ArrayType   = ArrayOf::     (BareType | GenericType) "[]" /ws
54
55 ws = [\r\n ]**
56 comma = ws! "," ws!
57
58 JavaLetter = [a-zA-Z_$]
59 Identifier = JavaLetter++
60            &~ ([0-9]! ~[]*!)
61            &~ Keyword
62            &~ BooleanLiteral
63            &~ NullLiteral
64 BooleanLiteral = "true" | "false"
65 NullLiteral    = "null"
66
67 // http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#29542
68 //
69 //HexDigit = 
70 //UnicodeEscape = "\\u" [0-9] [0-9] [0-9] [0-9]      // this is valid even inside strings/comments
71 //
72 //// Ctrl-Z
73 //// Unicode escapes (including \\u garbage)
74 //
75 //WhiteSpace = [\r\n\t ]
76 //Comment = "/*" (~[]* &~ (~[]*! "*/" ~[]*!)) "*/"
77 //        | "//" [^\r\n]* [\r\n]!
78 //
79 //Token   = Identifier | Keyword | Literal | Separator | Operator
80 //
81 //
82 //Literal =
83 //      | IntegerLiteral
84 //      | FloatingPointLiteral
85 //      | BooleanLiteral
86 //      | CharacterLiteral
87 //      | StringLiteral
88 //      | NullLiteral
89 //
90 //
91 //FloatLiteral        = (DecimalFloatLiteral > HexFloatLiteral) [dDfF]?
92 //DecimalFloatLiteral =             [0-9]++       "." [0-9]++       [ep] [+-]? [0-9]++
93 //HexFloatLiteral     = ("0x"|"0X") [0-9a-fA-F]++ "." [0-9a-fA-F]++ [ep] [+-]? [0-9a-fA-F]++
94 //
95 //CharLiteral   = "'"  ([^\\\'] | "\\" ~[])  "'"
96 //StringLiteral = "\"" ([^\\\"] | "\\" ~[])* "\""
97 //
98 //IntegerLiteral = (DecimalLiteral | OctalLiteral | HexLiteral) [lL]?
99 //DecimalLiteral = [0-9]++     &~ OctalLiteral
100 //OctalLiteral   = "0" [0-9]++ &~ "0"
101 //HexLiteral     = ("0x"|"0X") [0-9a-fA-F]++
102 //
103
104 Keyword = 
105          "abstract"   | "continue"   | "for"          | "new"         | "switch"
106        | "assert"     | "default"    | "if"           | "package"     | "synchronized"
107        | "boolean"    | "do"         | "goto"         | "private"     | "this"
108        | "break"      | "double"     | "implements"   | "protected"   | "throw"
109        | "byte"       | "else"       | "import"       | "public"      | "throws"
110        | "case"       | "enum"       | "instanceof"   | "return"      | "transient"
111        | "catch"      | "extends"    | "int"          | "short"       | "try"
112        | "char"       | "final"      | "interface"    | "static"      | "void"
113        | "class"      | "finally"    | "long"         | "strictfp"    | "volatile"
114        | "const"      | "float"      | "native"       | "super"       | "while"
115
116 // We don't obey this: 
117 //
118 //   "The longest possible translation is used at each step, even if
119 //   "the result does not ultimately make a correct program while
120 //   "another lexical translation would. Thus the input characters
121 //   "a--b are tokenized (-3.5) as a, --, b, which is not part of any
122 //   "grammatically correct program, even though the tokenization a,
123 //   "-, -, b could be part of a grammatically correct program.