body

package
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package body implements parsing of a rbnf rule body.

See: https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1RuleBasedNumberFormat.html#details

Token format:

substitution = bracket-start substitution-descriptor bracket-end
part = substitution or literal
item = part OR ('[' part* ']') *
substitution = a rule set name starting with %
               OR a DecimalFormat pattern starting with '0' or '#'.
               OR empty

bracket-start, bracket-end pairs are:

→, →
←, ←
=, =
$(, )$

Index

Constants

View Source
const (
	TypeLiteral             // literal text data e.g. " million"
	TypeSubstRightArrow     // →...→, simple
	TypeSubstLeftArrow      // ←...←, simple
	TypeSubstEqualsSign     // =...=, simple
	TypeOptionalStart       // "[" in [...], may contain substitutions and literals
	TypeOptionalEnd         // "]" in [...], may contain substitutions and literals
	TypeSubstPluralCardinal // $(cardinal,plural-syntax)$
	TypeSubstPluralOrdinal  // $(ordinal,plural-syntax)$
	TypeTripleRightArrow    // →→→.
	TypeEOF
)
View Source
const (
	SubstTypeNone = SubstType(iota)
	SubstTypeEmpty
	SubstTypeRulesetName
	SubstTypeDecimalFormat
	SubstTypeInvalid
)

Variables

This section is empty.

Functions

func NewTokenizer

func NewTokenizer(s string) (next func() (Token, error))

Types

type Slice

type Slice [2]int // byte offsets into the input string

func (Slice) Len

func (s Slice) Len() int

func (Slice) Of

func (s Slice) Of(str string) string

type SubstType

type SubstType uint8

type Token

type Token struct {
	Type    Type
	Content Slice
}

Token represents one broken-down component of a rule body. Where it includes string data (such as a substitution descriptor or literal text), this is represented by a Slice containing indexes into the original string initially passed to the tokenizer.

Tokens produced by a stream either contain an empty slice, or the slice indexes are non-overlapping and the start index is greater than or equal to any previous token's slice end index.

func (Token) SimpleSubstType

func (t Token) SimpleSubstType(s string) SubstType

SimpleSubstType returns the type of substitution descriptor appearing between delimiters e.g. "→→" (empty), "=%RulesetName=" "=#DecimalFormat=". The string argument is the rule body string that the token content slice applies to.

type Type

type Type uint8

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL