Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change file_substr to allow for external strings.
  • Loading branch information
kevina authored and nikomatsakis committed Feb 15, 2012
1 parent ff6b71f commit 74b4345
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/comp/syntax/codemap.rs
Expand Up @@ -8,8 +8,11 @@ type file_pos = {ch: uint, byte: uint};
* compiler.
*/

type file_substr_ = {lo: uint, hi: uint, col: uint, line: uint};
type file_substr = option<file_substr_>;
enum file_substr {
fss_none,
fss_internal(span),
fss_external({filename: str, line: uint, col: uint})
}

type filemap =
@{name: filename, substr: file_substr, src: @str,
Expand All @@ -33,16 +36,16 @@ fn new_filemap_w_substr(filename: filename, substr: file_substr,
fn new_filemap(filename: filename, src: @str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
ret new_filemap_w_substr(filename, none, src,
ret new_filemap_w_substr(filename, fss_none, src,
start_pos_ch, start_pos_byte);
}

fn get_substr_info(cm: codemap, lo: uint, hi: uint)
-> (filename, file_substr_)
fn get_substr_info(cm: codemap, sp: span)
-> (filename, file_substr)
{
let pos = lookup_char_pos(cm, lo);
let pos = lookup_char_pos(cm, sp.lo);
let name = #fmt("<%s:%u:%u>", pos.file.name, pos.line, pos.col);
ret (name, {lo: lo, hi: hi, col: pos.col, line: pos.line});
ret (name, fss_internal(sp));
}

fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
Expand Down
7 changes: 3 additions & 4 deletions src/comp/syntax/ext/qquote.rs
Expand Up @@ -149,10 +149,9 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
{
let cm = ecx.session().parse_sess.cm;
let str = @codemap::span_to_snippet(body.span, cm);
let (fname, ss) = codemap::get_substr_info
(cm, body.span.lo, body.span.hi);
let (fname, ss) = codemap::get_substr_info(cm, body.span);
let node = parse_from_source_str
(f, fname, some(ss), str,
(f, fname, ss, str,
ecx.session().opts.cfg, ecx.session().parse_sess);
ret expand_qquote(ecx, node.span(), *str, node);
}
Expand Down Expand Up @@ -229,7 +228,7 @@ fn expand_qquote<N: qq_helper>
"parse_from_source_str"],
[node.mk_parse_fn(cx,sp),
mk_str(cx,sp, "<anon>"),
mk_path(cx,sp, ["option","none"]),
mk_path(cx,sp, ["syntax", "codemap", "fss_none"]),
mk_unary(cx,sp, ast::box(ast::imm),
mk_str(cx,sp, str2)),
mk_access_(cx,sp,
Expand Down
6 changes: 3 additions & 3 deletions src/comp/syntax/parse/parser.rs
Expand Up @@ -2,7 +2,7 @@ import std::{io, fs};
import either::{left, right};
import std::map::{hashmap, new_str_hash};
import token::can_begin_expr;
import codemap::span;
import codemap::{span,fss_none};
import util::interner;
import ast::{node_id, spanned};
import ast_util::{mk_sp, ident_to_path};
Expand Down Expand Up @@ -2618,7 +2618,7 @@ fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,

fn parse_expr_from_source_str(name: str, source: @str, cfg: ast::crate_cfg,
sess: parse_sess) -> @ast::expr {
let p = new_parser_from_source_str(sess, cfg, name, none, source);
let p = new_parser_from_source_str(sess, cfg, name, fss_none, source);
let r = parse_expr(p);
sess.chpos = p.reader.chpos;
sess.byte_pos = sess.byte_pos + p.reader.pos;
Expand All @@ -2640,7 +2640,7 @@ fn parse_from_source_str<T>(f: fn (p: parser) -> T,

fn parse_crate_from_source_str(name: str, source: @str, cfg: ast::crate_cfg,
sess: parse_sess) -> @ast::crate {
let p = new_parser_from_source_str(sess, cfg, name, none, source);
let p = new_parser_from_source_str(sess, cfg, name, fss_none, source);
let r = parse_crate_mod(p, cfg);
sess.chpos = p.reader.chpos;
sess.byte_pos = sess.byte_pos + p.reader.pos;
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc/attr_parser.rs
Expand Up @@ -93,7 +93,7 @@ mod test {
mutable byte_pos: 0u
};
let parser = parser::new_parser_from_source_str(
parse_sess, [], "-", none, @source);
parse_sess, [], "-", codemap::fss_none, @source);

parser::parse_outer_attributes(parser)
}
Expand Down

0 comments on commit 74b4345

Please sign in to comment.