at_commands/parser/
command_grammar.rs

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
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// This module contains the pest grammar for AT commands.
use pest_derive::Parser;

#[derive(Parser)]
#[grammar_inline = r##"

input = { SOI ~ command ~ EOI }

command = { read | test | execute }

read =    { "AT" ~ optional_extension ~ command_name ~ "?" }
test =    { "AT" ~ optional_extension ~ command_name ~ "=?" }
execute = { "AT" ~ optional_extension ~ command_name ~ delimited_arguments? }

optional_extension = { "+"? }

delimited_arguments = { optional_argument_delimiter ~ arguments ~ optional_argument_terminator }
optional_argument_delimiter = { ("=" | ">")? }
optional_argument_terminator = { ";"? }

arguments = { parenthesized_argument_lists | argument_list? }
parenthesized_argument_lists = { ("(" ~ argument_list ~ ")")+ }
argument_list = { ((argument ~ ",")* ~ argument)? }
argument = { key_value_argument | primitive_argument }
key_value_argument = { primitive_argument ~ "=" ~ primitive_argument }
primitive_argument = @{ (!(WHITE_SPACE | "," | "=" | ">" | ")" | ";") ~ ASCII)* }

command_name = @{ ASCII_ALPHA_UPPER+ }

WHITESPACE = _{ WHITE_SPACE }
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }

"##]

pub struct Grammar {}