Skip to content

Commit 72e50d8

Browse files
committed
reference type
1 parent f884c6b commit 72e50d8

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

src/lexer.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use chumsky::{
1212

1313
type Spanned = (TagType, Range<usize>);
1414

15+
const C: [char; 3] = ['.', '_', '-'];
16+
1517
#[derive(Debug)]
1618
pub struct Lexer;
1719

@@ -267,6 +269,11 @@ impl Lexer {
267269
.delimited_by(just('{').then(whitespace()), whitespace().then(just('}')))
268270
.map(Ty::Dict);
269271

272+
let ty_name = filter(|x: &char| x.is_alphanumeric() || C.contains(x))
273+
.repeated()
274+
.collect()
275+
.map(Ty::Ref);
276+
270277
choice((
271278
union_array(any, inner.clone()),
272279
union_array(unknown, inner.clone()),
@@ -281,7 +288,8 @@ impl Lexer {
281288
union_array(lightuserdata, inner.clone()),
282289
union_array(fun, inner.clone()),
283290
union_array(table, inner.clone()),
284-
union_array(dict, inner),
291+
union_array(dict, inner.clone()),
292+
union_array(ty_name, inner),
285293
))
286294
})
287295
}

src/lexer/token.rs

+47-1
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,56 @@ pub enum Ty {
163163
Table(Option<(Box<Ty>, Box<Ty>)>),
164164
Fun(Vec<(String, Ty)>, Option<Box<Ty>>),
165165
Dict(Vec<(String, Ty)>),
166+
Ref(String),
166167
}
167168

168169
impl Display for Ty {
169170
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
170-
f.write_str("ty-ty")
171+
match self {
172+
Self::Nil => f.write_str("nil"),
173+
Self::Any => f.write_str("any"),
174+
Self::Unknown => f.write_str("unknown"),
175+
Self::Boolean => f.write_str("boolean"),
176+
Self::String => f.write_str("string"),
177+
Self::Number => f.write_str("number"),
178+
Self::Integer => f.write_str("integer"),
179+
Self::Function => f.write_str("function"),
180+
Self::Thread => f.write_str("thread"),
181+
Self::Userdata => f.write_str("userdata"),
182+
Self::Lightuserdata => f.write_str("lightuserdata"),
183+
Self::Union(rhs, lhs) => write!(f, "{rhs}|{lhs}"),
184+
Self::Array(ty) => write!(f, "{ty}[]"),
185+
Self::Table(spec) => match spec {
186+
Some((k, v)) => write!(f, "table<{k}, {v}>"),
187+
None => f.write_str("table"),
188+
},
189+
Self::Fun(args, ret) => {
190+
write!(
191+
f,
192+
"fun({})",
193+
args.iter()
194+
.map(|(arg, ty)| format!("{arg}: {ty}"))
195+
.collect::<Vec<String>>()
196+
.join(",")
197+
)?;
198+
if let Some(ret) = ret {
199+
write!(f, ": {}", ret)?;
200+
}
201+
Ok(())
202+
}
203+
Self::Dict(kv) => {
204+
f.write_str("{ ")?;
205+
write!(
206+
f,
207+
"{}",
208+
kv.iter()
209+
.map(|(arg, ty)| format!("{arg}: {ty}"))
210+
.collect::<Vec<String>>()
211+
.join(",")
212+
)?;
213+
f.write_str(" }")
214+
}
215+
Self::Ref(id) => f.write_str(id),
216+
}
171217
}
172218
}

src/vimdoc/alias.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl Display for AliasDoc<'_> {
3131
match &kind {
3232
AliasKind::Type(ty) => {
3333
description!(f, "Type: ~")?;
34-
writeln!(f, "{:>w$}", ty, w = 8 + ty.to_string().len())?;
34+
let ty = ty.to_string();
35+
writeln!(f, "{:>w$}", ty, w = 8 + ty.len())?;
3536
}
3637
AliasKind::Enum(variants) => {
3738
description!(f, "Variants: ~")?;

tests/basic.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ CommentConfig *CommentConfig*
161161
Plugin's configuration
162162
163163
Fields: ~
164-
{padding} (boolean) Add a space b/w comment and the line
165-
{sticky} (boolean) Whether the cursor should stay at its position
166-
NOTE: This only affects NORMAL mode mappings and doesn't work with dot-repeat
164+
{padding} (boolean) Add a space b/w comment and the line
165+
{sticky} (boolean) Whether the cursor should stay at its position
166+
NOTE: This only affects NORMAL mode mappings and doesn't work with dot-repeat
167167
168-
{ignore} (string|fun():string) Lines to be ignored while comment/uncomment.
169-
Could be a regex string or a function that returns a regex string.
170-
Example: Use '^$' to ignore empty lines
168+
{ignore} (string|fun(): string) Lines to be ignored while comment/uncomment.
169+
Could be a regex string or a function that returns a regex string.
170+
Example: Use '^$' to ignore empty lines
171171
172-
{pre_hook} (fun(ctx:CommentCtx):string) Function to be called before comment/uncomment
173-
{post_hook} (fun(ctx:CommentCtx)) Function to be called after comment/uncomment
172+
{pre_hook} (fun(ctx: CommentCtx): string) Function to be called before comment/uncomment
173+
{post_hook} (fun(ctx: CommentCtx)) Function to be called after comment/uncomment
174174
175175
176176
"

0 commit comments

Comments
 (0)