at_commands/parser/
command_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 commands.
6use pest_derive::Parser;
7
8#[derive(Parser)]
9#[grammar_inline = r##"
10
11input = { SOI ~ command ~ EOI }
12
13command = { read | test | execute }
14
15read =    { "AT" ~ optional_extension ~ command_name ~ "?" }
16test =    { "AT" ~ optional_extension ~ command_name ~ "=?" }
17execute = { "AT" ~ optional_extension ~ command_name ~ delimited_arguments? }
18
19optional_extension = { "+"? }
20
21delimited_arguments = { optional_argument_delimiter ~ arguments ~ optional_argument_terminator }
22optional_argument_delimiter = { ("=" | ">")? }
23optional_argument_terminator = { ";"? }
24
25arguments = { parenthesized_argument_lists | argument_list? }
26parenthesized_argument_lists = { ("(" ~ argument_list ~ ")")+ }
27argument_list = { ((argument ~ ",")* ~ argument)? }
28argument = { key_value_argument | primitive_argument }
29key_value_argument = { primitive_argument ~ "=" ~ primitive_argument }
30primitive_argument = @{ (!(WHITE_SPACE | "," | "=" | ">" | ")" | ";") ~ ASCII)* }
31
32command_name = @{ ASCII_ALPHA_UPPER+ }
33
34WHITESPACE = _{ WHITE_SPACE }
35COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }
36
37"##]
38
39pub struct Grammar {}