From 1d0f57cbceb778139ca215cc4fcfd1584951f6dd Mon Sep 17 00:00:00 2001 From: dshaligram Date: Wed, 22 Nov 2006 08:41:20 +0000 Subject: 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 --- crawl-ref/source/util/levcomp.ypp | 226 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 crawl-ref/source/util/levcomp.ypp (limited to 'crawl-ref/source/util/levcomp.ypp') 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 BRANCHDEF BRANCH DESC DEFAULT +%token DEFAULT_DEPTH SYMBOL TAGS +%token NAME DEPTH ORIENT PLACE CHANCE FLAGS MONS +%token ROOT_DEPTH ENTRY_MSG EXIT_MSG +%token ROCK_COLOUR FLOOR_COLOUR +%token ENCOMPASS +%token NORTH EAST SOUTH WEST +%token NORTHEAST SOUTHEAST SOUTHWEST NORTHWEST + +%token LEVEL END PVAULT PMINIVAULT MONSTERS ENDMONSTERS + +%token CHARACTER + +%token NO_HMIRROR NO_VMIRROR NO_ROTATE + +%token PANDEMONIC +%token DASH COMMA QUOTE OPAREN CPAREN +%token INTEGER + +%type orient_name flagname + +%token STRING MAP_LINE MONSTER_NAME +%token 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); + } + ; + +%% -- cgit v1.2.3-54-g00ecf