 |
Gorgon Game Engine
|
Go to the documentation of this file. 1 #include "../../Scripting.h"
3 namespace Gorgon {
namespace Scripting {
namespace Compilers {
10 char allowed[] = {args...};
11 int elements =
sizeof...(args);
13 auto errstr = [&] ()-> std::string {
14 std::string ret =
"Expected ";
15 for(
int i = 0; i < elements; i++) {
19 ret.push_back(allowed[i]);
25 if((
int)input.length() <= ch) {
26 throw ParseError({ExceptionType::UnexpectedToken, errstr() +
", end of string encountered.", ch, 0});
31 for(
int i = 0; i <
sizeof...(args); i++) {
38 throw ParseError({ExceptionType::UnexpectedToken, errstr() +
", found: " + input.substr(ch, 1), ch, 0});
54 for(; ch < (int)input.size(); ch++) {
72 else if(c >=
'0' && c <=
'9') {
74 num = (num << 4) + (c -
'0');
76 else if(tolower(c) >=
'a' && tolower(c) <=
'f') {
78 num = (num << 4) + (tolower(c) -
'a' + 10);
81 throw ParseError{ExceptionType::UnexpectedToken,
"Invalid escape sequence: \\" + input.substr(ch, 1), ch, 0};
88 ret.push_back((
char)num);
97 else if(c ==
'"' && quotes == 2) {
100 else if(c ==
'\'' && quotes == 1) {
void ASTToSVG(const std::string &line, ASTNode &tree, const std::vector< std::string > &compiled={}, bool show=false)
Converts given AST to an SVG file.
Definition: AST.cpp:88
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
constexpr Type Data
Data resource.
Definition: GID.h:164
std::string Replace(std::string str, const std::string &find, const std::string &replace)
String replace that does not use regex.
Definition: String.h:349
@ Operator
This node represents an operator. All operators in GorgonScript are left associative and binary.
Definition: AST.h:46
void PrintAST(ASTNode &tree)
Recursively prints an AST.
Definition: AST.cpp:120
std::string ExtractQuotes(const std::string &input, int &ch)
Extracts a string that is in quotes.
Definition: Utils.h:44
@ Identifier
This node is an identifier.
Definition: AST.h:40
@ Literal
This node represents a literal. Literal member of ASTNode should be set.
Definition: AST.h:25
float Float
Represents floating point data type.
Definition: Types.h:16
unsigned Compile(ASTNode *tree)
This function compiles given abstract syntax tree, returns the number of instructions generated.
Definition: AST.cpp:355
@ Keyword
This node is a keyword call.
Definition: AST.h:57
int GetPrecedence(const std::string &op)
Returns the precedence of the given operator.
Definition: Language.h:12
@ FunctionCall
This node represents a function call.
Definition: AST.h:30
bool IsReady() const
If this function returns true, it is ok to use instructions from the list.
Definition: AST.h:127
void Finalize()
Definition: AST.h:129
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
const Scripting::Type & Namespace()
Definition: Reflection.h:315
bool isspace(Glyph g)
Definition: Font.cpp:96
Type * ParameterTemplateType()
Definition: Runtime.cpp:8
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
uint32_t Char
Definition: Types.h:46
virtual void Finalize() override
Finalizes the compilation.
@ Variable
This node represents a variable identifier.
Definition: AST.h:43
@ MethodCall
Same as function call, this just calls method variant if it exists, if not it will print out return v...
Definition: AST.h:34
std::string Disassemble(const Instruction *)
Disassembles the given instruction.
Definition: Generator.cpp:55
virtual unsigned Compile(const std::string &input, unsigned long pline) override
Asks the compiler to compile the given input.
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
DefineEnumStringsCM(StaticMember, MemberType, {StaticMember::RegularType, "RegularType"}, {StaticMember::EventType, "EventType"}, {StaticMember::EnumType, "EnumType"}, {StaticMember::Namespace, "Namespace"}, {StaticMember::DataMember, "DataMember"}, {StaticMember::Function, "Function"}, {StaticMember::Constant, "Constant"},)
std::string ToLower(std::string str)
Converts the given string to lowercase.
Definition: String.h:416
bool operator!=(PointList< P_ > &left, const PointList< P_ > &right)
Comparison: this operation is expensive: O(n).
Definition: PointList.h:391
@ Member
This node represents a membership. Membership should be parsed as left associative.
Definition: AST.h:37
@ Assignment
This node is an assignment. This node should be top level.
Definition: AST.h:60
bool operator==(PointList< P_ > &left, const PointList< P_ > &right)
Comparison: this operation is expensive: O(n).
Definition: PointList.h:385
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
std::set< std::string, String::CaseInsensitiveLess > KeywordNames
Definition: Scripting.cpp:13
@ Index
This node represents an indexing operation.
Definition: AST.h:50
std::vector< Instruction > List
The instructions that are compiled.
Definition: Compilers.h:51
Type
Definition: Shader.h:14
@ Empty
This node is empty, possibly a placeholder for an identifier.
Definition: AST.h:63
@ List
List of expressions to be compiled.
Definition: AST.h:66
@ Construct
This node is a constructor node.
Definition: AST.h:54
int CheckInputFor(const std::string &input, int &ch, P_ ...args)
Checks if the input string contains one of the given characters at current point.
Definition: Utils.h:9
NodeType
Node type.
Definition: AST.h:23