From 955de4aa1b2100b8f9d0c9bd407d1cd127ed2212 Mon Sep 17 00:00:00 2001 From: clifford Date: Sat, 27 Feb 2010 22:30:36 +0000 Subject: Clifford Wolf: Added include<...> statement Prepared use<...> statement git-svn-id: http://svn.clifford.at/openscad/trunk@457 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/src/lexer.l b/src/lexer.l index 5a5c0e9..24ec83b 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -67,7 +67,33 @@ extern const char *parser_source_path; %% -"<"[^ \t\n>]+">" { +include[ \t\r\n>]*"<"[^ \t\r\n>]+">" { + QString filename(yytext); + filename.remove(QRegExp("^include[ \t\r\n>]*<")); + filename.remove(QRegExp(">$")); + QFileInfo finfo(QDir(parser_source_path), filename); + if (!finfo.exists()) { + finfo = QFileInfo(QDir(librarydir), filename); + } + handle_dep(finfo.absoluteFilePath()); + yyin = fopen(finfo.absoluteFilePath().toLocal8Bit(), "r"); + if (!yyin) { + PRINTA("WARNING: Can't open input file `%1'.", filename); + } else { + yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE )); + BEGIN(INITIAL); + } +} + +use[ \t\r\n>]*"<"[^ \t\r\n>]+">" { + QString filename(yytext); + filename.remove(QRegExp("^use[ \t\r\n>]*<")); + filename.remove(QRegExp(">$")); + parserlval.text = strdup(filename.toLocal8Bit()); + return TOK_USE; +} + +"<"[^ \t\r\n>]+">" { char *filename = strdup(yytext+1); filename[strlen(filename)-1] = 0; QFileInfo finfo(QDir(parser_source_path), filename); @@ -75,6 +101,7 @@ extern const char *parser_source_path; finfo = QFileInfo(QDir(librarydir), filename); } + PRINTF("WARNING: The use of implicit include is depricated. Use `include ' instead."); handle_dep(finfo.absoluteFilePath()); yyin = fopen(finfo.absoluteFilePath().toLocal8Bit(), "r"); if (!yyin) { diff --git a/src/module.h b/src/module.h index 20ea1af..66228dd 100644 --- a/src/module.h +++ b/src/module.h @@ -46,6 +46,8 @@ public: class Module : public AbstractModule { public: + QVector usedlibs; + QVector argnames; QVector argexpr; diff --git a/src/parser.y b/src/parser.y index a0e4ac9..8d31cd5 100644 --- a/src/parser.y +++ b/src/parser.y @@ -74,6 +74,7 @@ public: %token TOK_ID %token TOK_STRING +%token TOK_USE %token TOK_NUMBER %token TOK_TRUE @@ -117,11 +118,16 @@ public: input: /* empty */ | + TOK_USE { module->usedlibs.append($1); } input | statement input ; +inner_input: + /* empty */ | + statement inner_input ; + statement: ';' | - '{' input '}' | + '{' inner_input '}' | module_instantiation { if ($1) { module->children.append($1); -- cgit v0.10.1