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,99 @@
#!/usr/bin/lasso9
define config => type {
data public configtxt, public path
public oncreate(
path::string = 'testing/configuration.txt'
) => {
.configtxt = file(#path) -> readstring
.path = #path
}
public get(term::string) => {
.clean
local(
regexp = regexp(-find = `(?m)^` + #term + `($|\s*=\s*|\s+)(.*)$`, -input = .configtxt, -ignorecase),
result
)
while(#regexp -> find) => {
#result = (#regexp -> groupcount > 1 ? (#regexp -> matchString(2) -> trim& || true))
if(#result -> asstring >> ',') => {
#result = #result -> split(',')
#result -> foreach => {#1 -> trim}
}
return #result
}
return false
}
public set(term::string, value) => {
if(#value === false) => {
.disable(#term)
return
}
.enable(#term)
if(#value -> isanyof(::string, ::integer, ::decimal)) => {
.configtxt = regexp(-find = `(?m)^(` + #term + `) ?(.*?)$`, -replace = `$1 ` + #value, -input = .configtxt, -ignorecase) -> replaceall
}
}
public disable(term::string) => {
.clean
local(regexp = regexp(-find = `(?m)^(` + #term + `)`, -replace = `; $1`, -input = .configtxt, -ignorecase))
.configtxt = #regexp -> replaceall
}
public enable(term::string, -comment::string = '# Added ' + date) => {
.clean
local(regexp = regexp(-find = `(?m)^(; )?(` + #term + `)`, -replace = `$2`, -input = .configtxt, -ignorecase))
if(#regexp -> find) => {
.configtxt = #regexp -> replaceall
else
.configtxt -> append('\n' + (not #comment -> beginswith('#') ? '# ') +
#comment + '\n' +
string_uppercase(#term) + '\n'
)
}
}
public write => {
local(config = file(.path))
#config -> opentruncate
#config -> dowithclose => {
#config -> writestring(.configtxt)
}
}
public clean => {
local(
cleaned = array,
regexp = regexp(-find = `^(;+)\W*$`)
)
with line in .configtxt -> split('\n') do {
#line -> trim
#regexp -> input = #line
if(#line -> beginswith('#') or #line == '') => {
#cleaned -> insert(#line)
else(not (#regexp -> find))
if(#line -> beginswith(';')) => {
#line -> replace(regexp(`^;+ *`), `; `)
else
#line -> replace(regexp(`^(.*?) +(.*?)`), `$1 $2`)
}
#line -> replace(regexp(`\t`))
#cleaned -> insert(#line)
}
}
.configtxt = #cleaned -> join('\n')
}
}

View file

@ -0,0 +1,15 @@
local(
config = config,
)
stdoutnl(#config -> get('FAVOURITEFRUIT'))
stdoutnl(#config -> get('SEEDSREMOVED'))
stdoutnl(#config -> get('NUMBEROFBANANAS'))
#config -> enable('seedsremoved')
#config -> enable('PARAMWITHCOMMENT', -comment = 'This param was added to demonstrate the possibility to also have comments associated with it')
#config -> disable('needspeeling')
#config -> set('numberofstrawberries', 62000)
#config -> set('numberofbananas', 1024)
#config -> write