implement line-comments
This commit is contained in:
parent
0784661e7c
commit
7291ca86c8
@ -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 {
|
||||
|
1
main.go
1
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})
|
||||
|
Loading…
Reference in New Issue
Block a user