forked from katzen-cafe/iowo
rename trait meta syntaxkinds
This commit is contained in:
parent
cee9b97dbf
commit
f7d05ead2c
4 changed files with 10 additions and 7 deletions
|
@ -62,13 +62,15 @@ 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 EOF: Self = Self::EOF;
|
const SYNTAX_EOF: Self = Self::EOF;
|
||||||
|
|
||||||
const ERROR: Self = Self::PARSE_ERR;
|
const SYNTAX_ERROR: Self = Self::PARSE_ERR;
|
||||||
|
const SYNTAX_ROOT: Self = Self::ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SyntaxKind> for rowan::SyntaxKind {
|
impl From<SyntaxKind> for rowan::SyntaxKind {
|
||||||
|
|
|
@ -26,9 +26,10 @@ 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 EOF: Self;
|
const SYNTAX_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 ERROR: Self;
|
const SYNTAX_ERROR: Self;
|
||||||
|
const SYNTAX_ROOT: Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
||||||
|
@ -170,7 +171,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::ERROR.into())
|
builder.start_node(SyntaxKind::SYNTAX_ERROR.into())
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::EOF;
|
return SyntaxKind::SYNTAX_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::ERROR {
|
if kind != SyntaxKind::SYNTAX_ERROR {
|
||||||
writeln!(f, "{:?} {{", kind)?;
|
writeln!(f, "{:?} {{", kind)?;
|
||||||
} else {
|
} else {
|
||||||
let err = errs
|
let err = errs
|
||||||
|
|
Loading…
Reference in a new issue