diff --git a/Cargo.lock b/Cargo.lock index 13b598f6..04950840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -789,34 +789,25 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "logos" -version = "0.13.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" +checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" dependencies = [ "logos-derive", ] [[package]] -name = "logos-codegen" -version = "0.13.0" +name = "logos-derive" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" +checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c" dependencies = [ "beef", "fnv", "proc-macro2", "quote", "regex-syntax", - "syn 2.0.38", -] - -[[package]] -name = "logos-derive" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e" -dependencies = [ - "logos-codegen", + "syn 1.0.109", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d68dbf0b..32b68b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ quote = "1.0" syn = "2.0" peg = "0.8.2" drop_bomb = "0.1.5" -logos = "0.13.0" +logos = "0.12.0" miette = "5.5.0" rowan = "0.15" text-size = "1.1" diff --git a/cmds/jrsonnet-fmt/src/children.rs b/cmds/jrsonnet-fmt/src/children.rs index 9fa498e9..ed2936da 100644 --- a/cmds/jrsonnet-fmt/src/children.rs +++ b/cmds/jrsonnet-fmt/src/children.rs @@ -60,6 +60,7 @@ pub fn trivia_after(node: SyntaxNode, start: Option<&SyntaxElement>) -> ChildTri out } +#[allow(dead_code)] pub fn trivia_between( node: SyntaxNode, start: Option<&SyntaxElement>, diff --git a/cmds/jrsonnet-fmt/src/main.rs b/cmds/jrsonnet-fmt/src/main.rs index cfadb1c5..1fbfe237 100644 --- a/cmds/jrsonnet-fmt/src/main.rs +++ b/cmds/jrsonnet-fmt/src/main.rs @@ -20,7 +20,7 @@ use jrsonnet_rowan_parser::{ }; use crate::{ - children::{trivia_after, trivia_between}, + children::trivia_after, comments::{format_comments, CommentLocation}, }; @@ -445,7 +445,7 @@ impl Printable for CompSpec { impl Printable for Expr { fn print(&self) -> PrintItems { let mut o = p!(new:); - let (stmts, ending) = children_between::( + let (stmts, _ending) = children_between::( self.syntax().clone(), None, self.expr_base() @@ -460,7 +460,7 @@ impl Printable for Expr { p!(o: {stmt.value}); } p!(o: {self.expr_base()}); - let (suffixes, ending) = children_between::( + let (suffixes, _ending) = children_between::( self.syntax().clone(), self.expr_base() .as_ref() diff --git a/crates/jrsonnet-parser/src/source.rs b/crates/jrsonnet-parser/src/source.rs index bf1f2404..ae36242d 100644 --- a/crates/jrsonnet-parser/src/source.rs +++ b/crates/jrsonnet-parser/src/source.rs @@ -83,6 +83,7 @@ any_ext!(SourcePathT); /// /// Resolver may also return custom implementations of this trait, for example it may return http url in case of remotely loaded files #[derive(Eq, Debug, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SourcePath(Rc); impl SourcePath { pub fn new(inner: impl SourcePathT) -> Self { diff --git a/crates/jrsonnet-rowan-parser/src/event.rs b/crates/jrsonnet-rowan-parser/src/event.rs index 9c946549..7612e606 100644 --- a/crates/jrsonnet-rowan-parser/src/event.rs +++ b/crates/jrsonnet-rowan-parser/src/event.rs @@ -22,8 +22,6 @@ pub enum Event { }, /// Eat token Token { kind: SyntaxKind }, - /// Push token, but do not eat anything, - VirtualToken { kind: SyntaxKind }, /// Position of finished node Finish { /// Same as forward_parent of Start, but for wrapping @@ -120,13 +118,6 @@ impl<'i> Sink<'i> { self.token(kind); eat_start_whitespace = true; } - Event::VirtualToken { kind } => { - if eat_start_whitespace { - self.skip_whitespace(); - } - self.virtual_token(kind); - eat_start_whitespace = false; - } Event::Finish { wrapper, error } => { if depth == 1 { self.skip_whitespace(); @@ -183,9 +174,6 @@ impl<'i> Sink<'i> { errors: self.errors, } } - fn virtual_token(&mut self, kind: SyntaxKind) { - self.builder.token(JsonnetLanguage::kind_to_raw(kind), "") - } fn token(&mut self, kind: SyntaxKind) { let lexeme = self.lexemes[self.offset]; self.builder diff --git a/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs b/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs index 92ffc06b..5f9d4dec 100644 --- a/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs +++ b/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs @@ -281,7 +281,7 @@ impl SyntaxKind { } } pub fn from_raw(r: u16) -> Self { - assert!(r < Self::__LAST as u16); + assert!(r < __LAST as u16); unsafe { std::mem::transmute(r) } } pub fn into_raw(self) -> u16 { @@ -290,4 +290,3 @@ impl SyntaxKind { } #[macro_export] macro_rules ! T { [||] => { $ crate :: SyntaxKind :: OR } ; [??] => { $ crate :: SyntaxKind :: NULL_COAELSE } ; [&&] => { $ crate :: SyntaxKind :: AND } ; [|] => { $ crate :: SyntaxKind :: BIT_OR } ; [^] => { $ crate :: SyntaxKind :: BIT_XOR } ; [&] => { $ crate :: SyntaxKind :: BIT_AND } ; [==] => { $ crate :: SyntaxKind :: EQ } ; [!=] => { $ crate :: SyntaxKind :: NE } ; [<] => { $ crate :: SyntaxKind :: LT } ; [>] => { $ crate :: SyntaxKind :: GT } ; [<=] => { $ crate :: SyntaxKind :: LE } ; [>=] => { $ crate :: SyntaxKind :: GE } ; [<<] => { $ crate :: SyntaxKind :: LHS } ; [>>] => { $ crate :: SyntaxKind :: RHS } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [*] => { $ crate :: SyntaxKind :: MUL } ; [/] => { $ crate :: SyntaxKind :: DIV } ; [%] => { $ crate :: SyntaxKind :: MODULO } ; [!] => { $ crate :: SyntaxKind :: NOT } ; [~] => { $ crate :: SyntaxKind :: BIT_NOT } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_BRACE } ; ['}'] => { $ crate :: SyntaxKind :: R_BRACE } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLONCOLON } ; [:::] => { $ crate :: SyntaxKind :: COLONCOLONCOLON } ; [;] => { $ crate :: SyntaxKind :: SEMI } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [...] => { $ crate :: SyntaxKind :: DOTDOTDOT } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['$'] => { $ crate :: SyntaxKind :: DOLLAR } ; [=] => { $ crate :: SyntaxKind :: ASSIGN } ; [?] => { $ crate :: SyntaxKind :: QUESTION_MARK } ; [tailstrict] => { $ crate :: SyntaxKind :: TAILSTRICT_KW } ; [local] => { $ crate :: SyntaxKind :: LOCAL_KW } ; [importstr] => { $ crate :: SyntaxKind :: IMPORTSTR_KW } ; [importbin] => { $ crate :: SyntaxKind :: IMPORTBIN_KW } ; [import] => { $ crate :: SyntaxKind :: IMPORT_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [then] => { $ crate :: SyntaxKind :: THEN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [function] => { $ crate :: SyntaxKind :: FUNCTION_KW } ; [error] => { $ crate :: SyntaxKind :: ERROR_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [null] => { $ crate :: SyntaxKind :: NULL_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [assert] => { $ crate :: SyntaxKind :: ASSERT_KW } } -pub use T; diff --git a/crates/jrsonnet-rowan-parser/src/marker.rs b/crates/jrsonnet-rowan-parser/src/marker.rs index 3a41bc64..87570afd 100644 --- a/crates/jrsonnet-rowan-parser/src/marker.rs +++ b/crates/jrsonnet-rowan-parser/src/marker.rs @@ -12,6 +12,7 @@ pub struct Ranger { pub pos: usize, } impl Ranger { + #[allow(dead_code)] pub fn finish(self, p: &Parser) -> FinishedRanger { FinishedRanger { start_token: self.pos, @@ -79,10 +80,10 @@ impl Marker { finish_event_idx, } } - pub fn complete(mut self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { + pub fn complete(self, p: &mut Parser, kind: SyntaxKind) -> CompletedMarker { self.complete_raw(p, kind, None) } - pub fn complete_error(mut self, p: &mut Parser, msg: impl AsRef) -> CompletedMarker { + pub fn complete_error(self, p: &mut Parser, msg: impl AsRef) -> CompletedMarker { self.complete_raw( p, SyntaxKind::ERROR_CUSTOM, @@ -91,7 +92,7 @@ impl Marker { }), ) } - pub fn complete_missing(mut self, p: &mut Parser, expected: ExpectedSyntax) -> CompletedMarker { + pub fn complete_missing(self, p: &mut Parser, expected: ExpectedSyntax) -> CompletedMarker { self.complete_raw( p, SyntaxKind::ERROR_MISSING_TOKEN, @@ -99,7 +100,7 @@ impl Marker { ) } pub fn complete_unexpected( - mut self, + self, p: &mut Parser, expected: ExpectedSyntax, found: SyntaxKind, diff --git a/crates/jrsonnet-rowan-parser/src/parser.rs b/crates/jrsonnet-rowan-parser/src/parser.rs index cea7dc46..453e00cb 100644 --- a/crates/jrsonnet-rowan-parser/src/parser.rs +++ b/crates/jrsonnet-rowan-parser/src/parser.rs @@ -144,6 +144,7 @@ impl Parser { } } + #[allow(dead_code)] pub(crate) fn expect_with_no_skip(&mut self, kind: SyntaxKind) { if self.at(kind) { self.bump(); @@ -773,18 +774,23 @@ fn destruct(p: &mut Parser) -> CompletedMarker { m.complete(p, DESTRUCT_SKIP) } else if p.at(T!['[']) { p.bump(); + #[allow(unused_variables)] let mut had_rest = false; loop { if p.at(T![']']) { p.bump(); break; } else if p.at(T![...]) { + #[allow(unused_variables)] let m_err = p.start_ranger(); destruct_rest(p); // if had_rest { // p.custom_error(m_err.finish(p), "only one rest can be present in array"); // } - had_rest = true; + #[allow(unused_assignments)] + { + had_rest = true; + } } else { destruct(p); } @@ -804,6 +810,7 @@ fn destruct(p: &mut Parser) -> CompletedMarker { p.bump(); break; } else if p.at(T![...]) { + #[allow(unused_variables)] let m_err = p.start_ranger(); destruct_rest(p); // if had_rest { diff --git a/crates/jrsonnet-rowan-parser/src/tests.rs b/crates/jrsonnet-rowan-parser/src/tests.rs index 17d20044..b4b681ef 100644 --- a/crates/jrsonnet-rowan-parser/src/tests.rs +++ b/crates/jrsonnet-rowan-parser/src/tests.rs @@ -247,7 +247,7 @@ fn stdlib() { #[test] fn eval_simple() { let src = "local a = 1, b = 2; a + local c = 1; c"; - let (node, errors) = parse(src); + let (node, _errors) = parse(src); dbg!(node); } diff --git a/xtask/src/sourcegen/ast.rs b/xtask/src/sourcegen/ast.rs index 8894d98d..1cf29178 100644 --- a/xtask/src/sourcegen/ast.rs +++ b/xtask/src/sourcegen/ast.rs @@ -148,7 +148,7 @@ pub fn lower(kinds: &KindsSrc, grammar: &Grammar) -> AstSrc { lower_rule(&mut fields, grammar, None, rule, false); let mut types = HashMap::new(); for field in fields.iter().filter(|f| f.token_name().is_none()) { - if let Some(old) = types.insert(field.ty(), field.method_name(kinds)) { + if let Some(_old) = types.insert(field.ty(), field.method_name(kinds)) { // panic!("{name}.{} has same type as {name}.{}, resolve conflict by wrapping one field: {}", old, field.method_name(kinds), field.ty()); } // TODO: check for assignable field types, i.e you can have