Compare commits
363 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
482d5ecfa3 | ||
|
|
84b8ddb582 | ||
|
|
113bb5888a | ||
|
|
bf5fe6920b | ||
|
|
4b52ed0d2a | ||
|
|
d2c558ccfa | ||
|
|
a01f78b510 | ||
|
|
d80b473fae | ||
|
|
e6b4bc3d94 | ||
|
|
c6cde8db74 | ||
|
|
841a348dd0 | ||
|
|
b46fae331b | ||
|
|
7223e08df3 | ||
|
|
8321f83dac | ||
|
|
bd441a0293 | ||
|
|
f5a07e0d70 | ||
|
|
9d750ed5e1 | ||
|
|
9f111fe445 | ||
|
|
a4e433dab1 | ||
|
|
4e9f1e4fac | ||
|
|
4dee130873 | ||
|
|
8e712532e1 | ||
|
|
4b85236c5f | ||
|
|
66f003e6fd | ||
|
|
b35a2d5f5a | ||
|
|
320b5f8568 | ||
|
|
99b2af6c99 | ||
|
|
6e71acdb7d | ||
|
|
8406d37991 | ||
|
|
64bb597908 | ||
|
|
068864ea87 | ||
|
|
03a3ddbd63 | ||
|
|
122adee23b | ||
|
|
556afecbb8 | ||
|
|
e4407cbdd1 | ||
|
|
f57d60dab0 | ||
|
|
0aa3939a75 | ||
|
|
52cb81e75e | ||
|
|
945121202d | ||
|
|
f4e0dddd9d | ||
|
|
6b62176fd0 | ||
|
|
44483b4d54 | ||
|
|
48d3de77fe | ||
|
|
680b176501 | ||
|
|
dc0338e978 | ||
|
|
ff3e0a50af | ||
|
|
03c8c07fe0 | ||
|
|
3a6fc5b669 | ||
|
|
d258cdb839 | ||
|
|
aa5629354e | ||
|
|
efc4a04829 | ||
|
|
dd611ea64a | ||
|
|
4bd5f3bec7 | ||
|
|
c2b3509b6a | ||
|
|
7f3f5fb889 | ||
|
|
e0fbf17226 | ||
|
|
4e18cbafba | ||
|
|
46c36d7f3e | ||
|
|
c46a935cfc | ||
|
|
f50415cb32 | ||
|
|
4f1a151e97 | ||
|
|
c8e3fdba51 | ||
|
|
4b3fc20c62 | ||
|
|
3131f8ac64 | ||
|
|
60a4835590 | ||
|
|
172d72aa46 | ||
|
|
b4fcc6500b | ||
|
|
ddb6f31562 | ||
|
|
dc080b30fc | ||
|
|
9901e17437 | ||
|
|
ea000894f0 | ||
|
|
e7742b529a | ||
|
|
8eba0c4923 | ||
|
|
e0c0070a13 | ||
|
|
65ce116998 | ||
|
|
e348e7d4e3 | ||
|
|
492090470c | ||
|
|
3ec900c8df | ||
|
|
d0a008ed22 | ||
|
|
f2292f1c07 | ||
|
|
44392cfcca | ||
|
|
110630d230 | ||
|
|
ebe12d96c1 | ||
|
|
24c8ac8e21 | ||
|
|
259ad6e242 | ||
|
|
dd1f7c7777 | ||
|
|
c1b471208d | ||
|
|
606bab9e6d | ||
|
|
0edf5620a2 | ||
|
|
cdf87641c5 | ||
|
|
eb2995dd3b | ||
|
|
cd6a64c015 | ||
|
|
a4a83d047d | ||
|
|
a4414369ce | ||
|
|
83e4b72307 | ||
|
|
34b3e4fa7b | ||
|
|
c0e879dc1e | ||
|
|
fa31b001f4 | ||
|
|
0897061ff6 | ||
|
|
28a3e1bc7b | ||
|
|
3fd3d20722 | ||
|
|
90735586b5 | ||
|
|
78befc7665 | ||
|
|
ef549d3b19 | ||
|
|
777c756a7f | ||
|
|
037caf369c | ||
|
|
54085b5833 | ||
|
|
2bfa8e59e7 | ||
|
|
5d31db39a4 | ||
|
|
adcd0de7e4 | ||
|
|
c2f9789a64 | ||
|
|
579cbb5d11 | ||
|
|
cad2be43bf | ||
|
|
a0a4f0eb90 | ||
|
|
9f4f8e79ce | ||
|
|
77e0dbb42e | ||
|
|
eff5cdbf40 | ||
|
|
eef3571299 | ||
|
|
f227d8405e | ||
|
|
9520e5814b | ||
|
|
28ad4fd046 | ||
|
|
7626a69fa1 | ||
|
|
121c0ce516 | ||
|
|
5a64db98fe | ||
|
|
abfae9c6c0 | ||
|
|
5272e2f1b4 | ||
|
|
90d4b11922 | ||
|
|
d552ef6569 | ||
|
|
f050e9b6a8 | ||
|
|
a5e108bc37 | ||
|
|
58290515b5 | ||
|
|
423f65046e | ||
|
|
badeaf8246 | ||
|
|
d38100581c | ||
|
|
f4eff5ca56 | ||
|
|
5b02c21ebf | ||
|
|
5f1668702a | ||
|
|
1faaeeebf1 | ||
|
|
20a7c89084 | ||
|
|
e83417b243 | ||
|
|
36b80dc093 | ||
|
|
1812b1a56e | ||
|
|
1a70b3d2c0 | ||
|
|
abf066701e | ||
|
|
4984ea4179 | ||
|
|
3cb251ea6c | ||
|
|
4bfea41291 | ||
|
|
99376515ef | ||
|
|
23f4ba4205 | ||
|
|
55ad136283 | ||
|
|
c717541099 | ||
|
|
c2e921c2dc | ||
|
|
e499169f0e | ||
|
|
84c088df67 | ||
|
|
f210f95f99 | ||
|
|
17b81c7c72 | ||
|
|
2911fce7cc | ||
|
|
e622d9fa6b | ||
|
|
8186fbb8b3 | ||
|
|
68ccff74fa | ||
|
|
9a13cb72c6 | ||
|
|
65abaa332f | ||
|
|
67e5829fd9 | ||
|
|
995b41e697 | ||
|
|
eb51bdfe2f | ||
|
|
bbb9ec637a | ||
|
|
dc012b49f5 | ||
|
|
13863a68f7 | ||
|
|
2962f76c81 | ||
|
|
b9b3ef6e74 | ||
|
|
310ab2eab2 | ||
|
|
53320070da | ||
|
|
2d5593681f | ||
|
|
b3f97dbb40 | ||
|
|
a48d76321e | ||
|
|
59222c58b1 | ||
|
|
4d95a7f244 | ||
|
|
5a8159eed7 | ||
|
|
e24fcb9ded | ||
|
|
4b94dc60d2 | ||
|
|
2046603d01 | ||
|
|
30412361e1 | ||
|
|
e846c85188 | ||
|
|
99b74095e6 | ||
|
|
6b802d36bf | ||
|
|
33ca43ca40 | ||
|
|
f5280a3090 | ||
|
|
c28d8ccea4 | ||
|
|
9690545901 | ||
|
|
eba4fb94cf | ||
|
|
565978225a | ||
|
|
cce9ca87fa | ||
|
|
683c523ece | ||
|
|
7a4dc20dc9 | ||
|
|
022dda06eb | ||
|
|
7b88a2d248 | ||
|
|
fce5b92091 | ||
|
|
45a506334c | ||
|
|
e47901a67f | ||
|
|
7430daa768 | ||
|
|
6ce25c8a3b | ||
|
|
7b8fa1eb4a | ||
|
|
ffa5349f25 | ||
|
|
bb472b63cc | ||
|
|
57f566a7a1 | ||
|
|
2181993246 | ||
|
|
60d1ecfa75 | ||
|
|
3962db12a8 | ||
|
|
f192507cd9 | ||
|
|
252be3e001 | ||
|
|
28f12a04f7 | ||
|
|
d6232dc49c | ||
|
|
68a220aa1c | ||
|
|
2e7db0f8bd | ||
|
|
175ff1e6c4 | ||
|
|
0b42139393 | ||
|
|
67a9103b07 | ||
|
|
f141a4e186 | ||
|
|
aba29df34c | ||
|
|
87ce7d7432 | ||
|
|
68dccd54b1 | ||
|
|
4753f4c7c6 | ||
|
|
13c62bf29f | ||
|
|
670209e9fc | ||
|
|
4af0d3141f | ||
|
|
ab281de3c6 | ||
|
|
d556d28f49 | ||
|
|
9cfb2fa052 | ||
|
|
30c03b5529 | ||
|
|
b943f90766 | ||
|
|
0108f5b0b1 | ||
|
|
50145c6cf2 | ||
|
|
4a8607726c | ||
|
|
9bcba4020d | ||
|
|
8fd9ff3848 | ||
|
|
3fb7cb82cd | ||
|
|
e0ec5c115f | ||
|
|
f0868ba3ed | ||
|
|
425bc12353 | ||
|
|
03754be71e | ||
|
|
70002800c2 | ||
|
|
281c35677b | ||
|
|
92d15c3d91 | ||
|
|
b1773ac90e | ||
|
|
645d9abf9c | ||
|
|
d2f2bdf88d | ||
|
|
90ba17b68c | ||
|
|
31406fd520 | ||
|
|
49bc51ba89 | ||
|
|
92592104a4 | ||
|
|
33f4614d28 | ||
|
|
6c197c376a | ||
|
|
bcf1b49db2 | ||
|
|
49f6e70a19 | ||
|
|
31fb815681 | ||
|
|
7dfe24ff98 | ||
|
|
a5627d0cee | ||
|
|
93cfa71df2 | ||
|
|
78320d3265 | ||
|
|
9e908935f8 | ||
|
|
b18a703529 | ||
|
|
ea52dc60be | ||
|
|
f5699ce830 | ||
|
|
10aa0956ee | ||
|
|
816c164996 | ||
|
|
ee201e1336 | ||
|
|
4897952330 | ||
|
|
e1d85c6dc2 | ||
|
|
c420ccd029 | ||
|
|
a880629831 | ||
|
|
5e2dea1f28 | ||
|
|
f47d688be4 | ||
|
|
acfc5e5e68 | ||
|
|
503db94b2c | ||
|
|
a4381e5e39 | ||
|
|
e11de60def | ||
|
|
b2479e9de8 | ||
|
|
49d1cef7ae | ||
|
|
ba72cc1b29 | ||
|
|
c58b0e7c35 | ||
|
|
f19d262825 | ||
|
|
68f3f2e159 | ||
|
|
269e23c1b1 | ||
|
|
e111b8b9b8 | ||
|
|
353ff07420 | ||
|
|
94dec31130 | ||
|
|
cf5d3ed745 | ||
|
|
b0b287cd47 | ||
|
|
bcdf1f5e9d | ||
|
|
17d8e76e05 | ||
|
|
8db9038c53 | ||
|
|
a276ba70e0 | ||
|
|
b7442c1e92 | ||
|
|
364ba79517 | ||
|
|
47408763e5 | ||
|
|
bd187ebfe7 | ||
|
|
59cb3c2bbf | ||
|
|
44f7412a5c | ||
|
|
01464057ad | ||
|
|
0208020e3e | ||
|
|
a2f53361eb | ||
|
|
17db05c2c7 | ||
|
|
6139ea328d | ||
|
|
d20b4a410b | ||
|
|
05c64f53b1 | ||
|
|
f65d0bb82d | ||
|
|
50d2831081 | ||
|
|
bc9bd4f97b | ||
|
|
369d3e8c50 | ||
|
|
7d73eb6bd4 | ||
|
|
f59f153ee7 | ||
|
|
20c4a0f8f7 | ||
|
|
e776a051ad | ||
|
|
77e6c22ad8 | ||
|
|
c9d7251e3b | ||
|
|
8417b5fc9d | ||
|
|
acc29e7977 | ||
|
|
ebc0a30035 | ||
|
|
e2d55e13d3 | ||
|
|
e4d9c5f467 | ||
|
|
d8e3a85ef7 | ||
|
|
464685b52b | ||
|
|
5fed4e80a7 | ||
|
|
e53140426f | ||
|
|
9a4d290cf8 | ||
|
|
acd24d6198 | ||
|
|
880b00ef3f | ||
|
|
3069711447 | ||
|
|
4b6c717812 | ||
|
|
1d329cc310 | ||
|
|
b4f9a3b9b6 | ||
|
|
2dd5246506 | ||
|
|
4ba0e3611b | ||
|
|
728f79b86c | ||
|
|
192a4a2891 | ||
|
|
fafd85fb30 | ||
|
|
1c23065329 | ||
|
|
ed105b04ad | ||
|
|
f10efec21d | ||
|
|
72b4cf8e71 | ||
|
|
547fc40dbe | ||
|
|
9f1671658d | ||
|
|
18d0676fad | ||
|
|
7833a58461 | ||
|
|
0020d71089 | ||
|
|
cfdf39d1fa | ||
|
|
26f1eae9a1 | ||
|
|
3eff85059a | ||
|
|
d2d0e9e5dd | ||
|
|
c86d1000c0 | ||
|
|
911634cb42 | ||
|
|
0aa746fb1e | ||
|
|
33800c4a88 | ||
|
|
909ccadfa1 | ||
|
|
e352deb989 | ||
|
|
f5a6a26c43 | ||
|
|
dd7184da54 | ||
|
|
1168ddb1fe | ||
|
|
77ab636e6a | ||
|
|
f5dcacc79d | ||
|
|
e7c3c7aab6 | ||
|
|
7603b0a1cc | ||
|
|
dea3721b1c |
@@ -2,3 +2,4 @@
|
|||||||
target
|
target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
notes/
|
notes/
|
||||||
|
.lighthouse/
|
||||||
|
|||||||
@@ -1,203 +0,0 @@
|
|||||||
apiVersion: tekton.dev/v1beta1
|
|
||||||
kind: PipelineRun
|
|
||||||
metadata:
|
|
||||||
name: rust-foreign-document-test
|
|
||||||
spec:
|
|
||||||
pipelineSpec:
|
|
||||||
timeouts:
|
|
||||||
pipeline: "2h0m0s"
|
|
||||||
tasks: "1h0m40s"
|
|
||||||
finally: "0h30m0s"
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
description: The name for the built image
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
|
||||||
description: The path to the build context
|
|
||||||
type: string
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
description: The path to the Dockerfile
|
|
||||||
type: string
|
|
||||||
tasks:
|
|
||||||
- name: do-stuff
|
|
||||||
taskSpec:
|
|
||||||
metadata: {}
|
|
||||||
stepTemplate:
|
|
||||||
image: alpine:3.18
|
|
||||||
name: ""
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: 10m
|
|
||||||
memory: 600Mi
|
|
||||||
workingDir: /workspace/source
|
|
||||||
steps:
|
|
||||||
- image: alpine:3.18
|
|
||||||
name: do-stuff-step
|
|
||||||
script: |
|
|
||||||
#!/usr/bin/env sh
|
|
||||||
echo "hello world"
|
|
||||||
- name: report-pending
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has started"
|
|
||||||
- name: STATE
|
|
||||||
value: pending
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: fetch-repository
|
|
||||||
taskRef:
|
|
||||||
name: git-clone
|
|
||||||
workspaces:
|
|
||||||
- name: output
|
|
||||||
workspace: git-source
|
|
||||||
params:
|
|
||||||
- name: url
|
|
||||||
value: $(params.REPO_URL)
|
|
||||||
- name: revision
|
|
||||||
value: $(params.PULL_BASE_SHA)
|
|
||||||
- name: deleteExisting
|
|
||||||
value: "true"
|
|
||||||
- name: build-image
|
|
||||||
taskRef:
|
|
||||||
name: kaniko
|
|
||||||
params:
|
|
||||||
- name: IMAGE
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: CONTEXT
|
|
||||||
value: $(params.path-to-image-context)
|
|
||||||
- name: DOCKERFILE
|
|
||||||
value: $(params.path-to-dockerfile)
|
|
||||||
- name: BUILDER_IMAGE
|
|
||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
|
||||||
- name: EXTRA_ARGS
|
|
||||||
value:
|
|
||||||
- --target=foreign-document-test
|
|
||||||
- --cache=true
|
|
||||||
- --cache-copy-layers
|
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
|
||||||
- --use-new-run # Should result in a speed-up
|
|
||||||
- --reproducible # To remove timestamps so layer caching works.
|
|
||||||
- --snapshot-mode=redo
|
|
||||||
- --skip-unused-stages=true
|
|
||||||
- --registry-mirror=dockerhub.dockerhub.svc.cluster.local
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: dockerconfig
|
|
||||||
workspace: docker-credentials
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
- name: run-image
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- build-image
|
|
||||||
params:
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
finally:
|
|
||||||
- name: report-success
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Succeeded", "Completed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has succeeded"
|
|
||||||
- name: STATE
|
|
||||||
value: success
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: report-failure
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Failed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has failed"
|
|
||||||
- name: STATE
|
|
||||||
value: failure
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: cargo-cache-autoclean
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
params:
|
|
||||||
- name: command
|
|
||||||
value: [cargo, cache, --autoclean]
|
|
||||||
- name: args
|
|
||||||
value: []
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
- name: docker-credentials
|
|
||||||
- name: cargo-cache
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
volumeClaimTemplate:
|
|
||||||
spec:
|
|
||||||
storageClassName: "nfs-client"
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
subPath: rust-source
|
|
||||||
- name: cargo-cache
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: organic-cargo-cache-test-foreign-document
|
|
||||||
- name: docker-credentials
|
|
||||||
secret:
|
|
||||||
secretName: harbor-plain
|
|
||||||
serviceAccountName: build-bot
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
value: "harbor.fizz.buzz/private/organic-test-foreign-document"
|
|
||||||
- name: path-to-image-context
|
|
||||||
value: docker/organic_test/
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
value: docker/organic_test/Dockerfile
|
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
apiVersion: tekton.dev/v1beta1
|
|
||||||
kind: PipelineRun
|
|
||||||
metadata:
|
|
||||||
name: rust-build
|
|
||||||
spec:
|
|
||||||
pipelineSpec:
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
description: The name for the built image
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
|
||||||
description: The path to the build context
|
|
||||||
type: string
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
description: The path to the Dockerfile
|
|
||||||
type: string
|
|
||||||
tasks:
|
|
||||||
- name: report-pending
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has started"
|
|
||||||
- name: STATE
|
|
||||||
value: pending
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: fetch-repository
|
|
||||||
taskRef:
|
|
||||||
name: git-clone
|
|
||||||
workspaces:
|
|
||||||
- name: output
|
|
||||||
workspace: git-source
|
|
||||||
params:
|
|
||||||
- name: url
|
|
||||||
value: $(params.REPO_URL)
|
|
||||||
- name: revision
|
|
||||||
value: $(params.PULL_BASE_SHA)
|
|
||||||
- name: deleteExisting
|
|
||||||
value: "true"
|
|
||||||
- name: build-image
|
|
||||||
taskRef:
|
|
||||||
name: kaniko
|
|
||||||
params:
|
|
||||||
- name: IMAGE
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: CONTEXT
|
|
||||||
value: $(params.path-to-image-context)
|
|
||||||
- name: DOCKERFILE
|
|
||||||
value: $(params.path-to-dockerfile)
|
|
||||||
- name: BUILDER_IMAGE
|
|
||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
|
||||||
- name: EXTRA_ARGS
|
|
||||||
value:
|
|
||||||
- --cache=true
|
|
||||||
- --cache-copy-layers
|
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
|
||||||
- --use-new-run # Should result in a speed-up
|
|
||||||
- --reproducible # To remove timestamps so layer caching works.
|
|
||||||
- --snapshot-mode=redo
|
|
||||||
- --skip-unused-stages=true
|
|
||||||
- --registry-mirror=dockerhub.dockerhub.svc.cluster.local
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: dockerconfig
|
|
||||||
workspace: docker-credentials
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
- name: run-image-none
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- build-image
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: ["--no-default-features"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-tracing
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-none
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: ["--no-default-features", "--features", "tracing"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-compare
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-tracing
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: ["--no-default-features", "--features", "compare"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-default
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-compare
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: []
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-tracing-compare
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-default
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value: ["--no-default-features", "--features", "tracing,compare"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-compare-foreign
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-tracing-compare
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value:
|
|
||||||
[
|
|
||||||
"--no-default-features",
|
|
||||||
"--features",
|
|
||||||
"compare,foreign_document_test",
|
|
||||||
]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: run-image-all
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- run-image-compare-foreign
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value:
|
|
||||||
[
|
|
||||||
"--no-default-features",
|
|
||||||
"--features",
|
|
||||||
"tracing,compare,foreign_document_test",
|
|
||||||
]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
finally:
|
|
||||||
- name: report-success
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Succeeded", "Completed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has succeeded"
|
|
||||||
- name: STATE
|
|
||||||
value: success
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: report-failure
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Failed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has failed"
|
|
||||||
- name: STATE
|
|
||||||
value: failure
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: cargo-cache-autoclean
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
params:
|
|
||||||
- name: command
|
|
||||||
value: [cargo, cache, --autoclean]
|
|
||||||
- name: args
|
|
||||||
value: []
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
- name: docker-credentials
|
|
||||||
- name: cargo-cache
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
volumeClaimTemplate:
|
|
||||||
spec:
|
|
||||||
storageClassName: "nfs-client"
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
subPath: rust-source
|
|
||||||
- name: cargo-cache
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: organic-cargo-cache-build
|
|
||||||
- name: docker-credentials
|
|
||||||
secret:
|
|
||||||
secretName: harbor-plain
|
|
||||||
serviceAccountName: build-bot
|
|
||||||
timeout: 240h0m0s
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
value: "harbor.fizz.buzz/private/organic-build"
|
|
||||||
- name: path-to-image-context
|
|
||||||
value: docker/organic_build/
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
value: docker/organic_build/Dockerfile
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
apiVersion: tekton.dev/v1beta1
|
|
||||||
kind: PipelineRun
|
|
||||||
metadata:
|
|
||||||
name: rust-test
|
|
||||||
spec:
|
|
||||||
pipelineSpec:
|
|
||||||
timeouts:
|
|
||||||
pipeline: "2h0m0s"
|
|
||||||
tasks: "1h0m40s"
|
|
||||||
finally: "0h30m0s"
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
description: The name for the built image
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
|
||||||
description: The path to the build context
|
|
||||||
type: string
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
description: The path to the Dockerfile
|
|
||||||
type: string
|
|
||||||
tasks:
|
|
||||||
- name: do-stuff
|
|
||||||
taskSpec:
|
|
||||||
metadata: {}
|
|
||||||
stepTemplate:
|
|
||||||
image: alpine:3.18
|
|
||||||
name: ""
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: 10m
|
|
||||||
memory: 600Mi
|
|
||||||
workingDir: /workspace/source
|
|
||||||
steps:
|
|
||||||
- image: alpine:3.18
|
|
||||||
name: do-stuff-step
|
|
||||||
script: |
|
|
||||||
#!/usr/bin/env sh
|
|
||||||
echo "hello world"
|
|
||||||
- name: report-pending
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has started"
|
|
||||||
- name: STATE
|
|
||||||
value: pending
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: fetch-repository
|
|
||||||
taskRef:
|
|
||||||
name: git-clone
|
|
||||||
workspaces:
|
|
||||||
- name: output
|
|
||||||
workspace: git-source
|
|
||||||
params:
|
|
||||||
- name: url
|
|
||||||
value: $(params.REPO_URL)
|
|
||||||
- name: revision
|
|
||||||
value: $(params.PULL_BASE_SHA)
|
|
||||||
- name: deleteExisting
|
|
||||||
value: "true"
|
|
||||||
- name: build-image
|
|
||||||
taskRef:
|
|
||||||
name: kaniko
|
|
||||||
params:
|
|
||||||
- name: IMAGE
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: CONTEXT
|
|
||||||
value: $(params.path-to-image-context)
|
|
||||||
- name: DOCKERFILE
|
|
||||||
value: $(params.path-to-dockerfile)
|
|
||||||
- name: BUILDER_IMAGE
|
|
||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
|
||||||
- name: EXTRA_ARGS
|
|
||||||
value:
|
|
||||||
- --target=tester
|
|
||||||
- --cache=true
|
|
||||||
- --cache-copy-layers
|
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
|
||||||
- --use-new-run # Should result in a speed-up
|
|
||||||
- --reproducible # To remove timestamps so layer caching works.
|
|
||||||
- --snapshot-mode=redo
|
|
||||||
- --skip-unused-stages=true
|
|
||||||
- --registry-mirror=dockerhub.dockerhub.svc.cluster.local
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: dockerconfig
|
|
||||||
workspace: docker-credentials
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
- name: run-image
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- build-image
|
|
||||||
params:
|
|
||||||
- name: args
|
|
||||||
value:
|
|
||||||
[
|
|
||||||
--no-default-features,
|
|
||||||
--features,
|
|
||||||
compare,
|
|
||||||
--no-fail-fast,
|
|
||||||
--lib,
|
|
||||||
--test,
|
|
||||||
test_loader,
|
|
||||||
]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
finally:
|
|
||||||
- name: report-success
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Succeeded", "Completed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has succeeded"
|
|
||||||
- name: STATE
|
|
||||||
value: success
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: report-failure
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Failed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has failed"
|
|
||||||
- name: STATE
|
|
||||||
value: failure
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: cargo-cache-autoclean
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
params:
|
|
||||||
- name: command
|
|
||||||
value: [cargo, cache, --autoclean]
|
|
||||||
- name: args
|
|
||||||
value: []
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
- name: docker-credentials
|
|
||||||
- name: cargo-cache
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
volumeClaimTemplate:
|
|
||||||
spec:
|
|
||||||
storageClassName: "nfs-client"
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
subPath: rust-source
|
|
||||||
- name: cargo-cache
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: organic-cargo-cache-test
|
|
||||||
- name: docker-credentials
|
|
||||||
secret:
|
|
||||||
secretName: harbor-plain
|
|
||||||
serviceAccountName: build-bot
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
value: "harbor.fizz.buzz/private/organic-test"
|
|
||||||
- name: path-to-image-context
|
|
||||||
value: docker/organic_test/
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
value: docker/organic_test/Dockerfile
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
apiVersion: tekton.dev/v1beta1
|
|
||||||
kind: PipelineRun
|
|
||||||
metadata:
|
|
||||||
name: rustfmt
|
|
||||||
spec:
|
|
||||||
pipelineSpec:
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
description: The name for the built image
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
|
||||||
description: The path to the build context
|
|
||||||
type: string
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
description: The path to the Dockerfile
|
|
||||||
type: string
|
|
||||||
- name: GIT_USER_NAME
|
|
||||||
description: The username for git
|
|
||||||
type: string
|
|
||||||
default: "fluxcdbot"
|
|
||||||
- name: GIT_USER_EMAIL
|
|
||||||
description: The email for git
|
|
||||||
type: string
|
|
||||||
default: "fluxcdbot@users.noreply.github.com"
|
|
||||||
tasks:
|
|
||||||
- name: do-stuff
|
|
||||||
taskSpec:
|
|
||||||
metadata: {}
|
|
||||||
stepTemplate:
|
|
||||||
image: alpine:3.18
|
|
||||||
name: ""
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: 10m
|
|
||||||
memory: 600Mi
|
|
||||||
workingDir: /workspace/source
|
|
||||||
steps:
|
|
||||||
- image: alpine:3.18
|
|
||||||
name: do-stuff-step
|
|
||||||
script: |
|
|
||||||
#!/usr/bin/env sh
|
|
||||||
echo "hello world"
|
|
||||||
- name: report-pending
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has started"
|
|
||||||
- name: STATE
|
|
||||||
value: pending
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: fetch-repository
|
|
||||||
taskRef:
|
|
||||||
name: git-clone
|
|
||||||
workspaces:
|
|
||||||
- name: output
|
|
||||||
workspace: git-source
|
|
||||||
params:
|
|
||||||
- name: url
|
|
||||||
value: $(params.REPO_URL)
|
|
||||||
- name: revision
|
|
||||||
value: $(params.PULL_BASE_SHA)
|
|
||||||
- name: deleteExisting
|
|
||||||
value: "true"
|
|
||||||
- name: build-image
|
|
||||||
taskRef:
|
|
||||||
name: kaniko
|
|
||||||
params:
|
|
||||||
- name: IMAGE
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: CONTEXT
|
|
||||||
value: $(params.path-to-image-context)
|
|
||||||
- name: DOCKERFILE
|
|
||||||
value: $(params.path-to-dockerfile)
|
|
||||||
- name: BUILDER_IMAGE
|
|
||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
|
||||||
- name: EXTRA_ARGS
|
|
||||||
value:
|
|
||||||
- --cache=true
|
|
||||||
- --cache-copy-layers
|
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
|
||||||
- --use-new-run # Should result in a speed-up
|
|
||||||
- --reproducible # To remove timestamps so layer caching works.
|
|
||||||
- --snapshot-mode=redo
|
|
||||||
- --skip-unused-stages=true
|
|
||||||
- --registry-mirror=dockerhub.dockerhub.svc.cluster.local
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: dockerconfig
|
|
||||||
workspace: docker-credentials
|
|
||||||
runAfter:
|
|
||||||
- fetch-repository
|
|
||||||
- name: rustfmt
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
runAfter:
|
|
||||||
- build-image
|
|
||||||
params:
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: cargo-fix
|
|
||||||
taskRef:
|
|
||||||
name: run-docker-image
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
- name: cargo-cache
|
|
||||||
workspace: cargo-cache
|
|
||||||
runAfter:
|
|
||||||
- rustfmt
|
|
||||||
params:
|
|
||||||
- name: command
|
|
||||||
value: ["cargo", "fix"]
|
|
||||||
- name: args
|
|
||||||
value: ["--allow-dirty"]
|
|
||||||
- name: docker-image
|
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: commit-changes
|
|
||||||
taskRef:
|
|
||||||
name: git-cli
|
|
||||||
params:
|
|
||||||
- name: GIT_USER_NAME
|
|
||||||
value: $(params.GIT_USER_NAME)
|
|
||||||
- name: GIT_USER_EMAIL
|
|
||||||
value: $(params.GIT_USER_EMAIL)
|
|
||||||
- name: GIT_SCRIPT
|
|
||||||
value: |
|
|
||||||
pwd
|
|
||||||
git config --global --add safe.directory /workspace/source
|
|
||||||
git_status=$(git status --porcelain)
|
|
||||||
if [ -n "$git_status" ]; then
|
|
||||||
git commit -a -m "CI: autofix rust code."
|
|
||||||
git push origin HEAD:$(params.PULL_BASE_REF)
|
|
||||||
else
|
|
||||||
echo "No changes to commit."
|
|
||||||
fi
|
|
||||||
workspaces:
|
|
||||||
- name: source
|
|
||||||
workspace: git-source
|
|
||||||
runAfter:
|
|
||||||
- cargo-fix
|
|
||||||
finally:
|
|
||||||
- name: report-success
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Succeeded", "Completed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has succeeded"
|
|
||||||
- name: STATE
|
|
||||||
value: success
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
- name: report-failure
|
|
||||||
when:
|
|
||||||
- input: "$(tasks.status)"
|
|
||||||
operator: in
|
|
||||||
values: ["Failed"]
|
|
||||||
taskRef:
|
|
||||||
name: gitea-set-status
|
|
||||||
params:
|
|
||||||
- name: CONTEXT
|
|
||||||
value: "$(params.JOB_NAME)"
|
|
||||||
- name: REPO_FULL_NAME
|
|
||||||
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
|
||||||
- name: GITEA_HOST_URL
|
|
||||||
value: code.fizz.buzz
|
|
||||||
- name: SHA
|
|
||||||
value: "$(tasks.fetch-repository.results.commit)"
|
|
||||||
- name: DESCRIPTION
|
|
||||||
value: "Build $(params.JOB_NAME) has failed"
|
|
||||||
- name: STATE
|
|
||||||
value: failure
|
|
||||||
- name: TARGET_URL
|
|
||||||
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
- name: docker-credentials
|
|
||||||
workspaces:
|
|
||||||
- name: git-source
|
|
||||||
volumeClaimTemplate:
|
|
||||||
spec:
|
|
||||||
storageClassName: "nfs-client"
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 10Gi
|
|
||||||
subPath: rust-source
|
|
||||||
- name: cargo-cache
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: organic-cargo-cache-fmt
|
|
||||||
- name: docker-credentials
|
|
||||||
secret:
|
|
||||||
secretName: harbor-plain
|
|
||||||
serviceAccountName: build-bot
|
|
||||||
timeout: 240h0m0s
|
|
||||||
params:
|
|
||||||
- name: image-name
|
|
||||||
value: "harbor.fizz.buzz/private/organic-fmt"
|
|
||||||
- name: path-to-image-context
|
|
||||||
value: docker/cargo_fmt/
|
|
||||||
- name: path-to-dockerfile
|
|
||||||
value: docker/cargo_fmt/Dockerfile
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
apiVersion: config.lighthouse.jenkins-x.io/v1alpha1
|
|
||||||
kind: TriggerConfig
|
|
||||||
spec:
|
|
||||||
postsubmits:
|
|
||||||
- name: rustfmt
|
|
||||||
source: "pipeline-rustfmt.yaml"
|
|
||||||
# Override https-based url from lighthouse events.
|
|
||||||
clone_uri: "git@code.fizz.buzz:talexander/organic.git"
|
|
||||||
branches:
|
|
||||||
- ^main$
|
|
||||||
- ^master$
|
|
||||||
- name: rust-test
|
|
||||||
source: "pipeline-rust-test.yaml"
|
|
||||||
# Override https-based url from lighthouse events.
|
|
||||||
clone_uri: "git@code.fizz.buzz:talexander/organic.git"
|
|
||||||
skip_branches:
|
|
||||||
# We already run on every commit, so running when the semver tags get pushed is causing needless double-processing.
|
|
||||||
- "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
|
|
||||||
- name: rust-foreign-document-test
|
|
||||||
source: "pipeline-foreign-document-test.yaml"
|
|
||||||
# Override https-based url from lighthouse events.
|
|
||||||
clone_uri: "git@code.fizz.buzz:talexander/organic.git"
|
|
||||||
skip_branches:
|
|
||||||
# We already run on every commit, so running when the semver tags get pushed is causing needless double-processing.
|
|
||||||
- "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
|
|
||||||
- name: rust-build
|
|
||||||
source: "pipeline-rust-build.yaml"
|
|
||||||
# Override https-based url from lighthouse events.
|
|
||||||
clone_uri: "git@code.fizz.buzz:talexander/organic.git"
|
|
||||||
skip_branches:
|
|
||||||
# We already run on every commit, so running when the semver tags get pushed is causing needless double-processing.
|
|
||||||
- "^v[0-9]+\\.[0-9]+\\.[0-9]+$"
|
|
||||||
701
.webhook_bridge/pipeline-build-hash.yaml
Normal file
701
.webhook_bridge/pipeline-build-hash.yaml
Normal file
@@ -0,0 +1,701 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
name: build
|
||||||
|
spec:
|
||||||
|
timeouts:
|
||||||
|
pipeline: "2h0m0s"
|
||||||
|
tasks: "1h0m0s"
|
||||||
|
finally: "0h30m0s"
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: build-bot
|
||||||
|
pipelineSpec:
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
description: The name for the built image
|
||||||
|
type: string
|
||||||
|
- name: target-name
|
||||||
|
description: The dockerfile target to build
|
||||||
|
type: string
|
||||||
|
- name: path-to-image-context
|
||||||
|
description: The path to the build context
|
||||||
|
type: string
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
description: The path to the Dockerfile
|
||||||
|
type: string
|
||||||
|
tasks:
|
||||||
|
- name: report-pending
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has started"
|
||||||
|
- name: STATE
|
||||||
|
value: pending
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: fetch-repository
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-clone/0.9/git-clone.yaml
|
||||||
|
workspaces:
|
||||||
|
- name: output
|
||||||
|
workspace: git-source
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: $(params.REPO_URL)
|
||||||
|
- name: revision
|
||||||
|
value: $(params.PULL_BASE_SHA)
|
||||||
|
- name: deleteExisting
|
||||||
|
value: "true"
|
||||||
|
- name: get-git-commit-time
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: "$(workspaces.repo.path)"
|
||||||
|
results:
|
||||||
|
- name: unix-time
|
||||||
|
description: The time of the git commit in unix timestamp format.
|
||||||
|
steps:
|
||||||
|
- image: alpine/git:v2.34.2
|
||||||
|
name: detect-tag-step
|
||||||
|
script: |
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo pipefail
|
||||||
|
echo -n "$(git log -1 --pretty=%ct)" | tee $(results.unix-time.path)
|
||||||
|
workspaces:
|
||||||
|
- name: repo
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: build-image
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/talexander/personal_tekton_catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: 7ee31a185243ee6da13dcd26a592c585b64c80e5
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/buildkit-rootless-daemonless/0.1/buildkit-rootless-daemonless.yaml
|
||||||
|
params:
|
||||||
|
- name: OUTPUT
|
||||||
|
value: >-
|
||||||
|
type=image,"name=$(params.image-name):latest,$(params.image-name):$(tasks.fetch-repository.results.commit)",push=true,compression=zstd,compression-level=22,oci-mediatypes=true
|
||||||
|
- name: CONTEXT
|
||||||
|
value: $(params.path-to-image-context)
|
||||||
|
- name: DOCKERFILE
|
||||||
|
value: $(params.path-to-dockerfile)
|
||||||
|
- name: EXTRA_ARGS
|
||||||
|
value:
|
||||||
|
- "--opt"
|
||||||
|
- "target=$(params.target-name)"
|
||||||
|
- --import-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache"
|
||||||
|
- --export-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache,mode=max,compression=zstd,compression-level=22,rewrite-timestamp=true,image-manifest=true,oci-mediatypes=true"
|
||||||
|
- --opt
|
||||||
|
- build-arg:SOURCE_DATE_EPOCH=$(tasks.get-git-commit-time.results.unix-time)
|
||||||
|
- name: BUILDKITD_TOML
|
||||||
|
value: |
|
||||||
|
debug = true
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
[registry."dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
#############
|
||||||
|
- name: run-image-none
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args: ["--no-default-features"]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: none
|
||||||
|
runAfter:
|
||||||
|
- build-image
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-tracing
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args: ["--no-default-features", "--features", "tracing"]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: tracing
|
||||||
|
runAfter:
|
||||||
|
- run-image-none
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-compare
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args: ["--no-default-features", "--features", "compare"]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: compare
|
||||||
|
runAfter:
|
||||||
|
- run-image-tracing
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-default
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args: []
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: default
|
||||||
|
runAfter:
|
||||||
|
- run-image-compare
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-tracing-compare
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args: ["--no-default-features", "--features", "tracing,compare"]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: tracing-compare
|
||||||
|
runAfter:
|
||||||
|
- run-image-default
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-compare-foreign
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
"--no-default-features",
|
||||||
|
"--features",
|
||||||
|
"compare,foreign_document_test",
|
||||||
|
]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: compare-foreign
|
||||||
|
runAfter:
|
||||||
|
- run-image-tracing-compare
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-all
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
"--no-default-features",
|
||||||
|
"--features",
|
||||||
|
"tracing,compare,foreign_document_test",
|
||||||
|
]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: all
|
||||||
|
runAfter:
|
||||||
|
- run-image-compare-foreign
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-wasm
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
"--target",
|
||||||
|
"wasm32-unknown-unknown",
|
||||||
|
"--profile",
|
||||||
|
"wasm",
|
||||||
|
"--bin",
|
||||||
|
"wasm",
|
||||||
|
"--no-default-features",
|
||||||
|
"--features",
|
||||||
|
"wasm",
|
||||||
|
]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: wasm
|
||||||
|
runAfter:
|
||||||
|
- run-image-all
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
- name: run-image-wasm-test
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "build"]
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
"--bin",
|
||||||
|
"wasm_test",
|
||||||
|
"--no-default-features",
|
||||||
|
"--features",
|
||||||
|
"wasm_test",
|
||||||
|
]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: wasm-test
|
||||||
|
runAfter:
|
||||||
|
- run-image-wasm
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
#############
|
||||||
|
finally:
|
||||||
|
- name: report-success
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Succeeded", "Completed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has succeeded"
|
||||||
|
- name: STATE
|
||||||
|
value: success
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: report-failure
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Failed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has failed"
|
||||||
|
- name: STATE
|
||||||
|
value: failure
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: cargo-cache-autoclean
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.18
|
||||||
|
- name: cache-subdir
|
||||||
|
type: string
|
||||||
|
description: subPath used in the persistent volume for the cargo cache.
|
||||||
|
steptemplate:
|
||||||
|
image: alpine:3.18
|
||||||
|
name: ""
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 60Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["ls", "$(workspaces.cargo-cache.path)"]
|
||||||
|
# command: [echo, $(params.cache-subdir)]
|
||||||
|
# command: [cargo, cache, --autoclean]
|
||||||
|
args: []
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
subPath: $(params.cache-subdir)
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
- name: cache-subdir
|
||||||
|
value: none
|
||||||
|
# matrix:
|
||||||
|
# params:
|
||||||
|
# - name: cache-subdir
|
||||||
|
# value:
|
||||||
|
# - none
|
||||||
|
# - tracing
|
||||||
|
# - compare
|
||||||
|
# - default
|
||||||
|
# - tracing-compare
|
||||||
|
# - compare-foreign
|
||||||
|
# - all
|
||||||
|
# - wasm
|
||||||
|
# - wasm-test
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
- name: docker-credentials
|
||||||
|
- name: cargo-cache
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
storageClassName: "local-path"
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
subPath: rust-source
|
||||||
|
- name: cargo-cache
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: organic-cargo-cache-build
|
||||||
|
- name: docker-credentials
|
||||||
|
secret:
|
||||||
|
secretName: harbor-plain
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
value: "harbor.fizz.buzz/private/organic-development-wasm"
|
||||||
|
- name: target-name
|
||||||
|
value: "wasm"
|
||||||
|
- name: path-to-image-context
|
||||||
|
value: .
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
value: docker/organic_development/
|
||||||
301
.webhook_bridge/pipeline-foreign-document-test.yaml
Normal file
301
.webhook_bridge/pipeline-foreign-document-test.yaml
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
name: foreign-document-test
|
||||||
|
spec:
|
||||||
|
timeouts:
|
||||||
|
pipeline: "2h0m0s"
|
||||||
|
tasks: "1h0m40s"
|
||||||
|
finally: "0h30m0s"
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: build-bot
|
||||||
|
pipelineSpec:
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
description: The name for the built image
|
||||||
|
type: string
|
||||||
|
- name: target-name
|
||||||
|
description: The dockerfile target to build
|
||||||
|
type: string
|
||||||
|
- name: path-to-image-context
|
||||||
|
description: The path to the build context
|
||||||
|
type: string
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
description: The path to the Dockerfile
|
||||||
|
type: string
|
||||||
|
tasks:
|
||||||
|
- name: report-pending
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has started"
|
||||||
|
- name: STATE
|
||||||
|
value: pending
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: fetch-repository
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-clone/0.9/git-clone.yaml
|
||||||
|
workspaces:
|
||||||
|
- name: output
|
||||||
|
workspace: git-source
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: $(params.REPO_URL)
|
||||||
|
- name: revision
|
||||||
|
value: $(params.PULL_BASE_SHA)
|
||||||
|
- name: deleteExisting
|
||||||
|
value: "true"
|
||||||
|
- name: get-git-commit-time
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: "$(workspaces.repo.path)"
|
||||||
|
results:
|
||||||
|
- name: unix-time
|
||||||
|
description: The time of the git commit in unix timestamp format.
|
||||||
|
steps:
|
||||||
|
- image: alpine/git:v2.34.2
|
||||||
|
name: detect-tag-step
|
||||||
|
script: |
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo pipefail
|
||||||
|
echo -n "$(git log -1 --pretty=%ct)" | tee $(results.unix-time.path)
|
||||||
|
workspaces:
|
||||||
|
- name: repo
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: build-image
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/talexander/personal_tekton_catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: 7ee31a185243ee6da13dcd26a592c585b64c80e5
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/buildkit-rootless-daemonless/0.1/buildkit-rootless-daemonless.yaml
|
||||||
|
params:
|
||||||
|
- name: OUTPUT
|
||||||
|
value: >-
|
||||||
|
type=image,"name=$(params.image-name):latest,$(params.image-name):$(tasks.fetch-repository.results.commit)",push=true,compression=zstd,compression-level=22,oci-mediatypes=true
|
||||||
|
- name: CONTEXT
|
||||||
|
value: $(params.path-to-image-context)
|
||||||
|
- name: DOCKERFILE
|
||||||
|
value: $(params.path-to-dockerfile)
|
||||||
|
- name: EXTRA_ARGS
|
||||||
|
value:
|
||||||
|
- "--opt"
|
||||||
|
- "target=$(params.target-name)"
|
||||||
|
- --import-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache"
|
||||||
|
- --export-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache,mode=max,compression=zstd,compression-level=22,rewrite-timestamp=true,image-manifest=true,oci-mediatypes=true"
|
||||||
|
- --opt
|
||||||
|
- build-arg:SOURCE_DATE_EPOCH=$(tasks.get-git-commit-time.results.unix-time)
|
||||||
|
- name: BUILDKITD_TOML
|
||||||
|
value: |
|
||||||
|
debug = true
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
[registry."dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: run-test
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
runAfter:
|
||||||
|
- build-image
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
finally:
|
||||||
|
- name: report-success
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Succeeded", "Completed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has succeeded"
|
||||||
|
- name: STATE
|
||||||
|
value: success
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: report-failure
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Failed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has failed"
|
||||||
|
- name: STATE
|
||||||
|
value: failure
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: cargo-cache-autoclean
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: [cargo, cache, --autoclean]
|
||||||
|
args: []
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
- name: docker-credentials
|
||||||
|
- name: cargo-cache
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
storageClassName: "local-path"
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
subPath: rust-source
|
||||||
|
- name: cargo-cache
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: organic-cargo-cache-test-foreign-document
|
||||||
|
- name: docker-credentials
|
||||||
|
secret:
|
||||||
|
secretName: harbor-plain
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
value: "harbor.fizz.buzz/private/organic-test-foreign-document"
|
||||||
|
- name: target-name
|
||||||
|
value: "foreign-document"
|
||||||
|
- name: path-to-image-context
|
||||||
|
value: docker/organic_test/
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
value: docker/organic_test/
|
||||||
334
.webhook_bridge/pipeline-format.yaml
Normal file
334
.webhook_bridge/pipeline-format.yaml
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
name: rust-format
|
||||||
|
spec:
|
||||||
|
timeouts:
|
||||||
|
pipeline: "2h0m0s"
|
||||||
|
tasks: "1h0m0s"
|
||||||
|
finally: "0h30m0s"
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: build-bot
|
||||||
|
pipelineSpec:
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
description: The name for the built image
|
||||||
|
type: string
|
||||||
|
- name: target-name
|
||||||
|
description: The dockerfile target to build
|
||||||
|
type: string
|
||||||
|
- name: path-to-image-context
|
||||||
|
description: The path to the build context
|
||||||
|
type: string
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
description: The path to the Dockerfile
|
||||||
|
type: string
|
||||||
|
tasks:
|
||||||
|
- name: report-pending
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has started"
|
||||||
|
- name: STATE
|
||||||
|
value: pending
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: fetch-repository
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-clone/0.9/git-clone.yaml
|
||||||
|
workspaces:
|
||||||
|
- name: output
|
||||||
|
workspace: git-source
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: $(params.REPO_URL)
|
||||||
|
- name: revision
|
||||||
|
value: $(params.PULL_BASE_SHA)
|
||||||
|
- name: deleteExisting
|
||||||
|
value: "true"
|
||||||
|
- name: get-git-commit-time
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: "$(workspaces.repo.path)"
|
||||||
|
results:
|
||||||
|
- name: unix-time
|
||||||
|
description: The time of the git commit in unix timestamp format.
|
||||||
|
steps:
|
||||||
|
- image: alpine/git:v2.34.2
|
||||||
|
name: detect-tag-step
|
||||||
|
script: |
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo pipefail
|
||||||
|
echo -n "$(git log -1 --pretty=%ct)" | tee $(results.unix-time.path)
|
||||||
|
workspaces:
|
||||||
|
- name: repo
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: build-image
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/talexander/personal_tekton_catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: 7ee31a185243ee6da13dcd26a592c585b64c80e5
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/buildkit-rootless-daemonless/0.1/buildkit-rootless-daemonless.yaml
|
||||||
|
params:
|
||||||
|
- name: OUTPUT
|
||||||
|
value: >-
|
||||||
|
type=image,"name=$(params.image-name):latest,$(params.image-name):$(tasks.fetch-repository.results.commit)",push=true,compression=zstd,compression-level=22,oci-mediatypes=true
|
||||||
|
- name: CONTEXT
|
||||||
|
value: $(params.path-to-image-context)
|
||||||
|
- name: DOCKERFILE
|
||||||
|
value: $(params.path-to-dockerfile)
|
||||||
|
- name: EXTRA_ARGS
|
||||||
|
value:
|
||||||
|
- "--opt"
|
||||||
|
- "target=$(params.target-name)"
|
||||||
|
- --import-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache"
|
||||||
|
- --export-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache,mode=max,compression=zstd,compression-level=22,rewrite-timestamp=true,image-manifest=true,oci-mediatypes=true"
|
||||||
|
- --opt
|
||||||
|
- build-arg:SOURCE_DATE_EPOCH=$(tasks.get-git-commit-time.results.unix-time)
|
||||||
|
- name: BUILDKITD_TOML
|
||||||
|
value: |
|
||||||
|
debug = true
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
[registry."dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: run-cargo-fmt
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: ["cargo", "fmt"]
|
||||||
|
args: []
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
runAfter:
|
||||||
|
- build-image
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
- name: commit-changes
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-cli/0.4/git-cli.yaml
|
||||||
|
params:
|
||||||
|
- name: GIT_USER_NAME
|
||||||
|
value: fluxcdbot
|
||||||
|
- name: GIT_USER_EMAIL
|
||||||
|
value: "fluxcdbot@users.noreply.github.com"
|
||||||
|
- name: GIT_SCRIPT
|
||||||
|
value: |
|
||||||
|
pwd
|
||||||
|
git config --global --add safe.directory /workspace/source
|
||||||
|
git_status=$(git status --porcelain)
|
||||||
|
if [ -n "$git_status" ]; then
|
||||||
|
git commit -a -m "CI: autofix rust code."
|
||||||
|
git push origin HEAD:$(params.PULL_BASE_REF)
|
||||||
|
else
|
||||||
|
echo "No changes to commit."
|
||||||
|
fi
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- run-cargo-fmt
|
||||||
|
finally:
|
||||||
|
- name: report-success
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Succeeded", "Completed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has succeeded"
|
||||||
|
- name: STATE
|
||||||
|
value: success
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: report-failure
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Failed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has failed"
|
||||||
|
- name: STATE
|
||||||
|
value: failure
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: cargo-cache-autoclean
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: [cargo, cache, --autoclean]
|
||||||
|
args: []
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
- name: docker-credentials
|
||||||
|
- name: cargo-cache
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
storageClassName: "local-path"
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
subPath: rust-source
|
||||||
|
- name: cargo-cache
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: organic-cargo-cache-fmt
|
||||||
|
- name: docker-credentials
|
||||||
|
secret:
|
||||||
|
secretName: harbor-plain
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
value: "harbor.fizz.buzz/private/organic-development-format"
|
||||||
|
- name: target-name
|
||||||
|
value: "format"
|
||||||
|
- name: path-to-image-context
|
||||||
|
value: docker/organic_development/
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
value: docker/organic_development/
|
||||||
313
.webhook_bridge/pipeline-rust-clippy.yaml
Normal file
313
.webhook_bridge/pipeline-rust-clippy.yaml
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
name: rust-clippy
|
||||||
|
spec:
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: build-bot
|
||||||
|
timeouts:
|
||||||
|
pipeline: "2h0m0s"
|
||||||
|
tasks: "1h0m40s"
|
||||||
|
finally: "0h30m0s"
|
||||||
|
pipelineSpec:
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
description: The name for the built image
|
||||||
|
type: string
|
||||||
|
- name: target-name
|
||||||
|
description: The dockerfile target to build
|
||||||
|
type: string
|
||||||
|
- name: path-to-image-context
|
||||||
|
description: The path to the build context
|
||||||
|
type: string
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
description: The path to the Dockerfile
|
||||||
|
type: string
|
||||||
|
tasks:
|
||||||
|
- name: report-pending
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has started"
|
||||||
|
- name: STATE
|
||||||
|
value: pending
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: fetch-repository
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-clone/0.9/git-clone.yaml
|
||||||
|
workspaces:
|
||||||
|
- name: output
|
||||||
|
workspace: git-source
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: $(params.REPO_URL)
|
||||||
|
- name: revision
|
||||||
|
value: $(params.PULL_BASE_SHA)
|
||||||
|
- name: deleteExisting
|
||||||
|
value: "true"
|
||||||
|
- name: get-git-commit-time
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: "$(workspaces.repo.path)"
|
||||||
|
results:
|
||||||
|
- name: unix-time
|
||||||
|
description: The time of the git commit in unix timestamp format.
|
||||||
|
steps:
|
||||||
|
- image: alpine/git:v2.34.2
|
||||||
|
name: detect-tag-step
|
||||||
|
script: |
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo pipefail
|
||||||
|
echo -n "$(git log -1 --pretty=%ct)" | tee $(results.unix-time.path)
|
||||||
|
workspaces:
|
||||||
|
- name: repo
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: build-image
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/talexander/personal_tekton_catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: 7ee31a185243ee6da13dcd26a592c585b64c80e5
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/buildkit-rootless-daemonless/0.1/buildkit-rootless-daemonless.yaml
|
||||||
|
params:
|
||||||
|
- name: OUTPUT
|
||||||
|
value: >-
|
||||||
|
type=image,"name=$(params.image-name):latest,$(params.image-name):$(tasks.fetch-repository.results.commit)",push=true,compression=zstd,compression-level=22,oci-mediatypes=true
|
||||||
|
- name: CONTEXT
|
||||||
|
value: $(params.path-to-image-context)
|
||||||
|
- name: DOCKERFILE
|
||||||
|
value: $(params.path-to-dockerfile)
|
||||||
|
- name: EXTRA_ARGS
|
||||||
|
value:
|
||||||
|
- "--opt"
|
||||||
|
- "target=$(params.target-name)"
|
||||||
|
- --import-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache"
|
||||||
|
- --export-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache,mode=max,compression=zstd,compression-level=22,rewrite-timestamp=true,image-manifest=true,oci-mediatypes=true"
|
||||||
|
- --opt
|
||||||
|
- build-arg:SOURCE_DATE_EPOCH=$(tasks.get-git-commit-time.results.unix-time)
|
||||||
|
- name: BUILDKITD_TOML
|
||||||
|
value: |
|
||||||
|
debug = true
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
[registry."dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: run-cargo-clippy
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command:
|
||||||
|
[
|
||||||
|
"cargo",
|
||||||
|
"clippy",
|
||||||
|
"--no-deps",
|
||||||
|
"--all-targets",
|
||||||
|
"--all-features",
|
||||||
|
"--",
|
||||||
|
"-D",
|
||||||
|
"warnings",
|
||||||
|
]
|
||||||
|
args: []
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
runAfter:
|
||||||
|
- build-image
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
finally:
|
||||||
|
- name: report-success
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Succeeded", "Completed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has succeeded"
|
||||||
|
- name: STATE
|
||||||
|
value: success
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: report-failure
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Failed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has failed"
|
||||||
|
- name: STATE
|
||||||
|
value: failure
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: cargo-cache-autoclean
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: [cargo, cache, --autoclean]
|
||||||
|
args: []
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
- name: docker-credentials
|
||||||
|
- name: cargo-cache
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
storageClassName: "local-path"
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
subPath: rust-source
|
||||||
|
- name: cargo-cache
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: organic-cargo-cache-clippy
|
||||||
|
- name: docker-credentials
|
||||||
|
secret:
|
||||||
|
secretName: harbor-plain
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
value: "harbor.fizz.buzz/private/organic-development-clippy"
|
||||||
|
- name: target-name
|
||||||
|
value: "clippy"
|
||||||
|
- name: path-to-image-context
|
||||||
|
value: docker/organic_development/
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
value: docker/organic_development/
|
||||||
312
.webhook_bridge/pipeline-rust-test.yaml
Normal file
312
.webhook_bridge/pipeline-rust-test.yaml
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
apiVersion: tekton.dev/v1
|
||||||
|
kind: PipelineRun
|
||||||
|
metadata:
|
||||||
|
name: rust-test
|
||||||
|
spec:
|
||||||
|
timeouts:
|
||||||
|
pipeline: "2h0m0s"
|
||||||
|
tasks: "1h0m40s"
|
||||||
|
finally: "0h30m0s"
|
||||||
|
taskRunTemplate:
|
||||||
|
serviceAccountName: build-bot
|
||||||
|
pipelineSpec:
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
description: The name for the built image
|
||||||
|
type: string
|
||||||
|
- name: target-name
|
||||||
|
description: The dockerfile target to build
|
||||||
|
type: string
|
||||||
|
- name: path-to-image-context
|
||||||
|
description: The path to the build context
|
||||||
|
type: string
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
description: The path to the Dockerfile
|
||||||
|
type: string
|
||||||
|
tasks:
|
||||||
|
- name: report-pending
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has started"
|
||||||
|
- name: STATE
|
||||||
|
value: pending
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: fetch-repository
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/git-clone/0.9/git-clone.yaml
|
||||||
|
workspaces:
|
||||||
|
- name: output
|
||||||
|
workspace: git-source
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: $(params.REPO_URL)
|
||||||
|
- name: revision
|
||||||
|
value: $(params.PULL_BASE_SHA)
|
||||||
|
- name: deleteExisting
|
||||||
|
value: "true"
|
||||||
|
- name: get-git-commit-time
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: "$(workspaces.repo.path)"
|
||||||
|
results:
|
||||||
|
- name: unix-time
|
||||||
|
description: The time of the git commit in unix timestamp format.
|
||||||
|
steps:
|
||||||
|
- image: alpine/git:v2.34.2
|
||||||
|
name: detect-tag-step
|
||||||
|
script: |
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo pipefail
|
||||||
|
echo -n "$(git log -1 --pretty=%ct)" | tee $(results.unix-time.path)
|
||||||
|
workspaces:
|
||||||
|
- name: repo
|
||||||
|
workspace: git-source
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: build-image
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/talexander/personal_tekton_catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: 7ee31a185243ee6da13dcd26a592c585b64c80e5
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/buildkit-rootless-daemonless/0.1/buildkit-rootless-daemonless.yaml
|
||||||
|
params:
|
||||||
|
- name: OUTPUT
|
||||||
|
value: >-
|
||||||
|
type=image,"name=$(params.image-name):latest,$(params.image-name):$(tasks.fetch-repository.results.commit)",push=true,compression=zstd,compression-level=22,oci-mediatypes=true
|
||||||
|
- name: CONTEXT
|
||||||
|
value: $(params.path-to-image-context)
|
||||||
|
- name: DOCKERFILE
|
||||||
|
value: $(params.path-to-dockerfile)
|
||||||
|
- name: EXTRA_ARGS
|
||||||
|
value:
|
||||||
|
- "--opt"
|
||||||
|
- "target=$(params.target-name)"
|
||||||
|
- --import-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache"
|
||||||
|
- --export-cache
|
||||||
|
- "type=registry,ref=$(params.image-name):buildcache,mode=max,compression=zstd,compression-level=22,rewrite-timestamp=true,image-manifest=true,oci-mediatypes=true"
|
||||||
|
- --opt
|
||||||
|
- build-arg:SOURCE_DATE_EPOCH=$(tasks.get-git-commit-time.results.unix-time)
|
||||||
|
- name: BUILDKITD_TOML
|
||||||
|
value: |
|
||||||
|
debug = true
|
||||||
|
[registry."docker.io"]
|
||||||
|
mirrors = ["dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
[registry."dockerhub.dockerhub.svc.cluster.local"]
|
||||||
|
http = true
|
||||||
|
insecure = true
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: dockerconfig
|
||||||
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
|
- name: run-cargo-test
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: [cargo, test]
|
||||||
|
args:
|
||||||
|
[
|
||||||
|
--no-default-features,
|
||||||
|
--features,
|
||||||
|
"compare,wasm_test",
|
||||||
|
--no-fail-fast,
|
||||||
|
--lib,
|
||||||
|
--test,
|
||||||
|
test_loader,
|
||||||
|
]
|
||||||
|
env:
|
||||||
|
- name: CARGO_TARGET_DIR
|
||||||
|
value: /target
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
runAfter:
|
||||||
|
- build-image
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
finally:
|
||||||
|
- name: report-success
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Succeeded", "Completed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has succeeded"
|
||||||
|
- name: STATE
|
||||||
|
value: success
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: report-failure
|
||||||
|
when:
|
||||||
|
- input: "$(tasks.status)"
|
||||||
|
operator: in
|
||||||
|
values: ["Failed"]
|
||||||
|
taskRef:
|
||||||
|
resolver: git
|
||||||
|
params:
|
||||||
|
- name: url
|
||||||
|
value: https://code.fizz.buzz/mirror/catalog.git # mirror of https://github.com/tektoncd/catalog.git
|
||||||
|
- name: revision
|
||||||
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
|
- name: pathInRepo
|
||||||
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
params:
|
||||||
|
- name: CONTEXT
|
||||||
|
value: "$(params.JOB_NAME)"
|
||||||
|
- name: REPO_FULL_NAME
|
||||||
|
value: "$(params.REPO_OWNER)/$(params.REPO_NAME)"
|
||||||
|
- name: GITEA_HOST_URL
|
||||||
|
value: code.fizz.buzz
|
||||||
|
- name: SHA
|
||||||
|
value: "$(tasks.fetch-repository.results.commit)"
|
||||||
|
- name: DESCRIPTION
|
||||||
|
value: "Build $(params.JOB_NAME) has failed"
|
||||||
|
- name: STATE
|
||||||
|
value: failure
|
||||||
|
- name: TARGET_URL
|
||||||
|
value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)"
|
||||||
|
- name: cargo-cache-autoclean
|
||||||
|
taskSpec:
|
||||||
|
metadata: {}
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
type: string
|
||||||
|
description: Docker image to run.
|
||||||
|
default: alpine:3.20
|
||||||
|
stepTemplate:
|
||||||
|
image: alpine:3.20
|
||||||
|
computeResources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 600Mi
|
||||||
|
workingDir: /workspace/source
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
mountPath: /source
|
||||||
|
- name: cargo-cache
|
||||||
|
mountPath: /usr/local/cargo/registry
|
||||||
|
optional: true
|
||||||
|
steps:
|
||||||
|
- name: run
|
||||||
|
image: $(params.docker-image)
|
||||||
|
workingDir: "$(workspaces.source.path)"
|
||||||
|
command: [cargo, cache, --autoclean]
|
||||||
|
args: []
|
||||||
|
workspaces:
|
||||||
|
- name: source
|
||||||
|
workspace: git-source
|
||||||
|
- name: cargo-cache
|
||||||
|
workspace: cargo-cache
|
||||||
|
params:
|
||||||
|
- name: docker-image
|
||||||
|
value: "$(tasks.build-image.results.IMAGE_URL[1])"
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
- name: docker-credentials
|
||||||
|
- name: cargo-cache
|
||||||
|
workspaces:
|
||||||
|
- name: git-source
|
||||||
|
volumeClaimTemplate:
|
||||||
|
spec:
|
||||||
|
storageClassName: "local-path"
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 10Gi
|
||||||
|
subPath: rust-source
|
||||||
|
- name: cargo-cache
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: organic-cargo-cache-test
|
||||||
|
- name: docker-credentials
|
||||||
|
secret:
|
||||||
|
secretName: harbor-plain
|
||||||
|
params:
|
||||||
|
- name: image-name
|
||||||
|
value: "harbor.fizz.buzz/private/organic-test"
|
||||||
|
- name: target-name
|
||||||
|
value: "tester"
|
||||||
|
- name: path-to-image-context
|
||||||
|
value: docker/organic_test/
|
||||||
|
- name: path-to-dockerfile
|
||||||
|
value: docker/organic_test/
|
||||||
31
.webhook_bridge/webhook_bridge.toml
Normal file
31
.webhook_bridge/webhook_bridge.toml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
version = "0.0.1"
|
||||||
|
|
||||||
|
[[push]]
|
||||||
|
name = "rust-test"
|
||||||
|
source = "pipeline-rust-test.yaml"
|
||||||
|
clone_uri = "git@code.fizz.buzz:talexander/organic.git"
|
||||||
|
skip_branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
||||||
|
|
||||||
|
[[push]]
|
||||||
|
name = "foreign-document-test"
|
||||||
|
source = "pipeline-foreign-document-test.yaml"
|
||||||
|
clone_uri = "git@code.fizz.buzz:talexander/organic.git"
|
||||||
|
branches = [ "^main$", "^master$" ]
|
||||||
|
|
||||||
|
[[push]]
|
||||||
|
name = "clippy"
|
||||||
|
source = "pipeline-rust-clippy.yaml"
|
||||||
|
clone_uri = "git@code.fizz.buzz:talexander/organic.git"
|
||||||
|
skip_branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
||||||
|
|
||||||
|
[[push]]
|
||||||
|
name = "format"
|
||||||
|
source = "pipeline-format.yaml"
|
||||||
|
clone_uri = "git@code.fizz.buzz:talexander/organic.git"
|
||||||
|
skip_branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
||||||
|
|
||||||
|
[[push]]
|
||||||
|
name = "build"
|
||||||
|
source = "pipeline-build-hash.yaml"
|
||||||
|
clone_uri = "git@code.fizz.buzz:talexander/organic.git"
|
||||||
|
branches = [ "^main$", "^master$" ]
|
||||||
43
Cargo.toml
43
Cargo.toml
@@ -1,6 +1,9 @@
|
|||||||
|
# cargo-features = ["profile-rustflags"]
|
||||||
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "organic"
|
name = "organic"
|
||||||
version = "0.1.10"
|
version = "0.1.16"
|
||||||
authors = ["Tom Alexander <tom@fizz.buzz>"]
|
authors = ["Tom Alexander <tom@fizz.buzz>"]
|
||||||
description = "An org-mode parser."
|
description = "An org-mode parser."
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -37,17 +40,33 @@ path = "src/lib.rs"
|
|||||||
path = "src/bin_foreign_document_test.rs"
|
path = "src/bin_foreign_document_test.rs"
|
||||||
required-features = ["foreign_document_test"]
|
required-features = ["foreign_document_test"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "wasm"
|
||||||
|
path = "src/bin_wasm.rs"
|
||||||
|
required-features = ["wasm"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
# This bin exists for development purposes only. The real target of this crate is the library.
|
||||||
|
name = "wasm_test"
|
||||||
|
path = "src/bin_wasm_test.rs"
|
||||||
|
required-features = ["wasm_test"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { version = "0.3.28", optional = true }
|
futures = { version = "0.3.28", optional = true }
|
||||||
|
gloo-utils = "0.2.0"
|
||||||
nom = "7.1.1"
|
nom = "7.1.1"
|
||||||
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
|
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
|
||||||
opentelemetry-otlp = { version = "0.13.0", optional = true }
|
opentelemetry-otlp = { version = "0.13.0", optional = true }
|
||||||
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
|
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
|
||||||
|
serde = { version = "1.0.193", optional = true, features = ["derive"] }
|
||||||
|
serde-wasm-bindgen = { version = "0.6.3", optional = true }
|
||||||
|
serde_json = { version = "1.0.108", optional = true }
|
||||||
tokio = { version = "1.30.0", optional = true, default-features = false, features = ["rt", "rt-multi-thread"] }
|
tokio = { version = "1.30.0", optional = true, default-features = false, features = ["rt", "rt-multi-thread"] }
|
||||||
tracing = { version = "0.1.37", optional = true }
|
tracing = { version = "0.1.37", optional = true }
|
||||||
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
||||||
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
||||||
walkdir = { version = "2.3.3", optional = true }
|
walkdir = { version = "2.3.3", optional = true }
|
||||||
|
wasm-bindgen = { version = "0.2.89", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
walkdir = "2.3.3"
|
walkdir = "2.3.3"
|
||||||
@@ -57,6 +76,9 @@ default = []
|
|||||||
compare = ["tokio/process", "tokio/macros"]
|
compare = ["tokio/process", "tokio/macros"]
|
||||||
foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"]
|
foreign_document_test = ["compare", "dep:futures", "tokio/sync", "dep:walkdir", "tokio/process"]
|
||||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||||
|
event_count = []
|
||||||
|
wasm = ["dep:serde", "dep:wasm-bindgen", "dep:serde-wasm-bindgen"]
|
||||||
|
wasm_test = ["wasm", "dep:serde_json", "tokio/process", "tokio/macros"]
|
||||||
|
|
||||||
# Optimized build for any sort of release.
|
# Optimized build for any sort of release.
|
||||||
[profile.release-lto]
|
[profile.release-lto]
|
||||||
@@ -64,8 +86,27 @@ inherits = "release"
|
|||||||
lto = true
|
lto = true
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
||||||
|
# Optimized build for local execution.
|
||||||
|
# [profile.native]
|
||||||
|
# inherits = "release"
|
||||||
|
# lto = true
|
||||||
|
# strip = "symbols"
|
||||||
|
# rustflags = ["-C", "target-cpu=native"]
|
||||||
|
|
||||||
# Profile for performance testing with the "perf" tool. Notably keeps debug enabled and does not strip symbols to make reading the perf output easier.
|
# Profile for performance testing with the "perf" tool. Notably keeps debug enabled and does not strip symbols to make reading the perf output easier.
|
||||||
[profile.perf]
|
[profile.perf]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
lto = true
|
lto = true
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
|
[profile.wasm]
|
||||||
|
inherits = "release"
|
||||||
|
lto = true
|
||||||
|
strip = true
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
codegen-backend = "llvm"
|
||||||
|
opt-level = 3
|
||||||
|
|||||||
65
Makefile
65
Makefile
@@ -7,6 +7,7 @@ MAKEFLAGS += --no-builtin-rules
|
|||||||
TESTJOBS := 4
|
TESTJOBS := 4
|
||||||
OS:=$(shell uname -s)
|
OS:=$(shell uname -s)
|
||||||
RELEASEFLAGS :=
|
RELEASEFLAGS :=
|
||||||
|
WASMTARGET := bundler # or web
|
||||||
|
|
||||||
ifeq ($(OS),Linux)
|
ifeq ($(OS),Linux)
|
||||||
TESTJOBS:=$(shell nproc)
|
TESTJOBS:=$(shell nproc)
|
||||||
@@ -21,43 +22,83 @@ ifeq ($(origin .RECIPEPREFIX), undefined)
|
|||||||
endif
|
endif
|
||||||
.RECIPEPREFIX = >
|
.RECIPEPREFIX = >
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help: ## List the available make targets.
|
||||||
|
> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -E 's/^([^:]*): *## */\1: /'
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build: ## Make a debug build of the project.
|
||||||
> cargo build
|
> cargo build
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release:
|
release: ## Make an optimized build of the project.
|
||||||
> cargo build --release $(RELEASEFLAGS)
|
> cargo build --release $(RELEASEFLAGS)
|
||||||
|
|
||||||
|
.PHONY: wasm
|
||||||
|
wasm: ## Build the parser as wasm.
|
||||||
|
> cargo build --target=wasm32-unknown-unknown --profile wasm --bin wasm --features wasm
|
||||||
|
> wasm-bindgen --target $(WASMTARGET) --out-dir target/wasm32-unknown-unknown/js target/wasm32-unknown-unknown/wasm/wasm.wasm
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean: ## Delete the built binaries.
|
||||||
> cargo clean
|
> cargo clean
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=builder clean
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=format clean
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=clippy clean
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=wasm clean
|
||||||
|
> $(MAKE) -C docker/organic_test TARGET=tester build
|
||||||
|
|
||||||
.PHONY: format
|
.PHONY: format
|
||||||
format:
|
format: ## Format the code.
|
||||||
> $(MAKE) -C docker/cargo_fmt run
|
> cargo fmt
|
||||||
|
|
||||||
|
.PHONY: docker_format
|
||||||
|
docker_format: ## Format the code using docker.
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=format build
|
||||||
|
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "organic-cargo-registry:/usr/local/cargo/registry" organic-development-format cargo fmt
|
||||||
|
|
||||||
|
.PHONY: docker_clippy
|
||||||
|
docker_clippy: ## Lint the code using docker.
|
||||||
|
> $(MAKE) -C docker/organic_development TARGET=clippy build
|
||||||
|
> docker run --rm -i -t --mount type=tmpfs,destination=/tmp -v "$(shell readlink -f .):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "organic-cargo-registry:/usr/local/cargo/registry" organic-development-clippy cargo clippy --no-deps --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
|
.PHONY: clippy
|
||||||
|
clippy: ## Lint the code.
|
||||||
|
> cargo clippy --no-deps --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test: ## Run the test suite.
|
||||||
> cargo test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
|
> cargo test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
|
||||||
|
|
||||||
.PHONY: dockertest
|
.PHONY: doc
|
||||||
dockertest:
|
doc: ## Generate documentation.
|
||||||
> $(MAKE) -C docker/organic_test
|
> cargo doc --no-deps --open --lib --release --all-features
|
||||||
|
|
||||||
|
.PHONY: docker_test
|
||||||
|
docker_test: ## Run the test suite using docker.
|
||||||
|
> $(MAKE) -C docker/organic_test TARGET=tester build
|
||||||
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
|
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
|
||||||
|
|
||||||
.PHONY: buildtest
|
.PHONY: docker_wasm_test
|
||||||
buildtest:
|
docker_wasm_test: ## Run the test suite with wasm tests.
|
||||||
|
> $(MAKE) -C docker/organic_test TARGET=tester build
|
||||||
|
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare,wasm_test --no-fail-fast --lib --test test_loader autogen_wasm_ -- --test-threads $(TESTJOBS)
|
||||||
|
|
||||||
|
.PHONY: build_test
|
||||||
|
build_test:
|
||||||
> cargo build --no-default-features
|
> cargo build --no-default-features
|
||||||
> cargo build --no-default-features --features compare
|
> cargo build --no-default-features --features compare
|
||||||
> cargo build --no-default-features --features tracing
|
> cargo build --no-default-features --features tracing
|
||||||
> cargo build --no-default-features --features compare,tracing
|
> cargo build --no-default-features --features compare,tracing
|
||||||
> cargo build --no-default-features --features compare,foreign_document_test
|
> cargo build --no-default-features --features compare,foreign_document_test
|
||||||
> cargo build --no-default-features --features compare,tracing,foreign_document_test
|
> cargo build --no-default-features --features compare,tracing,foreign_document_test
|
||||||
|
> cargo build --target wasm32-unknown-unknown --profile wasm --bin wasm --no-default-features --features wasm
|
||||||
|
> cargo build --bin wasm_test --no-default-features --features wasm_test
|
||||||
|
|
||||||
.PHONY: foreign_document_test
|
.PHONY: foreign_document_test
|
||||||
foreign_document_test:
|
foreign_document_test:
|
||||||
> $(MAKE) -C docker/organic_test run_foreign_document_test
|
> $(MAKE) -C docker/organic_test TARGET=foreign-document build
|
||||||
|
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test-foreign-document
|
||||||
|
|
||||||
.PHONY: dockerclean
|
.PHONY: dockerclean
|
||||||
dockerclean:
|
dockerclean:
|
||||||
|
|||||||
@@ -10,17 +10,16 @@ Currently, Organic parses most documents the same as the official org-mode parse
|
|||||||
|
|
||||||
### Project Goals
|
### Project Goals
|
||||||
- We aim to provide perfect parity with the emacs org-mode parser. In that regard, any document that parses differently between Emacs and Organic is considered a bug.
|
- We aim to provide perfect parity with the emacs org-mode parser. In that regard, any document that parses differently between Emacs and Organic is considered a bug.
|
||||||
- The parser should have minimal dependencies. This should reduce effort w.r.t.: security audits, legal compliance, portability.
|
- The parser should have minimal dependencies.
|
||||||
- The parser should be usable everywhere. In the interest of getting org-mode used in as many places as possible, this parser should be usable by everyone everywhere. This means:
|
- The parser should be usable everywhere. In the interest of getting org used in as many places as possible, this parser should be usable by everyone everywhere. This means:
|
||||||
- It must have a permissive license.
|
- It must have a permissive license.
|
||||||
- We will investigate compiling to WASM. This is an important goal of the project and will definitely happen, but only after the parser has a more stable API.
|
- It compiles to both natively and to wasm.
|
||||||
- We will investigate compiling to a C library for native linking to other code. This is more of a maybe-goal for the project.
|
- We will investigate compiling to a C library for native linking to other code. This is more of a maybe-goal for the project.
|
||||||
### Project Non-Goals
|
### Project Non-Goals
|
||||||
- This project will not include an elisp engine since that would drastically increase the complexity of the code. Any features requiring an elisp engine will not be implemented (for example, Emacs supports embedded eval expressions in documents but this parser will never support that).
|
- This project will not include an elisp engine since that would drastically increase the complexity of the code. Any features requiring an elisp engine will not be implemented (for example, Emacs supports embedded eval expressions in documents but this parser will never support that).
|
||||||
- This project is exclusively an org-mode **parser**. This limits its scope to roughly the output of `(org-element-parse-buffer)`. It will not render org-mode documents in other formats like HTML or LaTeX.
|
- This project is exclusively an org-mode **parser**. This limits its scope to roughly the output of `(org-element-parse-buffer)`. It will not render org-mode documents in other formats like HTML or LaTeX.
|
||||||
### Project Maybe-Goals
|
### Project Maybe-Goals
|
||||||
- table.el support. Currently we support org-mode tables but org-mode also allows table.el tables. So far, their use in org-mode documents seems rather uncommon so this is a low-priority feature.
|
- table.el support. Currently we support org-mode tables but org-mode also allows table.el tables. So far, their use in org-mode documents seems rather uncommon so this is a low-priority feature.
|
||||||
- Document editing support. I do not anticipate any advanced editing features to make editing ergonomic, but it should be relatively easy to be able to parse an org-mode document and serialize it back into org-mode. This would enable cool features to be built on top of the library like auto-formatters. To accomplish this feature, We'd have to capture all of the various separators and whitespace that we are currently simply throwing away. This would add many additional fields to the parsed structs and it would add more noise to the parsers themselves, so I do not want to approach this feature until the parser is more complete since it would make modifications and refactoring more difficult.
|
|
||||||
### Supported Versions
|
### Supported Versions
|
||||||
This project targets the version of Emacs and Org-mode that are built into the [organic-test docker image](docker/organic_test/Dockerfile). This is newer than the version of Org-mode that shipped with Emacs 29.1. The parser itself does not depend on Emacs or Org-mode though, so this only matters for development purposes when running the automated tests that compare against upstream Org-mode.
|
This project targets the version of Emacs and Org-mode that are built into the [organic-test docker image](docker/organic_test/Dockerfile). This is newer than the version of Org-mode that shipped with Emacs 29.1. The parser itself does not depend on Emacs or Org-mode though, so this only matters for development purposes when running the automated tests that compare against upstream Org-mode.
|
||||||
|
|
||||||
|
|||||||
14
build.rs
14
build.rs
@@ -14,7 +14,7 @@ use walkdir::WalkDir;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let destination = Path::new(&out_dir).join("tests.rs");
|
let destination = Path::new(&out_dir).join("tests.rs");
|
||||||
let mut test_file = File::create(&destination).unwrap();
|
let mut test_file = File::create(destination).unwrap();
|
||||||
|
|
||||||
// Re-generate the tests if any org-mode files change
|
// Re-generate the tests if any org-mode files change
|
||||||
println!("cargo:rerun-if-changed=org_mode_samples");
|
println!("cargo:rerun-if-changed=org_mode_samples");
|
||||||
@@ -26,7 +26,7 @@ fn main() {
|
|||||||
dir_entry.file_type().is_file()
|
dir_entry.file_type().is_file()
|
||||||
&& Path::new(dir_entry.file_name())
|
&& Path::new(dir_entry.file_name())
|
||||||
.extension()
|
.extension()
|
||||||
.map(|ext| ext.to_ascii_lowercase() == "org")
|
.map(|ext| ext.eq_ignore_ascii_case("org"))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
@@ -51,7 +51,7 @@ fn write_test(test_file: &mut File, test: &walkdir::DirEntry) {
|
|||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.strip_suffix(".org")
|
.strip_suffix(".org")
|
||||||
.expect("Should have .org extension")
|
.expect("Should have .org extension")
|
||||||
.replace("/", "_");
|
.replace('/', "_");
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
test_file,
|
test_file,
|
||||||
@@ -66,10 +66,6 @@ fn write_test(test_file: &mut File, test: &walkdir::DirEntry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
fn is_expect_fail(name: &str) -> Option<&str> {
|
fn is_expect_fail(_name: &str) -> Option<&str> {
|
||||||
match name {
|
None
|
||||||
"greater_element_drawer_drawer_with_headline_inside" => Some("Apparently lines with :end: become their own paragraph. This odd behavior needs to be investigated more."),
|
|
||||||
"element_container_priority_footnote_definition_dynamic_block" => Some("Apparently broken begin lines become their own paragraph."),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
FROM rustlang/rust:nightly-alpine3.17
|
|
||||||
|
|
||||||
RUN apk add --no-cache musl-dev
|
|
||||||
RUN rustup component add rustfmt
|
|
||||||
|
|
||||||
ENTRYPOINT ["cargo", "fmt"]
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
IMAGE_NAME:=cargo-fmt
|
|
||||||
# REMOTE_REPO:=harbor.fizz.buzz/private
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: build push
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
docker build -t $(IMAGE_NAME) -f Dockerfile .
|
|
||||||
|
|
||||||
.PHONY: push
|
|
||||||
push:
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
docker push $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not pushing to a remote repo."
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
docker rmi $(IMAGE_NAME)
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker rmi $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not removing from remote repo."
|
|
||||||
endif
|
|
||||||
|
|
||||||
# NOTE: This target will write to folders underneath the git-root
|
|
||||||
.PHONY: run
|
|
||||||
run: build
|
|
||||||
docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source $(IMAGE_NAME)
|
|
||||||
|
|
||||||
.PHONY: shell
|
|
||||||
shell: build
|
|
||||||
docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source $(IMAGE_NAME)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
FROM rustlang/rust:nightly-alpine3.17
|
|
||||||
|
|
||||||
RUN apk add --no-cache musl-dev
|
|
||||||
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
|
||||||
|
|
||||||
ENTRYPOINT ["cargo", "build"]
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
IMAGE_NAME:=organic-build
|
|
||||||
# REMOTE_REPO:=harbor.fizz.buzz/private
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: build push
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
docker build -t $(IMAGE_NAME) -f Dockerfile .
|
|
||||||
|
|
||||||
.PHONY: push
|
|
||||||
push:
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
docker push $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not pushing to a remote repo."
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
docker rmi $(IMAGE_NAME)
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker rmi $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not removing from remote repo."
|
|
||||||
endif
|
|
||||||
docker volume rm cargo-cache
|
|
||||||
|
|
||||||
# NOTE: This target will write to folders underneath the git-root
|
|
||||||
.PHONY: run
|
|
||||||
run: build
|
|
||||||
docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME)
|
|
||||||
|
|
||||||
.PHONY: shell
|
|
||||||
shell: build
|
|
||||||
docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME)
|
|
||||||
20
docker/organic_development/Dockerfile
Normal file
20
docker/organic_development/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
ARG ALPINE_VERSION="3.20"
|
||||||
|
|
||||||
|
FROM rustlang/rust:nightly-alpine$ALPINE_VERSION AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev
|
||||||
|
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
||||||
|
RUN rustup component add rustc-codegen-cranelift
|
||||||
|
|
||||||
|
FROM builder AS format
|
||||||
|
|
||||||
|
RUN rustup component add rustfmt
|
||||||
|
|
||||||
|
FROM builder AS clippy
|
||||||
|
|
||||||
|
RUN rustup component add clippy
|
||||||
|
|
||||||
|
FROM builder AS wasm
|
||||||
|
|
||||||
|
RUN rustup target add wasm32-unknown-unknown
|
||||||
36
docker/organic_development/Makefile
Normal file
36
docker/organic_development/Makefile
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
SHELL := bash
|
||||||
|
.ONESHELL:
|
||||||
|
.SHELLFLAGS := -eu -o pipefail -c
|
||||||
|
.DELETE_ON_ERROR:
|
||||||
|
MAKEFLAGS += --warn-undefined-variables
|
||||||
|
MAKEFLAGS += --no-builtin-rules
|
||||||
|
|
||||||
|
ifeq ($(origin .RECIPEPREFIX), undefined)
|
||||||
|
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
|
||||||
|
endif
|
||||||
|
.RECIPEPREFIX = >
|
||||||
|
|
||||||
|
TARGET := builder
|
||||||
|
IMAGE_NAME := organic-development
|
||||||
|
ifneq ($(TARGET),builder)
|
||||||
|
IMAGE_NAME := $(IMAGE_NAME)-$(TARGET)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help:
|
||||||
|
> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -E 's/^([^:]*): *## */\1: /'
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build: ## Build the docker image.
|
||||||
|
> docker build --tag $(IMAGE_NAME) --target=$(TARGET) --file Dockerfile .
|
||||||
|
> docker volume create organic-cargo-registry
|
||||||
|
|
||||||
|
.PHONY: shell
|
||||||
|
shell: ## Launch an interactive shell inside the docker image with the source repository mounted at /source.
|
||||||
|
shell: build
|
||||||
|
> docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "organic-cargo-registry:/usr/local/cargo/registry" $(IMAGE_NAME)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean: ## Remove the docker image and volume.
|
||||||
|
> docker rmi $(IMAGE_NAME)
|
||||||
|
> docker volume rm organic-cargo-registry
|
||||||
@@ -1,10 +1,25 @@
|
|||||||
FROM alpine:3.17 AS build
|
# syntax=docker/dockerfile:1
|
||||||
|
ARG ALPINE_VERSION="3.20"
|
||||||
|
|
||||||
|
# ARG EMACS_REPO=https://git.savannah.gnu.org/git/emacs.git
|
||||||
|
ARG EMACS_REPO=https://code.fizz.buzz/mirror/emacs.git
|
||||||
|
|
||||||
|
ARG EMACS_VERSION=emacs-29.1
|
||||||
|
|
||||||
|
# ARG ORG_MODE_REPO=https://git.savannah.gnu.org/git/emacs/org-mode.git
|
||||||
|
ARG ORG_MODE_REPO=https://code.fizz.buzz/mirror/org-mode.git
|
||||||
|
|
||||||
|
ARG ORG_VERSION=abf5156096c06ee5aa05795c3dc5a065f76ada97
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:$ALPINE_VERSION AS build
|
||||||
RUN apk add --no-cache build-base musl-dev git autoconf make texinfo gnutls-dev ncurses-dev gawk libgccjit-dev
|
RUN apk add --no-cache build-base musl-dev git autoconf make texinfo gnutls-dev ncurses-dev gawk libgccjit-dev
|
||||||
|
|
||||||
|
|
||||||
FROM build AS build-emacs
|
FROM build AS build-emacs
|
||||||
ARG EMACS_VERSION=emacs-29.1
|
ARG EMACS_VERSION
|
||||||
RUN git clone --depth 1 --branch $EMACS_VERSION https://git.savannah.gnu.org/git/emacs.git /root/emacs
|
ARG EMACS_REPO
|
||||||
|
RUN git clone --depth 1 --branch $EMACS_VERSION $EMACS_REPO /root/emacs
|
||||||
WORKDIR /root/emacs
|
WORKDIR /root/emacs
|
||||||
RUN mkdir /root/dist
|
RUN mkdir /root/dist
|
||||||
RUN ./autogen.sh
|
RUN ./autogen.sh
|
||||||
@@ -14,23 +29,25 @@ RUN make DESTDIR="/root/dist" install
|
|||||||
|
|
||||||
|
|
||||||
FROM build AS build-org-mode
|
FROM build AS build-org-mode
|
||||||
ARG ORG_VERSION=abf5156096c06ee5aa05795c3dc5a065f76ada97
|
ARG ORG_VERSION
|
||||||
COPY --from=build-emacs /root/dist/ /
|
ARG ORG_MODE_REPO
|
||||||
|
COPY --link --from=build-emacs /root/dist/ /
|
||||||
RUN mkdir /root/dist
|
RUN mkdir /root/dist
|
||||||
# Savannah does not allow fetching specific revisions, so we're going to have to put unnecessary load on their server by cloning main and then checking out the revision we want.
|
# Savannah does not allow fetching specific revisions, so we're going to have to put unnecessary load on their server by cloning main and then checking out the revision we want.
|
||||||
RUN git clone https://git.savannah.gnu.org/git/emacs/org-mode.git /root/org-mode && git -C /root/org-mode checkout $ORG_VERSION
|
RUN git clone $ORG_MODE_REPO /root/org-mode && git -C /root/org-mode checkout $ORG_VERSION
|
||||||
# RUN mkdir /root/org-mode && git -C /root/org-mode init --initial-branch=main && git -C /root/org-mode remote add origin https://git.savannah.gnu.org/git/emacs/org-mode.git && git -C /root/org-mode fetch origin $ORG_VERSION && git -C /root/org-mode checkout FETCH_HEAD
|
# RUN mkdir /root/org-mode && git -C /root/org-mode init --initial-branch=main && git -C /root/org-mode remote add origin $ORG_REPO && git -C /root/org-mode fetch origin $ORG_VERSION && git -C /root/org-mode checkout FETCH_HEAD
|
||||||
WORKDIR /root/org-mode
|
WORKDIR /root/org-mode
|
||||||
RUN make compile
|
RUN make compile
|
||||||
RUN make DESTDIR="/root/dist" install
|
RUN make DESTDIR="/root/dist" install
|
||||||
|
|
||||||
|
|
||||||
FROM rustlang/rust:nightly-alpine3.17 AS tester
|
FROM rustlang/rust:nightly-alpine$ALPINE_VERSION AS tester
|
||||||
ENV LANG=en_US.UTF-8
|
ENV LANG=en_US.UTF-8
|
||||||
RUN apk add --no-cache musl-dev ncurses gnutls libgccjit
|
RUN apk add --no-cache musl-dev ncurses gnutls libgccjit
|
||||||
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
RUN --mount=type=tmpfs,target=/tmp --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
||||||
COPY --from=build-emacs /root/dist/ /
|
RUN rustup component add rustc-codegen-cranelift
|
||||||
COPY --from=build-org-mode /root/dist/ /
|
COPY --link --from=build-emacs /root/dist/ /
|
||||||
|
COPY --link --from=build-org-mode /root/dist/ /
|
||||||
|
|
||||||
ENTRYPOINT ["cargo", "test"]
|
ENTRYPOINT ["cargo", "test"]
|
||||||
|
|
||||||
@@ -93,13 +110,20 @@ ARG WORG_PATH=/foreign_documents/worg
|
|||||||
ARG WORG_REPO=https://git.sr.ht/~bzg/worg
|
ARG WORG_REPO=https://git.sr.ht/~bzg/worg
|
||||||
RUN mkdir -p $WORG_PATH && git -C $WORG_PATH init --initial-branch=main && git -C $WORG_PATH remote add origin $WORG_REPO && git -C $WORG_PATH fetch origin $WORG_VERSION && git -C $WORG_PATH checkout FETCH_HEAD
|
RUN mkdir -p $WORG_PATH && git -C $WORG_PATH init --initial-branch=main && git -C $WORG_PATH remote add origin $WORG_REPO && git -C $WORG_PATH fetch origin $WORG_VERSION && git -C $WORG_PATH checkout FETCH_HEAD
|
||||||
|
|
||||||
|
ARG LITERATE_BUILD_EMACS_VERSION=e3ac1afe1e40af601be7af12c1d13d96308ab209
|
||||||
|
ARG LITERATE_BUILD_EMACS_PATH=/foreign_documents/literate_build_emacs
|
||||||
|
ARG LITERATE_BUILD_EMACS_REPO=https://gitlab.com/spudlyo/orgdemo2.git
|
||||||
|
RUN mkdir -p $LITERATE_BUILD_EMACS_PATH && git -C $LITERATE_BUILD_EMACS_PATH init --initial-branch=main && git -C $LITERATE_BUILD_EMACS_PATH remote add origin $LITERATE_BUILD_EMACS_REPO && git -C $LITERATE_BUILD_EMACS_PATH fetch origin $LITERATE_BUILD_EMACS_VERSION && git -C $LITERATE_BUILD_EMACS_PATH checkout FETCH_HEAD
|
||||||
|
# unused/aws.org contains invalid paths for setupfile which causes both upstream org-mode and Organic to error out.
|
||||||
|
RUN rm $LITERATE_BUILD_EMACS_PATH/unused/aws.org
|
||||||
|
|
||||||
FROM tester as foreign-document-test
|
FROM tester as foreign-document
|
||||||
RUN apk add --no-cache bash coreutils
|
RUN apk add --no-cache bash coreutils
|
||||||
RUN mkdir /foreign_documents
|
RUN mkdir /foreign_documents
|
||||||
COPY --from=foreign-document-gather /foreign_documents/howardabrams /foreign_documents/howardabrams
|
COPY --link --from=foreign-document-gather /foreign_documents/howardabrams /foreign_documents/howardabrams
|
||||||
COPY --from=foreign-document-gather /foreign_documents/doomemacs /foreign_documents/doomemacs
|
COPY --link --from=foreign-document-gather /foreign_documents/doomemacs /foreign_documents/doomemacs
|
||||||
COPY --from=foreign-document-gather /foreign_documents/worg /foreign_documents/worg
|
COPY --link --from=foreign-document-gather /foreign_documents/worg /foreign_documents/worg
|
||||||
COPY --from=build-org-mode /root/org-mode /foreign_documents/org-mode
|
COPY --link --from=foreign-document-gather /foreign_documents/literate_build_emacs /foreign_documents/literate_build_emacs
|
||||||
COPY --from=build-emacs /root/emacs /foreign_documents/emacs
|
COPY --link --from=build-org-mode /root/org-mode /foreign_documents/org-mode
|
||||||
|
COPY --link --from=build-emacs /root/emacs /foreign_documents/emacs
|
||||||
ENTRYPOINT ["cargo", "run", "--bin", "foreign_document_test", "--features", "compare,foreign_document_test", "--profile", "release-lto"]
|
ENTRYPOINT ["cargo", "run", "--bin", "foreign_document_test", "--features", "compare,foreign_document_test", "--profile", "release-lto"]
|
||||||
|
|||||||
@@ -1,44 +1,36 @@
|
|||||||
IMAGE_NAME:=organic-test
|
SHELL := bash
|
||||||
# REMOTE_REPO:=harbor.fizz.buzz/private
|
.ONESHELL:
|
||||||
|
.SHELLFLAGS := -eu -o pipefail -c
|
||||||
|
.DELETE_ON_ERROR:
|
||||||
|
MAKEFLAGS += --warn-undefined-variables
|
||||||
|
MAKEFLAGS += --no-builtin-rules
|
||||||
|
|
||||||
.PHONY: all
|
ifeq ($(origin .RECIPEPREFIX), undefined)
|
||||||
all: build push
|
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
|
||||||
|
endif
|
||||||
|
.RECIPEPREFIX = >
|
||||||
|
|
||||||
|
TARGET := tester
|
||||||
|
IMAGE_NAME := organic-test
|
||||||
|
ifneq ($(TARGET),tester)
|
||||||
|
IMAGE_NAME := $(IMAGE_NAME)-$(TARGET)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: help
|
||||||
|
help:
|
||||||
|
> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -E 's/^([^:]*): *## */\1: /'
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build: ## Build the docker image.
|
||||||
docker build -t $(IMAGE_NAME) -f Dockerfile --target tester .
|
> docker build --tag $(IMAGE_NAME) --target=$(TARGET) --file Dockerfile .
|
||||||
|
> docker volume create organic-cargo-registry
|
||||||
.PHONY: build_foreign_document_test
|
|
||||||
build_foreign_document_test:
|
|
||||||
docker build -t $(IMAGE_NAME)-foreign-document -f Dockerfile --target foreign-document-test .
|
|
||||||
|
|
||||||
.PHONY: push
|
|
||||||
push:
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
docker push $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not pushing to a remote repo."
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
docker rmi $(IMAGE_NAME)
|
|
||||||
ifdef REMOTE_REPO
|
|
||||||
docker rmi $(REMOTE_REPO)/$(IMAGE_NAME)
|
|
||||||
else
|
|
||||||
@echo "REMOTE_REPO not defined, not removing from remote repo."
|
|
||||||
endif
|
|
||||||
docker volume rm rust-cache cargo-cache
|
|
||||||
|
|
||||||
.PHONY: run
|
|
||||||
run: build
|
|
||||||
docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) --no-default-features --features compare --no-fail-fast --lib --test test_loader
|
|
||||||
|
|
||||||
.PHONY: shell
|
.PHONY: shell
|
||||||
|
shell: ## Launch an interactive shell inside the docker image with the source repository mounted at /source.
|
||||||
shell: build
|
shell: build
|
||||||
docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME)
|
> docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --env CARGO_TARGET_DIR=/target -v "organic-cargo-registry:/usr/local/cargo/registry" $(IMAGE_NAME)
|
||||||
|
|
||||||
.PHONY: run_foreign_document_test
|
.PHONY: clean
|
||||||
run_foreign_document_test: build_foreign_document_test
|
clean: ## Remove the docker image and volume.
|
||||||
docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME)-foreign-document
|
> docker rmi $(IMAGE_NAME)
|
||||||
|
> docker volume rm organic-cargo-registry
|
||||||
|
|||||||
42
notes/affiliated_keyword_investigation/analysis.org
Normal file
42
notes/affiliated_keyword_investigation/analysis.org
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
* Elisp Structure
|
||||||
|
| Keyword | Single | Double | Single Optval | Double Optval |
|
||||||
|
|---------+---------------+---------------+---------------+---------------|
|
||||||
|
| CAPTION | objtree | objtree | objtree | objtree |
|
||||||
|
| DATA | quoted(:name) | quoted(:name) | - | - |
|
||||||
|
| HEADER | list(quoted) | list(quoted) | - | - |
|
||||||
|
| NAME | quoted(:name) | quoted(:name) | - | - |
|
||||||
|
| PLOT | quoted(:plot) | quoted(:plot) | - | - |
|
||||||
|
| RESULTS | optional pair | optional pair | optional pair | optional pair |
|
||||||
|
* types
|
||||||
|
** objtree
|
||||||
|
Outer list: 1 per keyword
|
||||||
|
next list: first entry = list of objects for value. remaining entries = optval
|
||||||
|
** list(quoted)
|
||||||
|
List of quoted strings, 1 per keyword
|
||||||
|
** quoted(NAME)
|
||||||
|
Quoted string under the NAME property (for example quoted(:name))
|
||||||
|
** optional pair
|
||||||
|
When optval is supplied this is an alist with the field value being the real value and the 3nd value being the optval.
|
||||||
|
#+begin_src elisp
|
||||||
|
("*f*" . "*bar*")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
When optval is not supplied this is a list containing a single string of the last occurrence of this keyword.
|
||||||
|
#+begin_src elisp
|
||||||
|
("*c*")
|
||||||
|
#+end_src
|
||||||
|
* Default settings
|
||||||
|
#+begin_src text
|
||||||
|
org-element-dual-keywords ("CAPTION" "RESULTS")
|
||||||
|
org-element-parsed-keywords ("CAPTION")
|
||||||
|
org-element-multiple-keywords ("CAPTION" "HEADER")
|
||||||
|
org-babel-results-keyword "RESULTS"
|
||||||
|
#+end_src
|
||||||
|
* Analysis
|
||||||
|
We don't have an example of a parsed non-dual keyword
|
||||||
|
|
||||||
|
Looks like multiple triggers list 1 per keyword
|
||||||
|
|
||||||
|
dual triggers support for optval
|
||||||
|
|
||||||
|
parsed triggers objects
|
||||||
31
notes/affiliated_keyword_investigation/run_test.bash
Executable file
31
notes/affiliated_keyword_investigation/run_test.bash
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
file_path="${DIR}/test_document.org"
|
||||||
|
|
||||||
|
for TARGET_VARIABLE in RESULTS CAPTION HEADER DATA NAME PLOT; do
|
||||||
|
INIT_SCRIPT=$(cat <<EOF
|
||||||
|
(progn
|
||||||
|
(erase-buffer)
|
||||||
|
(require 'org)
|
||||||
|
(defun org-table-align () t)
|
||||||
|
(setq vc-handled-backends nil)
|
||||||
|
(find-file "/input/${file_path}")
|
||||||
|
(org-mode)
|
||||||
|
(replace-regexp-in-region "foo" "${TARGET_VARIABLE}")
|
||||||
|
(message "%s" (pp-to-string (org-element-parse-buffer)))
|
||||||
|
)
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
docker run --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -w /input --entrypoint "" organic-test emacs -q --no-site-file --no-splash --batch --eval "$INIT_SCRIPT" 2> "${DIR}/${TARGET_VARIABLE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# exec docker run --init --rm -i -t --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -w /input --entrypoint "" organic-test emacs -q --no-site-file --no-splash --eval "$INIT_SCRIPT"
|
||||||
|
|
||||||
|
# org-element-dual-keywords ("CAPTION" "RESULTS")
|
||||||
|
# org-element-parsed-keywords ("CAPTION")
|
||||||
|
# org-element-multiple-keywords ("CAPTION" "HEADER")
|
||||||
|
# org-babel-results-keyword "RESULTS"
|
||||||
25
notes/affiliated_keyword_investigation/test_document.org
Normal file
25
notes/affiliated_keyword_investigation/test_document.org
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Single instance
|
||||||
|
#+foo: *a*
|
||||||
|
#+begin_example
|
||||||
|
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
# Two instances
|
||||||
|
#+foo: *b*
|
||||||
|
#+foo: *c*
|
||||||
|
#+begin_example
|
||||||
|
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
# Single with optval
|
||||||
|
#+foo[*bar*]: *d*
|
||||||
|
#+begin_example
|
||||||
|
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
# Two with optval
|
||||||
|
#+foo[*bar*]: *e*
|
||||||
|
#+foo[*bar*]: *f*
|
||||||
|
#+begin_example
|
||||||
|
|
||||||
|
#+end_example
|
||||||
5
org_mode_samples/affiliated_keyword/empty_caption.org
Normal file
5
org_mode_samples/affiliated_keyword/empty_caption.org
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#+caption:
|
||||||
|
#+caption: *foo*
|
||||||
|
#+caption[bar]:
|
||||||
|
#+begin_src bash
|
||||||
|
#+end_src
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
foo
|
||||||
|
:end:
|
||||||
|
bar
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
:end:
|
||||||
0
org_mode_samples/document/empty.org
Normal file
0
org_mode_samples/document/empty.org
Normal file
4
org_mode_samples/document/only_line_breaks.org
Normal file
4
org_mode_samples/document/only_line_breaks.org
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
5
org_mode_samples/document/post_blank.org
Normal file
5
org_mode_samples/document/post_blank.org
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
* foo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +1,32 @@
|
|||||||
|
* Empty
|
||||||
|
:PROPERTIES:
|
||||||
|
:END:
|
||||||
|
* Single new line
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
|
||||||
|
:END:
|
||||||
|
* Single line with spaces
|
||||||
|
:PROPERTIES:
|
||||||
|
|
||||||
|
:END:
|
||||||
|
* Many lines, first line without spaces
|
||||||
|
:PROPERTIES:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:END:
|
||||||
|
* Many lines, first line with spaces
|
||||||
|
:PROPERTIES:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:END:
|
||||||
|
* Many lines, first line with spaces, later line with spaces
|
||||||
|
:PROPERTIES:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:END:
|
:END:
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
** Foo
|
||||||
|
DEADLINE: <2023-10-16 Mon>
|
||||||
|
:PROPERTIES:
|
||||||
|
:foo: *a*
|
||||||
|
:Bar: *b*
|
||||||
|
:BAZ: *c*
|
||||||
|
:END:
|
||||||
@@ -5,3 +5,5 @@
|
|||||||
#+call: dolar cat(dog)
|
#+call: dolar cat(dog)
|
||||||
|
|
||||||
#+call: (bat)
|
#+call: (bat)
|
||||||
|
|
||||||
|
#+call:
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
: foo
|
||||||
|
:
|
||||||
|
: bar
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
1. foo
|
||||||
|
#+begin_src text
|
||||||
|
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
2. baz
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#+results[foo]: bar
|
||||||
|
#+results[lorem]: ipsum
|
||||||
|
#+begin_example
|
||||||
|
baz
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
#+caption[lorem]: ipsum
|
||||||
|
#+caption[foo]: bar
|
||||||
|
#+begin_example
|
||||||
|
baz
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
#+header[foo]: bar
|
||||||
|
#+begin_example
|
||||||
|
baz
|
||||||
|
#+end_example
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[[file:simple.org::2]]
|
||||||
1
org_mode_samples/object/regular_link/tramp_link.org
Normal file
1
org_mode_samples/object/regular_link/tramp_link.org
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[[/ssh:admin@test.example:important/file.pdf]]
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
foo <<bar>> baz
|
<<FOO>> bar
|
||||||
|
|
||||||
lorem << ipsum >> dolar
|
[[FOO][baz]]
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
* foo
|
||||||
|
|
||||||
|
** bar
|
||||||
|
|
||||||
|
* baz
|
||||||
76
scripts/build_all_feature_flag_combinations.bash
Executable file
76
scripts/build_all_feature_flag_combinations.bash
Executable file
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Time running a single parse without invoking a compare with emacs.
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
: ${PROFILE:="debug"}
|
||||||
|
|
||||||
|
############## Setup #########################
|
||||||
|
|
||||||
|
function cleanup {
|
||||||
|
for f in "${folders[@]}"; do
|
||||||
|
log "Deleting $f"
|
||||||
|
rm -rf "$f"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
folders=()
|
||||||
|
for sig in EXIT INT QUIT HUP TERM; do
|
||||||
|
trap "set +e; cleanup" "$sig"
|
||||||
|
done
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
############## Program #########################
|
||||||
|
|
||||||
|
function main {
|
||||||
|
if [ "$#" -gt 0 ]; then
|
||||||
|
export CARGO_TARGET_DIR="$1"
|
||||||
|
else
|
||||||
|
local work_directory=$(mktemp -d -t 'organic.XXXXXX')
|
||||||
|
folders+=("$work_directory")
|
||||||
|
export CARGO_TARGET_DIR="$work_directory"
|
||||||
|
fi
|
||||||
|
local features=(compare foreign_document_test tracing event_count wasm wasm_test)
|
||||||
|
ENABLED_FEATURES= for_each_combination "${features[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function for_each_combination {
|
||||||
|
local additional_flags=()
|
||||||
|
if [ "$PROFILE" = "dev" ] || [ "$PROFILE" = "debug" ]; then
|
||||||
|
PROFILE="debug"
|
||||||
|
else
|
||||||
|
additional_flags+=(--profile "$PROFILE")
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
local flag=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
if [ "$#" -gt 0 ]; then
|
||||||
|
ENABLED_FEATURES="$ENABLED_FEATURES" for_each_combination "${@}"
|
||||||
|
elif [ -z "$ENABLED_FEATURES" ]; then
|
||||||
|
(cd "$DIR/../" && printf "\n\n\n========== no features ==========\n\n\n" && set -x && cargo build "${additional_flags[@]}" --no-default-features)
|
||||||
|
else
|
||||||
|
(cd "$DIR/../" && printf "\n\n\n========== %s ==========\n\n\n" "${ENABLED_FEATURES:1}" && set -x && cargo build "${additional_flags[@]}" --no-default-features --features "${ENABLED_FEATURES:1}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
ENABLED_FEATURES="$ENABLED_FEATURES,$flag"
|
||||||
|
if [ "$#" -gt 0 ]; then
|
||||||
|
ENABLED_FEATURES="$ENABLED_FEATURES" for_each_combination "${@}"
|
||||||
|
else
|
||||||
|
(cd "$DIR/../" && printf "\n\n\n========== %s ==========\n\n\n" "${ENABLED_FEATURES:1}" && set -x && cargo build "${additional_flags[@]}" --no-default-features --features "${ENABLED_FEATURES:1}")
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "${@}"
|
||||||
58
scripts/dump_ast.bash
Executable file
58
scripts/dump_ast.bash
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Dump the AST of an org-mode document from emacs
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
||||||
|
MAKE=$(command -v gmake || command -v make)
|
||||||
|
|
||||||
|
############## Setup #########################
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
############## Program #########################
|
||||||
|
|
||||||
|
function main {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
dump_ast_stdin "${@}"
|
||||||
|
else
|
||||||
|
dump_ast_file "${@}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function dump_ast_stdin {
|
||||||
|
# Until we can find a good way to encode stdin as an elisp string in bash, I cannot operate on stdin.
|
||||||
|
die 1 "This script only works on files."
|
||||||
|
}
|
||||||
|
|
||||||
|
function dump_ast_file {
|
||||||
|
local target_file mounted_file elisp_script
|
||||||
|
target_file=$($REALPATH "$1")
|
||||||
|
mounted_file="/input${target_file}"
|
||||||
|
elisp_script=$(cat <<EOF
|
||||||
|
(progn
|
||||||
|
(erase-buffer)
|
||||||
|
(require 'org)
|
||||||
|
(defun org-table-align () t)
|
||||||
|
(find-file-read-only "${mounted_file}")
|
||||||
|
(org-mode)
|
||||||
|
(message "%s" (pp-to-string (org-element-parse-buffer)))
|
||||||
|
)
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
exec docker run --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" --entrypoint "" organic-test emacs -q --no-site-file --no-splash --batch --eval "$elisp_script"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main "${@}"
|
||||||
@@ -14,7 +14,7 @@ function main {
|
|||||||
additional_flags+=(--profile "$PROFILE")
|
additional_flags+=(--profile "$PROFILE")
|
||||||
fi
|
fi
|
||||||
(cd "$DIR/../" && cargo build --no-default-features "${additional_flags[@]}")
|
(cd "$DIR/../" && cargo build --no-default-features "${additional_flags[@]}")
|
||||||
perf record --freq=2000 --call-graph dwarf --output="$DIR/../perf.data" "$DIR/../target/${PROFILE}/parse" "${@}"
|
perf record --freq=70000 --call-graph dwarf --output="$DIR/../perf.data" "$DIR/../target/${PROFILE}/parse" "${@}"
|
||||||
|
|
||||||
# Convert to a format firefox will read
|
# Convert to a format firefox will read
|
||||||
# flags to consider --show-info
|
# flags to consider --show-info
|
||||||
|
|||||||
111
scripts/run_docker_wasm_compare.bash
Executable file
111
scripts/run_docker_wasm_compare.bash
Executable file
@@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
: ${SHELL:="NO"} # or YES to launch a shell instead of running the test
|
||||||
|
: ${TRACE:="NO"} # or YES to send traces to jaeger
|
||||||
|
: ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking
|
||||||
|
: ${NO_COLOR:=""} # Set to anything to disable color output
|
||||||
|
: ${PROFILE:="debug"}
|
||||||
|
|
||||||
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
||||||
|
MAKE=$(command -v gmake || command -v make)
|
||||||
|
|
||||||
|
############## Setup #########################
|
||||||
|
|
||||||
|
function die {
|
||||||
|
local status_code="$1"
|
||||||
|
shift
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
exit "$status_code"
|
||||||
|
}
|
||||||
|
|
||||||
|
function log {
|
||||||
|
(>&2 echo "${@}")
|
||||||
|
}
|
||||||
|
|
||||||
|
############## Program #########################
|
||||||
|
|
||||||
|
function main {
|
||||||
|
build_container
|
||||||
|
launch_container "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_container {
|
||||||
|
$MAKE -C "$DIR/../docker/organic_test"
|
||||||
|
}
|
||||||
|
|
||||||
|
function launch_container {
|
||||||
|
local additional_flags=()
|
||||||
|
local features=(wasm_test)
|
||||||
|
|
||||||
|
if [ "$NO_COLOR" != "" ]; then
|
||||||
|
additional_flags+=(--env "NO_COLOR=$NO_COLOR")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TRACE" = "YES" ]; then
|
||||||
|
# We use the host network so it can talk to jaeger hosted at 127.0.0.1
|
||||||
|
additional_flags+=(--network=host --env RUST_LOG=debug)
|
||||||
|
features+=(tracing)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$SHELL" != "YES" ]; then
|
||||||
|
additional_flags+=(--read-only)
|
||||||
|
else
|
||||||
|
additional_flags+=(-t)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$BACKTRACE" = "YES" ]; then
|
||||||
|
additional_flags+=(--env RUST_BACKTRACE=full)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$SHELL" = "YES" ]; then
|
||||||
|
exec docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test /bin/sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
local features_joined
|
||||||
|
features_joined=$(IFS=","; echo "${features[*]}")
|
||||||
|
|
||||||
|
local build_flags=()
|
||||||
|
if [ "$PROFILE" = "dev" ] || [ "$PROFILE" = "debug" ]; then
|
||||||
|
PROFILE="debug"
|
||||||
|
else
|
||||||
|
build_flags+=(--profile "$PROFILE")
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
# If we passed in args, we need to forward them along
|
||||||
|
for path in "${@}"; do
|
||||||
|
local full_path
|
||||||
|
full_path=$($REALPATH "$path")
|
||||||
|
init_script=$(cat <<EOF
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=\$'\n\t'
|
||||||
|
|
||||||
|
cargo build --bin wasm_test --no-default-features --features "$features_joined" ${build_flags[@]}
|
||||||
|
exec /target/${PROFILE}/wasm_test "/input${full_path}"
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
local current_directory init_script
|
||||||
|
current_directory=$(pwd)
|
||||||
|
init_script=$(cat <<EOF
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=\$'\n\t'
|
||||||
|
|
||||||
|
cargo build --bin wasm_test --no-default-features --features "$features_joined" ${build_flags[@]}
|
||||||
|
cd /input${current_directory}
|
||||||
|
exec /target/${PROFILE}/wasm_test
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
docker run "${additional_flags[@]}" --init --rm -i --mount type=tmpfs,destination=/tmp -v "/:/input:ro" -v "$($REALPATH "$DIR/../"):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source --entrypoint "" organic-test sh -c "$init_script"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "${@}"
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![feature(exit_status_error)]
|
||||||
#![feature(round_char_boundary)]
|
#![feature(round_char_boundary)]
|
||||||
#![feature(exact_size_is_empty)]
|
#![feature(exact_size_is_empty)]
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
@@ -15,23 +16,21 @@ mod init_tracing;
|
|||||||
#[cfg(not(feature = "tracing"))]
|
#[cfg(not(feature = "tracing"))]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async {
|
rt.block_on(async {
|
||||||
let main_body_result = main_body().await;
|
let main_body_result = main_body().await;
|
||||||
main_body_result
|
main_body_result
|
||||||
});
|
})
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async {
|
rt.block_on(async {
|
||||||
init_telemetry()?;
|
init_telemetry()?;
|
||||||
let main_body_result = main_body().await;
|
let main_body_result = main_body().await;
|
||||||
shutdown_telemetry()?;
|
shutdown_telemetry()?;
|
||||||
main_body_result
|
main_body_result
|
||||||
});
|
})
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
|||||||
@@ -21,23 +21,21 @@ mod init_tracing;
|
|||||||
#[cfg(not(feature = "tracing"))]
|
#[cfg(not(feature = "tracing"))]
|
||||||
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async {
|
rt.block_on(async {
|
||||||
let main_body_result = main_body().await;
|
let main_body_result = main_body().await;
|
||||||
main_body_result
|
main_body_result
|
||||||
});
|
})
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async {
|
rt.block_on(async {
|
||||||
init_telemetry()?;
|
init_telemetry()?;
|
||||||
let main_body_result = main_body().await;
|
let main_body_result = main_body().await;
|
||||||
shutdown_telemetry()?;
|
shutdown_telemetry()?;
|
||||||
main_body_result
|
main_body_result
|
||||||
});
|
})
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
@@ -55,6 +53,9 @@ async fn main_body() -> Result<ExitCode, Box<dyn std::error::Error>> {
|
|||||||
let layer = layer.chain(compare_group("doomemacs", || {
|
let layer = layer.chain(compare_group("doomemacs", || {
|
||||||
compare_all_org_document("/foreign_documents/doomemacs")
|
compare_all_org_document("/foreign_documents/doomemacs")
|
||||||
}));
|
}));
|
||||||
|
let layer = layer.chain(compare_group("literate_build_emacs", || {
|
||||||
|
compare_all_org_document("/foreign_documents/literate_build_emacs")
|
||||||
|
}));
|
||||||
|
|
||||||
let running_tests: Vec<_> = layer.map(|c| tokio::spawn(c.run_test())).collect();
|
let running_tests: Vec<_> = layer.map(|c| tokio::spawn(c.run_test())).collect();
|
||||||
let mut any_failed = false;
|
let mut any_failed = false;
|
||||||
@@ -108,10 +109,9 @@ fn compare_howard_abrams() -> impl Iterator<Item = TestConfig> {
|
|||||||
let layer = layer.chain(compare_group("clojure-yesql-xp", || {
|
let layer = layer.chain(compare_group("clojure-yesql-xp", || {
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/clojure-yesql-xp")
|
compare_all_org_document("/foreign_documents/howardabrams/clojure-yesql-xp")
|
||||||
}));
|
}));
|
||||||
let layer = layer.chain(compare_group("veep", || {
|
layer.chain(compare_group("veep", || {
|
||||||
compare_all_org_document("/foreign_documents/howardabrams/veep")
|
compare_all_org_document("/foreign_documents/howardabrams/veep")
|
||||||
}));
|
}))
|
||||||
layer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_group<N: Into<String>, F: Fn() -> I, I: Iterator<Item = TestConfig>>(
|
fn compare_group<N: Into<String>, F: Fn() -> I, I: Iterator<Item = TestConfig>>(
|
||||||
@@ -195,7 +195,6 @@ struct ResultLayer {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SingleFileResult {
|
struct SingleFileResult {
|
||||||
name: String,
|
name: String,
|
||||||
file_path: PathBuf,
|
|
||||||
status: TestStatus,
|
status: TestStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +224,6 @@ impl SingleFile {
|
|||||||
let result = silent_compare_on_file(&self.file_path).await;
|
let result = silent_compare_on_file(&self.file_path).await;
|
||||||
Ok(SingleFileResult {
|
Ok(SingleFileResult {
|
||||||
name: self.name,
|
name: self.name,
|
||||||
file_path: self.file_path,
|
|
||||||
status: if let Ok(true) = result {
|
status: if let Ok(true) = result {
|
||||||
TestStatus::Pass
|
TestStatus::Pass
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
10
src/bin_wasm.rs
Normal file
10
src/bin_wasm.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||||
|
organic::wasm_cli::parse_org(org_contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
62
src/bin_wasm_test.rs
Normal file
62
src/bin_wasm_test.rs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#![feature(exact_size_is_empty)]
|
||||||
|
#![feature(exit_status_error)]
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use organic::wasm_test::wasm_run_anonymous_compare;
|
||||||
|
use organic::wasm_test::wasm_run_compare_on_file;
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use crate::init_tracing::init_telemetry;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use crate::init_tracing::shutdown_telemetry;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
mod init_tracing;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "tracing"))]
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
|
rt.block_on(async {
|
||||||
|
let main_body_result = main_body().await;
|
||||||
|
main_body_result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
|
rt.block_on(async {
|
||||||
|
init_telemetry()?;
|
||||||
|
let main_body_result = main_body().await;
|
||||||
|
shutdown_telemetry()?;
|
||||||
|
main_body_result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args = std::env::args().skip(1);
|
||||||
|
if args.is_empty() {
|
||||||
|
let org_contents = read_stdin_to_string()?;
|
||||||
|
if wasm_run_anonymous_compare(org_contents).await? {
|
||||||
|
} else {
|
||||||
|
Err("Diff results do not match.")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
for arg in args {
|
||||||
|
if wasm_run_compare_on_file(arg).await? {
|
||||||
|
} else {
|
||||||
|
Err("Diff results do not match.")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
let mut stdin_contents = String::new();
|
||||||
|
std::io::stdin()
|
||||||
|
.lock()
|
||||||
|
.read_to_string(&mut stdin_contents)?;
|
||||||
|
Ok(stdin_contents)
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::compare::diff::compare_document;
|
use crate::compare::diff::compare_document;
|
||||||
use crate::compare::diff::DiffResult;
|
|
||||||
use crate::compare::parse::emacs_parse_anonymous_org_document;
|
|
||||||
use crate::compare::parse::emacs_parse_file_org_document;
|
|
||||||
use crate::compare::parse::get_emacs_version;
|
|
||||||
use crate::compare::parse::get_org_mode_version;
|
|
||||||
use crate::compare::sexp::sexp;
|
|
||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::LocalFileAccessInterface;
|
use crate::context::LocalFileAccessInterface;
|
||||||
use crate::parser::parse_file_with_settings;
|
use crate::parser::parse_file_with_settings;
|
||||||
use crate::parser::parse_with_settings;
|
use crate::parser::parse_with_settings;
|
||||||
|
use crate::util::cli::emacs_parse_anonymous_org_document;
|
||||||
|
use crate::util::cli::emacs_parse_file_org_document;
|
||||||
|
use crate::util::cli::print_versions;
|
||||||
|
use crate::util::elisp::sexp;
|
||||||
|
use crate::util::terminal::foreground_color;
|
||||||
|
use crate::util::terminal::reset_color;
|
||||||
|
|
||||||
pub async fn run_anonymous_compare<P: AsRef<str>>(
|
pub async fn run_anonymous_compare<P: AsRef<str>>(
|
||||||
org_contents: P,
|
org_contents: P,
|
||||||
@@ -68,8 +68,8 @@ pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
|
|||||||
} else if !silent {
|
} else if !silent {
|
||||||
println!(
|
println!(
|
||||||
"{color}Entire document passes.{reset}",
|
"{color}Entire document passes.{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,19 +121,10 @@ pub async fn run_compare_on_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
} else if !silent {
|
} else if !silent {
|
||||||
println!(
|
println!(
|
||||||
"{color}Entire document passes.{reset}",
|
"{color}Entire document passes.{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn print_versions() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
eprintln!("Using emacs version: {}", get_emacs_version().await?.trim());
|
|
||||||
eprintln!(
|
|
||||||
"Using org-mode version: {}",
|
|
||||||
get_org_mode_version().await?.trim()
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -7,8 +9,6 @@ use super::diff::artificial_owned_diff_scope;
|
|||||||
use super::diff::compare_ast_node;
|
use super::diff::compare_ast_node;
|
||||||
use super::diff::DiffEntry;
|
use super::diff::DiffEntry;
|
||||||
use super::diff::DiffStatus;
|
use super::diff::DiffStatus;
|
||||||
use super::sexp::unquote;
|
|
||||||
use super::sexp::Token;
|
|
||||||
use super::util::get_property;
|
use super::util::get_property;
|
||||||
use super::util::get_property_numeric;
|
use super::util::get_property_numeric;
|
||||||
use super::util::get_property_quoted_string;
|
use super::util::get_property_quoted_string;
|
||||||
@@ -16,9 +16,10 @@ use super::util::get_property_unquoted_atom;
|
|||||||
use crate::types::AstNode;
|
use crate::types::AstNode;
|
||||||
use crate::types::CharOffsetInLine;
|
use crate::types::CharOffsetInLine;
|
||||||
use crate::types::LineNumber;
|
use crate::types::LineNumber;
|
||||||
use crate::types::Object;
|
|
||||||
use crate::types::RetainLabels;
|
use crate::types::RetainLabels;
|
||||||
use crate::types::SwitchNumberLines;
|
use crate::types::SwitchNumberLines;
|
||||||
|
use crate::util::elisp::unquote;
|
||||||
|
use crate::util::elisp::Token;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum EmacsField<'s> {
|
pub(crate) enum EmacsField<'s> {
|
||||||
@@ -57,11 +58,11 @@ impl<'b, 's> ComparePropertiesResult<'b, 's> {
|
|||||||
/// Do no comparison.
|
/// Do no comparison.
|
||||||
///
|
///
|
||||||
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
|
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
|
||||||
pub(crate) fn compare_noop<'b, 's, 'x, R, RG>(
|
pub(crate) fn compare_noop<'b, 's, R, RG>(
|
||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
_emacs: &'b Token<'s>,
|
_emacs: &'b Token<'s>,
|
||||||
_rust_node: R,
|
_rust_node: R,
|
||||||
_emacs_field: &'x str,
|
_emacs_field: &str,
|
||||||
_rust_value_getter: RG,
|
_rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
@@ -70,18 +71,16 @@ pub(crate) fn compare_noop<'b, 's, 'x, R, RG>(
|
|||||||
/// Do no comparison.
|
/// Do no comparison.
|
||||||
///
|
///
|
||||||
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
|
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
|
||||||
pub(crate) fn compare_identity() -> () {
|
pub(crate) fn compare_identity() {}
|
||||||
()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Assert that the emacs value is always nil or absent.
|
/// Assert that the emacs value is always nil or absent.
|
||||||
///
|
///
|
||||||
/// This is usually used for fields which, in my testing, are always nil. Using this compare function instead of simply doing a compare_noop will enable us to be alerted when we finally come across an org-mode document that has a value other than nil for the property.
|
/// This is usually used for fields which, in my testing, are always nil. Using this compare function instead of simply doing a compare_noop will enable us to be alerted when we finally come across an org-mode document that has a value other than nil for the property.
|
||||||
pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>(
|
pub(crate) fn compare_property_always_nil<'b, 's, R, RG>(
|
||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
_rust_node: R,
|
_rust_node: R,
|
||||||
emacs_field: &'x str,
|
emacs_field: &str,
|
||||||
_rust_value_getter: RG,
|
_rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
let value = get_property(emacs, emacs_field)?;
|
let value = get_property(emacs, emacs_field)?;
|
||||||
@@ -100,7 +99,6 @@ pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>(
|
|||||||
pub(crate) fn compare_property_quoted_string<
|
pub(crate) fn compare_property_quoted_string<
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
'x,
|
|
||||||
R,
|
R,
|
||||||
RV: AsRef<str> + std::fmt::Debug,
|
RV: AsRef<str> + std::fmt::Debug,
|
||||||
RG: Fn(R) -> Option<RV>,
|
RG: Fn(R) -> Option<RV>,
|
||||||
@@ -108,12 +106,12 @@ pub(crate) fn compare_property_quoted_string<
|
|||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust_node: R,
|
rust_node: R,
|
||||||
emacs_field: &'x str,
|
emacs_field: &str,
|
||||||
rust_value_getter: RG,
|
rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
let value = get_property_quoted_string(emacs, emacs_field)?;
|
let value = get_property_quoted_string(emacs, emacs_field)?;
|
||||||
let rust_value = rust_value_getter(rust_node);
|
let rust_value = rust_value_getter(rust_node);
|
||||||
if rust_value.as_ref().map(|s| s.as_ref()) != value.as_ref().map(String::as_str) {
|
if rust_value.as_ref().map(|s| s.as_ref()) != value.as_deref() {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
@@ -181,7 +179,6 @@ where
|
|||||||
pub(crate) fn compare_property_list_of_quoted_string<
|
pub(crate) fn compare_property_list_of_quoted_string<
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
'x,
|
|
||||||
R,
|
R,
|
||||||
RV: AsRef<str> + std::fmt::Debug,
|
RV: AsRef<str> + std::fmt::Debug,
|
||||||
RI: Iterator<Item = RV>,
|
RI: Iterator<Item = RV>,
|
||||||
@@ -190,7 +187,7 @@ pub(crate) fn compare_property_list_of_quoted_string<
|
|||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust_node: R,
|
rust_node: R,
|
||||||
emacs_field: &'x str,
|
emacs_field: &str,
|
||||||
rust_value_getter: RG,
|
rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
let value = get_property(emacs, emacs_field)?
|
let value = get_property(emacs, emacs_field)?
|
||||||
@@ -267,15 +264,12 @@ pub(crate) fn compare_property_set_of_quoted_string<
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|e| e.as_atom())
|
.map(|e| e.as_atom())
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let value: Vec<String> = value
|
let value: Vec<Cow<'_, str>> = value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(unquote)
|
.map(unquote)
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let value: BTreeSet<&str> = value.iter().map(|e| e.as_str()).collect();
|
let value: BTreeSet<&str> = value.iter().map(|e| e.borrow()).collect();
|
||||||
let mismatched: Vec<_> = value
|
let mismatched: Vec<_> = value.symmetric_difference(&rust_value).copied().collect();
|
||||||
.symmetric_difference(&rust_value)
|
|
||||||
.map(|val| *val)
|
|
||||||
.collect();
|
|
||||||
if !mismatched.is_empty() {
|
if !mismatched.is_empty() {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
@@ -288,11 +282,111 @@ pub(crate) fn compare_property_set_of_quoted_string<
|
|||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>(
|
pub(crate) fn compare_property_optional_pair<
|
||||||
|
'b,
|
||||||
|
's,
|
||||||
|
R,
|
||||||
|
RV: AsRef<str> + std::fmt::Debug,
|
||||||
|
ROV: AsRef<str> + std::fmt::Debug,
|
||||||
|
RG: Fn(R) -> Option<(Option<ROV>, RV)>,
|
||||||
|
>(
|
||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust_node: R,
|
rust_node: R,
|
||||||
emacs_field: &'x str,
|
emacs_field: &str,
|
||||||
|
rust_value_getter: RG,
|
||||||
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
|
let value = get_property(emacs, emacs_field)?
|
||||||
|
.map(Token::as_list)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
match (value, &rust_value) {
|
||||||
|
(None, None) => {}
|
||||||
|
(None, Some(_)) | (Some(_), None) => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
(Some(el), Some((Some(_), _))) if el.len() != 3 => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
(Some(el), Some((None, _))) if el.len() != 1 => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
(Some(el), Some((Some(orl), rl))) => {
|
||||||
|
let e = el
|
||||||
|
.first()
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 3.");
|
||||||
|
let oe = el
|
||||||
|
.get(2)
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 3.");
|
||||||
|
let r = rl.as_ref();
|
||||||
|
let or = orl.as_ref();
|
||||||
|
if e != r {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}. Full list: {:?} != {:?}",
|
||||||
|
emacs_field, e, r, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
if oe != or {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}. Full list: {:?} != {:?}",
|
||||||
|
emacs_field, e, r, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(Some(el), Some((None, rl))) => {
|
||||||
|
let e = el
|
||||||
|
.first()
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.map(unquote)
|
||||||
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
|
.expect("Above match proved length to be 1.");
|
||||||
|
let r = rl.as_ref();
|
||||||
|
if e != r {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}. Full list: {:?} != {:?}",
|
||||||
|
emacs_field, e, r, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_property_boolean<'b, 's, R, RG: Fn(R) -> bool>(
|
||||||
|
_source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_node: R,
|
||||||
|
emacs_field: &str,
|
||||||
rust_value_getter: RG,
|
rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
// get_property already converts nil to None.
|
// get_property already converts nil to None.
|
||||||
@@ -376,14 +470,7 @@ where
|
|||||||
match (value, rust_value) {
|
match (value, rust_value) {
|
||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
(Some(el), None)
|
(Some(el), None)
|
||||||
if el.len() == 1
|
if el.len() == 1 && el.iter().all(|t| matches!(t.as_atom(), Ok(r#""""#))) => {}
|
||||||
&& el.into_iter().all(|t| {
|
|
||||||
if let Ok(r#""""#) = t.as_atom() {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}) => {}
|
|
||||||
(None, rv @ Some(_)) | (Some(_), rv @ None) => {
|
(None, rv @ Some(_)) | (Some(_), rv @ None) => {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
@@ -412,118 +499,161 @@ where
|
|||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Special compare used for affiliate keywords that are parsed as objects.
|
pub(crate) fn compare_property_object_tree<
|
||||||
///
|
|
||||||
/// Org-mode seems to store these as a 3-deep list:
|
|
||||||
/// - Outer list with 1 element per #+caption keyword (or other parsed keyword).
|
|
||||||
/// - Middle list which has:
|
|
||||||
/// - first element is a list of objects representing the value after the colon.
|
|
||||||
/// - every additional element is a list of objects from inside the square brackets (the optional value).
|
|
||||||
pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
|
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
'x,
|
'x,
|
||||||
R,
|
R,
|
||||||
RG: Fn(R) -> Option<&'b Vec<(Option<Vec<Object<'s>>>, Vec<Object<'s>>)>>,
|
RV: std::fmt::Debug + 'b,
|
||||||
|
ROV: std::fmt::Debug + 'b,
|
||||||
|
RI: Iterator<Item = &'b (Option<Vec<ROV>>, Vec<RV>)> + ExactSizeIterator + std::fmt::Debug,
|
||||||
|
RG: Fn(R) -> Option<RI>,
|
||||||
>(
|
>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust_node: R,
|
rust_node: R,
|
||||||
emacs_field: &'x str,
|
emacs_field: &'x str,
|
||||||
rust_value_getter: RG,
|
rust_value_getter: RG,
|
||||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>>
|
||||||
// TODO: Replace Object<'s> with generics. I hard-coded Object in to make lifetimes easier.
|
where
|
||||||
let rust_value = rust_value_getter(rust_node);
|
AstNode<'b, 's>: From<&'b RV>,
|
||||||
|
AstNode<'b, 's>: From<&'b ROV>,
|
||||||
|
{
|
||||||
let value = get_property(emacs, emacs_field)?
|
let value = get_property(emacs, emacs_field)?
|
||||||
.map(Token::as_list)
|
.map(Token::as_list)
|
||||||
.map_or(Ok(None), |r| r.map(Some))?;
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
let (value, rust_value) = match (value, rust_value) {
|
let rust_value = rust_value_getter(rust_node);
|
||||||
|
let (outer_emacs_list, outer_rust_list) = match (value, rust_value) {
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
return Ok(ComparePropertiesResult::NoChange);
|
return Ok(ComparePropertiesResult::NoChange);
|
||||||
}
|
}
|
||||||
(None, Some(_)) | (Some(_), None) => {
|
(None, rv @ Some(_)) | (Some(_), rv @ None) => {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
emacs_field, value, rust_value
|
emacs_field, value, rv
|
||||||
));
|
));
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
(Some(value), Some(rust_value)) if value.len() != rust_value.len() => {
|
(Some(el), Some(rl)) if el.len() != rl.len() => {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
emacs_field, value, rust_value
|
emacs_field, el, rl
|
||||||
));
|
));
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
(Some(value), Some(rust_value)) => (value, rust_value),
|
(Some(el), Some(rl)) => (el, rl),
|
||||||
};
|
};
|
||||||
|
let mut full_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(outer_rust_list.len());
|
||||||
|
|
||||||
let mut full_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
|
for (kw_e, kw_r) in outer_emacs_list.iter().zip(outer_rust_list) {
|
||||||
|
match (kw_e.as_atom(), kw_r) {
|
||||||
// Iterate the outer lists
|
(Ok("nil"), (None, mandatory_value)) if mandatory_value.is_empty() => {
|
||||||
for (value, (rust_optional, rust_value)) in value.iter().zip(rust_value.iter()) {
|
// If its an empty keyword then it becomes nil in the elisp.
|
||||||
let mut middle_value = value.as_list()?.iter();
|
continue;
|
||||||
// First element of middle list is the mandatory value (the value past the colon).
|
}
|
||||||
let mandatory_value = middle_value.next();
|
(Ok("nil"), _) => {
|
||||||
let mandatory_value = match mandatory_value {
|
|
||||||
Some(mandatory_value) => mandatory_value,
|
|
||||||
None => {
|
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
emacs_field, value, rust_value
|
emacs_field, kw_e, kw_r
|
||||||
));
|
));
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
};
|
_ => {}
|
||||||
|
}
|
||||||
// Compare optional value
|
let kw_e = kw_e.as_list()?;
|
||||||
if let Some(rust_optional) = rust_optional {
|
let child_status_length = kw_r.1.len() + kw_r.0.as_ref().map(|opt| opt.len()).unwrap_or(0);
|
||||||
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
|
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(child_status_length);
|
||||||
if rust_optional.len() != middle_value.len() {
|
if let Some(or) = &kw_r.0 {
|
||||||
|
// if optional value
|
||||||
|
let mut kw_e = kw_e.iter();
|
||||||
|
// First element is a list representing the mandatory value.
|
||||||
|
if let Some(val_e) = kw_e.next() {
|
||||||
|
match (val_e.as_atom(), kw_r) {
|
||||||
|
(Ok("nil"), (_, mandatory_value)) if mandatory_value.is_empty() => {}
|
||||||
|
(Ok("nil"), _) => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, kw_e, kw_r
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let el = val_e.as_list()?;
|
||||||
|
if el.len() != kw_r.1.len() {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, kw_e, kw_r
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
for (e, r) in el.iter().zip(kw_r.1.iter()) {
|
||||||
|
child_status.push(compare_ast_node(source, e, r.into())?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} optional value length mismatch (emacs != rust) {} != {} | {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
emacs_field,
|
emacs_field, kw_e, kw_r
|
||||||
middle_value.len(),
|
|
||||||
rust_optional.len(),
|
|
||||||
rust_optional
|
|
||||||
));
|
));
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
for (e, r) in middle_value.zip(rust_optional) {
|
// Remaining elements are the optional value.
|
||||||
|
if kw_e.len() != or.len() {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, kw_e, kw_r
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
for (e, r) in kw_e.zip(or.iter()) {
|
||||||
child_status.push(compare_ast_node(source, e, r.into())?);
|
child_status.push(compare_ast_node(source, e, r.into())?);
|
||||||
}
|
}
|
||||||
if !child_status.is_empty() {
|
} else {
|
||||||
let diff_scope = artificial_diff_scope("optional value", child_status)?;
|
// if no optional value
|
||||||
full_status.push(diff_scope);
|
if !kw_e.len() == 1 {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, kw_e, kw_r
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Compare mandatory value
|
let e = kw_e
|
||||||
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
|
.first()
|
||||||
let mandatory_value = mandatory_value.as_list()?;
|
.map(Token::as_list)
|
||||||
if rust_value.len() != mandatory_value.len() {
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
let this_status = DiffStatus::Bad;
|
.expect("The above if-statement proves this will be Some.")
|
||||||
let message = Some(format!(
|
.iter();
|
||||||
"{} mandatory value length mismatch (emacs != rust) {} != {} | {:?}",
|
let r = kw_r.1.iter();
|
||||||
emacs_field,
|
|
||||||
mandatory_value.len(),
|
if e.len() != r.len() {
|
||||||
rust_value.len(),
|
let this_status = DiffStatus::Bad;
|
||||||
rust_value
|
let message = Some(format!(
|
||||||
));
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
emacs_field, kw_e, kw_r
|
||||||
}
|
));
|
||||||
for (e, r) in mandatory_value.iter().zip(rust_value) {
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
child_status.push(compare_ast_node(source, e, r.into())?);
|
}
|
||||||
|
|
||||||
|
for (e, r) in e.zip(r) {
|
||||||
|
child_status.push(compare_ast_node(source, e, r.into())?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !child_status.is_empty() {
|
if !child_status.is_empty() {
|
||||||
let diff_scope = artificial_diff_scope("mandatory value", child_status)?;
|
let diff_scope = artificial_diff_scope("mandatory value", child_status)?;
|
||||||
full_status.push(diff_scope);
|
full_status.push(diff_scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if full_status.is_empty() {
|
if full_status.is_empty() {
|
||||||
Ok(ComparePropertiesResult::NoChange)
|
Ok(ComparePropertiesResult::NoChange)
|
||||||
} else {
|
} else {
|
||||||
@@ -553,7 +683,7 @@ pub(crate) fn compare_property_number_lines<
|
|||||||
(Some(number_lines), Some(rust_number_lines)) => {
|
(Some(number_lines), Some(rust_number_lines)) => {
|
||||||
let token_list = number_lines.as_list()?;
|
let token_list = number_lines.as_list()?;
|
||||||
let number_type = token_list
|
let number_type = token_list
|
||||||
.get(0)
|
.first()
|
||||||
.map(Token::as_atom)
|
.map(Token::as_atom)
|
||||||
.map_or(Ok(None), |r| r.map(Some))?
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
.ok_or(":number-lines should have a type.")?;
|
.ok_or(":number-lines should have a type.")?;
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ use super::compare_field::compare_property_retain_labels;
|
|||||||
use super::compare_field::compare_property_set_of_quoted_string;
|
use super::compare_field::compare_property_set_of_quoted_string;
|
||||||
use super::compare_field::compare_property_single_ast_node;
|
use super::compare_field::compare_property_single_ast_node;
|
||||||
use super::compare_field::compare_property_unquoted_atom;
|
use super::compare_field::compare_property_unquoted_atom;
|
||||||
use super::elisp_fact::ElispFact;
|
|
||||||
use super::elisp_fact::GetElispFact;
|
|
||||||
use super::sexp::unquote;
|
|
||||||
use super::sexp::Token;
|
|
||||||
use super::util::affiliated_keywords_names;
|
use super::util::affiliated_keywords_names;
|
||||||
use super::util::assert_no_children;
|
use super::util::assert_no_children;
|
||||||
use super::util::compare_additional_properties;
|
use super::util::compare_additional_properties;
|
||||||
@@ -57,7 +53,6 @@ use crate::types::FixedWidthArea;
|
|||||||
use crate::types::FootnoteDefinition;
|
use crate::types::FootnoteDefinition;
|
||||||
use crate::types::FootnoteReference;
|
use crate::types::FootnoteReference;
|
||||||
use crate::types::FootnoteReferenceType;
|
use crate::types::FootnoteReferenceType;
|
||||||
use crate::types::GetStandardProperties;
|
|
||||||
use crate::types::Heading;
|
use crate::types::Heading;
|
||||||
use crate::types::HorizontalRule;
|
use crate::types::HorizontalRule;
|
||||||
use crate::types::Hour;
|
use crate::types::Hour;
|
||||||
@@ -110,6 +105,12 @@ use crate::types::Verbatim;
|
|||||||
use crate::types::VerseBlock;
|
use crate::types::VerseBlock;
|
||||||
use crate::types::WarningDelayType;
|
use crate::types::WarningDelayType;
|
||||||
use crate::types::Year;
|
use crate::types::Year;
|
||||||
|
use crate::util::elisp::unquote;
|
||||||
|
use crate::util::elisp::Token;
|
||||||
|
use crate::util::elisp_fact::ElispFact;
|
||||||
|
use crate::util::elisp_fact::GetElispFact;
|
||||||
|
use crate::util::terminal::foreground_color;
|
||||||
|
use crate::util::terminal::reset_color;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DiffEntry<'b, 's> {
|
pub enum DiffEntry<'b, 's> {
|
||||||
@@ -128,7 +129,7 @@ pub struct DiffResult<'b, 's> {
|
|||||||
emacs_token: &'b Token<'s>,
|
emacs_token: &'b Token<'s>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum DiffStatus {
|
pub(crate) enum DiffStatus {
|
||||||
Good,
|
Good,
|
||||||
Bad,
|
Bad,
|
||||||
@@ -164,7 +165,7 @@ impl<'b, 's> DiffEntry<'b, 's> {
|
|||||||
|
|
||||||
fn is_immediately_bad(&self) -> bool {
|
fn is_immediately_bad(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
DiffEntry::DiffResult(diff) => diff.status == DiffStatus::Bad,
|
DiffEntry::DiffResult(diff) => matches!(diff.status, DiffStatus::Bad),
|
||||||
DiffEntry::DiffLayer(_) => false,
|
DiffEntry::DiffLayer(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,21 +202,21 @@ impl<'b, 's> DiffResult<'b, 's> {
|
|||||||
if self.has_bad_children() {
|
if self.has_bad_children() {
|
||||||
format!(
|
format!(
|
||||||
"{color}BADCHILD{reset}",
|
"{color}BADCHILD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 255, 0),
|
color = foreground_color(255, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{color}GOOD{reset}",
|
"{color}GOOD{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DiffStatus::Bad => format!(
|
DiffStatus::Bad => format!(
|
||||||
"{color}BAD{reset}",
|
"{color}BAD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 0, 0),
|
color = foreground_color(255, 0, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -227,7 +228,7 @@ impl<'b, 's> DiffResult<'b, 's> {
|
|||||||
status_text = status_text,
|
status_text = status_text,
|
||||||
name = self.name,
|
name = self.name,
|
||||||
char_offset = preceding_text.chars().count() + 1,
|
char_offset = preceding_text.chars().count() + 1,
|
||||||
message = self.message.as_ref().map(|m| m.as_str()).unwrap_or("")
|
message = self.message.as_deref().unwrap_or("")
|
||||||
);
|
);
|
||||||
for child in self.children.iter() {
|
for child in self.children.iter() {
|
||||||
child.print_indented(indentation + 1, original_document)?;
|
child.print_indented(indentation + 1, original_document)?;
|
||||||
@@ -240,45 +241,6 @@ impl<'b, 's> DiffResult<'b, 's> {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|child| child.is_immediately_bad() || child.has_bad_children())
|
.any(|child| child.is_immediately_bad() || child.has_bad_children())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn foreground_color(red: u8, green: u8, blue: u8) -> String {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
format!(
|
|
||||||
"\x1b[38;2;{red};{green};{blue}m",
|
|
||||||
red = red,
|
|
||||||
green = green,
|
|
||||||
blue = blue
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn background_color(red: u8, green: u8, blue: u8) -> String {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
format!(
|
|
||||||
"\x1b[48;2;{red};{green};{blue}m",
|
|
||||||
red = red,
|
|
||||||
green = green,
|
|
||||||
blue = blue
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn reset_color() -> &'static str {
|
|
||||||
if DiffResult::should_use_color() {
|
|
||||||
"\x1b[0m"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn should_use_color() -> bool {
|
|
||||||
!std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 's> DiffLayer<'b, 's> {
|
impl<'b, 's> DiffLayer<'b, 's> {
|
||||||
@@ -296,14 +258,14 @@ impl<'b, 's> DiffLayer<'b, 's> {
|
|||||||
let status_text = if self.has_bad_children() {
|
let status_text = if self.has_bad_children() {
|
||||||
format!(
|
format!(
|
||||||
"{color}BADCHILD{reset}",
|
"{color}BADCHILD{reset}",
|
||||||
color = DiffResult::foreground_color(255, 255, 0),
|
color = foreground_color(255, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{color}GOOD{reset}",
|
"{color}GOOD{reset}",
|
||||||
color = DiffResult::foreground_color(0, 255, 0),
|
color = foreground_color(0, 255, 0),
|
||||||
reset = DiffResult::reset_color(),
|
reset = reset_color(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
println!(
|
println!(
|
||||||
@@ -330,8 +292,8 @@ pub(crate) fn artificial_diff_scope<'b, 's>(
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn artificial_owned_diff_scope<'b, 's, 'x>(
|
pub(crate) fn artificial_owned_diff_scope<'b, 's>(
|
||||||
name: &'x str,
|
name: &str,
|
||||||
children: Vec<DiffEntry<'b, 's>>,
|
children: Vec<DiffEntry<'b, 's>>,
|
||||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
Ok(DiffLayer {
|
Ok(DiffLayer {
|
||||||
@@ -413,7 +375,7 @@ pub(crate) fn compare_ast_node<'b, 's>(
|
|||||||
name: rust.get_elisp_fact().get_elisp_name(),
|
name: rust.get_elisp_fact().get_elisp_name(),
|
||||||
message: Some(e.to_string()),
|
message: Some(e.to_string()),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
rust_source: rust.get_standard_properties().get_source(),
|
rust_source: rust.get_source(),
|
||||||
emacs_token: emacs,
|
emacs_token: emacs,
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
@@ -426,14 +388,9 @@ pub(crate) fn compare_ast_node<'b, 's>(
|
|||||||
|
|
||||||
// PlainText is a special case because upstream Org-Mode uses relative values for the bounds in plaintext rather than absolute so the below checks do not account for that.
|
// PlainText is a special case because upstream Org-Mode uses relative values for the bounds in plaintext rather than absolute so the below checks do not account for that.
|
||||||
if let AstNode::PlainText(_) = rust {
|
if let AstNode::PlainText(_) = rust {
|
||||||
} else {
|
} else if let Err(err) = compare_standard_properties(source, emacs, &rust) {
|
||||||
match compare_standard_properties(source, emacs, &rust) {
|
compare_result.status = DiffStatus::Bad;
|
||||||
Err(err) => {
|
compare_result.message = Some(err.to_string())
|
||||||
compare_result.status = DiffStatus::Bad;
|
|
||||||
compare_result.message = Some(err.to_string())
|
|
||||||
}
|
|
||||||
Ok(_) => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(compare_result.into())
|
Ok(compare_result.into())
|
||||||
@@ -495,7 +452,7 @@ fn _compare_document<'b, 's>(
|
|||||||
.map(EmacsField::Required),
|
.map(EmacsField::Required),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":path"),
|
EmacsField::Required(":path"),
|
||||||
|r| r.path.as_ref().map(|p| p.to_str()).flatten(),
|
|r| r.path.as_ref().and_then(|p| p.to_str()),
|
||||||
compare_property_quoted_string
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -1581,7 +1538,7 @@ fn compare_example_block<'b, 's>(
|
|||||||
[],
|
[],
|
||||||
(
|
(
|
||||||
EmacsField::Required(":value"),
|
EmacsField::Required(":value"),
|
||||||
|r| Some(r.contents.as_str()),
|
|r| Some(r.get_value()),
|
||||||
compare_property_quoted_string
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -1659,7 +1616,7 @@ fn compare_export_block<'b, 's>(
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":value"),
|
EmacsField::Required(":value"),
|
||||||
|r| Some(r.contents.as_str()),
|
|r| Some(r.get_value()),
|
||||||
compare_property_quoted_string
|
compare_property_quoted_string
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -1707,7 +1664,7 @@ fn compare_src_block<'b, 's>(
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":value"),
|
EmacsField::Required(":value"),
|
||||||
|r| Some(r.contents.as_str()),
|
|r| Some(r.get_value()),
|
||||||
compare_property_quoted_string
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -2158,7 +2115,7 @@ fn compare_plain_text<'b, 's>(
|
|||||||
let text = emacs.as_text()?;
|
let text = emacs.as_text()?;
|
||||||
let start_ind: usize = text
|
let start_ind: usize = text
|
||||||
.properties
|
.properties
|
||||||
.get(0)
|
.first()
|
||||||
.expect("Should have start index.")
|
.expect("Should have start index.")
|
||||||
.as_atom()?
|
.as_atom()?
|
||||||
.parse()?;
|
.parse()?;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod compare;
|
mod compare;
|
||||||
mod compare_field;
|
mod compare_field;
|
||||||
mod diff;
|
mod diff;
|
||||||
mod elisp_fact;
|
|
||||||
mod macros;
|
mod macros;
|
||||||
mod parse;
|
|
||||||
mod sexp;
|
|
||||||
mod util;
|
mod util;
|
||||||
pub use compare::run_anonymous_compare;
|
pub use compare::run_anonymous_compare;
|
||||||
pub use compare::run_anonymous_compare_with_settings;
|
pub use compare::run_anonymous_compare_with_settings;
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::compare_field::compare_property_list_of_list_of_list_of_ast_nodes;
|
|
||||||
use super::compare_field::compare_property_list_of_quoted_string;
|
use super::compare_field::compare_property_list_of_quoted_string;
|
||||||
|
use super::compare_field::compare_property_object_tree;
|
||||||
|
use super::compare_field::compare_property_optional_pair;
|
||||||
use super::compare_field::compare_property_quoted_string;
|
use super::compare_field::compare_property_quoted_string;
|
||||||
use super::compare_field::ComparePropertiesResult;
|
use super::compare_field::ComparePropertiesResult;
|
||||||
use super::diff::DiffEntry;
|
use super::diff::DiffEntry;
|
||||||
use super::diff::DiffStatus;
|
use super::diff::DiffStatus;
|
||||||
use super::elisp_fact::GetElispFact;
|
|
||||||
use super::sexp::Token;
|
|
||||||
use crate::compare::diff::compare_ast_node;
|
use crate::compare::diff::compare_ast_node;
|
||||||
use crate::compare::sexp::unquote;
|
|
||||||
use crate::types::AffiliatedKeywordValue;
|
use crate::types::AffiliatedKeywordValue;
|
||||||
use crate::types::AstNode;
|
use crate::types::AstNode;
|
||||||
use crate::types::GetAffiliatedKeywords;
|
use crate::types::GetAffiliatedKeywords;
|
||||||
use crate::types::GetStandardProperties;
|
|
||||||
use crate::types::StandardProperties;
|
use crate::types::StandardProperties;
|
||||||
|
use crate::util::elisp::get_emacs_standard_properties;
|
||||||
|
use crate::util::elisp::unquote;
|
||||||
|
use crate::util::elisp::Token;
|
||||||
|
use crate::util::elisp_fact::GetElispFact;
|
||||||
|
|
||||||
/// Check if the child string slice is a slice of the parent string slice.
|
/// Check if the child string slice is a slice of the parent string slice.
|
||||||
fn is_slice_of(parent: &str, child: &str) -> bool {
|
fn is_slice_of(parent: &str, child: &str) -> bool {
|
||||||
@@ -28,33 +30,30 @@ fn is_slice_of(parent: &str, child: &str) -> bool {
|
|||||||
/// Get the byte offset into source that the rust object exists at.
|
/// Get the byte offset into source that the rust object exists at.
|
||||||
///
|
///
|
||||||
/// These offsets are zero-based unlike the elisp ones.
|
/// These offsets are zero-based unlike the elisp ones.
|
||||||
fn get_rust_byte_offsets<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
fn get_rust_byte_offsets(original_document: &str, subset: &str) -> (usize, usize) {
|
||||||
original_document: &'s str,
|
debug_assert!(is_slice_of(original_document, subset));
|
||||||
rust_ast_node: &'b S,
|
let offset = subset.as_ptr() as usize - original_document.as_ptr() as usize;
|
||||||
) -> (usize, usize) {
|
let end = offset + subset.len();
|
||||||
let rust_object_source = rust_ast_node.get_source();
|
|
||||||
debug_assert!(is_slice_of(original_document, rust_object_source));
|
|
||||||
let offset = rust_object_source.as_ptr() as usize - original_document.as_ptr() as usize;
|
|
||||||
let end = offset + rust_object_source.len();
|
|
||||||
(offset, end)
|
(offset, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_standard_properties<
|
pub(crate) fn compare_standard_properties<
|
||||||
'b,
|
'b,
|
||||||
's,
|
's,
|
||||||
S: GetStandardProperties<'s> + GetElispFact<'s> + ?Sized,
|
S: StandardProperties<'s> + GetElispFact<'s> + ?Sized,
|
||||||
>(
|
>(
|
||||||
original_document: &'s str,
|
original_document: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b S,
|
rust: &'b S,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
assert_name(emacs, rust.get_elisp_fact().get_elisp_name())?;
|
assert_name(emacs, rust.get_elisp_fact().get_elisp_name())?;
|
||||||
assert_bounds(original_document, emacs, rust.get_standard_properties())?;
|
assert_bounds(original_document, emacs, rust)?;
|
||||||
|
assert_post_blank(emacs, rust)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn assert_name<'b, 's, S: AsRef<str>>(
|
fn assert_name<S: AsRef<str>>(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &Token<'_>,
|
||||||
name: S,
|
name: S,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let name = name.as_ref();
|
let name = name.as_ref();
|
||||||
@@ -76,155 +75,118 @@ pub(crate) fn assert_name<'b, 's, S: AsRef<str>>(
|
|||||||
/// Assert that the character ranges defined by upstream org-mode's :standard-properties match the slices in Organic's StandardProperties.
|
/// Assert that the character ranges defined by upstream org-mode's :standard-properties match the slices in Organic's StandardProperties.
|
||||||
///
|
///
|
||||||
/// This does **not** handle plain text because plain text is a special case.
|
/// This does **not** handle plain text because plain text is a special case.
|
||||||
pub(crate) fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
fn assert_bounds<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
||||||
original_document: &'s str,
|
original_document: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b S,
|
rust: &'b S,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let standard_properties = get_emacs_standard_properties(emacs)?; // 1-based
|
let standard_properties = get_emacs_standard_properties(emacs)?; // 1-based
|
||||||
let (begin, end) = (
|
|
||||||
standard_properties
|
// Check begin/end
|
||||||
.begin
|
{
|
||||||
.ok_or("Token should have a begin.")?,
|
let (begin, end) = (
|
||||||
standard_properties.end.ok_or("Token should have an end.")?,
|
standard_properties
|
||||||
);
|
.begin
|
||||||
let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust); // 0-based
|
.ok_or("Token should have a begin.")?,
|
||||||
let rust_begin_char_offset = (&original_document[..rust_begin]).chars().count() + 1; // 1-based
|
standard_properties.end.ok_or("Token should have an end.")?,
|
||||||
let rust_end_char_offset =
|
);
|
||||||
rust_begin_char_offset + (&original_document[rust_begin..rust_end]).chars().count(); // 1-based
|
let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust.get_source()); // 0-based
|
||||||
if rust_begin_char_offset != begin || rust_end_char_offset != end {
|
let rust_begin_char_offset = original_document[..rust_begin].chars().count() + 1; // 1-based
|
||||||
Err(format!("Rust bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?;
|
let rust_end_char_offset =
|
||||||
|
rust_begin_char_offset + original_document[rust_begin..rust_end].chars().count(); // 1-based
|
||||||
|
if rust_begin_char_offset != begin || rust_end_char_offset != end {
|
||||||
|
Err(format!("Rust bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check contents-begin/contents-end
|
||||||
|
{
|
||||||
|
if let Some(rust_contents) = rust.get_contents() {
|
||||||
|
let (begin, end) = (
|
||||||
|
standard_properties
|
||||||
|
.contents_begin
|
||||||
|
.ok_or("Token should have a contents-begin.")?,
|
||||||
|
standard_properties
|
||||||
|
.contents_end
|
||||||
|
.ok_or("Token should have an contents-end.")?,
|
||||||
|
);
|
||||||
|
let (rust_begin, rust_end) = get_rust_byte_offsets(original_document, rust_contents); // 0-based
|
||||||
|
let rust_begin_char_offset = original_document[..rust_begin].chars().count() + 1; // 1-based
|
||||||
|
let rust_end_char_offset =
|
||||||
|
rust_begin_char_offset + original_document[rust_begin..rust_end].chars().count(); // 1-based
|
||||||
|
if rust_begin_char_offset != begin || rust_end_char_offset != end {
|
||||||
|
Err(format!("Rust contents bounds (in chars) ({rust_begin}, {rust_end}) do not match emacs contents bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin_char_offset, rust_end = rust_end_char_offset, emacs_begin=begin, emacs_end=end))?;
|
||||||
|
}
|
||||||
|
} else if standard_properties.contents_begin.is_some()
|
||||||
|
|| standard_properties.contents_end.is_some()
|
||||||
|
{
|
||||||
|
Err(format!("Rust contents is None but emacs contents bounds are ({emacs_begin:?}, {emacs_end:?})", emacs_begin=standard_properties.contents_begin, emacs_end=standard_properties.contents_end))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EmacsStandardProperties {
|
/// Assert that the post blank matches between emacs and organic.
|
||||||
begin: Option<usize>,
|
///
|
||||||
#[allow(dead_code)]
|
/// This does **not** handle plain text because plain text is a special case.
|
||||||
post_affiliated: Option<usize>,
|
fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
||||||
#[allow(dead_code)]
|
|
||||||
contents_begin: Option<usize>,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
contents_end: Option<usize>,
|
|
||||||
end: Option<usize>,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
post_blank: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_emacs_standard_properties<'b, 's>(
|
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
rust: &'b S,
|
||||||
let children = emacs.as_list()?;
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let attributes_child = children
|
let standard_properties = get_emacs_standard_properties(emacs)?; // 1-based
|
||||||
.iter()
|
let rust_post_blank = rust.get_post_blank();
|
||||||
.nth(1)
|
let emacs_post_blank = standard_properties
|
||||||
.ok_or("Should have an attributes child.")?;
|
.post_blank
|
||||||
let attributes_map = attributes_child.as_map()?;
|
.ok_or("Token should have a post-blank.")?;
|
||||||
let standard_properties = attributes_map.get(":standard-properties");
|
if rust_post_blank as usize != emacs_post_blank {
|
||||||
Ok(if standard_properties.is_some() {
|
Err(format!("Rust post-blank {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?;
|
||||||
let mut std_props = standard_properties
|
}
|
||||||
.expect("if statement proves its Some")
|
|
||||||
.as_vector()?
|
|
||||||
.into_iter();
|
|
||||||
let begin = maybe_token_to_usize(std_props.next())?;
|
|
||||||
let post_affiliated = maybe_token_to_usize(std_props.next())?;
|
|
||||||
let contents_begin = maybe_token_to_usize(std_props.next())?;
|
|
||||||
let contents_end = maybe_token_to_usize(std_props.next())?;
|
|
||||||
let end = maybe_token_to_usize(std_props.next())?;
|
|
||||||
let post_blank = maybe_token_to_usize(std_props.next())?;
|
|
||||||
EmacsStandardProperties {
|
|
||||||
begin,
|
|
||||||
post_affiliated,
|
|
||||||
contents_begin,
|
|
||||||
contents_end,
|
|
||||||
end,
|
|
||||||
post_blank,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let begin = maybe_token_to_usize(attributes_map.get(":begin").map(|token| *token))?;
|
|
||||||
let end = maybe_token_to_usize(attributes_map.get(":end").map(|token| *token))?;
|
|
||||||
let contents_begin =
|
|
||||||
maybe_token_to_usize(attributes_map.get(":contents-begin").map(|token| *token))?;
|
|
||||||
let contents_end =
|
|
||||||
maybe_token_to_usize(attributes_map.get(":contents-end").map(|token| *token))?;
|
|
||||||
let post_blank =
|
|
||||||
maybe_token_to_usize(attributes_map.get(":post-blank").map(|token| *token))?;
|
|
||||||
let post_affiliated =
|
|
||||||
maybe_token_to_usize(attributes_map.get(":post-affiliated").map(|token| *token))?;
|
|
||||||
EmacsStandardProperties {
|
|
||||||
begin,
|
|
||||||
post_affiliated,
|
|
||||||
contents_begin,
|
|
||||||
contents_end,
|
|
||||||
end,
|
|
||||||
post_blank,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn maybe_token_to_usize(
|
Ok(())
|
||||||
token: Option<&Token<'_>>,
|
|
||||||
) -> Result<Option<usize>, Box<dyn std::error::Error>> {
|
|
||||||
Ok(token
|
|
||||||
.map(|token| token.as_atom())
|
|
||||||
.map_or(Ok(None), |r| r.map(Some))?
|
|
||||||
.map(|val| {
|
|
||||||
if val == "nil" {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(val.parse::<usize>())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.flatten() // Outer option is whether or not the param exists, inner option is whether or not it is nil
|
|
||||||
.map_or(Ok(None), |r| r.map(Some))?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a named property from the emacs token.
|
/// Get a named property from the emacs token.
|
||||||
///
|
///
|
||||||
/// Returns Ok(None) if value is nil or absent.
|
/// Returns Ok(None) if value is nil or absent.
|
||||||
pub(crate) fn get_property<'b, 's, 'x>(
|
pub(crate) fn get_property<'b, 's>(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
key: &'x str,
|
key: &str,
|
||||||
) -> Result<Option<&'b Token<'s>>, Box<dyn std::error::Error>> {
|
) -> Result<Option<&'b Token<'s>>, Box<dyn std::error::Error>> {
|
||||||
let children = emacs.as_list()?;
|
let children = emacs.as_list()?;
|
||||||
let attributes_child = children
|
let attributes_child = children.get(1).ok_or("Should have an attributes child.")?;
|
||||||
.iter()
|
|
||||||
.nth(1)
|
|
||||||
.ok_or("Should have an attributes child.")?;
|
|
||||||
let attributes_map = attributes_child.as_map()?;
|
let attributes_map = attributes_child.as_map()?;
|
||||||
let prop = attributes_map.get(key).map(|token| *token);
|
let prop = attributes_map.get(key).copied();
|
||||||
match prop.map(|token| token.as_atom()) {
|
if let Some(Ok("nil")) = prop.map(Token::as_atom) {
|
||||||
Some(Ok("nil")) => return Ok(None),
|
return Ok(None);
|
||||||
_ => {}
|
}
|
||||||
};
|
|
||||||
Ok(prop)
|
Ok(prop)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a named property containing an unquoted atom from the emacs token.
|
/// Get a named property containing an unquoted atom from the emacs token.
|
||||||
///
|
///
|
||||||
/// Returns None if key is not found.
|
/// Returns None if key is not found.
|
||||||
pub(crate) fn get_property_unquoted_atom<'b, 's, 'x>(
|
pub(crate) fn get_property_unquoted_atom<'s>(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &Token<'s>,
|
||||||
key: &'x str,
|
key: &str,
|
||||||
) -> Result<Option<&'s str>, Box<dyn std::error::Error>> {
|
) -> Result<Option<&'s str>, Box<dyn std::error::Error>> {
|
||||||
Ok(get_property(emacs, key)?
|
get_property(emacs, key)?
|
||||||
.map(Token::as_atom)
|
.map(Token::as_atom)
|
||||||
.map_or(Ok(None), |r| r.map(Some))?)
|
.map_or(Ok(None), |r| r.map(Some))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a named property containing an quoted string from the emacs token.
|
/// Get a named property containing an quoted string from the emacs token.
|
||||||
///
|
///
|
||||||
/// Returns None if key is not found.
|
/// Returns None if key is not found.
|
||||||
pub(crate) fn get_property_quoted_string<'b, 's, 'x>(
|
pub(crate) fn get_property_quoted_string<'s>(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &Token<'s>,
|
||||||
key: &'x str,
|
key: &str,
|
||||||
) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
) -> Result<Option<Cow<'s, str>>, Box<dyn std::error::Error>> {
|
||||||
Ok(get_property(emacs, key)?
|
get_property(emacs, key)?
|
||||||
.map(Token::as_atom)
|
.map(Token::as_atom)
|
||||||
.map_or(Ok(None), |r| r.map(Some))?
|
.map_or(Ok(None), |r| r.map(Some))?
|
||||||
.map(unquote)
|
.map(unquote)
|
||||||
.map_or(Ok(None), |r| r.map(Some))?)
|
.map_or(Ok(None), |r| r.map(Some))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a named property containing an unquoted numeric value.
|
/// Get a named property containing an unquoted numeric value.
|
||||||
@@ -250,7 +212,7 @@ where
|
|||||||
pub(crate) fn compare_children<'b, 's, 'x, RC>(
|
pub(crate) fn compare_children<'b, 's, 'x, RC>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust_children: &'x Vec<RC>,
|
rust_children: &'x [RC],
|
||||||
child_status: &mut Vec<DiffEntry<'b, 's>>,
|
child_status: &mut Vec<DiffEntry<'b, 's>>,
|
||||||
this_status: &mut DiffStatus,
|
this_status: &mut DiffStatus,
|
||||||
message: &mut Option<String>,
|
message: &mut Option<String>,
|
||||||
@@ -301,8 +263,8 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn assert_no_children<'b, 's>(
|
pub(crate) fn assert_no_children(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &Token<'_>,
|
||||||
this_status: &mut DiffStatus,
|
this_status: &mut DiffStatus,
|
||||||
message: &mut Option<String>,
|
message: &mut Option<String>,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -331,7 +293,7 @@ where
|
|||||||
let rust_key = rust_key.as_ref();
|
let rust_key = rust_key.as_ref();
|
||||||
let rust_value = rust_value.as_ref();
|
let rust_value = rust_value.as_ref();
|
||||||
let emacs_value = get_property_quoted_string(emacs, rust_key)?;
|
let emacs_value = get_property_quoted_string(emacs, rust_key)?;
|
||||||
if Some(rust_value) != emacs_value.as_ref().map(String::as_str) {
|
if Some(rust_value) != emacs_value.as_deref() {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
@@ -376,13 +338,23 @@ where
|
|||||||
)?;
|
)?;
|
||||||
ret.push(diff);
|
ret.push(diff);
|
||||||
}
|
}
|
||||||
AffiliatedKeywordValue::ListOfListsOfObjects(rust_value) => {
|
AffiliatedKeywordValue::OptionalPair { optval, val } => {
|
||||||
let diff = compare_property_list_of_list_of_list_of_ast_nodes(
|
let diff = compare_property_optional_pair(
|
||||||
source,
|
source,
|
||||||
emacs,
|
emacs,
|
||||||
rust,
|
rust,
|
||||||
emacs_property_name.as_str(),
|
emacs_property_name.as_str(),
|
||||||
|_| Some(rust_value),
|
|_| Some((*optval, *val)),
|
||||||
|
)?;
|
||||||
|
ret.push(diff);
|
||||||
|
}
|
||||||
|
AffiliatedKeywordValue::ObjectTree(rust_value) => {
|
||||||
|
let diff = compare_property_object_tree(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
rust,
|
||||||
|
emacs_property_name.as_str(),
|
||||||
|
|_| Some(rust_value.iter()),
|
||||||
)?;
|
)?;
|
||||||
ret.push(diff);
|
ret.push(diff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
use super::global_settings::EntityDefinition;
|
use super::global_settings::EntityDefinition;
|
||||||
|
|
||||||
pub(crate) const DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS: [&'static str; 1] = ["CAPTION"];
|
/// Keywords that contain the standard set of objects (excluding footnote references).
|
||||||
|
///
|
||||||
|
/// Corresponds to org-element-parsed-keywords elisp variable.
|
||||||
|
pub(crate) const ORG_ELEMENT_PARSED_KEYWORDS: [&str; 1] = ["CAPTION"];
|
||||||
|
|
||||||
pub(crate) const DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["CAPTION", "RESULTS"];
|
/// Keywords that can have a secondary value in square brackets.
|
||||||
|
///
|
||||||
|
/// Corresponds to org-element-dual-keywords elisp variable.
|
||||||
|
pub(crate) const ORG_ELEMENT_DUAL_KEYWORDS: [&str; 2] = ["CAPTION", "RESULTS"];
|
||||||
|
|
||||||
pub(crate) const DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
|
/// Keywords that can be affiliated with an element.
|
||||||
|
///
|
||||||
|
/// Corresponds to org-element-affiliated-keywords elisp variable.
|
||||||
|
pub(crate) const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&str; 13] = [
|
||||||
"CAPTION", "DATA", "HEADER", "HEADERS", "LABEL", "NAME", "PLOT", "RESNAME", "RESULT",
|
"CAPTION", "DATA", "HEADER", "HEADERS", "LABEL", "NAME", "PLOT", "RESNAME", "RESULT",
|
||||||
"RESULTS", "SOURCE", "SRCNAME", "TBLNAME",
|
"RESULTS", "SOURCE", "SRCNAME", "TBLNAME",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) const DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&'static str, &'static str); 8] = [
|
/// Mapping of keyword names.
|
||||||
|
///
|
||||||
|
/// Corresponds to org-element-keyword-translation-alist elisp variable.
|
||||||
|
pub(crate) const ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&str, &str); 8] = [
|
||||||
("DATA", "NAME"),
|
("DATA", "NAME"),
|
||||||
("LABEL", "NAME"),
|
("LABEL", "NAME"),
|
||||||
("RESNAME", "NAME"),
|
("RESNAME", "NAME"),
|
||||||
@@ -20,7 +32,7 @@ pub(crate) const DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST: [(&'static str,
|
|||||||
("HEADERS", "HEADER"),
|
("HEADERS", "HEADER"),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) const DEFAULT_ORG_LINK_PARAMETERS: [&'static str; 23] = [
|
pub(crate) const DEFAULT_ORG_LINK_PARAMETERS: [&str; 23] = [
|
||||||
"id",
|
"id",
|
||||||
"eww",
|
"eww",
|
||||||
"rmail",
|
"rmail",
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ use super::list::List;
|
|||||||
use super::DynContextMatcher;
|
use super::DynContextMatcher;
|
||||||
use super::RefContext;
|
use super::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::OrgSource;
|
use crate::parser::OrgSource;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) enum ContextElement<'r, 's> {
|
pub(crate) enum ContextElement<'r, 's> {
|
||||||
/// Stores a parser that indicates that children should exit upon matching an exit matcher.
|
/// Stores a parser that indicates that children should exit upon matching an exit matcher.
|
||||||
ExitMatcherNode(ExitMatcherNode<'r>),
|
ExitMatcherNode(ExitMatcherNode<'r>),
|
||||||
@@ -35,15 +33,6 @@ pub(crate) struct ExitMatcherNode<'r> {
|
|||||||
pub(crate) class: ExitClass,
|
pub(crate) class: ExitClass,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> std::fmt::Debug for ExitMatcherNode<'r> {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let mut formatter = f.debug_struct("ExitMatcherNode");
|
|
||||||
formatter.field("class", &self.class.to_string());
|
|
||||||
formatter.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct Context<'g, 'r, 's> {
|
pub(crate) struct Context<'g, 'r, 's> {
|
||||||
global_settings: &'g GlobalSettings<'g, 's>,
|
global_settings: &'g GlobalSettings<'g, 's>,
|
||||||
tree: List<'r, &'r ContextElement<'r, 's>>,
|
tree: List<'r, &'r ContextElement<'r, 's>>,
|
||||||
@@ -108,27 +97,22 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> {
|
|||||||
pub(crate) fn check_exit_matcher(
|
pub(crate) fn check_exit_matcher(
|
||||||
&'r self,
|
&'r self,
|
||||||
i: OrgSource<'s>,
|
i: OrgSource<'s>,
|
||||||
) -> IResult<OrgSource<'s>, OrgSource<'s>, CustomError<OrgSource<'s>>> {
|
) -> IResult<OrgSource<'s>, OrgSource<'s>, CustomError> {
|
||||||
let mut current_class_filter = ExitClass::Gamma;
|
let mut current_class_filter = ExitClass::Gamma;
|
||||||
for current_node in self.iter_context() {
|
for current_node in self.iter_context() {
|
||||||
let context_element = current_node.get_data();
|
let context_element = current_node.get_data();
|
||||||
match context_element {
|
if let ContextElement::ExitMatcherNode(exit_matcher) = context_element {
|
||||||
ContextElement::ExitMatcherNode(exit_matcher) => {
|
if exit_matcher.class as u32 <= current_class_filter as u32 {
|
||||||
if exit_matcher.class as u32 <= current_class_filter as u32 {
|
current_class_filter = exit_matcher.class;
|
||||||
current_class_filter = exit_matcher.class;
|
let local_result = (exit_matcher.exit_matcher)(¤t_node, i);
|
||||||
let local_result = (exit_matcher.exit_matcher)(¤t_node, i);
|
if local_result.is_ok() {
|
||||||
if local_result.is_ok() {
|
return local_result;
|
||||||
return local_result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
// TODO: Make this a specific error instead of just a generic MyError
|
// TODO: Make this a specific error instead of just a generic MyError
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("NoExit")));
|
||||||
"NoExit".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates if elements should consume the whitespace after them.
|
/// Indicates if elements should consume the whitespace after them.
|
||||||
@@ -140,11 +124,8 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> {
|
|||||||
|
|
||||||
fn _should_consume_trailing_whitespace(&self) -> Option<bool> {
|
fn _should_consume_trailing_whitespace(&self) -> Option<bool> {
|
||||||
for current_node in self.iter() {
|
for current_node in self.iter() {
|
||||||
match current_node {
|
if let ContextElement::ConsumeTrailingWhitespace(should) = current_node {
|
||||||
ContextElement::ConsumeTrailingWhitespace(should) => {
|
return Some(*should);
|
||||||
return Some(*should);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub(crate) enum ExitClass {
|
pub(crate) enum ExitClass {
|
||||||
Document = 1,
|
Document = 1,
|
||||||
Alpha = 2,
|
Alpha = 2,
|
||||||
Beta = 3,
|
Beta = 3,
|
||||||
Gamma = 4,
|
Gamma = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ExitClass {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
write!(f, "{:?}", self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
use std::fmt::Debug;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(any(feature = "compare", feature = "foreign_document_test"))]
|
#[cfg(any(feature = "compare", feature = "foreign_document_test"))]
|
||||||
pub trait FileAccessInterface: Sync + Debug {
|
pub trait FileAccessInterface: Sync {
|
||||||
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "compare", feature = "foreign_document_test")))]
|
#[cfg(not(any(feature = "compare", feature = "foreign_document_test")))]
|
||||||
pub trait FileAccessInterface: Debug {
|
pub trait FileAccessInterface {
|
||||||
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LocalFileAccessInterface {
|
pub struct LocalFileAccessInterface {
|
||||||
pub working_directory: Option<PathBuf>,
|
pub working_directory: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
@@ -20,10 +19,9 @@ impl FileAccessInterface for LocalFileAccessInterface {
|
|||||||
fn read_file(&self, path: &str) -> Result<String, std::io::Error> {
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error> {
|
||||||
let final_path = self
|
let final_path = self
|
||||||
.working_directory
|
.working_directory
|
||||||
.as_ref()
|
.as_deref()
|
||||||
.map(PathBuf::as_path)
|
|
||||||
.map(|pb| pb.join(path))
|
.map(|pb| pb.join(path))
|
||||||
.unwrap_or_else(|| PathBuf::from(path));
|
.unwrap_or_else(|| PathBuf::from(path));
|
||||||
Ok(std::fs::read_to_string(final_path)?)
|
std::fs::read_to_string(final_path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,12 @@ use super::constants::DEFAULT_ORG_ENTITIES;
|
|||||||
use super::constants::DEFAULT_ORG_LINK_PARAMETERS;
|
use super::constants::DEFAULT_ORG_LINK_PARAMETERS;
|
||||||
use super::FileAccessInterface;
|
use super::FileAccessInterface;
|
||||||
use super::LocalFileAccessInterface;
|
use super::LocalFileAccessInterface;
|
||||||
use crate::context::constants::DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS;
|
|
||||||
use crate::context::constants::DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS;
|
|
||||||
use crate::context::constants::DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST;
|
|
||||||
use crate::context::constants::DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS;
|
|
||||||
use crate::types::IndentationLevel;
|
use crate::types::IndentationLevel;
|
||||||
use crate::types::Object;
|
use crate::types::Object;
|
||||||
|
|
||||||
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
|
// TODO: Ultimately, I think we'll need most of this: https://orgmode.org/manual/In_002dbuffer-Settings.html
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GlobalSettings<'g, 's> {
|
pub struct GlobalSettings<'g, 's> {
|
||||||
pub radio_targets: Vec<&'g Vec<Object<'s>>>,
|
pub radio_targets: Vec<&'g Vec<Object<'s>>>,
|
||||||
pub file_access: &'g dyn FileAccessInterface,
|
pub file_access: &'g dyn FileAccessInterface,
|
||||||
@@ -58,26 +54,6 @@ pub struct GlobalSettings<'g, 's> {
|
|||||||
///
|
///
|
||||||
/// Corresponds to org-entities elisp variable.
|
/// Corresponds to org-entities elisp variable.
|
||||||
pub entities: &'g [EntityDefinition<'s>],
|
pub entities: &'g [EntityDefinition<'s>],
|
||||||
|
|
||||||
/// Keywords that contain the standard set of objects (excluding footnote references).
|
|
||||||
///
|
|
||||||
/// Corresponds to org-element-parsed-keywords elisp variable.
|
|
||||||
pub element_parsed_keywords: &'g [&'s str],
|
|
||||||
|
|
||||||
/// Keywords that can have a secondary value in square brackets.
|
|
||||||
///
|
|
||||||
/// Corresponds to org-element-dual-keywords elisp variable.
|
|
||||||
pub element_dual_keywords: &'g [&'s str],
|
|
||||||
|
|
||||||
/// Keywords that can be affiliated with an element.
|
|
||||||
///
|
|
||||||
/// Corresponds to org-element-affiliated-keywords elisp variable.
|
|
||||||
pub element_affiliated_keywords: &'g [&'s str],
|
|
||||||
|
|
||||||
/// Mapping of keyword names.
|
|
||||||
///
|
|
||||||
/// Corresponds to org-element-keyword-translation-alist elisp variable.
|
|
||||||
pub element_keyword_translation_alist: &'g [(&'s str, &'s str)],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
|
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
|
||||||
@@ -95,9 +71,7 @@ pub struct EntityDefinition<'a> {
|
|||||||
|
|
||||||
impl<'g, 's> GlobalSettings<'g, 's> {
|
impl<'g, 's> GlobalSettings<'g, 's> {
|
||||||
fn new() -> GlobalSettings<'g, 's> {
|
fn new() -> GlobalSettings<'g, 's> {
|
||||||
debug_assert!(
|
debug_assert!(DEFAULT_ORG_ENTITIES.is_sorted_by(|a, b| a.name.len() >= b.name.len()));
|
||||||
DEFAULT_ORG_ENTITIES.is_sorted_by(|a, b| b.name.len().partial_cmp(&a.name.len()))
|
|
||||||
);
|
|
||||||
GlobalSettings {
|
GlobalSettings {
|
||||||
radio_targets: Vec::new(),
|
radio_targets: Vec::new(),
|
||||||
file_access: &LocalFileAccessInterface {
|
file_access: &LocalFileAccessInterface {
|
||||||
@@ -112,10 +86,6 @@ impl<'g, 's> GlobalSettings<'g, 's> {
|
|||||||
link_parameters: &DEFAULT_ORG_LINK_PARAMETERS,
|
link_parameters: &DEFAULT_ORG_LINK_PARAMETERS,
|
||||||
link_templates: BTreeMap::new(),
|
link_templates: BTreeMap::new(),
|
||||||
entities: &DEFAULT_ORG_ENTITIES,
|
entities: &DEFAULT_ORG_ENTITIES,
|
||||||
element_parsed_keywords: &DEFAULT_ORG_ELEMENT_PARSED_KEYWORDS,
|
|
||||||
element_dual_keywords: &DEFAULT_ORG_ELEMENT_DUAL_KEYWORDS,
|
|
||||||
element_affiliated_keywords: &DEFAULT_ORG_ELEMENT_AFFILIATED_KEYWORDS,
|
|
||||||
element_keyword_translation_alist: &DEFAULT_ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,14 +96,10 @@ impl<'g, 's> Default for GlobalSettings<'g, 's> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Clone, PartialEq, Default)]
|
||||||
pub enum HeadlineLevelFilter {
|
pub enum HeadlineLevelFilter {
|
||||||
Odd,
|
Odd,
|
||||||
|
|
||||||
|
#[default]
|
||||||
OddEven,
|
OddEven,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HeadlineLevelFilter {
|
|
||||||
fn default() -> Self {
|
|
||||||
HeadlineLevelFilter::OddEven
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
|
|||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let ret = self.next.map(|link| link.get_data());
|
let ret = self.next.map(|link| link.get_data());
|
||||||
self.next = self.next.map(|link| link.get_parent()).flatten();
|
self.next = self.next.and_then(|link| link.get_parent());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ impl<'a, T> Iterator for IterList<'a, T> {
|
|||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let ret = self.next;
|
let ret = self.next;
|
||||||
self.next = self.next.map(|this| this.get_parent()).flatten();
|
self.next = self.next.and_then(|link| link.get_parent());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::OrgSource;
|
use crate::parser::OrgSource;
|
||||||
|
|
||||||
mod constants;
|
pub(crate) mod constants;
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod context;
|
mod context;
|
||||||
mod exiting;
|
mod exiting;
|
||||||
mod file_access_interface;
|
mod file_access_interface;
|
||||||
@@ -30,4 +31,5 @@ pub use global_settings::GlobalSettings;
|
|||||||
pub use global_settings::HeadlineLevelFilter;
|
pub use global_settings::HeadlineLevelFilter;
|
||||||
pub use global_settings::DEFAULT_TAB_WIDTH;
|
pub use global_settings::DEFAULT_TAB_WIDTH;
|
||||||
pub(crate) use list::List;
|
pub(crate) use list::List;
|
||||||
|
pub(crate) use parser_with_context::bind_context;
|
||||||
pub(crate) use parser_with_context::parser_with_context;
|
pub(crate) use parser_with_context::parser_with_context;
|
||||||
|
|||||||
@@ -4,3 +4,10 @@ macro_rules! parser_with_context {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub(crate) use parser_with_context;
|
pub(crate) use parser_with_context;
|
||||||
|
|
||||||
|
macro_rules! bind_context {
|
||||||
|
($target:expr, $context:expr) => {
|
||||||
|
|i| $target($context, i)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub(crate) use bind_context;
|
||||||
|
|||||||
@@ -2,22 +2,18 @@ use nom::error::ErrorKind;
|
|||||||
use nom::error::ParseError;
|
use nom::error::ParseError;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
|
||||||
pub(crate) type Res<T, U> = IResult<T, U, CustomError<T>>;
|
pub(crate) type Res<T, U> = IResult<T, U, CustomError>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CustomError<I> {
|
pub enum CustomError {
|
||||||
MyError(MyError<&'static str>),
|
Static(#[allow(dead_code)] &'static str),
|
||||||
Nom(I, ErrorKind),
|
IO(#[allow(dead_code)] std::io::Error),
|
||||||
IO(std::io::Error),
|
Parser(#[allow(dead_code)] ErrorKind),
|
||||||
BoxedError(Box<dyn std::error::Error>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl<I: std::fmt::Debug> ParseError<I> for CustomError {
|
||||||
pub struct MyError<I>(pub(crate) I);
|
fn from_error_kind(_input: I, kind: ErrorKind) -> Self {
|
||||||
|
CustomError::Parser(kind)
|
||||||
impl<I> ParseError<I> for CustomError<I> {
|
|
||||||
fn from_error_kind(input: I, kind: ErrorKind) -> Self {
|
|
||||||
CustomError::Nom(input, kind)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
||||||
@@ -26,20 +22,14 @@ impl<I> ParseError<I> for CustomError<I> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> From<std::io::Error> for CustomError<I> {
|
impl From<std::io::Error> for CustomError {
|
||||||
fn from(value: std::io::Error) -> Self {
|
fn from(value: std::io::Error) -> Self {
|
||||||
CustomError::IO(value)
|
CustomError::IO(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> From<&'static str> for CustomError<I> {
|
impl From<&'static str> for CustomError {
|
||||||
fn from(value: &'static str) -> Self {
|
fn from(value: &'static str) -> Self {
|
||||||
CustomError::MyError(MyError(value))
|
CustomError::Static(value)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I> From<Box<dyn std::error::Error>> for CustomError<I> {
|
|
||||||
fn from(value: Box<dyn std::error::Error>) -> Self {
|
|
||||||
CustomError::BoxedError(value)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod error;
|
mod error;
|
||||||
pub(crate) use error::CustomError;
|
pub(crate) use error::CustomError;
|
||||||
pub(crate) use error::MyError;
|
|
||||||
pub(crate) use error::Res;
|
pub(crate) use error::Res;
|
||||||
|
|||||||
43
src/event_count/database.rs
Normal file
43
src/event_count/database.rs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use super::EventType;
|
||||||
|
use crate::parser::OrgSource;
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||||
|
struct EventKey {
|
||||||
|
event_type: EventType,
|
||||||
|
byte_offset: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) type EventCount = usize;
|
||||||
|
|
||||||
|
static GLOBAL_DATA: Mutex<Option<HashMap<EventKey, EventCount>>> = Mutex::new(None);
|
||||||
|
|
||||||
|
pub(crate) fn record_event(event_type: EventType, input: OrgSource<'_>) {
|
||||||
|
let mut db = GLOBAL_DATA.lock().unwrap();
|
||||||
|
let db = db.get_or_insert_with(HashMap::new);
|
||||||
|
let key = EventKey {
|
||||||
|
event_type,
|
||||||
|
byte_offset: input.get_byte_offset(),
|
||||||
|
};
|
||||||
|
*db.entry(key).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn report(original_document: &str) {
|
||||||
|
let mut db = GLOBAL_DATA.lock().unwrap();
|
||||||
|
let db = db.get_or_insert_with(HashMap::new);
|
||||||
|
let mut results: Vec<_> = db.iter().collect();
|
||||||
|
results.sort_by_key(|(_k, v)| *v);
|
||||||
|
// This would put the most common at the top, but that is a pain when there is already a lot of output from the parser.
|
||||||
|
// results.sort_by(|(_ak, av), (_bk, bv)| bv.cmp(av));
|
||||||
|
for (key, count) in results {
|
||||||
|
println!(
|
||||||
|
"{:?} {} character offset: {} byte offset: {}",
|
||||||
|
key.event_type,
|
||||||
|
count,
|
||||||
|
original_document[..key.byte_offset].chars().count() + 1,
|
||||||
|
key.byte_offset
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/event_count/event_type.rs
Normal file
4
src/event_count/event_type.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||||
|
pub(crate) enum EventType {
|
||||||
|
ElementStart,
|
||||||
|
}
|
||||||
6
src/event_count/mod.rs
Normal file
6
src/event_count/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
mod database;
|
||||||
|
mod event_type;
|
||||||
|
|
||||||
|
pub(crate) use database::record_event;
|
||||||
|
pub(crate) use database::report;
|
||||||
|
pub(crate) use event_type::EventType;
|
||||||
@@ -5,7 +5,7 @@ use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
|
|||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
const SERVICE_NAME: &'static str = "organic";
|
const SERVICE_NAME: &str = "organic";
|
||||||
|
|
||||||
// Despite the obvious verbosity that fully-qualifying everything causes, in these functions I am fully-qualifying everything relating to tracing. This is because the tracing feature involves multiple libraries working together and so I think it is beneficial to see which libraries contribute which bits.
|
// Despite the obvious verbosity that fully-qualifying everything causes, in these functions I am fully-qualifying everything relating to tracing. This is because the tracing feature involves multiple libraries working together and so I think it is beneficial to see which libraries contribute which bits.
|
||||||
|
|
||||||
|
|||||||
@@ -90,12 +90,11 @@ impl<'r, 's> Iterator for AllAstNodeIter<'r, 's> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, 's> IntoIterator for AstNode<'r, 's> {
|
impl<'r, 's> AstNode<'r, 's> {
|
||||||
type Item = AstNode<'r, 's>;
|
/// Iterate all AST nodes.
|
||||||
|
///
|
||||||
type IntoIter = AllAstNodeIter<'r, 's>;
|
/// This is different from the iter/into_iter functions which iterate a single level of the children. This iterates the entire tree including returning the root node itself.
|
||||||
|
pub fn iter_all_ast_nodes(self) -> AllAstNodeIter<'r, 's> {
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
AllAstNodeIter {
|
AllAstNodeIter {
|
||||||
root: Some(self),
|
root: Some(self),
|
||||||
queue: VecDeque::new(),
|
queue: VecDeque::new(),
|
||||||
|
|||||||
18
src/lib.rs
18
src/lib.rs
@@ -1,14 +1,30 @@
|
|||||||
#![feature(exit_status_error)]
|
#![feature(exit_status_error)]
|
||||||
#![feature(trait_alias)]
|
#![feature(trait_alias)]
|
||||||
#![feature(path_file_prefix)]
|
#![feature(path_file_prefix)]
|
||||||
#![feature(is_sorted)]
|
#![feature(test)]
|
||||||
|
#![feature(iter_intersperse)]
|
||||||
|
#![feature(exact_size_is_empty)]
|
||||||
// TODO: #![warn(missing_docs)]
|
// TODO: #![warn(missing_docs)]
|
||||||
|
#![allow(clippy::bool_assert_comparison)] // Sometimes you want the long form because its easier to see at a glance.
|
||||||
|
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
pub mod compare;
|
pub mod compare;
|
||||||
|
pub mod parse_cli;
|
||||||
|
#[cfg(any(feature = "compare", feature = "wasm", feature = "wasm_test"))]
|
||||||
|
mod util;
|
||||||
|
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
|
||||||
|
mod wasm;
|
||||||
|
#[cfg(any(feature = "wasm", feature = "wasm_test"))]
|
||||||
|
pub mod wasm_cli;
|
||||||
|
#[cfg(feature = "wasm_test")]
|
||||||
|
pub mod wasm_test;
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
mod error;
|
mod error;
|
||||||
|
#[cfg(feature = "event_count")]
|
||||||
|
mod event_count;
|
||||||
mod iter;
|
mod iter;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|||||||
63
src/main.rs
63
src/main.rs
@@ -1,12 +1,4 @@
|
|||||||
#![feature(round_char_boundary)]
|
use organic::parse_cli::main_body;
|
||||||
#![feature(exact_size_is_empty)]
|
|
||||||
use std::io::Read;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use ::organic::parser::parse;
|
|
||||||
use organic::parser::parse_with_settings;
|
|
||||||
use organic::settings::GlobalSettings;
|
|
||||||
use organic::settings::LocalFileAccessInterface;
|
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use crate::init_tracing::init_telemetry;
|
use crate::init_tracing::init_telemetry;
|
||||||
@@ -23,59 +15,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async {
|
rt.block_on(async {
|
||||||
init_telemetry()?;
|
init_telemetry()?;
|
||||||
let main_body_result = main_body();
|
let main_body_result = main_body();
|
||||||
shutdown_telemetry()?;
|
shutdown_telemetry()?;
|
||||||
main_body_result
|
main_body_result
|
||||||
});
|
})
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
||||||
fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let args = std::env::args().skip(1);
|
|
||||||
if args.is_empty() {
|
|
||||||
let org_contents = read_stdin_to_string()?;
|
|
||||||
run_anonymous_parse(org_contents)
|
|
||||||
} else {
|
|
||||||
for arg in args {
|
|
||||||
run_parse_on_file(arg)?
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
let mut stdin_contents = String::new();
|
|
||||||
std::io::stdin()
|
|
||||||
.lock()
|
|
||||||
.read_to_string(&mut stdin_contents)?;
|
|
||||||
Ok(stdin_contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_anonymous_parse<P: AsRef<str>>(org_contents: P) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let rust_parsed = parse(org_contents.as_ref())?;
|
|
||||||
println!("{:#?}", rust_parsed);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_parse_on_file<P: AsRef<Path>>(org_path: P) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let org_path = org_path.as_ref();
|
|
||||||
let parent_directory = org_path
|
|
||||||
.parent()
|
|
||||||
.ok_or("Should be contained inside a directory.")?;
|
|
||||||
let org_contents = std::fs::read_to_string(org_path)?;
|
|
||||||
let org_contents = org_contents.as_str();
|
|
||||||
let file_access_interface = LocalFileAccessInterface {
|
|
||||||
working_directory: Some(parent_directory.to_path_buf()),
|
|
||||||
};
|
|
||||||
let global_settings = {
|
|
||||||
let mut global_settings = GlobalSettings::default();
|
|
||||||
global_settings.file_access = &file_access_interface;
|
|
||||||
global_settings
|
|
||||||
};
|
|
||||||
let rust_parsed = parse_with_settings(org_contents, &global_settings)?;
|
|
||||||
println!("{:#?}", rust_parsed);
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/parse_cli/mod.rs
Normal file
59
src/parse_cli/mod.rs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
use std::io::Read;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use crate::parser::parse;
|
||||||
|
use crate::parser::parse_with_settings;
|
||||||
|
use crate::settings::GlobalSettings;
|
||||||
|
use crate::settings::LocalFileAccessInterface;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
pub fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args = std::env::args().skip(1);
|
||||||
|
if args.is_empty() {
|
||||||
|
let org_contents = read_stdin_to_string()?;
|
||||||
|
run_anonymous_parse(org_contents)
|
||||||
|
} else {
|
||||||
|
for arg in args {
|
||||||
|
run_parse_on_file(arg)?
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
let mut stdin_contents = String::new();
|
||||||
|
std::io::stdin()
|
||||||
|
.lock()
|
||||||
|
.read_to_string(&mut stdin_contents)?;
|
||||||
|
Ok(stdin_contents)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_anonymous_parse<P: AsRef<str>>(org_contents: P) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let org_contents = org_contents.as_ref();
|
||||||
|
let rust_parsed = parse(org_contents)?;
|
||||||
|
println!("{:#?}", rust_parsed);
|
||||||
|
#[cfg(feature = "event_count")]
|
||||||
|
crate::event_count::report(org_contents);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_parse_on_file<P: AsRef<Path>>(org_path: P) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let org_path = org_path.as_ref();
|
||||||
|
let parent_directory = org_path
|
||||||
|
.parent()
|
||||||
|
.ok_or("Should be contained inside a directory.")?;
|
||||||
|
let org_contents = std::fs::read_to_string(org_path)?;
|
||||||
|
let org_contents = org_contents.as_str();
|
||||||
|
let file_access_interface = LocalFileAccessInterface {
|
||||||
|
working_directory: Some(parent_directory.to_path_buf()),
|
||||||
|
};
|
||||||
|
let global_settings = GlobalSettings {
|
||||||
|
file_access: &file_access_interface,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let rust_parsed = parse_with_settings(org_contents, &global_settings)?;
|
||||||
|
println!("{:#?}", rust_parsed);
|
||||||
|
#[cfg(feature = "event_count")]
|
||||||
|
crate::event_count::report(org_contents);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -14,17 +14,46 @@ use nom::multi::many0;
|
|||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
|
use super::keyword::affiliated_keyword;
|
||||||
use super::object_parser::standard_set_object;
|
use super::object_parser::standard_set_object;
|
||||||
use super::util::confine_context;
|
use super::util::confine_context;
|
||||||
use crate::context::parser_with_context;
|
use super::OrgSource;
|
||||||
|
use crate::context::bind_context;
|
||||||
|
use crate::context::constants::ORG_ELEMENT_DUAL_KEYWORDS;
|
||||||
|
use crate::context::constants::ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST;
|
||||||
|
use crate::context::constants::ORG_ELEMENT_PARSED_KEYWORDS;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
|
use crate::error::Res;
|
||||||
use crate::types::AffiliatedKeywordValue;
|
use crate::types::AffiliatedKeywordValue;
|
||||||
use crate::types::AffiliatedKeywords;
|
use crate::types::AffiliatedKeywords;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
pub(crate) fn affiliated_keywords<'s>(
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, Vec<Keyword<'s>>> {
|
||||||
|
let mut ret = Vec::new();
|
||||||
|
let mut remaining = input;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let result = affiliated_keyword(remaining);
|
||||||
|
match result {
|
||||||
|
Ok((remain, kw)) => {
|
||||||
|
remaining = remain;
|
||||||
|
ret.push(kw);
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((remaining, ret))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_affiliated_keywords<'g, 's, AK>(
|
pub(crate) fn parse_affiliated_keywords<'g, 's, AK>(
|
||||||
global_settings: &'g GlobalSettings<'g, 's>,
|
global_settings: &'g GlobalSettings<'g, 's>,
|
||||||
input: AK,
|
input: AK,
|
||||||
@@ -34,86 +63,98 @@ where
|
|||||||
{
|
{
|
||||||
let mut ret = BTreeMap::new();
|
let mut ret = BTreeMap::new();
|
||||||
for kw in input {
|
for kw in input {
|
||||||
let translated_name = translate_name(global_settings, kw.key);
|
let translated_name = translate_name(kw.key);
|
||||||
if is_single_string_keyword(global_settings, translated_name.as_str()) {
|
let keyword_type = identify_keyword_type(translated_name.as_str());
|
||||||
ret.insert(
|
match keyword_type {
|
||||||
translated_name,
|
AffiliatedKeywordType::SingleString => {
|
||||||
AffiliatedKeywordValue::SingleString(kw.value),
|
ret.insert(
|
||||||
);
|
translated_name,
|
||||||
} else if is_list_of_single_string_keyword(global_settings, translated_name.as_str()) {
|
AffiliatedKeywordValue::SingleString(kw.value),
|
||||||
let list_of_strings = ret
|
);
|
||||||
.entry(translated_name)
|
|
||||||
.or_insert_with(|| AffiliatedKeywordValue::ListOfStrings(Vec::with_capacity(1)));
|
|
||||||
match list_of_strings {
|
|
||||||
AffiliatedKeywordValue::ListOfStrings(list_of_strings)
|
|
||||||
if list_of_strings.is_empty() =>
|
|
||||||
{
|
|
||||||
list_of_strings.push(kw.value);
|
|
||||||
}
|
|
||||||
AffiliatedKeywordValue::ListOfStrings(list_of_strings) => {
|
|
||||||
list_of_strings.clear();
|
|
||||||
list_of_strings.push(kw.value);
|
|
||||||
}
|
|
||||||
_ => panic!("Invalid AffiliatedKeywordValue type."),
|
|
||||||
}
|
}
|
||||||
} else if is_list_of_objects_keyword(global_settings, translated_name.as_str()) {
|
AffiliatedKeywordType::ListOfStrings => {
|
||||||
let initial_context = ContextElement::document_context();
|
let list_of_strings = ret.entry(translated_name).or_insert_with(|| {
|
||||||
let initial_context = Context::new(global_settings, List::new(&initial_context));
|
AffiliatedKeywordValue::ListOfStrings(Vec::with_capacity(1))
|
||||||
|
});
|
||||||
let (_remaining, optional_objects) = opt(all_consuming(map(
|
match list_of_strings {
|
||||||
tuple((
|
AffiliatedKeywordValue::ListOfStrings(list_of_strings) => {
|
||||||
take_until("["),
|
list_of_strings.push(kw.value);
|
||||||
tag("["),
|
}
|
||||||
map_parser(
|
_ => panic!("Invalid AffiliatedKeywordValue type."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AffiliatedKeywordType::OptionalPair => {
|
||||||
|
let (_remaining, optional_string) = opt(all_consuming(map(
|
||||||
|
tuple((
|
||||||
|
take_until::<_, &str, nom::error::Error<_>>("["),
|
||||||
|
tag("["),
|
||||||
recognize(many_till(anychar, peek(tuple((tag("]"), eof))))),
|
recognize(many_till(anychar, peek(tuple((tag("]"), eof))))),
|
||||||
confine_context(|i| {
|
tag("]"),
|
||||||
all_consuming(many0(parser_with_context!(standard_set_object)(
|
eof,
|
||||||
&initial_context,
|
)),
|
||||||
)))(i)
|
|(_, _, objects, _, _)| objects,
|
||||||
}),
|
)))(kw.key)
|
||||||
),
|
.expect("Parser should always succeed.");
|
||||||
tag("]"),
|
ret.insert(
|
||||||
eof,
|
translated_name,
|
||||||
)),
|
AffiliatedKeywordValue::OptionalPair {
|
||||||
|(_, _, objects, _, _)| objects,
|
optval: optional_string,
|
||||||
)))(kw.key.into())
|
val: kw.value,
|
||||||
.expect("Object parser should always succeed.");
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
AffiliatedKeywordType::ObjectTree => {
|
||||||
|
let initial_context = ContextElement::document_context();
|
||||||
|
let initial_context = Context::new(global_settings, List::new(&initial_context));
|
||||||
|
|
||||||
// TODO: This should be omitting footnote references
|
let (_remaining, optional_objects) = opt(all_consuming(map(
|
||||||
let (_remaining, objects) = all_consuming(many0(parser_with_context!(
|
tuple((
|
||||||
standard_set_object
|
take_until("["),
|
||||||
)(&initial_context)))(kw.value.into())
|
tag("["),
|
||||||
.expect("Object parser should always succeed.");
|
map_parser(
|
||||||
let list_of_lists = ret.entry(translated_name).or_insert_with(|| {
|
recognize(many_till(anychar, peek(tuple((tag("]"), eof))))),
|
||||||
AffiliatedKeywordValue::ListOfListsOfObjects(Vec::with_capacity(1))
|
confine_context(|i| {
|
||||||
});
|
all_consuming(many0(bind_context!(
|
||||||
match list_of_lists {
|
standard_set_object,
|
||||||
AffiliatedKeywordValue::ListOfListsOfObjects(list_of_lists) => {
|
&initial_context
|
||||||
list_of_lists.push((optional_objects, objects));
|
)))(i)
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
tag("]"),
|
||||||
|
eof,
|
||||||
|
)),
|
||||||
|
|(_, _, objects, _, _)| objects,
|
||||||
|
)))(kw.key.into())
|
||||||
|
.expect("Object parser should always succeed.");
|
||||||
|
|
||||||
|
// TODO: This should be omitting footnote references
|
||||||
|
let (_remaining, objects) = all_consuming(many0(bind_context!(
|
||||||
|
standard_set_object,
|
||||||
|
&initial_context
|
||||||
|
)))(kw.value.into())
|
||||||
|
.expect("Object parser should always succeed.");
|
||||||
|
|
||||||
|
let entry_per_keyword_list = ret
|
||||||
|
.entry(translated_name)
|
||||||
|
.or_insert_with(|| AffiliatedKeywordValue::ObjectTree(Vec::with_capacity(1)));
|
||||||
|
match entry_per_keyword_list {
|
||||||
|
AffiliatedKeywordValue::ObjectTree(entry_per_keyword_list) => {
|
||||||
|
entry_per_keyword_list.push((optional_objects, objects));
|
||||||
|
}
|
||||||
|
_ => panic!("Invalid AffiliatedKeywordValue type."),
|
||||||
}
|
}
|
||||||
_ => panic!("Invalid AffiliatedKeywordValue type."),
|
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
let list_of_strings = ret
|
|
||||||
.entry(translated_name)
|
|
||||||
.or_insert_with(|| AffiliatedKeywordValue::ListOfStrings(Vec::with_capacity(1)));
|
|
||||||
match list_of_strings {
|
|
||||||
AffiliatedKeywordValue::ListOfStrings(list_of_strings) => {
|
|
||||||
list_of_strings.push(kw.value);
|
|
||||||
}
|
|
||||||
_ => panic!("Invalid AffiliatedKeywordValue type."),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AffiliatedKeywords { keywords: ret }
|
AffiliatedKeywords { keywords: ret }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> String {
|
fn translate_name(name: &str) -> String {
|
||||||
let name_until_optval = name
|
let name_until_optval = name
|
||||||
.split_once("[")
|
.split_once('[')
|
||||||
.map(|(before, _after)| before)
|
.map(|(before, _after)| before)
|
||||||
.unwrap_or(name);
|
.unwrap_or(name);
|
||||||
for (src, dst) in global_settings.element_keyword_translation_alist {
|
for (src, dst) in ORG_ELEMENT_KEYWORD_TRANSLATION_ALIST {
|
||||||
if name_until_optval.eq_ignore_ascii_case(src) {
|
if name_until_optval.eq_ignore_ascii_case(src) {
|
||||||
return dst.to_lowercase();
|
return dst.to_lowercase();
|
||||||
}
|
}
|
||||||
@@ -121,40 +162,32 @@ fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s
|
|||||||
name_until_optval.to_lowercase()
|
name_until_optval.to_lowercase()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_single_string_keyword<'g, 's>(
|
enum AffiliatedKeywordType {
|
||||||
_global_settings: &'g GlobalSettings<'g, 's>,
|
SingleString,
|
||||||
name: &'s str,
|
ListOfStrings,
|
||||||
) -> bool {
|
OptionalPair,
|
||||||
// TODO: Is this defined by an elisp variable?
|
ObjectTree,
|
||||||
for single_string_name in ["plot", "name"] {
|
|
||||||
if name.eq_ignore_ascii_case(single_string_name) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_list_of_single_string_keyword<'g, 's>(
|
fn identify_keyword_type(name: &str) -> AffiliatedKeywordType {
|
||||||
_global_settings: &'g GlobalSettings<'g, 's>,
|
let is_multiple = ["CAPTION", "HEADER"]
|
||||||
name: &'s str,
|
.into_iter()
|
||||||
) -> bool {
|
.any(|candidate| name.eq_ignore_ascii_case(candidate))
|
||||||
// TODO: Is this defined by an elisp variable?
|
|| name.to_lowercase().starts_with("attr_");
|
||||||
for single_string_name in ["results"] {
|
let is_parsed = ORG_ELEMENT_PARSED_KEYWORDS
|
||||||
if name.eq_ignore_ascii_case(single_string_name) {
|
.iter()
|
||||||
return true;
|
.any(|candidate| name.eq_ignore_ascii_case(candidate));
|
||||||
}
|
let can_have_optval = ORG_ELEMENT_DUAL_KEYWORDS
|
||||||
|
.iter()
|
||||||
|
.any(|candidate| name.eq_ignore_ascii_case(candidate));
|
||||||
|
match (is_multiple, is_parsed, can_have_optval) {
|
||||||
|
(true, true, true) => AffiliatedKeywordType::ObjectTree,
|
||||||
|
(true, true, false) => unreachable!("Nothing like this exists in upstream org-mode."),
|
||||||
|
(true, false, true) => unreachable!("Nothing like this exists in upstream org-mode."),
|
||||||
|
(true, false, false) => AffiliatedKeywordType::ListOfStrings,
|
||||||
|
(false, true, true) => unreachable!("Nothing like this exists in upstream org-mode."),
|
||||||
|
(false, true, false) => unreachable!("Nothing like this exists in upstream org-mode."),
|
||||||
|
(false, false, true) => AffiliatedKeywordType::OptionalPair,
|
||||||
|
(false, false, false) => AffiliatedKeywordType::SingleString,
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_list_of_objects_keyword<'g, 's>(
|
|
||||||
global_settings: &'g GlobalSettings<'g, 's>,
|
|
||||||
name: &'s str,
|
|
||||||
) -> bool {
|
|
||||||
for parsed_keyword in global_settings.element_parsed_keywords {
|
|
||||||
if name.eq_ignore_ascii_case(parsed_keyword) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ pub(crate) fn angle_link<'b, 'g, 'r, 's>(
|
|||||||
parser_with_context!(parse_angle_link)(context),
|
parser_with_context!(parse_angle_link)(context),
|
||||||
))(remaining)?;
|
))(remaining)?;
|
||||||
let (remaining, _) = tag(">")(remaining)?;
|
let (remaining, _) = tag(">")(remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -59,6 +59,7 @@ pub(crate) fn angle_link<'b, 'g, 'r, 's>(
|
|||||||
raw_link: raw_link.into(),
|
raw_link: raw_link.into(),
|
||||||
search_option: parsed_link.search_option,
|
search_option: parsed_link.search_option,
|
||||||
application: parsed_link.application,
|
application: parsed_link.application,
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use nom::bytes::complete::tag_no_case;
|
|||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::combinator::consumed;
|
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
@@ -21,7 +20,6 @@ use super::OrgSource;
|
|||||||
use crate::context::Matcher;
|
use crate::context::Matcher;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::org_line_ending;
|
use crate::parser::util::org_line_ending;
|
||||||
@@ -44,33 +42,10 @@ where
|
|||||||
start_of_line(remaining)?;
|
start_of_line(remaining)?;
|
||||||
let (remaining, _) = tuple((space0, tag("#+"), tag_no_case("call"), tag(":")))(remaining)?;
|
let (remaining, _) = tuple((space0, tag("#+"), tag_no_case("call"), tag(":")))(remaining)?;
|
||||||
|
|
||||||
if let Ok((remaining, (_, line_break))) = tuple((space0, org_line_ending))(remaining) {
|
|
||||||
let (remaining, _trailing_ws) =
|
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
|
||||||
let source = get_consumed(input, remaining);
|
|
||||||
return Ok((
|
|
||||||
remaining,
|
|
||||||
BabelCall {
|
|
||||||
source: Into::<&str>::into(source),
|
|
||||||
affiliated_keywords: parse_affiliated_keywords(
|
|
||||||
context.get_global_settings(),
|
|
||||||
affiliated_keywords,
|
|
||||||
),
|
|
||||||
value: Into::<&str>::into(line_break.take(0)),
|
|
||||||
call: None,
|
|
||||||
inside_header: None,
|
|
||||||
arguments: None,
|
|
||||||
end_header: None,
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (remaining, _ws) = space0(remaining)?;
|
let (remaining, _ws) = space0(remaining)?;
|
||||||
let (remaining, (value, (call, inside_header, arguments, end_header))) =
|
let (remaining, babel_call_value) = babel_call_value(remaining)?;
|
||||||
consumed(babel_call_value)(remaining)?;
|
|
||||||
let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?;
|
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
@@ -82,46 +57,87 @@ where
|
|||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
value: Into::<&str>::into(value).trim_end(),
|
value: Into::<&str>::into(babel_call_value.value),
|
||||||
call: call.map(Into::<&str>::into),
|
call: babel_call_value.call.map(Into::<&str>::into),
|
||||||
inside_header: inside_header.map(Into::<&str>::into),
|
inside_header: babel_call_value.inside_header.map(Into::<&str>::into),
|
||||||
arguments: arguments.map(Into::<&str>::into),
|
arguments: babel_call_value.arguments.map(Into::<&str>::into),
|
||||||
end_header: end_header.map(Into::<&str>::into),
|
end_header: babel_call_value.end_header.map(Into::<&str>::into),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct BabelCallValue<'s> {
|
||||||
|
/// The entire string to the right of "#+call: " without the trailing line break.
|
||||||
|
value: OrgSource<'s>,
|
||||||
|
|
||||||
|
/// The function name which may contain a line break if there are no headers/arguments.
|
||||||
|
call: Option<OrgSource<'s>>,
|
||||||
|
inside_header: Option<OrgSource<'s>>,
|
||||||
|
arguments: Option<OrgSource<'s>>,
|
||||||
|
end_header: Option<OrgSource<'s>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
fn babel_call_value<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, BabelCallValue<'s>> {
|
||||||
|
alt((
|
||||||
|
babel_call_value_without_headers,
|
||||||
|
babel_call_value_with_headers,
|
||||||
|
))(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
fn babel_call_value_without_headers<'s>(
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, BabelCallValue<'s>> {
|
||||||
|
let (remaining, value) = babel_call_call_with_headers(input)?;
|
||||||
|
let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
|
let call = get_consumed(input, remaining);
|
||||||
|
Ok((
|
||||||
|
remaining,
|
||||||
|
BabelCallValue {
|
||||||
|
value,
|
||||||
|
call: Some(call),
|
||||||
|
inside_header: None,
|
||||||
|
arguments: None,
|
||||||
|
end_header: None,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn babel_call_value<'s>(
|
fn babel_call_value_with_headers<'s>(
|
||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<
|
) -> Res<OrgSource<'s>, BabelCallValue<'s>> {
|
||||||
OrgSource<'s>,
|
let (remaining, call) = opt(babel_call_call_with_headers)(input)?;
|
||||||
(
|
|
||||||
Option<OrgSource<'s>>,
|
|
||||||
Option<OrgSource<'s>>,
|
|
||||||
Option<OrgSource<'s>>,
|
|
||||||
Option<OrgSource<'s>>,
|
|
||||||
),
|
|
||||||
> {
|
|
||||||
let (remaining, call) = opt(babel_call_call)(input)?;
|
|
||||||
let (remaining, inside_header) = opt(inside_header)(remaining)?;
|
let (remaining, inside_header) = opt(inside_header)(remaining)?;
|
||||||
let (remaining, arguments) = opt(arguments)(remaining)?;
|
let (remaining, arguments) = opt(arguments)(remaining)?;
|
||||||
let (remaining, end_header) = opt(end_header)(remaining)?;
|
let (remaining, end_header) = opt(end_header)(remaining)?;
|
||||||
|
let value = get_consumed(input, remaining);
|
||||||
|
let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
(call, inside_header, arguments.flatten(), end_header),
|
BabelCallValue {
|
||||||
|
value,
|
||||||
|
call,
|
||||||
|
inside_header,
|
||||||
|
arguments: arguments.flatten(),
|
||||||
|
end_header,
|
||||||
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn babel_call_call<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn babel_call_call_with_headers<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
|
// When babel call contains no arguments or headers (for example: "#+call: lorem ipsum\n") then the trailing line break is part of the call. Otherwise, it is not.
|
||||||
verify(
|
verify(
|
||||||
recognize(many_till(
|
recognize(many_till(
|
||||||
anychar,
|
anychar,
|
||||||
alt((
|
peek(alt((
|
||||||
peek(recognize(one_of("[("))),
|
recognize(one_of("[(")),
|
||||||
recognize(tuple((space0, org_line_ending))),
|
recognize(tuple((space0, org_line_ending))),
|
||||||
)),
|
))),
|
||||||
)),
|
)),
|
||||||
|s| s.len() > 0,
|
|s| s.len() > 0,
|
||||||
)(input)
|
)(input)
|
||||||
@@ -215,9 +231,7 @@ fn impl_balanced_bracket<
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fail_parser(remaining).is_ok() {
|
if fail_parser(remaining).is_ok() {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("Fail parser matched.")));
|
||||||
"Fail parser matched.",
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (remain, _) = anychar(remaining)?;
|
let (remain, _) = anychar(remaining)?;
|
||||||
@@ -226,26 +240,10 @@ fn impl_balanced_bracket<
|
|||||||
let contents_end = remaining;
|
let contents_end = remaining;
|
||||||
|
|
||||||
let (remaining, _) = end_parser(remaining)?;
|
let (remaining, _) = end_parser(remaining)?;
|
||||||
let contents = if contents_start != contents_end {
|
let contents = if Into::<&str>::into(contents_start) != Into::<&str>::into(contents_end) {
|
||||||
Some(contents_start.get_until(contents_end))
|
Some(contents_start.get_until(contents_end))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Ok((remaining, contents))
|
Ok((remaining, contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use nom::combinator::opt;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn simple_call() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let input = OrgSource::new("()");
|
|
||||||
let (remaining, call) = opt(babel_call_call)(input)?;
|
|
||||||
assert_eq!(Into::<&str>::into(remaining), "()");
|
|
||||||
assert_eq!(call, None);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
167
src/parser/bullshitium.rs
Normal file
167
src/parser/bullshitium.rs
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
use nom::branch::alt;
|
||||||
|
use nom::bytes::complete::tag_no_case;
|
||||||
|
use nom::character::complete::anychar;
|
||||||
|
use nom::character::complete::space0;
|
||||||
|
use nom::multi::many_till;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
|
use super::paragraph::paragraph;
|
||||||
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
use super::util::org_line_ending;
|
||||||
|
use super::util::start_of_line;
|
||||||
|
use super::OrgSource;
|
||||||
|
use crate::context::bind_context;
|
||||||
|
use crate::context::RefContext;
|
||||||
|
use crate::error::CustomError;
|
||||||
|
use crate::error::Res;
|
||||||
|
use crate::parser::macros::element;
|
||||||
|
use crate::types::Object;
|
||||||
|
use crate::types::Paragraph;
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn bullshitium<'b, 'g, 'r, 's>(
|
||||||
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, Paragraph<'s>> {
|
||||||
|
alt((
|
||||||
|
bind_context!(broken_end, context),
|
||||||
|
bind_context!(broken_dynamic_block, context),
|
||||||
|
))(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn detect_bullshitium<'b, 'g, 'r, 's>(
|
||||||
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()> {
|
||||||
|
element!(detect_broken_end, context, input);
|
||||||
|
element!(detect_broken_dynamic_block, context, input);
|
||||||
|
Err(nom::Err::Error(CustomError::Static("No bullshitium.")))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn broken_end<'b, 'g, 'r, 's>(
|
||||||
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, Paragraph<'s>> {
|
||||||
|
start_of_line(input)?;
|
||||||
|
let (remaining, _) = space0(input)?;
|
||||||
|
let (remaining, _) = tag_no_case(":end:")(remaining)?;
|
||||||
|
let (lead_in_remaining, _) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
|
if let Ok((remaining, mut paragraph)) =
|
||||||
|
paragraph(std::iter::empty(), lead_in_remaining, context, input)
|
||||||
|
{
|
||||||
|
match paragraph.children.first_mut() {
|
||||||
|
Some(Object::PlainText(plain_text)) => {
|
||||||
|
plain_text.source = input.get_until_end_of_str(plain_text.source).into();
|
||||||
|
paragraph.contents = Some(input.get_until_end_of_str(plain_text.source).into());
|
||||||
|
}
|
||||||
|
Some(obj) => {
|
||||||
|
panic!("Unhandled first object type inside bullshitium {:?}", obj);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
unreachable!("Paragraph must have children.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok((remaining, paragraph))
|
||||||
|
} else {
|
||||||
|
let (remaining, post_blank) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
|
||||||
|
|
||||||
|
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
remaining,
|
||||||
|
Paragraph::of_text(
|
||||||
|
input.get_until(remaining).into(),
|
||||||
|
body,
|
||||||
|
if !body.is_empty() { Some(body) } else { None },
|
||||||
|
post_blank.map(Into::<&str>::into),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(_context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn detect_broken_end<'b, 'g, 'r, 's>(
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()> {
|
||||||
|
start_of_line(input)?;
|
||||||
|
let (remaining, _) = space0(input)?;
|
||||||
|
let (remaining, _) = tag_no_case(":end:")(remaining)?;
|
||||||
|
let (_remaining, _) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
|
Ok((input, ()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||||
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, Paragraph<'s>> {
|
||||||
|
start_of_line(input)?;
|
||||||
|
let (remaining, _) = space0(input)?;
|
||||||
|
let (remaining, _) = tag_no_case("#+BEGIN:")(remaining)?;
|
||||||
|
let (lead_in_remaining, _) = many_till(anychar, org_line_ending)(remaining)?;
|
||||||
|
if let Ok((remaining, mut paragraph)) =
|
||||||
|
paragraph(std::iter::empty(), lead_in_remaining, context, input)
|
||||||
|
{
|
||||||
|
match paragraph.children.first_mut() {
|
||||||
|
Some(Object::PlainText(plain_text)) => {
|
||||||
|
plain_text.source = input.get_until_end_of_str(plain_text.source).into();
|
||||||
|
paragraph.contents = Some(input.get_until_end_of_str(plain_text.source).into());
|
||||||
|
}
|
||||||
|
Some(obj) => {
|
||||||
|
panic!("Unhandled first object type inside bullshitium {:?}", obj);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
unreachable!("Paragraph must have children.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok((remaining, paragraph))
|
||||||
|
} else {
|
||||||
|
let (remaining, post_blank) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, lead_in_remaining)?;
|
||||||
|
|
||||||
|
let body = Into::<&str>::into(input.get_until(lead_in_remaining));
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
remaining,
|
||||||
|
Paragraph::of_text(
|
||||||
|
input.get_until(remaining).into(),
|
||||||
|
body,
|
||||||
|
if !body.is_empty() { Some(body) } else { None },
|
||||||
|
post_blank.map(Into::<&str>::into),
|
||||||
|
),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(_context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn detect_broken_dynamic_block<'b, 'g, 'r, 's>(
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()> {
|
||||||
|
start_of_line(input)?;
|
||||||
|
let (remaining, _) = space0(input)?;
|
||||||
|
let (_remaining, _) = tag_no_case("#+BEGIN:")(remaining)?;
|
||||||
|
Ok((input, ()))
|
||||||
|
}
|
||||||
@@ -46,16 +46,22 @@ pub(crate) fn citation<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, prefix) =
|
let (remaining, prefix) =
|
||||||
must_balance_bracket(opt(parser_with_context!(global_prefix)(context)))(remaining)?;
|
must_balance_bracket(opt(parser_with_context!(global_prefix)(context)))(remaining)?;
|
||||||
|
|
||||||
|
let contents_begin = remaining;
|
||||||
let (remaining, references) =
|
let (remaining, references) =
|
||||||
separated_list1(tag(";"), parser_with_context!(citation_reference)(context))(remaining)?;
|
separated_list1(tag(";"), parser_with_context!(citation_reference)(context))(remaining)?;
|
||||||
|
let contents_end = {
|
||||||
|
let (rem, _) = opt(tag(";"))(remaining)?;
|
||||||
|
rem
|
||||||
|
};
|
||||||
let (remaining, suffix) = must_balance_bracket(opt(map(
|
let (remaining, suffix) = must_balance_bracket(opt(map(
|
||||||
tuple((tag(";"), parser_with_context!(global_suffix)(context))),
|
tuple((tag(";"), parser_with_context!(global_suffix)(context))),
|
||||||
|(_, suffix)| suffix,
|
|(_, suffix)| suffix,
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
let (remaining, _) = tag("]")(remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
let contents = contents_begin.get_until(contents_end);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Citation {
|
Citation {
|
||||||
@@ -64,6 +70,8 @@ pub(crate) fn citation<'b, 'g, 'r, 's>(
|
|||||||
prefix: prefix.unwrap_or(Vec::new()),
|
prefix: prefix.unwrap_or(Vec::new()),
|
||||||
suffix: suffix.unwrap_or(Vec::new()),
|
suffix: suffix.unwrap_or(Vec::new()),
|
||||||
children: references,
|
children: references,
|
||||||
|
contents: Into::<&str>::into(contents),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -137,7 +145,7 @@ fn _global_prefix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation global prefix bracket depth.")
|
unreachable!("Exceeded citation global prefix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@@ -191,7 +199,7 @@ fn _global_suffix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation global suffix bracket depth.")
|
unreachable!("Exceeded citation global suffix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@@ -205,49 +213,54 @@ fn _global_suffix_end<'b, 'g, 'r, 's>(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
use crate::parser::element_parser::element;
|
use crate::parser::element_parser::element;
|
||||||
use crate::types::CitationReference;
|
|
||||||
use crate::types::Element;
|
use crate::types::Element;
|
||||||
use crate::types::GetStandardProperties;
|
use crate::types::StandardProperties;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn citation_simple() {
|
fn citation_simple() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let input = OrgSource::new("[cite:@foo]");
|
let input = OrgSource::new("[cite:@foo]");
|
||||||
let global_settings = GlobalSettings::default();
|
let global_settings = GlobalSettings::default();
|
||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||||
let paragraph_matcher = parser_with_context!(element(true))(&initial_context);
|
let paragraph_matcher = bind_context!(element(true), &initial_context);
|
||||||
let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph");
|
let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph");
|
||||||
let first_paragraph = match first_paragraph {
|
let first_paragraph = match first_paragraph {
|
||||||
Element::Paragraph(paragraph) => paragraph,
|
Element::Paragraph(paragraph) => paragraph,
|
||||||
_ => panic!("Should be a paragraph!"),
|
_ => panic!("Should be a paragraph!"),
|
||||||
};
|
};
|
||||||
assert_eq!(Into::<&str>::into(remaining), "");
|
assert_eq!(Into::<&str>::into(remaining), "");
|
||||||
assert_eq!(
|
assert_eq!(first_paragraph.get_source(), "[cite:@foo]");
|
||||||
first_paragraph.get_standard_properties().get_source(),
|
|
||||||
"[cite:@foo]"
|
|
||||||
);
|
|
||||||
assert_eq!(first_paragraph.children.len(), 1);
|
assert_eq!(first_paragraph.children.len(), 1);
|
||||||
assert_eq!(
|
|
||||||
first_paragraph
|
match first_paragraph
|
||||||
.children
|
.children
|
||||||
.get(0)
|
.first()
|
||||||
.expect("Len already asserted to be 1"),
|
.expect("Len already asserted to be 1.")
|
||||||
&Object::Citation(Citation {
|
{
|
||||||
source: "[cite:@foo]",
|
Object::Citation(inner) => {
|
||||||
style: None,
|
assert_eq!(inner.get_source(), "[cite:@foo]");
|
||||||
prefix: vec![],
|
assert_eq!(inner.children.len(), 1);
|
||||||
suffix: vec![],
|
assert!(inner.prefix.is_empty());
|
||||||
children: vec![CitationReference {
|
assert!(inner.suffix.is_empty());
|
||||||
source: "@foo",
|
assert!(inner.style.is_none());
|
||||||
key: "foo",
|
let citation_reference = inner
|
||||||
prefix: vec![],
|
.children
|
||||||
suffix: vec![]
|
.first()
|
||||||
}]
|
.expect("Len already asserted to be 1.");
|
||||||
})
|
assert_eq!(citation_reference.get_source(), "@foo");
|
||||||
);
|
assert_eq!(citation_reference.key, "foo");
|
||||||
|
assert!(citation_reference.prefix.is_empty());
|
||||||
|
assert!(citation_reference.suffix.is_empty());
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err("Child should be a citation.".into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ use crate::context::ExitClass;
|
|||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::object_parser::minimal_set_object;
|
use crate::parser::object_parser::minimal_set_object;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
@@ -151,7 +150,7 @@ fn _key_prefix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation key prefix bracket depth.")
|
unreachable!("Exceeded citation key prefix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@@ -181,7 +180,7 @@ fn _key_suffix_end<'b, 'g, 'r, 's>(
|
|||||||
unreachable!("Exceeded citation key suffix bracket depth.")
|
unreachable!("Exceeded citation key suffix bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<&str, OrgSource<'_>, CustomError<OrgSource<'_>>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@@ -199,9 +198,7 @@ where
|
|||||||
let pre_bracket_depth = input.get_bracket_depth();
|
let pre_bracket_depth = input.get_bracket_depth();
|
||||||
let (remaining, output) = inner(input)?;
|
let (remaining, output) = inner(input)?;
|
||||||
if remaining.get_bracket_depth() - pre_bracket_depth != 0 {
|
if remaining.get_bracket_depth() - pre_bracket_depth != 0 {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("UnbalancedBrackets")));
|
||||||
"UnbalancedBrackets".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
Ok((remaining, output))
|
Ok((remaining, output))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ pub(crate) fn clock<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, (timestamp, duration)) = clock_timestamp(context, remaining)?;
|
let (remaining, (timestamp, duration)) = clock_timestamp(context, remaining)?;
|
||||||
let (remaining, _) = tuple((space0, org_line_ending))(remaining)?;
|
let (remaining, _) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -54,6 +54,7 @@ pub(crate) fn clock<'b, 'g, 'r, 's>(
|
|||||||
} else {
|
} else {
|
||||||
ClockStatus::Running
|
ClockStatus::Running
|
||||||
},
|
},
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -81,7 +82,7 @@ fn clock_timestamp<'b, 'g, 'r, 's>(
|
|||||||
|(timestamp, duration)| (timestamp, duration.map(Into::<&str>::into)),
|
|(timestamp, duration)| (timestamp, duration.map(Into::<&str>::into)),
|
||||||
),
|
),
|
||||||
map(
|
map(
|
||||||
parser_with_context!(inactive_timestamp)(context),
|
parser_with_context!(inactive_timestamp(true))(context),
|
||||||
|timestamp| (timestamp, None),
|
|timestamp| (timestamp, None),
|
||||||
),
|
),
|
||||||
))(input)
|
))(input)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use crate::context::parser_with_context;
|
|||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::immediate_in_section;
|
use crate::parser::util::immediate_in_section;
|
||||||
@@ -35,9 +34,9 @@ pub(crate) fn comment<'b, 'g, 'r, 's>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, Comment<'s>> {
|
) -> Res<OrgSource<'s>, Comment<'s>> {
|
||||||
if immediate_in_section(context, "comment") {
|
if immediate_in_section(context, "comment") {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element".into(),
|
"Cannot nest objects of the same element",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
let parser_context = ContextElement::Context("comment");
|
let parser_context = ContextElement::Context("comment");
|
||||||
let parser_context = context.with_additional_node(&parser_context);
|
let parser_context = context.with_additional_node(&parser_context);
|
||||||
@@ -47,7 +46,7 @@ pub(crate) fn comment<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, mut remaining_lines) =
|
let (remaining, mut remaining_lines) =
|
||||||
many0(preceded(not(exit_matcher), comment_line_matcher))(remaining)?;
|
many0(preceded(not(exit_matcher), comment_line_matcher))(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
||||||
@@ -68,6 +67,7 @@ pub(crate) fn comment<'b, 'g, 'r, 's>(
|
|||||||
Comment {
|
Comment {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
value,
|
value,
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -104,8 +104,8 @@ pub(crate) fn detect_comment<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()>
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::context::ContextElement;
|
|
||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ mod tests {
|
|||||||
let global_settings = GlobalSettings::default();
|
let global_settings = GlobalSettings::default();
|
||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||||
let comment_matcher = parser_with_context!(comment)(&initial_context);
|
let comment_matcher = bind_context!(comment, &initial_context);
|
||||||
let (remaining, first_comment) = comment_matcher(input).expect("Parse first comment");
|
let (remaining, first_comment) = comment_matcher(input).expect("Parse first comment");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Into::<&str>::into(remaining),
|
Into::<&str>::into(remaining),
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use nom::bytes::complete::is_not;
|
use nom::bytes::complete::is_not;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::multi::many0;
|
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
use super::keyword::affiliated_keyword;
|
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use super::util::org_line_ending;
|
use super::util::org_line_ending;
|
||||||
@@ -33,7 +31,7 @@ where
|
|||||||
let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(remaining)?;
|
let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(remaining)?;
|
||||||
let (remaining, _eol) = org_line_ending(remaining)?;
|
let (remaining, _eol) = org_line_ending(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -45,13 +43,24 @@ where
|
|||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
value: Into::<&str>::into(value),
|
value: Into::<&str>::into(value),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(
|
||||||
pub(crate) fn detect_diary_sexp<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
feature = "tracing",
|
||||||
let (input, _) = many0(affiliated_keyword)(input)?;
|
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords))
|
||||||
tuple((start_of_line, tag("%%(")))(input)?;
|
)]
|
||||||
|
pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's, AK>(
|
||||||
|
_affiliated_keywords: AK,
|
||||||
|
remaining: OrgSource<'s>,
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()>
|
||||||
|
where
|
||||||
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
|
{
|
||||||
|
tuple((start_of_line, tag("%%(")))(remaining)?;
|
||||||
Ok((input, ()))
|
Ok((input, ()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::path::Path;
|
|||||||
use nom::combinator::all_consuming;
|
use nom::combinator::all_consuming;
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::multi::many0;
|
use nom::multi::many0;
|
||||||
|
use nom::InputTake;
|
||||||
|
|
||||||
use super::headline::heading;
|
use super::headline::heading;
|
||||||
use super::in_buffer_settings::apply_in_buffer_settings;
|
use super::in_buffer_settings::apply_in_buffer_settings;
|
||||||
@@ -11,6 +12,7 @@ use super::in_buffer_settings::scan_for_in_buffer_settings;
|
|||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::section::zeroth_section;
|
use super::section::zeroth_section;
|
||||||
use super::util::get_consumed;
|
use super::util::get_consumed;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::parser_with_context;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
@@ -18,9 +20,7 @@ use crate::context::GlobalSettings;
|
|||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::org_source::convert_error;
|
|
||||||
use crate::parser::util::blank_line;
|
use crate::parser::util::blank_line;
|
||||||
use crate::types::AstNode;
|
use crate::types::AstNode;
|
||||||
use crate::types::Document;
|
use crate::types::Document;
|
||||||
@@ -30,7 +30,7 @@ use crate::types::Object;
|
|||||||
///
|
///
|
||||||
/// This is a main entry point for Organic. It will parse the full contents of the input string as an org-mode document without an underlying file attached.
|
/// This is a main entry point for Organic. It will parse the full contents of the input string as an org-mode document without an underlying file attached.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn parse<'s>(input: &'s str) -> Result<Document<'s>, Box<dyn std::error::Error>> {
|
pub fn parse(input: &str) -> Result<Document<'_>, Box<dyn std::error::Error>> {
|
||||||
parse_file_with_settings::<&Path>(input, &GlobalSettings::default(), None)
|
parse_file_with_settings::<&Path>(input, &GlobalSettings::default(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +40,10 @@ pub fn parse<'s>(input: &'s str) -> Result<Document<'s>, Box<dyn std::error::Err
|
|||||||
///
|
///
|
||||||
/// file_path is not used for reading the file contents. It is only used for determining the document category and filling in the path attribute on the Document.
|
/// file_path is not used for reading the file contents. It is only used for determining the document category and filling in the path attribute on the Document.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn parse_file<'s, P: AsRef<Path>>(
|
pub fn parse_file<P: AsRef<Path>>(
|
||||||
input: &'s str,
|
input: &str,
|
||||||
file_path: Option<P>,
|
file_path: Option<P>,
|
||||||
) -> Result<Document<'s>, Box<dyn std::error::Error>> {
|
) -> Result<Document<'_>, Box<dyn std::error::Error>> {
|
||||||
parse_file_with_settings(input, &GlobalSettings::default(), file_path)
|
parse_file_with_settings(input, &GlobalSettings::default(), file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ pub fn parse_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
let initial_context = Context::new(global_settings, List::new(&initial_context));
|
let initial_context = Context::new(global_settings, List::new(&initial_context));
|
||||||
let wrapped_input = OrgSource::new(input);
|
let wrapped_input = OrgSource::new(input);
|
||||||
let mut doc =
|
let mut doc =
|
||||||
all_consuming(parser_with_context!(document_org_source)(&initial_context))(wrapped_input)
|
all_consuming(bind_context!(document_org_source, &initial_context))(wrapped_input)
|
||||||
.map_err(|err| err.to_string())
|
.map_err(|err| err.to_string())
|
||||||
.map(|(_remaining, parsed_document)| parsed_document)?;
|
.map(|(_remaining, parsed_document)| parsed_document)?;
|
||||||
if let Some(file_path) = file_path {
|
if let Some(file_path) = file_path {
|
||||||
@@ -101,11 +101,8 @@ pub fn parse_file_with_settings<'g, 's, P: AsRef<Path>>(
|
|||||||
///
|
///
|
||||||
/// This will not prevent additional settings from being learned during parsing, for example when encountering a "#+TODO".
|
/// This will not prevent additional settings from being learned during parsing, for example when encountering a "#+TODO".
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn document<'b, 'g, 'r, 's>(
|
fn document<'s>(context: RefContext<'_, '_, '_, 's>, input: &'s str) -> Res<&'s str, Document<'s>> {
|
||||||
context: RefContext<'b, 'g, 'r, 's>,
|
let (remaining, doc) = document_org_source(context, input.into())?;
|
||||||
input: &'s str,
|
|
||||||
) -> Res<&'s str, Document<'s>> {
|
|
||||||
let (remaining, doc) = document_org_source(context, input.into()).map_err(convert_error)?;
|
|
||||||
Ok((Into::<&str>::into(remaining), doc))
|
Ok((Into::<&str>::into(remaining), doc))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,29 +126,16 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
.get_global_settings()
|
.get_global_settings()
|
||||||
.file_access
|
.file_access
|
||||||
.read_file(setup_file)
|
.read_file(setup_file)
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))
|
.map_err(|err| nom::Err::<CustomError>::Failure(err.into()))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
for setup_file in setup_files.iter().map(String::as_str) {
|
for setup_file in setup_files.iter().map(String::as_str) {
|
||||||
let (_, setup_file_settings) =
|
let (_, setup_file_settings) = scan_for_in_buffer_settings(setup_file.into())?;
|
||||||
scan_for_in_buffer_settings(setup_file.into()).map_err(|err| {
|
|
||||||
eprintln!("{}", err);
|
|
||||||
nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"TODO: make this take an owned string so I can dump err.to_string() into it."
|
|
||||||
.into(),
|
|
||||||
)))
|
|
||||||
})?;
|
|
||||||
final_settings.extend(setup_file_settings);
|
final_settings.extend(setup_file_settings);
|
||||||
}
|
}
|
||||||
final_settings.extend(document_settings);
|
final_settings.extend(document_settings);
|
||||||
let new_settings = apply_in_buffer_settings(final_settings, context.get_global_settings())
|
let new_settings = apply_in_buffer_settings(final_settings, context.get_global_settings())
|
||||||
.map_err(|err| {
|
.map_err(nom::Err::Error)?;
|
||||||
eprintln!("{}", err);
|
|
||||||
nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"TODO: make this take an owned string so I can dump err.to_string() into it."
|
|
||||||
.into(),
|
|
||||||
)))
|
|
||||||
})?;
|
|
||||||
let new_context = context.with_global_settings(&new_settings);
|
let new_context = context.with_global_settings(&new_settings);
|
||||||
let context = &new_context;
|
let context = &new_context;
|
||||||
|
|
||||||
@@ -160,7 +144,7 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
{
|
{
|
||||||
// If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets.
|
// If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets.
|
||||||
let all_radio_targets: Vec<&Vec<Object<'_>>> = Into::<AstNode>::into(&document)
|
let all_radio_targets: Vec<&Vec<Object<'_>>> = Into::<AstNode>::into(&document)
|
||||||
.into_iter()
|
.iter_all_ast_nodes()
|
||||||
.filter_map(|ast_node| {
|
.filter_map(|ast_node| {
|
||||||
if let AstNode::RadioTarget(ast_node) = ast_node {
|
if let AstNode::RadioTarget(ast_node) = ast_node {
|
||||||
Some(ast_node)
|
Some(ast_node)
|
||||||
@@ -176,15 +160,13 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
let parser_context = context.with_global_settings(&new_global_settings);
|
let parser_context = context.with_global_settings(&new_global_settings);
|
||||||
let (remaining, mut document) = _document(&parser_context, input)
|
let (remaining, mut document) = _document(&parser_context, input)
|
||||||
.map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
.map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
||||||
apply_post_parse_in_buffer_settings(&mut document)
|
apply_post_parse_in_buffer_settings(&mut document);
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))?;
|
|
||||||
return Ok((remaining.into(), document));
|
return Ok((remaining.into(), document));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find final in-buffer settings that do not impact parsing
|
// Find final in-buffer settings that do not impact parsing
|
||||||
apply_post_parse_in_buffer_settings(&mut document)
|
apply_post_parse_in_buffer_settings(&mut document);
|
||||||
.map_err(|err| nom::Err::<CustomError<OrgSource<'_>>>::Failure(err.into()))?;
|
|
||||||
|
|
||||||
Ok((remaining.into(), document))
|
Ok((remaining.into(), document))
|
||||||
}
|
}
|
||||||
@@ -200,8 +182,10 @@ fn _document<'b, 'g, 'r, 's>(
|
|||||||
let zeroth_section_matcher = parser_with_context!(zeroth_section)(context);
|
let zeroth_section_matcher = parser_with_context!(zeroth_section)(context);
|
||||||
let heading_matcher = parser_with_context!(heading(0))(context);
|
let heading_matcher = parser_with_context!(heading(0))(context);
|
||||||
let (remaining, _blank_lines) = many0(blank_line)(input)?;
|
let (remaining, _blank_lines) = many0(blank_line)(input)?;
|
||||||
|
let contents_begin = remaining;
|
||||||
let (remaining, zeroth_section) = opt(zeroth_section_matcher)(remaining)?;
|
let (remaining, zeroth_section) = opt(zeroth_section_matcher)(remaining)?;
|
||||||
let (remaining, children) = many0(heading_matcher)(remaining)?;
|
let (remaining, children) = many0(heading_matcher)(remaining)?;
|
||||||
|
let contents = get_consumed(contents_begin, remaining);
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
@@ -211,6 +195,25 @@ fn _document<'b, 'g, 'r, 's>(
|
|||||||
path: None,
|
path: None,
|
||||||
zeroth_section,
|
zeroth_section,
|
||||||
children,
|
children,
|
||||||
|
contents: if contents.len() > 0 {
|
||||||
|
Into::<&str>::into(contents)
|
||||||
|
} else {
|
||||||
|
Into::<&str>::into(remaining.take(0))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_full_document(b: &mut Bencher) {
|
||||||
|
let input = include_str!("../../org_mode_samples/element_container_priority/README.org");
|
||||||
|
|
||||||
|
b.iter(|| assert!(parse(input).is_ok()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use nom::bytes::complete::tag_no_case;
|
|||||||
use nom::bytes::complete::take_while;
|
use nom::bytes::complete::take_while;
|
||||||
use nom::character::complete::line_ending;
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::consumed;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
@@ -12,17 +13,17 @@ use nom::sequence::tuple;
|
|||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
|
use super::paragraph::empty_paragraph;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::parser_with_context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::ExitClass;
|
use crate::context::ExitClass;
|
||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::element_parser::element;
|
use crate::parser::element_parser::element;
|
||||||
use crate::parser::util::blank_line;
|
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::immediate_in_section;
|
use crate::parser::util::immediate_in_section;
|
||||||
@@ -31,8 +32,6 @@ use crate::parser::util::WORD_CONSTITUENT_CHARACTERS;
|
|||||||
use crate::types::Drawer;
|
use crate::types::Drawer;
|
||||||
use crate::types::Element;
|
use crate::types::Element;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
use crate::types::Paragraph;
|
|
||||||
use crate::types::SetSource;
|
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "tracing",
|
feature = "tracing",
|
||||||
@@ -48,9 +47,9 @@ where
|
|||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
if immediate_in_section(context, "drawer") {
|
if immediate_in_section(context, "drawer") {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element".into(),
|
"Cannot nest objects of the same element",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
start_of_line(remaining)?;
|
start_of_line(remaining)?;
|
||||||
let (remaining, _leading_whitespace) = space0(remaining)?;
|
let (remaining, _leading_whitespace) = space0(remaining)?;
|
||||||
@@ -72,30 +71,12 @@ where
|
|||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
let parser_context = context.with_additional_node(&contexts[0]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
||||||
|
let (remaining, (contents, children)) =
|
||||||
|
consumed(parser_with_context!(children)(&parser_context))(remaining)?;
|
||||||
|
|
||||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
|
||||||
let (remaining, children) = match tuple((
|
|
||||||
not(exit_matcher),
|
|
||||||
blank_line,
|
|
||||||
many_till(blank_line, exit_matcher),
|
|
||||||
))(remaining)
|
|
||||||
{
|
|
||||||
Ok((remain, (_not_immediate_exit, first_line, (_trailing_whitespace, _exit_contents)))) => {
|
|
||||||
let mut element = Element::Paragraph(Paragraph::of_text(first_line.into()));
|
|
||||||
let source = get_consumed(remaining, remain);
|
|
||||||
element.set_source(source.into());
|
|
||||||
(remain, vec![element])
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
let (remaining, (children, _exit_contents)) =
|
|
||||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
|
||||||
(remaining, children)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let (remaining, _end) = drawer_end(&parser_context, remaining)?;
|
let (remaining, _end) = drawer_end(&parser_context, remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
@@ -109,10 +90,34 @@ where
|
|||||||
),
|
),
|
||||||
drawer_name: drawer_name.into(),
|
drawer_name: drawer_name.into(),
|
||||||
children,
|
children,
|
||||||
|
contents: Some(contents.into()),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
|
)]
|
||||||
|
fn children<'b, 'g, 'r, 's>(
|
||||||
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, Vec<Element<'s>>> {
|
||||||
|
let element_matcher = parser_with_context!(element(true))(context);
|
||||||
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||||
|
|
||||||
|
if let Ok((remaining, (_not_exit, empty_para))) =
|
||||||
|
tuple((not(exit_matcher), bind_context!(empty_paragraph, context)))(input)
|
||||||
|
{
|
||||||
|
return Ok((remaining, vec![Element::Paragraph(empty_para)]));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (remaining, (children, _exit_contents)) = many_till(element_matcher, exit_matcher)(input)?;
|
||||||
|
|
||||||
|
Ok((remaining, children))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn name<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c))(input)
|
take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c))(input)
|
||||||
|
|||||||
@@ -6,30 +6,28 @@ use nom::character::complete::anychar;
|
|||||||
use nom::character::complete::line_ending;
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::character::complete::space1;
|
use nom::character::complete::space1;
|
||||||
use nom::combinator::consumed;
|
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::multi::many0;
|
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::preceded;
|
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
|
use super::greater_block::leading_blank_lines_end;
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
|
use super::paragraph::empty_paragraph;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::parser_with_context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::ExitClass;
|
use crate::context::ExitClass;
|
||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::element_parser::element;
|
use crate::parser::element_parser::element;
|
||||||
use crate::parser::util::blank_line;
|
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::immediate_in_section;
|
use crate::parser::util::immediate_in_section;
|
||||||
@@ -37,8 +35,6 @@ use crate::parser::util::start_of_line;
|
|||||||
use crate::types::DynamicBlock;
|
use crate::types::DynamicBlock;
|
||||||
use crate::types::Element;
|
use crate::types::Element;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
use crate::types::Paragraph;
|
|
||||||
use crate::types::SetSource;
|
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "tracing",
|
feature = "tracing",
|
||||||
@@ -54,9 +50,9 @@ where
|
|||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
if immediate_in_section(context, "dynamic block") {
|
if immediate_in_section(context, "dynamic block") {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element".into(),
|
"Cannot nest objects of the same element",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
start_of_line(remaining)?;
|
start_of_line(remaining)?;
|
||||||
@@ -79,32 +75,29 @@ where
|
|||||||
let parser_context = context.with_additional_node(&contexts[0]);
|
let parser_context = context.with_additional_node(&contexts[0]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
let parser_context = parser_context.with_additional_node(&contexts[1]);
|
||||||
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
||||||
let parameters = match parameters {
|
let parameters = parameters.map(|(_ws, parameters)| parameters);
|
||||||
Some((_ws, parameters)) => Some(parameters),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
not(exit_matcher)(remaining)?;
|
not(exit_matcher)(remaining)?;
|
||||||
let (remaining, leading_blank_lines) = opt(consumed(tuple((
|
let contents_begin = remaining;
|
||||||
blank_line,
|
let blank_line_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
many0(preceded(not(exit_matcher), blank_line)),
|
class: ExitClass::Alpha,
|
||||||
))))(remaining)?;
|
exit_matcher: &leading_blank_lines_end,
|
||||||
let leading_blank_lines =
|
});
|
||||||
leading_blank_lines.map(|(source, (first_line, _remaining_lines))| {
|
let blank_line_context = parser_context.with_additional_node(&blank_line_context);
|
||||||
let mut element = Element::Paragraph(Paragraph::of_text(first_line.into()));
|
|
||||||
element.set_source(source.into());
|
let (remaining, leading_blank_lines) =
|
||||||
element
|
opt(bind_context!(empty_paragraph, &blank_line_context))(remaining)?;
|
||||||
});
|
|
||||||
let (remaining, (mut children, _exit_contents)) =
|
let (remaining, (mut children, _exit_contents)) =
|
||||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||||
if let Some(lines) = leading_blank_lines {
|
if let Some(lines) = leading_blank_lines {
|
||||||
children.insert(0, lines);
|
children.insert(0, Element::Paragraph(lines));
|
||||||
}
|
}
|
||||||
|
let contents = get_consumed(contents_begin, remaining);
|
||||||
|
|
||||||
let (remaining, _end) = dynamic_block_end(&parser_context, remaining)?;
|
let (remaining, _end) = dynamic_block_end(&parser_context, remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -118,6 +111,12 @@ where
|
|||||||
block_name: name.into(),
|
block_name: name.into(),
|
||||||
parameters: parameters.map(|val| val.into()),
|
parameters: parameters.map(|val| val.into()),
|
||||||
children,
|
children,
|
||||||
|
contents: if contents.len() > 0 {
|
||||||
|
Some(Into::<&str>::into(contents))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
use nom::branch::alt;
|
|
||||||
use nom::multi::many0;
|
|
||||||
|
|
||||||
use super::babel_call::babel_call;
|
use super::babel_call::babel_call;
|
||||||
use super::clock::clock;
|
use super::clock::clock;
|
||||||
use super::comment::comment;
|
use super::comment::comment;
|
||||||
@@ -15,7 +12,6 @@ use super::footnote_definition::detect_footnote_definition;
|
|||||||
use super::footnote_definition::footnote_definition;
|
use super::footnote_definition::footnote_definition;
|
||||||
use super::greater_block::greater_block;
|
use super::greater_block::greater_block;
|
||||||
use super::horizontal_rule::horizontal_rule;
|
use super::horizontal_rule::horizontal_rule;
|
||||||
use super::keyword::affiliated_keyword;
|
|
||||||
use super::keyword::keyword;
|
use super::keyword::keyword;
|
||||||
use super::latex_environment::latex_environment;
|
use super::latex_environment::latex_environment;
|
||||||
use super::lesser_block::comment_block;
|
use super::lesser_block::comment_block;
|
||||||
@@ -28,11 +24,16 @@ use super::paragraph::paragraph;
|
|||||||
use super::plain_list::detect_plain_list;
|
use super::plain_list::detect_plain_list;
|
||||||
use super::plain_list::plain_list;
|
use super::plain_list::plain_list;
|
||||||
use super::table::detect_table;
|
use super::table::detect_table;
|
||||||
use crate::context::parser_with_context;
|
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
|
#[cfg(feature = "event_count")]
|
||||||
|
use crate::event_count::record_event;
|
||||||
|
#[cfg(feature = "event_count")]
|
||||||
|
use crate::event_count::EventType;
|
||||||
|
use crate::parser::affiliated_keyword::affiliated_keywords;
|
||||||
|
use crate::parser::bullshitium::bullshitium;
|
||||||
|
use crate::parser::bullshitium::detect_bullshitium;
|
||||||
use crate::parser::macros::ak_element;
|
use crate::parser::macros::ak_element;
|
||||||
use crate::parser::macros::element;
|
use crate::parser::macros::element;
|
||||||
use crate::parser::table::org_mode_table;
|
use crate::parser::table::org_mode_table;
|
||||||
@@ -56,7 +57,9 @@ fn _element<'b, 'g, 'r, 's>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
can_be_paragraph: bool,
|
can_be_paragraph: bool,
|
||||||
) -> Res<OrgSource<'s>, Element<'s>> {
|
) -> Res<OrgSource<'s>, Element<'s>> {
|
||||||
let (post_affiliated_keywords_input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
#[cfg(feature = "event_count")]
|
||||||
|
record_event(EventType::ElementStart, input);
|
||||||
|
let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
|
||||||
|
|
||||||
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
||||||
|
|
||||||
@@ -240,6 +243,9 @@ fn _element<'b, 'g, 'r, 's>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if can_be_paragraph {
|
if can_be_paragraph {
|
||||||
|
// Fake paragraphs
|
||||||
|
element!(bullshitium, context, input, Element::Paragraph);
|
||||||
|
|
||||||
// Paragraph without affiliated keyword
|
// Paragraph without affiliated keyword
|
||||||
ak_element!(
|
ak_element!(
|
||||||
paragraph,
|
paragraph,
|
||||||
@@ -251,9 +257,7 @@ fn _element<'b, 'g, 'r, 's>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
Err(nom::Err::Error(CustomError::Static("No element.")))
|
||||||
"No element.",
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const fn detect_element(
|
pub(crate) const fn detect_element(
|
||||||
@@ -272,22 +276,60 @@ fn _detect_element<'b, 'g, 'r, 's>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
can_be_paragraph: bool,
|
can_be_paragraph: bool,
|
||||||
) -> Res<OrgSource<'s>, ()> {
|
) -> Res<OrgSource<'s>, ()> {
|
||||||
if alt((
|
let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
|
||||||
parser_with_context!(detect_plain_list)(context),
|
|
||||||
|
let mut affiliated_keywords = affiliated_keywords.into_iter();
|
||||||
|
|
||||||
|
ak_element!(
|
||||||
|
detect_plain_list,
|
||||||
|
&mut affiliated_keywords,
|
||||||
|
post_affiliated_keywords_input,
|
||||||
|
context,
|
||||||
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
ak_element!(
|
||||||
detect_footnote_definition,
|
detect_footnote_definition,
|
||||||
|
&mut affiliated_keywords,
|
||||||
|
post_affiliated_keywords_input,
|
||||||
|
context,
|
||||||
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
ak_element!(
|
||||||
detect_diary_sexp,
|
detect_diary_sexp,
|
||||||
detect_comment,
|
&mut affiliated_keywords,
|
||||||
|
post_affiliated_keywords_input,
|
||||||
|
context,
|
||||||
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
element!(detect_comment, input);
|
||||||
|
|
||||||
|
ak_element!(
|
||||||
detect_fixed_width_area,
|
detect_fixed_width_area,
|
||||||
|
&mut affiliated_keywords,
|
||||||
|
post_affiliated_keywords_input,
|
||||||
|
context,
|
||||||
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
ak_element!(
|
||||||
detect_table,
|
detect_table,
|
||||||
))(input)
|
&mut affiliated_keywords,
|
||||||
.is_ok()
|
post_affiliated_keywords_input,
|
||||||
{
|
context,
|
||||||
return Ok((input, ()));
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fake paragraphs
|
||||||
|
if !can_be_paragraph {
|
||||||
|
element!(detect_bullshitium, context, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if _element(context, input, can_be_paragraph).is_ok() {
|
if _element(context, input, can_be_paragraph).is_ok() {
|
||||||
return Ok((input, ()));
|
return Ok((input, ()));
|
||||||
}
|
}
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"No element detected.".into(),
|
Err(nom::Err::Error(CustomError::Static("No element detected.")))
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::satisfy;
|
use nom::character::complete::satisfy;
|
||||||
|
use nom::combinator::cond;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
@@ -13,7 +13,6 @@ use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
|
|||||||
use crate::context::EntityDefinition;
|
use crate::context::EntityDefinition;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::types::Entity;
|
use crate::types::Entity;
|
||||||
@@ -29,7 +28,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, _) = tag("\\")(input)?;
|
let (remaining, _) = tag("\\")(input)?;
|
||||||
let (remaining, (entity_definition, entity_name, use_brackets)) = name(context, remaining)?;
|
let (remaining, (entity_definition, entity_name, use_brackets)) = name(context, remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
@@ -44,6 +43,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>(
|
|||||||
ascii: entity_definition.ascii,
|
ascii: entity_definition.ascii,
|
||||||
utf8: entity_definition.utf8,
|
utf8: entity_definition.utf8,
|
||||||
use_brackets,
|
use_brackets,
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -58,23 +58,21 @@ fn name<'b, 'g, 'r, 's>(
|
|||||||
) -> Res<OrgSource<'s>, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> {
|
) -> Res<OrgSource<'s>, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> {
|
||||||
for entity in context.get_global_settings().entities {
|
for entity in context.get_global_settings().entities {
|
||||||
let result = tuple((
|
let result = tuple((
|
||||||
tag::<_, _, CustomError<_>>(entity.name),
|
tag::<_, _, CustomError>(entity.name),
|
||||||
alt((
|
cond(
|
||||||
verify(map(tag("{}"), |_| true), |_| !entity.name.ends_with(" ")),
|
!entity.name.ends_with(' '),
|
||||||
map(peek(recognize(entity_end)), |_| false),
|
alt((
|
||||||
)),
|
map(tag("{}"), |_| true),
|
||||||
|
map(peek(recognize(entity_end)), |_| false),
|
||||||
|
)),
|
||||||
|
),
|
||||||
))(input);
|
))(input);
|
||||||
match result {
|
if let Ok((remaining, (ent, use_brackets))) = result {
|
||||||
Ok((remaining, (ent, use_brackets))) => {
|
return Ok((remaining, (entity, ent, use_brackets.unwrap_or(false))));
|
||||||
return Ok((remaining, (entity, ent, use_brackets)));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
Err(nom::Err::Error(CustomError::Static("NoEntity")))
|
||||||
"NoEntity".into(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub(crate) fn export_snippet<'b, 'g, 'r, 's>(
|
|||||||
parser_with_context!(contents)(&parser_context),
|
parser_with_context!(contents)(&parser_context),
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
let (remaining, _) = tag("@@")(remaining)?;
|
let (remaining, _) = tag("@@")(remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -48,6 +48,7 @@ pub(crate) fn export_snippet<'b, 'g, 'r, 's>(
|
|||||||
source: source.into(),
|
source: source.into(),
|
||||||
backend: backend_name.into(),
|
backend: backend_name.into(),
|
||||||
contents: backend_contents.map(|(_colon, backend_contents)| backend_contents.into()),
|
contents: backend_contents.map(|(_colon, backend_contents)| backend_contents.into()),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,17 @@ use nom::branch::alt;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::map;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::multi::many0;
|
use nom::multi::many0;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::preceded;
|
use nom::sequence::preceded;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
use nom::InputTake;
|
||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
use super::keyword::affiliated_keyword;
|
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use super::util::org_line_ending;
|
use super::util::org_line_ending;
|
||||||
@@ -36,28 +38,25 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's, AK>(
|
|||||||
where
|
where
|
||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context);
|
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||||
let (remaining, first_line) = fixed_width_area_line_matcher(remaining)?;
|
let (remaining, first_line) = fixed_width_area_line(remaining)?;
|
||||||
let (remaining, mut remaining_lines) =
|
let (remaining, remaining_lines) = many0(preceded(
|
||||||
many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?;
|
not(tuple((org_line_ending, exit_matcher))),
|
||||||
|
map(
|
||||||
|
tuple((org_line_ending, fixed_width_area_line)),
|
||||||
|
|(_line_ending, line_contents)| line_contents,
|
||||||
|
),
|
||||||
|
))(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let post_blank_begin = remaining;
|
||||||
|
let (remaining, _first_line_break) = org_line_ending(remaining)?;
|
||||||
|
let (remaining, _additional_post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
let post_blank = get_consumed(post_blank_begin, remaining);
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
|
||||||
let last_line = remaining_lines.pop();
|
value.push(Into::<&str>::into(first_line));
|
||||||
if let Some(last_line) = last_line {
|
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
|
||||||
value.push(Into::<&str>::into(first_line));
|
|
||||||
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
|
|
||||||
let last_line = Into::<&str>::into(last_line);
|
|
||||||
// Trim the line ending from the final line.
|
|
||||||
value.push(&last_line[..(last_line.len() - 1)])
|
|
||||||
} else {
|
|
||||||
// Trim the line ending from the only line.
|
|
||||||
let only_line = Into::<&str>::into(first_line);
|
|
||||||
value.push(&only_line[..(only_line.len() - 1)])
|
|
||||||
}
|
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
FixedWidthArea {
|
FixedWidthArea {
|
||||||
@@ -67,36 +66,45 @@ where
|
|||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
value,
|
value,
|
||||||
|
post_blank: if post_blank.len() > 0 {
|
||||||
|
Some(Into::<&str>::into(post_blank))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
feature = "tracing",
|
fn fixed_width_area_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
tracing::instrument(ret, level = "debug", skip(_context))
|
|
||||||
)]
|
|
||||||
fn fixed_width_area_line<'b, 'g, 'r, 's>(
|
|
||||||
_context: RefContext<'b, 'g, 'r, 's>,
|
|
||||||
input: OrgSource<'s>,
|
|
||||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
|
||||||
start_of_line(input)?;
|
start_of_line(input)?;
|
||||||
let (remaining, _) = tuple((space0, tag(":")))(input)?;
|
let (remaining, _) = tuple((space0, tag(":")))(input)?;
|
||||||
if let Ok((remaining, line_break)) = org_line_ending(remaining) {
|
if let Ok((_remain, _line_break)) = org_line_ending(remaining) {
|
||||||
return Ok((remaining, line_break));
|
return Ok((remaining, remaining.take(0)));
|
||||||
}
|
}
|
||||||
let (remaining, _) = tag(" ")(remaining)?;
|
let (remaining, _) = tag(" ")(remaining)?;
|
||||||
let (remaining, value) = recognize(many_till(anychar, org_line_ending))(remaining)?;
|
let (remaining, value) = recognize(many_till(anychar, peek(org_line_ending)))(remaining)?;
|
||||||
Ok((remaining, value))
|
Ok((remaining, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(
|
||||||
pub(crate) fn detect_fixed_width_area<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
feature = "tracing",
|
||||||
let (input, _) = many0(affiliated_keyword)(input)?;
|
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords))
|
||||||
|
)]
|
||||||
|
pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's, AK>(
|
||||||
|
_affiliated_keywords: AK,
|
||||||
|
remaining: OrgSource<'s>,
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()>
|
||||||
|
where
|
||||||
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
|
{
|
||||||
tuple((
|
tuple((
|
||||||
start_of_line,
|
start_of_line,
|
||||||
space0,
|
space0,
|
||||||
tag(":"),
|
tag(":"),
|
||||||
alt((tag(" "), org_line_ending)),
|
alt((tag(" "), org_line_ending)),
|
||||||
))(input)?;
|
))(remaining)?;
|
||||||
Ok((input, ()))
|
Ok((input, ()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use nom::multi::many_till;
|
|||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
use super::keyword::affiliated_keyword;
|
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::util::include_input;
|
use super::util::include_input;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
@@ -23,7 +22,6 @@ use crate::context::ExitClass;
|
|||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::element_parser::element;
|
use crate::parser::element_parser::element;
|
||||||
use crate::parser::util::blank_line;
|
use crate::parser::util::blank_line;
|
||||||
@@ -49,9 +47,9 @@ where
|
|||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
if immediate_in_section(context, "footnote definition") {
|
if immediate_in_section(context, "footnote definition") {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element".into(),
|
"Cannot nest objects of the same element",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
start_of_line(remaining)?;
|
start_of_line(remaining)?;
|
||||||
// Cannot be indented.
|
// Cannot be indented.
|
||||||
@@ -77,6 +75,7 @@ where
|
|||||||
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
let parser_context = parser_context.with_additional_node(&contexts[2]);
|
||||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
|
let before_contents = remaining;
|
||||||
let (mut remaining, (mut children, _exit_contents)) =
|
let (mut remaining, (mut children, _exit_contents)) =
|
||||||
many_till(include_input(element_matcher), exit_matcher)(remaining)?;
|
many_till(include_input(element_matcher), exit_matcher)(remaining)?;
|
||||||
|
|
||||||
@@ -92,13 +91,16 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let contents = get_consumed(before_contents, remaining);
|
||||||
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
FootnoteDefinition {
|
FootnoteDefinition {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
contents: Some(contents.into()),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
affiliated_keywords: parse_affiliated_keywords(
|
affiliated_keywords: parse_affiliated_keywords(
|
||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
@@ -125,7 +127,7 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, source) = alt((
|
let (remaining, source) = alt((
|
||||||
recognize(tuple((
|
recognize(tuple((
|
||||||
parser_with_context!(maybe_consume_trailing_whitespace)(context),
|
parser_with_context!(maybe_consume_trailing_whitespace)(context),
|
||||||
detect_footnote_definition,
|
|i| detect_footnote_definition(std::iter::empty(), i, context, i),
|
||||||
))),
|
))),
|
||||||
recognize(tuple((
|
recognize(tuple((
|
||||||
start_of_line,
|
start_of_line,
|
||||||
@@ -138,20 +140,31 @@ fn footnote_definition_end<'b, 'g, 'r, 's>(
|
|||||||
Ok((remaining, source))
|
Ok((remaining, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(
|
||||||
pub(crate) fn detect_footnote_definition<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
|
feature = "tracing",
|
||||||
let (input, _) = many0(affiliated_keyword)(input)?;
|
tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords))
|
||||||
tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(input)?;
|
)]
|
||||||
|
pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's, AK>(
|
||||||
|
_affiliated_keywords: AK,
|
||||||
|
remaining: OrgSource<'s>,
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, ()>
|
||||||
|
where
|
||||||
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
|
{
|
||||||
|
tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(remaining)?;
|
||||||
Ok((input, ()))
|
Ok((input, ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
use crate::types::GetStandardProperties;
|
use crate::types::StandardProperties;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn two_paragraphs() {
|
fn two_paragraphs() {
|
||||||
@@ -165,24 +178,20 @@ line footnote.",
|
|||||||
let global_settings = GlobalSettings::default();
|
let global_settings = GlobalSettings::default();
|
||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||||
let footnote_definition_matcher = parser_with_context!(element(true))(&initial_context);
|
let footnote_definition_matcher = bind_context!(element(true), &initial_context);
|
||||||
let (remaining, first_footnote_definition) =
|
let (remaining, first_footnote_definition) =
|
||||||
footnote_definition_matcher(input).expect("Parse first footnote_definition");
|
footnote_definition_matcher(input).expect("Parse first footnote_definition");
|
||||||
let (remaining, second_footnote_definition) =
|
let (remaining, second_footnote_definition) =
|
||||||
footnote_definition_matcher(remaining).expect("Parse second footnote_definition.");
|
footnote_definition_matcher(remaining).expect("Parse second footnote_definition.");
|
||||||
assert_eq!(Into::<&str>::into(remaining), "");
|
assert_eq!(Into::<&str>::into(remaining), "");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_footnote_definition
|
first_footnote_definition.get_source(),
|
||||||
.get_standard_properties()
|
|
||||||
.get_source(),
|
|
||||||
"[fn:1] A footnote.
|
"[fn:1] A footnote.
|
||||||
|
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
second_footnote_definition
|
second_footnote_definition.get_source(),
|
||||||
.get_standard_properties()
|
|
||||||
.get_source(),
|
|
||||||
"[fn:2] A multi-
|
"[fn:2] A multi-
|
||||||
|
|
||||||
line footnote."
|
line footnote."
|
||||||
@@ -202,14 +211,12 @@ not in the footnote.",
|
|||||||
let global_settings = GlobalSettings::default();
|
let global_settings = GlobalSettings::default();
|
||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
let initial_context = Context::new(&global_settings, List::new(&initial_context));
|
||||||
let footnote_definition_matcher = parser_with_context!(element(true))(&initial_context);
|
let footnote_definition_matcher = bind_context!(element(true), &initial_context);
|
||||||
let (remaining, first_footnote_definition) =
|
let (remaining, first_footnote_definition) =
|
||||||
footnote_definition_matcher(input).expect("Parse first footnote_definition");
|
footnote_definition_matcher(input).expect("Parse first footnote_definition");
|
||||||
assert_eq!(Into::<&str>::into(remaining), "not in the footnote.");
|
assert_eq!(Into::<&str>::into(remaining), "not in the footnote.");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
first_footnote_definition
|
first_footnote_definition.get_source(),
|
||||||
.get_standard_properties()
|
|
||||||
.get_source(),
|
|
||||||
"[fn:2] A multi-
|
"[fn:2] A multi-
|
||||||
|
|
||||||
line footnote.
|
line footnote.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use nom::branch::alt;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::bytes::complete::tag_no_case;
|
use nom::bytes::complete::tag_no_case;
|
||||||
use nom::combinator::all_consuming;
|
use nom::combinator::all_consuming;
|
||||||
|
use nom::combinator::consumed;
|
||||||
use nom::combinator::map_parser;
|
use nom::combinator::map_parser;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
use nom::multi::many1;
|
use nom::multi::many1;
|
||||||
@@ -20,7 +21,6 @@ use crate::context::ExitMatcherNode;
|
|||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::footnote_definition::label;
|
use crate::parser::footnote_definition::label;
|
||||||
use crate::parser::object_parser::standard_set_object;
|
use crate::parser::object_parser::standard_set_object;
|
||||||
@@ -60,7 +60,7 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
|
|||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
||||||
|
|
||||||
let (remaining, children) = map_parser(
|
let (remaining, (contents, children)) = consumed(map_parser(
|
||||||
verify(
|
verify(
|
||||||
parser_with_context!(text_until_exit)(&parser_context),
|
parser_with_context!(text_until_exit)(&parser_context),
|
||||||
|text| text.len() > 0,
|
|text| text.len() > 0,
|
||||||
@@ -70,17 +70,19 @@ fn anonymous_footnote<'b, 'g, 'r, 's>(
|
|||||||
&initial_context,
|
&initial_context,
|
||||||
)))(i)
|
)))(i)
|
||||||
}),
|
}),
|
||||||
)(remaining)?;
|
))(remaining)?;
|
||||||
|
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
let (remaining, _) = tag("]")(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
FootnoteReference {
|
FootnoteReference {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
contents: Some(contents.into()),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
label: None,
|
label: None,
|
||||||
definition: children,
|
definition: children,
|
||||||
},
|
},
|
||||||
@@ -107,7 +109,7 @@ fn inline_footnote<'b, 'g, 'r, 's>(
|
|||||||
let initial_context = ContextElement::document_context();
|
let initial_context = ContextElement::document_context();
|
||||||
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context));
|
||||||
|
|
||||||
let (remaining, children) = map_parser(
|
let (remaining, (contents, children)) = consumed(map_parser(
|
||||||
verify(
|
verify(
|
||||||
parser_with_context!(text_until_exit)(&parser_context),
|
parser_with_context!(text_until_exit)(&parser_context),
|
||||||
|text| text.len() > 0,
|
|text| text.len() > 0,
|
||||||
@@ -117,17 +119,19 @@ fn inline_footnote<'b, 'g, 'r, 's>(
|
|||||||
&initial_context,
|
&initial_context,
|
||||||
)))(i)
|
)))(i)
|
||||||
}),
|
}),
|
||||||
)(remaining)?;
|
))(remaining)?;
|
||||||
|
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
let (remaining, _) = tag("]")(remaining)?;
|
||||||
|
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
FootnoteReference {
|
FootnoteReference {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
contents: Some(contents.into()),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
label: Some(label_contents.into()),
|
label: Some(label_contents.into()),
|
||||||
definition: children,
|
definition: children,
|
||||||
},
|
},
|
||||||
@@ -145,13 +149,15 @@ fn footnote_reference_only<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, _) = tag_no_case("[fn:")(input)?;
|
let (remaining, _) = tag_no_case("[fn:")(input)?;
|
||||||
let (remaining, label_contents) = label(remaining)?;
|
let (remaining, label_contents) = label(remaining)?;
|
||||||
let (remaining, _) = tag("]")(remaining)?;
|
let (remaining, _) = tag("]")(remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
FootnoteReference {
|
FootnoteReference {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
contents: None,
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
label: Some(label_contents.into()),
|
label: Some(label_contents.into()),
|
||||||
definition: Vec::with_capacity(0),
|
definition: Vec::with_capacity(0),
|
||||||
},
|
},
|
||||||
@@ -176,9 +182,9 @@ fn _footnote_definition_end<'b, 'g, 'r, 's>(
|
|||||||
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
||||||
if current_depth > 0 {
|
if current_depth > 0 {
|
||||||
// Its impossible for the next character to end the footnote reference definition if we're any amount of brackets deep
|
// Its impossible for the next character to end the footnote reference definition if we're any amount of brackets deep
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"NoFootnoteReferenceDefinitionEnd".into(),
|
"NoFootnoteReferenceDefinitionEnd",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
if current_depth < 0 {
|
if current_depth < 0 {
|
||||||
// This shouldn't be possible because if depth is 0 then a closing bracket should end the footnote definition.
|
// This shouldn't be possible because if depth is 0 then a closing bracket should end the footnote definition.
|
||||||
|
|||||||
@@ -5,22 +5,21 @@ use nom::character::complete::anychar;
|
|||||||
use nom::character::complete::line_ending;
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::character::complete::space1;
|
use nom::character::complete::space1;
|
||||||
use nom::combinator::consumed;
|
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
use nom::multi::many0;
|
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::preceded;
|
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::affiliated_keyword::parse_affiliated_keywords;
|
use super::affiliated_keyword::parse_affiliated_keywords;
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
|
use super::paragraph::empty_paragraph;
|
||||||
use super::util::in_section;
|
use super::util::in_section;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
use crate::context::bind_context;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::parser_with_context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::ContextMatcher;
|
use crate::context::ContextMatcher;
|
||||||
@@ -28,7 +27,6 @@ use crate::context::ExitClass;
|
|||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::element_parser::element;
|
use crate::parser::element_parser::element;
|
||||||
use crate::parser::util::blank_line;
|
use crate::parser::util::blank_line;
|
||||||
@@ -38,9 +36,7 @@ use crate::parser::util::start_of_line;
|
|||||||
use crate::types::CenterBlock;
|
use crate::types::CenterBlock;
|
||||||
use crate::types::Element;
|
use crate::types::Element;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
use crate::types::Paragraph;
|
|
||||||
use crate::types::QuoteBlock;
|
use crate::types::QuoteBlock;
|
||||||
use crate::types::SetSource;
|
|
||||||
use crate::types::SpecialBlock;
|
use crate::types::SpecialBlock;
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
@@ -61,10 +57,10 @@ where
|
|||||||
let (remaining, (_begin, name)) = tuple((
|
let (remaining, (_begin, name)) = tuple((
|
||||||
tag_no_case("#+begin_"),
|
tag_no_case("#+begin_"),
|
||||||
verify(name, |name: &OrgSource<'_>| {
|
verify(name, |name: &OrgSource<'_>| {
|
||||||
match Into::<&str>::into(name).to_lowercase().as_str() {
|
!matches!(
|
||||||
"comment" | "example" | "export" | "src" | "verse" => false,
|
Into::<&str>::into(name).to_lowercase().as_str(),
|
||||||
_ => true,
|
"comment" | "example" | "export" | "src" | "verse",
|
||||||
}
|
)
|
||||||
}),
|
}),
|
||||||
))(remaining)?;
|
))(remaining)?;
|
||||||
let name = Into::<&str>::into(name);
|
let name = Into::<&str>::into(name);
|
||||||
@@ -104,7 +100,7 @@ fn center_block<'b, 'g, 'r, 's, AK>(
|
|||||||
where
|
where
|
||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
let (remaining, (source, children)) = greater_block_body(
|
let (remaining, body) = greater_block_body(
|
||||||
context,
|
context,
|
||||||
input,
|
input,
|
||||||
pre_affiliated_keywords_input,
|
pre_affiliated_keywords_input,
|
||||||
@@ -114,12 +110,14 @@ where
|
|||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Element::CenterBlock(CenterBlock {
|
Element::CenterBlock(CenterBlock {
|
||||||
source,
|
source: body.source,
|
||||||
affiliated_keywords: parse_affiliated_keywords(
|
affiliated_keywords: parse_affiliated_keywords(
|
||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
children,
|
children: body.children,
|
||||||
|
contents: body.contents,
|
||||||
|
post_blank: body.post_blank,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -137,7 +135,7 @@ fn quote_block<'b, 'g, 'r, 's, AK>(
|
|||||||
where
|
where
|
||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
let (remaining, (source, children)) = greater_block_body(
|
let (remaining, body) = greater_block_body(
|
||||||
context,
|
context,
|
||||||
input,
|
input,
|
||||||
pre_affiliated_keywords_input,
|
pre_affiliated_keywords_input,
|
||||||
@@ -147,12 +145,14 @@ where
|
|||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Element::QuoteBlock(QuoteBlock {
|
Element::QuoteBlock(QuoteBlock {
|
||||||
source,
|
source: body.source,
|
||||||
affiliated_keywords: parse_affiliated_keywords(
|
affiliated_keywords: parse_affiliated_keywords(
|
||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
children,
|
children: body.children,
|
||||||
|
contents: body.contents,
|
||||||
|
post_blank: body.post_blank,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ where
|
|||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
|
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
|
||||||
let (remaining, (source, children)) = greater_block_body(
|
let (remaining, body) = greater_block_body(
|
||||||
context,
|
context,
|
||||||
remaining,
|
remaining,
|
||||||
pre_affiliated_keywords_input,
|
pre_affiliated_keywords_input,
|
||||||
@@ -208,18 +208,28 @@ where
|
|||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Element::SpecialBlock(SpecialBlock {
|
Element::SpecialBlock(SpecialBlock {
|
||||||
source,
|
source: body.source,
|
||||||
affiliated_keywords: parse_affiliated_keywords(
|
affiliated_keywords: parse_affiliated_keywords(
|
||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
children,
|
children: body.children,
|
||||||
block_type: name,
|
block_type: name,
|
||||||
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),
|
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),
|
||||||
|
contents: body.contents,
|
||||||
|
post_blank: body.post_blank,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct GreaterBlockBody<'s> {
|
||||||
|
source: &'s str,
|
||||||
|
children: Vec<Element<'s>>,
|
||||||
|
contents: Option<&'s str>,
|
||||||
|
post_blank: Option<&'s str>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "tracing",
|
feature = "tracing",
|
||||||
tracing::instrument(ret, level = "debug", skip(context))
|
tracing::instrument(ret, level = "debug", skip(context))
|
||||||
@@ -230,11 +240,11 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>(
|
|||||||
pre_affiliated_keywords_input: OrgSource<'s>,
|
pre_affiliated_keywords_input: OrgSource<'s>,
|
||||||
name: &'c str,
|
name: &'c str,
|
||||||
context_name: &'c str,
|
context_name: &'c str,
|
||||||
) -> Res<OrgSource<'s>, (&'s str, Vec<Element<'s>>)> {
|
) -> Res<OrgSource<'s>, GreaterBlockBody<'s>> {
|
||||||
if in_section(context, context_name) {
|
if in_section(context, context_name) {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static(
|
||||||
"Cannot nest objects of the same element".into(),
|
"Cannot nest objects of the same element",
|
||||||
))));
|
)));
|
||||||
}
|
}
|
||||||
let exit_with_name = greater_block_end(name);
|
let exit_with_name = greater_block_end(name);
|
||||||
let (remaining, _nl) = tuple((space0, line_ending))(input)?;
|
let (remaining, _nl) = tuple((space0, line_ending))(input)?;
|
||||||
@@ -252,30 +262,43 @@ fn greater_block_body<'c, 'b, 'g, 'r, 's>(
|
|||||||
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
let element_matcher = parser_with_context!(element(true))(&parser_context);
|
||||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
|
||||||
not(exit_matcher)(remaining)?;
|
not(exit_matcher)(remaining)?;
|
||||||
let (remaining, leading_blank_lines) = opt(consumed(tuple((
|
let contents_begin = remaining;
|
||||||
blank_line,
|
|
||||||
many0(preceded(not(exit_matcher), blank_line)),
|
let blank_line_context = ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
))))(remaining)?;
|
class: ExitClass::Alpha,
|
||||||
let leading_blank_lines =
|
exit_matcher: &leading_blank_lines_end,
|
||||||
leading_blank_lines.map(|(source, (first_line, _remaining_lines))| {
|
});
|
||||||
let mut element = Element::Paragraph(Paragraph::of_text(first_line.into()));
|
let blank_line_context = parser_context.with_additional_node(&blank_line_context);
|
||||||
element.set_source(source.into());
|
|
||||||
element
|
let (remaining, leading_blank_lines) =
|
||||||
});
|
opt(bind_context!(empty_paragraph, &blank_line_context))(remaining)?;
|
||||||
let (remaining, (mut children, _exit_contents)) =
|
let (remaining, (mut children, _exit_contents)) =
|
||||||
many_till(element_matcher, exit_matcher)(remaining)?;
|
many_till(element_matcher, exit_matcher)(remaining)?;
|
||||||
if let Some(lines) = leading_blank_lines {
|
if let Some(lines) = leading_blank_lines {
|
||||||
children.insert(0, lines);
|
children.insert(0, Element::Paragraph(lines));
|
||||||
}
|
}
|
||||||
|
let contents = get_consumed(contents_begin, remaining);
|
||||||
|
|
||||||
let (remaining, _end) = exit_with_name(&parser_context, remaining)?;
|
let (remaining, _end) = exit_with_name(&parser_context, remaining)?;
|
||||||
|
|
||||||
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
|
// Not checking if parent exit matcher is causing exit because the greater_block_end matcher asserts we matched a full greater block
|
||||||
|
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(pre_affiliated_keywords_input, remaining);
|
let source = get_consumed(pre_affiliated_keywords_input, remaining);
|
||||||
Ok((remaining, (Into::<&str>::into(source), children)))
|
Ok((
|
||||||
|
remaining,
|
||||||
|
GreaterBlockBody {
|
||||||
|
source: Into::<&str>::into(source),
|
||||||
|
children,
|
||||||
|
contents: if contents.len() > 0 {
|
||||||
|
Some(Into::<&str>::into(contents))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
@@ -288,7 +311,7 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
|||||||
recognize(many_till(anychar, peek(tuple((space0, line_ending)))))(input)
|
recognize(many_till(anychar, peek(tuple((space0, line_ending)))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c {
|
fn greater_block_end(name: &str) -> impl ContextMatcher + '_ {
|
||||||
move |context, input: OrgSource<'_>| _greater_block_end(context, input, name)
|
move |context, input: OrgSource<'_>| _greater_block_end(context, input, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,3 +334,14 @@ fn _greater_block_end<'b, 'g, 'r, 's, 'c>(
|
|||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((remaining, source))
|
Ok((remaining, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(ret, level = "debug", skip(_context))
|
||||||
|
)]
|
||||||
|
pub(crate) fn leading_blank_lines_end<'b, 'g, 'r, 's, 'c>(
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
|
recognize(not(blank_line))(input)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,18 +18,18 @@ use nom::sequence::tuple;
|
|||||||
|
|
||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::section::section;
|
use super::section::section;
|
||||||
|
use super::util::exit_matcher_parser;
|
||||||
use super::util::get_consumed;
|
use super::util::get_consumed;
|
||||||
use super::util::org_line_ending;
|
use super::util::org_line_ending;
|
||||||
use super::util::org_space;
|
use super::util::org_space;
|
||||||
use super::util::org_space_or_line_ending;
|
use super::util::org_space_or_line_ending;
|
||||||
use super::util::start_of_line;
|
use super::util::start_of_line;
|
||||||
use crate::context::parser_with_context;
|
use crate::context::bind_context;
|
||||||
use crate::context::ContextElement;
|
use crate::context::ContextElement;
|
||||||
use crate::context::ExitClass;
|
use crate::context::ExitClass;
|
||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::object_parser::standard_set_object;
|
use crate::parser::object_parser::standard_set_object;
|
||||||
use crate::parser::util::blank_line;
|
use crate::parser::util::blank_line;
|
||||||
@@ -62,10 +62,12 @@ fn _heading<'b, 'g, 'r, 's>(
|
|||||||
let mut scheduled = None;
|
let mut scheduled = None;
|
||||||
let mut deadline = None;
|
let mut deadline = None;
|
||||||
let mut closed = None;
|
let mut closed = None;
|
||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(bind_context!(exit_matcher_parser, context))(input)?;
|
||||||
let (remaining, pre_headline) = headline(context, input, parent_star_count)?;
|
let (remaining, pre_headline) = headline(context, input, parent_star_count)?;
|
||||||
let section_matcher = parser_with_context!(section)(context);
|
let section_matcher = bind_context!(section, context);
|
||||||
let heading_matcher = parser_with_context!(heading(pre_headline.star_count))(context);
|
let heading_matcher = bind_context!(heading(pre_headline.star_count), context);
|
||||||
|
let (contents_begin, _) = opt(many0(blank_line))(remaining)?;
|
||||||
|
let maybe_post_blank = get_consumed(remaining, contents_begin);
|
||||||
let (remaining, maybe_section) =
|
let (remaining, maybe_section) =
|
||||||
opt(map(section_matcher, DocumentElement::Section))(remaining)?;
|
opt(map(section_matcher, DocumentElement::Section))(remaining)?;
|
||||||
let (remaining, _ws) = opt(tuple((start_of_line, many0(blank_line))))(remaining)?;
|
let (remaining, _ws) = opt(tuple((start_of_line, many0(blank_line))))(remaining)?;
|
||||||
@@ -75,14 +77,15 @@ fn _heading<'b, 'g, 'r, 's>(
|
|||||||
// If the section has a planning then the timestamp values are copied to the heading.
|
// If the section has a planning then the timestamp values are copied to the heading.
|
||||||
if let DocumentElement::Section(inner_section) = §ion {
|
if let DocumentElement::Section(inner_section) = §ion {
|
||||||
if let Some(Element::Planning(planning)) = inner_section.children.first() {
|
if let Some(Element::Planning(planning)) = inner_section.children.first() {
|
||||||
scheduled = planning.scheduled.clone();
|
scheduled.clone_from(&planning.scheduled);
|
||||||
deadline = planning.deadline.clone();
|
deadline.clone_from(&planning.deadline);
|
||||||
closed = planning.closed.clone();
|
closed.clone_from(&planning.closed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
children.insert(0, section);
|
children.insert(0, section);
|
||||||
}
|
}
|
||||||
let remaining = if children.is_empty() {
|
let has_children = !children.is_empty();
|
||||||
|
let remaining = if !has_children {
|
||||||
// Support empty headings
|
// Support empty headings
|
||||||
let (remain, _ws) = many0(blank_line)(remaining)?;
|
let (remain, _ws) = many0(blank_line)(remaining)?;
|
||||||
remain
|
remain
|
||||||
@@ -91,6 +94,7 @@ fn _heading<'b, 'g, 'r, 's>(
|
|||||||
};
|
};
|
||||||
let is_archived = pre_headline.tags.contains(&"ARCHIVE");
|
let is_archived = pre_headline.tags.contains(&"ARCHIVE");
|
||||||
|
|
||||||
|
let contents = get_consumed(contents_begin, remaining);
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
@@ -112,6 +116,16 @@ fn _heading<'b, 'g, 'r, 's>(
|
|||||||
scheduled,
|
scheduled,
|
||||||
deadline,
|
deadline,
|
||||||
closed,
|
closed,
|
||||||
|
contents: if contents.len() > 0 {
|
||||||
|
Some(Into::<&str>::into(contents))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
post_blank: if has_children {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Into::<&str>::into(maybe_post_blank))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -155,7 +169,7 @@ fn headline<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, (_, (headline_level, star_count, _), _)) = tuple((
|
let (remaining, (_, (headline_level, star_count, _), _)) = tuple((
|
||||||
start_of_line,
|
start_of_line,
|
||||||
verify(
|
verify(
|
||||||
parser_with_context!(headline_level)(&parser_context),
|
bind_context!(headline_level, &parser_context),
|
||||||
|(_, count, _)| *count > parent_star_count,
|
|(_, count, _)| *count > parent_star_count,
|
||||||
),
|
),
|
||||||
peek(org_space),
|
peek(org_space),
|
||||||
@@ -163,7 +177,7 @@ fn headline<'b, 'g, 'r, 's>(
|
|||||||
|
|
||||||
let (remaining, maybe_todo_keyword) = opt(tuple((
|
let (remaining, maybe_todo_keyword) = opt(tuple((
|
||||||
space1,
|
space1,
|
||||||
parser_with_context!(heading_keyword)(&parser_context),
|
bind_context!(heading_keyword, &parser_context),
|
||||||
peek(org_space_or_line_ending),
|
peek(org_space_or_line_ending),
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
|
|
||||||
@@ -177,9 +191,7 @@ fn headline<'b, 'g, 'r, 's>(
|
|||||||
|
|
||||||
let (remaining, maybe_title) = opt(tuple((
|
let (remaining, maybe_title) = opt(tuple((
|
||||||
space1,
|
space1,
|
||||||
consumed(many1(parser_with_context!(standard_set_object)(
|
consumed(many1(bind_context!(standard_set_object, &parser_context))),
|
||||||
&parser_context,
|
|
||||||
))),
|
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
|
|
||||||
let (remaining, maybe_tags) = opt(tuple((space0, tags)))(remaining)?;
|
let (remaining, maybe_tags) = opt(tuple((space0, tags)))(remaining)?;
|
||||||
@@ -206,11 +218,7 @@ fn headline<'b, 'g, 'r, 's>(
|
|||||||
.map(|(_, (_, title))| title)
|
.map(|(_, (_, title))| title)
|
||||||
.unwrap_or(Vec::new()),
|
.unwrap_or(Vec::new()),
|
||||||
tags: maybe_tags
|
tags: maybe_tags
|
||||||
.map(|(_ws, tags)| {
|
.map(|(_ws, tags)| tags.into_iter().map(Into::<&str>::into).collect())
|
||||||
tags.into_iter()
|
|
||||||
.map(|single_tag| Into::<&str>::into(single_tag))
|
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.unwrap_or(Vec::new()),
|
.unwrap_or(Vec::new()),
|
||||||
is_footnote_section,
|
is_footnote_section,
|
||||||
},
|
},
|
||||||
@@ -264,12 +272,9 @@ fn heading_keyword<'b, 'g, 'r, 's>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
{
|
{
|
||||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
let result = tag::<_, _, CustomError>(todo_keyword)(input);
|
||||||
match result {
|
if let Ok((remaining, ent)) = result {
|
||||||
Ok((remaining, ent)) => {
|
return Ok((remaining, (TodoKeywordType::Todo, ent)));
|
||||||
return Ok((remaining, (TodoKeywordType::Todo, ent)));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for todo_keyword in global_settings
|
for todo_keyword in global_settings
|
||||||
@@ -277,30 +282,25 @@ fn heading_keyword<'b, 'g, 'r, 's>(
|
|||||||
.iter()
|
.iter()
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
{
|
{
|
||||||
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
|
let result = tag::<_, _, CustomError>(todo_keyword)(input);
|
||||||
match result {
|
if let Ok((remaining, ent)) = result {
|
||||||
Ok((remaining, ent)) => {
|
return Ok((remaining, (TodoKeywordType::Done, ent)));
|
||||||
return Ok((remaining, (TodoKeywordType::Done, ent)));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
Err(nom::Err::Error(CustomError::Static("NoTodoKeyword")))
|
||||||
"NoTodoKeyword".into(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn priority_cookie<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PriorityCookie> {
|
fn priority_cookie(input: OrgSource<'_>) -> Res<OrgSource<'_>, PriorityCookie> {
|
||||||
let (remaining, (_, priority_character, _)) = tuple((
|
let (remaining, (_, priority_character, _)) = tuple((
|
||||||
tag("[#"),
|
tag("[#"),
|
||||||
verify(anychar, |c| c.is_alphanumeric()),
|
verify(anychar, |c| c.is_alphanumeric()),
|
||||||
tag("]"),
|
tag("]"),
|
||||||
))(input)?;
|
))(input)?;
|
||||||
let cookie = PriorityCookie::try_from(priority_character).map_err(|_| {
|
let cookie = PriorityCookie::try_from(priority_character).map_err(|_| {
|
||||||
nom::Err::Error(CustomError::MyError(MyError(
|
nom::Err::Error(CustomError::Static(
|
||||||
"Failed to cast priority cookie to number.".into(),
|
"Failed to cast priority cookie to number.",
|
||||||
)))
|
))
|
||||||
})?;
|
})?;
|
||||||
Ok((remaining, cookie))
|
Ok((remaining, cookie))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ where
|
|||||||
space0,
|
space0,
|
||||||
alt((line_ending, eof)),
|
alt((line_ending, eof)),
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -49,6 +49,7 @@ where
|
|||||||
context.get_global_settings(),
|
context.get_global_settings(),
|
||||||
affiliated_keywords,
|
affiliated_keywords,
|
||||||
),
|
),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>(
|
|||||||
let mut remaining = input;
|
let mut remaining = input;
|
||||||
loop {
|
loop {
|
||||||
// Skip text until possible in_buffer_setting
|
// Skip text until possible in_buffer_setting
|
||||||
let start_of_pound = take_until::<_, _, CustomError<_>>("#+")(remaining);
|
let start_of_pound = take_until::<_, _, CustomError>("#+")(remaining);
|
||||||
let start_of_pound = if let Ok((start_of_pound, _)) = start_of_pound {
|
let start_of_pound = if let Ok((start_of_pound, _)) = start_of_pound {
|
||||||
start_of_pound
|
start_of_pound
|
||||||
} else {
|
} else {
|
||||||
@@ -47,7 +47,7 @@ pub(crate) fn scan_for_in_buffer_settings<'s>(
|
|||||||
let (remain, maybe_kw) = match filtered_keyword(in_buffer_settings_key)(start_of_line) {
|
let (remain, maybe_kw) = match filtered_keyword(in_buffer_settings_key)(start_of_line) {
|
||||||
Ok((remain, kw)) => (remain, Some(kw)),
|
Ok((remain, kw)) => (remain, Some(kw)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let end_of_line = take_until::<_, _, CustomError<_>>("\n")(start_of_pound);
|
let end_of_line = take_until::<_, _, CustomError>("\n")(start_of_pound);
|
||||||
if let Ok((end_of_line, _)) = end_of_line {
|
if let Ok((end_of_line, _)) = end_of_line {
|
||||||
(end_of_line, None)
|
(end_of_line, None)
|
||||||
} else {
|
} else {
|
||||||
@@ -84,11 +84,14 @@ fn in_buffer_settings_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSou
|
|||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug"))]
|
#[cfg_attr(
|
||||||
|
feature = "tracing",
|
||||||
|
tracing::instrument(level = "debug", skip(original_settings))
|
||||||
|
)]
|
||||||
pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
||||||
keywords: Vec<Keyword<'sf>>,
|
keywords: Vec<Keyword<'sf>>,
|
||||||
original_settings: &'g GlobalSettings<'g, 's>,
|
original_settings: &'g GlobalSettings<'g, 's>,
|
||||||
) -> Result<GlobalSettings<'g, 's>, String> {
|
) -> Result<GlobalSettings<'g, 's>, CustomError> {
|
||||||
let mut new_settings = original_settings.clone();
|
let mut new_settings = original_settings.clone();
|
||||||
|
|
||||||
// Todo Keywords
|
// Todo Keywords
|
||||||
@@ -98,7 +101,11 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
|||||||
|| kw.key.eq_ignore_ascii_case("typ_todo")
|
|| kw.key.eq_ignore_ascii_case("typ_todo")
|
||||||
}) {
|
}) {
|
||||||
let (_, (in_progress_words, complete_words)) =
|
let (_, (in_progress_words, complete_words)) =
|
||||||
todo_keywords(kw.value).map_err(|err| err.to_string())?;
|
todo_keywords(kw.value).map_err(|err| match err {
|
||||||
|
nom::Err::Incomplete(_) => panic!("This parser does not support streaming."),
|
||||||
|
nom::Err::Error(e) => e,
|
||||||
|
nom::Err::Failure(e) => e,
|
||||||
|
})?;
|
||||||
new_settings
|
new_settings
|
||||||
.in_progress_todo_keywords
|
.in_progress_todo_keywords
|
||||||
.extend(in_progress_words.into_iter().map(str::to_string));
|
.extend(in_progress_words.into_iter().map(str::to_string));
|
||||||
@@ -112,9 +119,14 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|kw| kw.key.eq_ignore_ascii_case("startup"))
|
.filter(|kw| kw.key.eq_ignore_ascii_case("startup"))
|
||||||
{
|
{
|
||||||
let (_remaining, settings) =
|
let (_remaining, settings) = separated_list0(space1::<&str, CustomError>, is_not(" \t"))(
|
||||||
separated_list0(space1::<&str, nom::error::Error<_>>, is_not(" \t"))(kw.value)
|
kw.value,
|
||||||
.map_err(|err: nom::Err<_>| err.to_string())?;
|
)
|
||||||
|
.map_err(|err: nom::Err<_>| match err {
|
||||||
|
nom::Err::Incomplete(_) => panic!("This parser does not support streaming."),
|
||||||
|
nom::Err::Error(e) => e,
|
||||||
|
nom::Err::Failure(e) => e,
|
||||||
|
})?;
|
||||||
if settings.contains(&"odd") {
|
if settings.contains(&"odd") {
|
||||||
new_settings.odd_levels_only = HeadlineLevelFilter::Odd;
|
new_settings.odd_levels_only = HeadlineLevelFilter::Odd;
|
||||||
}
|
}
|
||||||
@@ -128,7 +140,11 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|kw| kw.key.eq_ignore_ascii_case("link"))
|
.filter(|kw| kw.key.eq_ignore_ascii_case("link"))
|
||||||
{
|
{
|
||||||
let (_, (link_key, link_value)) = link_template(kw.value).map_err(|e| e.to_string())?;
|
let (_, (link_key, link_value)) = link_template(kw.value).map_err(|err| match err {
|
||||||
|
nom::Err::Incomplete(_) => panic!("This parser does not support streaming."),
|
||||||
|
nom::Err::Error(e) => e,
|
||||||
|
nom::Err::Failure(e) => e,
|
||||||
|
})?;
|
||||||
new_settings
|
new_settings
|
||||||
.link_templates
|
.link_templates
|
||||||
.insert(link_key.to_owned(), link_value.to_owned());
|
.insert(link_key.to_owned(), link_value.to_owned());
|
||||||
@@ -139,11 +155,9 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
|
|||||||
|
|
||||||
/// Apply in-buffer settings that do not impact parsing and therefore can be applied after parsing.
|
/// Apply in-buffer settings that do not impact parsing and therefore can be applied after parsing.
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
pub(crate) fn apply_post_parse_in_buffer_settings<'g, 's, 'sf>(
|
pub(crate) fn apply_post_parse_in_buffer_settings<'g, 's, 'sf>(document: &mut Document<'s>) {
|
||||||
document: &mut Document<'s>,
|
|
||||||
) -> Result<(), &'static str> {
|
|
||||||
document.category = Into::<AstNode>::into(&*document)
|
document.category = Into::<AstNode>::into(&*document)
|
||||||
.into_iter()
|
.iter_all_ast_nodes()
|
||||||
.filter_map(|ast_node| {
|
.filter_map(|ast_node| {
|
||||||
if let AstNode::Keyword(ast_node) = ast_node {
|
if let AstNode::Keyword(ast_node) = ast_node {
|
||||||
if ast_node.key.eq_ignore_ascii_case("category") {
|
if ast_node.key.eq_ignore_ascii_case("category") {
|
||||||
@@ -154,7 +168,6 @@ pub(crate) fn apply_post_parse_in_buffer_settings<'g, 's, 'sf>(
|
|||||||
})
|
})
|
||||||
.last()
|
.last()
|
||||||
.map(|kw| kw.value.to_owned());
|
.map(|kw| kw.value.to_owned());
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ use crate::context::ExitClass;
|
|||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
@@ -39,7 +38,7 @@ pub(crate) fn inline_babel_call<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, arguments) = argument(context, remaining)?;
|
let (remaining, arguments) = argument(context, remaining)?;
|
||||||
let (remaining, end_header) = opt(parser_with_context!(header)(context))(remaining)?;
|
let (remaining, end_header) = opt(parser_with_context!(header)(context))(remaining)?;
|
||||||
let value = get_consumed(input, remaining);
|
let value = get_consumed(input, remaining);
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -55,6 +54,7 @@ pub(crate) fn inline_babel_call<'b, 'g, 'r, 's>(
|
|||||||
None
|
None
|
||||||
},
|
},
|
||||||
end_header: end_header.map(Into::<&str>::into),
|
end_header: end_header.map(Into::<&str>::into),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -131,9 +131,7 @@ fn _header_end<'b, 'g, 'r, 's>(
|
|||||||
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
||||||
if current_depth > 0 {
|
if current_depth > 0 {
|
||||||
// Its impossible for the next character to end the header if we're any amount of bracket deep
|
// Its impossible for the next character to end the header if we're any amount of bracket deep
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("NoHeaderEnd")));
|
||||||
"NoHeaderEnd".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
if current_depth < 0 {
|
if current_depth < 0 {
|
||||||
// This shouldn't be possible because if depth is 0 then a closing bracket should end the header.
|
// This shouldn't be possible because if depth is 0 then a closing bracket should end the header.
|
||||||
@@ -183,9 +181,7 @@ fn _argument_end<'b, 'g, 'r, 's>(
|
|||||||
let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth;
|
let current_depth = input.get_parenthesis_depth() - starting_parenthesis_depth;
|
||||||
if current_depth > 0 {
|
if current_depth > 0 {
|
||||||
// Its impossible for the next character to end the argument if we're any amount of parenthesis deep
|
// Its impossible for the next character to end the argument if we're any amount of parenthesis deep
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("NoArgumentEnd")));
|
||||||
"NoArgumentEnd".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
if current_depth < 0 {
|
if current_depth < 0 {
|
||||||
// This shouldn't be possible because if depth is 0 then a closing parenthesis should end the argument.
|
// This shouldn't be possible because if depth is 0 then a closing parenthesis should end the argument.
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use crate::context::ExitClass;
|
|||||||
use crate::context::ExitMatcherNode;
|
use crate::context::ExitMatcherNode;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
@@ -39,7 +38,7 @@ pub(crate) fn inline_source_block<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, language) = lang(context, remaining)?;
|
let (remaining, language) = lang(context, remaining)?;
|
||||||
let (remaining, parameters) = opt(parser_with_context!(header)(context))(remaining)?;
|
let (remaining, parameters) = opt(parser_with_context!(header)(context))(remaining)?;
|
||||||
let (remaining, value) = body(context, remaining)?;
|
let (remaining, value) = body(context, remaining)?;
|
||||||
let (remaining, _trailing_whitespace) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((
|
Ok((
|
||||||
@@ -49,6 +48,7 @@ pub(crate) fn inline_source_block<'b, 'g, 'r, 's>(
|
|||||||
language: language.into(),
|
language: language.into(),
|
||||||
parameters: parameters.map(Into::<&str>::into),
|
parameters: parameters.map(Into::<&str>::into),
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
|
post_blank: post_blank.map(Into::<&str>::into),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -125,9 +125,7 @@ fn _header_end<'b, 'g, 'r, 's>(
|
|||||||
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
let current_depth = input.get_bracket_depth() - starting_bracket_depth;
|
||||||
if current_depth > 0 {
|
if current_depth > 0 {
|
||||||
// Its impossible for the next character to end the header if we're any amount of bracket deep
|
// Its impossible for the next character to end the header if we're any amount of bracket deep
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("NoHeaderEnd")));
|
||||||
"NoHeaderEnd".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
if current_depth < 0 {
|
if current_depth < 0 {
|
||||||
// This shouldn't be possible because if depth is 0 then a closing bracket should end the header.
|
// This shouldn't be possible because if depth is 0 then a closing bracket should end the header.
|
||||||
@@ -187,9 +185,7 @@ fn _body_end<'b, 'g, 'r, 's>(
|
|||||||
let current_depth = input.get_brace_depth() - starting_brace_depth;
|
let current_depth = input.get_brace_depth() - starting_brace_depth;
|
||||||
if current_depth > 0 {
|
if current_depth > 0 {
|
||||||
// Its impossible for the next character to end the body if we're any amount of brace deep
|
// Its impossible for the next character to end the body if we're any amount of brace deep
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::Static("NoBodyEnd")));
|
||||||
"NoBodyEnd".into(),
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
if current_depth < 0 {
|
if current_depth < 0 {
|
||||||
// This shouldn't be possible because if depth is 0 then a closing brace should end the body.
|
// This shouldn't be possible because if depth is 0 then a closing brace should end the body.
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ use nom::bytes::complete::tag;
|
|||||||
use nom::bytes::complete::tag_no_case;
|
use nom::bytes::complete::tag_no_case;
|
||||||
use nom::bytes::complete::take_while1;
|
use nom::bytes::complete::take_while1;
|
||||||
use nom::character::complete::anychar;
|
use nom::character::complete::anychar;
|
||||||
use nom::character::complete::line_ending;
|
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::combinator::consumed;
|
use nom::combinator::consumed;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::map;
|
||||||
use nom::combinator::not;
|
use nom::combinator::not;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
@@ -21,24 +20,20 @@ use super::org_source::BracketDepth;
|
|||||||
use super::org_source::OrgSource;
|
use super::org_source::OrgSource;
|
||||||
use super::util::get_consumed;
|
use super::util::get_consumed;
|
||||||
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
use crate::context::Matcher;
|
use super::util::org_line_ending;
|
||||||
|
use crate::context::constants::ORG_ELEMENT_AFFILIATED_KEYWORDS;
|
||||||
|
use crate::context::constants::ORG_ELEMENT_DUAL_KEYWORDS;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
|
use crate::parser::macros::element;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
use crate::types::AffiliatedKeywords;
|
use crate::types::AffiliatedKeywords;
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
|
|
||||||
const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
|
pub(crate) fn filtered_keyword<'s, F: Fn(OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>>(
|
||||||
"caption", "data", "headers", "header", "label", "name", "plot", "resname", "results",
|
|
||||||
"result", "source", "srcname", "tblname",
|
|
||||||
];
|
|
||||||
const ORG_ELEMENT_DUAL_KEYWORDS: [&'static str; 2] = ["caption", "results"];
|
|
||||||
|
|
||||||
pub(crate) fn filtered_keyword<F: Matcher>(
|
|
||||||
key_parser: F,
|
key_parser: F,
|
||||||
) -> impl for<'s> Fn(OrgSource<'s>) -> Res<OrgSource<'s>, Keyword<'s>> {
|
) -> impl Fn(OrgSource<'s>) -> Res<OrgSource<'s>, Keyword<'s>> {
|
||||||
move |input| _filtered_keyword(&key_parser, input)
|
move |input| _filtered_keyword(&key_parser, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +41,7 @@ pub(crate) fn filtered_keyword<F: Matcher>(
|
|||||||
feature = "tracing",
|
feature = "tracing",
|
||||||
tracing::instrument(ret, level = "debug", skip(key_parser))
|
tracing::instrument(ret, level = "debug", skip(key_parser))
|
||||||
)]
|
)]
|
||||||
fn _filtered_keyword<'s, F: Matcher>(
|
fn _filtered_keyword<'s, F: Fn(OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>>(
|
||||||
key_parser: F,
|
key_parser: F,
|
||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, Keyword<'s>> {
|
) -> Res<OrgSource<'s>, Keyword<'s>> {
|
||||||
@@ -54,30 +49,22 @@ fn _filtered_keyword<'s, F: Matcher>(
|
|||||||
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
|
// TODO: When key is a member of org-element-parsed-keywords, value can contain the standard set objects, excluding footnote references.
|
||||||
let (remaining, (consumed_input, (_, _, parsed_key, _))) =
|
let (remaining, (consumed_input, (_, _, parsed_key, _))) =
|
||||||
consumed(tuple((space0, tag("#+"), key_parser, tag(":"))))(input)?;
|
consumed(tuple((space0, tag("#+"), key_parser, tag(":"))))(input)?;
|
||||||
match tuple((
|
|
||||||
space0::<OrgSource<'_>, CustomError<OrgSource<'_>>>,
|
|
||||||
alt((line_ending, eof)),
|
|
||||||
))(remaining)
|
|
||||||
{
|
|
||||||
Ok((remaining, _)) => {
|
|
||||||
return Ok((
|
|
||||||
remaining,
|
|
||||||
Keyword {
|
|
||||||
source: consumed_input.into(),
|
|
||||||
affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
|
|
||||||
key: parsed_key.into(),
|
|
||||||
value: "".into(),
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
};
|
|
||||||
let (remaining, _ws) = space0(remaining)?;
|
let (remaining, _ws) = space0(remaining)?;
|
||||||
let (remaining, parsed_value) = recognize(many_till(
|
if let Ok((remaining, _)) = org_line_ending(remaining) {
|
||||||
anychar,
|
return Ok((
|
||||||
peek(tuple((space0, alt((line_ending, eof))))),
|
remaining,
|
||||||
))(remaining)?;
|
Keyword {
|
||||||
let (remaining, _ws) = tuple((space0, alt((line_ending, eof))))(remaining)?;
|
source: consumed_input.into(),
|
||||||
|
affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
|
||||||
|
key: parsed_key.into(),
|
||||||
|
value: "",
|
||||||
|
post_blank: None,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let (remaining, parsed_value) =
|
||||||
|
recognize(many_till(anychar, peek(tuple((space0, org_line_ending)))))(remaining)?;
|
||||||
|
let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Keyword {
|
Keyword {
|
||||||
@@ -85,6 +72,7 @@ fn _filtered_keyword<'s, F: Matcher>(
|
|||||||
affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
|
affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
|
||||||
key: parsed_key.into(),
|
key: parsed_key.into(),
|
||||||
value: parsed_value.into(),
|
value: parsed_value.into(),
|
||||||
|
post_blank: None,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -103,12 +91,13 @@ where
|
|||||||
AK: IntoIterator<Item = Keyword<'s>>,
|
AK: IntoIterator<Item = Keyword<'s>>,
|
||||||
{
|
{
|
||||||
let (remaining, mut kw) = filtered_keyword(regular_keyword_key)(remaining)?;
|
let (remaining, mut kw) = filtered_keyword(regular_keyword_key)(remaining)?;
|
||||||
let (remaining, _trailing_ws) =
|
let (remaining, post_blank) =
|
||||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
kw.affiliated_keywords =
|
kw.affiliated_keywords =
|
||||||
parse_affiliated_keywords(context.get_global_settings(), affiliated_keywords);
|
parse_affiliated_keywords(context.get_global_settings(), affiliated_keywords);
|
||||||
kw.source = Into::<&str>::into(source);
|
kw.source = Into::<&str>::into(source);
|
||||||
|
kw.post_blank = post_blank.map(Into::<&str>::into);
|
||||||
Ok((remaining, kw))
|
Ok((remaining, kw))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,45 +139,43 @@ fn regular_keyword_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource
|
|||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
alt((
|
element!(dual_affiliated_key, input);
|
||||||
recognize(tuple((dual_affiliated_key, tag("["), optval, tag("]")))),
|
element!(plain_affiliated_key, input);
|
||||||
plain_affiliated_key,
|
element!(export_keyword, input);
|
||||||
export_keyword,
|
Err(nom::Err::Error(CustomError::Static("No affiliated key.")))
|
||||||
))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn plain_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn plain_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
for keyword in ORG_ELEMENT_AFFILIATED_KEYWORDS {
|
for keyword in ORG_ELEMENT_AFFILIATED_KEYWORDS {
|
||||||
let result = tag_no_case::<_, _, CustomError<_>>(keyword)(input);
|
let result = map(
|
||||||
match result {
|
tuple((tag_no_case::<_, _, CustomError>(keyword), peek(tag(":")))),
|
||||||
Ok((remaining, ent)) => {
|
|(key, _)| key,
|
||||||
return Ok((remaining, ent));
|
)(input);
|
||||||
}
|
if let Ok((remaining, ent)) = result {
|
||||||
Err(_) => {}
|
return Ok((remaining, ent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
Err(nom::Err::Error(CustomError::Static("NoKeywordKey")))
|
||||||
"NoKeywordKey".into(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn dual_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
fn dual_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||||
for keyword in ORG_ELEMENT_DUAL_KEYWORDS {
|
for keyword in ORG_ELEMENT_DUAL_KEYWORDS {
|
||||||
let result = tag_no_case::<_, _, CustomError<_>>(keyword)(input);
|
let result = recognize(tuple((
|
||||||
match result {
|
tag_no_case::<_, _, CustomError>(keyword),
|
||||||
Ok((remaining, ent)) => {
|
tag("["),
|
||||||
return Ok((remaining, ent));
|
optval,
|
||||||
}
|
tag("]"),
|
||||||
Err(_) => {}
|
peek(tag(":")),
|
||||||
|
)))(input);
|
||||||
|
if let Ok((remaining, ent)) = result {
|
||||||
|
return Ok((remaining, ent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
Err(nom::Err::Error(CustomError::Static("NoKeywordKey")))
|
||||||
"NoKeywordKey".into(),
|
|
||||||
))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
@@ -216,7 +203,7 @@ fn _optval_end<'s>(
|
|||||||
unreachable!("Exceeded optval bracket depth.")
|
unreachable!("Exceeded optval bracket depth.")
|
||||||
}
|
}
|
||||||
if current_depth == 0 {
|
if current_depth == 0 {
|
||||||
let close_bracket = tag::<_, _, CustomError<_>>("]")(input);
|
let close_bracket = tag::<_, _, CustomError>("]")(input);
|
||||||
if close_bracket.is_ok() {
|
if close_bracket.is_ok() {
|
||||||
return close_bracket;
|
return close_bracket;
|
||||||
}
|
}
|
||||||
@@ -231,3 +218,17 @@ fn export_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
|
|||||||
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
|
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_affiliated_keyword(b: &mut Bencher) {
|
||||||
|
let input = OrgSource::new("#+CAPTION[*foo*]: bar *baz*");
|
||||||
|
|
||||||
|
b.iter(|| assert!(affiliated_keyword(input).is_ok()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::error::Res;
|
|||||||
/// Parses the text in the value of a #+TODO keyword.
|
/// Parses the text in the value of a #+TODO keyword.
|
||||||
///
|
///
|
||||||
/// Example input: "foo bar baz | lorem ipsum"
|
/// Example input: "foo bar baz | lorem ipsum"
|
||||||
pub(crate) fn todo_keywords<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, Vec<&'s str>)> {
|
pub(crate) fn todo_keywords(input: &str) -> Res<&str, (Vec<&str>, Vec<&str>)> {
|
||||||
let (remaining, mut before_pipe_words) = separated_list0(space1, todo_keyword_word)(input)?;
|
let (remaining, mut before_pipe_words) = separated_list0(space1, todo_keyword_word)(input)?;
|
||||||
let (remaining, after_pipe_words) = opt(tuple((
|
let (remaining, after_pipe_words) = opt(tuple((
|
||||||
tuple((space0, tag("|"), space0)),
|
tuple((space0, tag("|"), space0)),
|
||||||
@@ -30,12 +30,9 @@ pub(crate) fn todo_keywords<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, V
|
|||||||
Ok((remaining, (before_pipe_words, after_pipe_words)))
|
Ok((remaining, (before_pipe_words, after_pipe_words)))
|
||||||
} else if !before_pipe_words.is_empty() {
|
} else if !before_pipe_words.is_empty() {
|
||||||
// If there was no pipe, then the last word becomes a completion state instead.
|
// If there was no pipe, then the last word becomes a completion state instead.
|
||||||
let mut after_pipe_words = Vec::with_capacity(1);
|
let after_pipe_words = vec![before_pipe_words
|
||||||
after_pipe_words.push(
|
.pop()
|
||||||
before_pipe_words
|
.expect("If-statement proves this is Some.")];
|
||||||
.pop()
|
|
||||||
.expect("If-statement proves this is Some."),
|
|
||||||
);
|
|
||||||
Ok((remaining, (before_pipe_words, after_pipe_words)))
|
Ok((remaining, (before_pipe_words, after_pipe_words)))
|
||||||
} else {
|
} else {
|
||||||
// No words founds
|
// No words founds
|
||||||
@@ -43,7 +40,7 @@ pub(crate) fn todo_keywords<'s>(input: &'s str) -> Res<&'s str, (Vec<&'s str>, V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn todo_keyword_word<'s>(input: &'s str) -> Res<&'s str, &'s str> {
|
fn todo_keyword_word(input: &str) -> Res<&str, &str> {
|
||||||
let (remaining, keyword) = verify(take_till(|c| "( \t\r\n|".contains(c)), |result: &str| {
|
let (remaining, keyword) = verify(take_till(|c| "( \t\r\n|".contains(c)), |result: &str| {
|
||||||
!result.is_empty()
|
!result.is_empty()
|
||||||
})(input)?;
|
})(input)?;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user