parser comments
parser comments
This commit is contained in:
parent
1b4ced8bcb
commit
fa5ba17c89
3 changed files with 20 additions and 6 deletions
|
@ -62,12 +62,14 @@ impl parser_attr for Parser {
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches attribute = # attribute_naked
|
||||||
fn parse_attribute(&self, style: ast::attr_style) -> ast::attribute {
|
fn parse_attribute(&self, style: ast::attr_style) -> ast::attribute {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(&token::POUND);
|
self.expect(&token::POUND);
|
||||||
return self.parse_attribute_naked(style, lo);
|
return self.parse_attribute_naked(style, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches attribute_naked = [ meta_item ]
|
||||||
fn parse_attribute_naked(&self, style: ast::attr_style, lo: BytePos) ->
|
fn parse_attribute_naked(&self, style: ast::attr_style, lo: BytePos) ->
|
||||||
ast::attribute {
|
ast::attribute {
|
||||||
self.expect(&token::LBRACKET);
|
self.expect(&token::LBRACKET);
|
||||||
|
@ -86,6 +88,7 @@ impl parser_attr for Parser {
|
||||||
// is an inner attribute of the containing item or an outer attribute of
|
// is an inner attribute of the containing item or an outer attribute of
|
||||||
// the first contained item until we see the semi).
|
// the first contained item until we see the semi).
|
||||||
|
|
||||||
|
// matches inner_attrs* outer_attr?
|
||||||
// you can make the 'next' field an Option, but the result is going to be
|
// you can make the 'next' field an Option, but the result is going to be
|
||||||
// more useful as a vector.
|
// more useful as a vector.
|
||||||
fn parse_inner_attrs_and_next(&self) ->
|
fn parse_inner_attrs_and_next(&self) ->
|
||||||
|
@ -134,6 +137,9 @@ impl parser_attr for Parser {
|
||||||
(inner_attrs, next_outer_attrs)
|
(inner_attrs, next_outer_attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches meta_item = IDENT
|
||||||
|
// | IDENT = lit
|
||||||
|
// | IDENT meta_seq
|
||||||
fn parse_meta_item(&self) -> @ast::meta_item {
|
fn parse_meta_item(&self) -> @ast::meta_item {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let name = self.id_to_str(self.parse_ident());
|
let name = self.id_to_str(self.parse_ident());
|
||||||
|
@ -156,6 +162,7 @@ impl parser_attr for Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches meta_seq = ( COMMASEP(meta_item) )
|
||||||
fn parse_meta_seq(&self) -> ~[@ast::meta_item] {
|
fn parse_meta_seq(&self) -> ~[@ast::meta_item] {
|
||||||
copy self.parse_seq(
|
copy self.parse_seq(
|
||||||
&token::LPAREN,
|
&token::LPAREN,
|
||||||
|
|
|
@ -870,6 +870,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches token_lit = LIT_INT | ...
|
||||||
fn lit_from_token(&self, tok: &token::Token) -> lit_ {
|
fn lit_from_token(&self, tok: &token::Token) -> lit_ {
|
||||||
match *tok {
|
match *tok {
|
||||||
token::LIT_INT(i, it) => lit_int(i, it),
|
token::LIT_INT(i, it) => lit_int(i, it),
|
||||||
|
@ -884,6 +885,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches lit = true | false | token_lit
|
||||||
fn parse_lit(&self) -> lit {
|
fn parse_lit(&self) -> lit {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let lit = if self.eat_keyword(&~"true") {
|
let lit = if self.eat_keyword(&~"true") {
|
||||||
|
@ -2762,8 +2764,6 @@ pub impl Parser {
|
||||||
// matches optbounds = ( ( : ( boundseq )? )? )
|
// matches optbounds = ( ( : ( boundseq )? )? )
|
||||||
// where boundseq = ( bound + boundseq ) | bound
|
// where boundseq = ( bound + boundseq ) | bound
|
||||||
// and bound = ( 'static ) | ty
|
// and bound = ( 'static ) | ty
|
||||||
// you might want to insist on the boundseq having seen the colon, but
|
|
||||||
// that's not currently in place.
|
|
||||||
fn parse_optional_ty_param_bounds(&self) -> @OptVec<TyParamBound> {
|
fn parse_optional_ty_param_bounds(&self) -> @OptVec<TyParamBound> {
|
||||||
if !self.eat(&token::COLON) {
|
if !self.eat(&token::COLON) {
|
||||||
return @opt_vec::Empty;
|
return @opt_vec::Empty;
|
||||||
|
@ -3085,6 +3085,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matches fn_header = IDENT generics
|
||||||
// parse the name and optional generic types of a function header.
|
// parse the name and optional generic types of a function header.
|
||||||
fn parse_fn_header(&self) -> (ident, ast::Generics) {
|
fn parse_fn_header(&self) -> (ident, ast::Generics) {
|
||||||
let id = self.parse_ident();
|
let id = self.parse_ident();
|
||||||
|
@ -3436,7 +3437,7 @@ pub impl Parser {
|
||||||
let attrs_remaining_len = attrs_remaining.len();
|
let attrs_remaining_len = attrs_remaining.len();
|
||||||
|
|
||||||
// looks like this code depends on the invariant that
|
// looks like this code depends on the invariant that
|
||||||
// outer attributes can't occur on view items (or macros
|
// outer attributes can't occur on view items (or macro
|
||||||
// invocations?)
|
// invocations?)
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
while *self.token != term {
|
while *self.token != term {
|
||||||
|
@ -3449,9 +3450,9 @@ pub impl Parser {
|
||||||
attrs);
|
attrs);
|
||||||
match self.parse_item_or_view_item(
|
match self.parse_item_or_view_item(
|
||||||
/*bad*/ copy attrs,
|
/*bad*/ copy attrs,
|
||||||
true,
|
true, // items allowed
|
||||||
false,
|
false, // foreign items allowed
|
||||||
true
|
true // macros allowed
|
||||||
) {
|
) {
|
||||||
iovi_item(item) => items.push(item),
|
iovi_item(item) => items.push(item),
|
||||||
iovi_view_item(view_item) => {
|
iovi_view_item(view_item) => {
|
||||||
|
@ -3706,6 +3707,7 @@ pub impl Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse extern mod foo { ... } or extern { ... }
|
||||||
fn parse_item_foreign_mod(&self,
|
fn parse_item_foreign_mod(&self,
|
||||||
lo: BytePos,
|
lo: BytePos,
|
||||||
opt_abis: Option<AbiSet>,
|
opt_abis: Option<AbiSet>,
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
/*! This module contains the Rust parser. It maps source text
|
||||||
|
* to token trees and to ASTs. It contains code for expanding
|
||||||
|
* macros.
|
||||||
|
*/
|
||||||
|
|
||||||
#[link(name = "syntax",
|
#[link(name = "syntax",
|
||||||
vers = "0.7-pre",
|
vers = "0.7-pre",
|
||||||
uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")];
|
uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")];
|
||||||
|
|
Loading…
Reference in a new issue