constantParser function

Parser<Expression<Object>> constantParser(
  1. List<Constant> constants
)

Implementation

Parser<Expression> constantParser(List<Constant> constants) {
  return ChoiceParser(
        constants.map(
          (constant) => string(constant.name) & (letter() | digit()).not(),
        ),
      )
      .flatten('constant expected')
      .trim()
      .map(
        (name) => Value(
          constants.firstWhere((constant) => constant.name == name).value,
        ),
      );
}