class Compiler; class ErrorReporter; class Expression; class FunctionDeclaration; struct Module; struct Program; class ProgramElement; enumclass ProgramKind : int8_t; class Statement; class SymbolTable; class Type; class VarDeclaration; class Variable;
/** * Consumes .sksl text and converts it into an IR tree, encapsulated in a Program.
*/ class Parser { public:
Parser(Compiler* compiler, const ProgramSettings& settings,
ProgramKind kind,
std::unique_ptr<std::string> text);
~Parser();
private: class AutoDepth; class AutoSymbolTable; class Checkpoint;
/** * Return the next token, including whitespace tokens, from the parse stream.
*/
Token nextRawToken();
/** * Return the next non-whitespace token from the parse stream.
*/
Token nextToken();
/** * Push a token back onto the parse stream, so that it is the next one read. Only a single level * of pushback is supported (that is, it is an error to call pushback() twice in a row without * an intervening nextToken()).
*/ void pushback(Token t);
/** * Returns the next non-whitespace token without consuming it from the stream.
*/
Token peek();
/** * Checks to see if the next token is of the specified type. If so, stores it in result (if * result is non-null) and returns true. Otherwise, pushes it back and returns false.
*/ bool checkNext(Token::Kind kind, Token* result = nullptr);
/** * Behaves like checkNext(TK_IDENTIFIER), but also verifies that identifier is not a builtin * type. If the token was actually a builtin type, false is returned (the next token is not * considered to be an identifier).
*/ bool checkIdentifier(Token* result = nullptr);
/** * Reads the next non-whitespace token and generates an error if it is not the expected type. * The 'expected' string is part of the error message, which reads: * * "expected <expected>, but found '<actual text>'" * * If 'result' is non-null, it is set to point to the token that was read. * Returns true if the read token was as expected, false otherwise.
*/ bool expect(Token::Kind kind, constchar* expected, Token* result = nullptr); bool expect(Token::Kind kind, std::string expected, Token* result = nullptr);
/** * Behaves like expect(TK_IDENTIFIER), but also verifies that identifier is not a type. * If the token was actually a type, generates an error message of the form: * * "expected an identifier, but found type 'float2'"
*/ bool expectIdentifier(Token* result);
/** If the next token is a newline, consumes it and returns true. If not, returns false. */ bool expectNewline();
// Returns the range from `start` to the current parse position.
Position rangeFrom(Position start);
Position rangeFrom(Token start);
// these functions parse individual grammar rules from the current parse position; you probably // don't need to call any of these outside of the parser. The function declarations in the .cpp // file have comments describing the grammar rules.
void declarations();
/** * Parses an expression representing an array size. Reports errors if the array size is not * valid (out of bounds, not a literal integer). Returns true if an expression was * successfully parsed, even if that array size is not actually valid. In the event of a true * return, outResult always contains a valid array size (even if the parsed array size was not * actually valid; invalid array sizes result in a 1 to avoid additional errors downstream).
*/ bool arraySize(SKSL_INT* outResult);
Compiler& fCompiler;
ProgramSettings fSettings;
ErrorReporter* fErrorReporter; bool fEncounteredFatalError;
ProgramKind fKind;
std::unique_ptr<std::string> fText;
std::vector<std::unique_ptr<SkSL::ProgramElement>> fProgramElements;
Lexer fLexer; // current parse depth, used to enforce a recursion limit to try to keep us from overflowing the // stack on pathological inputs int fDepth = 0;
Token fPushback;
};
} // namespace SkSL
#endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.