diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 08:07:56 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 08:07:56 +0000 |
commit | aff82e5ee1d587b858e7237511e611bb8cc61cf3 (patch) | |
tree | 83d1a4bbaa4be96f76c2d48c00ad479173f61274 /src/tree | |
parent | efadcf715862a2d96af0f57d2b53bfa325390779 (diff) | |
parent | 4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66 (diff) |
Merge #16
16: Proof-of-concept SyntaxKind as enum r=matklad a=CAD97
This was the one bit about the original RFC I was most confused about. Why isn't `SyntaxKind` a normal `enum`?
If it's to signify that it's non-exhaustive [`#[non_exhaustive]`](https://github.com/rust-lang/rust/issues/44109) should be used. (Or `#[doc(hidden)] __Nonexhaustive` on stable.)
If it's so that more variants can be added externally, why? There's no need for that, that I can foresee.
If it's to expose the `SyntaxKind` type but not any of its instances, why? This is the only actual benefit I can see of this pseudo-enum style.
This diff is meant to be as non-invasive as possible, and as such reexports all symbols as they existed prior to this. It's diffed on top of the assumed-good-to-merge #15 to avoid the conflict between them.
Diff without #15: <https://github.com/matklad/libsyntax2/pull/16/commits/4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66>
Just `src/syntax_kinds.rs`: <https://github.com/matklad/libsyntax2/pull/16/commits/4244948c6b1a62bd0e1ef276d1f0cc22c36f6f66#diff-8f0d69eb4fe0148851505f787b6fd3bb>
Diffstat (limited to 'src/tree')
-rw-r--r-- | src/tree/mod.rs | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/src/tree/mod.rs b/src/tree/mod.rs index aaf048c73..43bda480d 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use text::{TextRange, TextUnit}; | 1 | use text::{TextRange, TextUnit}; |
2 | use syntax_kinds::syntax_info; | ||
3 | 2 | ||
4 | use std::fmt; | 3 | use std::fmt; |
5 | use std::cmp; | 4 | use std::cmp; |
@@ -7,25 +6,7 @@ use std::cmp; | |||
7 | mod file_builder; | 6 | mod file_builder; |
8 | pub use self::file_builder::{FileBuilder, Sink}; | 7 | pub use self::file_builder::{FileBuilder, Sink}; |
9 | 8 | ||
10 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | 9 | pub use syntax_kinds::SyntaxKind; |
11 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
12 | pub struct SyntaxKind(pub(crate) u32); | ||
13 | |||
14 | pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); | ||
15 | pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" }; | ||
16 | |||
17 | pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); | ||
18 | pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { name: "TOMBSTONE" }; | ||
19 | |||
20 | impl SyntaxKind { | ||
21 | fn info(self) -> &'static SyntaxInfo { | ||
22 | match self { | ||
23 | EOF => &EOF_INFO, | ||
24 | TOMBSTONE => &TOMBSTONE_INFO, | ||
25 | _ => syntax_info(self), | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | 10 | ||
30 | impl fmt::Debug for SyntaxKind { | 11 | impl fmt::Debug for SyntaxKind { |
31 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 12 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |