Compare commits
No commits in common. "883b0c804e160cf06caba98390e6523f17d3f1df" and "cee9b97dbfcb775784a400114d959bec1141c2e5" have entirely different histories.
883b0c804e
...
cee9b97dbf
4 changed files with 7 additions and 16 deletions
|
@ -62,15 +62,13 @@ pub enum SyntaxKind {
|
||||||
PARSE_ERR,
|
PARSE_ERR,
|
||||||
|
|
||||||
// Meta SyntaxKinds
|
// Meta SyntaxKinds
|
||||||
ROOT,
|
|
||||||
EOF,
|
EOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pawarser::parser::SyntaxElement for SyntaxKind {
|
impl pawarser::parser::SyntaxElement for SyntaxKind {
|
||||||
const SYNTAX_EOF: Self = Self::EOF;
|
const EOF: Self = Self::EOF;
|
||||||
|
|
||||||
const SYNTAX_ERROR: Self = Self::PARSE_ERR;
|
const ERROR: Self = Self::PARSE_ERR;
|
||||||
const SYNTAX_ROOT: Self = Self::ROOT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SyntaxKind> for rowan::SyntaxKind {
|
impl From<SyntaxKind> for rowan::SyntaxKind {
|
||||||
|
|
|
@ -26,10 +26,9 @@ where
|
||||||
+ Eq,
|
+ Eq,
|
||||||
{
|
{
|
||||||
/// EOF value. This will be used by the rest of the parser library to represent an EOF.
|
/// EOF value. This will be used by the rest of the parser library to represent an EOF.
|
||||||
const SYNTAX_EOF: Self;
|
const EOF: Self;
|
||||||
/// Error value. This will be used as a placeholder for associated respective errors.
|
/// Error value. This will be used as a placeholder for associated respective errors.
|
||||||
const SYNTAX_ERROR: Self;
|
const ERROR: Self;
|
||||||
const SYNTAX_ROOT: Self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
||||||
|
@ -120,9 +119,6 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
||||||
let mut errors: Vec<SyntaxErr> = Vec::new();
|
let mut errors: Vec<SyntaxErr> = Vec::new();
|
||||||
raw_toks.reverse();
|
raw_toks.reverse();
|
||||||
|
|
||||||
// always have an implicit root node to avoid [`GreenNodeBuilder::finish()`] panicking due to multiple root elements.
|
|
||||||
builder.start_node(SyntaxKind::SYNTAX_ROOT.into());
|
|
||||||
|
|
||||||
for i in 0..events.len() {
|
for i in 0..events.len() {
|
||||||
match mem::replace(&mut events[i], Event::tombstone()) {
|
match mem::replace(&mut events[i], Event::tombstone()) {
|
||||||
Event::Start {
|
Event::Start {
|
||||||
|
@ -174,7 +170,7 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
||||||
NodeKind::Syntax(kind) => builder.start_node(kind.into()),
|
NodeKind::Syntax(kind) => builder.start_node(kind.into()),
|
||||||
NodeKind::Error(err) => {
|
NodeKind::Error(err) => {
|
||||||
errors.push(err);
|
errors.push(err);
|
||||||
builder.start_node(SyntaxKind::SYNTAX_ERROR.into())
|
builder.start_node(SyntaxKind::ERROR.into())
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -188,9 +184,6 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish SYNTAX_ROOT
|
|
||||||
builder.finish_node();
|
|
||||||
|
|
||||||
ParserOutput {
|
ParserOutput {
|
||||||
green_node: builder.finish(),
|
green_node: builder.finish(),
|
||||||
errors,
|
errors,
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl<'src, SyntaxKind: SyntaxElement> Input<'src, SyntaxKind> {
|
||||||
|
|
||||||
pub fn kind(&self, idx: usize) -> SyntaxKind {
|
pub fn kind(&self, idx: usize) -> SyntaxKind {
|
||||||
let Some(meaningful_idx) = self.meaningful_toks.get(idx) else {
|
let Some(meaningful_idx) = self.meaningful_toks.get(idx) else {
|
||||||
return SyntaxKind::SYNTAX_EOF;
|
return SyntaxKind::EOF;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.raw.get(*meaningful_idx).unwrap().0
|
self.raw.get(*meaningful_idx).unwrap().0
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn debug_print_output<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>(
|
||||||
match node {
|
match node {
|
||||||
NodeOrToken::Node(n) => {
|
NodeOrToken::Node(n) => {
|
||||||
let kind: SyntaxKind = node.kind().into();
|
let kind: SyntaxKind = node.kind().into();
|
||||||
if kind != SyntaxKind::SYNTAX_ERROR {
|
if kind != SyntaxKind::ERROR {
|
||||||
writeln!(f, "{:?} {{", kind)?;
|
writeln!(f, "{:?} {{", kind)?;
|
||||||
} else {
|
} else {
|
||||||
let err = errs
|
let err = errs
|
||||||
|
|
Loading…
Reference in a new issue