-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Fleenor
committed
Dec 29, 2013
1 parent
22c0b3e
commit 8aeee45
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2013 Andrew Fleenor | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# apatch | ||
|
||
apatch is an implementation of associative text patching in OCaml. My theory | ||
and motivation for associative patching is alread laid out decently at | ||
[adiff](https://github.com/andrewf/adiff), the project for my Clojure | ||
implementation. To understand this project, you can skip the part about | ||
"Nested Patches", since it doesn't matter for text and I'm not sure how | ||
sound it is. The main difference for this project is that I have implemented | ||
the run-length encoding optimization mentioned in the "what about real life?" | ||
section. | ||
|
||
## Writing patches | ||
|
||
The text format for patches is pretty simple. | ||
|
||
It's a %[D13]beautiful day. %[K34] | ||
We can do literal \%[K3] too. | ||
|
||
The `%[...]` syntax introduces what I call a "reader form", a patch element | ||
that either reads in or ignores/deletes characters from the source. As you | ||
might guess, `%[D13]` drops 13 characters and `%[K34]` copies in 34 | ||
characters. `\%[` results in a simple insertion of `%[`, so you can write | ||
patches for documents that talk about patches. The `%[..]` syntax was chosen | ||
for minimal interference with other languages. | ||
|
||
## Applying patches | ||
|
||
First, compile. If you have OCaml installed on your system, you can simply | ||
`make all`, which builds `apply` and the test programs. | ||
|
||
If you want to do patching in an OCaml program, `test.ml` has a number of | ||
examples of creating and applying patches. | ||
|
||
Using the command-line `apply` program is pretty simple. In short: | ||
`./apply patch < source > result`. You can try this with the included | ||
patch files: | ||
|
||
$ ./apply patchy.patch < sourcy.patch | ||
ABCabcd | ||
|
||
Watch out for implicit newlines at the end of files. If you get a mysterious | ||
"dangling insert" error, try increasing the size of a reader form in the | ||
patch by 1. | ||
|
||
## Future work | ||
|
||
Obviously, these sorts of patches are not much fun to write by hand. Someday | ||
I'll get around to implementing diffing. Also, both "adiff" and "apatch" are | ||
pretty lame names, and I need to invent a better one. |