Skip to content

Commit

Permalink
fix: try fixing more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Oct 29, 2023
1 parent b0c1ac7 commit 4f5cac2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 40 deletions.
21 changes: 6 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions cmds/jrsonnet-fmt/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
6 changes: 3 additions & 3 deletions cmds/jrsonnet-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use jrsonnet_rowan_parser::{
};

use crate::{
children::{trivia_after, trivia_between},
children::trivia_after,
comments::{format_comments, CommentLocation},
};

Expand Down Expand Up @@ -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::<Stmt>(
let (stmts, _ending) = children_between::<Stmt>(
self.syntax().clone(),
None,
self.expr_base()
Expand All @@ -460,7 +460,7 @@ impl Printable for Expr {
p!(o: {stmt.value});
}
p!(o: {self.expr_base()});
let (suffixes, ending) = children_between::<Suffix>(
let (suffixes, _ending) = children_between::<Suffix>(
self.syntax().clone(),
self.expr_base()
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions crates/jrsonnet-parser/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn SourcePathT>);
impl SourcePath {
pub fn new(inner: impl SourcePathT) -> Self {
Expand Down
12 changes: 0 additions & 12 deletions crates/jrsonnet-rowan-parser/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
9 changes: 5 additions & 4 deletions crates/jrsonnet-rowan-parser/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<str>) -> CompletedMarker {
pub fn complete_error(self, p: &mut Parser, msg: impl AsRef<str>) -> CompletedMarker {
self.complete_raw(
p,
SyntaxKind::ERROR_CUSTOM,
Expand All @@ -91,15 +92,15 @@ 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,
Some(SyntaxError::Missing { expected }),
)
}
pub fn complete_unexpected(
mut self,
self,
p: &mut Parser,
expected: ExpectedSyntax,
found: SyntaxKind,
Expand Down
9 changes: 8 additions & 1 deletion crates/jrsonnet-rowan-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-rowan-parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion xtask/src/sourcegen/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f5cac2

Please sign in to comment.