mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-22 19:30:36 +00:00
Rez: "data" declarations
This commit is contained in:
parent
c93cb8feae
commit
701c6d21bc
@ -55,6 +55,8 @@ add_executable(Rez
|
||||
|
||||
ResourceCompiler.cc
|
||||
ResourceCompiler.h
|
||||
|
||||
ResSpec.h
|
||||
)
|
||||
target_link_libraries(Rez ResourceFiles ${Boost_LIBRARIES})
|
||||
|
||||
|
24
Rez/ResSpec.h
Normal file
24
Rez/ResSpec.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef REZSPEC_H
|
||||
#define REZSPEC_H
|
||||
|
||||
#include "ResType.h"
|
||||
#include <string>
|
||||
|
||||
class ResSpec : public ResRef
|
||||
{
|
||||
int attr_;
|
||||
std::string name_;
|
||||
|
||||
public:
|
||||
ResSpec() {}
|
||||
ResSpec(ResType type, int id, int attr = 0, std::string name = "")
|
||||
: ResRef(type, id), attr_(attr), name_(name)
|
||||
{}
|
||||
|
||||
int& attr() { return attr_; }
|
||||
int attr() const { return attr_; }
|
||||
std::string& name() { return name_; }
|
||||
const std::string& name() const { return name_; }
|
||||
};
|
||||
|
||||
#endif // REZSPEC_H
|
@ -169,6 +169,11 @@ RezSymbol RezLexer::nextToken()
|
||||
static std::unordered_map<std::string, memfun> keywords = {
|
||||
KEYWORD(TYPE, "type"),
|
||||
KEYWORD(RESOURCE, "resource"),
|
||||
KEYWORD(DATA, "data"),
|
||||
KEYWORD(READ, "read"),
|
||||
KEYWORD(INCLUDE, "include"),
|
||||
KEYWORD(CHANGE, "change"),
|
||||
KEYWORD(DELETE, "delete"),
|
||||
|
||||
KEYWORD(ARRAY,"array"),
|
||||
KEYWORD(SWITCH, "switch"),
|
||||
|
@ -43,6 +43,13 @@
|
||||
|
||||
%token TYPE "type";
|
||||
%token RESOURCE "resource";
|
||||
%token DATA "data";
|
||||
%token READ "read";
|
||||
%token INCLUDE "include";
|
||||
%token CHANGE "change";
|
||||
%token DELETE "delete";
|
||||
|
||||
|
||||
%token ARRAY "array";
|
||||
%token SWITCH "switch";
|
||||
%token CASE "case";
|
||||
@ -95,6 +102,7 @@
|
||||
%code requires {
|
||||
#include "ResourceDefinitions.h"
|
||||
#include "Expression.h"
|
||||
#include "ResSpec.h"
|
||||
|
||||
#define YY_NULLPTR nullptr
|
||||
class RezLexer;
|
||||
@ -166,6 +174,7 @@
|
||||
rez : %empty
|
||||
| rez type_definition ";"
|
||||
| rez resource ";"
|
||||
| rez data ";"
|
||||
;
|
||||
|
||||
type_definition : "type" type_spec
|
||||
@ -411,18 +420,23 @@ string_expression1 : stringlit { $$ = std::make_shared<StringExpr>($1); }
|
||||
{ $$ = std::make_shared<ReadExpr>($string_expression); }
|
||||
;
|
||||
|
||||
resource : "resource" res_type "(" expression resource_attributes ")" "{" resource_body "}"
|
||||
resource : "resource" res_spec "{" resource_body "}"
|
||||
{
|
||||
int id = $expression->evaluateInt(nullptr);
|
||||
world.addResource($res_type, id, $resource_body);
|
||||
world.addResource($res_spec, $resource_body);
|
||||
}
|
||||
;
|
||||
|
||||
%type <int> resource_attributes resource_attribute;
|
||||
resource_attributes : %empty { $$ = 0; }
|
||||
| resource_attributes "," resource_attribute { $$ = $1 | $3; }
|
||||
%type <ResSpec> res_spec;
|
||||
|
||||
res_spec : res_type "(" expression resource_attributes ")"
|
||||
{ $$ = $resource_attributes( ResSpec($res_type, $expression->evaluateInt(nullptr)) ); }
|
||||
|
||||
%type <std::function<ResSpec(ResSpec)>> resource_attributes ;
|
||||
resource_attributes : %empty { $$ = [](ResSpec s){ return s; }; }
|
||||
| resource_attributes "," IDENTIFIER { $$ = $1; }
|
||||
| resource_attributes "," string_expression { $$ = $1; }
|
||||
|
||||
;
|
||||
resource_attribute : IDENTIFIER { $$ = 0; } /* ### */
|
||||
|
||||
%type <CompoundExprPtr> resource_body resource_body1;
|
||||
resource_body : %empty { $$ = std::make_shared<CompoundExpr>(); }
|
||||
@ -438,4 +452,11 @@ resource_item : value { $$ = $1; }
|
||||
| IDENTIFIER "{" resource_body "}" { $$ = std::make_shared<CaseExpr>($IDENTIFIER, $resource_body); }
|
||||
;
|
||||
|
||||
|
||||
data : "data" res_spec "{" string_expression "}"
|
||||
{
|
||||
world.addData($res_spec, $string_expression->evaluateString(nullptr));
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
|
@ -26,13 +26,20 @@ TypeDefinitionPtr RezWorld::getTypeDefinition(ResType type, int id)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RezWorld::addResource(ResType type, int id, CompoundExprPtr body)
|
||||
void RezWorld::addResource(ResSpec spec, CompoundExprPtr body)
|
||||
{
|
||||
if(verboseFlag)
|
||||
std::cout << "RESOURCE " << type << "(" << id << ")" << std::endl;
|
||||
TypeDefinitionPtr def = getTypeDefinition(type, id);
|
||||
std::cout << "RESOURCE " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
|
||||
TypeDefinitionPtr def = getTypeDefinition(spec.type(), spec.id());
|
||||
ResourceCompiler compiler(def, body, verboseFlag);
|
||||
compiler.compile();
|
||||
|
||||
resources.addResource(Resource(type, id, compiler.resourceData()));
|
||||
resources.addResource(Resource(spec.type(), spec.id(), compiler.resourceData(), spec.name(), spec.attr()));
|
||||
}
|
||||
|
||||
void RezWorld::addData(ResSpec spec, const std::string &data)
|
||||
{
|
||||
if(verboseFlag)
|
||||
std::cout << "DATA " << spec.type() << "(" << spec.id() << ", " << "\"" << spec.name() << "\"" << spec.attr() << ")" << std::endl;
|
||||
resources.addResource(Resource(spec.type(), spec.id(), data, spec.name(), spec.attr()));
|
||||
}
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include "ResourceDefinitions.h"
|
||||
#include "Expression.h"
|
||||
#include "ResourceFiles.h"
|
||||
#include "ResSpec.h"
|
||||
|
||||
class RezWorld
|
||||
{
|
||||
@ -23,7 +25,8 @@ public:
|
||||
|
||||
TypeDefinitionPtr getTypeDefinition(ResType type, int id);
|
||||
|
||||
void addResource(ResType type, int id, CompoundExprPtr body);
|
||||
void addResource(ResSpec spec, CompoundExprPtr body);
|
||||
void addData(ResSpec spec, const std::string& data);
|
||||
|
||||
Resources& getResources() { return resources; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user