Warning, /frameworks/syntax-highlighting/autotests/folding/highlight.exu.fold is written in an unsupported language. File is not indexed.

0001 -- Test file for Kate's Euphoria syntax highlighting/code folding.
0002 <beginfold id='1'>-- BEGIN region marker test</beginfold id='1'>
0003 
0004 -- code here
0005 
0006 <endfold id='1'>-- END region marker test</endfold id='1'>
0007 
0008 -- The N Queens Problem:
0009 -- Place N Queens on an NxN chess board
0010 -- such that they don't threaten each other.
0011 constant N = 8 -- try some other sizes
0012 constant ROW = 1, COLUMN = 2
0013 constant TRUE = 1, FALSE = 0
0014 <beginfold id='2'>type</beginfold id='2'> square(sequence x)
0015 -- a square on the board
0016     return length(x) = 2
0017 <endfold id='2'>end type</endfold id='2'>
0018 <beginfold id='2'>type</beginfold id='2'> row(integer x)
0019 -- a row on the board
0020     return x >= 1 and x <= N
0021 <endfold id='2'>end type</endfold id='2'>
0022 
0023 <beginfold id='3'>function</beginfold id='3'> threat(square q1, square q2)
0024 -- do two queens threaten each other?
0025     <beginfold id='4'>if</beginfold id='4'> q1[COLUMN] = q2[COLUMN] then
0026  return TRUE
0027     elsif q1[ROW] - q1[COLUMN] = q2[ROW] - q2[COLUMN] then
0028  return TRUE
0029     elsif q1[ROW] + q1[COLUMN] = q2[ROW] + q2[COLUMN] then
0030  return TRUE
0031     elsif q1[ROW] = q2[ROW] then
0032  return TRUE
0033     else
0034  return FALSE
0035     <endfold id='4'>end if</endfold id='4'>
0036 <endfold id='3'>end function</endfold id='3'>
0037 
0038 <beginfold id='3'>function</beginfold id='3'> conflict(square q, sequence queens)
0039 -- Would square p cause a conflict with other queens on board so far?
0040     <beginfold id='5'>for</beginfold id='5'> i = 1 to length(queens) do
0041  <beginfold id='4'>if</beginfold id='4'> threat(q, queens[i]) then
0042      return TRUE
0043  <endfold id='4'>end if</endfold id='4'>
0044     <endfold id='5'>end for</endfold id='5'>
0045     return FALSE
0046 <endfold id='3'>end function</endfold id='3'>
0047 
0048 integer soln
0049 soln = 0 -- solution number
0050 
0051 <beginfold id='6'>procedure</beginfold id='6'> print_board(sequence queens)
0052 -- print a solution, showing the Queens on the board
0053     integer k
0054     position(1, 1)
0055     printf(1, "Solution #%d\n\n  ", soln)
0056     <beginfold id='5'>for</beginfold id='5'> c = 'a' to 'a' + N - 1 do
0057  printf(1, "%2s", c)
0058     <endfold id='5'>end for</endfold id='5'>
0059     puts(1, "\n")
0060     <beginfold id='5'>for</beginfold id='5'> r = 1 to N do
0061  printf(1, "%2d ", r)
0062  <beginfold id='5'>for</beginfold id='5'> c = 1 to N do
0063      <beginfold id='4'>if</beginfold id='4'> find({r,c}, queens) then
0064   puts(1, "Q ")
0065      else
0066   puts(1, ". ")
0067      <endfold id='4'>end if</endfold id='4'>
0068  <endfold id='5'>end for</endfold id='5'>
0069  puts(1, "\n")
0070     <endfold id='5'>end for</endfold id='5'>
0071     puts(1, "\nPress Enter. (q to quit) ")
0072     <beginfold id='7'>while</beginfold id='7'> TRUE do
0073  k = get_key()
0074  <beginfold id='4'>if</beginfold id='4'> k = 'q' then
0075      abort(0)
0076  elsif k != -1 then
0077      exit
0078  <endfold id='4'>end if</endfold id='4'>
0079     <endfold id='7'>end while</endfold id='7'>
0080 <endfold id='6'>end procedure</endfold id='6'>
0081 
0082 <beginfold id='6'>procedure</beginfold id='6'> place_queen(sequence queens)
0083 -- place queens on a NxN chess board
0084 -- (recursive procedure)
0085     row r -- only need to consider one row for each queen
0086     <beginfold id='4'>if</beginfold id='4'> length(queens) = N then
0087  soln += 1
0088  print_board(queens)
0089  return
0090     <endfold id='4'>end if</endfold id='4'>
0091     r = length(queens)+1
0092     <beginfold id='5'>for</beginfold id='5'> c = 1 to N do
0093  <beginfold id='4'>if</beginfold id='4'> not conflict({r,c}, queens) then
0094      place_queen(append(queens, {r,c}))
0095  <endfold id='4'>end if</endfold id='4'>
0096     <endfold id='5'>end for</endfold id='5'>
0097 <endfold id='6'>end procedure</endfold id='6'>