mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Nested comments now work with tests.
This commit is contained in:
parent
7f17f06518
commit
0ea841eb4c
4 changed files with 25 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue