Skip to content

Commit

Permalink
Proc Macro - Fix some errors in AST->Token translation
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Apr 19, 2024
1 parent b95585e commit 0bd439f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
32 changes: 21 additions & 11 deletions src/ast/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,7 @@ void RustPrinter::print_params(const AST::GenericParams& params)
m_os << "/*-*/";
}
TU_ARMA(Lifetime, p) {
//m_os << p.attrs();
m_os << "'" << p;
m_os << p;
}
TU_ARMA(Type, p) {
m_os << p.attrs();
Expand Down Expand Up @@ -1032,10 +1031,10 @@ void RustPrinter::print_bounds(const AST::GenericParams& params)
m_os << "/*-*/";
),
(Lifetime,
m_os << "'" << ent.test << ": '" << ent.bound;
m_os << ent.test << ": " << ent.bound;
),
(TypeLifetime,
m_os << ent.type << ": '" << ent.bound;
m_os << ent.type << ": " << ent.bound;
),
(IsTrait,
m_os << ent.outer_hrbs << ent.type << ": " << ent.inner_hrbs << ent.trait;
Expand Down Expand Up @@ -1141,6 +1140,9 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable)
print_pattern(sp.pat, is_refutable);
m_os << ",";
}
if( v.is_exhaustive ) {
m_os << "..";
}
m_os << "}";
}),
(Tuple,
Expand All @@ -1150,14 +1152,17 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable)
),
(Slice,
m_os << "[";
m_os << v.sub_pats;
for(const auto& sp : v.sub_pats) {
print_pattern(sp, is_refutable);
m_os << ", ";
}
m_os << "]";
),
(SplitSlice,
m_os << "[";
bool needs_comma = false;
if(v.leading.size()) {
m_os << v.leading;
for(const auto& sp : v.leading) {
print_pattern(sp, is_refutable);
m_os << ", ";
}

Expand Down Expand Up @@ -1186,14 +1191,19 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable)
if( needs_comma ) {
m_os << ", ";
}
m_os << v.trailing;
for(const auto& sp : v.trailing) {
print_pattern(sp, is_refutable);
m_os << ", ";
}
}
m_os << "]";
),
(Or,
m_os << "(";
for(const auto& e : v)
m_os << (&e == &v.front() ? "" : " | ") << e;
for(const auto& e : v) {
m_os << (&e == &v.front() ? "" : " | ");
print_pattern(e, is_refutable);
}
m_os << ")";
)
)
Expand Down Expand Up @@ -1230,7 +1240,7 @@ void RustPrinter::handle_struct(const AST::Struct& s)
inc_indent();
for( const auto& i : e.ents )
{
m_os << indent() << (i.m_is_public ? "pub " : "") << i.m_name << ": " << i.m_type.print_pretty() << "\n";
m_os << indent() << (i.m_is_public ? "pub " : "") << i.m_name << ": " << i.m_type.print_pretty() << ",\n";
}
dec_indent();
m_os << indent() << "}\n";
Expand Down
25 changes: 25 additions & 0 deletions src/expand/proc_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,38 @@ namespace {
break;
}
m_pmi.send_ident(b.m_name);
m_pmi.send_symbol("@");
}
TU_MATCH_HDRA( (pat.data()), { )
default:
TODO(sp, "visit_pattern " << pat.data().tag_str() << " - " << pat);
TU_ARMA(Any, e) {
m_pmi.send_symbol("_");
}
TU_ARMA(MaybeBind, e) {
m_pmi.send_ident(e.name);
}
TU_ARMA(Tuple, e) {
m_pmi.send_symbol("(");
visit_tuple_pattern(e);
m_pmi.send_symbol(")");
}
}
}
void visit_tuple_pattern(const AST::Pattern::TuplePat& v)
{
for(const auto& p : v.start) {
visit_pattern(p);
m_pmi.send_symbol(",");
}
if( v.has_wildcard )
{
m_pmi.send_symbol("..");
m_pmi.send_symbol(",");
for(const auto& p : v.end) {
visit_pattern(p);
m_pmi.send_symbol(",");
}
}
}
void visit_type(const ::TypeRef& ty)
Expand Down
9 changes: 6 additions & 3 deletions src/parse/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,13 @@ Token Lexer::getTokenInt()
// Character constant with an escape code
uint32_t val = this->parseEscape('\'');
if(this->getc() != '\'') {
throw ParseError::Todo("Proper error for lex failures");
TODO(this->point_span(), "Proper error for lex failures - multi-char const?");
}
return Token( U128(val), CORETYPE_CHAR);
}
else if( firstchar.v == '\'' ) {
TODO(this->point_span(), "Proper error for empty char literals");
}
else {
ch = this->getc();
if( ch == '\'' ) {
Expand All @@ -743,7 +746,7 @@ Token Lexer::getTokenInt()
return Token(TOK_LIFETIME, Ident(this->realGetHygiene(), RcString::new_interned(str)));
}
else {
throw ParseError::Todo("Lex Fail - Expected ' after character constant");
TODO(this->point_span(), "Lex Fail - Expected ' after character constant");
}
}
break; }
Expand Down Expand Up @@ -1113,7 +1116,7 @@ uint32_t Lexer::parseEscape(char enclosing)
else
return ch.v;
default:
throw ParseError::Todo( FMT("Unknown escape sequence \\" << ch) );
throw ParseError::Todo(*this, FMT("Unknown escape sequence \\" << ch) );
}
}

Expand Down

0 comments on commit 0bd439f

Please sign in to comment.