import Program from './core/Program'

export default class ExpressionRunner {
  /**
   * Runs an expression with parameters
   *
   * @param source Expression source
   * @param params Expression parameters
   * @returns The result of the expression
   */
  static async run (source, params) {
    const delegate = this.getDelegate(source)
    return await delegate.invoke(params)
  }

  /**
   * Gets the delegate for the expression
   *
   * @param source Expression source
   * @returns A delegate to invoke
   */
  static getDelegate (source) {
    // Parse the source and return a delegate
    return new Program(source).parse()
  }
}
