summaryrefslogtreecommitdiffstats
path: root/token.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-18 13:45:49 +0200
committerclsr <clsr@clsr.net>2017-08-18 13:45:49 +0200
commit26248678aafc2f8e277d4bdafc116f2b349b02c5 (patch)
tree15f82488edb8c05aae756443284731875f36737c /token.go
downloadcnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.tar.gz
cnm-go-26248678aafc2f8e277d4bdafc116f2b349b02c5.zip
Initial commitv0.1.0
Diffstat (limited to 'token.go')
-rw-r--r--token.go58
1 files changed, 58 insertions, 0 deletions
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
+}