File tree 2 files changed +16
-11
lines changed
2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change 20
20
#define RUST_AST_MACRO_H
21
21
22
22
#include " rust-ast.h"
23
+ #include " rust-location.h"
23
24
24
25
namespace Rust {
25
26
namespace AST {
@@ -295,26 +296,28 @@ struct MacroRule
295
296
private:
296
297
MacroMatcher matcher;
297
298
MacroTranscriber transcriber;
298
-
299
- // TODO: should store location information?
299
+ Location locus;
300
300
301
301
public:
302
- MacroRule (MacroMatcher matcher, MacroTranscriber transcriber)
303
- : matcher (std::move (matcher)), transcriber (std::move (transcriber))
302
+ MacroRule (MacroMatcher matcher, MacroTranscriber transcriber, Location locus)
303
+ : matcher (std::move (matcher)), transcriber (std::move (transcriber)),
304
+ locus (locus)
304
305
{}
305
306
306
307
// Returns whether macro rule is in error state.
307
308
bool is_error () const { return matcher.is_error (); }
308
309
309
310
// Creates an error state macro rule.
310
- static MacroRule create_error ()
311
+ static MacroRule create_error (Location locus )
311
312
{
312
- // FIXME: Once #928 is merged, give location to MacroMatcher
313
- return MacroRule (MacroMatcher::create_error (Location ()),
313
+ return MacroRule (MacroMatcher::create_error (locus),
314
314
MacroTranscriber (DelimTokenTree::create_empty (),
315
- Location ()));
315
+ Location ()),
316
+ locus);
316
317
}
317
318
319
+ Location get_locus () const { return locus; }
320
+
318
321
std::string as_string () const ;
319
322
};
320
323
Original file line number Diff line number Diff line change @@ -1678,23 +1678,25 @@ template <typename ManagedTokenSource>
1678
1678
AST::MacroRule
1679
1679
Parser<ManagedTokenSource>::parse_macro_rule ()
1680
1680
{
1681
+ Location locus = lexer.peek_token ()->get_locus ();
1682
+
1681
1683
// parse macro matcher
1682
1684
AST::MacroMatcher matcher = parse_macro_matcher ();
1683
1685
1684
1686
if (matcher.is_error ())
1685
- return AST::MacroRule::create_error ();
1687
+ return AST::MacroRule::create_error (locus );
1686
1688
1687
1689
if (!skip_token (MATCH_ARROW))
1688
1690
{
1689
1691
// skip after somewhere?
1690
- return AST::MacroRule::create_error ();
1692
+ return AST::MacroRule::create_error (locus );
1691
1693
}
1692
1694
1693
1695
// parse transcriber (this is just a delim token tree)
1694
1696
Location token_tree_loc = lexer.peek_token ()->get_locus ();
1695
1697
AST::MacroTranscriber transcriber (parse_delim_token_tree (), token_tree_loc);
1696
1698
1697
- return AST::MacroRule (std::move (matcher), std::move (transcriber));
1699
+ return AST::MacroRule (std::move (matcher), std::move (transcriber), locus );
1698
1700
}
1699
1701
1700
1702
// Parses a macro matcher (part of a macro rule definition).
You can’t perform that action at this time.
0 commit comments