pep8analysis: Fix no init call
[nit.git] / contrib / pep8analysis / src / parser / pep8.sablecc3
1 /*
2  * This file is part of the pep8analyser project.
3  *
4  * Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
5  *
6  * Inspired from the Nit language grammar by:
7  * Copyright 2008-2009 Jean Privat <jean@pryen.org>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 /* This grammar defines the Pep/8 language. */
23
24 /*****************************************************************************/
25 Helpers
26 /*****************************************************************************/
27
28 all = [0 .. 0xFF];
29 lowercase = ['a' .. 'z'];
30 uppercase = ['A' .. 'Z'];
31 digit = ['0' .. '9'];
32 letter = lowercase | uppercase | digit | '_';
33
34 tab = 9;
35 cr = 13;
36 lf = 10;
37 any = [all - [cr + lf]];
38
39 str_char
40         = [[any - '"'] + '\']
41         | '\' any;
42
43 eol_helper = cr lf | cr | lf; // This takes care of different platforms;
44
45 hex_digit = ['0' .. '9'] | ['A' .. 'F'] | ['a' .. 'f'];
46
47 /*****************************************************************************/
48 States
49 /*****************************************************************************/
50 initial;
51
52 /*****************************************************************************/
53 Tokens
54 /*****************************************************************************/
55
56 blank = (' ' | tab)+;
57
58 eol = eol_helper;
59
60 number = '-'? digit+;
61 float = digit* '.' digit+;
62 char = (''' [[any - '''] - '\'] ''')
63         | (''' '\' any ''')
64         | (''' '\' 'x' hex_digit hex_digit ''');
65 string = '"' str_char* '"';
66 hex = '0' ('x'|'X') hex_digit+;
67
68 colon = ':';
69 comma = ',';
70 comment = ';' any*;
71
72 tk_byte = '.' ('B'|'b') ('Y'|'y') ('T'|'t') ('E'|'e');
73 tk_word = '.' ('W'|'w') ('O'|'o') ('R'|'r') ('D'|'d');
74 tk_block = '.' ('B'|'b') ('L'|'l') ('O'|'o') ('C'|'c') ('K'|'k');
75 tk_ascii = '.' ('A'|'a') ('S'|'s') ('C'|'c') ('I'|'i') ('I'|'i');
76 tk_addrss = '.' ('A'|'a') ('D'|'d') ('D'|'d') ('R'|'r') ('S'|'s') ('S'|'s');
77 tk_equate = '.' ('E'|'e') ('Q'|'q') ('U'|'u') ('A'|'a') ('T'|'t') ('E'|'e');
78 tk_burn = '.' ('B'|'b') ('U'|'u') ('R'|'r') ('N'|'n');
79
80 end_block = '.' ('E'|'e') ('N'|'n') ('D'|'d') (any | eol_helper)*;
81
82 id = letter+;
83
84 /*****************************************************************************/
85 Ignored Tokens
86 /*****************************************************************************/
87
88 blank;
89
90 /*****************************************************************************/
91 Productions
92 /*****************************************************************************/
93 listing = [lines]:line* label_decl? end_block;
94
95 line
96         = {empty} label_decl? comment? eol
97         | {instruction} label_decl? instruction comment? eol
98         | {directive} label_decl? directive comment? eol;
99
100 label_decl = id colon;
101
102 instruction
103         = {unary} id
104         | {binary} id operand;
105
106 /* operands
107  * We will manage which operands are possible with each stmt at a higher level.
108  * This will allow better error messages and a cleaner model. */
109 operand
110         = {immediate} value
111         | {any} value comma id;
112
113 value
114         = {label} id
115         | {number} number
116         | {char} char
117         | {string} string
118         | {hex} hex;
119 directive
120         = {byte} tk_byte value
121         | {word} tk_word value
122         | {block} tk_block value
123         | {ascii} tk_ascii value
124         | {addrss} tk_addrss value
125         | {equate} tk_equate value
126         | {burn} tk_burn value;
127