@@ -488,6 +488,30 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
488
488
}
489
489
else toendlineA (_it,endpycode);
490
490
break ;
491
+ case ' l' :
492
+ _it2 = _it;
493
+ if (has_keyword_pattern (_it,begcode,endpycode," lpyimport" )){
494
+ code+=std::string (beg,_it2);
495
+ beg = _it;
496
+ if (_it!=endpycode){
497
+ _it++;
498
+ beg = _it;
499
+ toendline (_it,endpycode);
500
+ if (beg != endpycode) {
501
+ if (notOnlySpace (beg,_it)){
502
+ std::string modulename = LpyParsing::trim (std::string (beg,_it));
503
+ addSubLsystem (modulename+" .lpy" );
504
+ }
505
+ else LsysParserSyntaxError (" invalid module to import" );
506
+ }
507
+ else LsysParserSyntaxError (" invalid module to import" );
508
+ }
509
+ else LsysParserSyntaxError (" invalid module to import" );
510
+ code+=" # " +std::string (_it2,_it);
511
+ beg = _it;
512
+ }
513
+ else toendlineA (_it,endpycode);
514
+ break ;
491
515
case ' c' :
492
516
_it2 = _it;
493
517
if (has_keyword_pattern (_it,begcode,endpycode," consider" )){
@@ -971,7 +995,8 @@ void LsysRule::set( const std::string& rule ){
971
995
972
996
/* ---------------------------------------------------------------------------*/
973
997
std::string::const_iterator next_token (std::string::const_iterator _it2,
974
- std::string::const_iterator end)
998
+ std::string::const_iterator end,
999
+ bool withbrackets = true )
975
1000
{
976
1001
if (_it2 != end){
977
1002
if (*_it2 == ' "' ){ // skip string
@@ -997,7 +1022,7 @@ std::string::const_iterator next_token(std::string::const_iterator _it2,
997
1022
}
998
1023
if (_it2 != end)_it2++;
999
1024
}
1000
- else if (*_it2 == ' [' ){ // skip array
1025
+ else if (withbrackets && *_it2 == ' [' ){ // skip array
1001
1026
int nbOpenBracket = 1 ;
1002
1027
while (_it2 != end && (*_it2 != ' ]' || nbOpenBracket > 0 )){
1003
1028
_it2++;
@@ -1010,7 +1035,7 @@ std::string::const_iterator next_token(std::string::const_iterator _it2,
1010
1035
}
1011
1036
if (_it2 != end)_it2++;
1012
1037
}
1013
- else if (*_it2 == ' {' ){ // skip dict
1038
+ else if (withbrackets && *_it2 == ' {' ){ // skip dict
1014
1039
int nbOpenBracket = 1 ;
1015
1040
while (_it2 != end && (*_it2 != ' }' || nbOpenBracket > 0 )){
1016
1041
_it2++;
@@ -1043,20 +1068,23 @@ LsysRule::parseHeader( const std::string& header){
1043
1068
bool begncd = false ;
1044
1069
while (it != end){
1045
1070
if (*it == ' <' ){
1071
+
1046
1072
if (!pred.empty ())LsysError (" Ill-formed Rule Header : " +header," " ,lineno);
1047
1073
if (*(it+1 ) == ' <' ){
1048
1074
if (ncg.empty ())ncg = std::string (beg,it);
1049
1075
else LsysError (" Ill-formed Rule Header : " +header," " ,lineno);
1050
1076
it++;
1051
1077
}
1052
1078
else {
1053
- if (cg.empty ())cg = std::string (beg,it);
1079
+ if (cg.empty ()) cg = std::string (beg,it);
1054
1080
else LsysError (" Ill-formed Rule Header : " +header," " ,lineno);
1055
1081
}
1056
1082
beg = it+1 ;
1057
1083
}
1058
- else if (*it == ' >' ){
1059
- if (*(it+1 ) == ' >' ) {
1084
+
1085
+ else if (*it == ' >' ){
1086
+
1087
+ if (*(it+1 ) == ' >' ) {
1060
1088
if (begncd || !ncd.empty ())LsysError (" Ill-formed Rule Header : Two new left contexts found : " +header," " ,lineno);
1061
1089
else {
1062
1090
if (pred.empty ()) pred = std::string (beg,it);
@@ -1075,7 +1103,7 @@ LsysRule::parseHeader( const std::string& header){
1075
1103
if (pred.empty ())LsysError (" Ill-formed Rule Header : No Predecessor found : " +header," " ,lineno);
1076
1104
beg = it+1 ;
1077
1105
}
1078
- it = next_token (it,end);
1106
+ it = next_token (it,end, false );
1079
1107
// it++;
1080
1108
}
1081
1109
if (pred.empty ()){
@@ -1141,34 +1169,34 @@ std::string LpyParsing::lstring2pyparam( std::string::const_iterator& beg,
1141
1169
std::string result;
1142
1170
std::string::const_iterator initbeg = beg;
1143
1171
std::vector<std::pair<size_t ,std::string> > parsedstring = parselstring (beg, endpos, delim, lineno,true );
1144
- ParametricProduction pprod;
1172
+ ParametricProductionPtr pprod = ParametricProduction::create () ;
1145
1173
if (parsedstring.empty ()){
1146
- pprod. append_module_type (" None" );
1174
+ pprod-> append_module_type (" None" );
1147
1175
}
1148
1176
else {
1149
1177
for (std::vector<std::pair<size_t ,std::string> >::const_iterator it = parsedstring.begin ();
1150
1178
it != parsedstring.end (); ++it){
1151
1179
if (it->first == ModuleClass::GetModule->getId ()){
1152
1180
// in the case of production $ is only followed by a var name.
1153
- pprod. append_variable_module ();
1181
+ pprod-> append_variable_module ();
1154
1182
result += " ," + it->second ;
1155
1183
}
1156
1184
else {
1157
- pprod. append_module_type (it->first );
1185
+ pprod-> append_module_type (it->first );
1158
1186
if (!it->second .empty ()) {
1159
1187
std::vector<std::string> args = parse_arguments (it->second );
1160
1188
for (std::vector<std::string>::const_iterator itArg = args.begin (); itArg != args.end (); ++itArg){
1161
1189
if (isAConstant (*itArg)){
1162
- pprod. append_module_value (LsysContext::current ()->evaluate (*itArg));
1190
+ pprod-> append_module_value (LsysContext::current ()->evaluate (*itArg));
1163
1191
}
1164
1192
else {
1165
1193
std::string m = " PackedArgs(" ;
1166
1194
if (itArg->size () > m.size () && std::string (itArg->begin (),itArg->begin ()+m.size ()) == m) {
1167
- pprod. append_module_star_variable ();
1195
+ pprod-> append_module_star_variable ();
1168
1196
result += " ," + std::string (itArg->begin ()+m.size (),itArg->end ()-1 );
1169
1197
}
1170
1198
else {
1171
- pprod. append_module_variable ();
1199
+ pprod-> append_module_variable ();
1172
1200
result += " ," + *itArg;
1173
1201
}
1174
1202
}
@@ -1177,7 +1205,8 @@ std::string LpyParsing::lstring2pyparam( std::string::const_iterator& beg,
1177
1205
}
1178
1206
} // end for
1179
1207
}
1180
- size_t id = LsysContext::current ()->add_pproduction (pprod);
1208
+ LsysContext::current ()->add_pproduction (pprod);
1209
+ size_t id = pprod->pid ();
1181
1210
if (pprod_id) *pprod_id = id;
1182
1211
size_t nbInitialLine = std::count (initbeg,beg,' \n ' );
1183
1212
size_t nbResultLine = std::count (result.begin (),result.end (),' \n ' );
0 commit comments