Nested comments now work with tests.

This commit is contained in:
Peter Camilleri 2016-05-15 17:46:47 -04:00
parent 7f17f06518
commit 0ea841eb4c
4 changed files with 25 additions and 3 deletions

View file

@ -187,4 +187,12 @@ class CompileLibraryTester < Minitest::Test
foorth_equal('"integration/_FILE_test.foorth" .load ', [nm, 7, nm])
end
def test_comments
foorth_equal('42 (foo (bar) etc) 33', [42, 33])
foorth_raises('( ( )')
foorth_equal('42 // foo bar etc 33', [42])
end
end

View file

@ -31,6 +31,9 @@ module XfOOrth
#The level of quote nesting.
attr_accessor :quotes
#The level of comment nesting.
attr_accessor :parens
#Is a force compile in effect?
attr_accessor :force
@ -39,6 +42,7 @@ module XfOOrth
@buffer = nil
@parser = nil
@quotes = 0
@parens = 0
@force = false
@context = Context.new(nil, vm: self, mode: :execute)
self

View file

@ -31,8 +31,18 @@ module XfOOrth
#<br>Note:
#* Raises an XfOOrthError exception on an unterminated comment.
def skip_over_comment
until @source.eoln?
return true if @source.get == ')'
vm = Thread.current[:vm]
vm.parens += 1
until @source.eof?
input = @source.get
if input == ')'
vm.parens -= 1
return true
elsif input == '('
skip_over_comment
end
end
error "F10: Unbalanced comment detected."

View file

@ -72,7 +72,7 @@ module XfOOrth
puts vm.pop
end
'>' * vm.context.depth + '"' * vm.quotes
'>' * vm.context.depth + '"' * vm.quotes + '(' * vm.parens
end
#What is the source of this text?