-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.lark
More file actions
73 lines (43 loc) · 1.74 KB
/
grammar.lark
File metadata and controls
73 lines (43 loc) · 1.74 KB
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
%import common.DIGIT -> DIGIT
%import common.LETTER -> LETTER
%import common.HEXDIGIT -> HEXDIGIT
%import common.SIGNED_INT -> SIGNED_INT
%import common.WS -> WS
%import common.SIGNED_NUMBER -> SIGNED_NUMBER
%import common.ESCAPED_STRING -> ESCAPED_STRING
%ignore WS
// Commment
COMMENT: /\/\/[^\n]*/
%ignore COMMENT
// Boolean
BOOLEAN: "true" | "false"
// Colors
COLOR: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/
// Alignment
TEXT_ALIGNMENT: "auto" | "left" | "right" | "center"
// DPI measurements (density-independent pixels)
DP: /[0-9]+ *dp/
// Value: a generic type for any kind of value (used for properties and variable assignments)
?value: COLOR | SIGNED_INT | BOOLEAN | SIGNED_NUMBER | VARIABLE | ESCAPED_STRING | TEXT_ALIGNMENT | DP
// Variables
VARIABLE: /@[a-zA-Z0-9\-_]+/
variable_declaration: VARIABLE ":" value ";"
// Parts
PART: "main" | "scrollbar" | "indicator" | "knob" | "selected" | "items" | "cursor" | "customFirst" | "any"
part_declaration: "part." PART
// States
STATE: "default" | "checked" | "focused" | "focusKey" | "edited" | "hovered" | "pressed" | "scrolled" | "disabled" | "user1" | "user2" | "user3" | "user4" | "any"
state_declaration: "state." STATE
// Style
STYLE_NAME: /[a-zA-Z\-_]+/
style_property: /[a-zA-Z\-_]+/ ":" value ";" -> property
style_declaration: STYLE_NAME "{" [style_property*]* "}"
// Classes (widgets)
CLASS_NAME: /[a-zA-Z\-_]+/
class_style_declaration: [part_declaration | state_declaration]
class_style_declaration_list: class_style_declaration ["," class_style_declaration]*
class_style: STYLE_NAME ":" ["default" | class_style_declaration_list] ";"
class_declaration: "#" CLASS_NAME "{" class_style* "}"
// Main
?entry: variable_declaration | style_declaration | class_declaration
start: [entry]*