The grammar of WikiScript marries two ancestries. From Lexon it takes the document: terms, clauses, and deontic lines. From HyperTalk it takes the operational lines: handlers, containers, and chunk expressions. The whole grammar is small enough to read in one sitting — that is the point.
# Document grammar An agreement opens with its name and home wiki. Terms define the parties, amounts, times, flags, texts and pages. Clauses carry deontic lines and handlers. Keywords are lowercase; defined Terms are Capitalised.
agreement "Crowdfund Withdrawal" of wiki "legalcommons.org". terms: "The Beneficiary" is a party. "A Funder" is any party. "The Fund" is page "Crowdfund Ledger" of this wiki. clause: "Withdrawal by Funders". A Funder may withdraw when Withdrawals Allowed is set and the balance of the Funder is greater than zero.
# Operational grammar Handlers respond to events by name. The statements are few: `put`, `get`, `record`, `ghost`, `if`, and one loop. `get` binds `it`. `ghost` is the only output channel.
on withdraw: get the balance of the Funder record "fund transfer" in the Fund put zero into the balance of the Funder ghost the Fund end withdraw
# Commands and queries Commands do things. Queries answer questions. HyperTalk kept the two apart, and ordinary people could read the code. Mainstream languages blurred them and lost that. WikiScript makes the split structural: statements are commands, everything inside an expression is a pure query, and `get` is the bridge. See DSLs and Hypertalk.
# Deterministic by design Six constraints make every agreement terminate and every evaluation reproducible: - no user defined functions and no recursion — handlers call only built ins - one loop, `repeat for each` over a finite chunk — there is no while, no forever - pure evaluation — the agreement, state page-json and an event go in; a verdict, ghost page-json and recorded facts come out - explicit time — `the date` resolves from supplied state, never from a clock - commands change state, queries only answer - deontic lines never execute — they project to the permission table
# Grammar source The grammar is written in Ohm and kept in the code repo — see WikiScript Repo — mirrored in the assets below. It is the single source of truth. The rule inventory reads:
Agreement = HeadLine TermsBlock? ClauseBlock+ DeonticLine = Subject Modal VerbPhrase WhenPart? "." Modal = "may not" | "may" | "must" | "shall" Handler = "on" name ":" Statement+ "end" name Statement = Put | Get | Record | Ghost | If | RepeatEach ChunkExpr = "the" ordinal chunk "of" Expr chunk = character | word | item | line | paragraph | page
# Assets
wikiscript-grammar
# See - WikiScript and Agreement Corpus - HyperTalk and Lexon - Ohm and WikiScript Repo - Double Parse - WikiScript Architecture