/ src / script / parsing.h
parsing.h
 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.h>
 9  
10  #include <string>
11  
12  namespace script {
13  
14  /** Parse a constant.
15   *
16   * If sp's initial part matches str, sp is optionally updated to skip that part, and true is returned.
17   * Otherwise sp is unmodified and false is returned.
18   */
19  bool Const(const std::string& str, std::span<const char>& sp, bool skip = true);
20  
21  /** Parse a function call.
22   *
23   * If sp's initial part matches str + "(", and sp ends with ")", sp is updated to be the
24   * section between the braces, and true is returned. Otherwise sp is unmodified and false
25   * is returned.
26   */
27  bool Func(const std::string& str, std::span<const char>& sp);
28  
29  /** Extract the expression that sp begins with.
30   *
31   * This function will return the initial part of sp, up to (but not including) the first
32   * comma or closing brace, skipping ones that are surrounded by braces. So for example,
33   * for "foo(bar(1),2),3" the initial part "foo(bar(1),2)" will be returned. sp will be
34   * updated to skip the initial part that is returned.
35   */
36  std::span<const char> Expr(std::span<const char>& sp);
37  
38  } // namespace script
39  
40  #endif // BITCOIN_SCRIPT_PARSING_H