Skip to content

Syntax Overview

andydhancock edited this page Nov 16, 2023 · 1 revision

Syntax Overview

LegaleseScript is designed with readability and ease of use in mind, drawing from familiar elements of Java and C-like syntax. This overview provides a foundational understanding of the syntax used in LegaleseScript.

Basics

  • Case Sensitivity: All keywords, variables, and identifiers in LegaleseScript are case-sensitive.
  • Comments: Use // for single-line comments and /* */ for multi-line comments.
  • Semicolons: Each statement is concluded with a semicolon (;).
  • Blocks: Blocks of code are denoted by curly braces {}.

Data Types

LegaleseScript introduces custom data types specifically tailored for legal contracts:

  • Text: For textual data.
  • Number: For numerical values.
  • WholeNumber: For integers.
  • FractionalNumber(minFraction): For numbers with a minimum fractional part.
  • Currency: For monetary values.
  • Date: For dates.
  • Duration: For time periods.
  • Party: For parties to a contract.

Variables

  • Declare variables with a data type followed by an identifier: Text contractTitle = "Employment Agreement";
  • Variables are mutable and can be reassigned.

Functions and Sections

  • Sections: Represent the different clauses or sections of a contract, similar to classes in OOP.
  • Obligations: Functions that specify what a party is required to do.
  • Rights: Functions that specify what a party is entitled to.
  • Signatures: Special functions to denote agreement by all parties.

Control Structures

  • Conditionals: Use if, else if, and else for conditional logic.
  • Loops: While loops and for loops are available for iterating over ranges or collections.

Error Handling

  • Use throw to indicate a violation or an error in contract terms.

References

  • Use import to include external documents.
  • Legal references are created with LawReference, CaseReference, and can be accessed using methods like .section() or .paragraph().

Example Contract

Here's a quick example to show the syntax in action:

section EmploymentAgreement {
    version("1.0.0");

    Party employer = "Acme Corporation";
    Party employee = "John Doe";
    WholeNumber minimumWage = 100;
    
    obligation calculatePay(WholeNumber hoursWorked) {
        if (hoursWorked <= 0) {
            throw new ContractException("Hours worked must be positive.");
        }
        return hoursWorked * minimumWage;
    }
    
    right requestLeave(FractionalNumber(0.5) daysRequested) {
        // Requests for leave must be in half-day increments.
    }
    
    signature signContract() {
        // Logic to confirm that all parties have signed the contract.
    }
}

Clone this wiki locally