From 26248678aafc2f8e277d4bdafc116f2b349b02c5 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 18 Aug 2017 13:45:49 +0200 Subject: Initial commit --- token.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 token.go (limited to 'token.go') diff --git a/token.go b/token.go new file mode 100644 index 0000000..a6b08b9 --- /dev/null +++ b/token.go @@ -0,0 +1,58 @@ +package cnm + +// Token represents a parsed line in a CNM document. +type Token interface { + Indent() int + Raw() string + Line() int +} + +// TokenLine represents an arbitrary CNM line. +type TokenLine struct { + Indentation int + RawLine string + LineNo int +} + +// Indent returns the indentation of the parsed line. +func (t *TokenLine) Indent() int { return t.Indentation } + +// Raw returns the original unparsed line. +func (t *TokenLine) Raw() string { return t.RawLine } + +// Line returns the line number in the document, starting from 1. +func (t *TokenLine) Line() int { return t.LineNo } + +// TokenEmptyLine represents an empty line. +// +// A line is empty as long as it contains up to as many tab characters as the +// line's indentation and nothing else. +type TokenEmptyLine struct { + TokenLine +} + +// TokenBlock represents a block header line. +type TokenBlock struct { + TokenLine + // Parent is the parent block + Parent *TokenBlock + // Name is the block name. + Name string + // Args are the block arguments, split by whitespace and then parsed as + // simple text. + Args []string +} + +// TokenSimpleText represents a line of simple text. +type TokenSimpleText struct { + TokenLine + // Text is the line contents parsed as simple text. + Text string +} + +// TokenRawText represents a non-empty line with unparsed contents. +type TokenRawText struct { + TokenLine + // Text is the raw contents of the line with the indentation removed. + Text string +} -- cgit