difftreelog
refactor(rowan-parser) remove intrinsic syntax
in: master
13 files changed
cmds/jrsonnet-fmt/src/children.rsdiffbeforeafterboth--- a/cmds/jrsonnet-fmt/src/children.rs
+++ b/cmds/jrsonnet-fmt/src/children.rs
@@ -3,13 +3,11 @@
use std::{fmt::Debug, mem};
use jrsonnet_rowan_parser::{
- nodes::{Trivia, TriviaKind},
- AstNode, AstToken, SyntaxElement,
- SyntaxKind::*,
- SyntaxNode, TS,
+ nodes::{CustomError, Trivia, TriviaKind},
+ AstNode, AstToken, SyntaxElement, SyntaxNode, TS,
};
-pub type ChildTrivia = Vec<Trivia>;
+pub type ChildTrivia = Vec<Result<Trivia, String>>;
/// Node should have no non-trivia tokens before element
pub fn trivia_before(node: SyntaxNode, end: Option<&SyntaxElement>) -> ChildTrivia {
@@ -20,12 +18,14 @@
}
if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {
- out.push(trivia);
+ out.push(Ok(trivia));
+ } else if CustomError::can_cast(item.kind()) {
+ out.push(Err(item.to_string()));
} else if end.is_none() {
break;
} else {
assert!(
- TS![, ;].contains(item.kind()) || item.kind() == ERROR,
+ TS![, ;].contains(item.kind()),
"silently eaten token: {:?}",
item.kind()
)
@@ -46,10 +46,12 @@
let mut out = Vec::new();
for item in iter {
if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {
- out.push(trivia);
+ out.push(Ok(trivia));
+ } else if CustomError::can_cast(item.kind()) {
+ out.push(Err(item.to_string()))
} else {
assert!(
- TS![, ;].contains(item.kind()) || item.kind() == ERROR,
+ TS![, ;].contains(item.kind()),
"silently eaten token: {:?}",
item.kind()
)
@@ -74,12 +76,14 @@
let mut out = Vec::new();
for item in iter.take_while(|i| Some(i) != end) {
if let Some(trivia) = item.as_token().cloned().and_then(Trivia::cast) {
- out.push(trivia);
+ out.push(Ok(trivia));
+ } else if CustomError::can_cast(item.kind()) {
+ out.push(Err(item.to_string()))
} else if loose {
break;
} else {
assert!(
- TS![, ;].contains(item.kind()) || item.kind() == ERROR,
+ TS![, ;].contains(item.kind()),
"silently eaten token: {:?}",
item.kind()
)
@@ -120,11 +124,16 @@
fn count_newlines_before(tt: &ChildTrivia) -> usize {
let mut nl_count = 0;
for t in tt {
- match t.kind() {
- TriviaKind::Whitespace => {
- nl_count += t.text().bytes().filter(|b| *b == b'\n').count();
+ match t {
+ Ok(t) => match t.kind() {
+ TriviaKind::Whitespace => {
+ nl_count += t.text().bytes().filter(|b| *b == b'\n').count();
+ }
+ _ => break,
+ },
+ Err(_) => {
+ nl_count += 1;
}
- _ => break,
}
}
nl_count
@@ -132,19 +141,22 @@
fn count_newlines_after(tt: &ChildTrivia) -> usize {
let mut nl_count = 0;
for t in tt.iter().rev() {
- match t.kind() {
- TriviaKind::Whitespace => {
- nl_count += t.text().bytes().filter(|b| *b == b'\n').count();
- }
- TriviaKind::SingleLineHashComment => {
- nl_count += 1;
- break;
- }
- TriviaKind::SingleLineSlashComment => {
- nl_count += 1;
- break;
- }
- _ => {}
+ match t {
+ Ok(t) => match t.kind() {
+ TriviaKind::Whitespace => {
+ nl_count += t.text().bytes().filter(|b| *b == b'\n').count();
+ }
+ TriviaKind::SingleLineHashComment => {
+ nl_count += 1;
+ break;
+ }
+ TriviaKind::SingleLineSlashComment => {
+ nl_count += 1;
+ break;
+ }
+ _ => {}
+ },
+ Err(_) => nl_count += 1,
}
}
nl_count
@@ -187,16 +199,18 @@
|| current_child.is_none()
|| trivia.text().contains('\n') && !is_single_line_comment
{
- next.push(trivia.clone());
+ next.push(Ok(trivia.clone()));
started_next = true;
} else {
let cur = current_child.as_mut().expect("checked not none");
- cur.inline_trivia.push(trivia);
+ cur.inline_trivia.push(Ok(trivia));
if is_single_line_comment {
started_next = true;
}
}
had_some = true;
+ } else if CustomError::can_cast(item.kind()) {
+ next.push(Err(item.to_string()))
} else if loose {
if had_some {
break;
@@ -204,7 +218,7 @@
started_next = true;
} else {
assert!(
- TS![, ;].contains(item.kind()) || item.kind() == ERROR,
+ TS![, ;].contains(item.kind()),
"silently eaten token: {:?}",
item.kind()
)
cmds/jrsonnet-fmt/src/comments.rsdiffbeforeafterboth--- a/cmds/jrsonnet-fmt/src/comments.rs
+++ b/cmds/jrsonnet-fmt/src/comments.rs
@@ -17,6 +17,24 @@
let mut pi = p!(new:);
for c in comments {
+ let Ok(c) = c else {
+ let mut text = c.as_ref().unwrap_err() as &str;
+ while !text.is_empty() {
+ let pos = text.find(|c| c == '\n' || c == '\t').unwrap_or(text.len());
+ let sliced = &text[..pos];
+ p!(pi: string(sliced.to_string()));
+ text = &text[pos..];
+ if! text.is_empty(){
+ match text.as_bytes()[0] {
+ b'\n' => p!(pi: nl),
+ b'\t' => p!(pi: tab),
+ _ => unreachable!()
+ }
+ text = &text[1..];
+ }
+ }
+ continue;
+ };
match c.kind() {
TriviaKind::Whitespace => {}
TriviaKind::MultiLineComment => {
@@ -37,7 +55,7 @@
let mut immediate_start = true;
let mut lines = text
.split('\n')
- .map(|l| l.trim_end())
+ .map(|l| l.trim_end().to_string())
.skip_while(|l| {
if l.is_empty() {
immediate_start = false;
@@ -51,7 +69,7 @@
lines.pop();
}
if lines.len() == 1 && !doc {
- p!(pi: str("/* ") str(lines[0].trim()) str(" */") nl)
+ p!(pi: str("/* ") string(lines[0].trim().to_string()) str(" */") nl)
} else if !lines.is_empty() {
fn common_ws_prefix<'a>(a: &'a str, b: &str) -> &'a str {
let offset = a
@@ -62,17 +80,18 @@
&a[..offset]
}
// First line is not empty, extract ws prefix of it
- let mut common_ws_padding = if immediate_start && lines.len() > 1 {
- common_ws_prefix(lines[1], lines[1])
+ let mut common_ws_padding = (if immediate_start && lines.len() > 1 {
+ common_ws_prefix(&lines[1], &lines[1])
} else {
- common_ws_prefix(lines[0], lines[0])
- };
+ common_ws_prefix(&lines[0], &lines[0])
+ })
+ .to_string();
for line in lines
.iter()
.skip(if immediate_start { 2 } else { 1 })
.filter(|l| !l.is_empty())
{
- common_ws_padding = common_ws_prefix(common_ws_padding, line);
+ common_ws_padding = common_ws_prefix(&common_ws_padding, line).to_string();
}
for line in lines
.iter_mut()
@@ -80,8 +99,9 @@
.filter(|l| !l.is_empty())
{
*line = line
- .strip_prefix(common_ws_padding)
- .expect("all non-empty lines start with this padding");
+ .strip_prefix(&common_ws_padding)
+ .expect("all non-empty lines start with this padding")
+ .to_string();
}
p!(pi: str("/*"));
@@ -105,9 +125,9 @@
} else {
p!(pi: tab);
}
- line = new_line;
+ line = new_line.to_string();
}
- p!(pi: str(line) nl)
+ p!(pi: string(line.to_string()) nl)
}
}
if doc {
@@ -136,7 +156,7 @@
if matches!(loc, CommentLocation::ItemInline) {
p!(pi: str(" "))
}
- p!(pi: str("# ") str(c.text().strip_prefix('#').expect("hash comment starts with #").trim()));
+ p!(pi: str("# ") string(c.text().strip_prefix('#').expect("hash comment starts with #").trim().to_string()));
if !matches!(loc, CommentLocation::ItemInline) {
p!(pi: nl)
}
@@ -145,14 +165,14 @@
if matches!(loc, CommentLocation::ItemInline) {
p!(pi: str(" "))
}
- p!(pi: str("// ") str(c.text().strip_prefix("//").expect("comment starts with //").trim()));
+ p!(pi: str("// ") string(c.text().strip_prefix("//").expect("comment starts with //").trim().to_string()));
if !matches!(loc, CommentLocation::ItemInline) {
p!(pi: nl)
}
}
// Garbage in - garbage out
TriviaKind::ErrorCommentTooShort => p!(pi: str("/*/")),
- TriviaKind::ErrorCommentUnterminated => p!(pi: str(c.text())),
+ TriviaKind::ErrorCommentUnterminated => p!(pi: string(c.text().to_string())),
}
}
cmds/jrsonnet-fmt/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet-fmt/src/main.rs
+++ b/cmds/jrsonnet-fmt/src/main.rs
@@ -5,10 +5,11 @@
use jrsonnet_rowan_parser::{
nodes::{
ArgsDesc, Assertion, BinaryOperator, Bind, CompSpec, Destruct, DestructArrayPart,
- DestructRest, Expr, Field, FieldName, ForSpec, IfSpec, ImportKind, LhsExpr, Literal,
- Member, Name, Number, ObjBody, ObjLocal, ParamsDesc, SliceDesc, SourceFile, Text,
- UnaryOperator,
+ DestructRest, Expr, FieldName, ForSpec, IfSpec, ImportKind, LhsExpr, Literal, Member, Name,
+ Number, ObjBody, ObjLocal, ParamsDesc, SliceDesc, SourceFile, Text, UnaryOperator,
+ Visibility, VisibilityKind,
},
+ rowan::NodeOrToken,
AstNode, AstToken, SyntaxToken,
};
@@ -37,6 +38,10 @@
$o.push_str($e);
pi!(@s; $o: $($t)*);
}};
+ (@s; $o:ident: string($e:expr $(,)?) $($t:tt)*) => {{
+ $o.push_string($e);
+ pi!(@s; $o: $($t)*);
+ }};
(@s; $o:ident: nl $($t:tt)*) => {{
$o.push_signal(dprint_core::formatting::Signal::NewLine);
pi!(@s; $o: $($t)*);
@@ -96,8 +101,8 @@
if let Some(v) = self {
v.print()
} else {
- p!(new: str(
- &format!(
+ p!(new: string(
+ format!(
"/*missing {}*/",
type_name::<P>().replace("jrsonnet_rowan_parser::generated::nodes::", "")
),
@@ -108,18 +113,18 @@
impl Printable for SyntaxToken {
fn print(&self) -> PrintItems {
- p!(new: str(&self.to_string()))
+ p!(new: string(self.to_string()))
}
}
impl Printable for Text {
fn print(&self) -> PrintItems {
- p!(new: str(&format!("{}", self)))
+ p!(new: string(format!("{}", self)))
}
}
impl Printable for Number {
fn print(&self) -> PrintItems {
- p!(new: str(&format!("{}", self)))
+ p!(new: string(format!("{}", self)))
}
}
@@ -201,22 +206,10 @@
}
}
}
-impl Printable for Field {
+
+impl Printable for Visibility {
fn print(&self) -> PrintItems {
- let mut pi = p!(new:);
- match self {
- Field::FieldNormal(n) => {
- p!(pi: {n.field_name()});
- if n.plus_token().is_some() {
- p!(pi: str("+"));
- }
- p!(pi: str(": ") {n.expr()});
- }
- Field::FieldMethod(m) => {
- p!(pi: {m.field_name()} {m.params_desc()} str(": ") {m.expr()});
- }
- }
- pi
+ p!(new: string(self.to_string()))
}
}
@@ -282,10 +275,82 @@
}
}
+impl Printable for Member {
+ fn print(&self) -> PrintItems {
+ match self {
+ Member::MemberBindStmt(b) => {
+ p!(new: {b.obj_local()})
+ }
+ Member::MemberAssertStmt(ass) => {
+ p!(new: {ass.assertion()})
+ }
+ Member::MemberFieldNormal(n) => {
+ p!(new: {n.field_name()} if(n.plus_token().is_some())({n.plus_token()}) {n.visibility()} str(" ") {n.expr()})
+ }
+ Member::MemberFieldMethod(_) => todo!(),
+ }
+ }
+}
+
impl Printable for ObjBody {
fn print(&self) -> PrintItems {
match self {
- ObjBody::ObjBodyComp(_) => todo!(),
+ ObjBody::ObjBodyComp(l) => {
+ let mut pi = p!(new: str("{") >i nl);
+ let (children, end_comments) = children_between::<Member>(
+ l.syntax().clone(),
+ l.l_brace_token().map(Into::into).as_ref(),
+ Some(
+ &(l.comp_specs()
+ .next()
+ .expect("at least one spec is defined")
+ .syntax()
+ .clone())
+ .into(),
+ ),
+ );
+ for mem in children.into_iter() {
+ if mem.should_start_with_newline {
+ p!(pi: nl);
+ }
+ p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));
+ p!(pi: {mem.value} str(","));
+ p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));
+ p!(pi: nl)
+ }
+
+ if end_comments.should_start_with_newline {
+ p!(pi: nl);
+ }
+ p!(pi: items(format_comments(&end_comments.trivia, CommentLocation::EndOfItems)));
+
+ let (compspecs, end_comments) = children_between::<CompSpec>(
+ l.syntax().clone(),
+ l.member_comps()
+ .last()
+ .map(|m| m.syntax().clone())
+ .map(Into::into)
+ .or_else(|| l.l_brace_token().map(Into::into))
+ .as_ref(),
+ l.r_brace_token().map(Into::into).as_ref(),
+ );
+ for mem in compspecs.into_iter() {
+ if mem.should_start_with_newline {
+ p!(pi: nl);
+ }
+ p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));
+ p!(pi: {mem.value});
+ p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));
+ p!(pi: nl)
+ }
+ if end_comments.should_start_with_newline {
+ p!(pi: nl);
+ }
+ p!(pi: items(format_comments(&end_comments.trivia, CommentLocation::EndOfItems)));
+
+ p!(pi: <i str("}"));
+ pi
+ }
ObjBody::ObjBodyMemberList(l) => {
let mut pi = p!(new: str("{") >i nl);
let (children, end_comments) = children_between::<Member>(
@@ -298,18 +363,7 @@
p!(pi: nl);
}
p!(pi: items(format_comments(&mem.before_trivia, CommentLocation::AboveItem)));
- match mem.value {
- Member::MemberBindStmt(b) => {
- p!(pi: {b.obj_local()})
- }
- Member::MemberAssertStmt(ass) => {
- p!(pi: {ass.assertion()})
- }
- Member::MemberField(f) => {
- p!(pi: {f.field()})
- }
- }
- p!(pi: str(","));
+ p!(pi: {mem.value} str(","));
p!(pi: items(format_comments(&mem.inline_trivia, CommentLocation::ItemInline)));
p!(pi: nl)
}
@@ -326,12 +380,12 @@
}
impl Printable for UnaryOperator {
fn print(&self) -> PrintItems {
- p!(new: str(self.text()))
+ p!(new: string(self.text().to_string()))
}
}
impl Printable for BinaryOperator {
fn print(&self) -> PrintItems {
- p!(new: str(self.text()))
+ p!(new: string(self.text().to_string()))
}
}
impl Printable for Bind {
@@ -348,12 +402,12 @@
}
impl Printable for Literal {
fn print(&self) -> PrintItems {
- p!(new: str(&self.syntax().to_string()))
+ p!(new: string(self.syntax().to_string()))
}
}
impl Printable for ImportKind {
fn print(&self) -> PrintItems {
- p!(new: str(&self.syntax().to_string()))
+ p!(new: string(self.syntax().to_string()))
}
}
impl Printable for LhsExpr {
@@ -406,9 +460,6 @@
Expr::ExprParened(p) => {
p!(new: str("(") {p.expr()} str(")"))
}
- Expr::ExprIntrinsicThisFile(_) => p!(new: str("$intrinsicThisFile")),
- Expr::ExprIntrinsicId(_) => p!(new: str("$intrinsicId")),
- Expr::ExprIntrinsic(i) => p!(new: str("$intrinsic(") {i.name()} str(")")),
Expr::ExprString(s) => p!(new: {s.text()}),
Expr::ExprNumber(n) => p!(new: {n.number()}),
Expr::ExprArray(a) => {
@@ -543,10 +594,6 @@
local ocomp = {[k]: 1 for k in v};
local ? = skip;
-
- local intr = $intrinsic(test);
- local intrId = $intrinsicId;
- local intrThisFile = $intrinsicThisFile;
local ie = a[expr];
@@ -643,7 +690,13 @@
2
- else Template {}
+ else Template {},
+
+ compspecs: {
+ obj_with_no_item: {for i in [1, 2, 3]},
+ obj_with_2_items: {a:1, b:2, for i in [1,2,3]},
+ }
+
} + Template
crates/jrsonnet-rowan-parser/jsonnet.ungramdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/jsonnet.ungram
+++ b/crates/jrsonnet-rowan-parser/jsonnet.ungram
@@ -38,15 +38,6 @@
ExprLiteral =
Literal
-ExprIntrinsicThisFile =
- '$intrinsicThisFile'
-ExprIntrinsicId =
- '$intrinsicId'
-ExprIntrinsic =
- '$intrinsic'
- '('
- name:Name
- ')'
ExprString =
Text
ExprNumber =
@@ -110,9 +101,6 @@
| ExprApply
| ExprObjExtend
| ExprParened
-| ExprIntrinsicThisFile
-| ExprIntrinsicId
-| ExprIntrinsic
| ExprString
| ExprNumber
| ExprLiteral
@@ -167,14 +155,7 @@
ObjBodyComp =
'{'
- pre:ObjLocalPostComma*
- '['
- key:LhsExpr
- ']'
- '+'?
- ':'
- value:Expr
- post:ObjLocalPreComma*
+ (MemberComp (',' MemberComp)* ','?)?
CompSpec*
'}'
ObjBodyMemberList =
@@ -185,13 +166,6 @@
ObjBodyComp
| ObjBodyMemberList
-ObjLocalPostComma =
- ObjLocal
- ','
-ObjLocalPreComma =
- ','
- ObjLocal
-
MemberBindStmt = ObjLocal
MemberAssertStmt = Assertion
MemberFieldNormal =
@@ -204,6 +178,10 @@
ParamsDesc
Visibility
Expr
+MemberComp =
+ MemberBindStmt
+| MemberFieldNormal
+| MemberFieldMethod
Member =
MemberBindStmt
| MemberAssertStmt
@@ -367,7 +345,7 @@
| 'LIT_SINGLE_LINE_HASH_COMMENT!'
| 'LIT_SINGLE_LINE_SLASH_COMMENT!'
-ParsingError =
+CustomError =
'ERROR_MISSING_TOKEN!'
| 'ERROR_UNEXPECTED_TOKEN!'
| 'ERROR_CUSTOM!'
crates/jrsonnet-rowan-parser/src/generated/nodes.rsdiffbeforeafterboth1//! This is a generated file, please do not edit manually. Changes can be2//! made in codegeneration that lives in `xtask` top-level dir.34#![allow(non_snake_case, clippy::match_like_matches_macro)]5use crate::{6 ast::{support, AstChildren, AstNode, AstToken},7 SyntaxKind::{self, *},8 SyntaxNode, SyntaxToken, T,9};1011#[derive(Debug, Clone, PartialEq, Eq, Hash)]12pub struct SourceFile {13 pub(crate) syntax: SyntaxNode,14}15impl SourceFile {16 pub fn expr(&self) -> Option<Expr> {17 support::child(&self.syntax)18 }19}2021#[derive(Debug, Clone, PartialEq, Eq, Hash)]22pub struct ExprBinary {23 pub(crate) syntax: SyntaxNode,24}25impl ExprBinary {26 pub fn lhs(&self) -> Option<LhsExpr> {27 support::child(&self.syntax)28 }29 pub fn binary_operator(&self) -> Option<BinaryOperator> {30 support::token_child(&self.syntax)31 }32 pub fn rhs(&self) -> Option<Expr> {33 support::child(&self.syntax)34 }35}3637#[derive(Debug, Clone, PartialEq, Eq, Hash)]38pub struct LhsExpr {39 pub(crate) syntax: SyntaxNode,40}41impl LhsExpr {42 pub fn expr(&self) -> Option<Expr> {43 support::child(&self.syntax)44 }45}4647#[derive(Debug, Clone, PartialEq, Eq, Hash)]48pub struct ExprUnary {49 pub(crate) syntax: SyntaxNode,50}51impl ExprUnary {52 pub fn unary_operator(&self) -> Option<UnaryOperator> {53 support::token_child(&self.syntax)54 }55 pub fn rhs(&self) -> Option<Expr> {56 support::child(&self.syntax)57 }58}5960#[derive(Debug, Clone, PartialEq, Eq, Hash)]61pub struct ExprSlice {62 pub(crate) syntax: SyntaxNode,63}64impl ExprSlice {65 pub fn expr(&self) -> Option<Expr> {66 support::child(&self.syntax)67 }68 pub fn slice_desc(&self) -> Option<SliceDesc> {69 support::child(&self.syntax)70 }71}7273#[derive(Debug, Clone, PartialEq, Eq, Hash)]74pub struct SliceDesc {75 pub(crate) syntax: SyntaxNode,76}77impl SliceDesc {78 pub fn l_brack_token(&self) -> Option<SyntaxToken> {79 support::token(&self.syntax, T!['['])80 }81 pub fn from(&self) -> Option<Expr> {82 support::child(&self.syntax)83 }84 pub fn colon_token(&self) -> Option<SyntaxToken> {85 support::token(&self.syntax, T![:])86 }87 pub fn end(&self) -> Option<SliceDescEnd> {88 support::child(&self.syntax)89 }90 pub fn step(&self) -> Option<SliceDescStep> {91 support::child(&self.syntax)92 }93 pub fn r_brack_token(&self) -> Option<SyntaxToken> {94 support::token(&self.syntax, T![']'])95 }96}9798#[derive(Debug, Clone, PartialEq, Eq, Hash)]99pub struct ExprIndex {100 pub(crate) syntax: SyntaxNode,101}102impl ExprIndex {103 pub fn expr(&self) -> Option<Expr> {104 support::child(&self.syntax)105 }106 pub fn dot_token(&self) -> Option<SyntaxToken> {107 support::token(&self.syntax, T![.])108 }109 pub fn index(&self) -> Option<Name> {110 support::child(&self.syntax)111 }112}113114#[derive(Debug, Clone, PartialEq, Eq, Hash)]115pub struct Name {116 pub(crate) syntax: SyntaxNode,117}118impl Name {119 pub fn ident_lit(&self) -> Option<SyntaxToken> {120 support::token(&self.syntax, IDENT)121 }122}123124#[derive(Debug, Clone, PartialEq, Eq, Hash)]125pub struct ExprIndexExpr {126 pub(crate) syntax: SyntaxNode,127}128impl ExprIndexExpr {129 pub fn base(&self) -> Option<LhsExpr> {130 support::child(&self.syntax)131 }132 pub fn l_brack_token(&self) -> Option<SyntaxToken> {133 support::token(&self.syntax, T!['['])134 }135 pub fn index(&self) -> Option<Expr> {136 support::child(&self.syntax)137 }138 pub fn r_brack_token(&self) -> Option<SyntaxToken> {139 support::token(&self.syntax, T![']'])140 }141}142143#[derive(Debug, Clone, PartialEq, Eq, Hash)]144pub struct ExprApply {145 pub(crate) syntax: SyntaxNode,146}147impl ExprApply {148 pub fn expr(&self) -> Option<Expr> {149 support::child(&self.syntax)150 }151 pub fn args_desc(&self) -> Option<ArgsDesc> {152 support::child(&self.syntax)153 }154 pub fn tailstrict_kw_token(&self) -> Option<SyntaxToken> {155 support::token(&self.syntax, T![tailstrict])156 }157}158159#[derive(Debug, Clone, PartialEq, Eq, Hash)]160pub struct ArgsDesc {161 pub(crate) syntax: SyntaxNode,162}163impl ArgsDesc {164 pub fn l_paren_token(&self) -> Option<SyntaxToken> {165 support::token(&self.syntax, T!['('])166 }167 pub fn args(&self) -> AstChildren<Arg> {168 support::children(&self.syntax)169 }170 pub fn r_paren_token(&self) -> Option<SyntaxToken> {171 support::token(&self.syntax, T![')'])172 }173}174175#[derive(Debug, Clone, PartialEq, Eq, Hash)]176pub struct ExprObjExtend {177 pub(crate) syntax: SyntaxNode,178}179impl ExprObjExtend {180 pub fn lhs_expr(&self) -> Option<LhsExpr> {181 support::child(&self.syntax)182 }183 pub fn expr(&self) -> Option<Expr> {184 support::child(&self.syntax)185 }186}187188#[derive(Debug, Clone, PartialEq, Eq, Hash)]189pub struct ExprParened {190 pub(crate) syntax: SyntaxNode,191}192impl ExprParened {193 pub fn l_paren_token(&self) -> Option<SyntaxToken> {194 support::token(&self.syntax, T!['('])195 }196 pub fn expr(&self) -> Option<Expr> {197 support::child(&self.syntax)198 }199 pub fn r_paren_token(&self) -> Option<SyntaxToken> {200 support::token(&self.syntax, T![')'])201 }202}203204#[derive(Debug, Clone, PartialEq, Eq, Hash)]205pub struct ExprLiteral {206 pub(crate) syntax: SyntaxNode,207}208impl ExprLiteral {209 pub fn literal(&self) -> Option<Literal> {210 support::token_child(&self.syntax)211 }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}252253#[derive(Debug, Clone, PartialEq, Eq, Hash)]254pub struct ExprString {255 pub(crate) syntax: SyntaxNode,256}257impl ExprString {258 pub fn text(&self) -> Option<Text> {259 support::token_child(&self.syntax)260 }261}262263#[derive(Debug, Clone, PartialEq, Eq, Hash)]264pub struct ExprNumber {265 pub(crate) syntax: SyntaxNode,266}267impl ExprNumber {268 pub fn number(&self) -> Option<Number> {269 support::token_child(&self.syntax)270 }271}272273#[derive(Debug, Clone, PartialEq, Eq, Hash)]274pub struct ExprArray {275 pub(crate) syntax: SyntaxNode,276}277impl ExprArray {278 pub fn l_brack_token(&self) -> Option<SyntaxToken> {279 support::token(&self.syntax, T!['['])280 }281 pub fn exprs(&self) -> AstChildren<Expr> {282 support::children(&self.syntax)283 }284 pub fn r_brack_token(&self) -> Option<SyntaxToken> {285 support::token(&self.syntax, T![']'])286 }287}288289#[derive(Debug, Clone, PartialEq, Eq, Hash)]290pub struct ExprObject {291 pub(crate) syntax: SyntaxNode,292}293impl ExprObject {294 pub fn obj_body(&self) -> Option<ObjBody> {295 support::child(&self.syntax)296 }297}298299#[derive(Debug, Clone, PartialEq, Eq, Hash)]300pub struct ExprArrayComp {301 pub(crate) syntax: SyntaxNode,302}303impl ExprArrayComp {304 pub fn l_brack_token(&self) -> Option<SyntaxToken> {305 support::token(&self.syntax, T!['['])306 }307 pub fn expr(&self) -> Option<Expr> {308 support::child(&self.syntax)309 }310 pub fn comma_token(&self) -> Option<SyntaxToken> {311 support::token(&self.syntax, T![,])312 }313 pub fn comp_specs(&self) -> AstChildren<CompSpec> {314 support::children(&self.syntax)315 }316 pub fn r_brack_token(&self) -> Option<SyntaxToken> {317 support::token(&self.syntax, T![']'])318 }319}320321#[derive(Debug, Clone, PartialEq, Eq, Hash)]322pub struct ExprImport {323 pub(crate) syntax: SyntaxNode,324}325impl ExprImport {326 pub fn import_kind(&self) -> Option<ImportKind> {327 support::token_child(&self.syntax)328 }329 pub fn text(&self) -> Option<Text> {330 support::token_child(&self.syntax)331 }332}333334#[derive(Debug, Clone, PartialEq, Eq, Hash)]335pub struct ExprVar {336 pub(crate) syntax: SyntaxNode,337}338impl ExprVar {339 pub fn name(&self) -> Option<Name> {340 support::child(&self.syntax)341 }342}343344#[derive(Debug, Clone, PartialEq, Eq, Hash)]345pub struct ExprLocal {346 pub(crate) syntax: SyntaxNode,347}348impl ExprLocal {349 pub fn local_kw_token(&self) -> Option<SyntaxToken> {350 support::token(&self.syntax, T![local])351 }352 pub fn binds(&self) -> AstChildren<Bind> {353 support::children(&self.syntax)354 }355 pub fn semi_token(&self) -> Option<SyntaxToken> {356 support::token(&self.syntax, T![;])357 }358 pub fn expr(&self) -> Option<Expr> {359 support::child(&self.syntax)360 }361}362363#[derive(Debug, Clone, PartialEq, Eq, Hash)]364pub struct ExprIfThenElse {365 pub(crate) syntax: SyntaxNode,366}367impl ExprIfThenElse {368 pub fn if_kw_token(&self) -> Option<SyntaxToken> {369 support::token(&self.syntax, T![if])370 }371 pub fn cond(&self) -> Option<Expr> {372 support::child(&self.syntax)373 }374 pub fn then_kw_token(&self) -> Option<SyntaxToken> {375 support::token(&self.syntax, T![then])376 }377 pub fn then(&self) -> Option<TrueExpr> {378 support::child(&self.syntax)379 }380 pub fn else_kw_token(&self) -> Option<SyntaxToken> {381 support::token(&self.syntax, T![else])382 }383 pub fn else_(&self) -> Option<FalseExpr> {384 support::child(&self.syntax)385 }386}387388#[derive(Debug, Clone, PartialEq, Eq, Hash)]389pub struct TrueExpr {390 pub(crate) syntax: SyntaxNode,391}392impl TrueExpr {393 pub fn expr(&self) -> Option<Expr> {394 support::child(&self.syntax)395 }396}397398#[derive(Debug, Clone, PartialEq, Eq, Hash)]399pub struct FalseExpr {400 pub(crate) syntax: SyntaxNode,401}402impl FalseExpr {403 pub fn expr(&self) -> Option<Expr> {404 support::child(&self.syntax)405 }406}407408#[derive(Debug, Clone, PartialEq, Eq, Hash)]409pub struct ExprFunction {410 pub(crate) syntax: SyntaxNode,411}412impl ExprFunction {413 pub fn function_kw_token(&self) -> Option<SyntaxToken> {414 support::token(&self.syntax, T![function])415 }416 pub fn l_paren_token(&self) -> Option<SyntaxToken> {417 support::token(&self.syntax, T!['('])418 }419 pub fn params_desc(&self) -> Option<ParamsDesc> {420 support::child(&self.syntax)421 }422 pub fn r_paren_token(&self) -> Option<SyntaxToken> {423 support::token(&self.syntax, T![')'])424 }425 pub fn expr(&self) -> Option<Expr> {426 support::child(&self.syntax)427 }428}429430#[derive(Debug, Clone, PartialEq, Eq, Hash)]431pub struct ParamsDesc {432 pub(crate) syntax: SyntaxNode,433}434impl ParamsDesc {435 pub fn l_paren_token(&self) -> Option<SyntaxToken> {436 support::token(&self.syntax, T!['('])437 }438 pub fn params(&self) -> AstChildren<Param> {439 support::children(&self.syntax)440 }441 pub fn r_paren_token(&self) -> Option<SyntaxToken> {442 support::token(&self.syntax, T![')'])443 }444}445446#[derive(Debug, Clone, PartialEq, Eq, Hash)]447pub struct ExprAssert {448 pub(crate) syntax: SyntaxNode,449}450impl ExprAssert {451 pub fn assertion(&self) -> Option<Assertion> {452 support::child(&self.syntax)453 }454 pub fn semi_token(&self) -> Option<SyntaxToken> {455 support::token(&self.syntax, T![;])456 }457 pub fn expr(&self) -> Option<Expr> {458 support::child(&self.syntax)459 }460}461462#[derive(Debug, Clone, PartialEq, Eq, Hash)]463pub struct Assertion {464 pub(crate) syntax: SyntaxNode,465}466impl Assertion {467 pub fn assert_kw_token(&self) -> Option<SyntaxToken> {468 support::token(&self.syntax, T![assert])469 }470 pub fn condition(&self) -> Option<LhsExpr> {471 support::child(&self.syntax)472 }473 pub fn colon_token(&self) -> Option<SyntaxToken> {474 support::token(&self.syntax, T![:])475 }476 pub fn message(&self) -> Option<Expr> {477 support::child(&self.syntax)478 }479}480481#[derive(Debug, Clone, PartialEq, Eq, Hash)]482pub struct ExprError {483 pub(crate) syntax: SyntaxNode,484}485impl ExprError {486 pub fn error_kw_token(&self) -> Option<SyntaxToken> {487 support::token(&self.syntax, T![error])488 }489 pub fn expr(&self) -> Option<Expr> {490 support::child(&self.syntax)491 }492}493494#[derive(Debug, Clone, PartialEq, Eq, Hash)]495pub struct SliceDescEnd {496 pub(crate) syntax: SyntaxNode,497}498impl SliceDescEnd {499 pub fn expr(&self) -> Option<Expr> {500 support::child(&self.syntax)501 }502}503504#[derive(Debug, Clone, PartialEq, Eq, Hash)]505pub struct SliceDescStep {506 pub(crate) syntax: SyntaxNode,507}508impl SliceDescStep {509 pub fn expr(&self) -> Option<Expr> {510 support::child(&self.syntax)511 }512}513514#[derive(Debug, Clone, PartialEq, Eq, Hash)]515pub struct Arg {516 pub(crate) syntax: SyntaxNode,517}518impl Arg {519 pub fn name(&self) -> Option<Name> {520 support::child(&self.syntax)521 }522 pub fn assign_token(&self) -> Option<SyntaxToken> {523 support::token(&self.syntax, T![=])524 }525 pub fn expr(&self) -> Option<Expr> {526 support::child(&self.syntax)527 }528}529530#[derive(Debug, Clone, PartialEq, Eq, Hash)]531pub struct ObjBodyComp {532 pub(crate) syntax: SyntaxNode,533}534impl ObjBodyComp {535 pub fn l_brace_token(&self) -> Option<SyntaxToken> {536 support::token(&self.syntax, T!['{'])537 }538 pub fn pre(&self) -> AstChildren<ObjLocalPostComma> {539 support::children(&self.syntax)540 }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> {563 support::children(&self.syntax)564 }565 pub fn r_brace_token(&self) -> Option<SyntaxToken> {566 support::token(&self.syntax, T!['}'])567 }568}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}595596#[derive(Debug, Clone, PartialEq, Eq, Hash)]597pub struct ObjBodyMemberList {598 pub(crate) syntax: SyntaxNode,599}600impl ObjBodyMemberList {601 pub fn l_brace_token(&self) -> Option<SyntaxToken> {602 support::token(&self.syntax, T!['{'])603 }604 pub fn members(&self) -> AstChildren<Member> {605 support::children(&self.syntax)606 }607 pub fn r_brace_token(&self) -> Option<SyntaxToken> {608 support::token(&self.syntax, T!['}'])609 }610}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}624625#[derive(Debug, Clone, PartialEq, Eq, Hash)]626pub struct MemberBindStmt {627 pub(crate) syntax: SyntaxNode,628}629impl MemberBindStmt {630 pub fn obj_local(&self) -> Option<ObjLocal> {631 support::child(&self.syntax)632 }633}634635#[derive(Debug, Clone, PartialEq, Eq, Hash)]636pub struct MemberAssertStmt {637 pub(crate) syntax: SyntaxNode,638}639impl MemberAssertStmt {640 pub fn assertion(&self) -> Option<Assertion> {641 support::child(&self.syntax)642 }643}644645#[derive(Debug, Clone, PartialEq, Eq, Hash)]646pub struct MemberFieldNormal {647 pub(crate) syntax: SyntaxNode,648}649impl MemberFieldNormal {650 pub fn field_name(&self) -> Option<FieldName> {651 support::child(&self.syntax)652 }653 pub fn plus_token(&self) -> Option<SyntaxToken> {654 support::token(&self.syntax, T![+])655 }656 pub fn visibility(&self) -> Option<Visibility> {657 support::token_child(&self.syntax)658 }659 pub fn expr(&self) -> Option<Expr> {660 support::child(&self.syntax)661 }662}663664#[derive(Debug, Clone, PartialEq, Eq, Hash)]665pub struct MemberFieldMethod {666 pub(crate) syntax: SyntaxNode,667}668impl MemberFieldMethod {669 pub fn field_name(&self) -> Option<FieldName> {670 support::child(&self.syntax)671 }672 pub fn params_desc(&self) -> Option<ParamsDesc> {673 support::child(&self.syntax)674 }675 pub fn visibility(&self) -> Option<Visibility> {676 support::token_child(&self.syntax)677 }678 pub fn expr(&self) -> Option<Expr> {679 support::child(&self.syntax)680 }681}682683#[derive(Debug, Clone, PartialEq, Eq, Hash)]684pub struct FieldNameFixed {685 pub(crate) syntax: SyntaxNode,686}687impl FieldNameFixed {688 pub fn id(&self) -> Option<Name> {689 support::child(&self.syntax)690 }691 pub fn text(&self) -> Option<Text> {692 support::token_child(&self.syntax)693 }694}695696#[derive(Debug, Clone, PartialEq, Eq, Hash)]697pub struct FieldNameDynamic {698 pub(crate) syntax: SyntaxNode,699}700impl FieldNameDynamic {701 pub fn l_brack_token(&self) -> Option<SyntaxToken> {702 support::token(&self.syntax, T!['['])703 }704 pub fn expr(&self) -> Option<Expr> {705 support::child(&self.syntax)706 }707 pub fn r_brack_token(&self) -> Option<SyntaxToken> {708 support::token(&self.syntax, T![']'])709 }710}711712#[derive(Debug, Clone, PartialEq, Eq, Hash)]713pub struct ForSpec {714 pub(crate) syntax: SyntaxNode,715}716impl ForSpec {717 pub fn for_kw_token(&self) -> Option<SyntaxToken> {718 support::token(&self.syntax, T![for])719 }720 pub fn bind(&self) -> Option<Name> {721 support::child(&self.syntax)722 }723 pub fn in_kw_token(&self) -> Option<SyntaxToken> {724 support::token(&self.syntax, T![in])725 }726 pub fn expr(&self) -> Option<Expr> {727 support::child(&self.syntax)728 }729}730731#[derive(Debug, Clone, PartialEq, Eq, Hash)]732pub struct IfSpec {733 pub(crate) syntax: SyntaxNode,734}735impl IfSpec {736 pub fn if_kw_token(&self) -> Option<SyntaxToken> {737 support::token(&self.syntax, T![if])738 }739 pub fn expr(&self) -> Option<Expr> {740 support::child(&self.syntax)741 }742}743744#[derive(Debug, Clone, PartialEq, Eq, Hash)]745pub struct BindDestruct {746 pub(crate) syntax: SyntaxNode,747}748impl BindDestruct {749 pub fn into(&self) -> Option<Destruct> {750 support::child(&self.syntax)751 }752 pub fn assign_token(&self) -> Option<SyntaxToken> {753 support::token(&self.syntax, T![=])754 }755 pub fn value(&self) -> Option<Expr> {756 support::child(&self.syntax)757 }758}759760#[derive(Debug, Clone, PartialEq, Eq, Hash)]761pub struct BindFunction {762 pub(crate) syntax: SyntaxNode,763}764impl BindFunction {765 pub fn name(&self) -> Option<Name> {766 support::child(&self.syntax)767 }768 pub fn params(&self) -> Option<ParamsDesc> {769 support::child(&self.syntax)770 }771 pub fn assign_token(&self) -> Option<SyntaxToken> {772 support::token(&self.syntax, T![=])773 }774 pub fn value(&self) -> Option<Expr> {775 support::child(&self.syntax)776 }777}778779#[derive(Debug, Clone, PartialEq, Eq, Hash)]780pub struct Param {781 pub(crate) syntax: SyntaxNode,782}783impl Param {784 pub fn destruct(&self) -> Option<Destruct> {785 support::child(&self.syntax)786 }787 pub fn assign_token(&self) -> Option<SyntaxToken> {788 support::token(&self.syntax, T![=])789 }790 pub fn expr(&self) -> Option<Expr> {791 support::child(&self.syntax)792 }793}794795#[derive(Debug, Clone, PartialEq, Eq, Hash)]796pub struct DestructFull {797 pub(crate) syntax: SyntaxNode,798}799impl DestructFull {800 pub fn name(&self) -> Option<Name> {801 support::child(&self.syntax)802 }803}804805#[derive(Debug, Clone, PartialEq, Eq, Hash)]806pub struct DestructSkip {807 pub(crate) syntax: SyntaxNode,808}809impl DestructSkip {810 pub fn question_mark_token(&self) -> Option<SyntaxToken> {811 support::token(&self.syntax, T![?])812 }813}814815#[derive(Debug, Clone, PartialEq, Eq, Hash)]816pub struct DestructArray {817 pub(crate) syntax: SyntaxNode,818}819impl DestructArray {820 pub fn l_brack_token(&self) -> Option<SyntaxToken> {821 support::token(&self.syntax, T!['['])822 }823 pub fn destruct_array_parts(&self) -> AstChildren<DestructArrayPart> {824 support::children(&self.syntax)825 }826 pub fn r_brack_token(&self) -> Option<SyntaxToken> {827 support::token(&self.syntax, T![']'])828 }829}830831#[derive(Debug, Clone, PartialEq, Eq, Hash)]832pub struct DestructObject {833 pub(crate) syntax: SyntaxNode,834}835impl DestructObject {836 pub fn l_brace_token(&self) -> Option<SyntaxToken> {837 support::token(&self.syntax, T!['{'])838 }839 pub fn destruct_object_fields(&self) -> AstChildren<DestructObjectField> {840 support::children(&self.syntax)841 }842 pub fn destruct_rest(&self) -> Option<DestructRest> {843 support::child(&self.syntax)844 }845 pub fn comma_token(&self) -> Option<SyntaxToken> {846 support::token(&self.syntax, T![,])847 }848 pub fn r_brace_token(&self) -> Option<SyntaxToken> {849 support::token(&self.syntax, T!['}'])850 }851}852853#[derive(Debug, Clone, PartialEq, Eq, Hash)]854pub struct DestructObjectField {855 pub(crate) syntax: SyntaxNode,856}857impl DestructObjectField {858 pub fn field(&self) -> Option<Name> {859 support::child(&self.syntax)860 }861 pub fn colon_token(&self) -> Option<SyntaxToken> {862 support::token(&self.syntax, T![:])863 }864 pub fn destruct(&self) -> Option<Destruct> {865 support::child(&self.syntax)866 }867 pub fn assign_token(&self) -> Option<SyntaxToken> {868 support::token(&self.syntax, T![=])869 }870 pub fn expr(&self) -> Option<Expr> {871 support::child(&self.syntax)872 }873}874875#[derive(Debug, Clone, PartialEq, Eq, Hash)]876pub struct DestructRest {877 pub(crate) syntax: SyntaxNode,878}879impl DestructRest {880 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> {881 support::token(&self.syntax, T![...])882 }883 pub fn into(&self) -> Option<Name> {884 support::child(&self.syntax)885 }886}887888#[derive(Debug, Clone, PartialEq, Eq, Hash)]889pub struct DestructArrayElement {890 pub(crate) syntax: SyntaxNode,891}892impl DestructArrayElement {893 pub fn destruct(&self) -> Option<Destruct> {894 support::child(&self.syntax)895 }896}897898#[derive(Debug, Clone, PartialEq, Eq, Hash)]899pub enum Expr {900 ExprBinary(ExprBinary),901 ExprUnary(ExprUnary),902 ExprSlice(ExprSlice),903 ExprIndex(ExprIndex),904 ExprIndexExpr(ExprIndexExpr),905 ExprApply(ExprApply),906 ExprObjExtend(ExprObjExtend),907 ExprParened(ExprParened),908 ExprIntrinsicThisFile(ExprIntrinsicThisFile),909 ExprIntrinsicId(ExprIntrinsicId),910 ExprIntrinsic(ExprIntrinsic),911 ExprString(ExprString),912 ExprNumber(ExprNumber),913 ExprLiteral(ExprLiteral),914 ExprArray(ExprArray),915 ExprObject(ExprObject),916 ExprArrayComp(ExprArrayComp),917 ExprImport(ExprImport),918 ExprVar(ExprVar),919 ExprLocal(ExprLocal),920 ExprIfThenElse(ExprIfThenElse),921 ExprFunction(ExprFunction),922 ExprAssert(ExprAssert),923 ExprError(ExprError),924}925926#[derive(Debug, Clone, PartialEq, Eq, Hash)]927pub enum ObjBody {928 ObjBodyComp(ObjBodyComp),929 ObjBodyMemberList(ObjBodyMemberList),930}931932#[derive(Debug, Clone, PartialEq, Eq, Hash)]933pub enum CompSpec {934 ForSpec(ForSpec),935 IfSpec(IfSpec),936}937938#[derive(Debug, Clone, PartialEq, Eq, Hash)]939pub enum Bind {940 BindDestruct(BindDestruct),941 BindFunction(BindFunction),942}943944#[derive(Debug, Clone, PartialEq, Eq, Hash)]945pub enum Member {946 MemberBindStmt(MemberBindStmt),947 MemberAssertStmt(MemberAssertStmt),948 MemberFieldNormal(MemberFieldNormal),949 MemberFieldMethod(MemberFieldMethod),950}951952#[derive(Debug, Clone, PartialEq, Eq, Hash)]953pub enum FieldName {954 FieldNameFixed(FieldNameFixed),955 FieldNameDynamic(FieldNameDynamic),956}957958#[derive(Debug, Clone, PartialEq, Eq, Hash)]959pub enum Destruct {960 DestructFull(DestructFull),961 DestructSkip(DestructSkip),962 DestructArray(DestructArray),963 DestructObject(DestructObject),964}965966#[derive(Debug, Clone, PartialEq, Eq, Hash)]967pub enum DestructArrayPart {968 DestructArrayElement(DestructArrayElement),969 DestructRest(DestructRest),970}971972#[derive(Debug, Clone, PartialEq, Eq, Hash)]973pub struct BinaryOperator {974 syntax: SyntaxToken,975 kind: BinaryOperatorKind,976}977978#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]979pub enum BinaryOperatorKind {980 Or,981 And,982 BitOr,983 BitXor,984 BitAnd,985 Eq,986 Ne,987 Lt,988 Gt,989 Le,990 Ge,991 InKw,992 Lhs,993 Rhs,994 Plus,995 Minus,996 Mul,997 Div,998 Modulo,999 MetaObjectApply,1000 ErrorNoOperator,1001}10021003#[derive(Debug, Clone, PartialEq, Eq, Hash)]1004pub struct UnaryOperator {1005 syntax: SyntaxToken,1006 kind: UnaryOperatorKind,1007}10081009#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1010pub enum UnaryOperatorKind {1011 Minus,1012 Not,1013 BitNot,1014}10151016#[derive(Debug, Clone, PartialEq, Eq, Hash)]1017pub struct Literal {1018 syntax: SyntaxToken,1019 kind: LiteralKind,1020}10211022#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1023pub enum LiteralKind {1024 NullKw,1025 TrueKw,1026 FalseKw,1027 SelfKw,1028 Dollar,1029 SuperKw,1030}10311032#[derive(Debug, Clone, PartialEq, Eq, Hash)]1033pub struct Text {1034 syntax: SyntaxToken,1035 kind: TextKind,1036}10371038#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1039pub enum TextKind {1040 StringDouble,1041 ErrorStringDoubleUnterminated,1042 StringSingle,1043 ErrorStringSingleUnterminated,1044 StringDoubleVerbatim,1045 ErrorStringDoubleVerbatimUnterminated,1046 StringSingleVerbatim,1047 ErrorStringSingleVerbatimUnterminated,1048 ErrorStringVerbatimMissingQuotes,1049 StringBlock,1050 ErrorStringBlockUnexpectedEnd,1051 ErrorStringBlockMissingNewLine,1052 ErrorStringBlockMissingTermination,1053 ErrorStringBlockMissingIndent,1054}10551056#[derive(Debug, Clone, PartialEq, Eq, Hash)]1057pub struct Number {1058 syntax: SyntaxToken,1059 kind: NumberKind,1060}10611062#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1063pub enum NumberKind {1064 Float,1065 ErrorFloatJunkAfterPoint,1066 ErrorFloatJunkAfterExponent,1067 ErrorFloatJunkAfterExponentSign,1068}10691070#[derive(Debug, Clone, PartialEq, Eq, Hash)]1071pub struct ImportKind {1072 syntax: SyntaxToken,1073 kind: ImportKindKind,1074}10751076#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1077pub enum ImportKindKind {1078 ImportstrKw,1079 ImportbinKw,1080 ImportKw,1081}10821083#[derive(Debug, Clone, PartialEq, Eq, Hash)]1084pub struct Visibility {1085 syntax: SyntaxToken,1086 kind: VisibilityKind,1087}10881089#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1090pub enum VisibilityKind {1091 Coloncoloncolon,1092 Coloncolon,1093 Colon,1094}10951096#[derive(Debug, Clone, PartialEq, Eq, Hash)]1097pub struct Trivia {1098 syntax: SyntaxToken,1099 kind: TriviaKind,1100}11011102#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1103pub enum TriviaKind {1104 Whitespace,1105 MultiLineComment,1106 ErrorCommentTooShort,1107 ErrorCommentUnterminated,1108 SingleLineHashComment,1109 SingleLineSlashComment,1110}11111112#[derive(Debug, Clone, PartialEq, Eq, Hash)]1113pub struct ParsingError {1114 syntax: SyntaxToken,1115 kind: ParsingErrorKind,1116}11171118#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]1119pub enum ParsingErrorKind {1120 ErrorMissingToken,1121 ErrorUnexpectedToken,1122 ErrorCustom,1123}1124impl AstNode for SourceFile {1125 fn can_cast(kind: SyntaxKind) -> bool {1126 kind == SOURCE_FILE1127 }1128 fn cast(syntax: SyntaxNode) -> Option<Self> {1129 if Self::can_cast(syntax.kind()) {1130 Some(Self { syntax })1131 } else {1132 None1133 }1134 }1135 fn syntax(&self) -> &SyntaxNode {1136 &self.syntax1137 }1138}1139impl AstNode for ExprBinary {1140 fn can_cast(kind: SyntaxKind) -> bool {1141 kind == EXPR_BINARY1142 }1143 fn cast(syntax: SyntaxNode) -> Option<Self> {1144 if Self::can_cast(syntax.kind()) {1145 Some(Self { syntax })1146 } else {1147 None1148 }1149 }1150 fn syntax(&self) -> &SyntaxNode {1151 &self.syntax1152 }1153}1154impl AstNode for LhsExpr {1155 fn can_cast(kind: SyntaxKind) -> bool {1156 kind == LHS_EXPR1157 }1158 fn cast(syntax: SyntaxNode) -> Option<Self> {1159 if Self::can_cast(syntax.kind()) {1160 Some(Self { syntax })1161 } else {1162 None1163 }1164 }1165 fn syntax(&self) -> &SyntaxNode {1166 &self.syntax1167 }1168}1169impl AstNode for ExprUnary {1170 fn can_cast(kind: SyntaxKind) -> bool {1171 kind == EXPR_UNARY1172 }1173 fn cast(syntax: SyntaxNode) -> Option<Self> {1174 if Self::can_cast(syntax.kind()) {1175 Some(Self { syntax })1176 } else {1177 None1178 }1179 }1180 fn syntax(&self) -> &SyntaxNode {1181 &self.syntax1182 }1183}1184impl AstNode for ExprSlice {1185 fn can_cast(kind: SyntaxKind) -> bool {1186 kind == EXPR_SLICE1187 }1188 fn cast(syntax: SyntaxNode) -> Option<Self> {1189 if Self::can_cast(syntax.kind()) {1190 Some(Self { syntax })1191 } else {1192 None1193 }1194 }1195 fn syntax(&self) -> &SyntaxNode {1196 &self.syntax1197 }1198}1199impl AstNode for SliceDesc {1200 fn can_cast(kind: SyntaxKind) -> bool {1201 kind == SLICE_DESC1202 }1203 fn cast(syntax: SyntaxNode) -> Option<Self> {1204 if Self::can_cast(syntax.kind()) {1205 Some(Self { syntax })1206 } else {1207 None1208 }1209 }1210 fn syntax(&self) -> &SyntaxNode {1211 &self.syntax1212 }1213}1214impl AstNode for ExprIndex {1215 fn can_cast(kind: SyntaxKind) -> bool {1216 kind == EXPR_INDEX1217 }1218 fn cast(syntax: SyntaxNode) -> Option<Self> {1219 if Self::can_cast(syntax.kind()) {1220 Some(Self { syntax })1221 } else {1222 None1223 }1224 }1225 fn syntax(&self) -> &SyntaxNode {1226 &self.syntax1227 }1228}1229impl AstNode for Name {1230 fn can_cast(kind: SyntaxKind) -> bool {1231 kind == NAME1232 }1233 fn cast(syntax: SyntaxNode) -> Option<Self> {1234 if Self::can_cast(syntax.kind()) {1235 Some(Self { syntax })1236 } else {1237 None1238 }1239 }1240 fn syntax(&self) -> &SyntaxNode {1241 &self.syntax1242 }1243}1244impl AstNode for ExprIndexExpr {1245 fn can_cast(kind: SyntaxKind) -> bool {1246 kind == EXPR_INDEX_EXPR1247 }1248 fn cast(syntax: SyntaxNode) -> Option<Self> {1249 if Self::can_cast(syntax.kind()) {1250 Some(Self { syntax })1251 } else {1252 None1253 }1254 }1255 fn syntax(&self) -> &SyntaxNode {1256 &self.syntax1257 }1258}1259impl AstNode for ExprApply {1260 fn can_cast(kind: SyntaxKind) -> bool {1261 kind == EXPR_APPLY1262 }1263 fn cast(syntax: SyntaxNode) -> Option<Self> {1264 if Self::can_cast(syntax.kind()) {1265 Some(Self { syntax })1266 } else {1267 None1268 }1269 }1270 fn syntax(&self) -> &SyntaxNode {1271 &self.syntax1272 }1273}1274impl AstNode for ArgsDesc {1275 fn can_cast(kind: SyntaxKind) -> bool {1276 kind == ARGS_DESC1277 }1278 fn cast(syntax: SyntaxNode) -> Option<Self> {1279 if Self::can_cast(syntax.kind()) {1280 Some(Self { syntax })1281 } else {1282 None1283 }1284 }1285 fn syntax(&self) -> &SyntaxNode {1286 &self.syntax1287 }1288}1289impl AstNode for ExprObjExtend {1290 fn can_cast(kind: SyntaxKind) -> bool {1291 kind == EXPR_OBJ_EXTEND1292 }1293 fn cast(syntax: SyntaxNode) -> Option<Self> {1294 if Self::can_cast(syntax.kind()) {1295 Some(Self { syntax })1296 } else {1297 None1298 }1299 }1300 fn syntax(&self) -> &SyntaxNode {1301 &self.syntax1302 }1303}1304impl AstNode for ExprParened {1305 fn can_cast(kind: SyntaxKind) -> bool {1306 kind == EXPR_PARENED1307 }1308 fn cast(syntax: SyntaxNode) -> Option<Self> {1309 if Self::can_cast(syntax.kind()) {1310 Some(Self { syntax })1311 } else {1312 None1313 }1314 }1315 fn syntax(&self) -> &SyntaxNode {1316 &self.syntax1317 }1318}1319impl AstNode for ExprLiteral {1320 fn can_cast(kind: SyntaxKind) -> bool {1321 kind == EXPR_LITERAL1322 }1323 fn cast(syntax: SyntaxNode) -> Option<Self> {1324 if Self::can_cast(syntax.kind()) {1325 Some(Self { syntax })1326 } else {1327 None1328 }1329 }1330 fn syntax(&self) -> &SyntaxNode {1331 &self.syntax1332 }1333}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 {1380 fn can_cast(kind: SyntaxKind) -> bool {1381 kind == EXPR_STRING1382 }1383 fn cast(syntax: SyntaxNode) -> Option<Self> {1384 if Self::can_cast(syntax.kind()) {1385 Some(Self { syntax })1386 } else {1387 None1388 }1389 }1390 fn syntax(&self) -> &SyntaxNode {1391 &self.syntax1392 }1393}1394impl AstNode for ExprNumber {1395 fn can_cast(kind: SyntaxKind) -> bool {1396 kind == EXPR_NUMBER1397 }1398 fn cast(syntax: SyntaxNode) -> Option<Self> {1399 if Self::can_cast(syntax.kind()) {1400 Some(Self { syntax })1401 } else {1402 None1403 }1404 }1405 fn syntax(&self) -> &SyntaxNode {1406 &self.syntax1407 }1408}1409impl AstNode for ExprArray {1410 fn can_cast(kind: SyntaxKind) -> bool {1411 kind == EXPR_ARRAY1412 }1413 fn cast(syntax: SyntaxNode) -> Option<Self> {1414 if Self::can_cast(syntax.kind()) {1415 Some(Self { syntax })1416 } else {1417 None1418 }1419 }1420 fn syntax(&self) -> &SyntaxNode {1421 &self.syntax1422 }1423}1424impl AstNode for ExprObject {1425 fn can_cast(kind: SyntaxKind) -> bool {1426 kind == EXPR_OBJECT1427 }1428 fn cast(syntax: SyntaxNode) -> Option<Self> {1429 if Self::can_cast(syntax.kind()) {1430 Some(Self { syntax })1431 } else {1432 None1433 }1434 }1435 fn syntax(&self) -> &SyntaxNode {1436 &self.syntax1437 }1438}1439impl AstNode for ExprArrayComp {1440 fn can_cast(kind: SyntaxKind) -> bool {1441 kind == EXPR_ARRAY_COMP1442 }1443 fn cast(syntax: SyntaxNode) -> Option<Self> {1444 if Self::can_cast(syntax.kind()) {1445 Some(Self { syntax })1446 } else {1447 None1448 }1449 }1450 fn syntax(&self) -> &SyntaxNode {1451 &self.syntax1452 }1453}1454impl AstNode for ExprImport {1455 fn can_cast(kind: SyntaxKind) -> bool {1456 kind == EXPR_IMPORT1457 }1458 fn cast(syntax: SyntaxNode) -> Option<Self> {1459 if Self::can_cast(syntax.kind()) {1460 Some(Self { syntax })1461 } else {1462 None1463 }1464 }1465 fn syntax(&self) -> &SyntaxNode {1466 &self.syntax1467 }1468}1469impl AstNode for ExprVar {1470 fn can_cast(kind: SyntaxKind) -> bool {1471 kind == EXPR_VAR1472 }1473 fn cast(syntax: SyntaxNode) -> Option<Self> {1474 if Self::can_cast(syntax.kind()) {1475 Some(Self { syntax })1476 } else {1477 None1478 }1479 }1480 fn syntax(&self) -> &SyntaxNode {1481 &self.syntax1482 }1483}1484impl AstNode for ExprLocal {1485 fn can_cast(kind: SyntaxKind) -> bool {1486 kind == EXPR_LOCAL1487 }1488 fn cast(syntax: SyntaxNode) -> Option<Self> {1489 if Self::can_cast(syntax.kind()) {1490 Some(Self { syntax })1491 } else {1492 None1493 }1494 }1495 fn syntax(&self) -> &SyntaxNode {1496 &self.syntax1497 }1498}1499impl AstNode for ExprIfThenElse {1500 fn can_cast(kind: SyntaxKind) -> bool {1501 kind == EXPR_IF_THEN_ELSE1502 }1503 fn cast(syntax: SyntaxNode) -> Option<Self> {1504 if Self::can_cast(syntax.kind()) {1505 Some(Self { syntax })1506 } else {1507 None1508 }1509 }1510 fn syntax(&self) -> &SyntaxNode {1511 &self.syntax1512 }1513}1514impl AstNode for TrueExpr {1515 fn can_cast(kind: SyntaxKind) -> bool {1516 kind == TRUE_EXPR1517 }1518 fn cast(syntax: SyntaxNode) -> Option<Self> {1519 if Self::can_cast(syntax.kind()) {1520 Some(Self { syntax })1521 } else {1522 None1523 }1524 }1525 fn syntax(&self) -> &SyntaxNode {1526 &self.syntax1527 }1528}1529impl AstNode for FalseExpr {1530 fn can_cast(kind: SyntaxKind) -> bool {1531 kind == FALSE_EXPR1532 }1533 fn cast(syntax: SyntaxNode) -> Option<Self> {1534 if Self::can_cast(syntax.kind()) {1535 Some(Self { syntax })1536 } else {1537 None1538 }1539 }1540 fn syntax(&self) -> &SyntaxNode {1541 &self.syntax1542 }1543}1544impl AstNode for ExprFunction {1545 fn can_cast(kind: SyntaxKind) -> bool {1546 kind == EXPR_FUNCTION1547 }1548 fn cast(syntax: SyntaxNode) -> Option<Self> {1549 if Self::can_cast(syntax.kind()) {1550 Some(Self { syntax })1551 } else {1552 None1553 }1554 }1555 fn syntax(&self) -> &SyntaxNode {1556 &self.syntax1557 }1558}1559impl AstNode for ParamsDesc {1560 fn can_cast(kind: SyntaxKind) -> bool {1561 kind == PARAMS_DESC1562 }1563 fn cast(syntax: SyntaxNode) -> Option<Self> {1564 if Self::can_cast(syntax.kind()) {1565 Some(Self { syntax })1566 } else {1567 None1568 }1569 }1570 fn syntax(&self) -> &SyntaxNode {1571 &self.syntax1572 }1573}1574impl AstNode for ExprAssert {1575 fn can_cast(kind: SyntaxKind) -> bool {1576 kind == EXPR_ASSERT1577 }1578 fn cast(syntax: SyntaxNode) -> Option<Self> {1579 if Self::can_cast(syntax.kind()) {1580 Some(Self { syntax })1581 } else {1582 None1583 }1584 }1585 fn syntax(&self) -> &SyntaxNode {1586 &self.syntax1587 }1588}1589impl AstNode for Assertion {1590 fn can_cast(kind: SyntaxKind) -> bool {1591 kind == ASSERTION1592 }1593 fn cast(syntax: SyntaxNode) -> Option<Self> {1594 if Self::can_cast(syntax.kind()) {1595 Some(Self { syntax })1596 } else {1597 None1598 }1599 }1600 fn syntax(&self) -> &SyntaxNode {1601 &self.syntax1602 }1603}1604impl AstNode for ExprError {1605 fn can_cast(kind: SyntaxKind) -> bool {1606 kind == EXPR_ERROR1607 }1608 fn cast(syntax: SyntaxNode) -> Option<Self> {1609 if Self::can_cast(syntax.kind()) {1610 Some(Self { syntax })1611 } else {1612 None1613 }1614 }1615 fn syntax(&self) -> &SyntaxNode {1616 &self.syntax1617 }1618}1619impl AstNode for SliceDescEnd {1620 fn can_cast(kind: SyntaxKind) -> bool {1621 kind == SLICE_DESC_END1622 }1623 fn cast(syntax: SyntaxNode) -> Option<Self> {1624 if Self::can_cast(syntax.kind()) {1625 Some(Self { syntax })1626 } else {1627 None1628 }1629 }1630 fn syntax(&self) -> &SyntaxNode {1631 &self.syntax1632 }1633}1634impl AstNode for SliceDescStep {1635 fn can_cast(kind: SyntaxKind) -> bool {1636 kind == SLICE_DESC_STEP1637 }1638 fn cast(syntax: SyntaxNode) -> Option<Self> {1639 if Self::can_cast(syntax.kind()) {1640 Some(Self { syntax })1641 } else {1642 None1643 }1644 }1645 fn syntax(&self) -> &SyntaxNode {1646 &self.syntax1647 }1648}1649impl AstNode for Arg {1650 fn can_cast(kind: SyntaxKind) -> bool {1651 kind == ARG1652 }1653 fn cast(syntax: SyntaxNode) -> Option<Self> {1654 if Self::can_cast(syntax.kind()) {1655 Some(Self { syntax })1656 } else {1657 None1658 }1659 }1660 fn syntax(&self) -> &SyntaxNode {1661 &self.syntax1662 }1663}1664impl AstNode for ObjBodyComp {1665 fn can_cast(kind: SyntaxKind) -> bool {1666 kind == OBJ_BODY_COMP1667 }1668 fn cast(syntax: SyntaxNode) -> Option<Self> {1669 if Self::can_cast(syntax.kind()) {1670 Some(Self { syntax })1671 } else {1672 None1673 }1674 }1675 fn syntax(&self) -> &SyntaxNode {1676 &self.syntax1677 }1678}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 {1710 fn can_cast(kind: SyntaxKind) -> bool {1711 kind == OBJ_BODY_MEMBER_LIST1712 }1713 fn cast(syntax: SyntaxNode) -> Option<Self> {1714 if Self::can_cast(syntax.kind()) {1715 Some(Self { syntax })1716 } else {1717 None1718 }1719 }1720 fn syntax(&self) -> &SyntaxNode {1721 &self.syntax1722 }1723}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 {1740 fn can_cast(kind: SyntaxKind) -> bool {1741 kind == MEMBER_BIND_STMT1742 }1743 fn cast(syntax: SyntaxNode) -> Option<Self> {1744 if Self::can_cast(syntax.kind()) {1745 Some(Self { syntax })1746 } else {1747 None1748 }1749 }1750 fn syntax(&self) -> &SyntaxNode {1751 &self.syntax1752 }1753}1754impl AstNode for MemberAssertStmt {1755 fn can_cast(kind: SyntaxKind) -> bool {1756 kind == MEMBER_ASSERT_STMT1757 }1758 fn cast(syntax: SyntaxNode) -> Option<Self> {1759 if Self::can_cast(syntax.kind()) {1760 Some(Self { syntax })1761 } else {1762 None1763 }1764 }1765 fn syntax(&self) -> &SyntaxNode {1766 &self.syntax1767 }1768}1769impl AstNode for MemberFieldNormal {1770 fn can_cast(kind: SyntaxKind) -> bool {1771 kind == MEMBER_FIELD_NORMAL1772 }1773 fn cast(syntax: SyntaxNode) -> Option<Self> {1774 if Self::can_cast(syntax.kind()) {1775 Some(Self { syntax })1776 } else {1777 None1778 }1779 }1780 fn syntax(&self) -> &SyntaxNode {1781 &self.syntax1782 }1783}1784impl AstNode for MemberFieldMethod {1785 fn can_cast(kind: SyntaxKind) -> bool {1786 kind == MEMBER_FIELD_METHOD1787 }1788 fn cast(syntax: SyntaxNode) -> Option<Self> {1789 if Self::can_cast(syntax.kind()) {1790 Some(Self { syntax })1791 } else {1792 None1793 }1794 }1795 fn syntax(&self) -> &SyntaxNode {1796 &self.syntax1797 }1798}1799impl AstNode for FieldNameFixed {1800 fn can_cast(kind: SyntaxKind) -> bool {1801 kind == FIELD_NAME_FIXED1802 }1803 fn cast(syntax: SyntaxNode) -> Option<Self> {1804 if Self::can_cast(syntax.kind()) {1805 Some(Self { syntax })1806 } else {1807 None1808 }1809 }1810 fn syntax(&self) -> &SyntaxNode {1811 &self.syntax1812 }1813}1814impl AstNode for FieldNameDynamic {1815 fn can_cast(kind: SyntaxKind) -> bool {1816 kind == FIELD_NAME_DYNAMIC1817 }1818 fn cast(syntax: SyntaxNode) -> Option<Self> {1819 if Self::can_cast(syntax.kind()) {1820 Some(Self { syntax })1821 } else {1822 None1823 }1824 }1825 fn syntax(&self) -> &SyntaxNode {1826 &self.syntax1827 }1828}1829impl AstNode for ForSpec {1830 fn can_cast(kind: SyntaxKind) -> bool {1831 kind == FOR_SPEC1832 }1833 fn cast(syntax: SyntaxNode) -> Option<Self> {1834 if Self::can_cast(syntax.kind()) {1835 Some(Self { syntax })1836 } else {1837 None1838 }1839 }1840 fn syntax(&self) -> &SyntaxNode {1841 &self.syntax1842 }1843}1844impl AstNode for IfSpec {1845 fn can_cast(kind: SyntaxKind) -> bool {1846 kind == IF_SPEC1847 }1848 fn cast(syntax: SyntaxNode) -> Option<Self> {1849 if Self::can_cast(syntax.kind()) {1850 Some(Self { syntax })1851 } else {1852 None1853 }1854 }1855 fn syntax(&self) -> &SyntaxNode {1856 &self.syntax1857 }1858}1859impl AstNode for BindDestruct {1860 fn can_cast(kind: SyntaxKind) -> bool {1861 kind == BIND_DESTRUCT1862 }1863 fn cast(syntax: SyntaxNode) -> Option<Self> {1864 if Self::can_cast(syntax.kind()) {1865 Some(Self { syntax })1866 } else {1867 None1868 }1869 }1870 fn syntax(&self) -> &SyntaxNode {1871 &self.syntax1872 }1873}1874impl AstNode for BindFunction {1875 fn can_cast(kind: SyntaxKind) -> bool {1876 kind == BIND_FUNCTION1877 }1878 fn cast(syntax: SyntaxNode) -> Option<Self> {1879 if Self::can_cast(syntax.kind()) {1880 Some(Self { syntax })1881 } else {1882 None1883 }1884 }1885 fn syntax(&self) -> &SyntaxNode {1886 &self.syntax1887 }1888}1889impl AstNode for Param {1890 fn can_cast(kind: SyntaxKind) -> bool {1891 kind == PARAM1892 }1893 fn cast(syntax: SyntaxNode) -> Option<Self> {1894 if Self::can_cast(syntax.kind()) {1895 Some(Self { syntax })1896 } else {1897 None1898 }1899 }1900 fn syntax(&self) -> &SyntaxNode {1901 &self.syntax1902 }1903}1904impl AstNode for DestructFull {1905 fn can_cast(kind: SyntaxKind) -> bool {1906 kind == DESTRUCT_FULL1907 }1908 fn cast(syntax: SyntaxNode) -> Option<Self> {1909 if Self::can_cast(syntax.kind()) {1910 Some(Self { syntax })1911 } else {1912 None1913 }1914 }1915 fn syntax(&self) -> &SyntaxNode {1916 &self.syntax1917 }1918}1919impl AstNode for DestructSkip {1920 fn can_cast(kind: SyntaxKind) -> bool {1921 kind == DESTRUCT_SKIP1922 }1923 fn cast(syntax: SyntaxNode) -> Option<Self> {1924 if Self::can_cast(syntax.kind()) {1925 Some(Self { syntax })1926 } else {1927 None1928 }1929 }1930 fn syntax(&self) -> &SyntaxNode {1931 &self.syntax1932 }1933}1934impl AstNode for DestructArray {1935 fn can_cast(kind: SyntaxKind) -> bool {1936 kind == DESTRUCT_ARRAY1937 }1938 fn cast(syntax: SyntaxNode) -> Option<Self> {1939 if Self::can_cast(syntax.kind()) {1940 Some(Self { syntax })1941 } else {1942 None1943 }1944 }1945 fn syntax(&self) -> &SyntaxNode {1946 &self.syntax1947 }1948}1949impl AstNode for DestructObject {1950 fn can_cast(kind: SyntaxKind) -> bool {1951 kind == DESTRUCT_OBJECT1952 }1953 fn cast(syntax: SyntaxNode) -> Option<Self> {1954 if Self::can_cast(syntax.kind()) {1955 Some(Self { syntax })1956 } else {1957 None1958 }1959 }1960 fn syntax(&self) -> &SyntaxNode {1961 &self.syntax1962 }1963}1964impl AstNode for DestructObjectField {1965 fn can_cast(kind: SyntaxKind) -> bool {1966 kind == DESTRUCT_OBJECT_FIELD1967 }1968 fn cast(syntax: SyntaxNode) -> Option<Self> {1969 if Self::can_cast(syntax.kind()) {1970 Some(Self { syntax })1971 } else {1972 None1973 }1974 }1975 fn syntax(&self) -> &SyntaxNode {1976 &self.syntax1977 }1978}1979impl AstNode for DestructRest {1980 fn can_cast(kind: SyntaxKind) -> bool {1981 kind == DESTRUCT_REST1982 }1983 fn cast(syntax: SyntaxNode) -> Option<Self> {1984 if Self::can_cast(syntax.kind()) {1985 Some(Self { syntax })1986 } else {1987 None1988 }1989 }1990 fn syntax(&self) -> &SyntaxNode {1991 &self.syntax1992 }1993}1994impl AstNode for DestructArrayElement {1995 fn can_cast(kind: SyntaxKind) -> bool {1996 kind == DESTRUCT_ARRAY_ELEMENT1997 }1998 fn cast(syntax: SyntaxNode) -> Option<Self> {1999 if Self::can_cast(syntax.kind()) {2000 Some(Self { syntax })2001 } else {2002 None2003 }2004 }2005 fn syntax(&self) -> &SyntaxNode {2006 &self.syntax2007 }2008}2009impl From<ExprBinary> for Expr {2010 fn from(node: ExprBinary) -> Expr {2011 Expr::ExprBinary(node)2012 }2013}2014impl From<ExprUnary> for Expr {2015 fn from(node: ExprUnary) -> Expr {2016 Expr::ExprUnary(node)2017 }2018}2019impl From<ExprSlice> for Expr {2020 fn from(node: ExprSlice) -> Expr {2021 Expr::ExprSlice(node)2022 }2023}2024impl From<ExprIndex> for Expr {2025 fn from(node: ExprIndex) -> Expr {2026 Expr::ExprIndex(node)2027 }2028}2029impl From<ExprIndexExpr> for Expr {2030 fn from(node: ExprIndexExpr) -> Expr {2031 Expr::ExprIndexExpr(node)2032 }2033}2034impl From<ExprApply> for Expr {2035 fn from(node: ExprApply) -> Expr {2036 Expr::ExprApply(node)2037 }2038}2039impl From<ExprObjExtend> for Expr {2040 fn from(node: ExprObjExtend) -> Expr {2041 Expr::ExprObjExtend(node)2042 }2043}2044impl From<ExprParened> for Expr {2045 fn from(node: ExprParened) -> Expr {2046 Expr::ExprParened(node)2047 }2048}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 {2065 fn from(node: ExprString) -> Expr {2066 Expr::ExprString(node)2067 }2068}2069impl From<ExprNumber> for Expr {2070 fn from(node: ExprNumber) -> Expr {2071 Expr::ExprNumber(node)2072 }2073}2074impl From<ExprLiteral> for Expr {2075 fn from(node: ExprLiteral) -> Expr {2076 Expr::ExprLiteral(node)2077 }2078}2079impl From<ExprArray> for Expr {2080 fn from(node: ExprArray) -> Expr {2081 Expr::ExprArray(node)2082 }2083}2084impl From<ExprObject> for Expr {2085 fn from(node: ExprObject) -> Expr {2086 Expr::ExprObject(node)2087 }2088}2089impl From<ExprArrayComp> for Expr {2090 fn from(node: ExprArrayComp) -> Expr {2091 Expr::ExprArrayComp(node)2092 }2093}2094impl From<ExprImport> for Expr {2095 fn from(node: ExprImport) -> Expr {2096 Expr::ExprImport(node)2097 }2098}2099impl From<ExprVar> for Expr {2100 fn from(node: ExprVar) -> Expr {2101 Expr::ExprVar(node)2102 }2103}2104impl From<ExprLocal> for Expr {2105 fn from(node: ExprLocal) -> Expr {2106 Expr::ExprLocal(node)2107 }2108}2109impl From<ExprIfThenElse> for Expr {2110 fn from(node: ExprIfThenElse) -> Expr {2111 Expr::ExprIfThenElse(node)2112 }2113}2114impl From<ExprFunction> for Expr {2115 fn from(node: ExprFunction) -> Expr {2116 Expr::ExprFunction(node)2117 }2118}2119impl From<ExprAssert> for Expr {2120 fn from(node: ExprAssert) -> Expr {2121 Expr::ExprAssert(node)2122 }2123}2124impl From<ExprError> for Expr {2125 fn from(node: ExprError) -> Expr {2126 Expr::ExprError(node)2127 }2128}2129impl AstNode for Expr {2130 fn can_cast(kind: SyntaxKind) -> bool {2131 match kind {2132 EXPR_BINARY2133 | EXPR_UNARY2134 | EXPR_SLICE2135 | EXPR_INDEX2136 | EXPR_INDEX_EXPR2137 | EXPR_APPLY2138 | EXPR_OBJ_EXTEND2139 | EXPR_PARENED2140 | EXPR_INTRINSIC_THIS_FILE2141 | EXPR_INTRINSIC_ID2142 | EXPR_INTRINSIC2143 | EXPR_STRING2144 | EXPR_NUMBER2145 | EXPR_LITERAL2146 | EXPR_ARRAY2147 | EXPR_OBJECT2148 | EXPR_ARRAY_COMP2149 | EXPR_IMPORT2150 | EXPR_VAR2151 | EXPR_LOCAL2152 | EXPR_IF_THEN_ELSE2153 | EXPR_FUNCTION2154 | EXPR_ASSERT2155 | EXPR_ERROR => true,2156 _ => false,2157 }2158 }2159 fn cast(syntax: SyntaxNode) -> Option<Self> {2160 let res = match syntax.kind() {2161 EXPR_BINARY => Expr::ExprBinary(ExprBinary { syntax }),2162 EXPR_UNARY => Expr::ExprUnary(ExprUnary { syntax }),2163 EXPR_SLICE => Expr::ExprSlice(ExprSlice { syntax }),2164 EXPR_INDEX => Expr::ExprIndex(ExprIndex { syntax }),2165 EXPR_INDEX_EXPR => Expr::ExprIndexExpr(ExprIndexExpr { syntax }),2166 EXPR_APPLY => Expr::ExprApply(ExprApply { syntax }),2167 EXPR_OBJ_EXTEND => Expr::ExprObjExtend(ExprObjExtend { syntax }),2168 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 }),2175 EXPR_NUMBER => Expr::ExprNumber(ExprNumber { syntax }),2176 EXPR_LITERAL => Expr::ExprLiteral(ExprLiteral { syntax }),2177 EXPR_ARRAY => Expr::ExprArray(ExprArray { syntax }),2178 EXPR_OBJECT => Expr::ExprObject(ExprObject { syntax }),2179 EXPR_ARRAY_COMP => Expr::ExprArrayComp(ExprArrayComp { syntax }),2180 EXPR_IMPORT => Expr::ExprImport(ExprImport { syntax }),2181 EXPR_VAR => Expr::ExprVar(ExprVar { syntax }),2182 EXPR_LOCAL => Expr::ExprLocal(ExprLocal { syntax }),2183 EXPR_IF_THEN_ELSE => Expr::ExprIfThenElse(ExprIfThenElse { syntax }),2184 EXPR_FUNCTION => Expr::ExprFunction(ExprFunction { syntax }),2185 EXPR_ASSERT => Expr::ExprAssert(ExprAssert { syntax }),2186 EXPR_ERROR => Expr::ExprError(ExprError { syntax }),2187 _ => return None,2188 };2189 Some(res)2190 }2191 fn syntax(&self) -> &SyntaxNode {2192 match self {2193 Expr::ExprBinary(it) => &it.syntax,2194 Expr::ExprUnary(it) => &it.syntax,2195 Expr::ExprSlice(it) => &it.syntax,2196 Expr::ExprIndex(it) => &it.syntax,2197 Expr::ExprIndexExpr(it) => &it.syntax,2198 Expr::ExprApply(it) => &it.syntax,2199 Expr::ExprObjExtend(it) => &it.syntax,2200 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,2205 Expr::ExprNumber(it) => &it.syntax,2206 Expr::ExprLiteral(it) => &it.syntax,2207 Expr::ExprArray(it) => &it.syntax,2208 Expr::ExprObject(it) => &it.syntax,2209 Expr::ExprArrayComp(it) => &it.syntax,2210 Expr::ExprImport(it) => &it.syntax,2211 Expr::ExprVar(it) => &it.syntax,2212 Expr::ExprLocal(it) => &it.syntax,2213 Expr::ExprIfThenElse(it) => &it.syntax,2214 Expr::ExprFunction(it) => &it.syntax,2215 Expr::ExprAssert(it) => &it.syntax,2216 Expr::ExprError(it) => &it.syntax,2217 }2218 }2219}2220impl From<ObjBodyComp> for ObjBody {2221 fn from(node: ObjBodyComp) -> ObjBody {2222 ObjBody::ObjBodyComp(node)2223 }2224}2225impl From<ObjBodyMemberList> for ObjBody {2226 fn from(node: ObjBodyMemberList) -> ObjBody {2227 ObjBody::ObjBodyMemberList(node)2228 }2229}2230impl AstNode for ObjBody {2231 fn can_cast(kind: SyntaxKind) -> bool {2232 match kind {2233 OBJ_BODY_COMP | OBJ_BODY_MEMBER_LIST => true,2234 _ => false,2235 }2236 }2237 fn cast(syntax: SyntaxNode) -> Option<Self> {2238 let res = match syntax.kind() {2239 OBJ_BODY_COMP => ObjBody::ObjBodyComp(ObjBodyComp { syntax }),2240 OBJ_BODY_MEMBER_LIST => ObjBody::ObjBodyMemberList(ObjBodyMemberList { syntax }),2241 _ => return None,2242 };2243 Some(res)2244 }2245 fn syntax(&self) -> &SyntaxNode {2246 match self {2247 ObjBody::ObjBodyComp(it) => &it.syntax,2248 ObjBody::ObjBodyMemberList(it) => &it.syntax,2249 }2250 }2251}2252impl From<ForSpec> for CompSpec {2253 fn from(node: ForSpec) -> CompSpec {2254 CompSpec::ForSpec(node)2255 }2256}2257impl From<IfSpec> for CompSpec {2258 fn from(node: IfSpec) -> CompSpec {2259 CompSpec::IfSpec(node)2260 }2261}2262impl AstNode for CompSpec {2263 fn can_cast(kind: SyntaxKind) -> bool {2264 match kind {2265 FOR_SPEC | IF_SPEC => true,2266 _ => false,2267 }2268 }2269 fn cast(syntax: SyntaxNode) -> Option<Self> {2270 let res = match syntax.kind() {2271 FOR_SPEC => CompSpec::ForSpec(ForSpec { syntax }),2272 IF_SPEC => CompSpec::IfSpec(IfSpec { syntax }),2273 _ => return None,2274 };2275 Some(res)2276 }2277 fn syntax(&self) -> &SyntaxNode {2278 match self {2279 CompSpec::ForSpec(it) => &it.syntax,2280 CompSpec::IfSpec(it) => &it.syntax,2281 }2282 }2283}2284impl From<BindDestruct> for Bind {2285 fn from(node: BindDestruct) -> Bind {2286 Bind::BindDestruct(node)2287 }2288}2289impl From<BindFunction> for Bind {2290 fn from(node: BindFunction) -> Bind {2291 Bind::BindFunction(node)2292 }2293}2294impl AstNode for Bind {2295 fn can_cast(kind: SyntaxKind) -> bool {2296 match kind {2297 BIND_DESTRUCT | BIND_FUNCTION => true,2298 _ => false,2299 }2300 }2301 fn cast(syntax: SyntaxNode) -> Option<Self> {2302 let res = match syntax.kind() {2303 BIND_DESTRUCT => Bind::BindDestruct(BindDestruct { syntax }),2304 BIND_FUNCTION => Bind::BindFunction(BindFunction { syntax }),2305 _ => return None,2306 };2307 Some(res)2308 }2309 fn syntax(&self) -> &SyntaxNode {2310 match self {2311 Bind::BindDestruct(it) => &it.syntax,2312 Bind::BindFunction(it) => &it.syntax,2313 }2314 }2315}2316impl From<MemberBindStmt> for Member {2317 fn from(node: MemberBindStmt) -> Member {2318 Member::MemberBindStmt(node)2319 }2320}2321impl From<MemberAssertStmt> for Member {2322 fn from(node: MemberAssertStmt) -> Member {2323 Member::MemberAssertStmt(node)2324 }2325}2326impl From<MemberFieldNormal> for Member {2327 fn from(node: MemberFieldNormal) -> Member {2328 Member::MemberFieldNormal(node)2329 }2330}2331impl From<MemberFieldMethod> for Member {2332 fn from(node: MemberFieldMethod) -> Member {2333 Member::MemberFieldMethod(node)2334 }2335}2336impl AstNode for Member {2337 fn can_cast(kind: SyntaxKind) -> bool {2338 match kind {2339 MEMBER_BIND_STMT | MEMBER_ASSERT_STMT | MEMBER_FIELD_NORMAL | MEMBER_FIELD_METHOD => {2340 true2341 }2342 _ => false,2343 }2344 }2345 fn cast(syntax: SyntaxNode) -> Option<Self> {2346 let res = match syntax.kind() {2347 MEMBER_BIND_STMT => Member::MemberBindStmt(MemberBindStmt { syntax }),2348 MEMBER_ASSERT_STMT => Member::MemberAssertStmt(MemberAssertStmt { syntax }),2349 MEMBER_FIELD_NORMAL => Member::MemberFieldNormal(MemberFieldNormal { syntax }),2350 MEMBER_FIELD_METHOD => Member::MemberFieldMethod(MemberFieldMethod { syntax }),2351 _ => return None,2352 };2353 Some(res)2354 }2355 fn syntax(&self) -> &SyntaxNode {2356 match self {2357 Member::MemberBindStmt(it) => &it.syntax,2358 Member::MemberAssertStmt(it) => &it.syntax,2359 Member::MemberFieldNormal(it) => &it.syntax,2360 Member::MemberFieldMethod(it) => &it.syntax,2361 }2362 }2363}2364impl From<FieldNameFixed> for FieldName {2365 fn from(node: FieldNameFixed) -> FieldName {2366 FieldName::FieldNameFixed(node)2367 }2368}2369impl From<FieldNameDynamic> for FieldName {2370 fn from(node: FieldNameDynamic) -> FieldName {2371 FieldName::FieldNameDynamic(node)2372 }2373}2374impl AstNode for FieldName {2375 fn can_cast(kind: SyntaxKind) -> bool {2376 match kind {2377 FIELD_NAME_FIXED | FIELD_NAME_DYNAMIC => true,2378 _ => false,2379 }2380 }2381 fn cast(syntax: SyntaxNode) -> Option<Self> {2382 let res = match syntax.kind() {2383 FIELD_NAME_FIXED => FieldName::FieldNameFixed(FieldNameFixed { syntax }),2384 FIELD_NAME_DYNAMIC => FieldName::FieldNameDynamic(FieldNameDynamic { syntax }),2385 _ => return None,2386 };2387 Some(res)2388 }2389 fn syntax(&self) -> &SyntaxNode {2390 match self {2391 FieldName::FieldNameFixed(it) => &it.syntax,2392 FieldName::FieldNameDynamic(it) => &it.syntax,2393 }2394 }2395}2396impl From<DestructFull> for Destruct {2397 fn from(node: DestructFull) -> Destruct {2398 Destruct::DestructFull(node)2399 }2400}2401impl From<DestructSkip> for Destruct {2402 fn from(node: DestructSkip) -> Destruct {2403 Destruct::DestructSkip(node)2404 }2405}2406impl From<DestructArray> for Destruct {2407 fn from(node: DestructArray) -> Destruct {2408 Destruct::DestructArray(node)2409 }2410}2411impl From<DestructObject> for Destruct {2412 fn from(node: DestructObject) -> Destruct {2413 Destruct::DestructObject(node)2414 }2415}2416impl AstNode for Destruct {2417 fn can_cast(kind: SyntaxKind) -> bool {2418 match kind {2419 DESTRUCT_FULL | DESTRUCT_SKIP | DESTRUCT_ARRAY | DESTRUCT_OBJECT => true,2420 _ => false,2421 }2422 }2423 fn cast(syntax: SyntaxNode) -> Option<Self> {2424 let res = match syntax.kind() {2425 DESTRUCT_FULL => Destruct::DestructFull(DestructFull { syntax }),2426 DESTRUCT_SKIP => Destruct::DestructSkip(DestructSkip { syntax }),2427 DESTRUCT_ARRAY => Destruct::DestructArray(DestructArray { syntax }),2428 DESTRUCT_OBJECT => Destruct::DestructObject(DestructObject { syntax }),2429 _ => return None,2430 };2431 Some(res)2432 }2433 fn syntax(&self) -> &SyntaxNode {2434 match self {2435 Destruct::DestructFull(it) => &it.syntax,2436 Destruct::DestructSkip(it) => &it.syntax,2437 Destruct::DestructArray(it) => &it.syntax,2438 Destruct::DestructObject(it) => &it.syntax,2439 }2440 }2441}2442impl From<DestructArrayElement> for DestructArrayPart {2443 fn from(node: DestructArrayElement) -> DestructArrayPart {2444 DestructArrayPart::DestructArrayElement(node)2445 }2446}2447impl From<DestructRest> for DestructArrayPart {2448 fn from(node: DestructRest) -> DestructArrayPart {2449 DestructArrayPart::DestructRest(node)2450 }2451}2452impl AstNode for DestructArrayPart {2453 fn can_cast(kind: SyntaxKind) -> bool {2454 match kind {2455 DESTRUCT_ARRAY_ELEMENT | DESTRUCT_REST => true,2456 _ => false,2457 }2458 }2459 fn cast(syntax: SyntaxNode) -> Option<Self> {2460 let res = match syntax.kind() {2461 DESTRUCT_ARRAY_ELEMENT => {2462 DestructArrayPart::DestructArrayElement(DestructArrayElement { syntax })2463 }2464 DESTRUCT_REST => DestructArrayPart::DestructRest(DestructRest { syntax }),2465 _ => return None,2466 };2467 Some(res)2468 }2469 fn syntax(&self) -> &SyntaxNode {2470 match self {2471 DestructArrayPart::DestructArrayElement(it) => &it.syntax,2472 DestructArrayPart::DestructRest(it) => &it.syntax,2473 }2474 }2475}2476impl AstToken for BinaryOperator {2477 fn can_cast(kind: SyntaxKind) -> bool {2478 BinaryOperatorKind::can_cast(kind)2479 }2480 fn cast(syntax: SyntaxToken) -> Option<Self> {2481 let kind = BinaryOperatorKind::cast(syntax.kind())?;2482 Some(BinaryOperator { syntax, kind })2483 }2484 fn syntax(&self) -> &SyntaxToken {2485 &self.syntax2486 }2487}2488impl BinaryOperatorKind {2489 fn can_cast(kind: SyntaxKind) -> bool {2490 match kind {2491 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | IN_KW | LHS2492 | RHS | PLUS | MINUS | MUL | DIV | MODULO | META_OBJECT_APPLY | ERROR_NO_OPERATOR => true,2493 _ => false,2494 }2495 }2496 pub fn cast(kind: SyntaxKind) -> Option<Self> {2497 let res = match kind {2498 OR => Self::Or,2499 AND => Self::And,2500 BIT_OR => Self::BitOr,2501 BIT_XOR => Self::BitXor,2502 BIT_AND => Self::BitAnd,2503 EQ => Self::Eq,2504 NE => Self::Ne,2505 LT => Self::Lt,2506 GT => Self::Gt,2507 LE => Self::Le,2508 GE => Self::Ge,2509 IN_KW => Self::InKw,2510 LHS => Self::Lhs,2511 RHS => Self::Rhs,2512 PLUS => Self::Plus,2513 MINUS => Self::Minus,2514 MUL => Self::Mul,2515 DIV => Self::Div,2516 MODULO => Self::Modulo,2517 META_OBJECT_APPLY => Self::MetaObjectApply,2518 ERROR_NO_OPERATOR => Self::ErrorNoOperator,2519 _ => return None,2520 };2521 Some(res)2522 }2523}2524impl BinaryOperator {2525 pub fn kind(&self) -> BinaryOperatorKind {2526 self.kind2527 }2528}2529impl std::fmt::Display for BinaryOperator {2530 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2531 std::fmt::Display::fmt(self.syntax(), f)2532 }2533}2534impl AstToken for UnaryOperator {2535 fn can_cast(kind: SyntaxKind) -> bool {2536 UnaryOperatorKind::can_cast(kind)2537 }2538 fn cast(syntax: SyntaxToken) -> Option<Self> {2539 let kind = UnaryOperatorKind::cast(syntax.kind())?;2540 Some(UnaryOperator { syntax, kind })2541 }2542 fn syntax(&self) -> &SyntaxToken {2543 &self.syntax2544 }2545}2546impl UnaryOperatorKind {2547 fn can_cast(kind: SyntaxKind) -> bool {2548 match kind {2549 MINUS | NOT | BIT_NOT => true,2550 _ => false,2551 }2552 }2553 pub fn cast(kind: SyntaxKind) -> Option<Self> {2554 let res = match kind {2555 MINUS => Self::Minus,2556 NOT => Self::Not,2557 BIT_NOT => Self::BitNot,2558 _ => return None,2559 };2560 Some(res)2561 }2562}2563impl UnaryOperator {2564 pub fn kind(&self) -> UnaryOperatorKind {2565 self.kind2566 }2567}2568impl std::fmt::Display for UnaryOperator {2569 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2570 std::fmt::Display::fmt(self.syntax(), f)2571 }2572}2573impl AstToken for Literal {2574 fn can_cast(kind: SyntaxKind) -> bool {2575 LiteralKind::can_cast(kind)2576 }2577 fn cast(syntax: SyntaxToken) -> Option<Self> {2578 let kind = LiteralKind::cast(syntax.kind())?;2579 Some(Literal { syntax, kind })2580 }2581 fn syntax(&self) -> &SyntaxToken {2582 &self.syntax2583 }2584}2585impl LiteralKind {2586 fn can_cast(kind: SyntaxKind) -> bool {2587 match kind {2588 NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | DOLLAR | SUPER_KW => true,2589 _ => false,2590 }2591 }2592 pub fn cast(kind: SyntaxKind) -> Option<Self> {2593 let res = match kind {2594 NULL_KW => Self::NullKw,2595 TRUE_KW => Self::TrueKw,2596 FALSE_KW => Self::FalseKw,2597 SELF_KW => Self::SelfKw,2598 DOLLAR => Self::Dollar,2599 SUPER_KW => Self::SuperKw,2600 _ => return None,2601 };2602 Some(res)2603 }2604}2605impl Literal {2606 pub fn kind(&self) -> LiteralKind {2607 self.kind2608 }2609}2610impl std::fmt::Display for Literal {2611 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2612 std::fmt::Display::fmt(self.syntax(), f)2613 }2614}2615impl AstToken for Text {2616 fn can_cast(kind: SyntaxKind) -> bool {2617 TextKind::can_cast(kind)2618 }2619 fn cast(syntax: SyntaxToken) -> Option<Self> {2620 let kind = TextKind::cast(syntax.kind())?;2621 Some(Text { syntax, kind })2622 }2623 fn syntax(&self) -> &SyntaxToken {2624 &self.syntax2625 }2626}2627impl TextKind {2628 fn can_cast(kind: SyntaxKind) -> bool {2629 match kind {2630 STRING_DOUBLE2631 | ERROR_STRING_DOUBLE_UNTERMINATED2632 | STRING_SINGLE2633 | ERROR_STRING_SINGLE_UNTERMINATED2634 | STRING_DOUBLE_VERBATIM2635 | ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED2636 | STRING_SINGLE_VERBATIM2637 | ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED2638 | ERROR_STRING_VERBATIM_MISSING_QUOTES2639 | STRING_BLOCK2640 | ERROR_STRING_BLOCK_UNEXPECTED_END2641 | ERROR_STRING_BLOCK_MISSING_NEW_LINE2642 | ERROR_STRING_BLOCK_MISSING_TERMINATION2643 | ERROR_STRING_BLOCK_MISSING_INDENT => true,2644 _ => false,2645 }2646 }2647 pub fn cast(kind: SyntaxKind) -> Option<Self> {2648 let res = match kind {2649 STRING_DOUBLE => Self::StringDouble,2650 ERROR_STRING_DOUBLE_UNTERMINATED => Self::ErrorStringDoubleUnterminated,2651 STRING_SINGLE => Self::StringSingle,2652 ERROR_STRING_SINGLE_UNTERMINATED => Self::ErrorStringSingleUnterminated,2653 STRING_DOUBLE_VERBATIM => Self::StringDoubleVerbatim,2654 ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED => {2655 Self::ErrorStringDoubleVerbatimUnterminated2656 }2657 STRING_SINGLE_VERBATIM => Self::StringSingleVerbatim,2658 ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED => {2659 Self::ErrorStringSingleVerbatimUnterminated2660 }2661 ERROR_STRING_VERBATIM_MISSING_QUOTES => Self::ErrorStringVerbatimMissingQuotes,2662 STRING_BLOCK => Self::StringBlock,2663 ERROR_STRING_BLOCK_UNEXPECTED_END => Self::ErrorStringBlockUnexpectedEnd,2664 ERROR_STRING_BLOCK_MISSING_NEW_LINE => Self::ErrorStringBlockMissingNewLine,2665 ERROR_STRING_BLOCK_MISSING_TERMINATION => Self::ErrorStringBlockMissingTermination,2666 ERROR_STRING_BLOCK_MISSING_INDENT => Self::ErrorStringBlockMissingIndent,2667 _ => return None,2668 };2669 Some(res)2670 }2671}2672impl Text {2673 pub fn kind(&self) -> TextKind {2674 self.kind2675 }2676}2677impl std::fmt::Display for Text {2678 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2679 std::fmt::Display::fmt(self.syntax(), f)2680 }2681}2682impl AstToken for Number {2683 fn can_cast(kind: SyntaxKind) -> bool {2684 NumberKind::can_cast(kind)2685 }2686 fn cast(syntax: SyntaxToken) -> Option<Self> {2687 let kind = NumberKind::cast(syntax.kind())?;2688 Some(Number { syntax, kind })2689 }2690 fn syntax(&self) -> &SyntaxToken {2691 &self.syntax2692 }2693}2694impl NumberKind {2695 fn can_cast(kind: SyntaxKind) -> bool {2696 match kind {2697 FLOAT2698 | ERROR_FLOAT_JUNK_AFTER_POINT2699 | ERROR_FLOAT_JUNK_AFTER_EXPONENT2700 | ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => true,2701 _ => false,2702 }2703 }2704 pub fn cast(kind: SyntaxKind) -> Option<Self> {2705 let res = match kind {2706 FLOAT => Self::Float,2707 ERROR_FLOAT_JUNK_AFTER_POINT => Self::ErrorFloatJunkAfterPoint,2708 ERROR_FLOAT_JUNK_AFTER_EXPONENT => Self::ErrorFloatJunkAfterExponent,2709 ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => Self::ErrorFloatJunkAfterExponentSign,2710 _ => return None,2711 };2712 Some(res)2713 }2714}2715impl Number {2716 pub fn kind(&self) -> NumberKind {2717 self.kind2718 }2719}2720impl std::fmt::Display for Number {2721 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2722 std::fmt::Display::fmt(self.syntax(), f)2723 }2724}2725impl AstToken for ImportKind {2726 fn can_cast(kind: SyntaxKind) -> bool {2727 ImportKindKind::can_cast(kind)2728 }2729 fn cast(syntax: SyntaxToken) -> Option<Self> {2730 let kind = ImportKindKind::cast(syntax.kind())?;2731 Some(ImportKind { syntax, kind })2732 }2733 fn syntax(&self) -> &SyntaxToken {2734 &self.syntax2735 }2736}2737impl ImportKindKind {2738 fn can_cast(kind: SyntaxKind) -> bool {2739 match kind {2740 IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW => true,2741 _ => false,2742 }2743 }2744 pub fn cast(kind: SyntaxKind) -> Option<Self> {2745 let res = match kind {2746 IMPORTSTR_KW => Self::ImportstrKw,2747 IMPORTBIN_KW => Self::ImportbinKw,2748 IMPORT_KW => Self::ImportKw,2749 _ => return None,2750 };2751 Some(res)2752 }2753}2754impl ImportKind {2755 pub fn kind(&self) -> ImportKindKind {2756 self.kind2757 }2758}2759impl std::fmt::Display for ImportKind {2760 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2761 std::fmt::Display::fmt(self.syntax(), f)2762 }2763}2764impl AstToken for Visibility {2765 fn can_cast(kind: SyntaxKind) -> bool {2766 VisibilityKind::can_cast(kind)2767 }2768 fn cast(syntax: SyntaxToken) -> Option<Self> {2769 let kind = VisibilityKind::cast(syntax.kind())?;2770 Some(Visibility { syntax, kind })2771 }2772 fn syntax(&self) -> &SyntaxToken {2773 &self.syntax2774 }2775}2776impl VisibilityKind {2777 fn can_cast(kind: SyntaxKind) -> bool {2778 match kind {2779 COLONCOLONCOLON | COLONCOLON | COLON => true,2780 _ => false,2781 }2782 }2783 pub fn cast(kind: SyntaxKind) -> Option<Self> {2784 let res = match kind {2785 COLONCOLONCOLON => Self::Coloncoloncolon,2786 COLONCOLON => Self::Coloncolon,2787 COLON => Self::Colon,2788 _ => return None,2789 };2790 Some(res)2791 }2792}2793impl Visibility {2794 pub fn kind(&self) -> VisibilityKind {2795 self.kind2796 }2797}2798impl std::fmt::Display for Visibility {2799 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2800 std::fmt::Display::fmt(self.syntax(), f)2801 }2802}2803impl AstToken for Trivia {2804 fn can_cast(kind: SyntaxKind) -> bool {2805 TriviaKind::can_cast(kind)2806 }2807 fn cast(syntax: SyntaxToken) -> Option<Self> {2808 let kind = TriviaKind::cast(syntax.kind())?;2809 Some(Trivia { syntax, kind })2810 }2811 fn syntax(&self) -> &SyntaxToken {2812 &self.syntax2813 }2814}2815impl TriviaKind {2816 fn can_cast(kind: SyntaxKind) -> bool {2817 match kind {2818 WHITESPACE2819 | MULTI_LINE_COMMENT2820 | ERROR_COMMENT_TOO_SHORT2821 | ERROR_COMMENT_UNTERMINATED2822 | SINGLE_LINE_HASH_COMMENT2823 | SINGLE_LINE_SLASH_COMMENT => true,2824 _ => false,2825 }2826 }2827 pub fn cast(kind: SyntaxKind) -> Option<Self> {2828 let res = match kind {2829 WHITESPACE => Self::Whitespace,2830 MULTI_LINE_COMMENT => Self::MultiLineComment,2831 ERROR_COMMENT_TOO_SHORT => Self::ErrorCommentTooShort,2832 ERROR_COMMENT_UNTERMINATED => Self::ErrorCommentUnterminated,2833 SINGLE_LINE_HASH_COMMENT => Self::SingleLineHashComment,2834 SINGLE_LINE_SLASH_COMMENT => Self::SingleLineSlashComment,2835 _ => return None,2836 };2837 Some(res)2838 }2839}2840impl Trivia {2841 pub fn kind(&self) -> TriviaKind {2842 self.kind2843 }2844}2845impl std::fmt::Display for Trivia {2846 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2847 std::fmt::Display::fmt(self.syntax(), f)2848 }2849}2850impl AstToken for ParsingError {2851 fn can_cast(kind: SyntaxKind) -> bool {2852 ParsingErrorKind::can_cast(kind)2853 }2854 fn cast(syntax: SyntaxToken) -> Option<Self> {2855 let kind = ParsingErrorKind::cast(syntax.kind())?;2856 Some(ParsingError { syntax, kind })2857 }2858 fn syntax(&self) -> &SyntaxToken {2859 &self.syntax2860 }2861}2862impl ParsingErrorKind {2863 fn can_cast(kind: SyntaxKind) -> bool {2864 match kind {2865 ERROR_MISSING_TOKEN | ERROR_UNEXPECTED_TOKEN | ERROR_CUSTOM => true,2866 _ => false,2867 }2868 }2869 pub fn cast(kind: SyntaxKind) -> Option<Self> {2870 let res = match kind {2871 ERROR_MISSING_TOKEN => Self::ErrorMissingToken,2872 ERROR_UNEXPECTED_TOKEN => Self::ErrorUnexpectedToken,2873 ERROR_CUSTOM => Self::ErrorCustom,2874 _ => return None,2875 };2876 Some(res)2877 }2878}2879impl ParsingError {2880 pub fn kind(&self) -> ParsingErrorKind {2881 self.kind2882 }2883}2884impl std::fmt::Display for ParsingError {2885 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2886 std::fmt::Display::fmt(self.syntax(), f)2887 }2888}2889impl std::fmt::Display for Expr {2890 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2891 std::fmt::Display::fmt(self.syntax(), f)2892 }2893}2894impl std::fmt::Display for ObjBody {2895 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2896 std::fmt::Display::fmt(self.syntax(), f)2897 }2898}2899impl std::fmt::Display for CompSpec {2900 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2901 std::fmt::Display::fmt(self.syntax(), f)2902 }2903}2904impl std::fmt::Display for Bind {2905 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2906 std::fmt::Display::fmt(self.syntax(), f)2907 }2908}2909impl std::fmt::Display for Member {2910 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2911 std::fmt::Display::fmt(self.syntax(), f)2912 }2913}2914impl std::fmt::Display for FieldName {2915 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2916 std::fmt::Display::fmt(self.syntax(), f)2917 }2918}2919impl std::fmt::Display for Destruct {2920 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2921 std::fmt::Display::fmt(self.syntax(), f)2922 }2923}2924impl std::fmt::Display for DestructArrayPart {2925 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2926 std::fmt::Display::fmt(self.syntax(), f)2927 }2928}2929impl std::fmt::Display for SourceFile {2930 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2931 std::fmt::Display::fmt(self.syntax(), f)2932 }2933}2934impl std::fmt::Display for ExprBinary {2935 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2936 std::fmt::Display::fmt(self.syntax(), f)2937 }2938}2939impl std::fmt::Display for LhsExpr {2940 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2941 std::fmt::Display::fmt(self.syntax(), f)2942 }2943}2944impl std::fmt::Display for ExprUnary {2945 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2946 std::fmt::Display::fmt(self.syntax(), f)2947 }2948}2949impl std::fmt::Display for ExprSlice {2950 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2951 std::fmt::Display::fmt(self.syntax(), f)2952 }2953}2954impl std::fmt::Display for SliceDesc {2955 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2956 std::fmt::Display::fmt(self.syntax(), f)2957 }2958}2959impl std::fmt::Display for ExprIndex {2960 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2961 std::fmt::Display::fmt(self.syntax(), f)2962 }2963}2964impl std::fmt::Display for Name {2965 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2966 std::fmt::Display::fmt(self.syntax(), f)2967 }2968}2969impl std::fmt::Display for ExprIndexExpr {2970 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2971 std::fmt::Display::fmt(self.syntax(), f)2972 }2973}2974impl std::fmt::Display for ExprApply {2975 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2976 std::fmt::Display::fmt(self.syntax(), f)2977 }2978}2979impl std::fmt::Display for ArgsDesc {2980 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2981 std::fmt::Display::fmt(self.syntax(), f)2982 }2983}2984impl std::fmt::Display for ExprObjExtend {2985 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2986 std::fmt::Display::fmt(self.syntax(), f)2987 }2988}2989impl std::fmt::Display for ExprParened {2990 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2991 std::fmt::Display::fmt(self.syntax(), f)2992 }2993}2994impl std::fmt::Display for ExprLiteral {2995 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {2996 std::fmt::Display::fmt(self.syntax(), f)2997 }2998}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 {3015 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3016 std::fmt::Display::fmt(self.syntax(), f)3017 }3018}3019impl std::fmt::Display for ExprNumber {3020 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3021 std::fmt::Display::fmt(self.syntax(), f)3022 }3023}3024impl std::fmt::Display for ExprArray {3025 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3026 std::fmt::Display::fmt(self.syntax(), f)3027 }3028}3029impl std::fmt::Display for ExprObject {3030 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3031 std::fmt::Display::fmt(self.syntax(), f)3032 }3033}3034impl std::fmt::Display for ExprArrayComp {3035 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3036 std::fmt::Display::fmt(self.syntax(), f)3037 }3038}3039impl std::fmt::Display for ExprImport {3040 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3041 std::fmt::Display::fmt(self.syntax(), f)3042 }3043}3044impl std::fmt::Display for ExprVar {3045 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3046 std::fmt::Display::fmt(self.syntax(), f)3047 }3048}3049impl std::fmt::Display for ExprLocal {3050 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3051 std::fmt::Display::fmt(self.syntax(), f)3052 }3053}3054impl std::fmt::Display for ExprIfThenElse {3055 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3056 std::fmt::Display::fmt(self.syntax(), f)3057 }3058}3059impl std::fmt::Display for TrueExpr {3060 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3061 std::fmt::Display::fmt(self.syntax(), f)3062 }3063}3064impl std::fmt::Display for FalseExpr {3065 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3066 std::fmt::Display::fmt(self.syntax(), f)3067 }3068}3069impl std::fmt::Display for ExprFunction {3070 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3071 std::fmt::Display::fmt(self.syntax(), f)3072 }3073}3074impl std::fmt::Display for ParamsDesc {3075 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3076 std::fmt::Display::fmt(self.syntax(), f)3077 }3078}3079impl std::fmt::Display for ExprAssert {3080 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3081 std::fmt::Display::fmt(self.syntax(), f)3082 }3083}3084impl std::fmt::Display for Assertion {3085 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3086 std::fmt::Display::fmt(self.syntax(), f)3087 }3088}3089impl std::fmt::Display for ExprError {3090 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3091 std::fmt::Display::fmt(self.syntax(), f)3092 }3093}3094impl std::fmt::Display for SliceDescEnd {3095 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3096 std::fmt::Display::fmt(self.syntax(), f)3097 }3098}3099impl std::fmt::Display for SliceDescStep {3100 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3101 std::fmt::Display::fmt(self.syntax(), f)3102 }3103}3104impl std::fmt::Display for Arg {3105 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3106 std::fmt::Display::fmt(self.syntax(), f)3107 }3108}3109impl std::fmt::Display for ObjBodyComp {3110 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3111 std::fmt::Display::fmt(self.syntax(), f)3112 }3113}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 {3125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3126 std::fmt::Display::fmt(self.syntax(), f)3127 }3128}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 {3135 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3136 std::fmt::Display::fmt(self.syntax(), f)3137 }3138}3139impl std::fmt::Display for MemberAssertStmt {3140 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3141 std::fmt::Display::fmt(self.syntax(), f)3142 }3143}3144impl std::fmt::Display for MemberFieldNormal {3145 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3146 std::fmt::Display::fmt(self.syntax(), f)3147 }3148}3149impl std::fmt::Display for MemberFieldMethod {3150 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3151 std::fmt::Display::fmt(self.syntax(), f)3152 }3153}3154impl std::fmt::Display for FieldNameFixed {3155 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3156 std::fmt::Display::fmt(self.syntax(), f)3157 }3158}3159impl std::fmt::Display for FieldNameDynamic {3160 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3161 std::fmt::Display::fmt(self.syntax(), f)3162 }3163}3164impl std::fmt::Display for ForSpec {3165 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3166 std::fmt::Display::fmt(self.syntax(), f)3167 }3168}3169impl std::fmt::Display for IfSpec {3170 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3171 std::fmt::Display::fmt(self.syntax(), f)3172 }3173}3174impl std::fmt::Display for BindDestruct {3175 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3176 std::fmt::Display::fmt(self.syntax(), f)3177 }3178}3179impl std::fmt::Display for BindFunction {3180 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3181 std::fmt::Display::fmt(self.syntax(), f)3182 }3183}3184impl std::fmt::Display for Param {3185 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3186 std::fmt::Display::fmt(self.syntax(), f)3187 }3188}3189impl std::fmt::Display for DestructFull {3190 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3191 std::fmt::Display::fmt(self.syntax(), f)3192 }3193}3194impl std::fmt::Display for DestructSkip {3195 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3196 std::fmt::Display::fmt(self.syntax(), f)3197 }3198}3199impl std::fmt::Display for DestructArray {3200 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3201 std::fmt::Display::fmt(self.syntax(), f)3202 }3203}3204impl std::fmt::Display for DestructObject {3205 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3206 std::fmt::Display::fmt(self.syntax(), f)3207 }3208}3209impl std::fmt::Display for DestructObjectField {3210 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3211 std::fmt::Display::fmt(self.syntax(), f)3212 }3213}3214impl std::fmt::Display for DestructRest {3215 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3216 std::fmt::Display::fmt(self.syntax(), f)3217 }3218}3219impl std::fmt::Display for DestructArrayElement {3220 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {3221 std::fmt::Display::fmt(self.syntax(), f)3222 }3223}crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs
+++ b/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs
@@ -89,12 +89,6 @@
ASSIGN,
#[token("?")]
QUESTION_MARK,
- #[token("$intrinsicThisFile")]
- INTRINSIC_THIS_FILE,
- #[token("$intrinsicId")]
- INTRINSIC_ID,
- #[token("$intrinsic")]
- INTRINSIC,
#[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?")]
FLOAT,
#[regex("(?:0|[1-9][0-9]*)\\.[^0-9]")]
@@ -199,9 +193,6 @@
EXPR_OBJ_EXTEND,
EXPR_PARENED,
EXPR_LITERAL,
- EXPR_INTRINSIC_THIS_FILE,
- EXPR_INTRINSIC_ID,
- EXPR_INTRINSIC,
EXPR_STRING,
EXPR_NUMBER,
EXPR_ARRAY,
@@ -222,11 +213,9 @@
SLICE_DESC_STEP,
ARG,
OBJ_BODY_COMP,
- OBJ_LOCAL_POST_COMMA,
- OBJ_LOCAL_PRE_COMMA,
OBJ_BODY_MEMBER_LIST,
- OBJ_LOCAL,
MEMBER_BIND_STMT,
+ OBJ_LOCAL,
MEMBER_ASSERT_STMT,
MEMBER_FIELD_NORMAL,
MEMBER_FIELD_METHOD,
@@ -248,6 +237,7 @@
OBJ_BODY,
COMP_SPEC,
BIND,
+ MEMBER_COMP,
MEMBER,
FIELD_NAME,
DESTRUCT,
@@ -260,7 +250,7 @@
IMPORT_KIND,
VISIBILITY,
TRIVIA,
- PARSING_ERROR,
+ CUSTOM_ERROR,
#[doc(hidden)]
__LAST,
}
@@ -271,18 +261,18 @@
OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | LHS | RHS
| PLUS | MINUS | MUL | DIV | MODULO | NOT | BIT_NOT | L_BRACK | R_BRACK | L_PAREN
| R_PAREN | L_BRACE | R_BRACE | COLON | COLONCOLON | COLONCOLONCOLON | SEMI | DOT
- | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | INTRINSIC_THIS_FILE
- | INTRINSIC_ID | INTRINSIC | TAILSTRICT_KW | IMPORTSTR_KW | IMPORTBIN_KW
- | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW | FUNCTION_KW | ERROR_KW | IN_KW
- | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | SUPER_KW | FOR_KW | ASSERT_KW => true,
+ | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | TAILSTRICT_KW
+ | IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW
+ | FUNCTION_KW | ERROR_KW | IN_KW | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW
+ | SUPER_KW | FOR_KW | ASSERT_KW => true,
_ => false,
}
}
pub fn is_enum(self) -> bool {
match self {
- EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER | FIELD_NAME | DESTRUCT
+ EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER_COMP | MEMBER | FIELD_NAME | DESTRUCT
| DESTRUCT_ARRAY_PART | BINARY_OPERATOR | UNARY_OPERATOR | LITERAL | TEXT | NUMBER
- | IMPORT_KIND | VISIBILITY | TRIVIA | PARSING_ERROR => true,
+ | IMPORT_KIND | VISIBILITY | TRIVIA | CUSTOM_ERROR => true,
_ => false,
}
}
@@ -295,5 +285,5 @@
}
}
#[macro_export]
-macro_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 } }
+macro_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 } }
pub use T;
crates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/parser.rs
+++ b/crates/jrsonnet-rowan-parser/src/parser.rs
@@ -114,7 +114,13 @@
pub fn parse(mut self) -> Vec<Event> {
let m = self.start();
expr(&mut self);
- self.expect(EOF);
+ if !self.at(EOF) {
+ let m = self.start();
+ while !self.at(EOF) {
+ self.bump();
+ }
+ m.complete_error(&mut self, "unexpected tokens after end");
+ }
m.complete(&mut self, SOURCE_FILE);
self.events
@@ -832,21 +838,6 @@
let m = p.start();
name(p);
m.complete(p, EXPR_VAR)
- } else if p.at(INTRINSIC_THIS_FILE) {
- let m = p.start();
- p.bump();
- m.complete(p, EXPR_INTRINSIC_THIS_FILE)
- } else if p.at(INTRINSIC_ID) {
- let m = p.start();
- p.bump();
- m.complete(p, EXPR_INTRINSIC_ID)
- } else if p.at(INTRINSIC) {
- let m = p.start();
- p.bump();
- p.expect(T!['(']);
- name(p);
- p.expect(T![')']);
- m.complete(p, EXPR_INTRINSIC)
} else if p.at(T![if]) {
let m = p.start();
p.bump();
crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__continue_after_total_failure.snapdiffbeforeafterboth--- /dev/null
+++ b/crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__continue_after_total_failure.snap
@@ -0,0 +1,74 @@
+---
+source: crates/jrsonnet-rowan-parser/src/tests.rs
+expression: "local intr = $intrinsic(test);\n\nlocal a = 1, b = 2, c = a + b;\n\n[c]\n"
+---
+SOURCE_FILE@0..68
+ EXPR_LOCAL@0..29
+ LOCAL_KW@0..5 "local"
+ WHITESPACE@5..6 " "
+ BIND_DESTRUCT@6..14
+ DESTRUCT_FULL@6..10
+ NAME@6..10
+ IDENT@6..10 "intr"
+ WHITESPACE@10..11 " "
+ ASSIGN@11..12 "="
+ WHITESPACE@12..13 " "
+ EXPR_LITERAL@13..14
+ DOLLAR@13..14 "$"
+ ERROR_UNEXPECTED_TOKEN@14..23
+ IDENT@14..23 "intrinsic"
+ EXPR_PARENED@23..29
+ L_PAREN@23..24 "("
+ EXPR_VAR@24..28
+ NAME@24..28
+ IDENT@24..28 "test"
+ R_PAREN@28..29 ")"
+ ERROR_CUSTOM@29..67
+ SEMI@29..30 ";"
+ WHITESPACE@30..32 "\n\n"
+ LOCAL_KW@32..37 "local"
+ WHITESPACE@37..38 " "
+ IDENT@38..39 "a"
+ WHITESPACE@39..40 " "
+ ASSIGN@40..41 "="
+ WHITESPACE@41..42 " "
+ FLOAT@42..43 "1"
+ COMMA@43..44 ","
+ WHITESPACE@44..45 " "
+ IDENT@45..46 "b"
+ WHITESPACE@46..47 " "
+ ASSIGN@47..48 "="
+ WHITESPACE@48..49 " "
+ FLOAT@49..50 "2"
+ COMMA@50..51 ","
+ WHITESPACE@51..52 " "
+ IDENT@52..53 "c"
+ WHITESPACE@53..54 " "
+ ASSIGN@54..55 "="
+ WHITESPACE@55..56 " "
+ IDENT@56..57 "a"
+ WHITESPACE@57..58 " "
+ PLUS@58..59 "+"
+ WHITESPACE@59..60 " "
+ IDENT@60..61 "b"
+ SEMI@61..62 ";"
+ WHITESPACE@62..64 "\n\n"
+ L_BRACK@64..65 "["
+ IDENT@65..66 "c"
+ R_BRACK@66..67 "]"
+ WHITESPACE@67..68 "\n"
+===
+LocatedSyntaxError { error: Unexpected { expected: Unnamed(SyntaxKindSet([L_BRACK, L_PAREN, L_BRACE, SEMI, DOT, COMMA])), found: IDENT }, range: 14..23 }
+LocatedSyntaxError { error: Custom { error: "unexpected tokens after end" }, range: 29..67 }
+===
+ x syntax error
+ ,-[1:1]
+ 1 | ,-> local intr = $intrinsic(test);
+ : || ^^^^|^^^^
+ : || `-- expected L_BRACK, L_PAREN, L_BRACE, SEMI, DOT or COMMA, found IDENT
+ 2 | |
+ 3 | | local a = 1, b = 2, c = a + b;
+ 4 | |
+ 5 | |-> [c]
+ : `---- unexpected tokens after end
+ `----
crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_lhs.snapdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_lhs.snap
+++ b/crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_lhs.snap
@@ -2,19 +2,21 @@
source: crates/jrsonnet-rowan-parser/src/tests.rs
expression: "+ 2\n"
---
-SOURCE_FILE@0..2
+SOURCE_FILE@0..4
ERROR_MISSING_TOKEN@0..0
- ERROR_UNEXPECTED_TOKEN@0..1
+ ERROR_CUSTOM@0..3
PLUS@0..1 "+"
- WHITESPACE@1..2 " "
+ WHITESPACE@1..2 " "
+ FLOAT@2..3 "2"
+ WHITESPACE@3..4 "\n"
===
LocatedSyntaxError { error: Missing { expected: Named("expression") }, range: 0..0 }
-LocatedSyntaxError { error: Unexpected { expected: Unnamed(SyntaxKindSet([EOF])), found: PLUS }, range: 0..1 }
+LocatedSyntaxError { error: Custom { error: "unexpected tokens after end" }, range: 0..3 }
===
x syntax error
,----
1 | + 2
- : ^|
- : |`-- expected EOF, found PLUS
+ : ^^|
+ : | `-- unexpected tokens after end
: `-- missing expression
`----
crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_operator.snapdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_operator.snap
+++ b/crates/jrsonnet-rowan-parser/src/snapshots/jrsonnet_rowan_parser__tests__no_operator.snap
@@ -6,15 +6,15 @@
EXPR_NUMBER@0..1
FLOAT@0..1 "2"
WHITESPACE@1..2 " "
- ERROR_UNEXPECTED_TOKEN@2..3
+ ERROR_CUSTOM@2..3
FLOAT@2..3 "2"
WHITESPACE@3..4 "\n"
===
-LocatedSyntaxError { error: Unexpected { expected: Unnamed(SyntaxKindSet([EOF, L_BRACK, L_PAREN, L_BRACE, DOT])), found: FLOAT }, range: 2..3 }
+LocatedSyntaxError { error: Custom { error: "unexpected tokens after end" }, range: 2..3 }
===
x syntax error
,----
1 | 2 2
: |
- : `-- expected EOF, L_BRACK, L_PAREN, L_BRACE or DOT, found FLOAT
+ : `-- unexpected tokens after end
`----
crates/jrsonnet-rowan-parser/src/tests.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/tests.rs
+++ b/crates/jrsonnet-rowan-parser/src/tests.rs
@@ -228,6 +228,14 @@
a: function(x) x,
}
"#
+
+ continue_after_total_failure => r#"
+ local intr = $intrinsic(test);
+
+ local a = 1, b = 2, c = a + b;
+
+ [c]
+ "#
);
#[test]
crates/jrsonnet-rowan-parser/src/token_set.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/token_set.rs
+++ b/crates/jrsonnet-rowan-parser/src/token_set.rs
@@ -27,7 +27,10 @@
SyntaxKindSet(self.0 | mask(kind))
}
- pub const fn contains(&self, kind: SyntaxKind) -> bool {
+ pub fn contains(&self, kind: SyntaxKind) -> bool {
+ if !is_token(kind) {
+ return false;
+ }
self.0 & mask(kind) != 0
}
}
@@ -74,6 +77,9 @@
}
const fn mask(kind: SyntaxKind) -> u128 {
+ if kind as u32 > 128 {
+ panic!("mask for not a token kind")
+ }
1u128 << (kind as u128)
}
@@ -95,3 +101,6 @@
"can't keep KindSet as bitset"
);
}
+fn is_token(kind: SyntaxKind) -> bool {
+ (kind as u32) < 127
+}
xtask/src/sourcegen/kinds.rsdiffbeforeafterboth--- a/xtask/src/sourcegen/kinds.rs
+++ b/xtask/src/sourcegen/kinds.rs
@@ -247,9 +247,6 @@
"$" => "DOLLAR";
"=" => "ASSIGN";
"?" => "QUESTION_MARK";
- "$intrinsicThisFile" => "INTRINSIC_THIS_FILE";
- "$intrinsicId" => "INTRINSIC_ID";
- "$intrinsic" => "INTRINSIC";
// Literals
lit("FLOAT") => r"(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?";
error("FLOAT_JUNK_AFTER_POINT") => r"(?:0|[1-9][0-9]*)\.[^0-9]";