diff --git a/builtins.go b/builtins.go index 1f7398d..dc809e8 100644 --- a/builtins.go +++ b/builtins.go @@ -58,6 +58,15 @@ func (b *Builtins) OpenComment(c *Context) func(string) error { } } +// EOLComment discards the rest of the parsed line +func (b *Builtins) EOLComment(c *Context) func(string) error { + return func(next string) error { + j, _ := c.RStack.Pop() + c.RStack.Push(j + len(next)) // push the end-point onto the stack + return nil + } +} + // CloseComment resumes parsing by consuming itself and resetting the immediate flag func (b *Builtins) CloseComment(c *Context) func(string) error { return func(_ string) error { diff --git a/main.go b/main.go index 2ff5808..292f231 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ func main() { // comments and strings dict.AddWord("(", Word{Name: "(", Impl: b.OpenComment(&c), Immediate: true}) dict.AddWord(")", Word{Name: ")", Impl: b.CloseComment(&c), Immediate: true}) + dict.AddWord(`\`, Word{Name: `\`, Impl: b.EOLComment(&c), Immediate: true}) dict.AddWord(`."`, Word{Name: `."`, Impl: b.OpenQuote(os.Stdout, &rstack, '"')}) dict.AddWord(`"`, Word{Name: `"`, Impl: b.CloseQuote(&c)}) dict.AddWord(`.(`, Word{Name: `.(`, Impl: b.OpenQuote(os.Stdout, &rstack, ')'), Immediate: true})