diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-14 16:34:18 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-14 16:34:50 -0800 |
| commit | 8069d2f266b5e5f21d9cc846b0b8b8daa1812dcc (patch) | |
| tree | bd3c033738fdaad9d929ce921ad8f17b90f12167 /src/libsyntax/parse/eval.rs | |
| parent | f67bfe97389a256fc95216c29a2b8a066ee16a2c (diff) | |
| download | rust-8069d2f266b5e5f21d9cc846b0b8b8daa1812dcc.tar.gz rust-8069d2f266b5e5f21d9cc846b0b8b8daa1812dcc.zip | |
Track character and byte positions together in the parser
Diffstat (limited to 'src/libsyntax/parse/eval.rs')
| -rw-r--r-- | src/libsyntax/parse/eval.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs index 56c9d4de9f3..bfbec5c530f 100644 --- a/src/libsyntax/parse/eval.rs +++ b/src/libsyntax/parse/eval.rs @@ -2,6 +2,7 @@ use parser::{Parser, SOURCE_FILE}; use attr::parser_attr; export eval_crate_directives_to_mod; +export update_parse_sess_position; type ctx = @{sess: parse::parse_sess, @@ -66,14 +67,20 @@ fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &Option<Path>) modpath, SOURCE_FILE); let inner_attrs = p0.parse_inner_attrs_and_next(); let m0 = p0.parse_mod_items(token::EOF, inner_attrs.next); - cx.sess.chpos = r0.chpos; - cx.sess.byte_pos = cx.sess.byte_pos + r0.pos; + update_parse_sess_position(&cx.sess, &r0); return (m0.view_items, m0.items, inner_attrs.inner); } else { return (~[], ~[], ~[]); } } +fn update_parse_sess_position(sess: &parse_sess, r: &lexer::string_reader) { + sess.pos = FilePos { + ch: r.chpos, + byte: sess.pos.byte + r.pos + }; +} + fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { match ::attr::first_attr_value_str_by_name(attrs, ~"path") { Some(d) => d, @@ -105,8 +112,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, /* FIXME (#2543) */ copy id, ast::item_mod(m0), vis, mod_attrs); // Thread defids, chpos and byte_pos through the parsers - cx.sess.chpos = r0.chpos; - cx.sess.byte_pos = cx.sess.byte_pos + r0.pos; + update_parse_sess_position(&cx.sess, &r0); items.push(i); } ast::cdir_dir_mod(vis, id, cdirs, attrs) => { |
