eyeling 1.14.13 → 1.15.0

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 (29) hide show
  1. package/examples/check/input/deep-taxonomy-100000.c +20 -0
  2. package/examples/check/input/gps.c +127 -0
  3. package/examples/check/input/high-trust-rdf-bloom-envelope.c +148 -0
  4. package/examples/check/input/high-trust-rdf-bloom-tamper-contrast.c +247 -0
  5. package/examples/check/input/odrl-dpv-risk-ranked.c +275 -0
  6. package/examples/check/output/deep-taxonomy-100000.n3 +300004 -0
  7. package/examples/check/output/gps.n3 +6 -0
  8. package/examples/check/output/high-trust-rdf-bloom-envelope.n3 +7 -0
  9. package/examples/check/output/high-trust-rdf-bloom-tamper-contrast.n3 +27 -0
  10. package/examples/check/output/odrl-dpv-risk-ranked.n3 +13 -0
  11. package/examples/decimal-ebike-motor-thermal-envelope.n3 +286 -0
  12. package/examples/decimal-transcendental-servo-envelope.n3 +197 -0
  13. package/examples/deck/high-trust-rdf-bloom-envelope.md +371 -0
  14. package/examples/deck/schema-foaf-mapping.md +3 -1
  15. package/examples/high-trust-rdf-bloom-envelope.n3 +281 -0
  16. package/examples/high-trust-rdf-bloom-tamper-contrast.n3 +395 -0
  17. package/examples/integer-first-control-tank-level.n3 +209 -0
  18. package/examples/integer-first-sqrt2-mediants.n3 +174 -0
  19. package/examples/output/decimal-ebike-motor-thermal-envelope.n3 +25 -0
  20. package/examples/output/decimal-transcendental-servo-envelope.n3 +29 -0
  21. package/examples/output/high-trust-rdf-bloom-envelope.n3 +7 -0
  22. package/examples/output/high-trust-rdf-bloom-tamper-contrast.n3 +27 -0
  23. package/examples/output/integer-first-control-tank-level.n3 +70 -0
  24. package/examples/output/integer-first-sqrt2-mediants.n3 +57 -0
  25. package/eyeling.js +90 -1
  26. package/lib/lexer.js +90 -1
  27. package/package.json +3 -2
  28. package/test/api.test.js +221 -0
  29. package/test/check.test.js +174 -0
@@ -0,0 +1,174 @@
1
+ # =======================================================================================
2
+ # Integer-first √2 bracketing via Stern-Brocot mediants
3
+ #
4
+ # Why this example exists:
5
+ # It illustrates the “integer thesis” in a very direct way. We do not start from a
6
+ # completed real number object. We start from finite integer data and refine it using a
7
+ # finite, checkable procedure.
8
+ #
9
+ # Idea:
10
+ # Keep two rational bounds L = pL/qL and U = pU/qU with
11
+ # pL^2 < 2 qL^2 and 2 qU^2 < pU^2 .
12
+ # Their mediant M = (pL+pU)/(qL+qU) still lies between them. We test M using only the
13
+ # integer comparison M^2 ? 2 and keep the half-interval that still brackets √2.
14
+ #
15
+ # What is certified:
16
+ # * exact integer lower/upper witnesses around √2
17
+ # * exact residual gaps to 2
18
+ # * Farey adjacency (cross-difference = 1), hence exact width = 1/(qL*qU)
19
+ # * readable decimal views are derived only at the end
20
+ #
21
+ # This is “integer-first” because the proof-carrying part is entirely discrete.
22
+ # =======================================================================================
23
+
24
+ @prefix : <http://example.org/integer-first#>.
25
+ @prefix math: <http://www.w3.org/2000/10/swap/math#>.
26
+ @prefix log: <http://www.w3.org/2000/10/swap/log#>.
27
+
28
+ # ----------
29
+ # Parameters
30
+ # ----------
31
+
32
+ :sqrt2 a :Target;
33
+ :computedBy :mediantRefiner.
34
+
35
+ :mediantRefiner a :SternBrocotProcedure;
36
+ :maxStep 8.
37
+
38
+ # Step 0: 1 < √2 < 2
39
+ :mediantRefiner :bounds (0 1 1 2 1).
40
+
41
+ # ------------------------------------------------------------------------
42
+ # Refinement: replace one endpoint by the mediant according to the sign of
43
+ # p^2 - 2 q^2, checked with integer arithmetic only.
44
+ # ------------------------------------------------------------------------
45
+
46
+ # If mediant^2 < 2 then it becomes the new lower bound.
47
+ {
48
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
49
+ :mediantRefiner :maxStep ?max.
50
+ ?n math:lessThan ?max.
51
+
52
+ ( ?n ?max ) :successor ?n1.
53
+ ( ?pL ?pU ) math:sum ?pM.
54
+ ( ?qL ?qU ) math:sum ?qM.
55
+ ( ?pM ?pM ) math:product ?pM2.
56
+ ( ?qM ?qM ) math:product ?qM2.
57
+ ( 2 ?qM2 ) math:product ?twoQM2.
58
+ ?pM2 math:lessThan ?twoQM2.
59
+ }
60
+ =>
61
+ {
62
+ :mediantRefiner :bounds (?n1 ?pM ?qM ?pU ?qU).
63
+ }.
64
+
65
+ # If mediant^2 > 2 then it becomes the new upper bound.
66
+ {
67
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
68
+ :mediantRefiner :maxStep ?max.
69
+ ?n math:lessThan ?max.
70
+
71
+ ( ?n ?max ) :successor ?n1.
72
+ ( ?pL ?pU ) math:sum ?pM.
73
+ ( ?qL ?qU ) math:sum ?qM.
74
+ ( ?pM ?pM ) math:product ?pM2.
75
+ ( ?qM ?qM ) math:product ?qM2.
76
+ ( 2 ?qM2 ) math:product ?twoQM2.
77
+ ?pM2 math:greaterThan ?twoQM2.
78
+ }
79
+ =>
80
+ {
81
+ :mediantRefiner :bounds (?n1 ?pL ?qL ?pM ?qM).
82
+ }.
83
+
84
+ # -----------------------------------------
85
+ # Exact integer certificates for each stage
86
+ # -----------------------------------------
87
+
88
+ {
89
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
90
+
91
+ ( ?pL ?pL ) math:product ?pL2.
92
+ ( ?qL ?qL ) math:product ?qL2.
93
+ ( 2 ?qL2 ) math:product ?twoQL2.
94
+ ( ?twoQL2 ?pL2 ) math:difference ?lowerGap.
95
+ ?lowerGap math:greaterThan 0.
96
+
97
+ ( ?pU ?pU ) math:product ?pU2.
98
+ ( ?qU ?qU ) math:product ?qU2.
99
+ ( 2 ?qU2 ) math:product ?twoQU2.
100
+ ( ?pU2 ?twoQU2 ) math:difference ?upperGap.
101
+ ?upperGap math:greaterThan 0.
102
+ }
103
+ =>
104
+ {
105
+ :sqrt2 :integerCertificate (?n ?lowerGap ?upperGap).
106
+ }.
107
+
108
+ # Farey adjacency: pU*qL - pL*qU = 1, so width = 1/(qL*qU) exactly.
109
+ {
110
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
111
+ ( ?pU ?qL ) math:product ?left.
112
+ ( ?pL ?qU ) math:product ?right.
113
+ ( ?left ?right ) math:difference ?det.
114
+ ?det math:equalTo 1.
115
+
116
+ ( ?qL ?qU ) math:product ?widthDen.
117
+ }
118
+ =>
119
+ {
120
+ :sqrt2 :fareyAdjacent (?n true).
121
+ :sqrt2 :widthExact (?n 1 ?widthDen).
122
+ }.
123
+
124
+ # ------------------------------
125
+ # Readable decimal views (query)
126
+ # ------------------------------
127
+
128
+ {
129
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
130
+ ( ?pL ?qL ) math:quotient ?L.
131
+ ( ?pU ?qU ) math:quotient ?U.
132
+ ( ?L ?U ) math:sum ?sum.
133
+ ( ?sum 2 ) math:quotient ?mid.
134
+ }
135
+ =>
136
+ {
137
+ :sqrt2 :decimalBounds (?n ?L ?U ?mid).
138
+ }.
139
+
140
+ # ---------------
141
+ # Helper relation
142
+ # ---------------
143
+
144
+ { ( ?n ?max ) :successor ?n1. } <= {
145
+ ?n math:lessThan ?max.
146
+ ( ?n 1 ) math:sum ?n1.
147
+ }.
148
+
149
+ # ----------------
150
+ # Output selection
151
+ # ----------------
152
+
153
+ {
154
+ :mediantRefiner :bounds (?n ?pL ?qL ?pU ?qU).
155
+ :sqrt2 :integerCertificate (?n ?lowerGap ?upperGap).
156
+ :sqrt2 :widthExact (?n ?widthNum ?widthDen).
157
+ :sqrt2 :fareyAdjacent (?n true).
158
+ }
159
+ log:query
160
+ {
161
+ :result :boundsQ (?n ?pL ?qL ?pU ?qU).
162
+ :result :gapTo2 (?n ?lowerGap ?upperGap).
163
+ :result :widthQ (?n ?widthNum ?widthDen).
164
+ :result :fareyAdjacent (?n true).
165
+ }.
166
+
167
+ {
168
+ :sqrt2 :decimalBounds (?n ?L ?U ?mid).
169
+ }
170
+ log:query
171
+ {
172
+ :result :decimalBounds (?n ?L ?U).
173
+ :result :midpoint (?n ?mid).
174
+ }.
@@ -0,0 +1,25 @@
1
+ @prefix : <http://example.org/ebike-thermal#> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3
+
4
+ :result :coolingStep 10 .
5
+ :result :coolingStep 11 .
6
+ :result :coolingStep 3 .
7
+ :result :coolingStep 4 .
8
+ :result :coolingStep 5 .
9
+ :result :coolingStep 6 .
10
+ :result :coolingStep 7 .
11
+ :result :coolingStep 8 .
12
+ :result :coolingStep 9 .
13
+ :result :summary ("cooling-symbol" "exp(-1/4)" "cooling-lower" "0.7788007830"^^xsd:decimal "cooling-upper" "0.7788007831"^^xsd:decimal "warning-limit-C" "35.0"^^xsd:decimal "hard-limit-C" "45.0"^^xsd:decimal "warning-recovery-step" 8 "warning-recovery-time-s" "40"^^xsd:decimal "decision" :ThermallySafeForThisAssistPlan) .
14
+ :result :temperatureTrace (0 :Turbo "33"^^xsd:decimal "33"^^xsd:decimal) .
15
+ :result :temperatureTrace (1 :Turbo "36.030406264"^^xsd:decimal "36.0304062648"^^xsd:decimal) .
16
+ :result :temperatureTrace (10 :Coast "30.605576433064357"^^xsd:decimal "30.605576437395232"^^xsd:decimal) .
17
+ :result :temperatureTrace (11 :Coast "29.36562731523687"^^xsd:decimal "29.365627319170315"^^xsd:decimal) .
18
+ :result :temperatureTrace (2 :Turbo "38.3904890352113"^^xsd:decimal "38.39048903693738"^^xsd:decimal) .
19
+ :result :temperatureTrace (3 :Tour "40.22852334537548"^^xsd:decimal "40.2285233480588"^^xsd:decimal) .
20
+ :result :temperatureTrace (4 :Tour "39.259985905312206"^^xsd:decimal "39.259985908924826"^^xsd:decimal) .
21
+ :result :temperatureTrace (5 :Eco "38.50568818862611"^^xsd:decimal "38.50568819286562"^^xsd:decimal) .
22
+ :result :temperatureTrace (6 :Eco "36.71824053625586"^^xsd:decimal "36.71824054090817"^^xsd:decimal) .
23
+ :result :temperatureTrace (7 :Eco "35.326174905018405"^^xsd:decimal "35.326174909813446"^^xsd:decimal) .
24
+ :result :temperatureTrace (8 :Coast "34.24203310142329"^^xsd:decimal "34.242033106190284"^^xsd:decimal) .
25
+ :result :temperatureTrace (9 :Coast "32.197702615900376"^^xsd:decimal "32.19770262053712"^^xsd:decimal) .
@@ -0,0 +1,29 @@
1
+ @prefix : <http://example.org/decimal-servo#> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3
+
4
+ :result :contractionAt 0 .
5
+ :result :contractionAt 1 .
6
+ :result :contractionAt 10 .
7
+ :result :contractionAt 11 .
8
+ :result :contractionAt 2 .
9
+ :result :contractionAt 3 .
10
+ :result :contractionAt 4 .
11
+ :result :contractionAt 5 .
12
+ :result :contractionAt 6 .
13
+ :result :contractionAt 7 .
14
+ :result :contractionAt 8 .
15
+ :result :contractionAt 9 .
16
+ :result :envelope (0 "12.5"^^xsd:decimal "12.5"^^xsd:decimal) .
17
+ :result :envelope (1 "8.95664138125"^^xsd:decimal "8.956641382499999"^^xsd:decimal) .
18
+ :result :envelope (10 "0.4459249163814359"^^xsd:decimal "0.44592491700377423"^^xsd:decimal) .
19
+ :result :envelope (11 "0.3195191647193932"^^xsd:decimal "0.3195191652099106"^^xsd:decimal) .
20
+ :result :envelope (12 "0.22894548582625215"^^xsd:decimal "0.22894548620967514"^^xsd:decimal) .
21
+ :result :envelope (2 "6.417713986585592"^^xsd:decimal "6.41771398837692"^^xsd:decimal) .
22
+ :result :envelope (3 "4.598493013222353"^^xsd:decimal "4.5984930151476675"^^xsd:decimal) .
23
+ :result :envelope (4 "3.2949642250893065"^^xsd:decimal "3.2949642269287036"^^xsd:decimal) .
24
+ :result :envelope (5 "2.3609450342538576"^^xsd:decimal "2.3609450359013398"^^xsd:decimal) .
25
+ :result :envelope (6 "1.6916910394123839"^^xsd:decimal "1.691691040828951"^^xsd:decimal) .
26
+ :result :envelope (7 "1.2121495974312624"^^xsd:decimal "1.2121495986154462"^^xsd:decimal) .
27
+ :result :envelope (8 "0.8685431395694698"^^xsd:decimal "0.8685431405391896"^^xsd:decimal) .
28
+ :result :envelope (9 "0.6223383540214966"^^xsd:decimal "0.6223383548031854"^^xsd:decimal) .
29
+ :result :summary ("exact-pole" "exp(-1/3)" "decimal-lower" "0.7165313105"^^xsd:decimal "decimal-upper" "0.7165313106"^^xsd:decimal "tolerance" "0.5"^^xsd:decimal "first-settled-step" 10 "first-settled-time-s" "0.2"^^xsd:decimal) .
@@ -0,0 +1,7 @@
1
+ @prefix : <http://example.org/high-trust-rdf#> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3
+
4
+ :result :expIntervalCertificate :CertifiedDecimalInterval .
5
+ :result :summary ("parameter-sanity" true "index-agreement" true "transcendental" "exp(-k*n/m)" "lambda" "0.5126953125"^^xsd:decimal "certified-lambda" 0.5126953125 "exp-lower" 0.5988792348 "exp-upper" 0.5988792349 "fp-lower" "0.0016708059567271017"^^xsd:decimal "fp-upper" "0.0016708059596428394"^^xsd:decimal "expected-extra-exact-lookups-upper" "83.54029798214196"^^xsd:decimal "decision" :AcceptForHighTrustUse) .
6
+ :result :withinExactLookupBudget true .
7
+ :result :withinFpRateBudget true .
@@ -0,0 +1,27 @@
1
+ @prefix : <http://example.org/high-trust-rdf#> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3
+
4
+ :result :decision [
5
+ :artifact :trustedArtifact ;
6
+ :hardened :AcceptForHighTrustUse ;
7
+ :weak :AcceptUnderWeakBudgetOnlyRules
8
+ ] .
9
+ :result :decision [
10
+ :artifact :tamperedArtifact ;
11
+ :hardened :RejectForHighTrustUse ;
12
+ :weak :AcceptUnderWeakBudgetOnlyRules
13
+ ] .
14
+ :result :rejectReason [
15
+ :artifact :tamperedArtifact ;
16
+ :why :NonPositiveBloomBits
17
+ ] .
18
+ :result :rejectReason [
19
+ :artifact :tamperedArtifact ;
20
+ :why :CertifiedLambdaMismatch
21
+ ] .
22
+ :result :rejectReason [
23
+ :artifact :tamperedArtifact ;
24
+ :why :MalformedIntervalOrdering
25
+ ] .
26
+ :result :summary (:tamperedArtifact "lambda" -700 "certified-lambda" 0.5126953125 "weak-fp-upper" "-194754273881"^^xsd:decimal "weak-extra-exact-upper" "-194754273881"^^xsd:decimal "weak-decision" :AcceptUnderWeakBudgetOnlyRules "hardened-decision" :RejectForHighTrustUse) .
27
+ :result :summary (:trustedArtifact "lambda" "0.5126953125"^^xsd:decimal "certified-lambda" 0.5126953125 "weak-fp-upper" "0.0016708059596428394"^^xsd:decimal "weak-extra-exact-upper" "83.54029798214196"^^xsd:decimal "weak-decision" :AcceptUnderWeakBudgetOnlyRules "hardened-decision" :AcceptForHighTrustUse) .
@@ -0,0 +1,70 @@
1
+ @prefix : <http://example.org/integer-control#> .
2
+
3
+ :result :holdBand (:trialHigh 5 true) .
4
+ :result :holdBand (:trialHigh 6 true) .
5
+ :result :holdBand (:trialHigh 7 true) .
6
+ :result :holdBand (:trialLow 5 true) .
7
+ :result :holdBand (:trialLow 6 true) .
8
+ :result :holdBand (:trialLow 7 true) .
9
+ :result :holdBand (:trialNominal 0 true) .
10
+ :result :holdBand (:trialNominal 1 true) .
11
+ :result :holdBand (:trialNominal 2 true) .
12
+ :result :holdBand (:trialNominal 3 true) .
13
+ :result :holdBand (:trialNominal 4 true) .
14
+ :result :holdBand (:trialNominal 5 true) .
15
+ :result :holdBand (:trialNominal 6 true) .
16
+ :result :holdBand (:trialNominal 7 true) .
17
+ :result :insideBand (:trialHigh 5 21) .
18
+ :result :insideBand (:trialHigh 6 21) .
19
+ :result :insideBand (:trialHigh 7 21) .
20
+ :result :insideBand (:trialHigh 8 21) .
21
+ :result :insideBand (:trialLow 5 19) .
22
+ :result :insideBand (:trialLow 6 19) .
23
+ :result :insideBand (:trialLow 7 19) .
24
+ :result :insideBand (:trialLow 8 19) .
25
+ :result :insideBand (:trialNominal 0 20) .
26
+ :result :insideBand (:trialNominal 1 20) .
27
+ :result :insideBand (:trialNominal 2 20) .
28
+ :result :insideBand (:trialNominal 3 20) .
29
+ :result :insideBand (:trialNominal 4 20) .
30
+ :result :insideBand (:trialNominal 5 20) .
31
+ :result :insideBand (:trialNominal 6 20) .
32
+ :result :insideBand (:trialNominal 7 20) .
33
+ :result :insideBand (:trialNominal 8 20) .
34
+ :result :strictImprovement (:trialHigh 0 true) .
35
+ :result :strictImprovement (:trialHigh 1 true) .
36
+ :result :strictImprovement (:trialHigh 2 true) .
37
+ :result :strictImprovement (:trialHigh 3 true) .
38
+ :result :strictImprovement (:trialHigh 4 true) .
39
+ :result :strictImprovement (:trialLow 0 true) .
40
+ :result :strictImprovement (:trialLow 1 true) .
41
+ :result :strictImprovement (:trialLow 2 true) .
42
+ :result :strictImprovement (:trialLow 3 true) .
43
+ :result :strictImprovement (:trialLow 4 true) .
44
+ :result :trace (:trialHigh 0 28 0 8) .
45
+ :result :trace (:trialHigh 1 26 0 6) .
46
+ :result :trace (:trialHigh 2 24 1 4) .
47
+ :result :trace (:trialHigh 3 23 1 3) .
48
+ :result :trace (:trialHigh 4 22 1 2) .
49
+ :result :trace (:trialHigh 5 21 2 1) .
50
+ :result :trace (:trialHigh 6 21 2 1) .
51
+ :result :trace (:trialHigh 7 21 2 1) .
52
+ :result :trace (:trialHigh 8 21 2 1) .
53
+ :result :trace (:trialLow 0 12 4 8) .
54
+ :result :trace (:trialLow 1 14 4 6) .
55
+ :result :trace (:trialLow 2 16 3 4) .
56
+ :result :trace (:trialLow 3 17 3 3) .
57
+ :result :trace (:trialLow 4 18 3 2) .
58
+ :result :trace (:trialLow 5 19 2 1) .
59
+ :result :trace (:trialLow 6 19 2 1) .
60
+ :result :trace (:trialLow 7 19 2 1) .
61
+ :result :trace (:trialLow 8 19 2 1) .
62
+ :result :trace (:trialNominal 0 20 2 0) .
63
+ :result :trace (:trialNominal 1 20 2 0) .
64
+ :result :trace (:trialNominal 2 20 2 0) .
65
+ :result :trace (:trialNominal 3 20 2 0) .
66
+ :result :trace (:trialNominal 4 20 2 0) .
67
+ :result :trace (:trialNominal 5 20 2 0) .
68
+ :result :trace (:trialNominal 6 20 2 0) .
69
+ :result :trace (:trialNominal 7 20 2 0) .
70
+ :result :trace (:trialNominal 8 20 2 0) .
@@ -0,0 +1,57 @@
1
+ @prefix : <http://example.org/integer-first#> .
2
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
3
+
4
+ :result :boundsQ (0 1 1 2 1) .
5
+ :result :boundsQ (1 1 1 3 2) .
6
+ :result :boundsQ (2 4 3 3 2) .
7
+ :result :boundsQ (3 7 5 3 2) .
8
+ :result :boundsQ (4 7 5 10 7) .
9
+ :result :boundsQ (5 7 5 17 12) .
10
+ :result :boundsQ (6 24 17 17 12) .
11
+ :result :boundsQ (7 41 29 17 12) .
12
+ :result :boundsQ (8 41 29 58 41) .
13
+ :result :decimalBounds (0 1 2) .
14
+ :result :decimalBounds (1 1 "1.5"^^xsd:decimal) .
15
+ :result :decimalBounds (2 "1.3333333333333333"^^xsd:decimal "1.5"^^xsd:decimal) .
16
+ :result :decimalBounds (3 "1.4"^^xsd:decimal "1.5"^^xsd:decimal) .
17
+ :result :decimalBounds (4 "1.4"^^xsd:decimal "1.4285714285714286"^^xsd:decimal) .
18
+ :result :decimalBounds (5 "1.4"^^xsd:decimal "1.4166666666666667"^^xsd:decimal) .
19
+ :result :decimalBounds (6 "1.411764705882353"^^xsd:decimal "1.4166666666666667"^^xsd:decimal) .
20
+ :result :decimalBounds (7 "1.4137931034482758"^^xsd:decimal "1.4166666666666667"^^xsd:decimal) .
21
+ :result :decimalBounds (8 "1.4137931034482758"^^xsd:decimal "1.4146341463414633"^^xsd:decimal) .
22
+ :result :fareyAdjacent (0 true) .
23
+ :result :fareyAdjacent (1 true) .
24
+ :result :fareyAdjacent (2 true) .
25
+ :result :fareyAdjacent (3 true) .
26
+ :result :fareyAdjacent (4 true) .
27
+ :result :fareyAdjacent (5 true) .
28
+ :result :fareyAdjacent (6 true) .
29
+ :result :fareyAdjacent (7 true) .
30
+ :result :fareyAdjacent (8 true) .
31
+ :result :gapTo2 (0 1 2) .
32
+ :result :gapTo2 (1 1 1) .
33
+ :result :gapTo2 (2 2 1) .
34
+ :result :gapTo2 (3 1 1) .
35
+ :result :gapTo2 (4 1 2) .
36
+ :result :gapTo2 (5 1 1) .
37
+ :result :gapTo2 (6 2 1) .
38
+ :result :gapTo2 (7 1 1) .
39
+ :result :gapTo2 (8 1 2) .
40
+ :result :midpoint (0 "1.5"^^xsd:decimal) .
41
+ :result :midpoint (1 "1.25"^^xsd:decimal) .
42
+ :result :midpoint (2 "1.4166666666666665"^^xsd:decimal) .
43
+ :result :midpoint (3 "1.45"^^xsd:decimal) .
44
+ :result :midpoint (4 "1.4142857142857141"^^xsd:decimal) .
45
+ :result :midpoint (5 "1.4083333333333332"^^xsd:decimal) .
46
+ :result :midpoint (6 "1.4142156862745099"^^xsd:decimal) .
47
+ :result :midpoint (7 "1.4152298850574714"^^xsd:decimal) .
48
+ :result :midpoint (8 "1.4142136248948696"^^xsd:decimal) .
49
+ :result :widthQ (0 1 1) .
50
+ :result :widthQ (1 1 2) .
51
+ :result :widthQ (2 1 6) .
52
+ :result :widthQ (3 1 10) .
53
+ :result :widthQ (4 1 35) .
54
+ :result :widthQ (5 1 60) .
55
+ :result :widthQ (6 1 204) .
56
+ :result :widthQ (7 1 348) .
57
+ :result :widthQ (8 1 1189) .
package/eyeling.js CHANGED
@@ -7847,6 +7847,95 @@ function decodeN3StringEscapes(s, offset = null) {
7847
7847
  return out;
7848
7848
  }
7849
7849
 
7850
+ function formatCodePoint(cp) {
7851
+ return cp
7852
+ .toString(16)
7853
+ .toUpperCase()
7854
+ .padStart(cp <= 0xffff ? 4 : 6, '0');
7855
+ }
7856
+
7857
+ function isForbiddenIriRefChar(c) {
7858
+ return (
7859
+ c === '<' || c === '>' || c === '"' || c === '{' || c === '}' || c === '|' || c === '^' || c === '`' || c === '\\'
7860
+ );
7861
+ }
7862
+
7863
+ function assertValidIriRefCodePoint(cp, offset = null) {
7864
+ if (cp <= 0x20) {
7865
+ throw new N3SyntaxError(`Invalid IRIREF: character U+${formatCodePoint(cp)} is not allowed inside <...>`, offset);
7866
+ }
7867
+
7868
+ if (cp >= 0xd800 && cp <= 0xdfff) {
7869
+ throw new N3SyntaxError(
7870
+ `Invalid IRIREF: surrogate code point U+${formatCodePoint(cp)} is not allowed inside <...>`,
7871
+ offset,
7872
+ );
7873
+ }
7874
+
7875
+ if (isForbiddenNoncharacterCodePoint(cp)) {
7876
+ throw new N3SyntaxError(
7877
+ `Invalid IRIREF: noncharacter U+${formatCodePoint(cp)} is not allowed inside <...>`,
7878
+ offset,
7879
+ );
7880
+ }
7881
+
7882
+ const c = String.fromCodePoint(cp);
7883
+ if (isForbiddenIriRefChar(c)) {
7884
+ throw new N3SyntaxError(`Invalid IRIREF: character ${JSON.stringify(c)} is not allowed inside <...>`, offset);
7885
+ }
7886
+ }
7887
+
7888
+ function decodeIriRefEscapes(s, offset = null) {
7889
+ let out = '';
7890
+ for (let i = 0; i < s.length; i++) {
7891
+ const c = s[i];
7892
+ if (c !== '\\') {
7893
+ const cp = c.codePointAt(0);
7894
+ assertValidIriRefCodePoint(cp, offset);
7895
+ out += c;
7896
+ continue;
7897
+ }
7898
+
7899
+ if (i + 1 >= s.length) {
7900
+ throw new N3SyntaxError('Invalid IRIREF: bare backslash is not allowed inside <...>', offset);
7901
+ }
7902
+
7903
+ const e = s[++i];
7904
+ if (e === 'u') {
7905
+ const hex = s.slice(i + 1, i + 5);
7906
+ if (!/^[0-9A-Fa-f]{4}$/.test(hex)) {
7907
+ throw new N3SyntaxError('Invalid IRIREF: malformed \\u escape inside <...>', offset);
7908
+ }
7909
+ const cp = parseInt(hex, 16);
7910
+ assertValidIriRefCodePoint(cp, offset);
7911
+ out += String.fromCodePoint(cp);
7912
+ i += 4;
7913
+ continue;
7914
+ }
7915
+
7916
+ if (e === 'U') {
7917
+ const hex = s.slice(i + 1, i + 9);
7918
+ if (!/^[0-9A-Fa-f]{8}$/.test(hex)) {
7919
+ throw new N3SyntaxError('Invalid IRIREF: malformed \\U escape inside <...>', offset);
7920
+ }
7921
+ const cp = parseInt(hex, 16);
7922
+ if (cp < 0 || cp > 0x10ffff) {
7923
+ throw new N3SyntaxError(`Invalid IRIREF: code point U+${hex.toUpperCase()} is out of range`, offset);
7924
+ }
7925
+ assertValidIriRefCodePoint(cp, offset);
7926
+ out += String.fromCodePoint(cp);
7927
+ i += 8;
7928
+ continue;
7929
+ }
7930
+
7931
+ throw new N3SyntaxError(
7932
+ `Invalid IRIREF: character ${JSON.stringify('\\' + e)} is not allowed inside <...>`,
7933
+ offset,
7934
+ );
7935
+ }
7936
+ return out;
7937
+ }
7938
+
7850
7939
  function assertValidStringLiteralValue(s, offset = null) {
7851
7940
  for (let i = 0; i < s.length; i++) {
7852
7941
  const cu = s.charCodeAt(i);
@@ -8032,7 +8121,7 @@ function lex(inputText) {
8032
8121
  throw new N3SyntaxError('Unterminated IRI <...>', start);
8033
8122
  }
8034
8123
  i++; // skip '>'
8035
- const iri = iriChars.join('');
8124
+ const iri = decodeIriRefEscapes(iriChars.join(''), start);
8036
8125
  tokens.push(new Token('IriRef', iri, start));
8037
8126
  continue;
8038
8127
  }
package/lib/lexer.js CHANGED
@@ -201,6 +201,95 @@ function decodeN3StringEscapes(s, offset = null) {
201
201
  return out;
202
202
  }
203
203
 
204
+ function formatCodePoint(cp) {
205
+ return cp
206
+ .toString(16)
207
+ .toUpperCase()
208
+ .padStart(cp <= 0xffff ? 4 : 6, '0');
209
+ }
210
+
211
+ function isForbiddenIriRefChar(c) {
212
+ return (
213
+ c === '<' || c === '>' || c === '"' || c === '{' || c === '}' || c === '|' || c === '^' || c === '`' || c === '\\'
214
+ );
215
+ }
216
+
217
+ function assertValidIriRefCodePoint(cp, offset = null) {
218
+ if (cp <= 0x20) {
219
+ throw new N3SyntaxError(`Invalid IRIREF: character U+${formatCodePoint(cp)} is not allowed inside <...>`, offset);
220
+ }
221
+
222
+ if (cp >= 0xd800 && cp <= 0xdfff) {
223
+ throw new N3SyntaxError(
224
+ `Invalid IRIREF: surrogate code point U+${formatCodePoint(cp)} is not allowed inside <...>`,
225
+ offset,
226
+ );
227
+ }
228
+
229
+ if (isForbiddenNoncharacterCodePoint(cp)) {
230
+ throw new N3SyntaxError(
231
+ `Invalid IRIREF: noncharacter U+${formatCodePoint(cp)} is not allowed inside <...>`,
232
+ offset,
233
+ );
234
+ }
235
+
236
+ const c = String.fromCodePoint(cp);
237
+ if (isForbiddenIriRefChar(c)) {
238
+ throw new N3SyntaxError(`Invalid IRIREF: character ${JSON.stringify(c)} is not allowed inside <...>`, offset);
239
+ }
240
+ }
241
+
242
+ function decodeIriRefEscapes(s, offset = null) {
243
+ let out = '';
244
+ for (let i = 0; i < s.length; i++) {
245
+ const c = s[i];
246
+ if (c !== '\\') {
247
+ const cp = c.codePointAt(0);
248
+ assertValidIriRefCodePoint(cp, offset);
249
+ out += c;
250
+ continue;
251
+ }
252
+
253
+ if (i + 1 >= s.length) {
254
+ throw new N3SyntaxError('Invalid IRIREF: bare backslash is not allowed inside <...>', offset);
255
+ }
256
+
257
+ const e = s[++i];
258
+ if (e === 'u') {
259
+ const hex = s.slice(i + 1, i + 5);
260
+ if (!/^[0-9A-Fa-f]{4}$/.test(hex)) {
261
+ throw new N3SyntaxError('Invalid IRIREF: malformed \\u escape inside <...>', offset);
262
+ }
263
+ const cp = parseInt(hex, 16);
264
+ assertValidIriRefCodePoint(cp, offset);
265
+ out += String.fromCodePoint(cp);
266
+ i += 4;
267
+ continue;
268
+ }
269
+
270
+ if (e === 'U') {
271
+ const hex = s.slice(i + 1, i + 9);
272
+ if (!/^[0-9A-Fa-f]{8}$/.test(hex)) {
273
+ throw new N3SyntaxError('Invalid IRIREF: malformed \\U escape inside <...>', offset);
274
+ }
275
+ const cp = parseInt(hex, 16);
276
+ if (cp < 0 || cp > 0x10ffff) {
277
+ throw new N3SyntaxError(`Invalid IRIREF: code point U+${hex.toUpperCase()} is out of range`, offset);
278
+ }
279
+ assertValidIriRefCodePoint(cp, offset);
280
+ out += String.fromCodePoint(cp);
281
+ i += 8;
282
+ continue;
283
+ }
284
+
285
+ throw new N3SyntaxError(
286
+ `Invalid IRIREF: character ${JSON.stringify('\\' + e)} is not allowed inside <...>`,
287
+ offset,
288
+ );
289
+ }
290
+ return out;
291
+ }
292
+
204
293
  function assertValidStringLiteralValue(s, offset = null) {
205
294
  for (let i = 0; i < s.length; i++) {
206
295
  const cu = s.charCodeAt(i);
@@ -386,7 +475,7 @@ function lex(inputText) {
386
475
  throw new N3SyntaxError('Unterminated IRI <...>', start);
387
476
  }
388
477
  i++; // skip '>'
389
- const iri = iriChars.join('');
478
+ const iri = decodeIriRefEscapes(iriChars.join(''), start);
390
479
  tokens.push(new Token('IriRef', iri, start));
391
480
  continue;
392
481
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.14.13",
3
+ "version": "1.15.0",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [
@@ -42,10 +42,11 @@
42
42
  "test:api": "node test/api.test.js",
43
43
  "test:n3gen": "node test/n3gen.test.js",
44
44
  "test:examples": "node test/examples.test.js",
45
+ "test:check": "node test/check.test.js",
45
46
  "test:manifest": "node test/manifest.test.js",
46
47
  "test:playground": "node test/playground.test.js",
47
48
  "test:package": "node test/package.test.js",
48
- "test:all": "npm run test:api && npm run test:n3gen && npm run test:examples && npm run test:manifest && npm run test:playground",
49
+ "test:all": "npm run test:api && npm run test:n3gen && npm run test:examples && npm run test:check && npm run test:manifest && npm run test:playground",
49
50
  "pretest": "npm run build && npm run test:packlist",
50
51
  "test": "npm run test:all",
51
52
  "posttest": "npm run test:package",