Skip to content

Commit

Permalink
Merge pull request #69 from oberien/error-reporting
Browse files Browse the repository at this point in the history
Error reporting, major refactors
  • Loading branch information
oberien committed Apr 14, 2019
2 parents 46ee7fa + ccb2b53 commit 81aa534
Show file tree
Hide file tree
Showing 43 changed files with 2,124 additions and 921 deletions.
78 changes: 78 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ regex = "1.1.0"
lazy_static = "1.2.0"
single = "1.0.0"
quoted-string = "0.6.0"
codespan = { git = "https://github.com/oberien/codespan", rev = "dc7b13739165fc58721415ce3120d05cf117ca81" }
codespan-reporting = { git = "https://github.com/oberien/codespan", rev = "dc7b13739165fc58721415ce3120d05cf117ca81" }
backtrace = "0.3.14"
enum-kinds = "0.4.1"

[profile.release]
debug = true
Expand Down
16 changes: 16 additions & 0 deletions examples/errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#label}
```rust, #label2, figure=true, nofigure, figure
let foo = bar;
```

```sequence
nothing here yet
```

{foo=bar}

text text text

{#section-label}

# Section {#section-label2}
2 changes: 1 addition & 1 deletion examples/functionality/codeblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Rust

```rust
```rust, caption = "\"foo\""
fn main() {
let foo = bar();
}
Expand Down
13 changes: 8 additions & 5 deletions src/backend/latex/complex/blockquote.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::io::{Result, Write};
use std::io::Write;

use crate::backend::{Backend, CodeGenUnit};
use crate::config::Config;
use crate::generator::Generator;

use crate::error::Result;
use crate::frontend::range::WithRange;
use crate::generator::event::Event;
use crate::generator::Generator;

#[derive(Debug)]
pub struct BlockQuoteGen {
Expand All @@ -13,7 +14,8 @@ pub struct BlockQuoteGen {

impl<'a> CodeGenUnit<'a, ()> for BlockQuoteGen {
fn new(
_cfg: &'a Config, _tag: (), _gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_cfg: &'a Config, _tag: WithRange<()>,
_gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
) -> Result<Self> {
Ok(BlockQuoteGen { quote: Vec::new() })
}
Expand All @@ -23,7 +25,8 @@ impl<'a> CodeGenUnit<'a, ()> for BlockQuoteGen {
}

fn finish(
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>, _peek: Option<&Event<'a>>,
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_peek: Option<WithRange<&Event<'a>>>,
) -> Result<()> {
let out = gen.get_out();
let quote = String::from_utf8(self.quote).expect("invalid UTF8");
Expand Down
17 changes: 10 additions & 7 deletions src/backend/latex/complex/codeblock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::io::{Result, Write};
use std::io::Write;

use crate::backend::{Backend, CodeGenUnit};
use crate::config::Config;
use crate::error::Result;
use crate::frontend::range::WithRange;
use crate::generator::event::{CodeBlock, Event};
use crate::generator::Generator;

Expand All @@ -10,20 +12,20 @@ pub struct CodeBlockGen;

impl<'a> CodeGenUnit<'a, CodeBlock<'a>> for CodeBlockGen {
fn new(
_cfg: &'a Config, code_block: CodeBlock<'a>,
_cfg: &'a Config, code_block: WithRange<CodeBlock<'a>>,
gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
) -> Result<Self> {
let CodeBlock { label, caption, language } = code_block;
let WithRange(CodeBlock { label, caption, language }, _range) = code_block;

let out = gen.get_out();
write!(out, "\\begin{{lstlisting}}[")?;
if let Some(label) = label {
if let Some(WithRange(label, _)) = label {
write!(out, "label={{{}}},", label)?;
}
if let Some(caption) = caption {
if let Some(WithRange(caption, _)) = caption {
write!(out, "caption={{{}}},", caption)?;
}
if let Some(language) = language {
if let Some(WithRange(language, _)) = language {
write!(out, "language={{{}}},", language)?;
}
writeln!(out, "]")?;
Expand All @@ -32,7 +34,8 @@ impl<'a> CodeGenUnit<'a, CodeBlock<'a>> for CodeBlockGen {
}

fn finish(
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>, _peek: Option<&Event<'a>>,
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_peek: Option<WithRange<&Event<'a>>>,
) -> Result<()> {
writeln!(gen.get_out(), "\\end{{lstlisting}}")?;
Ok(())
Expand Down
23 changes: 13 additions & 10 deletions src/backend/latex/complex/figure.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::borrow::Cow;
use std::fmt::Debug;
use std::io::{Result, Write};
use std::io::Write;
use std::marker::PhantomData;

use crate::backend::{Backend, CodeGenUnit};
use crate::config::Config;
use crate::generator::Generator;

use crate::error::Result;
use crate::frontend::range::WithRange;
use crate::generator::event::{Event, Figure};
use crate::generator::Generator;

#[derive(Debug)]
#[doc(hidden)]
Expand Down Expand Up @@ -36,29 +37,31 @@ pub type TableFigureGen<'a> = AnyFigureGen<'a, Table>;
#[derive(Debug)]
#[doc(hidden)]
pub struct AnyFigureGen<'a, T: Environment> {
label: Option<Cow<'a, str>>,
caption: Option<Cow<'a, str>>,
label: Option<WithRange<Cow<'a, str>>>,
caption: Option<WithRange<Cow<'a, str>>>,
_marker: PhantomData<T>,
}

impl<'a, T: Environment + Debug> CodeGenUnit<'a, Figure<'a>> for AnyFigureGen<'a, T> {
fn new(
_cfg: &'a Config, figure: Figure<'a>, gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_cfg: &'a Config, figure: WithRange<Figure<'a>>,
gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
) -> Result<Self> {
let Figure { label, caption } = figure;
let WithRange(Figure { label, caption }, _range) = figure;
write!(gen.get_out(), "\\begin{{{}}}", T::to_str())?;
Ok(AnyFigureGen { label, caption, _marker: PhantomData })
}

fn finish(
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>, _peek: Option<&Event<'a>>,
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_peek: Option<WithRange<&Event<'a>>>,
) -> Result<()> {
let out = gen.get_out();
match self.caption {
Some(caption) => writeln!(out, "\\caption{{{}}}", caption)?,
Some(WithRange(caption, _)) => writeln!(out, "\\caption{{{}}}", caption)?,
None => writeln!(out, "\\caption{{}}")?,
}
if let Some(label) = self.label {
if let Some(WithRange(label, _)) = self.label {
writeln!(out, "\\label{{{}}}", label)?;
}
writeln!(out, "\\end{{{}}}", T::to_str())?;
Expand Down
14 changes: 8 additions & 6 deletions src/backend/latex/complex/footnote_definition.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
use std::io::{Result, Write};
use std::io::Write;

use crate::backend::{Backend, CodeGenUnit};
use crate::config::Config;
use crate::generator::Generator;

use crate::error::Result;
use crate::frontend::range::WithRange;
use crate::generator::event::{Event, FootnoteDefinition};
use crate::generator::Generator;

#[derive(Debug)]
pub struct FootnoteDefinitionGen;

impl<'a> CodeGenUnit<'a, FootnoteDefinition<'a>> for FootnoteDefinitionGen {
fn new(
_cfg: &'a Config, fnote: FootnoteDefinition<'a>,
_cfg: &'a Config, fnote: WithRange<FootnoteDefinition<'a>>,
gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
) -> Result<Self> {
let FootnoteDefinition { label } = fnote;
let WithRange(FootnoteDefinition { label }, _range) = fnote;
// TODO: Add pass to get all definitions to put definition on the same site as the first
// reference
write!(gen.get_out(), "\\footnotetext{{\\label{{fnote:{}}}", label)?;
Ok(FootnoteDefinitionGen)
}

fn finish(
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>, _peek: Option<&Event<'a>>,
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
_peek: Option<WithRange<&Event<'a>>>,
) -> Result<()> {
writeln!(gen.get_out(), "}}")?;
Ok(())
Expand Down
Loading

0 comments on commit 81aa534

Please sign in to comment.