#
# Keywords
#

# YSH keywords
var v = 42; echo next
const c = 99  # comment
setvar dq = 'zz'
setglobal g = "yy"

proc p { echo hi }
func myFunc(x; offset=0) { return (x) }

call len('str'); echo next
call len('str')  # comment

= len(g); echo next
  = len(g)  # = keyword

# test for ; inside ()
call myFunc(42; offset=10); echo next

#=foo
#echo =foo

echo \# not a comment
echo \\ backslash

# Shell keywords
if test --file / {
  echo 'exists'
} elif true {
  echo 'true'
} else {
  echo 'else'
}

case (42) {
  (42)   { echo 'match' }
  /d+/   { echo 'pattern' }
  'str'  { echo 'str' }
  (else) { echo 'other' }
}

for x in a b {
  echo $x
}

while false {
  echo hi
}

# Comment at beginning of line

echo not#comment  # space required before comment

#
# Quotes can be quoted with \
# e.g. with \' \"
#

echo \'single \'single \"double \"double

#
# Single-quoted strings are raw by default
#

# Command mode
echo '/usr/bin'
echo r'C:\Program Files\'  # r'' prefix is allowed

# expression mode
var r1 = '/usr/bin/'
var r2 = r'C:\Program Files\' # r'' prefix is allowed

# corner cases for r''
echo ls --foo='bar'
echo ls --foo=r'bar'
echo ls bar'bar'
echo ls -r'bar'

# beginning of line
'echo'
r'echo'
u'echo'
$"echo"

#
# Double-quoted strings support interpolation (and a few \ escapes)
#

echo "hi $r1 \$ \" \\"
var dq = "hi $r2 \$ \" \\"

echo $"hi $r1 \$ \" \\"
var dq = $"hi $r2 \$ \" \\"

echo --foo=$"bar"

#
# J8 strings have \ escapes
#

echo b'hi \t \' \\'
var j8 = b'hi \t \' \\'

echo u'hi \t \' \\'
var j8 = u'hi \t \' \\'

#
# Triple-quoted strings
#  ''' r'''
#  """
#  b""" u"""
#

var empty = ''

# raw

echo '''
  $r1
  C:\Program Files\
  one ' 
  two ''
  ''' | cat

var x = '''
  C:\Program Files\
  one ' 
  two ''
  ''' ++ empty

echo r'''
  $r1
  C:\Program Files\
  one '
  two ''
  ''' | cat

var x = r'''
  C:\Program Files\
  one '
  two ''
  ''' ++ empty

# double quoted

echo """
  $r1
  one "
  two ""
  """

var x = """
  $r1
  one "
  two ""
  \""""

echo $"""
  $r1
  \$ one "
  \$ two ""
  \"""" other

var x = $"""
  $r1
  \$ one "
  \$ two ""
  """ ++ 'other'

# j8

echo b'''
  one '
  two ''
  three \'''
  ''' | cat

var x = b'''
  j8 \'''
  one '
  two ''
  three \'''
  ''' ++ empty

echo u'''
  one '
  two ''
  three \'''
  ''' | cat

var x = u'''
  j8 \'''
  one '
  two ''
  three \'''
  ''' ++ empty

#
# Expression Work Fine, Without Color
#

var mydict = {hi: 42}

echo $[42 + mydict['hi']]
echo "sum = $[42 + mydict['hi']]"

#
# Bug in the MINIMAL style: nested double quotes aren't matched correctly.
#
# This is a limitation of NON-recursive lexing.
#

echo  "$[42 + mydict["hi"]]"
echo "hi $["inner"]"


var ch = 'i'
echo  $[42 + mydict["h$[ch]"]]
echo "$[42 + mydict["h$[ch]"]]"

#
# Interpolation
#

var base_dir = '/bin'
var file = 'zz'

echo $base_dir/file /tmp/$file-suffix

# Inside double quotes - require modes, Vim regions
echo "$base_dir/file /tmp/$file-suffix"

var name42 = x
var name42x = x
var _x = x

echo $name42 $name42x
echo ${name42} ${name42x}
echo $_x ${_x}

# YSH has non-recursive ${}
echo ${file:-} "foo ${base_dir:-}"
echo ${12:-} "foo ${12:-}"

echo foo@example.com  foo@example  # should not be highlighted as a splice

var my_array = :| echo b c |
echo x @my_array
setvar myarray = :| a b c @my_array |

@my_array

set -- {0..11}

echo $0 ${11}
echo bad $00 $1a

echo "hi $0 x ${11}"
echo "bad $00 $1a"


#
# Multi-Line
#

... echo
    multi-
    line ;

# not valid
# var x = (...)

echo \
  multi- \
  line \
  $(echo next)


echo $(
  echo 1
  echo 2
  # no highlighting here, but we don't encourage complex code
  for x in 3 4 { echo $x }
  )