* Clean up the imploded parse tree. Quotes around strings are

removed, paths are absolutised relative to the path containing the
  expression we just parsed, and integer literals are converted to
  actual integers.
This commit is contained in:
Eelco Dolstra 2003-10-30 16:18:40 +00:00
parent e537844f4e
commit 9f8f39aa3c
4 changed files with 57 additions and 11 deletions

View file

@ -1,6 +1,6 @@
bin_PROGRAMS = fix-ng bin_PROGRAMS = fix-ng
fix_ng_SOURCES = fix.cc parser.cc fix_ng_SOURCES = fix-expr.cc parser.cc fix.cc
fix_ng_LDADD = ../libmain/libmain.a ../libnix/libnix.a ../boost/format/libformat.a \ fix_ng_LDADD = ../libmain/libmain.a ../libnix/libnix.a ../boost/format/libformat.a \
-L../../externals/inst/lib -ldb_cxx -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm -L../../externals/inst/lib -ldb_cxx -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm

View file

@ -29,5 +29,5 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
return (ATerm) ATreverse(out); return (ATerm) ATreverse(out);
} }
throw badTerm("cannot rewrite", e); return e;
} }

View file

@ -1,3 +1,9 @@
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
extern "C" { extern "C" {
#include <sglr.h> #include <sglr.h>
#include <asfix2.h> #include <asfix2.h>
@ -5,15 +11,58 @@ extern "C" {
#include "parser.hh" #include "parser.hh"
#include "shared.hh" #include "shared.hh"
#include "fix-expr.hh"
#include "expr.hh" #include "expr.hh"
#include "parse-table.h" #include "parse-table.h"
Expr parseExprFromFile(const Path & path) struct Cleanup : TermFun
{ {
string basePath;
virtual ATerm operator () (ATerm e)
{
char * s;
if (ATmatch(e, "Str(<str>)", &s)) {
string s2(s);
return ATmake("Str(<str>)",
string(s2, 1, s2.size() - 2).c_str());
}
if (ATmatch(e, "Path(<str>)", &s)) {
string path(s);
if (path[0] != '/')
path = basePath + "/" + path;
return ATmake("Str(<str>)", canonPath(path).c_str());
}
if (ATmatch(e, "Int(<str>)", &s)) {
istringstream s2(s);
int n;
s2 >> n;
return ATmake("Int(<int>)", n);
}
return e;
}
};
Expr parseExprFromFile(Path path)
{
#if 0
/* Perhaps this is already an imploded parse tree? */ /* Perhaps this is already an imploded parse tree? */
Expr e = ATreadFromNamedFile(path.c_str()); Expr e = ATreadFromNamedFile(path.c_str());
if (e) return e; if (e) return e;
#endif
/* If `path' refers to a directory, append `/default.fix'. */
struct stat st;
if (stat(path.c_str(), &st))
throw SysError(format("getting status of `%1%'") % path);
if (S_ISDIR(st.st_mode))
path = canonPath(path + "/default.fix");
/* Initialise the SDF libraries. */ /* Initialise the SDF libraries. */
static bool initialised = false; static bool initialised = false;
@ -72,5 +121,7 @@ Expr parseExprFromFile(const Path & path)
if (!imploded) if (!imploded)
throw Error(format("cannot implode parse tree")); throw Error(format("cannot implode parse tree"));
return imploded; Cleanup cleanup;
cleanup.basePath = dirOf(path);
return bottomupRewrite(cleanup, imploded);
} }

View file

@ -1,15 +1,10 @@
#ifndef __PARSER_H #ifndef __PARSER_H
#define __PARSER_H #define __PARSER_H
#include <string> #include "fix-expr.hh"
#include <aterm2.h>
#include "util.hh"
typedef ATerm Expr; Expr parseExprFromFile(Path path);
Expr parseExprFromFile(const Path & path);
#endif /* !__PARSER_H */ #endif /* !__PARSER_H */