Class ScriptParser
- Author:
- Matthew Tropiano
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An error object added when an error is logged.Nested classes/interfaces inherited from class com.blackrook.rookscript.struct.Lexer.Parser
Lexer.Parser.Exception
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Iterator variable prefix (must be named in a way that is impossible to access).static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final String
Label prefix.static final int
Return false. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addErrorMessage
(String message) Adds an error message (along with current token info) to the error message list.String[]
protected int
Marks a label on the current command.boolean
parseEntryPoint
(Script script, boolean checkMode) Parses a single entry point (as though the token "entry" was already parsed).boolean
parseFunctionEntry
(Script script, boolean checkMode) Parses a single function entry (as though the token "function" was already parsed).boolean
parseScript
(Script script) Parses a script from the current token until the end of the token stream is reached or an error is encountered or an exception is thrown.parseScriptlet
(Script script) Parses a scriptlet into an existing script.protected <T> T
parseValueFor
(Class<T> clazz) void
readScript
(Script script) Starts parsing a script.Methods inherited from class com.blackrook.rookscript.struct.Lexer.Parser
currentToken, currentType, getLexer, getTokenInfoLine, matchType, nextToken
-
Field Details
-
LABEL_IF_CONDITIONAL
Label prefix.- See Also:
-
LABEL_IF_SUCCESS
Label prefix.- See Also:
-
LABEL_IF_FAILURE
Label prefix.- See Also:
-
LABEL_IF_END
Label prefix.- See Also:
-
LABEL_WHILE_CONDITIONAL
Label prefix.- See Also:
-
LABEL_WHILE_SUCCESS
Label prefix.- See Also:
-
LABEL_WHILE_END
Label prefix.- See Also:
-
LABEL_FOR_INIT
Label prefix.- See Also:
-
LABEL_FOR_CONDITIONAL
Label prefix.- See Also:
-
LABEL_FOR_STEP
Label prefix.- See Also:
-
LABEL_FOR_SUCCESS
Label prefix.- See Also:
-
LABEL_FOR_END
Label prefix.- See Also:
-
LABEL_EACH_START
Label prefix.- See Also:
-
LABEL_EACH_NEXT
Label prefix.- See Also:
-
LABEL_EACH_INIT
Label prefix.- See Also:
-
LABEL_EACH_STEP
Label prefix.- See Also:
-
LABEL_EACH_BODY
Label prefix.- See Also:
-
LABEL_EACH_END
Label prefix.- See Also:
-
LABEL_TERNARY_TRUE
Label prefix.- See Also:
-
LABEL_TERNARY_FALSE
Label prefix.- See Also:
-
LABEL_TERNARY_END
Label prefix.- See Also:
-
LABEL_SSAND_TRUE
Label prefix.- See Also:
-
LABEL_SSAND_FALSE
Label prefix.- See Also:
-
LABEL_SSAND_END
Label prefix.- See Also:
-
LABEL_SSOR_TRUE
Label prefix.- See Also:
-
LABEL_SSOR_FALSE
Label prefix.- See Also:
-
LABEL_SSOR_END
Label prefix.- See Also:
-
LABEL_COALESCE_START
Label prefix.- See Also:
-
LABEL_COALESCE_END
Label prefix.- See Also:
-
LABEL_CHECK_START
Label prefix.- See Also:
-
LABEL_CHECK_END
Label prefix.- See Also:
-
LABEL_SCRIPTLET_START
Label prefix.- See Also:
-
LABEL_SCRIPTLET_END
Label prefix.- See Also:
-
LABEL_ITERATOR_VAR
Iterator variable prefix (must be named in a way that is impossible to access).- See Also:
-
PARSEFUNCTIONCALL_FALSE
public static final int PARSEFUNCTIONCALL_FALSEReturn false.- See Also:
-
-
Constructor Details
-
ScriptParser
Creates a new script parser.- Parameters:
lexer
- the lexer to fetch tokens from.
-
-
Method Details
-
getErrorMessages
- Returns:
- the list of error messages emitted by this parser.
-
getErrors
- Returns:
- the list of error messages emitted by this parser.
- Since:
- 1.11.0, this is exposed to implementors.
-
readScript
Starts parsing a script.This is equivalent to:
nextToken(); parseScript(script); ErrorMessage[] errors = getErrorMessages(); if (errors.length > 0) throw new ScriptParseException(errors);
- Parameters:
script
- the script to start adding compiled code to.- Throws:
ScriptParseException
- if any errors were logged.- Since:
- 1.11.0, this calls
parseScript(Script)
-
parseScript
Parses a script from the current token until the end of the token stream is reached or an error is encountered or an exception is thrown.If this function returns false, then one or more errors may have been encountered, and they should be fetched from
getErrorMessages()
for display or logging.- Parameters:
script
- the script to emit commands and entries to.- Returns:
- true if no errors were encountered, or false if a parse error occurred and parsing was halted.
- Since:
- 1.11.0
-
parseScriptlet
Parses a scriptlet into an existing script. A scriptlet is either a single function call statement (scoped or not), or a set of statements between curly braces. Scriptlets are demarcated in the output script with labels.Use caution when parsing scriptlets - tokens are parsed and emitted as-is as though they were part of a full script!
[Scriptlet] := [IDENTIFIER] [FunctionCall] "{" [StatementList] "}"
- Parameters:
script
- the script to emit commands into.- Returns:
- the index of the scriptlet starting point if no errors were encountered, or null if a parse error occurred and parsing was halted.
- Since:
- 1.11.0, this has been made public.
-
parseFunctionEntry
Parses a single function entry (as though the token "function" was already parsed). The function entry is added to the script, and the label and the rest of the function are emitted into the script.Use caution when parsing functions - tokens are parsed and emitted as-is as though they were part of a full script!
[FunctionEntry] := [IDENTIFIER] "(" [FunctionArgumentList] ")" "{" [StatementList] "}"
If this method returns false, a parse error occurred and you must check for any emitted errors via
getErrorMessages()
.- Parameters:
script
- the script to add the function to and emit commands into.checkMode
- if true, the function is parsed as though "check" was prepended to the function entry.- Returns:
- true if no errors were encountered, or false if a parse error occurred and parsing was halted.
- Since:
- 1.11.0, this has been made public.
-
parseEntryPoint
Parses a single entry point (as though the token "entry" was already parsed). The entry point is added to the script, and the label and the rest of the entry are emitted into the script.Use caution when parsing entry points - tokens are parsed and emitted as-is as though they were part of a full script!
[ScriptEntry] := [ScriptName] "(" [ScriptEntryArgumentList] ")" "{" [StatementList] "}"
If this method returns false, a parse error occurred and you must check for any emitted errors via
getErrorMessages()
.- Parameters:
script
- the script to add the entry point to and emit commands into.checkMode
- if true, the entry point is parsed as though "check" was prepended to the entry.- Returns:
- true if no errors were encountered, or false if a parse error occurred and parsing was halted.
- Since:
- 1.11.0, this has been made public.
-
addErrorMessage
Adds an error message (along with current token info) to the error message list.- Parameters:
message
- the error message.- Since:
- 1.11.0, this is exposed as a protected method.
-
parseValueFor
-
mark
Marks a label on the current command.- Parameters:
currentScript
- the current script.label
- the label to set for the current command index.- Returns:
- the command index marked.
-