Skip to main content

oak_tsv/
lib.rs

1#![doc = include_str!("readme.md")]
2#![feature(new_range_api)]
3#![warn(missing_docs)]
4
5/// The AST nodes for TSV.
6pub mod ast;
7/// The builder for TSV.
8pub mod builder;
9/// The language configuration and marker.
10pub mod language;
11/// The lexer for TSV.
12pub mod lexer;
13/// The parser for TSV.
14pub mod parser;
15
16/// Language service implementation for TSV.
17#[cfg(feature = "lsp")]
18pub mod lsp;
19
20pub use crate::{
21    ast::{TsvField, TsvRecord, TsvRoot},
22    builder::TsvBuilder,
23    language::{TSV_LANG, TsvLanguage},
24    lexer::TsvLexer,
25    parser::TsvParser,
26};
27
28/// A TSV root node.
29pub type TsvRootNode = crate::ast::TsvRoot;
30
31/// Serializes the given value to a TSV string.
32#[cfg(feature = "serde")]
33/// Serializes the given value to a TSV string.
34pub fn to_string<T: ::serde::Serialize>(value: &T) -> Result<String, oak_core::OakError> {
35    oak_dsv::to_string_with_config::<TSV_LANG, T>(value)
36}
37
38/// Deserializes a TSV string into a value of type `T`.
39#[cfg(feature = "serde")]
40/// Deserializes a TSV string into a value of type `T`.
41pub fn from_str<T: ::serde::de::DeserializeOwned>(s: &str) -> Result<T, oak_core::OakError> {
42    oak_dsv::from_str_with_config::<TSV_LANG, T>(s)
43}
44
45/// Returns the default TSV configuration.
46pub fn language() -> oak_dsv::DsvLanguage {
47    TSV_LANG
48}
49
50/// Parses a TSV string into a `TsvRoot` AST.
51pub fn parse(tsv: &str) -> Result<crate::ast::TsvRoot, oak_core::OakError> {
52    use oak_core::{Builder, parser::session::ParseSession, source::SourceText};
53    let builder = TsvBuilder::new();
54    let source = SourceText::new(tsv.to_string());
55    let mut cache = ParseSession::default();
56    let result = builder.build(&source, &[], &mut cache);
57    result.result
58}
59
60/// Language service implementation for TSV.
61#[cfg(feature = "lsp")]
62pub use crate::lsp::TsvLanguageService;