Move decoration into mod.rs 🔙

This commit is contained in:
Laurenz 2020-09-30 12:49:30 +02:00
parent bc1b4216a8
commit 3e791e3337
6 changed files with 27 additions and 49 deletions

View File

@ -4,17 +4,9 @@
//! layout on a best effort process, generating diagnostics for incorrect
//! things.
#[cfg(feature = "serialize")]
use serde::Serialize;
use crate::syntax::SpanVec;
/// A list of spanned diagnostics.
pub type Diagnostics = SpanVec<Diagnostic>;
/// A diagnostic that arose in parsing or layouting.
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
pub struct Diagnostic {
/// How severe / important the diagnostic is.
pub level: Level,
@ -24,7 +16,7 @@ pub struct Diagnostic {
/// How severe / important a diagnostic is.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub enum Level {
Warning,

View File

@ -46,11 +46,11 @@ use std::pin::Pin;
use crate::compute::scope::Scope;
use crate::compute::value::Value;
use crate::diagnostic::Diagnostics;
use crate::diagnostic::Diagnostic;
use crate::font::SharedFontLoader;
use crate::layout::{Commands, MultiLayout};
use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::syntax::{Decorations, Offset, Pos, SyntaxTree};
use crate::syntax::{Decoration, Offset, Pos, SpanVec, SyntaxTree};
/// Transforms source code into typesetted layouts.
///
@ -166,9 +166,9 @@ impl Pass<Value> {
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Feedback {
/// Diagnostics about the source code.
pub diagnostics: Diagnostics,
pub diagnostics: SpanVec<Diagnostic>,
/// Decorations of the source code for semantic syntax highlighting.
pub decorations: Decorations,
pub decorations: SpanVec<Decoration>,
}
impl Feedback {

View File

@ -1,26 +0,0 @@
//! Decorations for semantic syntax highlighting.
#[cfg(feature = "serialize")]
use serde::Serialize;
use super::span::SpanVec;
/// A list of spanned decorations.
pub type Decorations = SpanVec<Decoration>;
/// Decorations for semantic syntax highlighting.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub enum Decoration {
/// Text in italics.
Italic,
/// Text in bold.
Bold,
/// A valid, successfully resolved name.
Resolved,
/// An invalid, unresolved name.
Unresolved,
/// The key part of a key-value entry in a table.
TableKey,
}

View File

@ -1,11 +1,26 @@
//! Syntax types.
mod decoration;
mod span;
mod token;
mod tree;
pub use decoration::*;
pub use span::*;
pub use token::*;
pub use tree::*;
/// Decorations for semantic syntax highlighting.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))]
pub enum Decoration {
/// Text in italics.
Italic,
/// Text in bold.
Bold,
/// A valid, successfully resolved name.
Resolved,
/// An invalid, unresolved name.
Unresolved,
/// The key part of a key-value entry in a table.
TableKey,
}

View File

@ -6,9 +6,6 @@ use std::ops::{Add, Sub};
#[cfg(test)]
use std::cell::Cell;
#[cfg(feature = "serialize")]
use serde::Serialize;
#[cfg(test)]
thread_local! {
static CMP_SPANS: Cell<bool> = Cell::new(true);
@ -34,7 +31,7 @@ impl<T> Offset for SpanVec<T> {
/// A value with the span it corresponds to in the source code.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
pub struct Spanned<T> {
pub span: Span,
pub v: T,
@ -92,7 +89,7 @@ impl<T: Debug> Debug for Spanned<T> {
/// Locates a slice of source code.
#[derive(Copy, Clone, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
pub struct Span {
/// The inclusive start position.
pub start: Pos,
@ -164,7 +161,7 @@ impl Debug for Span {
/// Zero-indexed line-column position in source code.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
pub struct Pos {
/// The zero-indexed line.
pub line: usize,

View File

@ -2,8 +2,8 @@
use std::fmt::{self, Debug, Formatter};
use super::decoration::Decoration;
use super::span::{SpanVec, Spanned};
use super::Decoration;
use crate::color::RgbaColor;
use crate::compute::table::{SpannedEntry, Table};
use crate::compute::value::{TableValue, Value};