Expand description
ยง๐ ๏ธ TSV Parser Developer Guide
Tsv support for the Oak language framework.
This guide is designed to help you quickly get started with developing and integrating oak-tsv.
ยง๐ฆ Quick Start
ยงBasic Parsing Example
The following is a standard workflow for parsing a simple TSV string:
use oak_tsv::{TsvParser, TsvLanguage};
use oak_core::{Parser, source::SourceText, parser::session::ParseSession};
fn main() {
let source = SourceText::new("header1\theader2\nvalue1\tvalue2");
let mut session = ParseSession::<TsvLanguage>::default();
let parser = TsvParser::new();
let result = parser.parse(&source, &[], &mut session);
let ast = result.result.unwrap();
println!("{:#?}", ast);
}ยงAdvanced Usage
For more advanced scenarios, such as customized parsing or handling larger files, you can use the TsvBuilder to construct TSV AST manually.
use oak_tsv::TsvBuilder;
// your code hereยง๐ Core API Usage
ยง1. Syntax Tree Traversal
After a successful parse, you can use the built-in visitor pattern or manually traverse the Green/Red Tree to extract TSV constructs like headers, rows, and individual fields.
ยง2. Incremental Parsing
No need to re-parse massive TSV files when small changes occur:
// Assuming you have an old parse result 'old_result' and new source text 'new_source'
let new_result = parser.parse(&new_source, &[], &mut session);ยง3. Diagnostics
oak-tsv provides rich error contexts specifically tailored for TSV data:
for diag in result.diagnostics {
println!("{:?}", diag);
}ยง๐๏ธ Architecture Overview
- Lexer: Tokenizes TSV source text into a stream of tokens, handling tab delimiters, row separators, and complex quoting logic.
- Parser: Syntax analyzer based on the structural layout of records and fields.
- AST: A strongly-typed syntax abstraction layer designed for building high-performance data processing tools and editors.
ยง๐ Advanced Resources
Re-exportsยง
pub use crate::ast::TsvField;pub use crate::ast::TsvRecord;pub use crate::ast::TsvRoot;pub use crate::builder::TsvBuilder;pub use crate::language::TSV_LANG;pub use crate::language::TsvLanguage;pub use crate::lexer::TsvLexer;pub use crate::parser::TsvParser;pub use crate::lsp::TsvLanguageService;
Modulesยง
- ast
- The AST nodes for TSV.
- builder
- The builder for TSV.
- language
- The language configuration and marker.
- lexer
- The lexer for TSV.
- lsp
- Language service implementation for TSV.
- parser
- The parser for TSV.
Functionsยง
- from_
str - Deserializes a TSV string into a value of type
T. Deserializes a TSV string into a value of typeT. - language
- Returns the default TSV configuration.
- parse
- Parses a TSV string into a
TsvRootAST. - to_
string - Serializes the given value to a TSV string. Serializes the given value to a TSV string.
Type Aliasesยง
- TsvRoot
Node - A TSV root node.