implement line-comments
This commit is contained in:
		@@ -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})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user