difftreelog
refactor(rowan-parser) remove intrinsic syntax
in: master
13 files changed
cmds/jrsonnet-fmt/src/children.rsdiffbeforeafterboth3use std::{fmt::Debug, mem};3use std::{fmt::Debug, mem};445use jrsonnet_rowan_parser::{5use jrsonnet_rowan_parser::{6 nodes::{Trivia, TriviaKind},6 nodes::{CustomError, Trivia, TriviaKind},7 AstNode, AstToken, SyntaxElement,7 AstNode, AstToken, SyntaxElement, SyntaxNode, TS,8 SyntaxKind::*,9 SyntaxNode, TS,10};8};11912pub type ChildTrivia = Vec<Trivia>;10pub type ChildTrivia = Vec<Result<Trivia, String>>;131114/// Node should have no non-trivia tokens before element12/// Node should have no non-trivia tokens before element15pub fn trivia_before(node: SyntaxNode, end: Option<&SyntaxElement>) -> ChildTrivia {13pub fn trivia_before(node: SyntaxNode, end: Option<&SyntaxElement>) -> ChildTrivia {20 }18 }211922 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {20 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {23 out.push(trivia);21 out.push(Ok(trivia));24 } else if end.is_none() {22 } else if CustomError::can_cast(item.kind()) {23 out.push(Err(item.to_string()));24 } else if end.is_none() {25 break;25 break;26 } else {26 } else {27 assert!(27 assert!(28 TS![, ;].contains(item.kind()) || item.kind() == ERROR,28 TS![, ;].contains(item.kind()),29 "silently eaten token: {:?}",29 "silently eaten token: {:?}",30 item.kind()30 item.kind()31 )31 )46 let mut out = Vec::new();46 let mut out = Vec::new();47 for item in iter {47 for item in iter {48 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {48 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {49 out.push(trivia);49 out.push(Ok(trivia));50 } else {50 } else if CustomError::can_cast(item.kind()) {51 out.push(Err(item.to_string()))52 } else {51 assert!(53 assert!(52 TS![, ;].contains(item.kind()) || item.kind() == ERROR,54 TS![, ;].contains(item.kind()),53 "silently eaten token: {:?}",55 "silently eaten token: {:?}",54 item.kind()56 item.kind()55 )57 )74 let mut out = Vec::new();76 let mut out = Vec::new();75 for item in iter.take_while(|i| Some(i) != end) {77 for item in iter.take_while(|i| Some(i) != end) {76 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {78 if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {77 out.push(trivia);79 out.push(Ok(trivia));78 } else if loose {80 } else if CustomError::can_cast(item.kind()) {81 out.push(Err(item.to_string()))82 } else if loose {79 break;83 break;80 } else {84 } else {81 assert!(85 assert!(82 TS![, ;].contains(item.kind()) || item.kind() == ERROR,86 TS![, ;].contains(item.kind()),83 "silently eaten token: {:?}",87 "silently eaten token: {:?}",84 item.kind()88 item.kind()85 )89 )120fn count_newlines_before(tt: &ChildTrivia) -> usize {124fn count_newlines_before(tt: &ChildTrivia) -> usize {121 let mut nl_count = 0;125 let mut nl_count = 0;122 for t in tt {126 for t in tt {127 match t {123 match t.kind() {128 Ok(t) => match t.kind() {124 TriviaKind::Whitespace => {129 TriviaKind::Whitespace => {125 nl_count += t.text().bytes().filter(|b| *b == b'\n').count();130 nl_count += t.text().bytes().filter(|b| *b == b'\n').count();126 }131 }127 _ => break,132 _ => break,128 }133 },134 Err(_) => {135 nl_count += 1;136 }137 }129 }138 }130 nl_count139 nl_count131}140}132fn count_newlines_after(tt: &ChildTrivia) -> usize {141fn count_newlines_after(tt: &ChildTrivia) -> usize {133 let mut nl_count = 0;142 let mut nl_count = 0;134 for t in tt.iter().rev() {143 for t in tt.iter().rev() {144 match t {135 match t.kind() {145 Ok(t) => match t.kind() {136 TriviaKind::Whitespace => {146 TriviaKind::Whitespace => {137 nl_count += t.text().bytes().filter(|b| *b == b'\n').count();147 nl_count += t.text().bytes().filter(|b| *b == b'\n').count();138 }148 }145 break;155 break;146 }156 }147 _ => {}157 _ => {}148 }158 },159 Err(_) => nl_count += 1,160 }149 }161 }150 nl_count162 nl_count151}163}187 || current_child.is_none()199 || current_child.is_none()188 || trivia.text().contains('\n') && !is_single_line_comment200 || trivia.text().contains('\n') && !is_single_line_comment189 {201 {190 next.push(trivia.clone());202 next.push(Ok(trivia.clone()));191 started_next = true;203 started_next = true;192 } else {204 } else {193 let cur = current_child.as_mut().expect("checked not none");205 let cur = current_child.as_mut().expect("checked not none");194 cur.inline_trivia.push(trivia);206 cur.inline_trivia.push(Ok(trivia));195 if is_single_line_comment {207 if is_single_line_comment {196 started_next = true;208 started_next = true;197 }209 }198 }210 }199 had_some = true;211 had_some = true;200 } else if loose {212 } else if CustomError::can_cast(item.kind()) {213 next.push(Err(item.to_string()))214 } else if loose {201 if had_some {215 if had_some {202 break;216 break;203 }217 }204 started_next = true;218 started_next = true;205 } else {219 } else {206 assert!(220 assert!(207 TS![, ;].contains(item.kind()) || item.kind() == ERROR,221 TS![, ;].contains(item.kind()),208 "silently eaten token: {:?}",222 "silently eaten token: {:?}",209 item.kind()223 item.kind()210 )224 )cmds/jrsonnet-fmt/src/comments.rsdiffbeforeafterboth17 let mut pi = p!(new:);17 let mut pi = p!(new:);181819 for c in comments {19 for c in comments {20 let Ok(c) = c else {21 let mut text = c.as_ref().unwrap_err() as &str;22 while !text.is_empty() {23 let pos = text.find(|c| c == '\n' || c == '\t').unwrap_or(text.len());24 let sliced = &text[..pos];25 p!(pi: string(sliced.to_string()));26 text = &text[pos..];27 if! text.is_empty(){28 match text.as_bytes()[0] {29 b'\n' => p!(pi: nl),30 b'\t' => p!(pi: tab),31 _ => unreachable!()32 }33 text = &text[1..];34 }35 }36 continue;37 };20 match c.kind() {38 match c.kind() {21 TriviaKind::Whitespace => {}39 TriviaKind::Whitespace => {}22 TriviaKind::MultiLineComment => {40 TriviaKind::MultiLineComment => {37 let mut immediate_start = true;55 let mut immediate_start = true;38 let mut lines = text56 let mut lines = text39 .split('\n')57 .split('\n')40 .map(|l| l.trim_end())58 .map(|l| l.trim_end().to_string())41 .skip_while(|l| {59 .skip_while(|l| {42 if l.is_empty() {60 if l.is_empty() {43 immediate_start = false;61 immediate_start = false;51 lines.pop();69 lines.pop();52 }70 }53 if lines.len() == 1 && !doc {71 if lines.len() == 1 && !doc {54 p!(pi: str("/* ") str(lines[0].trim()) str(" */") nl)72 p!(pi: str("/* ") string(lines[0].trim().to_string()) str(" */") nl)55 } else if !lines.is_empty() {73 } else if !lines.is_empty() {56 fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {74 fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {57 let offset = a75 let offset = a62 &a[..offset]80 &a[..offset]63 }81 }64 // First line is not empty, extract ws prefix of it82 // First line is not empty, extract ws prefix of it65 let mut common_ws_padding = if immediate_start && lines.len() > 1 {83 let mut common_ws_padding = (if immediate_start && lines.len() > 1 {66 common_ws_prefix(lines[1], lines[1])84 common_ws_prefix(&lines[1], &lines[1])67 } else {85 } else {68 common_ws_prefix(lines[0], lines[0])86 common_ws_prefix(&lines[0], &lines[0])69 };87 })88 .to_string();70 for line in lines89 for line in lines71 .iter()90 .iter()72 .skip(if immediate_start { 2 } else { 1 })91 .skip(if immediate_start { 2 } else { 1 })73 .filter(|l| !l.is_empty())92 .filter(|l| !l.is_empty())74 {93 {75 common_ws_padding = common_ws_prefix(common_ws_padding, line);94 common_ws_padding = common_ws_prefix(&common_ws_padding, line).to_string();76 }95 }77 for line in lines96 for line in lines78 .iter_mut()97 .iter_mut()79 .skip(if immediate_start { 1 } else { 0 })98 .skip(if immediate_start { 1 } else { 0 })80 .filter(|l| !l.is_empty())99 .filter(|l| !l.is_empty())81 {100 {82 *line = line101 *line = line83 .strip_prefix(common_ws_padding)102 .strip_prefix(&common_ws_padding)103 .expect("all non-empty lines start with this padding")84 .expect("all non-empty lines start with this padding");104 .to_string();85 }105 }8610687 p!(pi: str("/*"));107 p!(pi: str("/*"));105 } else {125 } else {106 p!(pi: tab);126 p!(pi: tab);107 }127 }108 line = new_line;128 line = new_line.to_string();109 }129 }110 p!(pi: str(line) nl)130 p!(pi: string(line.to_string()) nl)111 }131 }112 }132 }113 if doc {133 if doc {136 if matches!(loc, CommentLocation::ItemInline) {156 if matches!(loc, CommentLocation::ItemInline) {137 p!(pi: str(" "))157 p!(pi: str(" "))138 }158 }139 p!(pi: str("# ") str(c.text().strip_prefix('#').expect("hash comment starts with #").trim()));159 p!(pi: str("# ") string(c.text().strip_prefix('#').expect("hash comment starts with #").trim().to_string()));140 if !matches!(loc, CommentLocation::ItemInline) {160 if !matches!(loc, CommentLocation::ItemInline) {141 p!(pi: nl)161 p!(pi: nl)142 }162 }145 if matches!(loc, CommentLocation::ItemInline) {165 if matches!(loc, CommentLocation::ItemInline) {146 p!(pi: str(" "))166 p!(pi: str(" "))147 }167 }148 p!(pi: str("// ") str(c.text().strip_prefix("//").expect("comment starts with //").trim()));168 p!(pi: str("// ") string(c.text().strip_prefix("//").expect("comment starts with //").trim().to_string()));149 if !matches!(loc, CommentLocation::ItemInline) {169 if !matches!(loc, CommentLocation::ItemInline) {150 p!(pi: nl)170 p!(pi: nl)151 }171 }152 }172 }153 // Garbage in - garbage out173 // Garbage in - garbage out154 TriviaKind::ErrorCommentTooShort => p!(pi: str("/*/")),174 TriviaKind::ErrorCommentTooShort => p!(pi: str("/*/")),155 TriviaKind::ErrorCommentUnterminated => p!(pi: str(c.text())),175 TriviaKind::ErrorCommentUnterminated => p!(pi: string(c.text().to_string())),156 }176 }157 }177 }158178cmds/jrsonnet-fmt/src/main.rsdiffbeforeafterboth5use jrsonnet_rowan_parser::{5use jrsonnet_rowan_parser::{6 nodes::{6 nodes::{7 ArgsDesc, Assertion, BinaryOperator, Bind, CompSpec, Destruct, DestructArrayPart,7 ArgsDesc, Assertion, BinaryOperator, Bind, CompSpec, Destruct, DestructArrayPart,8 DestructRest, Expr, Field, FieldName, ForSpec, IfSpec, ImportKind, LhsExpr, Literal,8 DestructRest, Expr, FieldName, ForSpec, IfSpec, ImportKind, LhsExpr, Literal, Member, Name,9 Member, Name, Number, ObjBody, ObjLocal, ParamsDesc, SliceDesc, SourceFile, Text,9 Number, ObjBody, ObjLocal, ParamsDesc, SliceDesc, SourceFile, Text, UnaryOperator,10 UnaryOperator,10 Visibility, VisibilityKind,11 },11 },12 rowan::NodeOrToken,12 AstNode, AstToken, SyntaxToken,13 AstNode, AstToken, SyntaxToken,13};14};141537 $o.push_str($e);38 $o.push_str($e);38 pi!(@s; $o: $($t)*);39 pi!(@s; $o: $($t)*);39 }};40 }};41 (@s; $o:ident: string($e:expr $(,)?) $($t:tt)*) => {{42 $o.push_string($e);43 pi!(@s; $o: $($t)*);44 }};40 (@s; $o:ident: nl $($t:tt)*) => {{45 (@s; $o:ident: nl $($t:tt)*) => {{41 $o.push_signal(dprint_core::formatting::Signal::NewLine);46 $o.push_signal(dprint_core::formatting::Signal::NewLine);42 pi!(@s; $o: $($t)*);47 pi!(@s; $o: $($t)*);96 if let Some(v) = self {101 if let Some(v) = self {97 v.print()102 v.print()98 } else {103 } else {99 p!(new: str(104 p!(new: string(100 &format!(105 format!(101 "/*missing {}*/",106 "/*missing {}*/",102 type_name::<P>().replace("jrsonnet_rowan_parser::generated::nodes::", "")107 type_name::<P>().replace("jrsonnet_rowan_parser::generated::nodes::", "")103 ),108 ),108113109impl Printable for SyntaxToken {114impl Printable for SyntaxToken {110 fn print(&self) -> PrintItems {115 fn print(&self) -> PrintItems {111 p!(new: str(&self.to_string()))116 p!(new: string(self.to_string()))112 }117 }113}118}114119115impl Printable for Text {120impl Printable for Text {116 fn print(&self) -> PrintItems {121 fn print(&self) -> PrintItems {117 p!(new: str(&format!("{}", self)))122 p!(new: string(format!("{}", self)))118 }123 }119}124}120impl Printable for Number {125impl Printable for Number {121 fn print(&self) -> PrintItems {126 fn print(&self) -> PrintItems {122 p!(new: str(&format!("{}", self)))127 p!(new: string(format!("{}", self)))123 }128 }124}129}125130202 }207 }203}208}209204impl Printable for Field {210impl Printable for Visibility {205 fn print(&self) -> PrintItems {211 fn print(&self) -> PrintItems {206 let mut pi = p!(new:);207 match self {208 Field::FieldNormal(n) => {209 p!(pi: {n.field_name()});212 p!(new: string(self.to_string()))210 if n.plus_token().is_some() {211 p!(pi: str("+"));212 }213 p!(pi: str(": ") {n.expr()});214 }215 Field::FieldMethod(m) => {216 p!(pi: {m.field_name()} {m.params_desc()} str(": ") {m.expr()});217 }218 }219 pi220 }213 }221}214}222215282 }275 }283}276}277278impl Printable for Member {279 fn print(&self) -> PrintItems {280 match self {281 Member::MemberBindStmt(b) => {282 p!(new: {b.obj_local()})283 }284 Member::MemberAssertStmt(ass) => {285 p!(new: {ass.assertion()})286 }287 Member::MemberFieldNormal(n) => {288 p!(new: {n.field_name()} if(n.plus_token().is_some())({n.plus_token()}) {n.visibility()} str(" ") {n.expr()})289 }290 Member::MemberFieldMethod(_) => todo!(),291 }292 }293}284294285impl Printable for ObjBody {295impl Printable for ObjBody {286 fn print(&self) -> PrintItems {296 fn print(&self) -> PrintItems {287 match self {297 match self {288 ObjBody::ObjBodyComp(_) => todo!(),298 ObjBody::ObjBodyComp(l) => {299 let mut pi = p!(new: str("{") >i nl);300 let (children, end_comments) = children_between::<Member>(301 l.syntax().clone(),302 l.l_brace_token().map(Into::into).as_ref(),303 Some(304 &(l.comp_specs()305 .next()306 .expect("at least one spec is defined")307 .syntax()308 .clone())309 .into(),310 ),311 );312 for mem in children.into_iter() {313 if mem.should_start_with_newline {314 p!(pi: nl);315 }316 p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));317 p!(pi: {mem.value} str(","));318 p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));319 p!(pi: nl)320 }321322 if end_comments.should_start_with_newline {323 p!(pi: nl);324 }325 p!(pi: items(format_comments(&end_comments.trivia, CommentLocation::EndOfItems)));326327 let (compspecs, end_comments) = children_between::<CompSpec>(328 l.syntax().clone(),329 l.member_comps()330 .last()331 .map(|m| m.syntax().clone())332 .map(Into::into)333 .or_else(|| l.l_brace_token().map(Into::into))334 .as_ref(),335 l.r_brace_token().map(Into::into).as_ref(),336 );337 for mem in compspecs.into_iter() {338 if mem.should_start_with_newline {339 p!(pi: nl);340 }341 p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));342 p!(pi: {mem.value});343 p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));344 p!(pi: nl)345 }346 if end_comments.should_start_with_newline {347 p!(pi: nl);348 }349 p!(pi: items(format_comments(&end_comments.trivia, CommentLocation::EndOfItems)));350351 p!(pi: <i str("}"));352 pi353 }289 ObjBody::ObjBodyMemberList(l) => {354 ObjBody::ObjBodyMemberList(l) => {290 let mut pi = p!(new: str("{") >i nl);355 let mut pi = p!(new: str("{") >i nl);291 let (children, end_comments) = children_between::<Member>(356 let (children, end_comments) = children_between::<Member>(298 p!(pi: nl);363 p!(pi: nl);299 }364 }300 p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));365 p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));301 match mem.value {302 Member::MemberBindStmt(b) => {303 p!(pi: {b.obj_local()})304 }305 Member::MemberAssertStmt(ass) => {306 p!(pi: {ass.assertion()})307 }308 Member::MemberField(f) => {309 p!(pi: {f.field()})310 }311 }312 p!(pi: str(","));366 p!(pi: {mem.value} str(","));313 p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));367 p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));314 p!(pi: nl)368 p!(pi: nl)315 }369 }326}380}327impl Printable for UnaryOperator {381impl Printable for UnaryOperator {328 fn print(&self) -> PrintItems {382 fn print(&self) -> PrintItems {329 p!(new: str(self.text()))383 p!(new: string(self.text().to_string()))330 }384 }331}385}332impl Printable for BinaryOperator {386impl Printable for BinaryOperator {333 fn print(&self) -> PrintItems {387 fn print(&self) -> PrintItems {334 p!(new: str(self.text()))388 p!(new: string(self.text().to_string()))335 }389 }336}390}337impl Printable for Bind {391impl Printable for Bind {348}402}349impl Printable for Literal {403impl Printable for Literal {350 fn print(&self) -> PrintItems {404 fn print(&self) -> PrintItems {351 p!(new: str(&self.syntax().to_string()))405 p!(new: string(self.syntax().to_string()))352 }406 }353}407}354impl Printable for ImportKind {408impl Printable for ImportKind {355 fn print(&self) -> PrintItems {409 fn print(&self) -> PrintItems {356 p!(new: str(&self.syntax().to_string()))410 p!(new: string(self.syntax().to_string()))357 }411 }358}412}359impl Printable for LhsExpr {413impl Printable for LhsExpr {406 Expr::ExprParened(p) => {460 Expr::ExprParened(p) => {407 p!(new: str("(") {p.expr()} str(")"))461 p!(new: str("(") {p.expr()} str(")"))408 }462 }409 Expr::ExprIntrinsicThisFile(_) => p!(new: str("$intrinsicThisFile")),410 Expr::ExprIntrinsicId(_) => p!(new: str("$intrinsicId")),411 Expr::ExprIntrinsic(i) => p!(new: str("$intrinsic(") {i.name()} str(")")),412 Expr::ExprString(s) => p!(new: {s.text()}),463 Expr::ExprString(s) => p!(new: {s.text()}),413 Expr::ExprNumber(n) => p!(new: {n.number()}),464 Expr::ExprNumber(n) => p!(new: {n.number()}),414 Expr::ExprArray(a) => {465 Expr::ExprArray(a) => {524575525fn main() {576fn main() {526 let (parsed, _errors) = jrsonnet_rowan_parser::parse(577 let (parsed, _errors) = jrsonnet_rowan_parser::parse(527 r#"578 r#"528579529580530 # Edit me!581 # Edit me!531 local b = import "b.libsonnet"; # comment582 local b = import "b.libsonnet"; # comment532 local a = import "a.libsonnet";583 local a = import "a.libsonnet";533584534 local f(x,y)=x+y;585 local f(x,y)=x+y;535586536 local {a: [b, ..., c], d, ...e} = null;587 local {a: [b, ..., c], d, ...e} = null;537588538 local ass = assert false : false; false;589 local ass = assert false : false; false;539590540 local fn = function(a, b, c = 3) 4;591 local fn = function(a, b, c = 3) 4;541592542 local comp = [a for b in c if d == e];593 local comp = [a for b in c if d == e];543 local ocomp = {[k]: 1 for k in v};594 local ocomp = {[k]: 1 for k in v};544595545 local ? = skip;596 local ? = skip;546597547 local intr = $intrinsic(test);598 local ie = a[expr];548 local intrId = $intrinsicId;549 local intrThisFile = $intrinsicThisFile;550551 local ie = a[expr];599552600 local unary = !a;553 local unary = !a;601554602 local555 local603 // I am comment556 // I am comment604 singleLocalWithItemComment = 1,557 singleLocalWithItemComment = 1,605 ;558 ;606559607 // Comment between local and expression560 // Comment between local and expression608561609 local562 local610 a = 1, // Inline563 a = 1, // Inline611 // Comment above b564 // Comment above b612 b = 4,565 b = 4,613566614 // c needs some space567 // c needs some space615 c = 5,568 c = 5,616569617 // Comment after everything570 // Comment after everything618 ;571 ;619572620573621 local Template = {z: "foo"};574 local Template = {z: "foo"};622575623 {576 {624 local577 local625578626 h = 3,579 h = 3,627 assert self.a == 1580 assert self.a == 1628581629 : "error",582 : "error",630 "f": ((((((3)))))) ,583 "f": ((((((3)))))) ,631 "g g":584 "g g":632 f(4,2),585 f(4,2),633 arr: [[586 arr: [[634 1, 2,587 1, 2,635 ],588 ],636 3,589 3,637 {590 {638 b: {591 b: {639 c: {592 c: {640 k: [16]593 k: [16]641 }594 }642 }595 }643 }596 }644 ],597 ],645 m: a[1::],598 m: a[1::],646 m: b[::],599 m: b[::],647600648 comments: {601 comments: {649 _: '',602 _: '',650 // Plain comment603 // Plain comment651 a: '',604 a: '',652605653 # Plain comment with empty line before606 # Plain comment with empty line before654 b: '',607 b: '',655 /*Single-line multiline comment608 /*Single-line multiline comment656609657 */610 */658 c: '',611 c: '',659612660 /**Single-line multiline doc comment613 /**Single-line multiline doc comment661614662 */615 */663 c: '',616 c: '',664617665 /**multiline doc comment618 /**multiline doc comment666 s619 s667 */620 */668 c: '',621 c: '',669622670 /*623 /*671624672 Multi-line625 Multi-line673626674 comment627 comment675 */628 */676 d: '',629 d: '',677630678 e: '', // Inline comment631 e: '', // Inline comment679632680 k: '',633 k: '',681634682 // Text after everything635 // Text after everything683 },636 },684 comments2: {637 comments2: {685 k: '',638 k: '',686 // Text after everything, but no newline above639 // Text after everything, but no newline above687 },640 },688 k: if a == b then641 k: if a == b then689642690643691 2644 2692645693 else Template {},694695 compspecs: {696 obj_with_no_item: {for i in [1, 2, 3]},697 obj_with_2_items: {a:1, b:2, for i in [1,2,3]},698 }646 else Template {}699647 } + Template700 } + Template648701649702650 // Comment after everything703 // Comment after everything651"#,704"#,652 );705 );653706654 // dbg!(errors);707 // dbg!(errors);crates/jrsonnet-rowan-parser/jsonnet.ungramdiffbeforeafterboth383839ExprLiteral =39ExprLiteral =40 Literal40 Literal41ExprIntrinsicThisFile =42 '$intrinsicThisFile'43ExprIntrinsicId =44 '$intrinsicId'45ExprIntrinsic =46 '$intrinsic'47 '('48 name:Name49 ')'50ExprString =41ExprString =51 Text42 Text52ExprNumber =43ExprNumber =110| ExprApply101| ExprApply111| ExprObjExtend102| ExprObjExtend112| ExprParened103| ExprParened113| ExprIntrinsicThisFile114| ExprIntrinsicId115| ExprIntrinsic116| ExprString104| ExprString117| ExprNumber105| ExprNumber118| ExprLiteral106| ExprLiteral167155168ObjBodyComp =156ObjBodyComp =169 '{'157 '{'170 pre:ObjLocalPostComma*158 (MemberComp (',' MemberComp)* ','?)?171 '['172 key:LhsExpr173 ']'174 '+'?175 ':'176 value:Expr177 post:ObjLocalPreComma*178 CompSpec*159 CompSpec*179 '}'160 '}'180ObjBodyMemberList =161ObjBodyMemberList =185 ObjBodyComp166 ObjBodyComp186| ObjBodyMemberList167| ObjBodyMemberList187168188ObjLocalPostComma =189 ObjLocal190 ','191ObjLocalPreComma =192 ','193 ObjLocal194195MemberBindStmt = ObjLocal169MemberBindStmt = ObjLocal196MemberAssertStmt = Assertion170MemberAssertStmt = Assertion197MemberFieldNormal =171MemberFieldNormal =204 ParamsDesc178 ParamsDesc205 Visibility179 Visibility206 Expr180 Expr181MemberComp =182 MemberBindStmt183| MemberFieldNormal184| MemberFieldMethod207Member =185Member =208 MemberBindStmt186 MemberBindStmt209| MemberAssertStmt187| MemberAssertStmt367| 'LIT_SINGLE_LINE_HASH_COMMENT!'345| 'LIT_SINGLE_LINE_HASH_COMMENT!'368| 'LIT_SINGLE_LINE_SLASH_COMMENT!'346| 'LIT_SINGLE_LINE_SLASH_COMMENT!'369347370ParsingError =348CustomError =371 'ERROR_MISSING_TOKEN!'349 'ERROR_MISSING_TOKEN!'372| 'ERROR_UNEXPECTED_TOKEN!'350| 'ERROR_UNEXPECTED_TOKEN!'373| 'ERROR_CUSTOM!'351| 'ERROR_CUSTOM!'crates/jrsonnet-rowan-parser/src/generated/nodes.rsdiffbeforeafterboth211 }211 }212}212}213214#[derive(Debug, Clone, PartialEq, Eq, Hash)]215pub struct ExprIntrinsicThisFile {216 pub(crate) syntax: SyntaxNode,217}218impl ExprIntrinsicThisFile {219 pub fn intrinsic_this_file_token(&self) -> Option<SyntaxToken> {220 support::token(&self.syntax, T!["$intrinsicThisFile"])221 }222}223224#[derive(Debug, Clone, PartialEq, Eq, Hash)]225pub struct ExprIntrinsicId {226 pub(crate) syntax: SyntaxNode,227}228impl ExprIntrinsicId {229 pub fn intrinsic_id_token(&self) -> Option<SyntaxToken> {230 support::token(&self.syntax, T!["$intrinsicId"])231 }232}233234#[derive(Debug, Clone, PartialEq, Eq, Hash)]235pub struct ExprIntrinsic {236 pub(crate) syntax: SyntaxNode,237}238impl ExprIntrinsic {239 pub fn intrinsic_token(&self) -> Option<SyntaxToken> {240 support::token(&self.syntax, T!["$intrinsic"])241 }242 pub fn l_paren_token(&self) -> Option<SyntaxToken> {243 support::token(&self.syntax, T!['('])244 }245 pub fn name(&self) -> Option<Name> {246 support::child(&self.syntax)247 }248 pub fn r_paren_token(&self) -> Option<SyntaxToken> {249 support::token(&self.syntax, T![')'])250 }251}252213253#[derive(Debug, Clone, PartialEq, Eq, Hash)]214#[derive(Debug, Clone, PartialEq, Eq, Hash)]254pub struct ExprString {215pub struct ExprString {535 pub fn l_brace_token(&self) -> Option<SyntaxToken> {496 pub fn l_brace_token(&self) -> Option<SyntaxToken> {536 support::token(&self.syntax, T!['{'])497 support::token(&self.syntax, T!['{'])537 }498 }538 pub fn pre(&self) -> AstChildren<ObjLocalPostComma> {499 pub fn member_comps(&self) -> AstChildren<MemberComp> {539 support::children(&self.syntax)500 support::children(&self.syntax)540 }501 }541 pub fn l_brack_token(&self) -> Option<SyntaxToken> {542 support::token(&self.syntax, T!['['])543 }544 pub fn key(&self) -> Option<LhsExpr> {545 support::child(&self.syntax)546 }547 pub fn r_brack_token(&self) -> Option<SyntaxToken> {548 support::token(&self.syntax, T![']'])549 }550 pub fn plus_token(&self) -> Option<SyntaxToken> {551 support::token(&self.syntax, T![+])552 }553 pub fn colon_token(&self) -> Option<SyntaxToken> {554 support::token(&self.syntax, T![:])555 }556 pub fn value(&self) -> Option<Expr> {557 support::child(&self.syntax)558 }559 pub fn post(&self) -> AstChildren<ObjLocalPreComma> {560 support::children(&self.syntax)561 }562 pub fn comp_specs(&self) -> AstChildren<CompSpec> {502 pub fn comp_specs(&self) -> AstChildren<CompSpec> {563 support::children(&self.syntax)503 support::children(&self.syntax)564 }504 }567 }507 }568}508}569570#[derive(Debug, Clone, PartialEq, Eq, Hash)]571pub struct ObjLocalPostComma {572 pub(crate) syntax: SyntaxNode,573}574impl ObjLocalPostComma {575 pub fn obj_local(&self) -> Option<ObjLocal> {576 support::child(&self.syntax)577 }578 pub fn comma_token(&self) -> Option<SyntaxToken> {579 support::token(&self.syntax, T![,])580 }581}582583#[derive(Debug, Clone, PartialEq, Eq, Hash)]584pub struct ObjLocalPreComma {585 pub(crate) syntax: SyntaxNode,586}587impl ObjLocalPreComma {588 pub fn comma_token(&self) -> Option<SyntaxToken> {589 support::token(&self.syntax, T![,])590 }591 pub fn obj_local(&self) -> Option<ObjLocal> {592 support::child(&self.syntax)593 }594}595509596#[derive(Debug, Clone, PartialEq, Eq, Hash)]510#[derive(Debug, Clone, PartialEq, Eq, Hash)]597pub struct ObjBodyMemberList {511pub struct ObjBodyMemberList {609 }523 }610}524}611612#[derive(Debug, Clone, PartialEq, Eq, Hash)]613pub struct ObjLocal {614 pub(crate) syntax: SyntaxNode,615}616impl ObjLocal {617 pub fn local_kw_token(&self) -> Option<SyntaxToken> {618 support::token(&self.syntax, T![local])619 }620 pub fn bind(&self) -> Option<Bind> {621 support::child(&self.syntax)622 }623}624525625#[derive(Debug, Clone, PartialEq, Eq, Hash)]526#[derive(Debug, Clone, PartialEq, Eq, Hash)]626pub struct MemberBindStmt {527pub struct MemberBindStmt {632 }533 }633}534}535536#[derive(Debug, Clone, PartialEq, Eq, Hash)]537pub struct ObjLocal {538 pub(crate) syntax: SyntaxNode,539}540impl ObjLocal {541 pub fn local_kw_token(&self) -> Option<SyntaxToken> {542 support::token(&self.syntax, T![local])543 }544 pub fn bind(&self) -> Option<Bind> {545 support::child(&self.syntax)546 }547}634548635#[derive(Debug, Clone, PartialEq, Eq, Hash)]549#[derive(Debug, Clone, PartialEq, Eq, Hash)]636pub struct MemberAssertStmt {550pub struct MemberAssertStmt {905 ExprApply(ExprApply),819 ExprApply(ExprApply),906 ExprObjExtend(ExprObjExtend),820 ExprObjExtend(ExprObjExtend),907 ExprParened(ExprParened),821 ExprParened(ExprParened),908 ExprIntrinsicThisFile(ExprIntrinsicThisFile),909 ExprIntrinsicId(ExprIntrinsicId),910 ExprIntrinsic(ExprIntrinsic),911 ExprString(ExprString),822 ExprString(ExprString),912 ExprNumber(ExprNumber),823 ExprNumber(ExprNumber),913 ExprLiteral(ExprLiteral),824 ExprLiteral(ExprLiteral),941 BindFunction(BindFunction),852 BindFunction(BindFunction),942}853}854855#[derive(Debug, Clone, PartialEq, Eq, Hash)]856pub enum MemberComp {857 MemberBindStmt(MemberBindStmt),858 MemberFieldNormal(MemberFieldNormal),859 MemberFieldMethod(MemberFieldMethod),860}943861944#[derive(Debug, Clone, PartialEq, Eq, Hash)]862#[derive(Debug, Clone, PartialEq, Eq, Hash)]945pub enum Member {863pub enum Member {1110}1028}111110291112#[derive(Debug, Clone, PartialEq, Eq, Hash)]1030#[derive(Debug, Clone, PartialEq, Eq, Hash)]1113pub struct ParsingError {1031pub struct CustomError {1114 syntax: SyntaxToken,1032 syntax: SyntaxToken,1115 kind: ParsingErrorKind,1033 kind: CustomErrorKind,1116}1034}111710351118#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1036#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1119pub enum ParsingErrorKind {1037pub enum CustomErrorKind {1120 ErrorMissingToken,1038 ErrorMissingToken,1121 ErrorUnexpectedToken,1039 ErrorUnexpectedToken,1122 ErrorCustom,1040 ErrorCustom,1331 &self.syntax1249 &self.syntax1332 }1250 }1333}1251}1334impl AstNode for ExprIntrinsicThisFile {1335 fn can_cast(kind: SyntaxKind) -> bool {1336 kind == EXPR_INTRINSIC_THIS_FILE1337 }1338 fn cast(syntax: SyntaxNode) -> Option<Self> {1339 if Self::can_cast(syntax.kind()) {1340 Some(Self { syntax })1341 } else {1342 None1343 }1344 }1345 fn syntax(&self) -> &SyntaxNode {1346 &self.syntax1347 }1348}1349impl AstNode for ExprIntrinsicId {1350 fn can_cast(kind: SyntaxKind) -> bool {1351 kind == EXPR_INTRINSIC_ID1352 }1353 fn cast(syntax: SyntaxNode) -> Option<Self> {1354 if Self::can_cast(syntax.kind()) {1355 Some(Self { syntax })1356 } else {1357 None1358 }1359 }1360 fn syntax(&self) -> &SyntaxNode {1361 &self.syntax1362 }1363}1364impl AstNode for ExprIntrinsic {1365 fn can_cast(kind: SyntaxKind) -> bool {1366 kind == EXPR_INTRINSIC1367 }1368 fn cast(syntax: SyntaxNode) -> Option<Self> {1369 if Self::can_cast(syntax.kind()) {1370 Some(Self { syntax })1371 } else {1372 None1373 }1374 }1375 fn syntax(&self) -> &SyntaxNode {1376 &self.syntax1377 }1378}1379impl AstNode for ExprString {1252impl AstNode for ExprString {1380 fn can_cast(kind: SyntaxKind) -> bool {1253 fn can_cast(kind: SyntaxKind) -> bool {1381 kind == EXPR_STRING1254 kind == EXPR_STRING1676 &self.syntax1549 &self.syntax1677 }1550 }1678}1551}1679impl AstNode for ObjLocalPostComma {1680 fn can_cast(kind: SyntaxKind) -> bool {1681 kind == OBJ_LOCAL_POST_COMMA1682 }1683 fn cast(syntax: SyntaxNode) -> Option<Self> {1684 if Self::can_cast(syntax.kind()) {1685 Some(Self { syntax })1686 } else {1687 None1688 }1689 }1690 fn syntax(&self) -> &SyntaxNode {1691 &self.syntax1692 }1693}1694impl AstNode for ObjLocalPreComma {1695 fn can_cast(kind: SyntaxKind) -> bool {1696 kind == OBJ_LOCAL_PRE_COMMA1697 }1698 fn cast(syntax: SyntaxNode) -> Option<Self> {1699 if Self::can_cast(syntax.kind()) {1700 Some(Self { syntax })1701 } else {1702 None1703 }1704 }1705 fn syntax(&self) -> &SyntaxNode {1706 &self.syntax1707 }1708}1709impl AstNode for ObjBodyMemberList {1552impl AstNode for ObjBodyMemberList {1710 fn can_cast(kind: SyntaxKind) -> bool {1553 fn can_cast(kind: SyntaxKind) -> bool {1711 kind == OBJ_BODY_MEMBER_LIST1554 kind == OBJ_BODY_MEMBER_LIST1721 &self.syntax1564 &self.syntax1722 }1565 }1723}1566}1724impl AstNode for ObjLocal {1725 fn can_cast(kind: SyntaxKind) -> bool {1726 kind == OBJ_LOCAL1727 }1728 fn cast(syntax: SyntaxNode) -> Option<Self> {1729 if Self::can_cast(syntax.kind()) {1730 Some(Self { syntax })1731 } else {1732 None1733 }1734 }1735 fn syntax(&self) -> &SyntaxNode {1736 &self.syntax1737 }1738}1739impl AstNode for MemberBindStmt {1567impl AstNode for MemberBindStmt {1740 fn can_cast(kind: SyntaxKind) -> bool {1568 fn can_cast(kind: SyntaxKind) -> bool {1741 kind == MEMBER_BIND_STMT1569 kind == MEMBER_BIND_STMT1751 &self.syntax1579 &self.syntax1752 }1580 }1753}1581}1582impl AstNode for ObjLocal {1583 fn can_cast(kind: SyntaxKind) -> bool {1584 kind == OBJ_LOCAL1585 }1586 fn cast(syntax: SyntaxNode) -> Option<Self> {1587 if Self::can_cast(syntax.kind()) {1588 Some(Self { syntax })1589 } else {1590 None1591 }1592 }1593 fn syntax(&self) -> &SyntaxNode {1594 &self.syntax1595 }1596}1754impl AstNode for MemberAssertStmt {1597impl AstNode for MemberAssertStmt {1755 fn can_cast(kind: SyntaxKind) -> bool {1598 fn can_cast(kind: SyntaxKind) -> bool {1756 kind == MEMBER_ASSERT_STMT1599 kind == MEMBER_ASSERT_STMT2046 Expr::ExprParened(node)1889 Expr::ExprParened(node)2047 }1890 }2048}1891}2049impl From<ExprIntrinsicThisFile> for Expr {2050 fn from(node: ExprIntrinsicThisFile) -> Expr {2051 Expr::ExprIntrinsicThisFile(node)2052 }2053}2054impl From<ExprIntrinsicId> for Expr {2055 fn from(node: ExprIntrinsicId) -> Expr {2056 Expr::ExprIntrinsicId(node)2057 }2058}2059impl From<ExprIntrinsic> for Expr {2060 fn from(node: ExprIntrinsic) -> Expr {2061 Expr::ExprIntrinsic(node)2062 }2063}2064impl From<ExprString> for Expr {1892impl From<ExprString> for Expr {2065 fn from(node: ExprString) -> Expr {1893 fn from(node: ExprString) -> Expr {2066 Expr::ExprString(node)1894 Expr::ExprString(node)2137 | EXPR_APPLY2138 | EXPR_OBJ_EXTEND1961 | EXPR_OBJ_EXTEND | EXPR_PARENED | EXPR_STRING | EXPR_NUMBER | EXPR_LITERAL2139 | EXPR_PARENED2140 | EXPR_INTRINSIC_THIS_FILE2141 | EXPR_INTRINSIC_ID2142 | EXPR_INTRINSIC2143 | EXPR_STRING2144 | EXPR_NUMBER2145 | EXPR_LITERAL2166 EXPR_APPLY => Expr::ExprApply(ExprApply { syntax }),1974 EXPR_APPLY => Expr::ExprApply(ExprApply { syntax }),2167 EXPR_OBJ_EXTEND => Expr::ExprObjExtend(ExprObjExtend { syntax }),1975 EXPR_OBJ_EXTEND => Expr::ExprObjExtend(ExprObjExtend { syntax }),2168 EXPR_PARENED => Expr::ExprParened(ExprParened { syntax }),1976 EXPR_PARENED => Expr::ExprParened(ExprParened { syntax }),2169 EXPR_INTRINSIC_THIS_FILE => {2170 Expr::ExprIntrinsicThisFile(ExprIntrinsicThisFile { syntax })2171 }2172 EXPR_INTRINSIC_ID => Expr::ExprIntrinsicId(ExprIntrinsicId { syntax }),2173 EXPR_INTRINSIC => Expr::ExprIntrinsic(ExprIntrinsic { syntax }),2174 EXPR_STRING => Expr::ExprString(ExprString { syntax }),1977 EXPR_STRING => Expr::ExprString(ExprString { syntax }),2175 EXPR_NUMBER => Expr::ExprNumber(ExprNumber { syntax }),1978 EXPR_NUMBER => Expr::ExprNumber(ExprNumber { syntax }),2176 EXPR_LITERAL => Expr::ExprLiteral(ExprLiteral { syntax }),1979 EXPR_LITERAL => Expr::ExprLiteral(ExprLiteral { syntax }),2198 Expr::ExprApply(it) => &it.syntax,2001 Expr::ExprApply(it) => &it.syntax,2199 Expr::ExprObjExtend(it) => &it.syntax,2002 Expr::ExprObjExtend(it) => &it.syntax,2200 Expr::ExprParened(it) => &it.syntax,2003 Expr::ExprParened(it) => &it.syntax,2201 Expr::ExprIntrinsicThisFile(it) => &it.syntax,2202 Expr::ExprIntrinsicId(it) => &it.syntax,2203 Expr::ExprIntrinsic(it) => &it.syntax,2204 Expr::ExprString(it) => &it.syntax,2004 Expr::ExprString(it) => &it.syntax,2205 Expr::ExprNumber(it) => &it.syntax,2005 Expr::ExprNumber(it) => &it.syntax,2206 Expr::ExprLiteral(it) => &it.syntax,2006 Expr::ExprLiteral(it) => &it.syntax,2313 }2113 }2314 }2114 }2315}2115}2116impl From<MemberBindStmt> for MemberComp {2117 fn from(node: MemberBindStmt) -> MemberComp {2118 MemberComp::MemberBindStmt(node)2119 }2120}2121impl From<MemberFieldNormal> for MemberComp {2122 fn from(node: MemberFieldNormal) -> MemberComp {2123 MemberComp::MemberFieldNormal(node)2124 }2125}2126impl From<MemberFieldMethod> for MemberComp {2127 fn from(node: MemberFieldMethod) -> MemberComp {2128 MemberComp::MemberFieldMethod(node)2129 }2130}2131impl AstNode for MemberComp {2132 fn can_cast(kind: SyntaxKind) -> bool {2133 match kind {2134 MEMBER_BIND_STMT | MEMBER_FIELD_NORMAL | MEMBER_FIELD_METHOD => true,2135 _ => false,2136 }2137 }2138 fn cast(syntax: SyntaxNode) -> Option<Self> {2139 let res = match syntax.kind() {2140 MEMBER_BIND_STMT => MemberComp::MemberBindStmt(MemberBindStmt { syntax }),2141 MEMBER_FIELD_NORMAL => MemberComp::MemberFieldNormal(MemberFieldNormal { syntax }),2142 MEMBER_FIELD_METHOD => MemberComp::MemberFieldMethod(MemberFieldMethod { syntax }),2143 _ => return None,2144 };2145 Some(res)2146 }2147 fn syntax(&self) -> &SyntaxNode {2148 match self {2149 MemberComp::MemberBindStmt(it) => &it.syntax,2150 MemberComp::MemberFieldNormal(it) => &it.syntax,2151 MemberComp::MemberFieldMethod(it) => &it.syntax,2152 }2153 }2154}2316impl From<MemberBindStmt> for Member {2155impl From<MemberBindStmt> for Member {2317 fn from(node: MemberBindStmt) -> Member {2156 fn from(node: MemberBindStmt) -> Member {2318 Member::MemberBindStmt(node)2157 Member::MemberBindStmt(node)2847 std::fmt::Display::fmt(self.syntax(), f)2686 std::fmt::Display::fmt(self.syntax(), f)2848 }2687 }2849}2688}2850impl AstToken for ParsingError {2689impl AstToken for CustomError {2851 fn can_cast(kind: SyntaxKind) -> bool {2690 fn can_cast(kind: SyntaxKind) -> bool {2852 ParsingErrorKind::can_cast(kind)2691 CustomErrorKind::can_cast(kind)2853 }2692 }2854 fn cast(syntax: SyntaxToken) -> Option<Self> {2693 fn cast(syntax: SyntaxToken) -> Option<Self> {2855 let kind = ParsingErrorKind::cast(syntax.kind())?;2694 let kind = CustomErrorKind::cast(syntax.kind())?;2856 Some(ParsingError { syntax, kind })2695 Some(CustomError { syntax, kind })2857 }2696 }2858 fn syntax(&self) -> &SyntaxToken {2697 fn syntax(&self) -> &SyntaxToken {2859 &self.syntax2698 &self.syntax2860 }2699 }2861}2700}2862impl ParsingErrorKind {2701impl CustomErrorKind {2863 fn can_cast(kind: SyntaxKind) -> bool {2702 fn can_cast(kind: SyntaxKind) -> bool {2864 match kind {2703 match kind {2865 ERROR_MISSING_TOKEN | ERROR_UNEXPECTED_TOKEN | ERROR_CUSTOM => true,2704 ERROR_MISSING_TOKEN | ERROR_UNEXPECTED_TOKEN | ERROR_CUSTOM => true,2876 Some(res)2715 Some(res)2877 }2716 }2878}2717}2879impl ParsingError {2718impl CustomError {2880 pub fn kind(&self) -> ParsingErrorKind {2719 pub fn kind(&self) -> CustomErrorKind {2881 self.kind2720 self.kind2882 }2721 }2883}2722}2884impl std::fmt::Display for ParsingError {2723impl std::fmt::Display for CustomError {2885 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2724 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2886 std::fmt::Display::fmt(self.syntax(), f)2725 std::fmt::Display::fmt(self.syntax(), f)2887 }2726 }2906 std::fmt::Display::fmt(self.syntax(), f)2745 std::fmt::Display::fmt(self.syntax(), f)2907 }2746 }2908}2747}2748impl std::fmt::Display for MemberComp {2749 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2750 std::fmt::Display::fmt(self.syntax(), f)2751 }2752}2909impl std::fmt::Display for Member {2753impl std::fmt::Display for Member {2910 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2754 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2911 std::fmt::Display::fmt(self.syntax(), f)2755 std::fmt::Display::fmt(self.syntax(), f)2996 std::fmt::Display::fmt(self.syntax(), f)2840 std::fmt::Display::fmt(self.syntax(), f)2997 }2841 }2998}2842}2999impl std::fmt::Display for ExprIntrinsicThisFile {3000 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3001 std::fmt::Display::fmt(self.syntax(), f)3002 }3003}3004impl std::fmt::Display for ExprIntrinsicId {3005 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3006 std::fmt::Display::fmt(self.syntax(), f)3007 }3008}3009impl std::fmt::Display for ExprIntrinsic {3010 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3011 std::fmt::Display::fmt(self.syntax(), f)3012 }3013}3014impl std::fmt::Display for ExprString {2843impl std::fmt::Display for ExprString {3015 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2844 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3016 std::fmt::Display::fmt(self.syntax(), f)2845 std::fmt::Display::fmt(self.syntax(), f)3111 std::fmt::Display::fmt(self.syntax(), f)2940 std::fmt::Display::fmt(self.syntax(), f)3112 }2941 }3113}2942}3114impl std::fmt::Display for ObjLocalPostComma {3115 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3116 std::fmt::Display::fmt(self.syntax(), f)3117 }3118}3119impl std::fmt::Display for ObjLocalPreComma {3120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3121 std::fmt::Display::fmt(self.syntax(), f)3122 }3123}3124impl std::fmt::Display for ObjBodyMemberList {2943impl std::fmt::Display for ObjBodyMemberList {3125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2944 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3126 std::fmt::Display::fmt(self.syntax(), f)2945 std::fmt::Display::fmt(self.syntax(), f)3127 }2946 }3128}2947}3129impl std::fmt::Display for ObjLocal {3130 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3131 std::fmt::Display::fmt(self.syntax(), f)3132 }3133}3134impl std::fmt::Display for MemberBindStmt {2948impl std::fmt::Display for MemberBindStmt {3135 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2949 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3136 std::fmt::Display::fmt(self.syntax(), f)2950 std::fmt::Display::fmt(self.syntax(), f)3137 }2951 }3138}2952}2953impl std::fmt::Display for ObjLocal {2954 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2955 std::fmt::Display::fmt(self.syntax(), f)2956 }2957}3139impl std::fmt::Display for MemberAssertStmt {2958impl std::fmt::Display for MemberAssertStmt {3140 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2959 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3141 std::fmt::Display::fmt(self.syntax(), f)2960 std::fmt::Display::fmt(self.syntax(), f)crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rsdiffbeforeafterboth89 ASSIGN,89 ASSIGN,90 #[token("?")]90 #[token("?")]91 QUESTION_MARK,91 QUESTION_MARK,92 #[token("$intrinsicThisFile")]93 INTRINSIC_THIS_FILE,94 #[token("$intrinsicId")]95 INTRINSIC_ID,96 #[token("$intrinsic")]97 INTRINSIC,98 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?")]92 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?")]99 FLOAT,93 FLOAT,100 #[regex("(?:0|[1-9][0-9]*)\\.[^0-9]")]94 #[regex("(?:0|[1-9][0-9]*)\\.[^0-9]")]199 EXPR_OBJ_EXTEND,193 EXPR_OBJ_EXTEND,200 EXPR_PARENED,194 EXPR_PARENED,201 EXPR_LITERAL,195 EXPR_LITERAL,202 EXPR_INTRINSIC_THIS_FILE,203 EXPR_INTRINSIC_ID,204 EXPR_INTRINSIC,205 EXPR_STRING,196 EXPR_STRING,206 EXPR_NUMBER,197 EXPR_NUMBER,207 EXPR_ARRAY,198 EXPR_ARRAY,222 SLICE_DESC_STEP,213 SLICE_DESC_STEP,223 ARG,214 ARG,224 OBJ_BODY_COMP,215 OBJ_BODY_COMP,225 OBJ_LOCAL_POST_COMMA,226 OBJ_LOCAL_PRE_COMMA,227 OBJ_BODY_MEMBER_LIST,216 OBJ_BODY_MEMBER_LIST,228 OBJ_LOCAL,229 MEMBER_BIND_STMT,217 MEMBER_BIND_STMT,218 OBJ_LOCAL,230 MEMBER_ASSERT_STMT,219 MEMBER_ASSERT_STMT,231 MEMBER_FIELD_NORMAL,220 MEMBER_FIELD_NORMAL,248 OBJ_BODY,237 OBJ_BODY,249 COMP_SPEC,238 COMP_SPEC,250 BIND,239 BIND,240 MEMBER_COMP,251 MEMBER,241 MEMBER,252 FIELD_NAME,242 FIELD_NAME,253 DESTRUCT,243 DESTRUCT,260 IMPORT_KIND,250 IMPORT_KIND,261 VISIBILITY,251 VISIBILITY,262 TRIVIA,252 TRIVIA,263 PARSING_ERROR,253 CUSTOM_ERROR,264 #[doc(hidden)]254 #[doc(hidden)]265 __LAST,255 __LAST,266}256}271 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | LHS | RHS261 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | LHS | RHS272 | PLUS | MINUS | MUL | DIV | MODULO | NOT | BIT_NOT | L_BRACK | R_BRACK | L_PAREN262 | PLUS | MINUS | MUL | DIV | MODULO | NOT | BIT_NOT | L_BRACK | R_BRACK | L_PAREN273 | R_PAREN | L_BRACE | R_BRACE | COLON | COLONCOLON | COLONCOLONCOLON | SEMI | DOT263 | R_PAREN | L_BRACE | R_BRACE | COLON | COLONCOLON | COLONCOLONCOLON | SEMI | DOT274 | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | INTRINSIC_THIS_FILE264 | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | TAILSTRICT_KW275 | INTRINSIC_ID | INTRINSIC | TAILSTRICT_KW | IMPORTSTR_KW | IMPORTBIN_KW265 | IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW276 | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW | FUNCTION_KW | ERROR_KW | IN_KW266 | FUNCTION_KW | ERROR_KW | IN_KW | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW277 | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | SUPER_KW | FOR_KW | ASSERT_KW => true,267 | SUPER_KW | FOR_KW | ASSERT_KW => true,278 _ => false,268 _ => false,279 }269 }280 }270 }281 pub fn is_enum(self) -> bool {271 pub fn is_enum(self) -> bool {282 match self {272 match self {283 EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER | FIELD_NAME | DESTRUCT273 EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER_COMP | MEMBER | FIELD_NAME | DESTRUCT284 | DESTRUCT_ARRAY_PART | BINARY_OPERATOR | UNARY_OPERATOR | LITERAL | TEXT | NUMBER274 | DESTRUCT_ARRAY_PART | BINARY_OPERATOR | UNARY_OPERATOR | LITERAL | TEXT | NUMBER285 | IMPORT_KIND | VISIBILITY | TRIVIA | PARSING_ERROR => true,275 | IMPORT_KIND | VISIBILITY | TRIVIA | CUSTOM_ERROR => true,286 _ => false,276 _ => false,287 }277 }288 }278 }295 }285 }296}286}297#[macro_export]287#[macro_export]298macro_rules ! T { [||] => { $ crate :: SyntaxKind :: OR } ; [&&] => { $ 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 } ; ["$intrinsicThisFile"] => { $ crate :: SyntaxKind :: INTRINSIC_THIS_FILE } ; ["$intrinsicId"] => { $ crate :: SyntaxKind :: INTRINSIC_ID } ; ["$intrinsic"] => { $ crate :: SyntaxKind :: INTRINSIC } ; [tailstrict] => { $ crate :: SyntaxKind :: TAILSTRICT_KW } ; [importstr] => { $ crate :: SyntaxKind :: IMPORTSTR_KW } ; [importbin] => { $ crate :: SyntaxKind :: IMPORTBIN_KW } ; [import] => { $ crate :: SyntaxKind :: IMPORT_KW } ; [local] => { $ crate :: SyntaxKind :: LOCAL_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 } }288macro_rules ! T { [||] => { $ crate :: SyntaxKind :: OR } ; [&&] => { $ 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 } ; [importstr] => { $ crate :: SyntaxKind :: IMPORTSTR_KW } ; [importbin] => { $ crate :: SyntaxKind :: IMPORTBIN_KW } ; [import] => { $ crate :: SyntaxKind :: IMPORT_KW } ; [local] => { $ crate :: SyntaxKind :: LOCAL_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 } }299pub use T;289pub use T;300290crates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth114 pub fn parse(mut self) -> Vec<Event> {114 pub fn parse(mut self) -> Vec<Event> {115 let m = self.start();115 let m = self.start();116 expr(&mut self);116 expr(&mut self);117 self.expect(EOF);117 if !self.at(EOF) {118 let m = self.start();119 while !self.at(EOF) {120 self.bump();121 }122 m.complete_error(&mut self, "unexpected tokens after end");123 }118 m.complete(&mut self, SOURCE_FILE);124 m.complete(&mut self, SOURCE_FILE);119125120 self.events126 self.events832 let m = p.start();838 let m = p.start();833 name(p);839 name(p);834 m.complete(p, EXPR_VAR)840 m.complete(p, EXPR_VAR)835 } else if p.at(INTRINSIC_THIS_FILE) {841 } else if p.at(T![if]) {836 let m = p.start();837 p.bump();838 m.complete(p, EXPR_INTRINSIC_THIS_FILE)839 } else if p.at(INTRINSIC_ID) {840 let m = p.start();841 p.bump();842 m.complete(p, EXPR_INTRINSIC_ID)843 } else if p.at(INTRINSIC) {844 let m = p.start();845 p.bump();846 p.expect(T!['(']);847 name(p);848 p.expect(T![')']);849 m.complete(p, EXPR_INTRINSIC)850 } else if p.at(T![if]) {851 let m = p.start();842 let m = p.start();852 p.bump();843 p.bump();853 expr(p);844 expr(p);crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__continue_after_total_failure.snapdiffbeforeafterbothno changes
crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_lhs.snapdiffbeforeafterboth2source: crates/jrsonnet-rowan-parser/src/tests.rs2source: crates/jrsonnet-rowan-parser/src/tests.rs3expression: "+ 2\n"3expression: "+ 2\n"4---4---5SOURCE_FILE@0..25SOURCE_FILE@0..46 ERROR_MISSING_TOKEN@0..06 ERROR_MISSING_TOKEN@0..07 ERROR_UNEXPECTED_TOKEN@0..17 ERROR_CUSTOM@0..38 PLUS@0..1 "+"8 PLUS@0..1 "+"9 WHITESPACE@1..2 " "9 WHITESPACE@1..2 " "10 FLOAT@2..3 "2"11 WHITESPACE@3..4 "\n"10===12===11LocatedSyntaxError { error: Missing { expected: Named("expression") }, range: 0..0 }13LocatedSyntaxError { error: Missing { expected: Named("expression") }, range: 0..0 }12LocatedSyntaxError { error: Unexpected { expected: Unnamed(SyntaxKindSet([EOF])), found: PLUS }, range: 0..1 }14LocatedSyntaxError { error: Custom { error: "unexpected tokens after end" }, range: 0..3 }13===15===14 x syntax error16 x syntax error15 ,----17 ,----16 1 | + 218 1 | + 217 : ^|19 : ^^|18 : |`-- expected EOF, found PLUS20 : | `-- unexpected tokens after end19 : `-- missing expression21 : `-- missing expression20 `----22 `----2123crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_operator.snapdiffbeforeafterboth6 EXPR_NUMBER@0..16 EXPR_NUMBER@0..17 FLOAT@0..1 "2"7 FLOAT@0..1 "2"8 WHITESPACE@1..2 " "8 WHITESPACE@1..2 " "9 ERROR_UNEXPECTED_TOKEN@2..39 ERROR_CUSTOM@2..310 FLOAT@2..3 "2"10 FLOAT@2..3 "2"11 WHITESPACE@3..4 "\n"11 WHITESPACE@3..4 "\n"12===12===13LocatedSyntaxError { error: Unexpected { expected: Unnamed(SyntaxKindSet([EOF, L_BRACK, L_PAREN, L_BRACE, DOT])), found: FLOAT }, range: 2..3 }13LocatedSyntaxError { error: Custom { error: "unexpected tokens after end" }, range: 2..3 }14===14===15 x syntax error15 x syntax error16 ,----16 ,----17 1 | 2 217 1 | 2 218 : |18 : |19 : `-- expected EOF, L_BRACK, L_PAREN, L_BRACE or DOT, found FLOAT19 : `-- unexpected tokens after end20 `----20 `----2121crates/jrsonnet-rowan-parser/src/tests.rsdiffbeforeafterboth229 }229 }230 "#230 "#231232 continue_after_total_failure => r#"233 local intr = $intrinsic(test);234235 local a = 1, b = 2, c = a + b;236237 [c]238 "#231);239);232240233#[test]241#[test]crates/jrsonnet-rowan-parser/src/token_set.rsdiffbeforeafterboth27 SyntaxKindSet(self.0 | mask(kind))27 SyntaxKindSet(self.0 | mask(kind))28 }28 }292930 pub const fn contains(&self, kind: SyntaxKind) -> bool {30 pub fn contains(&self, kind: SyntaxKind) -> bool {31 if !is_token(kind) {32 return false;33 }31 self.0 & mask(kind) != 034 self.0 & mask(kind) != 032 }35 }33}36}74}77}757876const fn mask(kind: SyntaxKind) -> u128 {79const fn mask(kind: SyntaxKind) -> u128 {80 if kind as u32 > 128 {81 panic!("mask for not a token kind")82 }77 1u128 << (kind as u128)83 1u128 << (kind as u128)78}84}798595 "can't keep KindSet as bitset"101 "can't keep KindSet as bitset"96 );102 );97}103}104fn is_token(kind: SyntaxKind) -> bool {105 (kind as u32) < 127106}98107xtask/src/sourcegen/kinds.rsdiffbeforeafterboth247 "$" => "DOLLAR";247 "$" => "DOLLAR";248 "=" => "ASSIGN";248 "=" => "ASSIGN";249 "?" => "QUESTION_MARK";249 "?" => "QUESTION_MARK";250 "$intrinsicThisFile" => "INTRINSIC_THIS_FILE";251 "$intrinsicId" => "INTRINSIC_ID";252 "$intrinsic" => "INTRINSIC";253 // Literals250 // Literals254 lit("FLOAT") => r"(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?";251 lit("FLOAT") => r"(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?";255 error("FLOAT_JUNK_AFTER_POINT") => r"(?:0|[1-9][0-9]*)\.[^0-9]";252 error("FLOAT_JUNK_AFTER_POINT") => r"(?:0|[1-9][0-9]*)\.[^0-9]";