breakpad = { SOI ~ module ~ (NEWLINE ~ record)* ~ NEWLINE* ~ EOI }
record = { module | info | file | func_lines | public | stack }
func_lines = { func ~ (NEWLINE ~ !record ~ line)* }
stack = { stack_cfi | stack_win }

// MODULE record
// Example: "MODULE Linux x86 D3096ED481217FD4C16B29CD9BC208BA0 firefox-bin"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#module-records>
module = { "MODULE" ~ os ~ arch ~ debug_id ~ name }
os = @{ ident }
arch = @{ ident }
debug_id = @{ ASCII_HEX_DIGIT{32,40} }

// INFO record
// Example: "INFO CODE_ID C22813AC7D101E2FF2598697023E1F28"
// no documentation available
info = { "INFO" ~ (info_code_id | info_other) }
info_code_id = { "CODE_ID" ~ code_id ~ name? }
info_other = { ident ~ text }
code_id = @{ hex }

// FILE record
// Example: "FILE 2 /home/jimb/mc/in/browser/app/nsBrowserApp.cpp"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#file-records>
file = { "FILE" ~ file_id ~ name }
file_id = @{ dec }

// FUNC record
// Example: "FUNC m c184 30 0 nsQueryInterfaceWithError::operator()(nsID const&, void**) const"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#func-records>
func = { "FUNC" ~ multiple? ~ addr ~ size ~ param_size ~ name? }
param_size = @{ hex }

// LINE record (part of functions)
// Example: "c184 7 59 4"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#line-records>
line = { addr ~ size ~ line_num ~ file_id }
line_num = @{ "-"? ~ dec }

// PUBLIC record
// Example: "PUBLIC m 2160 0 Public2_1"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#public-records>
public = { "PUBLIC" ~ multiple? ~ addr ~ param_size ~ name? }

// STACK WIN record
// Example: "STACK WIN 4 2170 14 1 0 0 0 0 0 1 $eip 4 + ^ = $esp $ebp 8 + = $ebp $ebp ^ ="
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#stack-win-records>
stack_win = { "STACK WIN" ~ text }

// STACK CFI record
// Example: "STACK CFI INIT 804c4b0 40 .cfa: $esp 4 + $eip: .cfa 4 - ^"
// see <https://github.com/google/breakpad/blob/master/docs/symbol_files.md#stack-cfi-records>
stack_cfi = { "STACK CFI" ~ text }

// helpers
ident = @{ XID_START ~ XID_CONTINUE{,31} }
name = @{ text }
text = @{ char+ }
addr = @{ hex }
size = @{ hex }
dec = @{ ASCII_DIGIT+ }
hex = @{ ASCII_HEX_DIGIT+ }
char = @{ !NEWLINE ~ ANY }
multiple = { "m" }

// parser config
WHITESPACE = _{ " " | "\t" }

