libsyntax: Remove the obsolete ability to parse from substrings.
This was used by the quasiquoter.
This commit is contained in:
parent
7232dbf768
commit
ff6c0af15b
2 changed files with 9 additions and 82 deletions
|
@ -191,15 +191,6 @@ pub struct FileLines
|
||||||
lines: ~[uint]
|
lines: ~[uint]
|
||||||
}
|
}
|
||||||
|
|
||||||
// represents the origin of a file:
|
|
||||||
pub enum FileSubstr {
|
|
||||||
// indicates that this is a normal standalone file:
|
|
||||||
FssNone,
|
|
||||||
// indicates that this "file" is actually a substring
|
|
||||||
// of another file that appears earlier in the codemap
|
|
||||||
FssInternal(Span),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Identifies an offset of a multi-byte character in a FileMap
|
/// Identifies an offset of a multi-byte character in a FileMap
|
||||||
pub struct MultiByteChar {
|
pub struct MultiByteChar {
|
||||||
/// The absolute offset of the character in the CodeMap
|
/// The absolute offset of the character in the CodeMap
|
||||||
|
@ -214,8 +205,6 @@ pub struct FileMap {
|
||||||
/// originate from files has names between angle brackets by convention,
|
/// originate from files has names between angle brackets by convention,
|
||||||
/// e.g. `<anon>`
|
/// e.g. `<anon>`
|
||||||
name: FileName,
|
name: FileName,
|
||||||
/// Extra information used by qquote
|
|
||||||
substr: FileSubstr,
|
|
||||||
/// The complete source code
|
/// The complete source code
|
||||||
src: @str,
|
src: @str,
|
||||||
/// The start position of this source in the CodeMap
|
/// The start position of this source in the CodeMap
|
||||||
|
@ -278,16 +267,7 @@ impl CodeMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a new FileMap to the CodeMap and return it
|
|
||||||
pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap {
|
pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap {
|
||||||
return self.new_filemap_w_substr(filename, FssNone, src);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_filemap_w_substr(&self,
|
|
||||||
filename: FileName,
|
|
||||||
substr: FileSubstr,
|
|
||||||
src: @str)
|
|
||||||
-> @FileMap {
|
|
||||||
let mut files = self.files.borrow_mut();
|
let mut files = self.files.borrow_mut();
|
||||||
let start_pos = if files.get().len() == 0 {
|
let start_pos = if files.get().len() == 0 {
|
||||||
0
|
0
|
||||||
|
@ -298,7 +278,8 @@ impl CodeMap {
|
||||||
};
|
};
|
||||||
|
|
||||||
let filemap = @FileMap {
|
let filemap = @FileMap {
|
||||||
name: filename, substr: substr, src: src,
|
name: filename,
|
||||||
|
src: src,
|
||||||
start_pos: Pos::from_uint(start_pos),
|
start_pos: Pos::from_uint(start_pos),
|
||||||
lines: RefCell::new(~[]),
|
lines: RefCell::new(~[]),
|
||||||
multibyte_chars: RefCell::new(~[]),
|
multibyte_chars: RefCell::new(~[]),
|
||||||
|
@ -322,31 +303,16 @@ impl CodeMap {
|
||||||
|
|
||||||
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
|
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
|
||||||
let loc = self.lookup_char_pos(pos);
|
let loc = self.lookup_char_pos(pos);
|
||||||
match (loc.file.substr) {
|
LocWithOpt {
|
||||||
FssNone =>
|
filename: loc.file.name,
|
||||||
LocWithOpt {
|
line: loc.line,
|
||||||
filename: loc.file.name,
|
col: loc.col,
|
||||||
line: loc.line,
|
file: Some(loc.file)
|
||||||
col: loc.col,
|
|
||||||
file: Some(loc.file)},
|
|
||||||
FssInternal(sp) =>
|
|
||||||
self.lookup_char_pos_adj(
|
|
||||||
sp.lo + (pos - loc.file.start_pos)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjust_span(&self, sp: Span) -> Span {
|
pub fn adjust_span(&self, sp: Span) -> Span {
|
||||||
let line = self.lookup_line(sp.lo);
|
sp
|
||||||
match (line.fm.substr) {
|
|
||||||
FssNone => sp,
|
|
||||||
FssInternal(s) => {
|
|
||||||
self.adjust_span(Span {
|
|
||||||
lo: s.lo + (sp.lo - line.fm.start_pos),
|
|
||||||
hi: s.lo + (sp.hi - line.fm.start_pos),
|
|
||||||
expn_info: sp.expn_info
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_to_str(&self, sp: Span) -> ~str {
|
pub fn span_to_str(&self, sp: Span) -> ~str {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{Span, CodeMap, FileMap, FileSubstr};
|
use codemap::{Span, CodeMap, FileMap};
|
||||||
use codemap;
|
use codemap;
|
||||||
use diagnostic::{SpanHandler, mk_span_handler, mk_handler, Emitter};
|
use diagnostic::{SpanHandler, mk_span_handler, mk_handler, Emitter};
|
||||||
use parse::attr::ParserAttr;
|
use parse::attr::ParserAttr;
|
||||||
|
@ -180,27 +180,6 @@ pub fn parse_tts_from_source_str(
|
||||||
maybe_aborted(p.parse_all_token_trees(),p)
|
maybe_aborted(p.parse_all_token_trees(),p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// given a function and parsing information (source str,
|
|
||||||
// filename, crate cfg, and sess), create a parser,
|
|
||||||
// apply the function, and check that the parser
|
|
||||||
// consumed all of the input before returning the function's
|
|
||||||
// result.
|
|
||||||
pub fn parse_from_source_str<T>(
|
|
||||||
f: |&mut Parser| -> T,
|
|
||||||
name: @str,
|
|
||||||
ss: codemap::FileSubstr,
|
|
||||||
source: @str,
|
|
||||||
cfg: ast::CrateConfig,
|
|
||||||
sess: @ParseSess)
|
|
||||||
-> T {
|
|
||||||
let mut p = new_parser_from_source_substr(sess, cfg, name, ss, source);
|
|
||||||
let r = f(&mut p);
|
|
||||||
if !p.reader.is_eof() {
|
|
||||||
p.reader.fatal(~"expected end-of-string");
|
|
||||||
}
|
|
||||||
maybe_aborted(r,p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new parser from a source string
|
// Create a new parser from a source string
|
||||||
pub fn new_parser_from_source_str(sess: @ParseSess,
|
pub fn new_parser_from_source_str(sess: @ParseSess,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
|
@ -210,17 +189,6 @@ pub fn new_parser_from_source_str(sess: @ParseSess,
|
||||||
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
|
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new parser from a source string where the origin
|
|
||||||
// is specified as a substring of another file.
|
|
||||||
pub fn new_parser_from_source_substr(sess: @ParseSess,
|
|
||||||
cfg: ast::CrateConfig,
|
|
||||||
name: @str,
|
|
||||||
ss: codemap::FileSubstr,
|
|
||||||
source: @str)
|
|
||||||
-> Parser {
|
|
||||||
filemap_to_parser(sess,substring_to_filemap(sess,source,name,ss),cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new parser, handling errors as appropriate
|
/// Create a new parser, handling errors as appropriate
|
||||||
/// if the file doesn't exist
|
/// if the file doesn't exist
|
||||||
pub fn new_parser_from_file(
|
pub fn new_parser_from_file(
|
||||||
|
@ -297,13 +265,6 @@ pub fn string_to_filemap(sess: @ParseSess, source: @str, path: @str)
|
||||||
sess.cm.new_filemap(path, source)
|
sess.cm.new_filemap(path, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
// given a session and a string and a path and a FileSubStr, add
|
|
||||||
// the string to the CodeMap and return the new FileMap
|
|
||||||
pub fn substring_to_filemap(sess: @ParseSess, source: @str, path: @str,
|
|
||||||
filesubstr: FileSubstr) -> @FileMap {
|
|
||||||
sess.cm.new_filemap_w_substr(path,filesubstr,source)
|
|
||||||
}
|
|
||||||
|
|
||||||
// given a filemap, produce a sequence of token-trees
|
// given a filemap, produce a sequence of token-trees
|
||||||
pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap)
|
pub fn filemap_to_tts(sess: @ParseSess, filemap: @FileMap)
|
||||||
-> ~[ast::TokenTree] {
|
-> ~[ast::TokenTree] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue