parsing.h raw

   1  // Copyright (c) 2018-2022 The Limenka 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 LIMENKA_SCRIPT_PARSING_H
   6  #define LIMENKA_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 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, Span<const char>& sp);
  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, 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  Span<const char> Expr(Span<const char>& sp);
  37  
  38  } // namespace script
  39  
  40  #endif // LIMENKA_SCRIPT_PARSING_H
  41