# occam-grammars

> Occam's grammars.

Latest version **1.3.741** (published 2026-10-03) · MIT, Anti-996 license · 0 weekly downloads

## Install

```sh
npm install occam-grammars
pnpm add occam-grammars
yarn add occam-grammars
bun add occam-grammars
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.3.741 |
| Published | 2026-10-03 |
| First published | 2020-07-12 |
| Weekly downloads | 0 |
| License | MIT, Anti-996 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 242.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | James Smith |
| Maintainers | djalbat |

## Links

- npm: https://www.npmjs.com/package/occam-grammars
- Repository: https://github.com/djalbat/occam-grammars
- Issues: https://github.com/djalbat/occam-grammars/issues
- npm.io page: https://npm.io/package/occam-grammars

## Dependencies (4)

- [necessary](https://npm.io/package/necessary.md) ^17.7.2
- [occam-query](https://npm.io/package/occam-query.md) ^4.1.241
- [occam-lexers](https://npm.io/package/occam-lexers.md) ^23.3.13
- [occam-parsers](https://npm.io/package/occam-parsers.md) ^23.3.51

## Recent versions

- 1.3.741 (latest) — 2026-10-03
- 1.3.740 — 2026-10-03
- 1.3.739 — 2026-10-02
- 1.3.737 — 2026-10-02
- 1.3.738 — 2026-10-02
- 1.3.736 — 2026-10-02
- 1.3.735 — 2026-10-02
- 1.3.734 — 2026-09-29
- 1.3.733 — 2026-09-29
- 1.3.732 — 2026-09-29
- 1.3.731 — 2026-09-29
- 1.3.730 — 2026-09-28
- 1.3.729 — 2026-09-28
- 1.3.728 — 2026-09-27
- 1.3.727 — 2026-09-27
- … 1358 more at https://npm.io/package/occam-grammars/versions

## README

# Occam Grammars

[Occam](https://github.com/djalbat/occam)'s grammars.

### Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Examples](#examples)
- [Usage](#usage)
- [Building](#building)
- [Contact](#contact)

## Introduction

In Occam parlance, a grammar is a combination of lexical entries for a lexer and BNF for a parser. This package contains all the grammars for Occam, specifically:

* Florence
* Plain
* Meta JSON
* Custom grammar BNF
* Custom grammar pattern

This package exports the lexers and parsers to support these grammars.

## Installation

With [npm](https://www.npmjs.com/):

    npm install occam-grammars

You can also clone the repository with [Git](https://git-scm.com/)...

    git clone https://github.com/djalbat/occam-grammars.git

...and then install the dependencies with npm from within the project's root directory:

    npm install

You can also run a development server, see the section on building later on.

## Examples

There is a small development server that can be run from within the project's directory with the following command:

    npm start

The examples will then be available at the following URL:

http://localhost:8888

The source for the examples can be found in the `src/example.js` file and corresponding `src/example` folder. You are encouraged to try the examples whilst reading what follows. You can rebuild them on the fly with the following command:

    npm run watch-debug

The development server will reload the page whenever you make changes.

One last thing to bear in mind is that this package is included by way of a relative rather than a package import. If you are importing it into your own application, however, you should use the standard package import.

## Usage

Import the requisite lexer and parser from this package. Then call their fromNothing(...) factory methods.

```
import { FlorenceLexer } from "occam-grammars";
import { FlorenceParser } from "occam-grammars"

const florenceLexer = FlorenceLexer.fromNothing(),
      florenceParser = FlorenceParser.fromNothing();

const content = `

        ...

      `,
      tokens = florenceLexer.tokenise(content),
      node = florenceParser.parse(tokens);

...
```

The tokens returned from the lexers's `tokenise(...)`` method can be passed directly to the parser's `parse(...) method`, which itself returns a node or `null`.

## Building

Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:

    npm run build-debug
    npm run watch-debug

## Contact

* james.smith@djalbat.com

---
_Source: https://npm.io/package/occam-grammars · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
