|
| 1 | +%:- use_module(library(dcg/basics)). %, [eos//0, number//1]). |
| 2 | +:- use_module(library(tokenize)). |
| 3 | +:- set_prolog_flag(back_quotes, codes). |
| 4 | +:- use_rendering(svgtree, [list(false)]). |
| 5 | + |
| 6 | +parse(Tokens, SyntaxStructure) :- |
| 7 | + phrase(doc, Tokens). |
| 8 | + |
| 9 | +lexing(Source, Tokens) :- |
| 10 | + tokenize(Source, Tokens, [cased(false), spaces(false)]). |
| 11 | + |
| 12 | +get_vars([X|Xs]) --> list(_), [strings(X), get_vars(Xs)]. |
| 13 | + |
| 14 | +doc(D) --> head(H), terms(T), clauses, list(_), {D = doc(H)}. %terms, clauses. |
| 15 | +head(H) --> lex(L), version(V), author(A), preamble(P), list(_), {H = head(L, V, A, P)}. |
| 16 | +lex(L) --> [word(lex), punct((:))], list(LT), ending, {L = lex(LT)}. |
| 17 | +version(V) --> [word(lexon), punct((:))], list(VT), ending, {V = version(VT)}. |
| 18 | +author(A) --> authorhead, list(AT), ending, {A = author(AT), write(AT)}. |
| 19 | +authorhead --> [word(author), punct((:))]. |
| 20 | +preambhead --> [word(preamble), punct((:))]. |
| 21 | +preamble(P) --> preambhead, list(PT), ending, {P = preamble(PT), write(PT)}. |
| 22 | + |
| 23 | +termhead --> [word(terms), punct((:))]. |
| 24 | +terms(T) --> termhead, list(T). |
| 25 | + |
| 26 | +clausehead --> [word(clause), punct((:))]. |
| 27 | +clauses --> lexclause, clauses. |
| 28 | +clauses --> lexclause. |
| 29 | +lexclause --> clausehead, list(C). |
| 30 | + |
| 31 | +spac --> space(_). |
| 32 | +ending --> [cntrl(('\n'))]. |
| 33 | + |
| 34 | +list([]) --> []. |
| 35 | +list([L|Ls]) --> [L], list(Ls). |
| 36 | + |
| 37 | +preambtest(`PREAMBLE: This is a licensing contract for a software evaluation. |
| 38 | + dfd `). |
| 39 | +ptt([word(preamble), punct((:)), word(this), word((is)), word(a), word(licensing), word(contract), word(for), word(a), word(software), word(evaluation), punct(('.'))]). |
| 40 | + |
| 41 | +testhead(`LEX: Evaluation License System. |
| 42 | +LEXON: 0.3.0 |
| 43 | +AUTHOR: FLORIAN IDELBERGER, HENNING DIEDRICH |
| 44 | +PREAMBLE: This is a licensing contract for a software evaluation.`). |
| 45 | + |
| 46 | +testfile(`LEX: Evaluation License System. |
| 47 | +LEXON: 0.3.0 |
| 48 | +AUTHOR: FLORIAN IDELBERGER, HENNING DIEDRICH |
| 49 | +PREAMBLE: This is a licensing contract for a software evaluation. |
| 50 | +TERMS: |
| 51 | +\"Licensor\" is a person. |
| 52 | +\"Arbiter\" is a person. |
| 53 | +\"License\" is this contract. |
| 54 | +\"Licensing Fee\" is an amount. |
| 55 | +\"Breach Fee\" is an amount. |
| 56 | +The Licensor appoints the Arbiter, |
| 57 | +fixes the Licensing Fee, |
| 58 | +and fixes the Breach Fee. |
| 59 | +CONTRACTS per Licensee: |
| 60 | +\"Description of Goods\" is a text. |
| 61 | +\"Licensee\" is a person. |
| 62 | +\"Paid\" is [ a binary ]. |
| 63 | +\"Commissioned\" is a binary. |
| 64 | +\"Comment Text\" is a text. |
| 65 | +\"Published\" is a binary. |
| 66 | +\"Permission to Comment\" is a binary. |
| 67 | +\"Notice Time\" is a time. |
| 68 | +The Licensor fixes the Description of Goods. |
| 69 | +CLAUSE: Pay |
| 70 | +The Licensee pays the Licensing Fee to the Licensor, |
| 71 | +and pays the Breach Fee into escrow. |
| 72 | +The License is therefore Paid. |
| 73 | +CLAUSE: Commission. |
| 74 | +The Licensor may certify this License as Commissioned. |
| 75 | +CLAUSE: Comment. |
| 76 | +The Licensee may register a Comment Text. |
| 77 | +CLAUSE: Publication. |
| 78 | +The Licensee may certify the License as Published. |
| 79 | +CLAUSE: Grant Permission to Comment. |
| 80 | +The Licensee may grant the Permission to Comment. |
| 81 | +CLAUSE: Declare Breach. |
| 82 | +The Arbiter may, if the License is Factually Breached: |
| 83 | +pay the Breach Fee to the Licensor, |
| 84 | +and afterwards terminate this License. |
| 85 | +CLAUSE: Factually Breached. |
| 86 | +\"Breached\" is defined as: |
| 87 | +the License is Commissioned and the Comment Text is not fixed, |
| 88 | +or the License is Published and there is no Permission to Comment and the Notice Time |
| 89 | +is 24 hours in the past. |
| 90 | +CLAUSE: Notice. |
| 91 | +The Licensor or the Arbiter may fix the respective current time as the Notice Time. |
| 92 | +CLAUSE: Noticed. |
| 93 | +\"Noticed\" is defined as a Notice Time being fixed.`). |
0 commit comments