parsing.h raw

   1  // Copyright (c) 2018-present The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef BITCOIN_SCRIPT_PARSING_H
   6  #define BITCOIN_SCRIPT_PARSING_H
   7  
   8  #include <span>
   9  #include <string>
  10  
  11  namespace script {
  12  
  13  /** Parse a constant.
  14   *
  15   * If sp's initial part matches str, sp is optionally updated to skip that part, and true is returned.
  16   * Otherwise sp is unmodified and false is returned.
  17   */
  18  bool Const(const std::string& str, std::span<const char>& sp, bool skip = true);
  19  
  20  /** Parse a function call.
  21   *
  22   * If sp's initial part matches str + "(", and sp ends with ")", sp is updated to be the
  23   * section between the braces, and true is returned. Otherwise sp is unmodified and false
  24   * is returned.
  25   */
  26  bool Func(const std::string& str, std::span<const char>& sp);
  27  
  28  /** Extract the expression that sp begins with.
  29   *
  30   * This function will return the initial part of sp, up to (but not including) the first
  31   * comma or closing brace, skipping ones that are surrounded by braces. So for example,
  32   * for "foo(bar(1),2),3" the initial part "foo(bar(1),2)" will be returned. sp will be
  33   * updated to skip the initial part that is returned.
  34   */
  35  std::span<const char> Expr(std::span<const char>& sp);
  36  
  37  } // namespace script
  38  
  39  #endif // BITCOIN_SCRIPT_PARSING_H
  40