��工具
 * @param {Rule} rule 解析规则
 * @return {ASTNode|undefined|false} 解析得到 AST
 */
export function run (walker, rule) {
  return rule[0](walker, rule[1])
}

/**
 * 顺序执行规则列表，当其中某条规则解析错误时，则整体解析失败，同时回滚字符串解析下标
 *
 * @param {Walker} walker 表达式字符串读取工具
 * @param {Array.<Rule>} rules 解析规则列表
 * @return {ASTNode|false} 解析得到的 AST
 */
export const seq = restorable((walker, rules) => {
  if (typeof rules[0] === 'function') {
    return run(walker, rules)
  }
  let results = []
  for (let node of rules) {
    let result = run(walker, node)
    if (result === false) {
      return false
    }
    results.push(result)
  }
  return results
})

/**
 * 顺序执行规则列表，当其中某条规则解析成功时，则直接返回该解析结果，全部规则解析失败时，则整体解析失败，同时回滚字符串解析下标
 *
 * @param {Walker} walker 表达式字符串读取工具
 * @param {Array.<Rule>} rules 解析规则列表
 * @return {ASTNode|false} 解析得到的 AST
 */
export const or = (walker, rules) => {
  let index = walker.index
  for (let node of rules) {
    let result = run(walker, node)
    if (result !== false) {
      return result
    }
    walker.index = index
  }
  return false
}

/**
 * zero or more
 *
 * @param {Walker} walker 表达式字符串读取工具
 * @param {Rule} rule 解析规则
 * @return {ASTNode|undefined} 解析得到的 AST
 */
export const any = (walker, rule) => {
  let results = []
  while (!walker.end()) {
    let result = seq(walker, rule)
    if (result === false) {
      break
    }
    results.push(result)
  }
  return results
}

/**
 * one or more
 *
 * @param {Walker} walker 表达式字符串读取工具
 * @param {Rule} rule 解析规则
 * @return {ASTNode|false} 解析得到的 AST
 */
export const some = (walker, rule) => {
  let results = []
  while (!walker.end()) {
    let result = seq(walker, rule)
    if (result =