summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util
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
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')
-rw-r--r--crawl-ref/source/util/levcomp.cc18
-rw-r--r--crawl-ref/source/util/levcomp.h12
-rw-r--r--crawl-ref/source/util/levcomp.lpp155
-rw-r--r--crawl-ref/source/util/levcomp.ypp226
4 files changed, 411 insertions, 0 deletions
diff --git a/crawl-ref/source/util/levcomp.cc b/crawl-ref/source/util/levcomp.cc
new file mode 100644
index 0000000000..5e0bb4cb64
--- /dev/null
+++ b/crawl-ref/source/util/levcomp.cc
@@ -0,0 +1,18 @@
+#include "AppHdr.h"
+#include "levcomp.h"
+
+std::string lc_desfile;
+map_def lc_map;
+level_range lc_range;
+level_range lc_default_depth;
+
+extern int yylineno;
+
+void reset_map_parser()
+{
+ lc_map.init();
+ lc_range.reset();
+ lc_default_depth.reset();
+
+ yylineno = 1;
+}
diff --git a/crawl-ref/source/util/levcomp.h b/crawl-ref/source/util/levcomp.h
new file mode 100644
index 0000000000..99f0495f90
--- /dev/null
+++ b/crawl-ref/source/util/levcomp.h
@@ -0,0 +1,12 @@
+#include <cstdio>
+#include <string>
+#include <vector>
+#include "mapdef.h"
+#include "maps.h"
+
+extern map_def lc_map;
+extern level_range lc_range;
+extern level_range lc_default_depth;
+extern std::string lc_desfile;
+
+void reset_map_parser();
diff --git a/crawl-ref/source/util/levcomp.lpp b/crawl-ref/source/util/levcomp.lpp
new file mode 100644
index 0000000000..69ad33ee23
--- /dev/null
+++ b/crawl-ref/source/util/levcomp.lpp
@@ -0,0 +1,155 @@
+%{
+
+// levcomp.l:
+// Level compiler lexer for Dungeon Crawl Stone Soup.
+//
+// Based loosely on NetHack's lev_comp.l
+
+#include "AppHdr.h"
+#include "levcomp.tab.h"
+#include <cstring>
+
+static bool alloced = false;
+
+static void clean()
+{
+ if (yylval.text && alloced)
+ free( (void*) yylval.text);
+ yylval.text = NULL;
+ alloced = false;
+}
+
+static void settext()
+{
+ clean();
+ if ((yylval.text = strdup(yytext)))
+ alloced = true;
+}
+
+%}
+
+%s MAPDEF
+%s ARGUMENT
+%s MNAME
+%s KEYWORDS
+
+%option yylineno
+%option never-interactive
+
+NSPACE [^\ \t\r\n]
+
+%%
+
+<MAPDEF>^\s*ENDMAP { BEGIN(INITIAL); }
+
+<MAPDEF>^#.*\r?\n ;
+
+<MAPDEF>[a-zA-Z_&0-9|$+.@^#()\[\]=<>{}%*\-?]* {
+ settext();
+ return MAP_LINE;
+ }
+
+^\s*MAP { BEGIN(MAPDEF); }
+
+^\s*#.* ;
+
+NAME: { BEGIN(ARGUMENT); return NAME; }
+default-depth: return DEFAULT_DEPTH;
+DEPTH: return DEPTH;
+ORIENT: return ORIENT;
+PLACE: { BEGIN(ARGUMENT); return PLACE; }
+CHANCE: return CHANCE;
+FLAGS: return FLAGS;
+TAGS: { BEGIN(KEYWORDS); return TAGS; }
+SYMBOL: { BEGIN(ARGUMENT); return SYMBOL; }
+MONS: { BEGIN(MNAME); return MONS; }
+
+BRANCHDEF: return BRANCH;
+DEFAULT return DEFAULT;
+DESC: return DESC;
+BRANCH: return BRANCH;
+ROOT_DEPTH: return ROOT_DEPTH;
+FLOOR_COLOUR: return FLOOR_COLOUR;
+ROCK_COLOUR: return ROCK_COLOUR;
+
+LEVEL return LEVEL;
+END return END;
+PVAULT: return PVAULT;
+PMINIVAULT: return PMINIVAULT;
+
+ENTRY_MSG: { BEGIN(ARGUMENT); return ENTRY_MSG; }
+EXIT_MSG: { BEGIN(ARGUMENT); return EXIT_MSG; }
+
+MONSTERS return MONSTERS;
+ENDMONSTERS return ENDMONSTERS;
+
+<KEYWORDS>[A-Za-z_0-9\-]+ {
+ settext();
+ return STRING;
+ }
+
+<KEYWORDS>[ \t]+ ;
+<KEYWORDS>[ \t]*\r?\n { BEGIN(INITIAL); }
+
+<MNAME>[^, \t\r\n][^,\r\n]+[^, \t\r\n] {
+ settext();
+ return MONSTER_NAME;
+ }
+
+<MNAME>, return COMMA;
+<MNAME>[ \t]*\r?\n { BEGIN(INITIAL); }
+<MNAME>[ \t] ;
+
+pandemonic return PANDEMONIC;
+no_hmirror return NO_HMIRROR;
+no_vmirror return NO_VMIRROR;
+no_rotate return NO_ROTATE;
+
+encompass return ENCOMPASS;
+north return NORTH;
+south return SOUTH;
+east return EAST;
+west return WEST;
+northeast return NORTHEAST;
+northwest return NORTHWEST;
+southeast return SOUTHEAST;
+southwest return SOUTHWEST;
+
+- return DASH;
+, return COMMA;
+
+[0-9]+ {
+ clean();
+ yylval.i = atoi(yytext);
+ return INTEGER;
+ }
+
+<ARGUMENT>{NSPACE}.*{NSPACE} {
+ BEGIN(INITIAL);
+ settext();
+ return STRING;
+ }
+
+<ARGUMENT>\r?\n { BEGIN(INITIAL); }
+
+[\ \t\r\n]+ ;
+
+\( return OPAREN;
+\) return CPAREN;
+
+\" return QUOTE;
+
+[a-zA-Z_][a-zA-Z_0-9]+ {
+ settext();
+ return IDENTIFIER;
+ }
+
+. return CHARACTER;
+
+%%
+
+int yywrap()
+{
+ clean();
+ return 1;
+}
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);
+ }
+ ;
+
+%%