diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tcsh/src/tiger_parse.i | |
Diffstat (limited to 'tiger-compiler/tcsh/src/tiger_parse.i')
| -rw-r--r-- | tiger-compiler/tcsh/src/tiger_parse.i | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tiger-compiler/tcsh/src/tiger_parse.i b/tiger-compiler/tcsh/src/tiger_parse.i new file mode 100644 index 0000000..1d62bd8 --- /dev/null +++ b/tiger-compiler/tcsh/src/tiger_parse.i @@ -0,0 +1,102 @@ +// -*- C++ -*- + +%module tiger_parse + +%include "std_string.i" +%include "std_pair.i" + +%{ + #include <sstream> + #include <misc/error.hh> + #include <parse/location.hh> + #include <parse/tiger-driver.hh> + #include <parse/libparse.hh> +%} + +%import "tiger_misc.i" + +%include "parse/fwd.hh" + +// Explicit instantiation of MetavarMap's. +%include "parse/metavar-map.hh" +%template(MetavarMap) parse::MetavarMap<ast::Exp>; +%template(MetavarVar) parse::MetavarMap<ast::Var>; +%template(MetavarNameTy) parse::MetavarMap<ast::NameTy>; +%template(MetavarChunkList) parse::MetavarMap<ast::ChunkList>; +%template(MetavarTweast) parse::MetavarMap<parse::Tweast>; + +/*------------------. +| parse::position. | +`------------------*/ + +// Replace parse::position's ctor and ignore parse::position::initialize, +// as Python is unable to parse the literal `1u' used as default value +// of two of their arguments. +%extend parse::position +{ + // External ctor. For more information, see + // http://www.nabble.com/Java---adding-code-to-a-constructor-td20210601.html + position (const std::string* f = nullptr, + unsigned int l = 1, unsigned int c = 1) + { + return new parse::position(f, l, c); + } +} +%ignore parse::position::position; +%ignore parse::position::initialize; +%extend parse::position +{ + std::string + __str__ () const + { + std::ostringstream o; + o << *$self; + return o.str (); + } +} + +/*------------------. +| parse::location. | +`------------------*/ + +// Ignore parse::location::initialize, as Python is unable to +// parse the literal `1u' used as default value of two of its +// arguments. +%ignore parse::location::initialize; +%include "parse/location.hh" +%extend parse::location +{ + std::string + __str__ () const + { + std::ostringstream o; + o << *$self; + return o.str (); + } +} + +/*-----------. +| libparse. | +`-----------*/ + +%import "parse/tweast.hh" +%include "parse/tiger-driver.hh" +%inline +{ + namespace parse + { + // Parse a Tiger file, return the corresponding abstract syntax. + ast::ChunkList* + parse (const std::string& prelude, const std::string& fname, + misc::file_library& library) + { + std::pair<ast::ChunkList*, misc::error> res = + parse (prelude, fname, library, false, false, true); + res.second.exit_on_error(); + return res.first; + } + } + +} + +%include "parse/libparse.hh" |
