java.lang.Object
org.kink_lang.kink.internal.program.ast.Parser
A parser of Kink programs.
The parser converts a list of tokens to an AST.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
Parser
Constructs a parser.- Parameters:
locale
- the locale for error messages.
-
-
Method Details
-
parse
public <T> T parse(List<Token> tokens, Function<? super SeqExpr, ? extends T> onSucc, Function3<? super String, ? super Integer, ? super Integer, ? extends T> onError) Parses the token list to produce an AST.When parsing succeeds, the method calls
onSucc
with the AST and returns its result.When parsing results in an error, the method calls
onError
with the message, startPos, and endPos, then returns its result.The last element of
tokens
must be an instance ofEotToken
orErrorToken
.- Type Parameters:
T
- the result type of onSucc and onError.- Parameters:
tokens
- the token list of a Kink program.onSucc
- called when the parsing succeeds.onError
- called when the parsing results in a compile error.- Returns:
- the result of onSucc or onError.
- Throws:
IllegalArgumentException
- when the last element of thetokens
argument is not an EotToken nor an ErrorToken.
-