Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
ParserGenerator
Commits
c0e17708
Commit
c0e17708
authored
Jan 13, 2021
by
Pierre Aubert
Browse files
Fix oneOf code generation
parent
80d22609
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
61 deletions
+59
-61
TESTS/TEST_VAR_DECL_STRING/var_decl_string.pdecparser
TESTS/TEST_VAR_DECL_STRING/var_decl_string.pdecparser
+0
-2
src/CppBackEnd/repr_cpp_to_language.cpp
src/CppBackEnd/repr_cpp_to_language.cpp
+21
-21
src/CppBackEnd/repr_cpp_token.cpp
src/CppBackEnd/repr_cpp_token.cpp
+36
-36
src/GraphParser/PGraphParser.cpp
src/GraphParser/PGraphParser.cpp
+2
-2
No files found.
TESTS/TEST_VAR_DECL_STRING/var_decl_string.pdecparser
View file @
c0e17708
///The Curry coloration seems to be good, but it will be better to have the proper coloration for this language
Vector(String) vecVarType;
///A variable with a type and a name
...
...
src/CppBackEnd/repr_cpp_to_language.cpp
View file @
c0e17708
...
...
@@ -84,7 +84,7 @@ std::string repr_cpp_to_languageHeader(const PTabGraphToken & tabGraphToken){
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceToken
(
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert a token into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert a token into a string
\n
"
;
body
+=
indentation
+
"body +=
\"
"
+
token
.
getToken
()
+
"
\"
;
\n
"
;
//Simply convert the token into a string
return
body
;
}
...
...
@@ -98,7 +98,7 @@ std::string graph_cpp_graphTokenToLanguageSourceToken(const PGraphToken & graphT
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceOr
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert an OR into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert an OR into a string
\n
"
;
//TODO : compare the different possibilities and looking for an hint to determine the good one
bool
choiseSaved
(
false
);
...
...
@@ -113,7 +113,7 @@ std::string graph_cpp_graphTokenToLanguageSourceOr(const PTabGraphToken & tabGra
if
(
vecPar
.
size
()
==
2lu
){
body
+=
indentation
+
"if("
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
graphToken
.
getVarName
())
+
" == "
+
callToken
.
getRightFctCallName
()
+
"){
\n
"
;
body
+=
indentation
+
"
\t
//Call the tokens inside the OR, solved by VALUE
\n
"
;
body
+=
indentation
+
"
\t
//
repr_cpp_to_language :
Call the tokens inside the OR, solved by VALUE
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecChoiseToken
,
indentation
+
"
\t
"
);
body
+=
indentation
+
"}
\n
"
;
choiseSaved
=
true
;
...
...
@@ -121,7 +121,7 @@ std::string graph_cpp_graphTokenToLanguageSourceOr(const PTabGraphToken & tabGra
}
}
if
(
!
choiseSaved
&&
vecToken
.
size
()
!=
0lu
){
body
+=
indentation
+
"//
\t
choose default path into OR because no hint was given to decide
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
choose default path into OR because no hint was given to decide
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceSwitchToken
(
tabGraphToken
,
graphToken
,
vecToken
.
front
(),
indentation
);
}
...
...
@@ -137,7 +137,7 @@ std::string graph_cpp_graphTokenToLanguageSourceOr(const PTabGraphToken & tabGra
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceRepeat
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert a Repeat into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert a Repeat into a string
\n
"
;
//TODO : Same as optional with a while instead of an if
//I have to search the pushBack function recursivelly
...
...
@@ -168,7 +168,7 @@ std::string graph_cpp_graphTokenToLanguageSourceRepeat(const PTabGraphToken & ta
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceOptional
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert an Optional into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert an Optional into a string
\n
"
;
//Find an attribute of the current input of the graph token to make a condition and determine if the optional has been used
// If there is no such hint, the optional will be skipped
//If there is a vector in the optional the condition will be the vector is not empty
...
...
@@ -180,7 +180,7 @@ std::string graph_cpp_graphTokenToLanguageSourceOptional(const PTabGraphToken &
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
body
+=
indentation
+
"if("
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
graphToken
.
getVarName
())
+
" == "
+
callToken
.
getRightFctCallName
()
+
"){
\n
"
;
body
+=
indentation
+
"
\t
//Call the tokens inside the OPTIONAL, solved by VALUE
\n
"
;
body
+=
indentation
+
"
\t
//
repr_cpp_to_language :
Call the tokens inside the OPTIONAL, solved by VALUE
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecToken
,
indentation
+
"
\t
"
);
body
+=
indentation
+
"}
\n
"
;
}
...
...
@@ -189,12 +189,12 @@ std::string graph_cpp_graphTokenToLanguageSourceOptional(const PTabGraphToken &
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
body
+=
indentation
+
"if("
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
graphToken
.
getVarName
())
+
".size() != 0lu){
\n
"
;
body
+=
indentation
+
"
\t
//Call the tokens inside the OPTIONAL, solved by PUSHBACK
\n
"
;
body
+=
indentation
+
"
\t
//
repr_cpp_to_language :
Call the tokens inside the OPTIONAL, solved by PUSHBACK
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecToken
,
indentation
+
"
\t
"
);
body
+=
indentation
+
"}
\n
"
;
}
}
else
{
//Do something else
body
+=
indentation
+
"//The OPTIONAL token does not contain VALUE or PUSHBACK call
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
The OPTIONAL token does not contain VALUE or PUSHBACK call
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecToken
,
indentation
);
}
return
body
;
...
...
@@ -209,7 +209,7 @@ std::string graph_cpp_graphTokenToLanguageSourceOptional(const PTabGraphToken &
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceNone
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert a None into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert a None into a string
\n
"
;
const
PVecToken
&
vecToken
=
token
.
getVecSubToken
();
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecToken
,
indentation
);
return
body
;
...
...
@@ -235,14 +235,14 @@ std::string graph_cpp_graphTokenToLanguageSourceCommandPushBack(const PTabGraphT
}
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
indentation
+
"//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
functionName = "
+
functionName
+
"
\n
"
;
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
return
indentation
+
"#error
\"
Expected only one argument
\"\n
"
;
}
const
PCallToken
&
param
(
vecParam
.
front
());
body
+=
indentation
+
"//Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
std
::
string
calleeGraphName
(
param
.
getRightFctCallName
()),
vectorName
(
vecPar
.
back
()),
itVar
(
"it"
+
firstToUpper
(
vectorName
));
const
PGraphToken
*
calleeGraph
=
getGraphTokenByName
(
tabGraphToken
,
calleeGraphName
);
...
...
@@ -284,8 +284,8 @@ std::string graph_cpp_graphTokenToLanguageSourceCommandOneOf(const PGraphToken &
std
::
string
body
(
""
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
body
+=
indentation
+
"//Convert command OneOf into a string
\n
"
;
body
+=
indentation
+
"body += "
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
vecPar
.
front
())
+
vecPar
.
front
()
+
"
\"
\"
;
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert command OneOf into a string
\n
"
;
body
+=
indentation
+
"body += "
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
graphToken
.
getVarName
())
+
vecPar
.
front
()
+
"
+
\"
\"
;
\n
"
;
}
return
body
;
}
...
...
@@ -300,7 +300,7 @@ std::string graph_cpp_graphTokenToLanguageSourceCommandCallGraph(const PGraphTok
std
::
string
body
(
""
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
body
+=
indentation
+
"//Convert command Call Graph into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert command Call Graph into a string
\n
"
;
body
+=
indentation
+
"body += "
+
callToken
.
getRightFctCallName
()
+
"("
+
getTokenGetterCall
(
graphToken
.
getVarType
(),
vecPar
.
back
(),
vecPar
.
front
())
+
vecPar
.
front
()
+
") +
\"
\"
;
\n
"
;
}
return
body
;
...
...
@@ -321,7 +321,7 @@ std::string graph_cpp_graphTokenToLanguageSourceCommandParam(const PTabGraphToke
if
(
!
getAttributeFromClassIsExist
(
varToken
,
tabGraphToken
,
classVarType
,
vecPar
[
1lu
])){
return
indentation
+
"#error
\"
IMPOSSIBLE TO GET "
+
classVarType
+
"."
+
vecPar
[
1lu
]
+
" DOES NOT EXIST
\"\n
"
;
}
body
+=
indentation
+
"//Convert a Param into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert a Param into a string
\n
"
;
std
::
string
type
(
varToken
.
getType
());
if
(
type
==
"String"
){
body
+=
indentation
+
"body += "
+
getTokenGetterCall
(
graph
.
getVarType
(),
vecPar
.
back
(),
graph
.
getVarName
())
+
";
\n
"
;
...
...
@@ -341,7 +341,7 @@ std::string graph_cpp_graphTokenToLanguageSourceCommandParam(const PTabGraphToke
*/
std
::
string
graph_cpp_graphTokenToLanguageSourceCommand
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graphToken
,
const
PToken
&
token
,
const
std
::
string
&
indentation
){
std
::
string
body
(
""
);
body
+=
indentation
+
"//Convert a Command into a string
\n
"
;
body
+=
indentation
+
"//
repr_cpp_to_language :
Convert a Command into a string
\n
"
;
const
PCallToken
&
callToken
=
token
.
getCommand
();
switch
(
callToken
.
getType
()){
case
PCallTokenType
::
FUNCTION_PUSHBACK
:
...
...
@@ -443,7 +443,7 @@ std::string graph_cpp_graphTokenToLanguageSource(const PTabGraphToken & tabGraph
body
+=
"
\t
if(!"
+
classVarName
+
".isType("
+
classDefine
+
")){return
\"\"
;}
\n
"
;
//Here, we have to get all the operator which use the current graph as an input
body
+=
"
\t
//If the graph token is used by an Operator, we have to check that here.
\n
"
;
body
+=
"
\t
//
repr_cpp_to_language :
If the graph token is used by an Operator, we have to check that here.
\n
"
;
PVecOperator
vecOpUseCurrentGraph
;
search_operatorByGraphUse
(
vecOpUseCurrentGraph
,
tabGraphToken
.
getVecOperator
(),
graphToken
.
getName
());
...
...
@@ -454,11 +454,11 @@ std::string graph_cpp_graphTokenToLanguageSource(const PTabGraphToken & tabGraph
body
+=
"
\t
"
+
itPrevElse
+
"if("
+
it
->
getExprClass
()
+
"_get"
+
firstToUpper
(
it
->
getAttrEnum
())
+
"("
+
classVarName
+
") == "
+
it
->
getValueEnum
()
+
"){return operator_to_language_"
+
repr_cpp_operator_getEnumValue
(
it
->
getValueEnum
())
+
"("
+
classVarName
+
");}
\n
"
;
itPrevElse
=
"else "
;
}
body
+=
"
\t\n\t
//Back to previous back end if no Operator is used until now
\n\t\n
"
;
body
+=
"
\t\n\t
//
repr_cpp_to_language :
Back to previous back end if no Operator is used until now
\n\t\n
"
;
}
body
+=
"
\t
std::string body(
\"\"
);
\n
"
;
body
+=
"
\t
//Initialising all the iterators to be used by pushBack in the graph
\n
"
;
body
+=
"
\t
//
repr_cpp_to_language :
Initialising all the iterators to be used by pushBack in the graph
\n
"
;
const
PVecToken
&
vecToken
=
graphToken
.
getVecToken
();
//I need the type inside the vector, and the associate variable name
PVecVecName
vecVectorName
;
...
...
@@ -467,7 +467,7 @@ std::string graph_cpp_graphTokenToLanguageSource(const PTabGraphToken & tabGraph
body
+=
"
\t
"
+
convertTypeToStd
(
it
->
getType
())
+
"::const_iterator it"
+
firstToUpper
(
it
->
getName
())
+
"("
+
getTokenGetterCall
(
classVarType
,
it
->
getName
(),
classVarName
)
+
".begin());
\n
"
;
}
body
+=
"
\t
//Do the conversion here
\n
"
;
body
+=
"
\t
//
repr_cpp_to_language :
Do the conversion here
\n
"
;
body
+=
graph_cpp_graphTokenToLanguageSourceVecToken
(
tabGraphToken
,
graphToken
,
vecToken
,
"
\t
"
);
body
+=
"
\t
return body;
\n
"
;
body
+=
"}
\n\n
"
;
...
...
src/CppBackEnd/repr_cpp_token.cpp
View file @
c0e17708
...
...
@@ -57,8 +57,8 @@ std::string repr_cpp_tokenFunctionHeader(const PGraphToken & graph, const PToken
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoToken
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//TOKEN
\n
"
);
body
+=
"
\t
// Imperative token '"
+
token
.
getToken
()
+
"'
\n
"
;
std
::
string
body
(
"
\t
//
repr_cpp_token :
TOKEN
\n
"
);
body
+=
"
\t
//
repr_cpp_token :
Imperative token '"
+
token
.
getToken
()
+
"'
\n
"
;
body
+=
"
\t
if(!p_parser->isMatch(
\"
"
+
token
.
getToken
()
+
"
\"
)){return false;}
\n
"
;
body
+=
"
\t
else{return true;}
\n
"
;
return
body
;
...
...
@@ -71,7 +71,7 @@ std::string repr_cpp_tokenFunctionSourceDoToken(const PTabGraphToken & tabGraphT
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoOr
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//OR
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
OR
\n
"
);
const
PVecToken
&
vecToken
=
token
.
getVecSubToken
();
if
(
vecToken
.
size
()
==
0lu
){
return
"
\t
return true; //No sub tokens in the current token
\n
"
;}
for
(
PVecToken
::
const_iterator
it
(
vecToken
.
begin
());
it
!=
vecToken
.
end
();
++
it
){
...
...
@@ -92,7 +92,7 @@ std::string repr_cpp_tokenFunctionSourceDoOr(const PTabGraphToken & tabGraphToke
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoRepeat
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//REPEAT (A REPEAT is OPTIONAL
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
REPEAT (A REPEAT is
also
OPTIONAL
\n
"
);
const
PVecToken
&
vecToken
=
token
.
getVecSubToken
();
if
(
vecToken
.
size
()
==
0lu
){
return
"
\t
return true; //No sub tokens in the current token
\n
"
;}
long
unsigned
int
tokenIndex
(
1lu
);
...
...
@@ -109,7 +109,7 @@ std::string repr_cpp_tokenFunctionSourceDoRepeat(const PTabGraphToken & tabGraph
body
+=
"
\t
}
\n
"
;
++
tokenIndex
;
}
body
+=
"
\t
//We recall the token itsef to have a repeatition, but if there is no repeat, it is not an error
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
We recall the token itsef to have a repeatition, but if there is no repeat, it is not an error
\n
"
;
body
+=
"
\t
return "
+
token
.
getFunctionName
()
+
"Do("
+
graph
.
getVarName
()
+
");
\n
"
;
return
body
;
}
...
...
@@ -121,7 +121,7 @@ std::string repr_cpp_tokenFunctionSourceDoRepeat(const PTabGraphToken & tabGraph
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoOptional
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//OPTIONAL : only the first token is optional, and if the first token is found, the next have the be there
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
OPTIONAL : only the first token is optional, and if the first token is found, the next have the be there
\n
"
);
const
PVecToken
&
vecToken
=
token
.
getVecSubToken
();
if
(
vecToken
.
size
()
==
0lu
){
return
"
\t
return true; //No sub tokens in the current token
\n
"
;}
long
unsigned
int
tokenIndex
(
1lu
);
...
...
@@ -149,7 +149,7 @@ std::string repr_cpp_tokenFunctionSourceDoOptional(const PTabGraphToken & tabGra
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoNone
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//NONE
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
NONE
\n
"
);
const
PVecToken
&
vecToken
=
token
.
getVecSubToken
();
if
(
vecToken
.
size
()
==
0lu
){
return
"
\t
return true; //No sub tokens in the current token
\n
"
;}
long
unsigned
int
tokenIndex
(
1lu
);
...
...
@@ -176,7 +176,7 @@ std::string repr_cpp_tokenFunctionSourceDoNone(const PTabGraphToken & tabGraphTo
std
::
string
repr_cpp_tokenFunctionSourceDoCommandFunctionPushBack
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
std
::
string
body
(
"
\t
//
\t
repr_cpp_token :
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
PVarToken
varToken
;
...
...
@@ -185,14 +185,14 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionPushBack(const PTabGrap
}
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//functionName = "
+
functionName
+
"
\n
"
;
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
return
"
\t
#error
\"
Expected only one argument
\"\n
"
;
}
const
PCallToken
&
param
(
vecParam
.
front
());
body
+=
"
\t
//Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
std
::
string
calleeGraphName
(
param
.
getRightFctCallName
());
const
PGraphToken
*
calleeGraph
=
getGraphTokenByName
(
tabGraphToken
,
calleeGraphName
);
...
...
@@ -226,7 +226,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionPushBack(const PTabGrap
std
::
string
repr_cpp_tokenFunctionSourceDoCommandFunctionPushBackFirst
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
std
::
string
body
(
"
\t
//
\t
repr_cpp_token :
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
PVarToken
varToken
;
...
...
@@ -235,7 +235,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionPushBackFirst(const PTa
}
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
return
"
\t
#error
\"
Expected only one argument
\"\n
"
;
...
...
@@ -281,7 +281,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionPushBackFirst(const PTa
std
::
string
repr_cpp_tokenFunctionSourceDoCommandFunctionBackPushBack
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
PVarToken
varToken
;
...
...
@@ -290,14 +290,14 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionBackPushBack(const PTab
}
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
return
"
\t
#error
\"
Expected only one argument
\"\n
"
;
}
const
PCallToken
&
param
(
vecParam
.
front
());
body
+=
"
\t
//Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
Get the name of the class to make a temporary to call the graph before "
+
functionName
+
"
\n
"
;
std
::
string
calleeGraphName
(
param
.
getRightFctCallName
());
const
PGraphToken
*
calleeGraph
=
getGraphTokenByName
(
tabGraphToken
,
calleeGraphName
);
...
...
@@ -341,7 +341,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionBackPushBack(const PTab
std
::
string
repr_cpp_tokenFunctionSourceDoCommandFunctionOneOf
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION : extra function call
\n
"
),
classVarType
(
graph
.
getVarType
());
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION : extra function call
oneof
\n
"
),
classVarType
(
graph
.
getVarType
());
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
PVarToken
varToken
;
...
...
@@ -358,13 +358,13 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionOneOf(const PTabGraphTo
if
(
var
==
NULL
){
return
body
+
"#error
\"
No global variable named '"
+
varName
+
"'
\"\n
"
;
}
body
+=
"
\t
//TODO : Create the same kind of call for the Vector of other types like Int or UInt
\n
"
;
body
+=
"
\t
std::string res(p_parser->isMatch("
+
varName
+
"));"
;
body
+=
"
\t
//
repr_cpp_token :
TODO : Create the same kind of call for the Vector of other types like Int or UInt
\n
"
;
body
+=
"
\t
std::string res(p_parser->isMatch(
p_
"
+
varName
+
"));
\n
"
;
body
+=
"
\t
if(res ==
\"\"
){
\n
"
;
body
+=
"
\t\t
return false;
\n
"
;
body
+=
"
\t
}else{
\n
"
;
// body += "\t\t\n" + vecPar.front() + ".set" + firstToUpper(vecPar.back())+"(res);";
body
+=
"
\t\t
"
+
getTokenSetterCall
(
classVarType
,
vecPar
.
back
(),
vecPar
.
front
(),
"res"
);
body
+=
"
\t\t
"
+
getTokenSetterCall
(
classVarType
,
vecPar
.
back
(),
graph
.
getVarName
(),
"res"
);
body
+=
"
\t\t
return true;
\n
"
;
body
+=
"
\t
}
\n
"
;
}
...
...
@@ -378,7 +378,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandFunctionOneOf(const PTabGraphTo
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoCommandCallGraph
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
){
std
::
string
body
(
"
\t
//
\t
CALLGRAPH : to call a graph we need to call its first token
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
CALLGRAPH : to call a graph we need to call its first token
\n
"
);
std
::
string
graphName
(
callToken
.
getRightFctCallName
());
const
PGraphToken
*
calleeGraph
=
getGraphTokenByName
(
tabGraphToken
,
graphName
);
if
(
calleeGraph
==
NULL
){
...
...
@@ -407,7 +407,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandCallGraph(const PTabGraphToken
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoCommandParam
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
){
std
::
string
body
(
"
\t
//
\t
PARAM : set a class parameter with its CharSet (default csVariableName)
\n
"
),
classVarType
(
graph
.
getVarType
());
std
::
string
body
(
"
\t
//
repr_cpp_token :
PARAM : set a class parameter with its CharSet (default csVariableName)
\n
"
),
classVarType
(
graph
.
getVarType
());
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
PVarToken
varToken
;
...
...
@@ -444,7 +444,7 @@ std::string repr_cpp_tokenFunctionSourceDoCommandParam(const PTabGraphToken & ta
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoCommandValue
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
){
std
::
string
body
(
"
\t
//
\t
VALUE : set a value (mostly an enum) to a class attribute
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
VALUE : set a value (mostly an enum) to a class attribute
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
// body += "\t" + vecPar.front() + ".set" + firstToUpper(vecPar.back()) + "("+callToken.getRightFctCallName()+");\n";
...
...
@@ -461,8 +461,8 @@ std::string repr_cpp_tokenFunctionSourceDoCommandValue(const PTabGraphToken & ta
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceDoCommand
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//COMMAND
\n
"
);
const
PCallToken
&
callToken
=
token
.
getCommand
();
std
::
string
body
(
"
\t
//repr_cpp_token : COMMAND type "
+
convertToString
(
callToken
.
getType
())
+
"
\n
"
);
switch
(
callToken
.
getType
()){
case
PCallTokenType
::
FUNCTION_PUSHBACK
:
body
+=
repr_cpp_tokenFunctionSourceDoCommandFunctionPushBack
(
tabGraphToken
,
graph
,
token
,
callToken
);
...
...
@@ -510,7 +510,7 @@ std::string repr_cpp_tokenFunctionSourceDo(const std::string & parserName, const
body
+=
"*/
\n
"
;
body
+=
"bool "
+
parserName
+
"::"
+
token
.
getFunctionName
()
+
"Do("
+
graph
.
getVarType
()
+
" & "
+
graph
.
getVarName
()
+
"){
\n
"
;
body
+=
"
\t
p_parser->pushPosition(); //Save the current position of the parser
\n
"
;
body
+=
"
\t
// Token type = "
+
convertToString
(
token
.
getType
())
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
Token type = "
+
convertToString
(
token
.
getType
())
+
"
\n
"
;
switch
(
token
.
getType
()){
case
PTokenType
::
TOKEN
:
body
+=
repr_cpp_tokenFunctionSourceDoToken
(
tabGraphToken
,
graph
,
token
);
...
...
@@ -547,11 +547,11 @@ std::string repr_cpp_tokenFunctionSourceDo(const std::string & parserName, const
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandFunctionPushBack
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
//We don't have to pop a graph because we don't have push back on fail
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
...
...
@@ -574,11 +574,11 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandFunctionPushBack(const PTabGr
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandFunctionPushBackFirst
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
//We don't have to pop a graph because we don't have push back on fail
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
...
...
@@ -601,11 +601,11 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandFunctionPushBackFirst(const P
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandFunctionBackPushBack
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
//We don't have to pop a graph because we don't have push back on fail
const
PVecCallToken
&
vecParam
=
callToken
.
getVecParam
();
if
(
vecParam
.
size
()
!=
1lu
){
...
...
@@ -636,11 +636,11 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandFunctionBackPushBack(const PT
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandFunctionOneOf
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
FUNCTION
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
FUNCTION
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
std
::
string
functionName
(
callToken
.
getRightFctCallName
());
body
+=
"
\t
//
\t
functionName = "
+
functionName
+
"
\n
"
;
body
+=
"
\t
//
repr_cpp_token :
functionName = "
+
functionName
+
"
\n
"
;
}
return
body
;
}
...
...
@@ -654,7 +654,7 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandFunctionOneOf(const PTabGraph
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandCallGraph
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
CALLGRAPH
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
CALLGRAPH
\n
"
);
body
+=
"
\t
//Nothing to do
\n
"
;
return
body
;
}
...
...
@@ -668,7 +668,7 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandCallGraph(const PTabGraphToke
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandParam
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
PARAM
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
PARAM
\n
"
);
body
+=
"
\t
//Nothing to do
\n
"
;
return
body
;
}
...
...
@@ -682,7 +682,7 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandParam(const PTabGraphToken &
std
::
string
repr_cpp_tokenFunctionSourceUndoCommandValue
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PCallToken
&
callToken
)
{
std
::
string
body
(
"
\t
//
\t
VALUE
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
VALUE
\n
"
);
const
PVecInclude
&
vecPar
=
callToken
.
getVecLeftVar
();
if
(
vecPar
.
size
()
==
2lu
){
...
...
@@ -703,7 +703,7 @@ std::string repr_cpp_tokenFunctionSourceUndoCommandValue(const PTabGraphToken &
* @return C++ source
*/
std
::
string
repr_cpp_tokenFunctionSourceUndoCommand
(
const
PTabGraphToken
&
tabGraphToken
,
const
PGraphToken
&
graph
,
const
PToken
&
token
){
std
::
string
body
(
"
\t
//COMMAND
\n
"
);
std
::
string
body
(
"
\t
//
repr_cpp_token :
COMMAND
\n
"
);
const
PCallToken
&
callToken
=
token
.
getCommand
();
switch
(
callToken
.
getType
()){
case
PCallTokenType
::
FUNCTION_PUSHBACK
:
...
...
src/GraphParser/PGraphParser.cpp
View file @
c0e17708
...
...
@@ -428,9 +428,9 @@ bool PGraphParser::parseFunction(PCallToken & callToken){
}
PCallToken
param
;
param
.
setRightFctCallName
(
listName
);
param
.
setType
(
PCallTokenType
::
PARAM
);
param
.
setType
(
PCallTokenType
::
FUNCTION_ONEOF
);
callToken
.
getVecParam
().
push_back
(
param
);
callToken
.
setType
(
PCallTokenType
::
FUNCTION_ONEOF
);
if
(
!
checkExprectedMatch
(
")"
,
listName
))
return
false
;
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment