occam-grammars 1.0.427 → 1.0.428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -85
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,85 +1,86 @@
|
|
|
1
|
-
# Occam Grammars
|
|
2
|
-
|
|
3
|
-
[Occam](https://github.com/djalbat/occam)'s grammars.
|
|
4
|
-
|
|
5
|
-
### Contents
|
|
6
|
-
|
|
7
|
-
- [Introduction](#introduction)
|
|
8
|
-
- [Installation](#installation)
|
|
9
|
-
- [Usage](#usage)
|
|
10
|
-
- [Examples](#examples)
|
|
11
|
-
- [Building](#building)
|
|
12
|
-
- [Contact](#contact)
|
|
13
|
-
|
|
14
|
-
## Introduction
|
|
15
|
-
|
|
16
|
-
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:
|
|
17
|
-
|
|
18
|
-
* Florence
|
|
19
|
-
* Plain
|
|
20
|
-
* Meta JSON
|
|
21
|
-
* Custom grammar BNF
|
|
22
|
-
* Custom grammar pattern
|
|
23
|
-
|
|
24
|
-
This package exports the lexers and parsers to support these grammars.
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
With [npm](https://www.npmjs.com/):
|
|
29
|
-
|
|
30
|
-
npm install occam-grammars
|
|
31
|
-
|
|
32
|
-
You can also clone the repository with [Git](https://git-scm.com/)...
|
|
33
|
-
|
|
34
|
-
git clone https://github.com/djalbat/occam-grammars.git
|
|
35
|
-
|
|
36
|
-
...and then install the dependencies with npm from within the project's root directory:
|
|
37
|
-
|
|
38
|
-
npm install
|
|
39
|
-
|
|
40
|
-
You can also run a development server, see the section on building later on.
|
|
41
|
-
|
|
42
|
-
## Usage
|
|
43
|
-
|
|
44
|
-
Import the requisite lexer and parser from this package. Then call their fromNothing(...) factory methods.
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
import { FlorenceLexer } from "occam-grammars";
|
|
48
|
-
import { FlorenceParser } from "occam-grammars"
|
|
49
|
-
|
|
50
|
-
const florenceLexer = FlorenceLexer.fromNothing(),
|
|
51
|
-
florenceParser = FlorenceParser.fromNothing();
|
|
52
|
-
|
|
53
|
-
const content = `
|
|
54
|
-
|
|
55
|
-
...
|
|
56
|
-
|
|
57
|
-
`,
|
|
58
|
-
tokens = florenceLexer.tokenise(content),
|
|
59
|
-
node = florenceParser.parse(tokens);
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
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`.
|
|
65
|
-
|
|
66
|
-
## Examples
|
|
67
|
-
|
|
68
|
-
There are examples for each grammar. To view them, open the `index.html` file in the root of the repository. Each example shows a representation of the parse tree, which is useful for debugging.
|
|
69
|
-
|
|
70
|
-
## Building
|
|
71
|
-
|
|
72
|
-
Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
|
|
73
|
-
|
|
74
|
-
npm run build-debug
|
|
75
|
-
npm run watch-debug
|
|
76
|
-
|
|
77
|
-
You can also start a small development server:
|
|
78
|
-
|
|
79
|
-
npm start
|
|
80
|
-
|
|
81
|
-
The example will then be available at http://localhost:8888 and will reload automatically when changes are made.
|
|
82
|
-
|
|
83
|
-
## Contact
|
|
84
|
-
|
|
85
|
-
* james.smith@
|
|
1
|
+
# Occam Grammars
|
|
2
|
+
|
|
3
|
+
[Occam](https://github.com/djalbat/occam)'s grammars.
|
|
4
|
+
|
|
5
|
+
### Contents
|
|
6
|
+
|
|
7
|
+
- [Introduction](#introduction)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Examples](#examples)
|
|
11
|
+
- [Building](#building)
|
|
12
|
+
- [Contact](#contact)
|
|
13
|
+
|
|
14
|
+
## Introduction
|
|
15
|
+
|
|
16
|
+
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:
|
|
17
|
+
|
|
18
|
+
* Florence
|
|
19
|
+
* Plain
|
|
20
|
+
* Meta JSON
|
|
21
|
+
* Custom grammar BNF
|
|
22
|
+
* Custom grammar pattern
|
|
23
|
+
|
|
24
|
+
This package exports the lexers and parsers to support these grammars.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
With [npm](https://www.npmjs.com/):
|
|
29
|
+
|
|
30
|
+
npm install occam-grammars
|
|
31
|
+
|
|
32
|
+
You can also clone the repository with [Git](https://git-scm.com/)...
|
|
33
|
+
|
|
34
|
+
git clone https://github.com/djalbat/occam-grammars.git
|
|
35
|
+
|
|
36
|
+
...and then install the dependencies with npm from within the project's root directory:
|
|
37
|
+
|
|
38
|
+
npm install
|
|
39
|
+
|
|
40
|
+
You can also run a development server, see the section on building later on.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Import the requisite lexer and parser from this package. Then call their fromNothing(...) factory methods.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
import { FlorenceLexer } from "occam-grammars";
|
|
48
|
+
import { FlorenceParser } from "occam-grammars"
|
|
49
|
+
|
|
50
|
+
const florenceLexer = FlorenceLexer.fromNothing(),
|
|
51
|
+
florenceParser = FlorenceParser.fromNothing();
|
|
52
|
+
|
|
53
|
+
const content = `
|
|
54
|
+
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
`,
|
|
58
|
+
tokens = florenceLexer.tokenise(content),
|
|
59
|
+
node = florenceParser.parse(tokens);
|
|
60
|
+
|
|
61
|
+
...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
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`.
|
|
65
|
+
|
|
66
|
+
## Examples
|
|
67
|
+
|
|
68
|
+
There are examples for each grammar. To view them, open the `index.html` file in the root of the repository. Each example shows a representation of the parse tree, which is useful for debugging.
|
|
69
|
+
|
|
70
|
+
## Building
|
|
71
|
+
|
|
72
|
+
Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
|
|
73
|
+
|
|
74
|
+
npm run build-debug
|
|
75
|
+
npm run watch-debug
|
|
76
|
+
|
|
77
|
+
You can also start a small development server:
|
|
78
|
+
|
|
79
|
+
npm start
|
|
80
|
+
|
|
81
|
+
The example will then be available at http://localhost:8888 and will reload automatically when changes are made.
|
|
82
|
+
|
|
83
|
+
## Contact
|
|
84
|
+
|
|
85
|
+
* james.smith@djalbat.com
|
|
86
|
+
|