Skip to content

Commit b52022b

Browse files
committed
remove proc-macro dependencies
1 parent 12ba1d9 commit b52022b

27 files changed

+121
-149
lines changed

.github/workflows/antlr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
repository: rrevenantt/antlr4
1919
ref: rust-target
2020
submodules: true
21-
- run: git fetch origin $GITHUB_REF
21+
- run: |
22+
git fetch origin $GITHUB_REF
23+
git checkout FETCH_HEAD
2224
working-directory: runtime/Rust
2325
- name: Set up JDK 1.8
2426
uses: actions/setup-java@v1

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ bit-set = "=0.5.*"
2323
once_cell = "^1.2"
2424
#backtrace = "=0.3"
2525
typed-arena = "^2.0"
26-
better_any = "=0.1"
26+
better_any = "0.2.0-dev.1"
27+
#better_any = "=0.1"
2728
parking_lot = "0.11"
2829
#qcell = { path="../qcell" }
2930

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,6 @@ Since version `0.3` works on stable rust.
3131
Previous versions are not maintained any more
3232
so in case of nightly breakage you should migrate to the latest version.
3333

34-
###### Long term improvements
35-
36-
things to consider for next versions:
37-
- [ ] attempt a workaround to use stable rust
38-
- [ ] remove proc macro dependency
39-
- [ ] move to once_cell completely
40-
- [ ] rustfmt in antlr tool
41-
- [ ] make `Node` and associated type in visitors
42-
- [ ] bulk import for context extension traits
43-
- [ ] intradoc links
44-
- [ ] move benches to repository
45-
- [ ] LexerAtnSimulator position tracking customization
46-
- [ ] Lexer position tracking customization
47-
- [ ] thread local DFA(questionable because of quite slow threadlocals in rust)
48-
- [ ] arena allocation for tree nodes
49-
- [ ] tree utils
50-
- [ ] features
51-
- [ ] stateful lexer test
52-
- [ ] better downcasting
53-
- [ ] options for customizing downcast bounds
54-
- [ ] token stream rewriter
55-
- [ ] doctests + dummy parser for them
56-
- [ ] actual examples
57-
- [ ] normal visitor example/docs
58-
- [ ] string interner test/example
59-
- [ ] figure out base class api replacement
60-
- [ ] rustfmt import config
61-
- [ ] draft upstream PR
62-
- [ ] add recursion limit
63-
- [ ] test custom errors
64-
- [ ] add fuzzer tests
65-
6634
### Usage
6735

6836
You should use the ANTLR4 "tool" to generate a parser, that will use the ANTLR

src/common_token_stream.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use crate::token_stream::{TokenStream, UnbufferedTokenStream};
99
use better_any::{Tid, TidAble};
1010

1111
/// Default token stream that skips token that not correspond to current channel.
12-
#[derive(Tid, Debug)]
12+
#[derive(Debug)]
1313
pub struct CommonTokenStream<'input, T: TokenSource<'input>> {
1414
base: UnbufferedTokenStream<'input, T>,
1515
channel: isize,
1616
}
1717

18+
better_any::tid! { impl<'input,T> TidAble<'input> for CommonTokenStream<'input, T> where T: TokenSource<'input>}
19+
1820
impl<'input, T: TokenSource<'input>> IntStream for CommonTokenStream<'input, T> {
1921
#[inline]
2022
fn consume(&mut self) {

src/error_strategy.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::token_factory::TokenFactory;
2020
use crate::transition::RuleTransition;
2121
use crate::tree::Tree;
2222
use crate::utils::escape_whitespaces;
23-
use better_any::{impl_tid, Tid, TidAble};
23+
use better_any::{Tid, TidAble};
2424

2525
/// The interface for defining strategies to deal with syntax errors encountered
2626
/// during a parse by ANTLR-generated parsers. We distinguish between three
@@ -94,8 +94,8 @@ pub trait ErrorStrategy<'a, T: Parser<'a>>: Tid<'a> {
9494
// /// Supports downcasting.
9595
// pub type DynHandler<'a, T> = Box<dyn ErrorStrategy<'a, T> + 'a>;
9696

97-
#[impl_tid]
98-
impl<'a, T: Parser<'a> + TidAble<'a>> TidAble<'a> for Box<dyn ErrorStrategy<'a, T> + 'a> {}
97+
// impl<'a, T: Parser<'a> + TidAble<'a>> TidAble<'a> for Box<dyn ErrorStrategy<'a, T> + 'a> {}
98+
better_any::tid! { impl<'a, T> TidAble<'a> for Box<dyn ErrorStrategy<'a, T> + 'a> where T: Parser<'a>}
9999

100100
impl<'a, T: Parser<'a> + TidAble<'a>> ErrorStrategy<'a, T> for Box<dyn ErrorStrategy<'a, T> + 'a> {
101101
#[inline(always)]
@@ -135,7 +135,7 @@ impl<'a, T: Parser<'a> + TidAble<'a>> ErrorStrategy<'a, T> for Box<dyn ErrorStra
135135

136136
/// This is the default implementation of `ErrorStrategy` used for
137137
/// error reporting and recovery in ANTLR parsers.
138-
#[derive(Debug, Tid)]
138+
#[derive(Debug)]
139139
pub struct DefaultErrorStrategy<'input, Ctx: ParserNodeType<'input>> {
140140
error_recovery_mode: bool,
141141
last_error_index: isize,
@@ -144,6 +144,8 @@ pub struct DefaultErrorStrategy<'input, Ctx: ParserNodeType<'input>> {
144144
next_tokens_ctx: Option<Rc<Ctx::Type>>,
145145
}
146146

147+
better_any::tid! { impl<'i,Ctx> TidAble<'i> for DefaultErrorStrategy<'i,Ctx> where Ctx: ParserNodeType<'i>}
148+
147149
impl<'input, Ctx: ParserNodeType<'input>> Default for DefaultErrorStrategy<'input, Ctx> {
148150
fn default() -> Self { Self::new() }
149151
}
@@ -545,11 +547,13 @@ impl<'a, T: Parser<'a>> ErrorStrategy<'a, T> for DefaultErrorStrategy<'a, T::Nod
545547
///
546548
/// [`ParserRuleContext.exception`]: todo
547549
/// */
548-
#[derive(Default, Debug, Tid)]
550+
#[derive(Default, Debug)]
549551
pub struct BailErrorStrategy<'input, Ctx: ParserNodeType<'input>>(
550552
DefaultErrorStrategy<'input, Ctx>,
551553
);
552554

555+
better_any::tid! {impl<'i,Ctx> TidAble<'i> for BailErrorStrategy<'i,Ctx> where Ctx:ParserNodeType<'i> }
556+
553557
impl<'input, Ctx: ParserNodeType<'input>> BailErrorStrategy<'input, Ctx> {
554558
/// Creates new instance of `BailErrorStrategy`
555559
pub fn new() -> Self { Self(DefaultErrorStrategy::new()) }

src/input_stream.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::char_stream::{CharStream, InputData};
55
use crate::int_stream::IntStream;
66
use std::ops::Deref;
77

8-
use better_any::{impl_tid, TidAble};
8+
use better_any::TidAble;
99

1010
/// Default rust target input stream.
1111
///
@@ -21,11 +21,12 @@ pub struct InputStream<Data: Deref> {
2121
index: isize,
2222
}
2323

24-
#[impl_tid]
25-
impl<'a, T: ?Sized + 'static> TidAble<'a> for InputStream<&'a T> {}
26-
27-
#[impl_tid]
28-
impl<'a, T: ?Sized + 'static> TidAble<'a> for InputStream<Box<T>> {}
24+
// #[impl_tid]
25+
// impl<'a, T: ?Sized + 'static> TidAble<'a> for InputStream<Box<T>> {}
26+
// #[impl_tid]
27+
// impl<'a, T: ?Sized + 'static> TidAble<'a> for InputStream<&'a T> {}
28+
better_any::tid! {impl<'a, T: 'static> TidAble<'a> for InputStream<&'a T> where T: ?Sized}
29+
better_any::tid! {impl<'a, T: 'static> TidAble<'a> for InputStream<Box<T>> where T: ?Sized}
2930

3031
impl<'a, T: From<&'a str>> CharStream<T> for InputStream<&'a str> {
3132
#[inline]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub use lazy_static::lazy_static;
9494
pub use parking_lot::RwLock;
9595

9696
#[doc(hidden)]
97-
pub use better_any::{impl_tid, type_id, Tid, TidAble, TidExt};
97+
pub use better_any::{tid, Tid, TidAble, TidExt};
9898

9999
#[doc(inline)]
100100
pub use error_strategy::{BailErrorStrategy, DefaultErrorStrategy, ErrorStrategy};

src/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub trait ParserNodeType<'input>: TidAble<'input> + Sized {
105105
/// It is a member of generated parser struct, so
106106
/// almost always you don't need to create it yourself.
107107
/// Generated parser hides complexity of this struct and expose required flexibility via generic parameters
108-
#[derive(Tid)]
109108
pub struct BaseParser<
110109
'input,
111110
Ext: 'static, //: ParserRecog<'input, Self> + 'static, // user provided behavior, such as semantic predicates
@@ -151,6 +150,13 @@ pub struct BaseParser<
151150
pd: PhantomData<fn() -> &'input str>,
152151
}
153152

153+
better_any::tid! {
154+
impl<'input, Ext:'static, I, Ctx, T> TidAble<'input> for BaseParser<'input,Ext, I, Ctx, T>
155+
where I: TokenStream<'input>,
156+
Ctx: ParserNodeType<'input, TF = I::TF>,
157+
T: ParseTreeListener<'input, Ctx> + ?Sized
158+
}
159+
154160
impl<'input, Ext, I, Ctx, T> Deref for BaseParser<'input, Ext, I, Ctx, T>
155161
where
156162
Ext: ParserRecog<'input, Self> + 'static,

src/parser_rule_context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ pub fn cast_mut<'a, T: ParserRuleContext<'a> + 'a + ?Sized, Result: 'a>(
233233
// pub type ParserRuleContextType<'input,T> = ParseTreeNode<'input,T>;
234234

235235
/// Default rule context implementation that keeps everything provided by parser
236-
#[derive(Tid)]
237236
pub struct BaseParserRuleContext<'input, Ctx: CustomRuleContext<'input>> {
238237
base: BaseRuleContext<'input, Ctx>,
239238

@@ -245,6 +244,8 @@ pub struct BaseParserRuleContext<'input, Ctx: CustomRuleContext<'input>> {
245244
pub(crate) children: RefCell<Vec<Rc<<Ctx::Ctx as ParserNodeType<'input>>::Type>>>,
246245
}
247246

247+
better_any::tid! { impl<'i,Ctx> TidAble<'i> for BaseParserRuleContext<'i,Ctx> where Ctx:CustomRuleContext<'i> }
248+
248249
impl<'input, Ctx: CustomRuleContext<'input>> Debug for BaseParserRuleContext<'input, Ctx> {
249250
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { f.write_str(type_name::<Self>()) }
250251
}

src/rule_context.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ where
5959
// Self: Sized;
6060
// }
6161

62-
#[derive(Tid, Debug)]
62+
#[derive(Debug)]
6363
#[doc(hidden)]
6464
pub struct EmptyCustomRuleContext<'a, TF: TokenFactory<'a> + 'a>(
6565
pub(crate) PhantomData<&'a TF::Tok>,
6666
);
6767

68+
better_any::tid! { impl <'a,TF> TidAble<'a> for EmptyCustomRuleContext<'a,TF> where TF:TokenFactory<'a> + 'a}
69+
6870
impl<'a, TF: TokenFactory<'a> + 'a> CustomRuleContext<'a> for EmptyCustomRuleContext<'a, TF> {
6971
type TF = TF;
7072
type Ctx = EmptyContextType<'a, TF>;
@@ -88,10 +90,12 @@ impl<'a, TF: TokenFactory<'a> + 'a> CustomRuleContext<'a> for EmptyCustomRuleCon
8890
pub type EmptyContext<'a, TF> =
8991
dyn ParserRuleContext<'a, TF = TF, Ctx = EmptyContextType<'a, TF>> + 'a;
9092

91-
#[derive(Tid, Debug)]
93+
#[derive(Debug)]
9294
#[doc(hidden)] // public for implementation reasons
9395
pub struct EmptyContextType<'a, TF: TokenFactory<'a>>(pub PhantomData<&'a TF>);
9496

97+
better_any::tid! { impl <'a,TF> TidAble<'a> for EmptyContextType<'a,TF> where TF:TokenFactory<'a> }
98+
9599
impl<'a, TF: TokenFactory<'a>> ParserNodeType<'a> for EmptyContextType<'a, TF> {
96100
type TF = TF;
97101
type Type = dyn ParserRuleContext<'a, TF = Self::TF, Ctx = Self> + 'a;
@@ -127,13 +131,14 @@ pub trait CustomRuleContext<'input> {
127131
}
128132

129133
/// Minimal parse tree node implementation, that stores only data required for correct parsing
130-
#[derive(Tid)]
131134
pub struct BaseRuleContext<'input, ExtCtx: CustomRuleContext<'input>> {
132135
pub(crate) parent_ctx: RefCell<Option<Weak<<ExtCtx::Ctx as ParserNodeType<'input>>::Type>>>,
133136
invoking_state: Cell<isize>,
134137
pub(crate) ext: ExtCtx,
135138
}
136139

140+
better_any::tid! { impl <'input,Ctx> TidAble<'input> for BaseRuleContext<'input,Ctx> where Ctx:CustomRuleContext<'input>}
141+
137142
#[allow(missing_docs)]
138143
impl<'input, ExtCtx: CustomRuleContext<'input>> BaseRuleContext<'input, ExtCtx> {
139144
pub fn new_parser_ctx(

src/token_factory.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ pub trait TokenFactory<'a>: TidAble<'a> + Sized {
8080
}
8181

8282
/// Default token factory
83-
#[derive(Default, Tid, Debug)]
83+
#[derive(Default, Debug)]
8484
pub struct CommonTokenFactory;
8585

86+
better_any::tid! {CommonTokenFactory}
87+
8688
impl Default for &'_ CommonTokenFactory {
8789
fn default() -> Self { &**COMMON_TOKEN_FACTORY_DEFAULT }
8890
}
@@ -139,9 +141,11 @@ impl<'a> TokenFactory<'a> for CommonTokenFactory {
139141

140142
/// Token factory that produces heap allocated
141143
/// `OwningToken`s
142-
#[derive(Default, Tid, Debug)]
144+
#[derive(Default, Debug)]
143145
pub struct OwningTokenFactory;
144146

147+
better_any::tid! {OwningTokenFactory}
148+
145149
impl<'a> TokenFactory<'a> for OwningTokenFactory {
146150
type Inner = OwningToken;
147151
type Tok = Box<Self::Inner>;
@@ -220,13 +224,14 @@ pub type ArenaCommonFactory<'a> = ArenaFactory<'a, CommonTokenFactory, CommonTok
220224
/// const INVALID_TOKEN:CustomToken = ...
221225
/// ```
222226
// Box is used here because it is almost always should be used for token factory
223-
#[derive(Tid)]
224227
pub struct ArenaFactory<'input, TF, T> {
225228
arena: Arena<T>,
226229
factory: TF,
227230
pd: PhantomData<&'input str>,
228231
}
229232

233+
better_any::tid! {impl<'input,TF,T> TidAble<'input> for ArenaFactory<'input,TF,T>}
234+
230235
impl<'input, TF: Debug, T> Debug for ArenaFactory<'input, TF, T> {
231236
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
232237
f.debug_struct("ArenaFactory")

src/token_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ impl<'a, 'input: 'a, T: TokenStream<'input>> Iterator for TokenIter<'a, 'input,
6868
}
6969

7070
/// Token stream that keeps all data in internal Vec
71-
#[derive(Tid)]
7271
pub struct UnbufferedTokenStream<'input, T: TokenSource<'input>> {
7372
token_source: T,
7473
pub(crate) tokens: Vec<<T::TF as TokenFactory<'input>>::Tok>,
@@ -77,6 +76,8 @@ pub struct UnbufferedTokenStream<'input, T: TokenSource<'input>> {
7776
markers_count: isize,
7877
pub(crate) p: isize,
7978
}
79+
better_any::tid! { impl<'input,T> TidAble<'input> for UnbufferedTokenStream<'input, T> where T: TokenSource<'input>}
80+
8081
impl<'input, T: TokenSource<'input>> Debug for UnbufferedTokenStream<'input, T> {
8182
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
8283
f.debug_struct("UnbufferedTokenStream")

src/tree.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ pub trait ParseTree<'input>: Tree<'input> {
104104
// }
105105

106106
#[doc(hidden)]
107-
#[derive(Tid, Debug)]
107+
#[derive(Debug)]
108108
pub struct NoError;
109109

110110
#[doc(hidden)]
111-
#[derive(Tid, Debug)]
111+
#[derive(Debug)]
112112
pub struct IsError;
113113

114114
/// Generic leaf AST node
115-
#[derive(Tid)]
116115
pub struct LeafNode<'input, Node: ParserNodeType<'input>, T: 'static> {
117116
/// Token, this leaf consist of
118117
pub symbol: <Node::TF as TokenFactory<'input>>::Tok,
119118
iserror: PhantomData<T>,
120119
}
120+
better_any::tid! { impl <'input, Node, T:'static> TidAble<'input> for LeafNode<'input, Node, T> where Node:ParserNodeType<'input> }
121121

122122
impl<'input, Node: ParserNodeType<'input>, T: 'static> CustomRuleContext<'input>
123123
for LeafNode<'input, Node, T>
@@ -132,8 +132,8 @@ impl<'input, Node: ParserNodeType<'input>, T: 'static> CustomRuleContext<'input>
132132
}
133133
}
134134

135-
impl<'input, Node: ParserNodeType<'input> + TidAble<'input>, T: 'static + TidAble<'input>>
136-
ParserRuleContext<'input> for LeafNode<'input, Node, T>
135+
impl<'input, Node: ParserNodeType<'input>, T: 'static> ParserRuleContext<'input>
136+
for LeafNode<'input, Node, T>
137137
{
138138
}
139139

0 commit comments

Comments
 (0)