Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,23 @@
var # creation
x = "this is a string"
y = "this is another string"
z = "this is a string"
if x == z: echo "x is z" # comparison
z = "now this is another string too" # assignment
y = z # copying
if x.len == 0: echo "empty" # check if empty
x.add('!') # append a byte
echo x[5..8] # substring
echo x[8 .. -1] # substring
z = x & y # join strings
import strutils
echo z.replace('t', 'T') # replace occurences of t with T

View file

@ -0,0 +1,24 @@
string s = "abc"
s = x"ef bb bf" -- explicit binary string (the utf8 BOM)
s[2] = 0
s[3] = 'z'
if s="\#EF\0z" then puts(1,"ok\n") end if
string t = s
t[1..2] = "xy" -- s remains unaltered
?t -- "xyz"
t = "food" ?t
t[2..3] = 'e' ?t -- "feed"
t[3..2] = "ast" ?t -- "feasted"
t[3..-2] = "" ?t -- "fed"
if length(t)=0 then puts(1,"t is empty\n") end if
if t!="" then puts(1,"t is not empty\n") end if
t = "be"
t &= 't' ?t -- bet
t = 'a'&t ?t -- abet
?t[2..3] -- be
?substitute(t,"be","bbo") -- abbot
?substitute(t,"be","dep") -- adept
t = substitute(t,"be","dep") -- to actually modify t
?join({"abc","def","ghi"}) -- "abc def ghi"
?join({"abc","def","ghi"},"") -- "abcdefghi"
?join({"abc","def","ghi"},"\n") -- "abc\ndef\nghi"

View file

@ -0,0 +1,43 @@
# string creation
x = "hello world"
# string destruction
x = NULL
# string assignment with a null byte
x = "a"+char(0)+"b"
see len(x) # ==> 3
# string comparison
if x = "hello"
See "equal"
else
See "not equal"
ok
y = 'bc'
if strcmp(x,y) < 0
See x + " is lexicographically less than " + y
ok
# string cloning
xx = x
See x = xx # true, same length and content
# check if empty
if x = NULL
See "is empty"
ok
# append a byte
x += char(7)
# substring
x = "hello"
x[1] = "H"
See x + nl
# join strings
a = "hel"
b = "lo w"
c = "orld"
See a + b + c

View file

@ -0,0 +1,10 @@
# If the input is a valid representation of a binary string
# then pass it along:
def check_binary:
. as $a
| reduce .[] as $x
($a;
if $x | (type == "number" and . == floor
and 0 <= . and . <= 255) then $a
else error("\(.) is an invalid representation of a byte")
end );

View file

@ -0,0 +1,70 @@
## Creation of an entity representing an empty binary string
[]
## Assignment
# Unless a check is appropriate, assignment can be done in the
# usual ways, for example:
[0] as $x # assignment to a variable, $x
s as $x # assignment of s to a variable
.key = s # assignment to a key in a JSON object
# If s must be checked, these become:
(s|check_binary) as $x
.key = (s|check_binary)
## Concatenation:
str+str2
## Comparison
[72,101,108,108,111] == ("Hello"|explode) # evaluates to true
# Other jq comparison operators (!=, <, >, <=, >=) can be used as well.
## Cloning and copying
# In jq, all entities are immutable and so the distinction between
# copying and cloning is irrelevant in jq.
# For example, consider the expression "$s[0] = 1"
# in the following:
[0] as $s | $s[0] = 1 | $s
# The result is [0] because the expression "$s[0] = 1"
# evaluates to [1] but does not alter $s. The value of
# $s can be changed by assignment, e.g.
[0] as $s | $s[0] = 1 | . as $s
## Check if an entity represents the empty binary string
length == 0
# or
s == []
## append a byte, b
s + [b] # if the byte, b, is known to be in range
s + ([b]|check_binary) # if b is suspect
## Extract a substring from a string
# jq uses an index origin of 0 for both JSON arrays strings,
# so to extract the substring with indices from m to (n-1)
# inclusive, the expression s[m:n] can be used.
# There are many other possibilities, such as s[m:], s[-1], etc.
## Replace every occurrence of one byte, x, with
## another sequence of bytes presented as an array, a,
## of byte-valued integers:
reduce .[] as $byte ([];
if $byte == x then . + a else . + [$byte] end)