diff options
author | ubq323 <ubq323@ubq323.website> | 2024-11-05 20:53:09 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-11-05 21:18:50 +0000 |
commit | 8fbebbd08b2bb15dd5dd41b49de26c04adc13810 (patch) | |
tree | a5b2e3b2cec1777a70a8f96fb1e67e2c3a90eb4f /conlex.lua | |
parent | 0431089dd2bd506171d5cc22183d53c9b81f611e (diff) |
get vötgil working, allow selecting language
Diffstat (limited to 'conlex.lua')
-rwxr-xr-x | conlex.lua | 67 |
1 files changed, 58 insertions, 9 deletions
@@ -1,4 +1,6 @@ #!/usr/bin/env lua5.3 +local lpeg = require'lpeg' + local function template(str, args) return (str:gsub("%%(%w+)%%", args)) end @@ -74,24 +76,65 @@ function glossors.sanila(text) table.insert(items, format_def(word, entry)) end - return items + return table.concat(items, "\n") +end + +glossors["vötgil"] = function(text) + local words = load_dict "vötgil.tsv" + local function norm(s) + return s:lower():gsub("Ð","ð"):gsub("Ö","ö"):gsub("0","ö"):gsub("9","ð") + end + + local letter = lpeg.R("az","AZ") + lpeg.S"09" + "ö" + "Ö" + 'ð' + 'Ð' + local word = (letter*letter*letter) / function (w) + return format_def(w, words[norm(w)]) + end * lpeg.Cp() + + local i = 1 + local out = "" + while i < #text do + local item, ni = lpeg.match(word, text, i) + if item then + out = out .. item + i = ni + else + out = out .. text:sub(i,i) + i = i + 1 + end + end + return out end local function engloss(langue, text) - local items = glossors[langue](text) + local text = glossors[langue](text) return template([[ <section>%text%</section> - <section id=place></section>]], {text=table.concat(items, "\n")}) + <section id=place></section> + <section><a href="%path%">< return</a></section> + ]], {text=text,path=os.getenv"SCRIPT_NAME"}) end local function enform() - return [[ + local options = {} + for k in pairs(glossors) do + table.insert(options, template('<option value="%x%" >%x%</option>', {x=k})) + end + table.sort(options) + return template([[ <section> <form> <textarea name=q></textarea> - <button>perform <i>conlation</i></button> + <label for=langue>select con-langue:</label> + <select name=langue id=langue> + %options% + </select> + <br><button>perform <i>conglossatio</i></button> </form> -</section>]] +</section> +]], { + options=table.concat(options, "\n"), + + }) end local function response(content) @@ -101,14 +144,20 @@ local function response(content) end local function main() - local text = nil + local langue, text local qs = os.getenv"QUERY_STRING" - if qs then text = parse_qs(qs).q end + if qs then + local pqs = parse_qs(qs) + langue = pqs.langue + text = pqs.q + end if not text then response(enform()) + elseif not glossors[langue] then + response("unknown langue "..langue) else - response(engloss('sanila', text)) + response(engloss(langue, text)) end end |