Function keyword

  • Parse keywords like let, case, and type.

      run(keyword("let"))("let")     => Ok()
    run(keyword("let"))("var") => Err ... (ExpectingKeyword("let")) ...
    run(keyword("let"))("letters") => Err ... (ExpectingKeyword("let")) ...

    Note: Notice the third case there! keyword actually looks ahead one character to make sure it is not a letter, number, or underscore. The goal is to help with parsers like this:

     succeed(x => x)
    .skip(keyword("let"))
    .skip(spaces)
    .apply(elmVar)
    .skip(spaces)
    .skip(symbol("="))

    The trouble is that spaces may chomp zero characters (to handle expressions like [1,2] and [ 1 , 2 ]) and in this case, it would mean letters could be parsed as let ters and then wonder where the equals sign is! Check out the token docs if you need to customize this!

    Parameters

    • kwd: string

    Returns Simple.Parser<Symbol>