MoonTTL is a high-performance RDF parsing and serialization library for MoonBit, supporting Turtle, TriG, N-Triples, N-Quads and N3 formats.
{
"name": "your_username/your_project",
"deps": [
"thy7/moonttl"
]
}moon run src/cmd/main -- "<http://example.org/s> <http://example.org/p> <http://example.org/o> ."echo '<http://example.org/s> <http://example.org/p> <http://example.org/o> .' > test.nq
moon run src/cmd/main -- -f test.nqmoon run src/cmd/main -- -v -f test.nq<subject> <predicate> <object> <graph> .<http://example.org/s> <http://example.org/p> <http://example.org/o> .let content = "<http://example.org/s> <http://example.org/p> <http://example.org/o> .\n"
let data = @utf8.encode(content)
let lexer = @lib.Lexer::Lexer(
@lib.RdfLexer::RdfLexer(@lib.RdfLexerMode::NTriples, false),
data.to_array(),
true,
@lib.MIN_BUFFER_SIZE,
@lib.MAX_BUFFER_SIZE,
Some(b"#"),
0,
0,
)
let machine = @lib.NQuadsRecognizer::{
stack: [@lib.NQuadsState::ExpectSubject],
subjects: [],
predicates: [],
objects: [],
lenient: false,
debug_logger: @lib.make_mute_logger(),
last_range: @lib.Range::default(),
errors: [],
}
let context = @lib.RdfContext::NQuadsRecognizerContext(
@lib.NQuadsRecognizerContext::{
with_graph_name: false,
lexer_options: { base_iri: None },
},
)
let parser = @lib.ParserM::{
lexer,
engine: @lib.GenericStateMachine::{ machine, context, outputs: [] },
context,
errors: [],
}
for ;; {
match parser.parse_next() {
Some(Ok(quad)) => println("Parsed: \{quad}")
Some(Err(e)) => println("Error: \{e}")
None => break
}
}src/
├── lexer_*.mbt # 词法分析器
├── parser*.mbt # 语法分析器
├── nquads_*.mbt # N-Quads 格式支持
├── turtle_*.mbt # Turtle 格式支持
├── trig_*.mbt # TriG 格式支持
├── n3_*.mbt # N3 格式支持
├── iri.mbt # IRI 处理
├── literal.mbt # 字面量处理
├── langtag.mbt # 语言标签处理
└── tests/ # 测试文件moon run src/examples/nquadsWritten N-Quads content to: ./example.nq
Parsing N-Quads file...
[1] Quad<http://example.org/s1, http://example.org/p1, http://example.org/o1>
[2] Quad<http://example.org/s2, http://example.org/p2, http://example.org/o2>
[3] Quad<http://example.org/s3, http://example.org/p3, http://example.org/o3>
[4] Error: InvalidTurtleToken - Unexpected end of input turtle .
=== Summary ===
Total quads parsed: 3test {
let x = @ref.Ref(42)
@test.assert_eq(x.val, 42)
x.val = 100
@test.assert_eq(x.val, 100)
}pub trait DebugLogger {
fn info(Self, String) -> Unit
fn error(Self, String) -> Unit
fn warn(Self, String) -> Unit
}pub trait ErrOut {
fn message(self : Self) -> String
fn err_kind(self : Self) -> String
}pub trait IriComponents {
fn query(self : Self) -> String?
fn is_absolute(self : Self) -> Bool
fn scheme(self : Self) -> String?
fn authority(self : Self) -> String?
fn path(self : Self) -> String?
fn fragment(self : Self) -> String?
}pub trait RuleRecognizer {
fn error_recovery_state(Self) -> Self
fn recognize_next(Self, token : LocatedTokenOrLineJump, context : RdfContext, results : Array[RdfOut]) -> Self
fn recognize_end(Self, context : RdfContext, results : Array[RdfOut]) -> Unit
fn lexer_options(context : RdfContext) -> LexerOptions?
fn[DL : DebugLogger] debug_logger(Self, debug_logger : DL) -> Unit
}pub trait StateMachine {
fn initial_state(Self) -> RdfState
fn transition(Self, state : RdfState, event : LocatedTokenOrLineJump, context : RdfContext) -> Result[(Self, RdfState, RdfOut?), RuleRecognizerError]
fn current_state(Self) -> RdfState
fn step(Self, event : LocatedTokenOrLineJump) -> Self
fn reset(Self) -> Self
fn is_accepting(Self) -> Bool
fn context(Self) -> RdfContext
fn set_context(Self, RdfContext) -> Self
fn[ST : StateWrapper] set_current_state(Self, state : ST) -> Self
fn error_recovery_statemachine(Self) -> Self
}pub trait StringRepr {
fn as_stringview(self : Self) -> StringView
fn into_string(self : Self) -> String
}pub trait TokenRecognizer {
fn recognize_next_token(Self, data : ArrayView[Byte], is_ending : Bool, options : LexerOptions?, location_ctx : SourcePos) -> (Int, Result[LocatedTokenOrLineJump, TokenRecognizerError])?
}pub(all) suberror IriError {
NoScheme
Expected(Char, Int)
InvalidIriCodePoint(Char, Int)
InvalidPercentEncoding(Int)
InvalidHostCharacter(Char, Int)
InvalidHostIp(String, Int)
InvalidPortCharacter(Char, Int)
PathStartingWithTwoSlashes(Int)
RelativePathSegment(Char, Int)
InvalidErrMessage(String)
}pub(all) suberror LexerError {
OutOfMemory(String)
IoReadError(String)
SyntaxError(String)
}pub(all) suberror RuleRecognizerError {
SyntaxError(String, Range)
BlankNodeOrIriError
PredicateNotAnIRI
LiteralDatatypeError
TripleMissingDot
InvalidLanguageTag
BlankNodePropertyListMissingEndBracket
}pub(all) suberror TagParseErr {
EmptyExtension
EmptyPrivateUse
ForbiddenChar
InvalidSubtag
InvalidLanguage
SubtagTooLong
EmptySubtag
TooManyExtlangs
InvalidLanguageLength
}impl Show for TagParseErrpub(all) suberror TokenRecognizerError {
Invalid
InvalidFormat(ArrayView[Byte], Range)
InvalidToken(ArrayView[Byte], Range)
InvalidCharacter(ArrayView[Byte], Range)
IncompleteEscapeSequence(ArrayView[Byte], Range)
InvalidEscapeSequence(ArrayView[Byte], Range)
UnsupportedFeature(ArrayView[Byte], Range)
IriTruncated(ArrayView[Byte], Range)
IriParsingError(String, Range)
UnexpectedEndOfInput(ArrayView[Byte], Range)
InvalidErrMessage(ArrayView[Byte], Range, String)
}async fn[TR : TokenRecognizer, RR : RuleRecognizer] AsyncReaderIterator::next(self : AsyncReaderIterator[TR, RR]) -> Result[RdfOut, LexerError]?async fn[RL : TokenRecognizer] AsyncReaderN3Parser::next(self : AsyncReaderN3Parser[RL]) -> Result[N3Quad, TurtleError]?async fn[RL : TokenRecognizer] AsyncReaderNQuadsParser::next(self : AsyncReaderNQuadsParser[RL]) -> Result[RdfOut, LexerError]?async fn[RL : TokenRecognizer] AsyncReaderNTriplesParser::next(self : AsyncReaderNTriplesParser[RL]) -> Result[RdfOut, LexerError]?async fn[RL : TokenRecognizer] AsyncReaderTriGParser::next(self : AsyncReaderTriGParser[RL]) -> Result[Quad, TurtleError]?async fn[RL : TokenRecognizer] AsyncReaderTurtleParser::next(self : AsyncReaderTurtleParser[RL]) -> Result[N3Quad, TurtleError]?pub struct AsyncWriterNQuadsSerializer[W] {
buffer_writer : BufferedWriter[W]
low_level_writer : LowLevelNQuadsSerializer
}async fn[W : Writer] AsyncWriterNQuadsSerializer::finish(self : AsyncWriterNQuadsSerializer[W]) -> Result[BufferedWriter[W], Unit]async fn[W : Writer] AsyncWriterNQuadsSerializer::serialize_quad(self : AsyncWriterNQuadsSerializer[W], q : Quad) -> Result[AsyncWriterNQuadsSerializer[W], SerializationError]pub struct AsyncWriterNTriplesSerializer[W] {
buffer_writer : BufferedWriter[W]
low_level_writer : LowLevelNTriplesSerializer
}async fn[W : Writer] AsyncWriterNTriplesSerializer::finish(self : AsyncWriterNTriplesSerializer[W]) -> Result[BufferedWriter[W], Unit]fn[W] AsyncWriterNTriplesSerializer::serialize_triple(self : AsyncWriterNTriplesSerializer[W], t : Triple) -> Result[String, Unit]pub struct AsyncWriterTriGSerializer[W] {
buffer_writer : BufferedWriter[W]
low_level_writer : LowLevelTriGSerializer
}async fn[W : Writer] AsyncWriterTriGSerializer::finish(self : AsyncWriterTriGSerializer[W]) -> Result[BufferedWriter[W], Unit]async fn[W : Writer] AsyncWriterTriGSerializer::serialize_quad(self : AsyncWriterTriGSerializer[W], q : Quad) -> Result[AsyncWriterTriGSerializer[W], SerializationError]pub struct AsyncWriterTurtleSerializer[W] {
buffer_writer : BufferedWriter[W]
low_level_writer : LowLevelTriGSerializer
}fn[W] AsyncWriterTurtleSerializer::serialize_triple(self : AsyncWriterTurtleSerializer[W], t : Triple) -> Result[String, Unit]impl Show for BaseDirectionpub(all) enum Command {
ParseQuad(NamedOrBlankNodeRef, NamedNodeRef, TermRef, GraphNameRef)
ParseTriple(NamedOrBlankNodeRef, NamedNodeRef, TermRef)
ParseLiteralQuad(NamedOrBlankNodeRef, NamedNodeRef, String, String, GraphNameRef)
ParseTypedLiteral(NamedOrBlankNodeRef, NamedNodeRef, String, NamedNodeRef, GraphNameRef)
ParseBlankSubject(BlankNodeRef, NamedNodeRef, TermRef, GraphNameRef)
ParseBlankObject(NamedOrBlankNodeRef, NamedNodeRef, BlankNodeRef, GraphNameRef)
} derive(Eq, Debug)impl StateMachine for GenericStateMachine[M]fn[M : StateMachine] error_recovery_statemachine(self : GenericStateMachine[M]) -> GenericStateMachine[M]fn[M : StateMachine] set_context(self : GenericStateMachine[M], new_context : RdfContext) -> GenericStateMachine[M]fn[M : StateMachine, ST : StateWrapper] set_current_state(self : GenericStateMachine[M], state : ST) -> GenericStateMachine[M]fn[M : StateMachine] step(self : GenericStateMachine[M], event : LocatedTokenOrLineJump) -> GenericStateMachine[M]fn[M : StateMachine] transition(self : GenericStateMachine[M], state : RdfState, event : LocatedTokenOrLineJump, context : RdfContext) -> Result[(GenericStateMachine[M], RdfState, RdfOut?), RuleRecognizerError]fn[M] GenericStateMachine::GenericStateMachine(machine : M, context : RdfContext) -> GenericStateMachine[M]fn[M] GenericStateMachine::remove_first_output(self : GenericStateMachine[M]) -> GenericStateMachine[M]fn[M : StateMachine] GenericStateMachine::run(self : GenericStateMachine[M], events : Array[LocatedTokenOrLineJump]) -> Result[Array[RdfOut], RuleRecognizerError]?pub(all) enum GraphNameRef {
DefaultGraph
NamedNodeRef(NamedNodeRef)
BlankNodeRef(BlankNodeRef)
} derive(Eq, Hash, Debug)impl IriComponents for IriRefimpl StringRepr for IriReffn IriRef::resolve_into(self : IriRef, relative_ref : String, buffer : StringBuilder) -> Result[Unit, IriError]pub(all) struct LanguageTag {
tag : String
positions : TagElementsPositions
} derive(Default, Eq, Hash, Debug)impl Show for LanguageTagasync fn[RL] Lexer::extend_from_async_read(self : Lexer[RL], reader : &Reader) -> Result[Int, LexerError]async fn[RL] Lexer::extend_from_reader(self : Lexer[RL], reader : &Reader) -> Result[Int, LexerError]fn[RL] Lexer::location_from_buffer_offset_range(self : Lexer[RL], offset_range : Range) -> SourceRangefn[RL : TokenRecognizer] Lexer::parse_next(self : Lexer[RL], options : LexerOptions?) -> Result[LocatedTokenOrLineJump, TokenRecognizerError]?fn Literal::new_directional_language_tagged_literal(value : String, language : String, direction : BaseDirection) -> Result[Literal, LanguageTagParseError]fn Literal::new_directional_language_tagged_literal_unchecked(value : StringView, language : LanguageTag, direction : BaseDirection) -> Literalfn Literal::new_language_tagged_literal(value : String, language : String) -> Result[Literal, LanguageTagParseError]pub(all) enum LiteralContent {
String(String)
LanguageTaggedString(value~ : String, language~ : String)
DirectionalLanguageTaggedString(value~ : StringView, language~ : String, direction~ : BaseDirection)
TypedLiteral(value~ : VarDataType, datatype~ : NamedNode)
} derive(Eq, Hash, Debug)impl Show for LiteralReffn LiteralRef::new_directional_language_tagged_literal_unchecked(value : String, language : LanguageTag, direction : BaseDirection) -> LiteralReffn LiteralRef::new_language_tagged_literal_unchecked(value : String, language : StringView) -> LiteralRefpub(all) enum LiteralRefContent {
String(StringView)
LanguageTaggedString(value~ : String, language~ : StringView)
DirectionalLanguageTaggedString(value~ : StringView, language~ : StringView, direction~ : BaseDirection)
TypedLiteral(value~ : VarDataType, datatype~ : NamedNodeRef)
} derive(Eq, Hash, Debug)impl Show for LocatedN3Token#alias(Event)
pub enum LocatedTokenOrLineJump {
LocatedN3Token(LocatedN3Token)
LineJump(Int)
End
} derive(Debug)fn[RL : TokenRecognizer] LowLevelN3Parser::parse_next(self : LowLevelN3Parser[RL]) -> Result[RdfOut, TurtleError]?fn[RL] LowLevelNQuadsParser::extend_from_slice(self : LowLevelNQuadsParser[RL], other : Bytes) -> Unitfn[RL : TokenRecognizer] LowLevelNQuadsParser::parse_next(self : LowLevelNQuadsParser[RL]) -> Result[Quad, TurtleError]?fn LowLevelNQuadsSerializer::serialize_quad(_self : LowLevelNQuadsSerializer, q : Quad) -> Result[String, Unit]fn LowLevelNTriplesParser::extend_from_slice(self : LowLevelNTriplesParser[RdfLexer], other : Bytes) -> Unitfn[RL : TokenRecognizer] LowLevelNTriplesParser::parse_next(self : LowLevelNTriplesParser[RL]) -> Result[Triple, TurtleError]?fn LowLevelNTriplesSerializer::serialize_triple(_self : LowLevelNTriplesSerializer, t : Triple) -> Result[String, Unit]fn[RL : TokenRecognizer] LowLevelTriGParser::parse_next(self : LowLevelTriGParser[RL]) -> Result[Quad, TurtleError]?pub struct LowLevelTriGSerializer {
prefixes : Array[(String, String)]
base_iri : Iri?
prelude_written : Bool
current_graph_name : GraphName
current_subject_predicate : (NamedOrBlankNode, NamedNode)?
}async fn[W : Writer] LowLevelTriGSerializer::finish(self : LowLevelTriGSerializer, writer : BufferedWriter[W]) -> Result[Unit, Unit]fn LowLevelTriGSerializer::serialize_quad(self : LowLevelTriGSerializer, q : Quad) -> Result[String, Unit]fn[RL] LowLevelTurtleParser::extend_from_slice(self : LowLevelTurtleParser[RL], other : Bytes) -> Unitfn[RL : TokenRecognizer] LowLevelTurtleParser::parse_next(self : LowLevelTurtleParser[RL]) -> Result[RdfOut, TurtleError]?async fn[W : Writer] LowLevelTurtleSerializer::finish(self : LowLevelTurtleSerializer, writer : BufferedWriter[W]) -> Result[Unit, Unit]fn LowLevelTurtleSerializer::serialize_triple(self : LowLevelTurtleSerializer, t : Triple) -> Result[String, Unit]type N3Recognizerimpl RuleRecognizer for N3Recognizerfn recognize_next(self : N3Recognizer, token : LocatedTokenOrLineJump, context : RdfContext, results : Array[RdfOut]) -> N3Recognizerimpl StateMachine for N3Recognizerfn transition(self : N3Recognizer, state : RdfState, event : LocatedTokenOrLineJump, context : RdfContext) -> Result[(N3Recognizer, RdfState, RdfOut?), RuleRecognizerError]fn N3Recognizer::new_parser(data : Array[Byte], is_ending : Bool, unchecked : Bool, base_iri : Iri?, prefixes : Map[String, Iri], debug_logger? : &DebugLogger) -> Parser[RdfLexer, N3Recognizer]type N3RecognizerContextpub(all) enum N3Token {
Iri(String)
PrefixedName(prefix~ : String, localx~ : String, might_be_invalid_iri~ : Bool)
Variable(String)
BlankNodeLabel(String)
String(String)
LongString(String)
Integer(String)
Decimal(String)
Double(String)
LangTag(language~ : String, direction~ : BaseDirection?)
Punctuation(String)
PlainKeyword(String)
} derive(Eq, Debug)fn NQuadsParser::for_async_reader(self : NQuadsParser, reader : &Reader) -> AsyncReaderNQuadsParser[RdfLexer]fn NQuadsParser::for_slice(self : NQuadsParser, slice : BytesView) -> SliceNQuadsParser[NQuadsRecognizer]async fn NQuadsParser::split_file_for_parallel_parsing(self : NQuadsParser, path : String, target_parallelism : Int64) -> Result[Array[SliceNQuadsParser[NQuadsRecognizer]], String]fn NQuadsParser::split_slice_for_parallel_parsing(self : NQuadsParser, slice : BytesView, target_parallelism : Int) -> Array[SliceNQuadsParser[NQuadsRecognizer]]pub(all) struct NQuadsRecognizer {
stack : Array[NQuadsState]
subjects : Array[NamedOrBlankNodeRef]
predicates : Array[NamedNodeRef]
objects : Array[TermRef]
lenient : Bool
debug_logger : &DebugLogger
last_range : Range
errors : Array[RuleRecognizerError]
}impl RuleRecognizer for NQuadsRecognizerfn recognize_next(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, context : RdfContext, results : Array[RdfOut]) -> NQuadsRecognizerimpl StateMachine for NQuadsRecognizerfn transition(self : NQuadsRecognizer, state : RdfState, event : LocatedTokenOrLineJump, context : RdfContext) -> Result[(NQuadsRecognizer, RdfState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::handle_after_quoted_triple_m(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, _ctx : NQuadsRecognizerContext) -> Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::handle_expect_line_jump_m(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, _ctx : NQuadsRecognizerContext) -> Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::handle_expect_literal_datatype_m(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, _ctx : NQuadsRecognizerContext, value : String) -> Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::handle_expect_possible_graph_or_end_of_quoted_triple_m(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, ctx : NQuadsRecognizerContext) -> Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::handle_recover_to_line_jump_m(self : NQuadsRecognizer, token : LocatedTokenOrLineJump, _ctx : NQuadsRecognizerContext) -> Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]fn NQuadsRecognizer::new_parser(data : Array[Byte], with_graph_name : Bool, lenient : Bool, debug_logger? : &DebugLogger) -> Parser[RdfLexer, NQuadsRecognizer]fn NQuadsRecognizer::process_transition_result(self : NQuadsRecognizer, current_state : NQuadsState, result : Result[(NQuadsRecognizer, NQuadsState, RdfOut?), RuleRecognizerError]) -> (NQuadsRecognizer, RdfState, RdfOut?)fn[W] NQuadsSerializer::for_async_writer(self : NQuadsSerializer, buffer_writer : BufferedWriter[W]) -> AsyncWriterNQuadsSerializer[W]fn[W] NQuadsSerializer::for_writer(self : NQuadsSerializer, writer : W) -> WriterNQuadsSerializer[W]fn NTriplesParser::for_async_reader(self : NTriplesParser, reader : &Reader) -> AsyncReaderNTriplesParser[RdfLexer]fn NTriplesParser::for_reader(self : NTriplesParser, reader : &Reader) -> ReaderNTriplesParser[RdfLexer]fn NTriplesParser::for_slice(self : NTriplesParser, slice : BytesView) -> SliceNTriplesParser[NQuadsRecognizer]async fn NTriplesParser::split_file_for_parallel_parsing(self : NTriplesParser, path : String, target_parallelism : Int64) -> Result[Array[SliceNTriplesParser[NQuadsRecognizer]], String]fn NTriplesParser::split_slice_for_parallel_parsing(self : NTriplesParser, slice : BytesView, target_parallelism : Int) -> Array[SliceNTriplesParser[NQuadsRecognizer]]fn[W] NTriplesSerializer::for_async_writer(self : NTriplesSerializer, buffer_writer : BufferedWriter[W]) -> AsyncWriterNTriplesSerializer[W]fn[W] NTriplesSerializer::for_writer(self : NTriplesSerializer, writer : W) -> WriterNTriplesSerializer[W]impl Show for NamedOrBlankNodepub enum NamedOrBlankNodeRef {
NamedNodeRef(NamedNodeRef)
BlankNodeRef(BlankNodeRef)
} derive(Eq, Hash, Debug)pub(all) struct Parser[TR, RR] {
lexer : Lexer[TR]
state : RR?
context : RdfContext
results : Array[RdfOut]
errors : Array[RuleRecognizerError]
}fn[TR, RR] Parser::Parser(lexer : Lexer[TR], recognizer : RR, context : RdfContext) -> Parser[TR, RR]fn[TR, RR] Parser::for_async_reader(self : Parser[TR, RR], reader : &Reader) -> AsyncReaderIterator[TR, RR]fn[TR : TokenRecognizer, RR : RuleRecognizer] Parser::parse_next(self : Parser[TR, RR]) -> Result[RdfOut, TurtleError]?pub(all) struct ParserM[TR, M] {
lexer : Lexer[TR]
engine : GenericStateMachine[M]
context : RdfContext
errors : Array[RuleRecognizerError]
}fn[TR, M] ParserM::ParserM(lexer : Lexer[TR], engine : GenericStateMachine[M], context : RdfContext) -> ParserM[TR, M]fn[TR : TokenRecognizer, M : StateMachine + RuleRecognizer] ParserM::parse_next(self : ParserM[TR, M]) -> Result[RdfOut, TurtleError]?pub struct QuadRef {
subject : NamedOrBlankNodeRef
predicate : NamedNodeRef
object : TermRef
graph_name : GraphNameRef
}#alias(Ctx)
pub(all) enum RdfContext {
TriGRecognizerContext(TriGRecognizerContext)
NQuadsRecognizerContext(NQuadsRecognizerContext)
N3RecognizerContext(N3RecognizerContext)
}impl TokenRecognizer for RdfLexerfn recognize_next_token(self : RdfLexer, data : ArrayView[Byte], is_ending : Bool, options : LexerOptions?, location_ctx : SourcePos) -> (Int, Result[LocatedTokenOrLineJump, TokenRecognizerError])?pub(all) enum RdfState {
TriGState(TriGState)
NQuadsState(NQuadsState)
N3State(N3State)
} derive(Eq, Hash)async fn[RR : RuleRecognizer] ReaderIterator::next(self : ReaderIterator[RdfLexer, RR]) -> Result[RdfOut, LexerError]?pub(all) enum SerializationError {
FormatError(String)
IoError(String)
}impl Show for SerializationErrorfn[TR : TokenRecognizer, RR : RuleRecognizer] SliceIterator::next(self : SliceIterator[TR, RR]) -> Result[RdfOut, LexerError]?impl Show for SourceRangepub(all) enum SubtagType {
PrivateUseIntro
ExtensionIntro(Char)
Alphabetic(Int)
Numeric(Int)
Alphanumeric(Int)
Invalid
}pub(all) enum TermRef {
NamedNodeRef(NamedNodeRef)
BlankNodeRef(BlankNodeRef)
LiteralRef(LiteralRef)
TripleRef(TripleRef)
} derive(Eq, Hash, Debug)pub(all) enum Token {
Iri(String)
PnameLn(String)
PnameNs(String)
BlankNodeLabel(String)
StringLiteral1(String)
StringLiteral2(String)
StringLiteralLong1(String)
StringLiteralLong2(String)
LangDir(String)
Integer(String)
Decimal(String)
Double(String)
IntegerPositive(String)
DecimalPositive(String)
DoublePositive(String)
IntegerNegative(String)
DecimalNegative(String)
DoubleNegative(String)
Var1(String)
Var2(String)
Keyword(String)
Operator(String)
Error(String)
} derive(Eq, Debug)fn TriGParser::for_async_reader(self : TriGParser, reader : &Reader) -> AsyncReaderTriGParser[RdfLexer]fn TriGParser::with_prefix(self : TriGParser, prefix_name : String, prefix_iri : IriRef) -> Result[TriGParser, IriError]pub(all) struct TriGRecognizer {
stack : Array[TriGState]
cur_subject : Array[NamedOrBlankNodeRef]
cur_predicate : Array[NamedNodeRef]
cur_object : Array[TermRef]
cur_graph : GraphNameRef
cur_reifier : Array[NamedOrBlankNodeRef]
lenient : Bool
debug_logger : &DebugLogger
last_range : Range
errors : Array[RuleRecognizerError]
}impl Show for TriGRecognizerimpl RuleRecognizer for TriGRecognizerfn recognize_next(self : TriGRecognizer, token : LocatedTokenOrLineJump, context : RdfContext, results : Array[RdfOut]) -> TriGRecognizerimpl StateMachine for TriGRecognizerfn transition(self : TriGRecognizer, state : RdfState, event : LocatedTokenOrLineJump, context : RdfContext) -> Result[(TriGRecognizer, RdfState, RdfOut?), RuleRecognizerError]fn TriGRecognizer::new_parser(data : Array[Byte], is_ending : Bool, with_graph_name : Bool, lenient : Bool, base_iri : Iri?, prefixes : Map[String, Iri], debug_logger? : &DebugLogger) -> Parser[RdfLexer, TriGRecognizer]fn TriGRecognizer::process_transition_result(self : TriGRecognizer, current_state : TriGState, result : Result[(TriGRecognizer, TriGState, RdfOut?), RuleRecognizerError]) -> (TriGRecognizer, RdfState, RdfOut?)pub(all) struct TriGRecognizerContext {
lexer_options : LexerOptions
with_graph_name : Bool
prefixes : Map[String, Iri]
}fn TriGRecognizerContext::TriGRecognizerContext(lexer_options : LexerOptions, with_graph_name : Bool, prefixes : Map[String, Iri]) -> TriGRecognizerContextfn[W] TriGSerializer::for_async_writer(self : TriGSerializer, writer : BufferedWriter[W]) -> AsyncWriterTriGSerializer[W]fn TriGSerializer::with_base_iri(self : TriGSerializer, base_iri : IriRef) -> Result[TriGSerializer, IriError]fn TriGSerializer::with_prefix(self : TriGSerializer, prefix_name : String, prefix_iri : IriRef) -> Result[TriGSerializer, IriError]pub(all) enum TriGState {
ExpectAtKeyword
TriGDoc
ExpectDot
BaseExpectIri
PrefixExpectPrefix
PrefixExpectIri(name~ : String)
VersionExpectVersion
TriplesOrGraph
WrappedGraphBlankNodePropertyListCurrent
SubjectBlankNodePropertyListEnd
SubjectBlankNodePropertyListAfter
SubjectCollectionBeginning
SubjectCollectionPossibleEnd
WrappedGraphOrPredicateObjectList(term~ : NamedOrBlankNodeRef)
WrappedGraph
WrappedGraphPossibleEnd
GraphName
GraphNameAnonEnd
Triples
TriplesBlankNodePropertyListCurrent
MaybePredicateObjectList
PredicateObjectList
PredicateObjectListEnd
PredicateObjectListPossibleContinuation
ObjectsList
AnnotationBlock(with_reifier~ : Bool)
AnnotationEnd(with_reifier~ : Bool)
Verb
Object
ObjectBlankNodePropertyListCurrent
ObjectBlankNodePropertyListEnd
ObjectCollectionBeginning
ObjectCollectionPossibleEnd
LiteralPossibleSuffix(value~ : String, emit~ : Bool)
LiteralExpectDatatype(value~ : String, emit~ : Bool)
SubjectReifiedTripleEnd
ObjectReifiedTripleEnd(emit~ : Bool)
TripleTermEnd(emit~ : Bool)
EndOfReifiedTripleBeforeReifier
Reifier(triple~ : Triple)
ReifiedTripleSubject(is_reified~ : Bool)
ReifiedTripleObject(is_reified~ : Bool)
QuotedAnonEnd
InCollection
CollectionElement
CollectionEnd
} derive(Eq, Hash, Debug)fn Triple::from_terms(subject : NamedOrBlankNode, predicate : NamedNode, object : Term) -> Result[Triple, TryFromTermError]pub struct TripleRef {
subject : NamedOrBlankNodeRef
predicate : NamedNodeRef
object : TermRef
} derive(Eq, Hash, Debug)fn TripleRef::TripleRef(subject : NamedOrBlankNodeRef, predicate : NamedNodeRef, object : TermRef) -> TripleReffn TurtleParser::for_async_reader(self : TurtleParser, reader : &Reader) -> AsyncReaderTurtleParser[RdfLexer]fn TurtleParser::for_slice(self : TurtleParser, slice : BytesView) -> SliceTurtleParser[TriGRecognizer]fn TurtleParser::split_slice_for_parallel_parsing(self : TurtleParser, slice : BytesView, target_parallelism : Int) -> Array[SliceTurtleParser[TriGRecognizer]]fn TurtleParser::with_base_iri(self : TurtleParser, base_iri : IriRef) -> Result[TurtleParser, IriError]fn TurtleParser::with_prefix(self : TurtleParser, prefix_name : String, prefix_iri : IriRef) -> Result[TurtleParser, IriError]fn[W] TurtleSerializer::for_async_writer(self : TurtleSerializer, writer : BufferedWriter[W]) -> AsyncWriterTurtleSerializer[W]fn[W] TurtleSerializer::for_writer(self : TurtleSerializer, writer : W) -> WriterTurtleSerializer[W]fn TurtleSerializer::with_base_iri(self : TurtleSerializer, base_iri : IriRef) -> Result[TurtleSerializer, IriError]fn TurtleSerializer::with_prefix(self : TurtleSerializer, prefix_name : String, prefix_iri : IriRef) -> Result[TurtleSerializer, IriError]fn[W] WriterNQuadsSerializer::serialize_quad(self : WriterNQuadsSerializer[W], q : Quad) -> Result[String, Unit]fn[W] WriterNTriplesSerializer::serialize_triple(self : WriterNTriplesSerializer[W], t : Triple) -> Result[String, Unit]fn[W] WriterTriGSerializer::serialize_quad(self : WriterTriGSerializer[W], q : Quad) -> Result[String, Unit]fn[W] WriterTurtleSerializer::serialize_triple(self : WriterTurtleSerializer[W], t : Triple) -> Result[String, Unit]fn find_newline_in_range(bytes : BytesView, start : Int, end : Int) -> Int?fn resolve_local_name(prefix : String, localx : String, might_be_invalid_iri : Bool, prefixes : Map[String, Iri]) -> Result[NamedNodeRef, String]Install
Download zipMoonTTL is a high-performance RDF parsing and serialization library for MoonBit, supporting Turtle, TriG, N-Triples, N-Quads and N3 formats.