forked from software-engineering-amsterdam/latex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch-appendix.tex
97 lines (65 loc) · 2.82 KB
/
ch-appendix.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
% !TEX root = thesis.tex
\chapter{Concrete Syntax of CssCoco}
This appendix contains all rules presented in the Context Syntax section of the Expressing CSS Code Conventions chapter. The following two snippets present the lexer and parser rules, respectively. Both snippets are taken from the grammar file of CssCoco\footnote{\url{https://github.com/boryanagoncharenko/CssCoco/blob/master/csscoco/lang/syntax/coco.g4}}.
\begin{snippet}
\begin{verbatim}
Letter : [a-zA-Z] ;
EscapeSequence : "\\" "'" ;
Digit : ZeroDigit | NonZeroDigit ;
NonZeroDigit : [1-9] ;
ZeroDigit : [0] ;
Boolean : 'true' | 'True' | 'false' | 'False' ;
Identifier : (Letter)(Letter|Digit|'_'|'-')* ;
String : "'" (EscapeSequence | ~['])*? "'" ;
Integer : (ZeroDigit | NonZeroDigit Digit*) ;
Decimal : ( NonZeroDigit Digit* | ZeroDigit? ) '.' Digit+ ;
\end{verbatim}
\end{snippet}
The parser rules of CssCoco are presented in the next snippet.
\begin{snippet}
\begin{verbatim}
stylesheet : context* ;
context : Identifier ignore_clause? '{' convention* '}' ;
ignore_clause : 'ignore' (node_descriptor)+ (',' (node_descriptor)+)* ;
convention : 'forbid' pattern 'message' String
| 'find' pattern ('where' logic_expr)? ('require'|'forbid') logic_expr 'message' String
;
pattern : node_declaration (('in'|'next-to') node_declaration)*
| fork ('in' node_declaration)*
;
fork : '(' node_declaration (',' node_declaration)+ ')' ;
node_declaration : (Identifier '=')? semantic_node ;
node_descriptor : 'unique'? node_type ('{' (logic_expr|repeater) '}')? ;
repeater : Integer ',' Integer? | (',')? Integer ;
logic_expr : '(' logic_expr ')'
| 'not' logic_expr
| logic_expr 'and' logic_expr
| logic_expr 'or' logic_expr
| type_expr
| arithmetic_expr
;
type_expr : arithmetic_expr operator='is' Identifier
| node_descriptor+ ('before' | 'after') type_operand
| node_descriptor+ 'between' type_operand 'and' type_operand
;
type_operand : Identifier | semantic_node ;
arithmetic_expr : ('-'|'+') arithmetic_expr
| arithmetic_expr ('<'|'>'|'<='|'>='|'=='|'!=') arithmetic_expr
| arithmetic_expr ('in'|'not in'|'match'|'not match') arithmetic_expr
| call_expression
| element
;
element : Boolean | Decimal | Integer | String | list_ ;
call_expression : call_expression '.' call_expression
| Identifier ('(' (element | semantic_node ) ')')?
;
list_ : '[' list_element (',' list_element)* ']' ;
list_element : Integer | Decimal | String | semantic_node ;
node_type : '(' node_type ')'
| 'not' node_type
| node_type 'and' node_type
| node_type 'or' node_type
| Identifier
;
\end{verbatim}
\end{snippet}