summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util/levcomp.ypp
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 08:41:20 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-22 08:41:20 +0000
commit1d0f57cbceb778139ca215cc4fcfd1584951f6dd (patch)
treecafd60c944c51fcce778aa5d6912bc548c518339 /crawl-ref/source/util/levcomp.ypp
parent6f5e187a9e5cd348296dba2fd89d2e206e775a01 (diff)
downloadcrawl-ref-1d0f57cbceb778139ca215cc4fcfd1584951f6dd.tar.gz
crawl-ref-1d0f57cbceb778139ca215cc4fcfd1584951f6dd.zip
Merged stone_soup r15:451 into trunk.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@452 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/util/levcomp.ypp')
-rw-r--r--crawl-ref/source/util/levcomp.ypp226
1 files changed, 226 insertions, 0 deletions
diff --git a/crawl-ref/source/util/levcomp.ypp b/crawl-ref/source/util/levcomp.ypp
new file mode 100644
index 0000000000..e419bdc878
--- /dev/null
+++ b/crawl-ref/source/util/levcomp.ypp
@@ -0,0 +1,226 @@
+%{
+
+#include "AppHdr.h"
+#include "libutil.h"
+#include "levcomp.h"
+
+int yylex();
+
+extern int yylineno;
+
+void yyerror(const char *e)
+{
+ fprintf(stderr, "%s:%d: %s\n", lc_desfile.c_str(), yylineno, e);
+ // Bail bail bail.
+ exit(1);
+}
+
+%}
+
+%union
+{
+ int i;
+ const char *text;
+}
+
+%token <i> BRANCHDEF BRANCH DESC DEFAULT
+%token <i> DEFAULT_DEPTH SYMBOL TAGS
+%token <i> NAME DEPTH ORIENT PLACE CHANCE FLAGS MONS
+%token <i> ROOT_DEPTH ENTRY_MSG EXIT_MSG
+%token <i> ROCK_COLOUR FLOOR_COLOUR
+%token <i> ENCOMPASS
+%token <i> NORTH EAST SOUTH WEST
+%token <i> NORTHEAST SOUTHEAST SOUTHWEST NORTHWEST
+
+%token <i> LEVEL END PVAULT PMINIVAULT MONSTERS ENDMONSTERS
+
+%token <i> CHARACTER
+
+%token <i> NO_HMIRROR NO_VMIRROR NO_ROTATE
+
+%token <i> PANDEMONIC
+%token <i> DASH COMMA QUOTE OPAREN CPAREN
+%token <i> INTEGER
+
+%type <i> orient_name flagname
+
+%token <text> STRING MAP_LINE MONSTER_NAME
+%token <text> IDENTIFIER
+
+%%
+
+file : definitions { }
+ ;
+
+definitions : /* empty */ {}
+ | definition definitions {}
+ ;
+
+definition : def {}
+ | level {}
+ ;
+
+def : defdepth
+ ;
+
+defdepth : DEFAULT_DEPTH depth_range
+ {
+ lc_default_depth = lc_range;
+ }
+ ;
+
+level : name metalines map_def metalines
+ {
+ add_parsed_map( lc_map );
+ }
+ ;
+
+name : NAME STRING
+ {
+ lc_map.init();
+ lc_map.depth = lc_default_depth;
+ lc_map.name = $2;
+ }
+ ;
+
+metalines : /* no metadata */
+ | metaline metalines
+ ;
+
+metaline : place
+ | depth
+ | chance
+ | orientation
+ | flags
+ | mons
+ | symbol
+ | tags
+ ;
+
+tags : TAGS tagstrings {}
+ ;
+
+tagstrings : /* empty */
+ | STRING tagstrings
+ {
+ lc_map.tags += " ";
+ lc_map.tags += $1;
+ lc_map.tags += " ";
+ }
+ ;
+
+symbol : SYMBOL {}
+ | SYMBOL STRING
+ {
+ lc_map.random_symbols = $2;
+ }
+ ;
+
+mons : MONS {}
+ | MONS mnames {}
+ ;
+
+mnames : mname COMMA mnames
+ | mname
+ ;
+
+mname : MONSTER_NAME
+ {
+ bool recognised = lc_map.mons.add_mons($1);
+ if (!recognised)
+ {
+ char buf[300];
+ snprintf(buf, sizeof buf, "unknown monster '%s'",
+ $1);
+ yyerror(buf);
+ }
+ }
+ ;
+
+place : PLACE STRING
+ {
+ lc_map.place = $2;
+ }
+ ;
+
+depth : DEPTH {}
+ | DEPTH depth_range
+ {
+ lc_map.depth = lc_range;
+ }
+ ;
+
+depth_range : INTEGER DASH INTEGER
+ {
+ lc_range.set($1, $3);
+ }
+
+ | INTEGER
+ {
+ lc_range.set($1);
+ }
+ ;
+
+chance : CHANCE INTEGER
+ {
+ lc_map.chance = $2;
+ }
+ ;
+
+orientation : ORIENT {}
+ | ORIENT orient_name
+ {
+ lc_map.orient = (map_section_type) $2;
+ }
+ ;
+
+orient_name : ENCOMPASS { $$ = MAP_ENCOMPASS; }
+ | NORTH { $$ = MAP_NORTH; }
+ | EAST { $$ = MAP_EAST; }
+ | SOUTH { $$ = MAP_SOUTH; }
+ | WEST { $$ = MAP_WEST; }
+ | NORTHEAST { $$ = MAP_NORTHEAST; }
+ | SOUTHEAST { $$ = MAP_SOUTHEAST; }
+ | SOUTHWEST { $$ = MAP_SOUTHWEST; }
+ | NORTHWEST { $$ = MAP_NORTHWEST; }
+ ;
+
+flags : FLAGS flagnames {}
+ ;
+
+flagnames : /* empty */
+ | flagname flagnames
+ {
+ switch ($1) {
+ case NO_HMIRROR:
+ lc_map.flags &= ~MAPF_MIRROR_HORIZONTAL;
+ break;
+ case NO_VMIRROR:
+ lc_map.flags &= ~MAPF_MIRROR_VERTICAL;
+ break;
+ case NO_ROTATE:
+ lc_map.flags &= ~MAPF_ROTATE;
+ break;
+ }
+ }
+ ;
+
+flagname : NO_HMIRROR { $$ = NO_HMIRROR; }
+ | NO_VMIRROR { $$ = NO_VMIRROR; }
+ | NO_ROTATE { $$ = NO_ROTATE; }
+ ;
+
+map_def : map_lines
+ ;
+
+map_lines : map_line
+ | map_line map_lines
+ ;
+
+map_line : MAP_LINE
+ {
+ lc_map.map.add_line($1);
+ }
+ ;
+
+%%