Rust 1.7.0 语法基础 标识符(ident)和分隔符的约束

来源:互联网 发布:杨闻萍审计 知乎 编辑:程序博客网 时间:2024/06/18 03:53

一、标识符

identifier 是标识符,在Rust语法中简写为 ident
ident 是由任意个非空的unicode字符组成。

举例:

在 attribute 语法中,有

meta_item : ident [ '=' literal  | '(' meta_seq ')' ] ? ;

实际使用如下:

#![crate_type = "lib"]#![allow(dead_code)]#![feature(intrinsics, lang_items)]#[test]

上面的 crate_type、allow、feature和test 都是 ident 。

更多参看 Rust 1.7.0 语法基础 attribute

二、分隔符约束

Rust语法中规定了哪些字符不能作为分隔符,而不是规定了哪些字符可以作为分隔符。

约束规则如下:

non_null 表示任意单个unicode字符,但排除 U+0000 (即排除null)
non_eol 表示的是受限的 non_null,排除回车符 U+000A (‘\n’)
non_single_quote 表示的是受限的 non_null 排除单引号 U+0027 (‘)
non_double_quote 表示受限的 non_null 排除了双引号 U+0022 (“)

0 0