From 701c6d21bce19986b4fa520214c673c2dd476a53 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Tue, 14 Oct 2014 02:19:26 +0200 Subject: [PATCH] Rez: "data" declarations --- Rez/CMakeLists.txt | 2 ++ Rez/ResSpec.h | 24 ++++++++++++++++++++++++ Rez/RezLexerNextToken.cc | 5 +++++ Rez/RezParser.yy | 35 ++++++++++++++++++++++++++++------- Rez/RezWorld.cc | 15 +++++++++++---- Rez/RezWorld.h | 5 ++++- 6 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 Rez/ResSpec.h diff --git a/Rez/CMakeLists.txt b/Rez/CMakeLists.txt index cd200af5fb..402ce60a18 100644 --- a/Rez/CMakeLists.txt +++ b/Rez/CMakeLists.txt @@ -55,6 +55,8 @@ add_executable(Rez ResourceCompiler.cc ResourceCompiler.h + + ResSpec.h ) target_link_libraries(Rez ResourceFiles ${Boost_LIBRARIES}) diff --git a/Rez/ResSpec.h b/Rez/ResSpec.h new file mode 100644 index 0000000000..2aa648a061 --- /dev/null +++ b/Rez/ResSpec.h @@ -0,0 +1,24 @@ +#ifndef REZSPEC_H +#define REZSPEC_H + +#include "ResType.h" +#include + +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 diff --git a/Rez/RezLexerNextToken.cc b/Rez/RezLexerNextToken.cc index bffe017cc0..14bed3c566 100644 --- a/Rez/RezLexerNextToken.cc +++ b/Rez/RezLexerNextToken.cc @@ -169,6 +169,11 @@ RezSymbol RezLexer::nextToken() static std::unordered_map 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"), diff --git a/Rez/RezParser.yy b/Rez/RezParser.yy index ff4d421476..0b6e9d49af 100644 --- a/Rez/RezParser.yy +++ b/Rez/RezParser.yy @@ -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($1); } { $$ = std::make_shared($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 resource_attributes resource_attribute; -resource_attributes : %empty { $$ = 0; } - | resource_attributes "," resource_attribute { $$ = $1 | $3; } +%type res_spec; + +res_spec : res_type "(" expression resource_attributes ")" + { $$ = $resource_attributes( ResSpec($res_type, $expression->evaluateInt(nullptr)) ); } + +%type > resource_attributes ; +resource_attributes : %empty { $$ = [](ResSpec s){ return s; }; } + | resource_attributes "," IDENTIFIER { $$ = $1; } + | resource_attributes "," string_expression { $$ = $1; } + ; -resource_attribute : IDENTIFIER { $$ = 0; } /* ### */ %type resource_body resource_body1; resource_body : %empty { $$ = std::make_shared(); } @@ -438,4 +452,11 @@ resource_item : value { $$ = $1; } | IDENTIFIER "{" resource_body "}" { $$ = std::make_shared($IDENTIFIER, $resource_body); } ; + +data : "data" res_spec "{" string_expression "}" +{ + world.addData($res_spec, $string_expression->evaluateString(nullptr)); +} +; + %% diff --git a/Rez/RezWorld.cc b/Rez/RezWorld.cc index 7c33d5345b..93d0d5bfb3 100644 --- a/Rez/RezWorld.cc +++ b/Rez/RezWorld.cc @@ -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())); } diff --git a/Rez/RezWorld.h b/Rez/RezWorld.h index 50277b55ea..5c047f196a 100644 --- a/Rez/RezWorld.h +++ b/Rez/RezWorld.h @@ -3,9 +3,11 @@ #include #include +#include #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; }