occam-nominal 0.0.2 → 0.0.4
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 +59 -5
- package/example.js +45998 -0
- package/lib/constants.js +42 -0
- package/lib/customGrammar/combined.js +219 -0
- package/lib/customGrammar/default.js +49 -0
- package/lib/customGrammar.js +213 -0
- package/lib/example/customGrammar/userDefined.js +22 -0
- package/lib/example/div/sizeable.js +39 -0
- package/lib/example/grammarNames.js +22 -0
- package/lib/example/input/startRuleName.js +142 -0
- package/lib/example/input.js +39 -0
- package/lib/example/select/name.js +176 -0
- package/lib/example/select/ruleName.js +176 -0
- package/lib/example/select/vocabularyName.js +176 -0
- package/lib/example/select.js +39 -0
- package/lib/example/subHeading.js +39 -0
- package/lib/example/textarea/bnf.js +142 -0
- package/lib/example/textarea/content.js +163 -0
- package/lib/example/textarea/nominalBNF.js +172 -0
- package/lib/example/textarea/parseTree.js +149 -0
- package/lib/example/textarea/vocabulary.js +142 -0
- package/lib/example/textarea.js +39 -0
- package/lib/example/utilities/rules.js +25 -0
- package/lib/example/view.js +281 -0
- package/lib/example.js +19 -0
- package/lib/grammarNames.js +13 -0
- package/lib/index.js +51 -0
- package/lib/ruleNames.js +29 -0
- package/lib/typesMap.js +45 -0
- package/lib/utilities/grammar.js +31 -0
- package/lib/utilities/lexers.js +95 -0
- package/lib/utilities/nominal.js +25 -0
- package/lib/utilities/parsers.js +108 -0
- package/lib/utilities/part.js +23 -0
- package/lib/utilities/query.js +36 -0
- package/lib/utilities/validate.js +114 -0
- package/lib/utilities/vocabulary.js +35 -0
- package/lib/vocabularyNames.js +29 -0
- package/package.json +6 -4
- package/src/constants.js +11 -0
- package/src/customGrammar/combined.js +196 -0
- package/src/customGrammar/default.js +80 -0
- package/src/customGrammar.js +163 -0
- package/src/example/customGrammar/userDefined.js +21 -0
- package/src/example/div/sizeable.js +12 -0
- package/src/example/grammarNames.js +5 -0
- package/src/example/input/startRuleName.js +33 -0
- package/src/example/input.js +14 -0
- package/src/example/select/name.js +51 -0
- package/src/example/select/ruleName.js +51 -0
- package/src/example/select/vocabularyName.js +52 -0
- package/src/example/select.js +19 -0
- package/src/example/subHeading.js +16 -0
- package/src/example/textarea/bnf.js +33 -0
- package/src/example/textarea/content.js +41 -0
- package/src/example/textarea/nominalBNF.js +51 -0
- package/src/example/textarea/parseTree.js +42 -0
- package/src/example/textarea/vocabulary.js +33 -0
- package/src/example/textarea.js +18 -0
- package/src/example/utilities/rules.js +25 -0
- package/src/example/view.js +195 -0
- package/src/example.js +21 -0
- package/src/grammarNames.js +3 -0
- package/src/index.js +12 -0
- package/src/ruleNames.js +9 -0
- package/src/typesMap.js +50 -0
- package/src/utilities/grammar.js +12 -0
- package/src/utilities/lexers.js +69 -0
- package/src/utilities/nominal.js +9 -0
- package/src/utilities/parsers.js +115 -0
- package/src/utilities/part.js +22 -0
- package/src/utilities/query.js +25 -0
- package/src/utilities/validate.js +155 -0
- package/src/utilities/vocabulary.js +43 -0
- package/src/vocabularyNames.js +9 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Occam
|
|
1
|
+
# Occam Nominal
|
|
2
2
|
|
|
3
3
|
[Occam](https://github.com/djalbat/occam)'s Nominal language.
|
|
4
4
|
|
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
- [Introduction](#introduction)
|
|
8
8
|
- [Installation](#installation)
|
|
9
9
|
- [Example](#example)
|
|
10
|
+
- [Usage](#usage)
|
|
10
11
|
- [Building](#building)
|
|
11
12
|
- [Contact](#contact)
|
|
12
13
|
|
|
13
14
|
## Introduction
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
In Occam parlance, a grammar is a combination of lexical entries for a lexer and BNF for a parser.
|
|
17
|
+
On the other hand, a custom grammar is a single lexical entry together with four BNF snippets for terms, expressions, statements and metastatements.
|
|
18
|
+
|
|
19
|
+
Custom grammars augment the Nominal grammar in order to allow for custom terms and statements.
|
|
20
|
+
This package exports the means to combine custom grammars as well as supplying factory functions to create Nominal lexers and parsers that make use of them.
|
|
16
21
|
|
|
17
22
|
## Installation
|
|
18
23
|
|
|
@@ -28,6 +33,8 @@ You can also clone the repository with [Git](https://git-scm.com/)...
|
|
|
28
33
|
|
|
29
34
|
npm install
|
|
30
35
|
|
|
36
|
+
You can also run a development server, see the section on building later on.
|
|
37
|
+
|
|
31
38
|
## Example
|
|
32
39
|
|
|
33
40
|
There is a small development server that can be run from within the project's directory with the following command:
|
|
@@ -39,13 +46,61 @@ The example will then be available at the following URL:
|
|
|
39
46
|
http://localhost:8888
|
|
40
47
|
|
|
41
48
|
The source for the example can be found in the `src/example.js` file and corresponding `src/example` folder.
|
|
42
|
-
You
|
|
49
|
+
You are encouraged to try the example whilst reading what follows.
|
|
50
|
+
You can rebuild it on the fly with the following command:
|
|
43
51
|
|
|
44
52
|
npm run watch-debug
|
|
45
53
|
|
|
46
54
|
The development server will reload the page whenever you make changes.
|
|
47
55
|
|
|
48
|
-
One last thing to bear in mind is that this package is included by way of a relative rather than a package import.
|
|
56
|
+
One last thing to bear in mind is that this package is included by way of a relative rather than a package import.
|
|
57
|
+
If you are importing it into your own application, however, you should use the standard package import.
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
Custom grammars can be created by calling the `fromName(...)` method of the `CustomGrammar` class and then calling the requisite setters for other properties besides its name:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
import { CustomGrammar } from "occam-nominal";
|
|
65
|
+
|
|
66
|
+
const name = "User defined",
|
|
67
|
+
customGrammar = CustomGrammar.fromName(name),
|
|
68
|
+
ruleName = "term",
|
|
69
|
+
bnf = `
|
|
70
|
+
|
|
71
|
+
...
|
|
72
|
+
|
|
73
|
+
`,
|
|
74
|
+
lexicalPattern = "->|=>";
|
|
75
|
+
|
|
76
|
+
customGrammar.setBNF(ruleName, bnf);
|
|
77
|
+
|
|
78
|
+
customGrammar.setLexicalPattern(lexicalPattern);
|
|
79
|
+
...
|
|
80
|
+
```
|
|
81
|
+
Arrays of Custom grammars can then be combined:
|
|
82
|
+
```
|
|
83
|
+
import { CombinedCustomGrammar } from "occam-nominal";
|
|
84
|
+
|
|
85
|
+
const customGrammars = [
|
|
86
|
+
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
],
|
|
90
|
+
combinedCustomGrammar = CombinedCustomGrammar.fromCustomGrammars(customGrammars);
|
|
91
|
+
```
|
|
92
|
+
Once combined, custom grammars can be passed to utility functions in order to create lexers and parsers:
|
|
93
|
+
```
|
|
94
|
+
const { lexersUtilities, parsersUtilities } = customGrammars,
|
|
95
|
+
{ florenceLexerFromCombinedCustomGrammar } = lexersUtilities,
|
|
96
|
+
{ florenceParserFromCombinedCustomGrammar } = parsersUtilities;
|
|
97
|
+
|
|
98
|
+
const combinedCustomGrammar = ...
|
|
99
|
+
florenceLexer = florenceLexerFromCombinedCustomGrammar(combinedCustomGrammar),
|
|
100
|
+
florenceParser = florenceParserFromCombinedCustomGrammar(combinedCustomGrammar);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Custom grammars should be provided in topological order, with dependencies coming before dependents.
|
|
49
104
|
|
|
50
105
|
## Building
|
|
51
106
|
|
|
@@ -57,4 +112,3 @@ Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have
|
|
|
57
112
|
## Contact
|
|
58
113
|
|
|
59
114
|
* james.smith@djalbat.com
|
|
60
|
-
|