Narratives - craterdog/go-component-framework GitHub Wiki

Overview

A narrative string is a sequence of text lines. Each narrative string has the following string format:

$narrative: '"' '>' (ANY | EOL)* '<' '"'

The source of this format is Bali Document Notation™ (Bali) defined here.

UML Diagram

A Quick Example

To whet your appetite, here is some short example code that demonstrates the use of narrative strings.

package main

import (
	fmt "fmt"
	fra "github.com/craterdog/go-component-framework/v7"
)

func main() {
	// Create a new narrative string using the module level constructor shortcut.
	var haiku = fra.NarrativeFromString(
		`">
    Cascading Water
    Shimmering in the Moonlight
    Sweet Serenity
        -Derk Norton
<"
`,
	)
	fmt.Println(haiku)
	fmt.Println()

	// Iterate through the lines of the narrative string.
	var iterator = haiku.GetIterator()
	for iterator.HasNext() {
		var line = iterator.GetNext()
		fmt.Println(line)
	}
}

Try it out in the Go Playground...