occam-query 3.1.133

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.
Files changed (43) hide show
  1. package/.swcrc +11 -0
  2. package/README.md +118 -0
  3. package/bin/main.js +15 -0
  4. package/example.js +35580 -0
  5. package/index.html +47 -0
  6. package/lib/constants.js +13 -0
  7. package/lib/example/utilities/token.js +28 -0
  8. package/lib/example/view/div/sizeable.js +39 -0
  9. package/lib/example/view/input/expression.js +156 -0
  10. package/lib/example/view/input/maximumDepth.js +156 -0
  11. package/lib/example/view/input.js +39 -0
  12. package/lib/example/view/subHeading.js +39 -0
  13. package/lib/example/view/textarea/content.js +155 -0
  14. package/lib/example/view/textarea/nodes.js +176 -0
  15. package/lib/example/view/textarea/parseTree.js +183 -0
  16. package/lib/example/view/textarea.js +39 -0
  17. package/lib/example/view.js +250 -0
  18. package/lib/example.js +19 -0
  19. package/lib/index.js +27 -0
  20. package/lib/query.js +168 -0
  21. package/lib/spread.js +86 -0
  22. package/lib/utilities/array.js +61 -0
  23. package/lib/utilities/query.js +79 -0
  24. package/license.txt +48 -0
  25. package/package.json +41 -0
  26. package/src/constants.js +3 -0
  27. package/src/example/utilities/token.js +21 -0
  28. package/src/example/view/div/sizeable.js +12 -0
  29. package/src/example/view/input/expression.js +35 -0
  30. package/src/example/view/input/maximumDepth.js +35 -0
  31. package/src/example/view/input.js +14 -0
  32. package/src/example/view/subHeading.js +16 -0
  33. package/src/example/view/textarea/content.js +33 -0
  34. package/src/example/view/textarea/nodes.js +64 -0
  35. package/src/example/view/textarea/parseTree.js +50 -0
  36. package/src/example/view/textarea.js +18 -0
  37. package/src/example/view.js +120 -0
  38. package/src/example.js +21 -0
  39. package/src/index.js +4 -0
  40. package/src/query.js +170 -0
  41. package/src/spread.js +65 -0
  42. package/src/utilities/array.js +30 -0
  43. package/src/utilities/query.js +52 -0
package/.swcrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "jsc": {
3
+ "parser": {
4
+ "syntax": "ecmascript",
5
+ "jsx": true
6
+ }
7
+ },
8
+ "module": {
9
+ "type": "commonjs"
10
+ }
11
+ }
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # Occam Query
2
+
3
+ [Occam](https://github.com/djalbat/occam)'s query functionality.
4
+
5
+ ### Contents
6
+
7
+ - [Introduction](#introduction)
8
+ - [Installation](#installation)
9
+ - [Example](#example)
10
+ - [Usage](#usage)
11
+ - [Building](#building)
12
+ - [Contact](#contact)
13
+
14
+ ## Introduction
15
+
16
+ This package provides a simple, [XPath](https://en.wikipedia.org/wiki/XPath)-like query language for selecting from nodes returned by Occam's [parsers](https://github.com/djalbat/occam-parsers).
17
+
18
+ A query expression consists of a leading, forward slash `/` followed by an optional forward slash to signify arbitrary depth, followed by a list of either non-terminal node rule names or terminal node significant token types, finally followed by an optional spread expression and a sub-query. You cannot mix rule names and significant token types and the sub-queries of query expressions with significant token types are ignored. Further explanation would likely just confuse. It is best simply to play around with the expression in the example to select different nodes.
19
+
20
+ Here is an example parse tree together with some query expressions and their meaning, to help clarify:
21
+ ```
22
+ stylesheet
23
+ |
24
+ ruleSet
25
+ |
26
+ ------------------------------------------------------------------------------------------------------
27
+ | | | |
28
+ selectors {[special] declaration }[special]
29
+ | |
30
+ selector ---------------------------------------------
31
+ | | | | |
32
+ class property :[special] expression ;[special]
33
+ | | |
34
+ ------------------------------- background[identifier] term
35
+ | | | |
36
+ .[special] <NO_WHITESPACE> view[identifier] red[identifier]
37
+ ```
38
+ * `/stylesheet` matches the topmost `stylesheet` non-terminal node.
39
+ * `//term` matches all `term` non-terminal nodes to an arbitrary depth.
40
+ * `//@special[2...4]` matches from the third to the fifth of all `special` terminal nodes.
41
+
42
+ ## Installation
43
+
44
+ With [npm](https://www.npmjs.com/):
45
+
46
+ npm install occam-query
47
+
48
+ You can also clone the repository with [Git](https://git-scm.com/)...
49
+
50
+ git clone https://github.com/djalbat/occam-query.git
51
+
52
+ ...and then install the dependencies with npm from within the project's root directory:
53
+
54
+ npm install
55
+
56
+ You can also run a development server, see the section on building later on.
57
+
58
+ ## Example
59
+
60
+ There is a small development server that can be run from within the project's directory with the following command:
61
+
62
+ npm start
63
+
64
+ The example will then be available at the following URL:
65
+
66
+ http://localhost:8888
67
+
68
+ The source for the example can be found in the `src/example.js` file and corresponding `src/example` folder. You are encouraged to try the example whilst reading what follows. You can rebuild it on the fly with the following command:
69
+
70
+ npm run watch-debug
71
+
72
+ The development server will reload the page whenever you make changes.
73
+
74
+ 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.
75
+
76
+ ## Usage
77
+
78
+ The collection of query utility functions is exported as a plain old JavaScript object. The only one of use is the `queryByExpression(...)` function:
79
+
80
+ ```
81
+ import { queryUtilities } from "occam-query";
82
+
83
+ const { queryByExpression } = queryUtilities;
84
+
85
+ const node = ...,
86
+ expression = "...",
87
+ maximumDepth = 10,
88
+ nodes = queryByExpression(node, expression, maximumDepth);
89
+
90
+ ...
91
+ ```
92
+ The `maximumDepth` argument is optional, the default is `Infinity`.
93
+
94
+ If repeatedly using the same query expression, build a `query` object and make use of its `execute(...)` method:
95
+
96
+ ```
97
+ import { Query } from "occam-query";
98
+
99
+ const node = ...,
100
+ expression = "...",
101
+ query = Query.fromExpression(expression)
102
+ nodes = query.execute(node);
103
+
104
+ ...
105
+ ```
106
+ This is quicker than using the `queryByExpression()` function, which will create such an object each time it is invoked. Again there is an optional last `maximumDepth` argument, left out here.
107
+
108
+ ## Building
109
+
110
+ Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
111
+
112
+ npm run build-debug
113
+ npm run watch-debug
114
+
115
+ ## Contact
116
+
117
+ * james.smith@djalbat.com
118
+
package/bin/main.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ const express = require("express");
4
+
5
+ const { createLiveReloadHandler } = require("lively-cli");
6
+
7
+ const server = express(), ///
8
+ staticRouter = express.static("."),
9
+ liveReloadHandler = createLiveReloadHandler("./example.js");
10
+
11
+ server.use(staticRouter);
12
+
13
+ server.get("/live-reload", liveReloadHandler);
14
+
15
+ server.listen(8888);