diff options
| author | Benjamin Herr <ben@0x539.de> | 2013-10-08 02:49:10 +0200 |
|---|---|---|
| committer | Benjamin Herr <ben@0x539.de> | 2013-10-08 03:43:28 +0200 |
| commit | 9d7b13004192b8eef1f68501035d05c85dee8c47 (patch) | |
| tree | c96d00a2f583c825b91836764219440f5b9cb7b6 /src/libsyntax/parse/parser.rs | |
| parent | 97878725532c4d1dd1af07e88175462178d78cdb (diff) | |
| download | rust-9d7b13004192b8eef1f68501035d05c85dee8c47.tar.gz rust-9d7b13004192b8eef1f68501035d05c85dee8c47.zip | |
add new enum ast::StrStyle as field to ast::lit_str
For the benefit of the pretty printer we want to keep track of how string literals in the ast were originally represented in the source code. This commit changes parser functions so they don't extract strings from the token stream without at least also returning what style of string literal it was. This is stored in the resulting ast node for string literals, obviously, for the package id in `extern mod = r"package id"` view items, for the inline asm in `asm!()` invocations. For `asm!()`'s other arguments or for `extern "Rust" fn()` items, I just the style of string, because it seemed disproportionally cumbersome to thread that information through the string processing that happens with those string literals, given the limited advantage raw string literals would provide in these positions. The other syntax extensions don't seem to store passed string literals in the ast, so they also discard the style of strings they parse.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c8689db417c..ffebe7980bf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -48,6 +48,7 @@ use ast::{BiRem, required}; use ast::{ret_style, return_val, BiShl, BiShr, Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, struct_def, struct_field}; use ast::{struct_variant_kind, BiSub}; +use ast::StrStyle; use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; @@ -1282,8 +1283,8 @@ impl Parser { token::LIT_FLOAT(s, ft) => lit_float(self.id_to_str(s), ft), token::LIT_FLOAT_UNSUFFIXED(s) => lit_float_unsuffixed(self.id_to_str(s)), - token::LIT_STR(s) => lit_str(self.id_to_str(s)), - token::LIT_STR_RAW(s, _) => lit_str(self.id_to_str(s)), + token::LIT_STR(s) => lit_str(self.id_to_str(s), ast::CookedStr), + token::LIT_STR_RAW(s, n) => lit_str(self.id_to_str(s), ast::RawStr(n)), token::LPAREN => { self.expect(&token::RPAREN); lit_nil }, _ => { self.unexpected_last(tok); } } @@ -2158,7 +2159,7 @@ impl Parser { // HACK: turn &[...] into a &-evec ex = match e.node { ExprVec(*) | ExprLit(@codemap::Spanned { - node: lit_str(_), span: _ + node: lit_str(*), span: _ }) if m == MutImmutable => { ExprVstore(e, ExprVstoreSlice) @@ -2182,7 +2183,7 @@ impl Parser { ExprVec(*) | ExprRepeat(*) if m == MutMutable => ExprVstore(e, ExprVstoreMutBox), ExprVec(*) | - ExprLit(@codemap::Spanned { node: lit_str(_), span: _}) | + ExprLit(@codemap::Spanned { node: lit_str(*), span: _}) | ExprRepeat(*) if m == MutImmutable => ExprVstore(e, ExprVstoreBox), _ => self.mk_unary(UnBox(m), e) }; @@ -2195,7 +2196,7 @@ impl Parser { // HACK: turn ~[...] into a ~-evec ex = match e.node { ExprVec(*) | - ExprLit(@codemap::Spanned { node: lit_str(_), span: _}) | + ExprLit(@codemap::Spanned { node: lit_str(*), span: _}) | ExprRepeat(*) => ExprVstore(e, ExprVstoreUniq), _ => self.mk_unary(UnUniq, e) }; @@ -2707,7 +2708,7 @@ impl Parser { pat = match sub.node { PatLit(e@@Expr { node: ExprLit(@codemap::Spanned { - node: lit_str(_), + node: lit_str(*), span: _}), _ }) => { let vst = @Expr { @@ -2735,7 +2736,7 @@ impl Parser { pat = match sub.node { PatLit(e@@Expr { node: ExprLit(@codemap::Spanned { - node: lit_str(_), + node: lit_str(*), span: _}), _ }) => { let vst = @Expr { @@ -2764,7 +2765,7 @@ impl Parser { pat = match sub.node { PatLit(e@@Expr { node: ExprLit(@codemap::Spanned { - node: lit_str(_), span: _}), _ + node: lit_str(*), span: _}), _ }) => { let vst = @Expr { id: ast::DUMMY_NODE_ID, @@ -4373,15 +4374,15 @@ impl Parser { abi::all_names().connect(", "), word)); } - } - } + } + } Some(abis) } _ => { None - } - } + } + } } // parse one of the items or view items allowed by the @@ -4932,18 +4933,17 @@ impl Parser { } } - pub fn parse_optional_str(&self) -> Option<@str> { - match *self.token { - token::LIT_STR(s) - | token::LIT_STR_RAW(s, _) => { - self.bump(); - Some(ident_to_str(&s)) - } - _ => None - } + pub fn parse_optional_str(&self) -> Option<(@str, ast::StrStyle)> { + let (s, style) = match *self.token { + token::LIT_STR(s) => (s, ast::CookedStr), + token::LIT_STR_RAW(s, n) => (s, ast::RawStr(n)), + _ => return None + }; + self.bump(); + Some((ident_to_str(&s), style)) } - pub fn parse_str(&self) -> @str { + pub fn parse_str(&self) -> (@str, StrStyle) { match self.parse_optional_str() { Some(s) => { s } _ => self.fatal("expected string literal") |
