at_commands/parser/
response_grammar.rs

1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/// This module contains the pest grammar for AT command responses.
6use pest_derive::Parser;
7
8#[derive(Parser)]
9#[grammar_inline = r##"
10
11input = { SOI ~ response ~ EOI }
12
13response = { ok | error | hardcoded_error | cme_error | success }
14
15ok = { "OK" }
16
17error = { "ERROR" }
18
19hardcoded_error = {
20    "NO CARRIER" |
21    "BUSY" |
22    "NO ANSWER" |
23    "DELAYED" |
24    "BLACKLIST"
25}
26
27cme_error = { "+CME ERROR:" ~ integer }
28integer = @{ ASCII_DIGIT+ }
29
30success = { optional_extension ~ command_name ~ delimited_arguments }
31optional_extension = { "+"? }
32
33delimited_arguments = { optional_argument_delimiter ~ arguments ~ optional_argument_terminator }
34optional_argument_delimiter = { ":" ? }
35optional_argument_terminator = { ";"? }
36
37arguments = { parenthesized_argument_lists | argument_list }
38parenthesized_argument_lists = { ("(" ~ argument_list ~ ")")+ }
39argument_list = {  ((argument ~ ",")* ~ argument)? }
40argument = { key_value_argument | primitive_argument }
41key_value_argument = { primitive_argument ~ "=" ~ primitive_argument }
42primitive_argument = @{ (!(WHITE_SPACE | "," | "=" | ")" | ";") ~ ASCII)* }
43
44command_name = @{ ASCII_ALPHA_UPPER+ }
45
46WHITESPACE = _{ WHITE_SPACE }
47COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }
48
49"##]
50
51pub struct Grammar {}