%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

// Comment

SINGLE_LINE_COMMENT: /\/\/[^\n]*/
MULTI_LINE_COMMENT: /\/\*([^*]|\*+[^*\/])*\*+\//
%ignore SINGLE_LINE_COMMENT
%ignore MULTI_LINE_COMMENT

// Boolean

BOOLEAN: "true" | "false"

// Main

INCLUDE_C: /#include <[\w\/.\-]+>/
DEFINE_C: /#define[^\n]+/

PROPERTY_NAME: /#?[a-zA-Z0-9_\-,]+/

QUOTE: "\""
QUOTED_TEXT: QUOTE /[^"]+/ QUOTE
quoted_text_array: QUOTED_TEXT ("," " "* QUOTED_TEXT)+
HEX_NUMBER: "0x" HEXDIGIT+
NUMBER: SIGNED_NUMBER | HEX_NUMBER
PHANDLE: /&[0-9a-zA-Z_\-]+/
C_VARIABLE: /[0-9a-zA-Z_]+/
VALUE: NUMBER | PHANDLE | C_VARIABLE
value: VALUE
values: VALUE+
array: NUMBER+

phandle_array_entry: "<" values ">"
phandle_array: phandle_array_entry ("," phandle_array_entry)+

property_value: quoted_text_array | QUOTED_TEXT | phandle_array | "<" value ">" | "<" values ">" | "[" array "]" | PHANDLE
device_property: PROPERTY_NAME ["=" property_value] ";"

NODE_ALIAS: /[a-zA-Z0-9_\-\/]+/
NODE_NAME: /[a-zA-Z0-9_\-\/]+/
NODE_ADDRESS: /[0-9a-zA-Z_]+/

device: (NODE_ALIAS ":")? NODE_NAME ("@" NODE_ADDRESS)? "{" (device | device_property)* "};"

dts_version: /[0-9a-zA-Z\-]+/

start: "/" dts_version "/;" (INCLUDE_C | DEFINE_C)* device+
