diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-02-27 22:30:36 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-02-27 22:30:36 (GMT) |
commit | 955de4aa1b2100b8f9d0c9bd407d1cd127ed2212 (patch) | |
tree | d742bccb0cafe4590a8f2272268b38eba7af4e45 /src | |
parent | 738174847a7d78cba9c2b7eb6fb485da945363f1 (diff) |
Clifford Wolf:
Added include<...> statement
Prepared use<...> statement
git-svn-id: http://svn.clifford.at/openscad/trunk@457 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer.l | 29 | ||||
-rw-r--r-- | src/module.h | 2 | ||||
-rw-r--r-- | src/parser.y | 8 |
3 files changed, 37 insertions, 2 deletions
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 <filename>' 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<QString> usedlibs; + QVector<QString> argnames; QVector<Expression*> 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 <text> TOK_ID %token <text> TOK_STRING +%token <text> TOK_USE %token <number> 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); |