1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
|
%{
#include "AppHdr.h"
#include <map>
#include <algorithm>
#include "end.h"
#include "l-defs.h"
#include "mapdef.h"
#include "maps.h"
#include "stringutil.h"
#define YYERROR_VERBOSE 1
#define YYENABLE_NLS 0
#define YYLTYPE_IS_TRIVIAL 0
int yylex();
extern int yylineno;
static NORETURN void yyerror(const char *e, bool dlua_error = false)
{
if (strstr(e, lc_desfile.c_str()) == e)
fprintf(stderr, "%s\n", e);
else
fprintf(stderr, "%s:%d: %s\n", lc_desfile.c_str(), yylineno, e);
if (dlua_error && !dlua_errors.empty())
fprintf(stderr, "%s\n", dlua_errors.back().stack_trace.c_str());
// Bail bail bail.
end(1);
}
%}
%union
{
int i;
double f;
const char *text;
}
/* Two harmless shift/reduce conflicts */
%expect 2
%token <i> DEFAULT_DEPTH SHUFFLE CLEAR SUBST TAGS KFEAT KITEM KMONS KMASK KPROP
%token <i> NAME DEPTH ORIENT PLACE CHANCE WEIGHT MONS ITEM MARKER COLOUR
%token <i> PRELUDE MAIN VALIDATE VETO EPILOGUE NSUBST WELCOME
%token <i> LFLOORCOL LROCKCOL LFLOORTILE LROCKTILE FTILE RTILE TILE
%token <i> SUBVAULT FHEIGHT DESC ORDER
%token <i> COMMA COLON PERC DASH CHARACTER
%token <f> NUMBER
%token <text> STRING MAP_LINE MONSTER_NAME ITEM_INFO
%token <text> LUA_LINE
%type <i> chance_roll
%%
file : definitions { }
;
definitions : /* empty */ {}
| definitions definition {}
;
definition : def {}
| level {}
;
error_seq : CHARACTER
{
yyerror("Unexpected character sequence.");
}
;
def : defdepth {}
| global_lua {}
;
defdepth : DEFAULT_DEPTH STRING
{
dgn_reset_default_depth();
string err = dgn_set_default_depth($2);
if (!err.empty())
yyerror(make_stringf("Bad default-depth: %s (%s)",
$2, err.c_str()).c_str());
}
;
level : name map_specs
{
lc_map.set_file(lc_desfile);
if (lc_run_global_prelude && !lc_global_prelude.empty())
{
lc_global_prelude.set_file(lc_desfile);
lc_run_global_prelude = false;
if (lc_global_prelude.load_call(dlua, nullptr))
yyerror( lc_global_prelude.orig_error().c_str() );
}
string err = lc_map.validate_map_def();
dump_map(lc_map);
if (!err.empty())
yyerror(err.c_str(), true);
add_parsed_map(lc_map);
}
;
map_specs : /* nothing */ { }
| map_specs map_spec { }
;
map_spec : metaline { }
| map_def { }
;
name : NAME STRING
{
lc_map.init();
lc_map.name = $2;
map_load_info_t::const_iterator i =
lc_loaded_maps.find($2);
if (i != lc_loaded_maps.end())
{
yyerror(
make_stringf(
"Map named '%s' already loaded at %s:%d",
$2,
i->second.filename.c_str(),
i->second.lineno).c_str() );
}
lc_map.place_loaded_from =
map_file_place(lc_desfile, yylineno);
lc_loaded_maps[$2] = lc_map.place_loaded_from;
}
;
metaline : place
| desc
| order
| depth
| chance
| weight
| orientation
| welcome
| mons
| items
| marker
| subst
| nsubst
| colour
| lfloorcol
| lrockcol
| lfloortile
| lrocktile
| ftile
| rtile
| tile
| shuffle
| clear
| tags
| kfeat
| kitem
| kmons
| kmask
| kprop
| fheight
| subvault
| main_lua
| prelude_lua
| validate_lua
| veto_lua
| epilogue_lua
| error_seq {}
;
global_lua : MAIN global_lua_lines { }
global_lua_lines : /* empty */ { }
| global_lua_lines global_lua_line { }
;
global_lua_line : LUA_LINE
{
lc_global_prelude.add(yylineno, $1);
}
main_lua : MAIN main_lua_lines { }
main_lua_lines : /* empty */ { }
| main_lua_lines main_lua_line { }
;
main_lua_line : LUA_LINE
{
lc_map.main.add(yylineno, $1);
}
validate_lua : VALIDATE validate_lua_lines { }
validate_lua_lines : /* empty */ { }
| validate_lua_lines validate_lua_line { }
;
validate_lua_line : LUA_LINE
{
lc_map.validate.add(yylineno, $1);
}
veto_lua : VETO veto_lua_lines { }
veto_lua_lines : /* empty */ { }
| veto_lua_lines veto_lua_line { }
;
veto_lua_line : LUA_LINE
{
lc_map.veto.add(yylineno, $1);
}
prelude_lua : PRELUDE prelude_lua_lines { }
prelude_lua_lines : /* empty */ { }
| prelude_lua_lines prelude_lua_line { }
;
prelude_lua_line : LUA_LINE
{
lc_map.prelude.add(yylineno, $1);
}
epilogue_lua : EPILOGUE epilogue_lua_lines { }
epilogue_lua_lines : /* empty */ { }
| epilogue_lua_lines epilogue_lua_line { }
;
epilogue_lua_line : LUA_LINE
{
lc_map.epilogue.add(yylineno, $1);
}
kfeat : KFEAT { }
| KFEAT STRING
{
lc_map.main.add(
yylineno,
make_stringf("kfeat(\"%s\")",
quote_lua_string($2).c_str()));
}
kmons : KMONS { }
| KMONS STRING
{
lc_map.main.add(
yylineno,
make_stringf("kmons(\"%s\")",
quote_lua_string($2).c_str()));
}
kitem : KITEM { }
| KITEM STRING
{
lc_map.main.add(
yylineno,
make_stringf("kitem(\"%s\")",
quote_lua_string($2).c_str()));
}
kmask : KMASK { }
| KMASK STRING
{
lc_map.main.add(
yylineno,
make_stringf("kmask(\"%s\")",
quote_lua_string($2).c_str()));
}
kprop : KPROP { }
| KPROP STRING
{
lc_map.main.add(
yylineno,
make_stringf("kprop(\"%s\")",
quote_lua_string($2).c_str()));
}
shuffle : SHUFFLE shuffle_specifiers {}
;
shuffle_specifiers : shuffle_spec
| shuffle_specifiers COMMA shuffle_spec
;
shuffle_spec : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("shuffle(\"%s\")",
quote_lua_string($1).c_str()));
}
clear : CLEAR STRING
{
lc_map.main.add(
yylineno,
make_stringf("clear(\"%s\")",
quote_lua_string($2).c_str()));
}
;
tags : TAGS tagstrings {}
;
tagstrings : /* empty */
| tagstrings tagstring
;
tagstring : STRING
{
lc_map.main.add(
yylineno,
make_stringf("tags(\"%s\")",
quote_lua_string($1).c_str()));
}
;
marker : MARKER STRING
{
string key, arg;
int sep(0);
const string err =
mapdef_split_key_item($2, &key, &sep, &arg);
if (!err.empty())
yyerror(err.c_str());
// Special treatment for Lua markers.
if (arg.find("lua:") == 0)
{
arg = arg.substr(4);
lc_map.main.add(
yylineno,
make_stringf("lua_marker(\"%s\", function () "
" return %s "
"end)",
quote_lua_string(key).c_str(),
arg.c_str()));
}
else
{
lc_map.main.add(
yylineno,
make_stringf("marker(\"%s\")",
quote_lua_string($2).c_str()));
}
}
;
colour : COLOUR colour_specifiers { }
;
lfloorcol : LFLOORCOL { }
| LFLOORCOL STRING
{
lc_map.main.add(
yylineno,
make_stringf("lfloorcol(\"%s\")",
quote_lua_string($2).c_str()));
}
lrockcol : LROCKCOL { }
| LROCKCOL STRING
{
lc_map.main.add(
yylineno,
make_stringf("lrockcol(\"%s\")",
quote_lua_string($2).c_str()));
}
lfloortile : LFLOORTILE { }
| LFLOORTILE STRING
{
lc_map.main.add(
yylineno,
make_stringf("lfloortile(\"%s\")",
quote_lua_string($2).c_str()));
}
;
lrocktile : LROCKTILE { }
| LROCKTILE STRING
{
lc_map.main.add(
yylineno,
make_stringf("lrocktile(\"%s\")",
quote_lua_string($2).c_str()));
}
;
fheight : FHEIGHT fheight_specifiers
fheight_specifiers: fheight_specifier
| fheight_specifiers COMMA fheight_specifier
;
fheight_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("fheight(\"%s\")",
quote_lua_string($1).c_str()));
}
;
ftile : FTILE ftile_specifiers
;
ftile_specifiers: ftile_specifier
| ftile_specifiers COMMA ftile_specifier
;
ftile_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("ftile(\"%s\")",
quote_lua_string($1).c_str()));
}
;
rtile : RTILE rtile_specifiers
;
rtile_specifiers: rtile_specifier
| rtile_specifiers COMMA rtile_specifier
;
rtile_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("rtile(\"%s\")",
quote_lua_string($1).c_str()));
}
;
tile : TILE tile_specifiers
;
tile_specifiers : tile_specifier
| tile_specifiers COMMA tile_specifier
;
tile_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("tile(\"%s\")",
quote_lua_string($1).c_str()));
}
;
colour_specifiers : colour_specifier { }
| colour_specifiers COMMA colour_specifier { }
;
colour_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("colour(\"%s\")",
quote_lua_string($1).c_str()));
}
;
nsubst : NSUBST nsubst_specifiers { }
;
nsubst_specifiers : nsubst_spec { }
| nsubst_specifiers COMMA nsubst_spec { }
;
nsubst_spec : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("nsubst(\"%s\")",
quote_lua_string($1).c_str()));
}
;
subst : SUBST subst_specifiers { }
;
subst_specifiers : subst_spec
| subst_spec COMMA subst_specifiers
;
subst_spec : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("subst(\"%s\")",
quote_lua_string($1).c_str()));
}
;
items : ITEM {}
| ITEM item_specifiers {}
;
item_specifiers : item_specifiers COMMA item_specifier
| item_specifier
;
item_specifier : ITEM_INFO
{
lc_map.main.add(
yylineno,
make_stringf("item(\"%s\")",
quote_lua_string($1).c_str()));
}
mons : MONS {}
| MONS mnames {}
;
mnames : mname COMMA mnames
| mname
;
mname : MONSTER_NAME
{
lc_map.main.add(
yylineno,
make_stringf("mons(\"%s\")",
quote_lua_string($1).c_str()));
}
;
place : PLACE STRING
{
lc_map.main.add(
yylineno,
make_stringf("place(\"%s\")",
quote_lua_string($2).c_str()));
}
;
desc : DESC STRING
{
lc_map.main.add(
yylineno,
make_stringf("desc(\"%s\")",
quote_lua_string($2).c_str()));
}
;
order : ORDER NUMBER
{
lc_map.main.add(
yylineno,
make_stringf("order(%d)", int($2)));
}
;
depth : DEPTH {}
| DEPTH STRING
{
lc_map.main.add(
yylineno,
make_stringf("depth(\"%s\")",
quote_lua_string($2).c_str()));
}
;
chance : CHANCE chance_specifiers { }
| CHANCE { }
;
chance_specifiers : chance_specifiers COMMA chance_specifier
| chance_specifier;
chance_roll : NUMBER PERC
{
$$ = $1 * 100;
}
| NUMBER
{
$$ = $1;
}
chance_specifier : chance_roll STRING
{
lc_map.main.add(
yylineno,
make_stringf("depth_chance(\"%s\", %d)",
quote_lua_string($2).c_str(), (int)$1));
}
| chance_roll
{
lc_map.main.add(
yylineno,
make_stringf("chance(%d)", (int)$1));
}
;
weight : WEIGHT weight_specifiers;
weight_specifiers : weight_specifiers COMMA weight_specifier
| weight_specifier;
weight_specifier : NUMBER STRING
{
lc_map.main.add(
yylineno,
make_stringf("depth_weight(\"%s\", %d)",
quote_lua_string($2).c_str(), (int)$1));
}
| NUMBER
{
lc_map.main.add(
yylineno,
make_stringf("weight(%d)", (int)$1));
}
;
orientation : ORIENT {}
| ORIENT STRING
{
lc_map.main.add(
yylineno,
make_stringf("orient(\"%s\")",
quote_lua_string($2).c_str()));
}
;
welcome : WELCOME STRING
{
lc_map.main.add(
yylineno,
make_stringf("welcome(\"%s\")",
quote_lua_string($2).c_str()));
}
;
map_def : map_lines
;
map_lines : map_lines map_line
| map_line
;
map_line : MAP_LINE
{
lc_map.mapchunk.add(
yylineno,
make_stringf("map(\"%s\")",
quote_lua_string($1).c_str()));
}
;
subvault : SUBVAULT subvault_specifiers
;
subvault_specifiers: subvault_specifier
| subvault_specifiers COMMA subvault_specifier
;
subvault_specifier : STRING
{
lc_map.main.add(
yylineno,
make_stringf("subvault(\"%s\")",
quote_lua_string($1).c_str()));
}
;
%%
|