Skip to content

Commit

Permalink
Test LaTeX parser
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Mar 5, 2020
1 parent f6b686c commit ca5f23c
Show file tree
Hide file tree
Showing 3 changed files with 661 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/syntax/latex/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,7 @@ pub struct Section {

impl Section {
pub fn print(&self, tree: &Tree) -> Option<String> {
let arg = tree.extract_group(self.parent, GroupKind::Group, self.arg_index)?;
let text = tree.print(arg);
tree.as_group(arg)?.right.as_ref()?;
Some(text[1..text.len() - 1].trim().into())
tree.print_group_content(self.parent, GroupKind::Group, self.arg_index)
}

fn parse(ctx: SymbolContext) -> Vec<Self> {
Expand Down Expand Up @@ -692,8 +689,8 @@ impl Label {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LabelNumbering {
parent: NodeIndex,
number: String,
pub parent: NodeIndex,
pub number: String,
}

impl LabelNumbering {
Expand Down Expand Up @@ -750,6 +747,10 @@ pub struct Caption {
}

impl Caption {
pub fn print(self, tree: &Tree) -> Option<String> {
tree.print_group_content(self.parent, GroupKind::Group, self.arg_index)
}

fn parse(ctx: SymbolContext) -> Vec<Self> {
ctx.commands
.iter()
Expand Down Expand Up @@ -778,8 +779,7 @@ pub struct Item {

impl Item {
pub fn name(self, tree: &Tree) -> Option<String> {
tree.extract_text(self.parent, GroupKind::Options, 0)
.map(|text| text.words.iter().map(Token::text).join(" "))
tree.print_group_content(self.parent, GroupKind::Options, 0)
}

fn parse(ctx: SymbolContext) -> Vec<Self> {
Expand Down
12 changes: 12 additions & 0 deletions src/syntax/latex/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ impl Tree {
}
Some(words)
}

pub fn print_group_content(
&self,
parent: NodeIndex,
group_kind: GroupKind,
index: usize,
) -> Option<String> {
let arg = self.extract_group(parent, group_kind, index)?;
let text = self.print(arg);
self.as_group(arg)?.right.as_ref()?;
Some(text[1..text.len() - 1].trim().into())
}
}

pub trait Visitor {
Expand Down
Loading

0 comments on commit ca5f23c

Please sign in to comment.