Lawtext syntax
Detailed syntax
Please refer to the comments in the source code referred from the following documents for the detailed syntax of Lawtext.
- The library documentation for
Line
describes the types ofLine
s and links to the codes that contain the actual syntax definition bygeneric-parser
(opens in a new tab) to convert a Lawtext string to a sequence ofLine
s. - The library documentation for
VirtualLine
describes the types ofVirtualLine
s and the steps to convert a sequence ofLine
s toVirtualLine
s. - The library documentation for
$law
is the entry point of the parser that converts a sequence ofVirtualLine
s toStdEL
(JsonEL
). It contains the actual syntax definition bygeneric-parser
(opens in a new tab), and you can follow the defined rule to find syntax definitions for other element types.
How to try
Try it out here
- On this page, open the browser console (for Chrome, press
Ctrl+Shift+J
(Windows/Linux) orCmd+Opt+J
(Mac)).. - Run the following command in the browser console:
lawtext.run({ input: { elaws: "405AC0000000088" }, outtypes: ["lawtext"], }) .then(r => { console.log("Lawtext:"); console.log(r.lawtext); return lawtext.run({ input: { lawtext: r.lawtext }, outtypes: ["json"], controlel: true, }); }) .then(r => { console.log("\u{2705} Parsed VirtualLines:"); console.log(r.virtuallines); console.table(r.virtuallines.map(v => ({ "VirtualLine.type": v.type, ...Object.fromEntries(v.line?.rangeTexts().map(([, t, d], i) => [`rangeTexts()[${i}]`, t]) ?? []), }))); console.log("\u{2705} Parsed StdEL (JsonEL):"); console.log(r.json); console.log(JSON.stringify(r.json, undefined, 2)); });
Hint: run console.log(lawtext.run.help)
to show the help.
Try using the CLI
Please see CLI usage and run CLI with a lawtext
input and json
output with controlel
option (and virtuallinesout
option when running in Node.js) to get the parsed VirtualLine
s and the parsed StdEL
(JsonEL
) representation.
Try using the Visual Studio Code extension
-
You can try the extension at github.dev (opens in a new tab) with a few clicks. (A GitHub account is required. You can create one on the linked page.)
-
Otherwise, you can visit vscode.dev (opens in a new tab), install Lawtext extension (opens in a new tab) and ope n the sample Lawtext (opens in a new tab).