chromium/third_party/openscreen/src/tools/cddl/parse.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "tools/cddl/parse.h"

#include <unistd.h>

#include <algorithm>
#include <iostream>
#include <memory>
#include <sstream>
#include <utility>
#include <vector>

#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "tools/cddl/logging.h"

static_assert;

// All of the parsing methods in this file that operate on Parser are named
// either Parse* or Skip* and are named according to the CDDL grammar in
// grammar.abnf.  Similarly, methods like ParseMemberKey1 attempt to parse the
// first choice in the memberkey rule.
struct Parser {};

AstNode* AddNode(Parser* p,
                 AstNode::Type type,
                 std::string_view text,
                 AstNode* children = nullptr) {}

bool IsBinaryDigit(char x) {}

// Determines if the given character matches regex '[a-zA-Z@_$]'.
bool IsExtendedAlpha(char x) {}

bool IsNewline(char x) {}

bool IsWhitespaceOrSemicolon(char c) {}

std::string_view SkipNewline(std::string_view view) {}

std::optional<std::string> ParseTypeKeyFromComment(Parser* p);

// Skips over a comment that makes up the remainder of the current line.
std::string_view SkipComment(std::string_view view, bool skip_type_key = true) {}

void SkipWhitespaceImpl(Parser* p, bool skip_type_key = true) {}

void SkipWhitespace(Parser* p, bool skip_comments = true) {}

// This is only used for the start of the file to avoid losing the first type
// key.
void SkipStartWhitespace(Parser* p) {}

bool TrySkipNewline(Parser* p) {}

bool TrySkipCharacter(Parser* p, char c) {}

enum class AssignType {};

AssignType ParseAssignmentType(Parser* p) {}

AstNode* ParseType1(Parser* p);
AstNode* ParseType(Parser* p, bool skip_comments = true);
AstNode* ParseId(Parser* p);

void SkipUint(Parser* p) {}

AstNode* ParseNumber(Parser* p) {}

AstNode* ParseText(Parser* p) {}

AstNode* ParseBytes(Parser* p) {}

// Returns whether |c| could be the first character in a valid "value" string.
// This is not a guarantee however, since 'h' and 'b' could also indicate the
// start of an ID, but value needs to be tried first.
bool IsValue(char c) {}

AstNode* ParseValue(Parser* p) {}

// Determines whether an occurrence operator (such as '*' or '?') prefacing
// the group definition occurs before the next whitespace character, and
// creates a new Occurrence node if so.
AstNode* ParseOccur(Parser* p) {}

std::optional<std::string> ParseTypeKeyFromComment(Parser* p) {}

AstNode* ParseMemberKeyFromComment(Parser* p) {}

AstNode* ParseMemberKey1(Parser* p) {}

AstNode* ParseMemberKey2(Parser* p) {}

AstNode* ParseMemberKey3(Parser* p) {}

// Iteratively tries all valid member key formats, retuning a Node representing
// the member key if found or nullptr if not.
AstNode* ParseMemberKey(Parser* p) {}

AstNode* ParseGroupEntry(Parser* p);

bool SkipOptionalComma(Parser* p) {}

// Parse the group contained inside of other brackets. Since the brackets around
// the group are optional inside of other brackets, we can't directly call
// ParseGroupEntry(...) and instead need this wrapper around it.
AstNode* ParseGroupChoice(Parser* p) {}

AstNode* ParseGroup(Parser* p) {}

// Parse optional range operator .. (inlcusive) or ... (exclusive)
// ABNF rule: rangeop = "..." / ".."
AstNode* ParseRangeop(Parser* p) {}

// Parse optional control operator .id
// ABNF rule: ctlop = "." id
AstNode* ParseCtlop(Parser* p) {}

AstNode* ParseType2(Parser* p) {}

AstNode* ParseType1(Parser* p) {}

// Different valid types for a call are specified as type1 / type2, so we split
// at the '/' character and process each allowed type separately.
AstNode* ParseType(Parser* p, bool skip_comments) {}

AstNode* ParseId(Parser* p) {}

AstNode* UpdateNodesForGroupEntry(Parser* p,
                                  Parser* p_speculative,
                                  AstNode* occur,
                                  AstNode* member_key,
                                  AstNode* type) {}

// Parse a group entry of form <id_num>: <type> ; <name>
AstNode* ParseGroupEntryWithNameInComment(Parser* p) {}

AstNode* ParseGroupEntryWithNameAsId(Parser* p) {}

// NOTE: This should probably never be hit, why is it in the grammar?
AstNode* ParseGroupEntryWithGroupReference(Parser* p) {}

// Recursively parse a group entry that's an inline-defined group of the form
// '(...<some contents>...)'.
AstNode* ParseGroupEntryWithInlineGroupDefinition(Parser* p) {}

// Recursively parse the group assignemnt.
AstNode* ParseGroupEntry(Parser* p) {}

AstNode* ParseRule(Parser* p) {}

// Iteratively parse the CDDL spec into a tree structure.
ParseResult ParseCddl(std::string_view data) {}

// Recursively print out the AstNode graph.
void DumpAst(AstNode* node, int indent_level) {}