[fine] ConcreteTree -> SyntaxTree
This commit is contained in:
parent
7abb8eafc2
commit
120bd43652
2 changed files with 12 additions and 12 deletions
|
|
@ -3,14 +3,14 @@
|
|||
use crate::tokens::{Lines, Token, TokenKind, Tokens};
|
||||
use std::{cell::Cell, num::NonZeroU32};
|
||||
|
||||
pub struct ConcreteTree<'a> {
|
||||
pub struct SyntaxTree<'a> {
|
||||
trees: Vec<Tree<'a>>,
|
||||
root: Option<TreeRef>,
|
||||
}
|
||||
|
||||
impl<'a> ConcreteTree<'a> {
|
||||
impl<'a> SyntaxTree<'a> {
|
||||
pub fn new() -> Self {
|
||||
ConcreteTree {
|
||||
SyntaxTree {
|
||||
trees: vec![],
|
||||
root: None,
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ impl<'a> ConcreteTree<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> std::ops::Index<TreeRef> for ConcreteTree<'a> {
|
||||
impl<'a> std::ops::Index<TreeRef> for SyntaxTree<'a> {
|
||||
type Output = Tree<'a>;
|
||||
|
||||
fn index(&self, index: TreeRef) -> &Self::Output {
|
||||
|
|
@ -48,7 +48,7 @@ impl<'a> std::ops::Index<TreeRef> for ConcreteTree<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> std::ops::IndexMut<TreeRef> for ConcreteTree<'a> {
|
||||
impl<'a> std::ops::IndexMut<TreeRef> for SyntaxTree<'a> {
|
||||
fn index_mut(&mut self, index: TreeRef) -> &mut Self::Output {
|
||||
&mut self.trees[index.index()]
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ impl TreeRef {
|
|||
}
|
||||
|
||||
impl<'a> Tree<'a> {
|
||||
pub fn dump(&self, tree: &ConcreteTree<'a>) -> String {
|
||||
pub fn dump(&self, tree: &SyntaxTree<'a>) -> String {
|
||||
let mut output = String::new();
|
||||
output.push_str(&format!("{:?}\n", self.kind));
|
||||
for child in self.children.iter() {
|
||||
|
|
@ -116,7 +116,7 @@ pub enum Child<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Child<'a> {
|
||||
fn dump_rec(&self, indent: usize, tree: &ConcreteTree<'a>, output: &mut String) {
|
||||
fn dump_rec(&self, indent: usize, tree: &SyntaxTree<'a>, output: &mut String) {
|
||||
for _ in 0..indent {
|
||||
output.push(' ');
|
||||
}
|
||||
|
|
@ -284,11 +284,11 @@ impl<'a> CParser<'a> {
|
|||
});
|
||||
}
|
||||
|
||||
fn build_tree(self) -> (ConcreteTree<'a>, Lines) {
|
||||
fn build_tree(self) -> (SyntaxTree<'a>, Lines) {
|
||||
let mut events = self.events;
|
||||
let mut stack = Vec::new();
|
||||
|
||||
let mut result = ConcreteTree::new();
|
||||
let mut result = SyntaxTree::new();
|
||||
|
||||
// The first element in our events vector must be a start; the whole
|
||||
// thing must be bracketed in a tree.
|
||||
|
|
@ -327,7 +327,7 @@ impl<'a> CParser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_concrete(source: &str) -> (ConcreteTree, Lines) {
|
||||
pub fn parse_concrete(source: &str) -> (SyntaxTree, Lines) {
|
||||
let tokens = Tokens::new(source);
|
||||
let mut parser = CParser::new(tokens);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use fine::parser::concrete::ConcreteTree;
|
||||
use fine::parser::concrete::SyntaxTree;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn rebase_concrete(source_path: &str, dump: &str) {
|
||||
|
|
@ -68,7 +68,7 @@ fn rebase_concrete(source_path: &str, dump: &str) {
|
|||
std::fs::write(source_path, result).expect("unable to write the new file!");
|
||||
}
|
||||
|
||||
fn assert_concrete(tree: &ConcreteTree, expected: &str, source_path: &str) {
|
||||
fn assert_concrete(tree: &SyntaxTree, expected: &str, source_path: &str) {
|
||||
let dump = tree.dump();
|
||||
let rebase = std::env::var("FINE_TEST_REBASE")
|
||||
.unwrap_or(String::new())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue