├── .gitattributes ├── .gitignore ├── .travis.yml ├── Cargo.lock ├── Cargo.toml ├── LICENSE.md ├── README.md ├── ci ├── after_success.sh ├── before_script.sh ├── codecov.yml └── script.sh ├── src ├── main.rs └── parser │ ├── cell.rs │ ├── cell_group_data.rs │ ├── header.rs │ ├── mod.rs │ ├── notebook.rs │ ├── utilities.rs │ └── whitespace.rs └── tests ├── .gitignore ├── notebook.nb ├── notebook.sh └── notebooks.rs /.gitattributes: -------------------------------------------------------------------------------- 1 | tests/*.nb !filter 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | **/*.rs.bk 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | 3 | sudo: required 4 | 5 | rust: 6 | - stable 7 | - beta 8 | - nightly 9 | 10 | matrix: 11 | allow_failures: 12 | - rust: beta 13 | - rust: nightly 14 | 15 | env: 16 | global: 17 | - RUSTFLAGS="-C link-dead-code -D warnings -D missing_docs" 18 | 19 | cache: cargo 20 | 21 | addons: 22 | apt: 23 | update: true 24 | packages: 25 | - libcurl4-openssl-dev 26 | - libelf-dev 27 | - libdw-dev 28 | - cmake 29 | - gcc 30 | - binutils-dev 31 | - libiberty-dev 32 | - libgsl0-dev 33 | 34 | before_script: 35 | - | 36 | if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then 37 | export FEATURES="--features nightly"; 38 | else 39 | export FEATURES=""; 40 | fi 41 | - ./ci/before_script.sh 42 | 43 | script: 44 | - ./ci/script.sh 45 | 46 | after_success: 47 | - ./ci/after_success.sh 48 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "ansi_term" 5 | version = "0.11.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | dependencies = [ 8 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "atty" 13 | version = "0.2.11" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | dependencies = [ 16 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 17 | "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 18 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 19 | ] 20 | 21 | [[package]] 22 | name = "autocfg" 23 | version = "0.1.2" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | 26 | [[package]] 27 | name = "bitflags" 28 | version = "1.0.4" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | 31 | [[package]] 32 | name = "cfg-if" 33 | version = "0.1.7" 34 | source = "registry+https://github.com/rust-lang/crates.io-index" 35 | 36 | [[package]] 37 | name = "chrono" 38 | version = "0.4.6" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | dependencies = [ 41 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 42 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 43 | "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", 44 | ] 45 | 46 | [[package]] 47 | name = "clap" 48 | version = "2.33.0" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | dependencies = [ 51 | "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 52 | "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 53 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 54 | "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 55 | "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 56 | "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 57 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 58 | "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 59 | ] 60 | 61 | [[package]] 62 | name = "cloudabi" 63 | version = "0.0.3" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | dependencies = [ 66 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 67 | ] 68 | 69 | [[package]] 70 | name = "fuchsia-cprng" 71 | version = "0.1.1" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "kernel32-sys" 76 | version = "0.2.2" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | dependencies = [ 79 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 80 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 81 | ] 82 | 83 | [[package]] 84 | name = "lazy_static" 85 | version = "1.3.0" 86 | source = "registry+https://github.com/rust-lang/crates.io-index" 87 | 88 | [[package]] 89 | name = "libc" 90 | version = "0.2.51" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | 93 | [[package]] 94 | name = "log" 95 | version = "0.4.6" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | dependencies = [ 98 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 99 | ] 100 | 101 | [[package]] 102 | name = "mathematica-notebook-filter" 103 | version = "0.2.3" 104 | dependencies = [ 105 | "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 106 | "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", 107 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 108 | "stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 109 | "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", 110 | ] 111 | 112 | [[package]] 113 | name = "num-integer" 114 | version = "0.1.39" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | dependencies = [ 117 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 118 | ] 119 | 120 | [[package]] 121 | name = "num-traits" 122 | version = "0.2.6" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | 125 | [[package]] 126 | name = "rand" 127 | version = "0.6.5" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | dependencies = [ 130 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 131 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 132 | "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 133 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 134 | "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 135 | "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 136 | "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 137 | "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 138 | "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 139 | "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 140 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 141 | ] 142 | 143 | [[package]] 144 | name = "rand_chacha" 145 | version = "0.1.1" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | dependencies = [ 148 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 149 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 150 | ] 151 | 152 | [[package]] 153 | name = "rand_core" 154 | version = "0.3.1" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | dependencies = [ 157 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 158 | ] 159 | 160 | [[package]] 161 | name = "rand_core" 162 | version = "0.4.0" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | 165 | [[package]] 166 | name = "rand_hc" 167 | version = "0.1.0" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | dependencies = [ 170 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 171 | ] 172 | 173 | [[package]] 174 | name = "rand_isaac" 175 | version = "0.1.1" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | dependencies = [ 178 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 179 | ] 180 | 181 | [[package]] 182 | name = "rand_jitter" 183 | version = "0.1.3" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | dependencies = [ 186 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 187 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 188 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 189 | ] 190 | 191 | [[package]] 192 | name = "rand_os" 193 | version = "0.1.3" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | dependencies = [ 196 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 197 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 198 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 199 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 200 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 201 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 202 | ] 203 | 204 | [[package]] 205 | name = "rand_pcg" 206 | version = "0.1.2" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | dependencies = [ 209 | "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 210 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 211 | ] 212 | 213 | [[package]] 214 | name = "rand_xorshift" 215 | version = "0.1.1" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | dependencies = [ 218 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 219 | ] 220 | 221 | [[package]] 222 | name = "rdrand" 223 | version = "0.4.0" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | dependencies = [ 226 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 227 | ] 228 | 229 | [[package]] 230 | name = "redox_syscall" 231 | version = "0.1.54" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | 234 | [[package]] 235 | name = "redox_termios" 236 | version = "0.1.1" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | dependencies = [ 239 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 240 | ] 241 | 242 | [[package]] 243 | name = "remove_dir_all" 244 | version = "0.5.1" 245 | source = "registry+https://github.com/rust-lang/crates.io-index" 246 | dependencies = [ 247 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 248 | ] 249 | 250 | [[package]] 251 | name = "stderrlog" 252 | version = "0.4.1" 253 | source = "registry+https://github.com/rust-lang/crates.io-index" 254 | dependencies = [ 255 | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 256 | "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 257 | "termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 258 | "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 259 | ] 260 | 261 | [[package]] 262 | name = "strsim" 263 | version = "0.8.0" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | 266 | [[package]] 267 | name = "tempfile" 268 | version = "3.0.7" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | dependencies = [ 271 | "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 272 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 273 | "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 274 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 275 | "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 276 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 277 | ] 278 | 279 | [[package]] 280 | name = "term_size" 281 | version = "0.3.1" 282 | source = "registry+https://github.com/rust-lang/crates.io-index" 283 | dependencies = [ 284 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 285 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 286 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 287 | ] 288 | 289 | [[package]] 290 | name = "termcolor" 291 | version = "0.3.6" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | dependencies = [ 294 | "wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 295 | ] 296 | 297 | [[package]] 298 | name = "termion" 299 | version = "1.5.1" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | dependencies = [ 302 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 303 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 304 | "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 305 | ] 306 | 307 | [[package]] 308 | name = "textwrap" 309 | version = "0.11.0" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | dependencies = [ 312 | "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 313 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 314 | ] 315 | 316 | [[package]] 317 | name = "thread_local" 318 | version = "0.3.6" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | dependencies = [ 321 | "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 322 | ] 323 | 324 | [[package]] 325 | name = "time" 326 | version = "0.1.42" 327 | source = "registry+https://github.com/rust-lang/crates.io-index" 328 | dependencies = [ 329 | "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", 330 | "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", 331 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 332 | ] 333 | 334 | [[package]] 335 | name = "unicode-width" 336 | version = "0.1.5" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | 339 | [[package]] 340 | name = "vec_map" 341 | version = "0.8.1" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | 344 | [[package]] 345 | name = "winapi" 346 | version = "0.2.8" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | 349 | [[package]] 350 | name = "winapi" 351 | version = "0.3.7" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | dependencies = [ 354 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 355 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 356 | ] 357 | 358 | [[package]] 359 | name = "winapi-build" 360 | version = "0.1.1" 361 | source = "registry+https://github.com/rust-lang/crates.io-index" 362 | 363 | [[package]] 364 | name = "winapi-i686-pc-windows-gnu" 365 | version = "0.4.0" 366 | source = "registry+https://github.com/rust-lang/crates.io-index" 367 | 368 | [[package]] 369 | name = "winapi-x86_64-pc-windows-gnu" 370 | version = "0.4.0" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | 373 | [[package]] 374 | name = "wincolor" 375 | version = "0.1.6" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | dependencies = [ 378 | "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 379 | ] 380 | 381 | [metadata] 382 | "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 383 | "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" 384 | "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" 385 | "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" 386 | "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" 387 | "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" 388 | "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" 389 | "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 390 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 391 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 392 | "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 393 | "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" 394 | "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" 395 | "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" 396 | "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 397 | "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" 398 | "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" 399 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 400 | "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" 401 | "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" 402 | "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" 403 | "checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" 404 | "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" 405 | "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" 406 | "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" 407 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 408 | "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" 409 | "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" 410 | "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" 411 | "checksum stderrlog 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "61dc66b7ae72b65636dbf36326f9638fb3ba27871bb737a62e2c309b87d91b70" 412 | "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 413 | "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" 414 | "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" 415 | "checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83" 416 | "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" 417 | "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 418 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" 419 | "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" 420 | "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" 421 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" 422 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 423 | "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" 424 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 425 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 426 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 427 | "checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" 428 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mathematica-notebook-filter" 3 | version = "0.2.3" 4 | authors = ["JP-Ellis "] 5 | 6 | readme = "README.md" 7 | description = """ 8 | `mathematica-notebook-filter` parses Mathematica notebook files and strips them of superfluous 9 | information so that they can be committed into version control systems more 10 | easily. 11 | """ 12 | 13 | documentation = "https://github.com/JP-Ellis/mathematica-notebook-filter" 14 | homepage = "https://github.com/JP-Ellis/mathematica-notebook-filter" 15 | repository = "https://github.com/JP-Ellis/mathematica-notebook-filter" 16 | 17 | keywords = ["mathematica", "vcs", "cli", "parser"] 18 | categories = ["command-line-utilities", "text-processing"] 19 | 20 | license = "GPL-3.0" 21 | 22 | edition = "2018" 23 | 24 | [badges] 25 | travis-ci = { repository = "JP-Ellis/mathematica-notebook-filter", branch = "master" } 26 | codecov = { repository = "JP-Ellis/mathematica-notebook-filter", branch = "master", service = "github" } 27 | 28 | [dependencies] 29 | atty = "0.2.11" 30 | clap = { version = "2.33.0", features = ["wrap_help"] } 31 | log = "0.4.6" 32 | stderrlog = "0.4.1" 33 | tempfile = "3.0.7" 34 | 35 | [features] 36 | default = [] 37 | nightly = [] 38 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ### GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | ### Preamble 12 | 13 | The GNU General Public License is a free, copyleft license for 14 | software and other kinds of works. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | the GNU General Public License is intended to guarantee your freedom 19 | to share and change all versions of a program--to make sure it remains 20 | free software for all its users. We, the Free Software Foundation, use 21 | the GNU General Public License for most of our software; it applies 22 | also to any other work released this way by its authors. You can apply 23 | it to your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | them if you wish), that you receive source code or can get it if you 29 | want it, that you can change the software or use pieces of it in new 30 | free programs, and that you know you can do these things. 31 | 32 | To protect your rights, we need to prevent others from denying you 33 | these rights or asking you to surrender the rights. Therefore, you 34 | have certain responsibilities if you distribute copies of the 35 | software, or if you modify it: responsibilities to respect the freedom 36 | of others. 37 | 38 | For example, if you distribute copies of such a program, whether 39 | gratis or for a fee, you must pass on to the recipients the same 40 | freedoms that you received. You must make sure that they, too, receive 41 | or can get the source code. And you must show them these terms so they 42 | know their rights. 43 | 44 | Developers that use the GNU GPL protect your rights with two steps: 45 | (1) assert copyright on the software, and (2) offer you this License 46 | giving you legal permission to copy, distribute and/or modify it. 47 | 48 | For the developers' and authors' protection, the GPL clearly explains 49 | that there is no warranty for this free software. For both users' and 50 | authors' sake, the GPL requires that modified versions be marked as 51 | changed, so that their problems will not be attributed erroneously to 52 | authors of previous versions. 53 | 54 | Some devices are designed to deny users access to install or run 55 | modified versions of the software inside them, although the 56 | manufacturer can do so. This is fundamentally incompatible with the 57 | aim of protecting users' freedom to change the software. The 58 | systematic pattern of such abuse occurs in the area of products for 59 | individuals to use, which is precisely where it is most unacceptable. 60 | Therefore, we have designed this version of the GPL to prohibit the 61 | practice for those products. If such problems arise substantially in 62 | other domains, we stand ready to extend this provision to those 63 | domains in future versions of the GPL, as needed to protect the 64 | freedom of users. 65 | 66 | Finally, every program is threatened constantly by software patents. 67 | States should not allow patents to restrict development and use of 68 | software on general-purpose computers, but in those that do, we wish 69 | to avoid the special danger that patents applied to a free program 70 | could make it effectively proprietary. To prevent this, the GPL 71 | assures that patents cannot be used to render the program non-free. 72 | 73 | The precise terms and conditions for copying, distribution and 74 | modification follow. 75 | 76 | ### TERMS AND CONDITIONS 77 | 78 | #### 0. Definitions. 79 | 80 | "This License" refers to version 3 of the GNU General Public License. 81 | 82 | "Copyright" also means copyright-like laws that apply to other kinds 83 | of works, such as semiconductor masks. 84 | 85 | "The Program" refers to any copyrightable work licensed under this 86 | License. Each licensee is addressed as "you". "Licensees" and 87 | "recipients" may be individuals or organizations. 88 | 89 | To "modify" a work means to copy from or adapt all or part of the work 90 | in a fashion requiring copyright permission, other than the making of 91 | an exact copy. The resulting work is called a "modified version" of 92 | the earlier work or a work "based on" the earlier work. 93 | 94 | A "covered work" means either the unmodified Program or a work based 95 | on the Program. 96 | 97 | To "propagate" a work means to do anything with it that, without 98 | permission, would make you directly or secondarily liable for 99 | infringement under applicable copyright law, except executing it on a 100 | computer or modifying a private copy. Propagation includes copying, 101 | distribution (with or without modification), making available to the 102 | public, and in some countries other activities as well. 103 | 104 | To "convey" a work means any kind of propagation that enables other 105 | parties to make or receive copies. Mere interaction with a user 106 | through a computer network, with no transfer of a copy, is not 107 | conveying. 108 | 109 | An interactive user interface displays "Appropriate Legal Notices" to 110 | the extent that it includes a convenient and prominently visible 111 | feature that (1) displays an appropriate copyright notice, and (2) 112 | tells the user that there is no warranty for the work (except to the 113 | extent that warranties are provided), that licensees may convey the 114 | work under this License, and how to view a copy of this License. If 115 | the interface presents a list of user commands or options, such as a 116 | menu, a prominent item in the list meets this criterion. 117 | 118 | #### 1. Source Code. 119 | 120 | The "source code" for a work means the preferred form of the work for 121 | making modifications to it. "Object code" means any non-source form of 122 | a work. 123 | 124 | A "Standard Interface" means an interface that either is an official 125 | standard defined by a recognized standards body, or, in the case of 126 | interfaces specified for a particular programming language, one that 127 | is widely used among developers working in that language. 128 | 129 | The "System Libraries" of an executable work include anything, other 130 | than the work as a whole, that (a) is included in the normal form of 131 | packaging a Major Component, but which is not part of that Major 132 | Component, and (b) serves only to enable use of the work with that 133 | Major Component, or to implement a Standard Interface for which an 134 | implementation is available to the public in source code form. A 135 | "Major Component", in this context, means a major essential component 136 | (kernel, window system, and so on) of the specific operating system 137 | (if any) on which the executable work runs, or a compiler used to 138 | produce the work, or an object code interpreter used to run it. 139 | 140 | The "Corresponding Source" for a work in object code form means all 141 | the source code needed to generate, install, and (for an executable 142 | work) run the object code and to modify the work, including scripts to 143 | control those activities. However, it does not include the work's 144 | System Libraries, or general-purpose tools or generally available free 145 | programs which are used unmodified in performing those activities but 146 | which are not part of the work. For example, Corresponding Source 147 | includes interface definition files associated with source files for 148 | the work, and the source code for shared libraries and dynamically 149 | linked subprograms that the work is specifically designed to require, 150 | such as by intimate data communication or control flow between those 151 | subprograms and other parts of the work. 152 | 153 | The Corresponding Source need not include anything that users can 154 | regenerate automatically from other parts of the Corresponding Source. 155 | 156 | The Corresponding Source for a work in source code form is that same 157 | work. 158 | 159 | #### 2. Basic Permissions. 160 | 161 | All rights granted under this License are granted for the term of 162 | copyright on the Program, and are irrevocable provided the stated 163 | conditions are met. This License explicitly affirms your unlimited 164 | permission to run the unmodified Program. The output from running a 165 | covered work is covered by this License only if the output, given its 166 | content, constitutes a covered work. This License acknowledges your 167 | rights of fair use or other equivalent, as provided by copyright law. 168 | 169 | You may make, run and propagate covered works that you do not convey, 170 | without conditions so long as your license otherwise remains in force. 171 | You may convey covered works to others for the sole purpose of having 172 | them make modifications exclusively for you, or provide you with 173 | facilities for running those works, provided that you comply with the 174 | terms of this License in conveying all material for which you do not 175 | control copyright. Those thus making or running the covered works for 176 | you must do so exclusively on your behalf, under your direction and 177 | control, on terms that prohibit them from making any copies of your 178 | copyrighted material outside their relationship with you. 179 | 180 | Conveying under any other circumstances is permitted solely under the 181 | conditions stated below. Sublicensing is not allowed; section 10 makes 182 | it unnecessary. 183 | 184 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 185 | 186 | No covered work shall be deemed part of an effective technological 187 | measure under any applicable law fulfilling obligations under article 188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 189 | similar laws prohibiting or restricting circumvention of such 190 | measures. 191 | 192 | When you convey a covered work, you waive any legal power to forbid 193 | circumvention of technological measures to the extent such 194 | circumvention is effected by exercising rights under this License with 195 | respect to the covered work, and you disclaim any intention to limit 196 | operation or modification of the work as a means of enforcing, against 197 | the work's users, your or third parties' legal rights to forbid 198 | circumvention of technological measures. 199 | 200 | #### 4. Conveying Verbatim Copies. 201 | 202 | You may convey verbatim copies of the Program's source code as you 203 | receive it, in any medium, provided that you conspicuously and 204 | appropriately publish on each copy an appropriate copyright notice; 205 | keep intact all notices stating that this License and any 206 | non-permissive terms added in accord with section 7 apply to the code; 207 | keep intact all notices of the absence of any warranty; and give all 208 | recipients a copy of this License along with the Program. 209 | 210 | You may charge any price or no price for each copy that you convey, 211 | and you may offer support or warranty protection for a fee. 212 | 213 | #### 5. Conveying Modified Source Versions. 214 | 215 | You may convey a work based on the Program, or the modifications to 216 | produce it from the Program, in the form of source code under the 217 | terms of section 4, provided that you also meet all of these 218 | conditions: 219 | 220 | - a) The work must carry prominent notices stating that you modified 221 | it, and giving a relevant date. 222 | - b) The work must carry prominent notices stating that it is 223 | released under this License and any conditions added under 224 | section 7. This requirement modifies the requirement in section 4 225 | to "keep intact all notices". 226 | - c) You must license the entire work, as a whole, under this 227 | License to anyone who comes into possession of a copy. This 228 | License will therefore apply, along with any applicable section 7 229 | additional terms, to the whole of the work, and all its parts, 230 | regardless of how they are packaged. This License gives no 231 | permission to license the work in any other way, but it does not 232 | invalidate such permission if you have separately received it. 233 | - d) If the work has interactive user interfaces, each must display 234 | Appropriate Legal Notices; however, if the Program has interactive 235 | interfaces that do not display Appropriate Legal Notices, your 236 | work need not make them do so. 237 | 238 | A compilation of a covered work with other separate and independent 239 | works, which are not by their nature extensions of the covered work, 240 | and which are not combined with it such as to form a larger program, 241 | in or on a volume of a storage or distribution medium, is called an 242 | "aggregate" if the compilation and its resulting copyright are not 243 | used to limit the access or legal rights of the compilation's users 244 | beyond what the individual works permit. Inclusion of a covered work 245 | in an aggregate does not cause this License to apply to the other 246 | parts of the aggregate. 247 | 248 | #### 6. Conveying Non-Source Forms. 249 | 250 | You may convey a covered work in object code form under the terms of 251 | sections 4 and 5, provided that you also convey the machine-readable 252 | Corresponding Source under the terms of this License, in one of these 253 | ways: 254 | 255 | - a) Convey the object code in, or embodied in, a physical product 256 | (including a physical distribution medium), accompanied by the 257 | Corresponding Source fixed on a durable physical medium 258 | customarily used for software interchange. 259 | - b) Convey the object code in, or embodied in, a physical product 260 | (including a physical distribution medium), accompanied by a 261 | written offer, valid for at least three years and valid for as 262 | long as you offer spare parts or customer support for that product 263 | model, to give anyone who possesses the object code either (1) a 264 | copy of the Corresponding Source for all the software in the 265 | product that is covered by this License, on a durable physical 266 | medium customarily used for software interchange, for a price no 267 | more than your reasonable cost of physically performing this 268 | conveying of source, or (2) access to copy the Corresponding 269 | Source from a network server at no charge. 270 | - c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | - d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | - e) Convey the object code using peer-to-peer transmission, 288 | provided you inform other peers where the object code and 289 | Corresponding Source of the work are being offered to the general 290 | public at no charge under subsection 6d. 291 | 292 | A separable portion of the object code, whose source code is excluded 293 | from the Corresponding Source as a System Library, need not be 294 | included in conveying the object code work. 295 | 296 | A "User Product" is either (1) a "consumer product", which means any 297 | tangible personal property which is normally used for personal, 298 | family, or household purposes, or (2) anything designed or sold for 299 | incorporation into a dwelling. In determining whether a product is a 300 | consumer product, doubtful cases shall be resolved in favor of 301 | coverage. For a particular product received by a particular user, 302 | "normally used" refers to a typical or common use of that class of 303 | product, regardless of the status of the particular user or of the way 304 | in which the particular user actually uses, or expects or is expected 305 | to use, the product. A product is a consumer product regardless of 306 | whether the product has substantial commercial, industrial or 307 | non-consumer uses, unless such uses represent the only significant 308 | mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to 312 | install and execute modified versions of a covered work in that User 313 | Product from a modified version of its Corresponding Source. The 314 | information must suffice to ensure that the continued functioning of 315 | the modified object code is in no case prevented or interfered with 316 | solely because modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or 331 | updates for a work that has been modified or installed by the 332 | recipient, or for the User Product in which it has been modified or 333 | installed. Access to a network may be denied when the modification 334 | itself materially and adversely affects the operation of the network 335 | or violates the rules and protocols for communication across the 336 | network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | #### 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders 364 | of that material) supplement the terms of this License with terms: 365 | 366 | - a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | - b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | - c) Prohibiting misrepresentation of the origin of that material, 372 | or requiring that modified versions of such material be marked in 373 | reasonable ways as different from the original version; or 374 | - d) Limiting the use for publicity purposes of names of licensors 375 | or authors of the material; or 376 | - e) Declining to grant rights under trademark law for use of some 377 | trade names, trademarks, or service marks; or 378 | - f) Requiring indemnification of licensors and authors of that 379 | material by anyone who conveys the material (or modified versions 380 | of it) with contractual assumptions of liability to the recipient, 381 | for any liability that these contractual assumptions directly 382 | impose on those licensors and authors. 383 | 384 | All other non-permissive additional terms are considered "further 385 | restrictions" within the meaning of section 10. If the Program as you 386 | received it, or any part of it, contains a notice stating that it is 387 | governed by this License along with a term that is a further 388 | restriction, you may remove that term. If a license document contains 389 | a further restriction but permits relicensing or conveying under this 390 | License, you may add to a covered work material governed by the terms 391 | of that license document, provided that the further restriction does 392 | not survive such relicensing or conveying. 393 | 394 | If you add terms to a covered work in accord with this section, you 395 | must place, in the relevant source files, a statement of the 396 | additional terms that apply to those files, or a notice indicating 397 | where to find the applicable terms. 398 | 399 | Additional terms, permissive or non-permissive, may be stated in the 400 | form of a separately written license, or stated as exceptions; the 401 | above requirements apply either way. 402 | 403 | #### 8. Termination. 404 | 405 | You may not propagate or modify a covered work except as expressly 406 | provided under this License. Any attempt otherwise to propagate or 407 | modify it is void, and will automatically terminate your rights under 408 | this License (including any patent licenses granted under the third 409 | paragraph of section 11). 410 | 411 | However, if you cease all violation of this License, then your license 412 | from a particular copyright holder is reinstated (a) provisionally, 413 | unless and until the copyright holder explicitly and finally 414 | terminates your license, and (b) permanently, if the copyright holder 415 | fails to notify you of the violation by some reasonable means prior to 416 | 60 days after the cessation. 417 | 418 | Moreover, your license from a particular copyright holder is 419 | reinstated permanently if the copyright holder notifies you of the 420 | violation by some reasonable means, this is the first time you have 421 | received notice of violation of this License (for any work) from that 422 | copyright holder, and you cure the violation prior to 30 days after 423 | your receipt of the notice. 424 | 425 | Termination of your rights under this section does not terminate the 426 | licenses of parties who have received copies or rights from you under 427 | this License. If your rights have been terminated and not permanently 428 | reinstated, you do not qualify to receive new licenses for the same 429 | material under section 10. 430 | 431 | #### 9. Acceptance Not Required for Having Copies. 432 | 433 | You are not required to accept this License in order to receive or run 434 | a copy of the Program. Ancillary propagation of a covered work 435 | occurring solely as a consequence of using peer-to-peer transmission 436 | to receive a copy likewise does not require acceptance. However, 437 | nothing other than this License grants you permission to propagate or 438 | modify any covered work. These actions infringe copyright if you do 439 | not accept this License. Therefore, by modifying or propagating a 440 | covered work, you indicate your acceptance of this License to do so. 441 | 442 | #### 10. Automatic Licensing of Downstream Recipients. 443 | 444 | Each time you convey a covered work, the recipient automatically 445 | receives a license from the original licensors, to run, modify and 446 | propagate that work, subject to this License. You are not responsible 447 | for enforcing compliance by third parties with this License. 448 | 449 | An "entity transaction" is a transaction transferring control of an 450 | organization, or substantially all assets of one, or subdividing an 451 | organization, or merging organizations. If propagation of a covered 452 | work results from an entity transaction, each party to that 453 | transaction who receives a copy of the work also receives whatever 454 | licenses to the work the party's predecessor in interest had or could 455 | give under the previous paragraph, plus a right to possession of the 456 | Corresponding Source of the work from the predecessor in interest, if 457 | the predecessor has it or can get it with reasonable efforts. 458 | 459 | You may not impose any further restrictions on the exercise of the 460 | rights granted or affirmed under this License. For example, you may 461 | not impose a license fee, royalty, or other charge for exercise of 462 | rights granted under this License, and you may not initiate litigation 463 | (including a cross-claim or counterclaim in a lawsuit) alleging that 464 | any patent claim is infringed by making, using, selling, offering for 465 | sale, or importing the Program or any portion of it. 466 | 467 | #### 11. Patents. 468 | 469 | A "contributor" is a copyright holder who authorizes use under this 470 | License of the Program or a work on which the Program is based. The 471 | work thus licensed is called the contributor's "contributor version". 472 | 473 | A contributor's "essential patent claims" are all patent claims owned 474 | or controlled by the contributor, whether already acquired or 475 | hereafter acquired, that would be infringed by some manner, permitted 476 | by this License, of making, using, or selling its contributor version, 477 | but do not include claims that would be infringed only as a 478 | consequence of further modification of the contributor version. For 479 | purposes of this definition, "control" includes the right to grant 480 | patent sublicenses in a manner consistent with the requirements of 481 | this License. 482 | 483 | Each contributor grants you a non-exclusive, worldwide, royalty-free 484 | patent license under the contributor's essential patent claims, to 485 | make, use, sell, offer for sale, import and otherwise run, modify and 486 | propagate the contents of its contributor version. 487 | 488 | In the following three paragraphs, a "patent license" is any express 489 | agreement or commitment, however denominated, not to enforce a patent 490 | (such as an express permission to practice a patent or covenant not to 491 | sue for patent infringement). To "grant" such a patent license to a 492 | party means to make such an agreement or commitment not to enforce a 493 | patent against the party. 494 | 495 | If you convey a covered work, knowingly relying on a patent license, 496 | and the Corresponding Source of the work is not available for anyone 497 | to copy, free of charge and under the terms of this License, through a 498 | publicly available network server or other readily accessible means, 499 | then you must either (1) cause the Corresponding Source to be so 500 | available, or (2) arrange to deprive yourself of the benefit of the 501 | patent license for this particular work, or (3) arrange, in a manner 502 | consistent with the requirements of this License, to extend the patent 503 | license to downstream recipients. "Knowingly relying" means you have 504 | actual knowledge that, but for the patent license, your conveying the 505 | covered work in a country, or your recipient's use of the covered work 506 | in a country, would infringe one or more identifiable patents in that 507 | country that you have reason to believe are valid. 508 | 509 | If, pursuant to or in connection with a single transaction or 510 | arrangement, you convey, or propagate by procuring conveyance of, a 511 | covered work, and grant a patent license to some of the parties 512 | receiving the covered work authorizing them to use, propagate, modify 513 | or convey a specific copy of the covered work, then the patent license 514 | you grant is automatically extended to all recipients of the covered 515 | work and works based on it. 516 | 517 | A patent license is "discriminatory" if it does not include within the 518 | scope of its coverage, prohibits the exercise of, or is conditioned on 519 | the non-exercise of one or more of the rights that are specifically 520 | granted under this License. You may not convey a covered work if you 521 | are a party to an arrangement with a third party that is in the 522 | business of distributing software, under which you make payment to the 523 | third party based on the extent of your activity of conveying the 524 | work, and under which the third party grants, to any of the parties 525 | who would receive the covered work from you, a discriminatory patent 526 | license (a) in connection with copies of the covered work conveyed by 527 | you (or copies made from those copies), or (b) primarily for and in 528 | connection with specific products or compilations that contain the 529 | covered work, unless you entered into that arrangement, or that patent 530 | license was granted, prior to 28 March 2007. 531 | 532 | Nothing in this License shall be construed as excluding or limiting 533 | any implied license or other defenses to infringement that may 534 | otherwise be available to you under applicable patent law. 535 | 536 | #### 12. No Surrender of Others' Freedom. 537 | 538 | If conditions are imposed on you (whether by court order, agreement or 539 | otherwise) that contradict the conditions of this License, they do not 540 | excuse you from the conditions of this License. If you cannot convey a 541 | covered work so as to satisfy simultaneously your obligations under 542 | this License and any other pertinent obligations, then as a 543 | consequence you may not convey it at all. For example, if you agree to 544 | terms that obligate you to collect a royalty for further conveying 545 | from those to whom you convey the Program, the only way you could 546 | satisfy both those terms and this License would be to refrain entirely 547 | from conveying the Program. 548 | 549 | #### 13. Use with the GNU Affero General Public License. 550 | 551 | Notwithstanding any other provision of this License, you have 552 | permission to link or combine any covered work with a work licensed 553 | under version 3 of the GNU Affero General Public License into a single 554 | combined work, and to convey the resulting work. The terms of this 555 | License will continue to apply to the part which is the covered work, 556 | but the special requirements of the GNU Affero General Public License, 557 | section 13, concerning interaction through a network will apply to the 558 | combination as such. 559 | 560 | #### 14. Revised Versions of this License. 561 | 562 | The Free Software Foundation may publish revised and/or new versions 563 | of the GNU General Public License from time to time. Such new versions 564 | will be similar in spirit to the present version, but may differ in 565 | detail to address new problems or concerns. 566 | 567 | Each version is given a distinguishing version number. If the Program 568 | specifies that a certain numbered version of the GNU General Public 569 | License "or any later version" applies to it, you have the option of 570 | following the terms and conditions either of that numbered version or 571 | of any later version published by the Free Software Foundation. If the 572 | Program does not specify a version number of the GNU General Public 573 | License, you may choose any version ever published by the Free 574 | Software Foundation. 575 | 576 | If the Program specifies that a proxy can decide which future versions 577 | of the GNU General Public License can be used, that proxy's public 578 | statement of acceptance of a version permanently authorizes you to 579 | choose that version for the Program. 580 | 581 | Later license versions may give you additional or different 582 | permissions. However, no additional obligations are imposed on any 583 | author or copyright holder as a result of your choosing to follow a 584 | later version. 585 | 586 | #### 15. Disclaimer of Warranty. 587 | 588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 596 | CORRECTION. 597 | 598 | #### 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR 602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 609 | 610 | #### 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mathematica-notebook-filter 2 | 3 | `mathematica-notebook-filter` is a program written in 4 | [Rust](https://www.rust-lang.org/) that parses Mathematica notebook files and 5 | strips them of superfluous information so that they can be committed into 6 | version control systems more easily. Instructions to integrate this program 7 | into version control systems can be found [below](#integration) and can be set 8 | up so that this is all done transparently without modifying the file on disk. 9 | 10 | [![Crates.io](https://img.shields.io/crates/v/mathematica-notebook-filter.svg)](https://crates.io/crates/mathematica-notebook-filter) 11 | [![Travis](https://img.shields.io/travis/JP-Ellis/mathematica-notebook-filter/master.svg)](https://travis-ci.org/JP-Ellis/mathematica-notebook-filter) 12 | [![Codecov](https://img.shields.io/codecov/c/github/JP-Ellis/mathematica-notebook-filter/master.svg)](https://codecov.io/gh/JP-Ellis/mathematica-notebook-filter) 13 | 14 | Licensed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html). 15 | 16 | *This program has not been rigorously tested. It works for me on all my 17 | Notebooks, but there may still be some situations which have not been accounted 18 | for. If you use this program, please let me know (both good and bad feedback).* 19 | 20 | ## Introduction 21 | 22 | Version control systems (such as [git](https://git-scm.com/) and 23 | [mercurial](https://www.mercurial-scm.org/) among many others) provide a 24 | fantastic way to keep track of changes to files in such a way that multiple 25 | people can collaborate on them without accidentally overwriting other people's 26 | changes. Version control systems primarily keep track of source code and if two 27 | people change the same file, it is possible to compare the two files 28 | side-by-side so that the changes can be merged. 29 | 30 | Although binary files (such as compiled outputs, images, PDFs, ...) can be 31 | included in a version control system too, it is generally not possible or 32 | meaningful to compare two sets of changes to one binary file. As a result, 33 | binary files are quite opaque to version control systems and it is inadvisable 34 | to store binary files in a version control system if they will be changed 35 | frequently. 36 | 37 | This is specifically an issue for Mathematica notebooks as they store both 38 | inputs and outputs in the same file. A quite typical example of this is the 39 | simple input: 40 | 41 | ```mathematica 42 | Plot[Sin[x] / x, {x, -4 Pi, 4 Pi}] 43 | ``` 44 | 45 | which, when plotted, is stored in the Notebook file as: 46 | 47 | ```mathematica 48 | GraphicsBox[{{{{}, {}, 49 | TagBox[ 50 | {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], 51 | Opacity[1.], LineBox[CompressedData[""]], 52 | LineBox[CompressedData[""]]}, 53 | Annotation[#, 54 | "Charting`Private`Tag$5185#1"]& ], {}}, {{}, {}, {}}}, {}, {}}, 55 | AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], 56 | Axes->{True, True}, 57 | AxesLabel->{None, None}, 58 | AxesOrigin->{0, 0}, 59 | DisplayFunction->Identity, 60 | Frame->{{False, False}, {False, False}}, 61 | FrameLabel->{{None, None}, {None, None}}, 62 | FrameTicks->{{Automatic, 63 | Charting`ScaledFrameTicks[{Identity, Identity}]}, {Automatic, 64 | Charting`ScaledFrameTicks[{Identity, Identity}]}}, 65 | GridLines->{None, None}, 66 | GridLinesStyle->Directive[ 67 | GrayLevel[0.5, 0.4]], 68 | ImagePadding->All, 69 | Method->{ 70 | "DefaultBoundaryStyle" -> Automatic, "DefaultMeshStyle" -> 71 | AbsolutePointSize[6], "ScalingFunctions" -> None, 72 | "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ 73 | (Identity[#]& )[ 74 | Part[#, 1]], 75 | (Identity[#]& )[ 76 | Part[#, 2]]}& ), "CopiedValueFunction" -> ({ 77 | (Identity[#]& )[ 78 | Part[#, 1]], 79 | (Identity[#]& )[ 80 | Part[#, 2]]}& )}}, 81 | PlotRange-> 82 | NCache[{{(-4) Pi, 4 Pi}, {-0.21723358083481298`, 83 | 0.9999892952885239}}, {{-12.566370614359172`, 84 | 12.566370614359172`}, {-0.21723358083481298`, 0.9999892952885239}}], 85 | PlotRangeClipping->True, 86 | PlotRangePadding->{{ 87 | Scaled[0.02], 88 | Scaled[0.02]}, { 89 | Scaled[0.05], 90 | Scaled[0.05]}}, 91 | Ticks->{Automatic, Automatic}] 92 | ``` 93 | 94 | Note that the above snippet was significantly abbreviated as the compressed 95 | base-64 encoded data is an additional 300 lines or so. 96 | 97 | For the version control system, this large output is extremely cumbersome as a 98 | small change in the input (such as replacing `Sin[x]` with `Sin[2 x]`) will 99 | produce a 300+ line diff. The purpose of `mathematica-notebook-filter` is 100 | specifically to avoid such large diffs and try and make them much more 101 | meaningful. It does so by parsing the Mathematica notebook file format and 102 | removing all the output cells and metadata. The program is implemented in 103 | [Rust](https://www.rust-lang.org/) and distributed on 104 | [crates.io](https://crates.io/crates/mathematica-notebook-filter). 105 | 106 | Having said that, it should be noted that Mathematica unfortunately does not 107 | store the input in a very simple form as it not only stores the plain 108 | Mathematica expression, but also stores formatting information. As a concrete 109 | example, an input cell with the above plot function will be stored in the 110 | Notebook file as: 111 | 112 | ```mathematica 113 | Cell[BoxData[ 114 | RowBox[{"Plot", "[", 115 | RowBox[{ 116 | FractionBox[ 117 | RowBox[{"Sin", "[", "x", "]"}], "x"], ",", 118 | RowBox[{"{", 119 | RowBox[{"x", ",", 120 | RowBox[{ 121 | RowBox[{"-", "4"}], "Pi"}], ",", 122 | RowBox[{"4", "Pi"}]}], "}"}]}], "]"}]], "Input"] 123 | ``` 124 | 125 | The change of `Sin[x]` to `Sin[2 x]` results in the cell now being stored as: 126 | 127 | ```mathematica 128 | Cell[BoxData[ 129 | RowBox[{"Plot", "[", 130 | RowBox[{ 131 | FractionBox[ 132 | RowBox[{"Sin", "[", 133 | RowBox[{"2", "x"}], "]"}], "x"], ",", 134 | RowBox[{"{", 135 | RowBox[{"x", ",", 136 | RowBox[{ 137 | RowBox[{"-", "4"}], "Pi"}], ",", 138 | RowBox[{"4", "Pi"}]}], "}"}]}], "]"}]], "Input"] 139 | ``` 140 | 141 | This program, at least at this stage, will *not* strip the extra formatting 142 | information. If you wish to avoid the above, then you should save your 143 | notebooks as scripts files (with extension `.wl` or `.m`). 144 | 145 | ## Usage Notes 146 | 147 | `mathematica-notebook-filter` parses Mathematica notebook files (usually stored 148 | with the extension `.nb`) and strips all generated outputs and other metadata. 149 | By default, the program reads from standard input and outputs to standard 150 | output. Additional usage information can be obtained from 151 | 152 | ```sh 153 | mathematica-notebook-filter --help 154 | ``` 155 | 156 | Although it is possible to use `mathematica-notebook-filter` manually, it is 157 | designed to be integrated with version control systems (see 158 | [below](#Integration) for instructions) such that Notebooks are first piped 159 | through the filter before the diffs are generated. This is specifically 160 | designed so that original file is left untouched with all outputs and metadata 161 | remaining, and the filter effectively makes the version control system blind to 162 | the extra content. 163 | 164 | If you wish to run it manually, a simple call would be: 165 | 166 | ```sh 167 | mathematica-notebook-filter -i my_notebook.nb -o my_notebook_cleaned.nb 168 | ``` 169 | 170 | If both input and output files are identical, the program will first output to a 171 | temporary file and only after successfully parsing the whole input will the 172 | original file be replaced. 173 | 174 | This program does *not* parse the Wolfram language in general and is specific to 175 | *full* Mathematica notebooks; thus it makes some fairly strong assumptions about 176 | the functions that will be found and their order. It only parses a single 177 | Notebook at a time and will stop after the end of the first Notebook. If an 178 | error is encountered during the parsing, `mathematica-notebook-filter` will exit 179 | with a non-zero code and the output will be left incomplete. 180 | 181 | It also should be re-iterated that the best way to commit Mathematica code to a 182 | version control system is to save the code in script files (`.wl` or `.m`). 183 | When doing so, Mathematica save the file in a very simple format (essentially a 184 | plain text file), without the superfluous formatting information and without 185 | outputs. This unfortunately has the disadvantage that the Notebook interface is 186 | not available. 187 | 188 | Also note that Mathematica notebooks allow you to copy-paste graphics (such as 189 | generated plots) and use them as inputs. If you do so, the version control 190 | system will be forced to include the full plot in the diff, thereby defeating 191 | the point of `mathematica-notebook-filter`. An alternative to copy-pasting 192 | outputs is to store the output into a variable, or use `%` (and `%%`, `%%%`, 193 | ...) to refer to the previous output (though make sure to only use `%` within 194 | the one cell and not across cells as `%` refers to the last generated output, 195 | not the previous output in the Notebook order). 196 | 197 | ## Installation 198 | 199 | This program is written in [Rust](https://www.rust-lang.org/). Probably the 200 | easiest way to install Rust is to use the [rustup.rs](https://www.rustup.rs/) 201 | script. Once set up, it should simply be a matter of running 202 | 203 | ```sh 204 | cargo install mathematica-notebook-filter 205 | ``` 206 | 207 | This will download, compile, and install `mathematica-notebook-filter` in your 208 | Cargo home direction (`~/.cargo` by default on Linux). Assuming you have 209 | correctly set up your PATH variable (which rustup.rs should have done 210 | automatically), then you can execute the program by typing 211 | `mathematica-notebook-filter`. 212 | 213 | ## Integration 214 | 215 | ### Git 216 | 217 | It is possible to set *attributes* based on pattern globs. In this instance, we 218 | want to make sure that all `*.nb` files are processed by this filter before 219 | being committed. To globally set the attribute, add to `~/.gitattributes`: 220 | 221 | ```text 222 | *.nb filter=dropoutput_nb 223 | ``` 224 | 225 | and to your `~/.gitconfig`: 226 | 227 | ```text 228 | [filter "dropoutput_nb"] 229 | clean = mathematica-notebook-filter 230 | smudge = cat 231 | ``` 232 | 233 | ### Other 234 | 235 | Pull requests to add instructions for other version control system are welcome. 236 | 237 | 238 | ## Disclaimer 239 | 240 | The Wolfram Research organization unfortunately does not appear to offer any 241 | specification to their language or their file formats. As a result, this filter 242 | was entirely developed by inspecting outputs generated by Mathematica. 243 | Specifically, this was developed using Mathematica 11.1 and thus there is no 244 | guarantee that this filter will work with past or future version of the Notebook 245 | file format. 246 | 247 | If you find a bug, please feel free to open an issue though please provide 248 | enough information to reproduce the bug or a minimal example of a Notebook file 249 | that causes the issue. 250 | 251 | ## Contributing 252 | 253 | Pull requests to improve compatibility with other versions (or to fix bugs) are 254 | very welcome. If you find a bug, please feel free to open an issue and make 255 | sure to provide enough information to reproduce the bug or a minimal example of 256 | a Notebook file that causes the issue. 257 | -------------------------------------------------------------------------------- /ci/after_success.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Echo all commands before executing them 4 | set -o xtrace 5 | # Forbid any unset variables 6 | set -o nounset 7 | # Exit on any error 8 | set -o errexit 9 | 10 | COVERAGE_RUN=false 11 | 12 | run_kcov() { 13 | # Run kcov on all the test suites 14 | if [[ $COVERAGE_RUN != "true" ]]; then 15 | # At the moment, kcov doesn't track child processes spawned by the 16 | # tests, as a result, we have to manually run kcov and merge the results 17 | cargo coverage 18 | ./tests/notebook.sh 19 | COVERAGE_RUN=true 20 | fi 21 | } 22 | 23 | coverage_codecov() { 24 | if [[ "$TRAVIS_RUST_VERSION" != "stable" ]]; then 25 | return 26 | fi 27 | 28 | run_kcov 29 | 30 | bash <(curl -s https://codecov.io/bash) -s target/kcov 31 | echo "Uploaded code coverage to codecov.io" 32 | } 33 | 34 | coverage_coveralls() { 35 | if [[ "$TRAVIS_RUST_VERSION" != "stable" ]]; then 36 | return 37 | fi 38 | 39 | run_kcov 40 | 41 | # Data is automatically uploaded by kcov 42 | } 43 | 44 | main() { 45 | # coverage_coveralls 46 | coverage_codecov 47 | } 48 | 49 | main 50 | -------------------------------------------------------------------------------- /ci/before_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Echo all commands before executing them 4 | set -o xtrace 5 | # Forbid any unset variables 6 | set -o nounset 7 | # Exit on any error 8 | set -o errexit 9 | 10 | # Install clippy and rustfmt 11 | rustup_tools() { 12 | rustup component add clippy rustfmt 13 | } 14 | 15 | # Install cargo tools 16 | cargo_tools() { 17 | cargo install cargo-update || echo "cargo-update already installed" 18 | cargo install cargo-travis || echo "cargo-travis already installed" 19 | # Update cached binaries 20 | cargo install-update -a 21 | } 22 | 23 | main() { 24 | rustup_tools 25 | cargo_tools 26 | } 27 | 28 | main 29 | -------------------------------------------------------------------------------- /ci/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 0 3 | round: down 4 | range: "70...100" 5 | 6 | status: 7 | project: yes 8 | patch: yes 9 | changes: no 10 | -------------------------------------------------------------------------------- /ci/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Echo all commands before executing them 4 | set -o xtrace 5 | # Forbid any unset variables 6 | set -o nounset 7 | # Exit on any error 8 | set -o errexit 9 | 10 | # Ensure there are no outstanding lints. 11 | check_lints() { 12 | cargo clippy $FEATURES 13 | } 14 | 15 | # Ensure the code is correctly formatted. 16 | check_format() { 17 | cargo fmt -- --check 18 | } 19 | 20 | # Run the test suite. 21 | check_tests() { 22 | cargo test $FEATURES 23 | } 24 | 25 | check_command_line() { 26 | cargo run -- -vvv -i tests/notebook.nb -o tests/notebook.min.nb 27 | if [[ $(wc -c < tests/notebook.nb) -le $(wc -c < tests/notebook.min.nb) ]]; then 28 | echo "No reduction in file size ($(wc -c < tests/notebook.nb) => $(wc -c < tests/notebook.min.nb))." >&2 29 | false 30 | fi 31 | } 32 | 33 | main() { 34 | check_lints 35 | check_format 36 | check_tests 37 | check_command_line 38 | } 39 | 40 | main 41 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | // mathematica-notebook-filter 2 | // Copyright (C) 2017 Joshua Ellis 3 | // 4 | // This program is free software: you can redistribute it and/or modify it under 5 | // the terms of the GNU General Public License as published by the Free Software 6 | // Foundation, either version 3 of the License, or (at your option) any later 7 | // version. 8 | // 9 | // This program is distributed in the hope that it will be useful, but WITHOUT 10 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 12 | // details. 13 | // 14 | // You should have received a copy of the GNU General Public License along with 15 | // this program. If not, see . 16 | 17 | //! `mathematica-notebook-filter` parses Mathematica notebook files and strips 18 | //! them of superfluous information so that they can be committed into version 19 | //! control systems more easily. 20 | //! 21 | //! Project home page: https://github.com/JP-Ellis/mathematica-notebook-filter 22 | 23 | extern crate atty; 24 | #[macro_use] 25 | extern crate clap; 26 | #[macro_use] 27 | extern crate log; 28 | extern crate stderrlog; 29 | extern crate tempfile; 30 | 31 | use std::fs; 32 | use std::io; 33 | use std::io::prelude::*; 34 | use std::io::BufReader; 35 | use std::path; 36 | use std::process::exit; 37 | 38 | use clap::{App, AppSettings, Arg}; 39 | 40 | mod parser; 41 | 42 | /// Create the `clap::App` which will be used to parse the arguments. 43 | fn app() -> App<'static, 'static> { 44 | App::new("mathematica-notebook-filter") 45 | .author(crate_authors!()) 46 | .version(crate_version!()) 47 | .setting(AppSettings::UnifiedHelpMessage) 48 | .about("mathematica-notebook-filter parses Mathematica notebook files and strips them of superfluous information so that they can be committed into version control systems more easily. 49 | 50 | Project home page: https://github.com/JP-Ellis/mathematica-notebook-filter 51 | ") 52 | .long_about("mathematica-notebook-filter parses Mathematica notebook files and strips them of superfluous information so that they can be committed into version control systems more easily. 53 | 54 | By default, mathematica-notebook-filter is intended to be used as a pipe and will read from the standard input and write to the standard output. 55 | 56 | Project home page: https://github.com/JP-Ellis/mathematica-notebook-filter 57 | ") 58 | .arg( 59 | Arg::with_name("input") 60 | .short("i") 61 | .long("input") 62 | .value_name("FILE") 63 | .takes_value(true) 64 | .default_value("-") 65 | .number_of_values(1) 66 | .allow_hyphen_values(true) 67 | .help("Input file name, or standard input if not provided.") 68 | .long_help( 69 | "Specify the input file to the Mathematica Notebook which will parsed. This value is option and will default to the standard input. The standard input can be explicitly specified using the special file name '-'.", 70 | ), 71 | ) 72 | .arg( 73 | Arg::with_name("output") 74 | .short("o") 75 | .long("output") 76 | .value_name("FILE") 77 | .takes_value(true) 78 | .default_value("-") 79 | .number_of_values(1) 80 | .allow_hyphen_values(true) 81 | .help("Output file name, or standard output if not provided.") 82 | .long_help( 83 | "Specify the output file to which the Mathematica Notebook stripped of all output will be written. This value is option and will default to the standard output. The standard output can be explicitly specified using the special file name '-'. 84 | 85 | If the input and output files are both the same, the output will be written to a temporary file first before overwriting the input file. 86 | 87 | If the output file already exists, the contents of the file will be overwritten.", 88 | ), 89 | ) 90 | .arg( 91 | Arg::with_name("verbose") 92 | .short("v") 93 | .long("verbose") 94 | .multiple(true) 95 | .takes_value(false) 96 | .help("Increase the verbosity of errors.") 97 | .long_help( 98 | "Increase the verbosity of errors. The errors are outputted to the standard error stream and thus do not appear in the output. This option can be specified multiple times for increasing levels of verbosity.", 99 | ), 100 | ) 101 | } 102 | 103 | /// Initialize the logger based on the desired level of verbosity. 104 | fn initialize_logger(level: u64) { 105 | if let Err(e) = stderrlog::new() 106 | .module(module_path!()) 107 | .verbosity(level as usize) 108 | .init() 109 | { 110 | eprintln!("Error when initializing the logger: {}.", e); 111 | exit(1); 112 | }; 113 | 114 | debug!("Verbosity set to Debug."); 115 | } 116 | 117 | /// Main function 118 | fn main() { 119 | // Parse the arguments, and immediately initialize the logger. 120 | let matches = app().get_matches(); 121 | initialize_logger(matches.occurrences_of("verbose")); 122 | 123 | // Check if the input and output files are the same (and not both standard 124 | // input/output) as we need to take care of not overwriting the input as we 125 | // write to it. 126 | let use_temporary_file = matches.value_of("input") != Some("-") 127 | && matches.value_of("input") == matches.value_of("output"); 128 | 129 | // We initialize stdin and stdout here so that they don't go out of scope 130 | // (even if they don't get used). This doesn't seem like the best way of 131 | // doing this... 132 | let stdin = io::stdin(); 133 | let stdout = io::stdout(); 134 | 135 | // Get the input file. 136 | let mut input_file: Box = match matches.value_of("input") { 137 | Some("-") | None => { 138 | if atty::is(atty::Stream::Stdin) { 139 | error!("Cowardly exiting as standard input is a tty."); 140 | exit(1); 141 | } 142 | 143 | debug!("Reading from standard input."); 144 | 145 | Box::new(stdin.lock()) 146 | } 147 | Some(filename) => { 148 | debug!("Reading from: {}.", filename); 149 | 150 | let file = match fs::File::open(filename) { 151 | Ok(file) => file, 152 | Err(e) => { 153 | error!("Error when opening input file: {}.", e); 154 | exit(1) 155 | } 156 | }; 157 | Box::new(BufReader::new(file)) 158 | } 159 | }; 160 | 161 | // Get the output file and output filename if it exists since we might need 162 | // to rename the output file and overwrite the input file if both input and 163 | // output files were identical. 164 | let (mut output_file, output_filename): (Box, _) = 165 | match (matches.value_of("output"), use_temporary_file) { 166 | (_, true) => { 167 | debug!("Creating temporary output file."); 168 | 169 | // Using a temporary file. As we will wish to rename it (and 170 | // the temporary file is not used to store any sensitive 171 | // information), we use a NamedTempFile. 172 | let output_file = match tempfile::NamedTempFile::new() { 173 | Ok(file) => file, 174 | Err(e) => { 175 | error!("Error when creating temporary file: {}.", e); 176 | exit(1) 177 | } 178 | }; 179 | let p = output_file.path().to_path_buf(); 180 | 181 | debug!("Writing to temporary file: {:?}.", p); 182 | 183 | (Box::new(output_file), Some(p)) 184 | } 185 | 186 | (Some("-"), false) | (None, false) => { 187 | debug!("Writing to standard output."); 188 | 189 | (Box::new(stdout.lock()), None) 190 | } 191 | 192 | (Some(filename), false) => { 193 | debug!("Writing to: {}.", filename); 194 | 195 | let p = path::Path::new(filename); 196 | if p.is_file() { 197 | warn!("Overwriting output file: {}.", filename); 198 | } 199 | let file = match fs::File::create(p) { 200 | Ok(file) => file, 201 | Err(e) => { 202 | error!("Error when opening output file: {}.", e); 203 | exit(1) 204 | } 205 | }; 206 | 207 | (Box::new(file), Some(p.to_path_buf())) 208 | } 209 | }; 210 | 211 | if let Err(e) = parser::parse_input(&mut input_file, &mut output_file) { 212 | error!("Error when parsing notebook: {}.", e); 213 | exit(1); 214 | } 215 | 216 | // Before exiting, we just need to overwrite the input file. 217 | if use_temporary_file { 218 | let input_filename = matches.value_of("input").unwrap(); 219 | let output_filename = output_filename.unwrap(); 220 | debug!("Moving {:?} => {}", output_filename, input_filename); 221 | 222 | if let Err(e) = fs::copy(output_filename, input_filename) { 223 | error!( 224 | "Error when replacing original input with temporary outout: {}", 225 | e 226 | ); 227 | exit(1) 228 | } else { 229 | exit(0) 230 | } 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /src/parser/cell.rs: -------------------------------------------------------------------------------- 1 | use std::cmp; 2 | use std::io; 3 | 4 | use super::cell_group_data::parse_cell_group_data; 5 | use super::utilities::{check_start, load_function, read_consume_output}; 6 | 7 | const CELL_OPT_TO_IGNORE: [&[u8]; 4] = [ 8 | b"CellChangeTimes", 9 | b"ExpressionUUID", 10 | b"CellLabel", 11 | b"EmphasizeSyntaxErrors", 12 | ]; 13 | 14 | const CELL_STYLE_TO_IGNORE: [&[u8]; 4] = [ 15 | b"\"Message\"", 16 | b"\"Output\"", 17 | b"\"PrintTemporary\"", 18 | b"\"Print\"", 19 | ]; 20 | 21 | /// Parse a list of `Cell[]` of the form: 22 | /// 23 | /// ```mathematica 24 | /// {Cell[...], Cell[...], ...} 25 | /// ``` 26 | /// 27 | /// This function requires the input to be at the opening brace and will consume 28 | /// everything up to and including the closing brace of the list. 29 | /// 30 | /// If a `Cell` is omitted (due to being an output `Cell`), this function will 31 | /// ensure that the separating commas are appropriately adjusted as the Wolfram 32 | /// language does not allow dangling commas. 33 | pub fn parse_cell_list(input: &mut I, output: &mut O) -> Result<(), io::Error> 34 | where 35 | I: io::BufRead, 36 | O: io::Write, 37 | { 38 | debug!("Parsing cell list."); 39 | 40 | if !check_start(input, b"{")? { 41 | return Err(io::Error::new( 42 | io::ErrorKind::InvalidInput, 43 | "Expected the start of a list of cells.", 44 | )); 45 | } 46 | 47 | // Note that although we could load the full list, it could actually be 48 | // *very* long so we parse each cell individually. 49 | 50 | // To make parsing the loop easier later, we'll output the opening brace now 51 | // and everything up to the first cell, or up to and including the closing 52 | // brace if there are no cells in the list. In the latter case, we can exit 53 | // the function early. 54 | let cell_bytes = b"Cell["; 55 | let (next_cell, next_brace) = { 56 | let buf = input.fill_buf()?; 57 | ( 58 | buf.windows(cell_bytes.len()).position(|w| w == cell_bytes), 59 | buf.iter().position(|&c| c == b'}'), 60 | ) 61 | }; 62 | 63 | match (next_cell, next_brace) { 64 | (None, None) => { 65 | return Err(io::Error::new( 66 | io::ErrorKind::UnexpectedEof, 67 | "Unable to locate the next cell or end of list in list of cells.", 68 | )); 69 | } 70 | (None, Some(p)) => { 71 | // Write everything up to and including the next brace 72 | read_consume_output(input, output, p + 1)?; 73 | return Ok(()); 74 | } 75 | (Some(p1), Some(p)) if p < p1 => { 76 | // Write everything up to and including the next brace 77 | read_consume_output(input, output, p + 1)?; 78 | return Ok(()); 79 | } 80 | (Some(p), None) => { 81 | // Write everything up to the next Cell 82 | read_consume_output(input, output, p)?; 83 | } 84 | (Some(p), Some(p2)) if p < p2 => { 85 | // Write everything up to the next Cell 86 | read_consume_output(input, output, p)?; 87 | } 88 | _ => unreachable!("Unexpected branch reached. This is a bug and should be reported."), 89 | }; 90 | 91 | // At this stage, `input` is at the start of the first `Cell[]`, with the 92 | // opening brace already having been outputted. Note that if we happen to 93 | // have omitted cells at the start of the list, we do not want to output a 94 | // separating comma, so we must keep track of when we still are at the start 95 | // of the list. 96 | let mut cell_buf = Vec::new(); 97 | let mut start_of_list = true; 98 | loop { 99 | cell_buf.clear(); 100 | 101 | // Get the positions of the next `Cell[` and `}`. 102 | let (next_cell, next_brace) = { 103 | let buf = input.fill_buf()?; 104 | ( 105 | buf.windows(cell_bytes.len()).position(|w| w == cell_bytes), 106 | buf.iter().position(|&c| c == b'}'), 107 | ) 108 | }; 109 | 110 | // If we have a closing brace coming up first, we've reached the end of 111 | // the list so we can output up to that and exit. If instead we have a 112 | // Cell coming up, we need to parse the Cell and check whether it will 113 | // need to be outputted. 114 | match (next_cell, next_brace) { 115 | (None, None) => { 116 | return Err(io::Error::new( 117 | io::ErrorKind::UnexpectedEof, 118 | "Unable to locate the next cell or end of list in list of cells.", 119 | )); 120 | } 121 | (None, Some(p)) => { 122 | // Write everything up to and including the closing brace 123 | read_consume_output(input, output, p + 1)?; 124 | return Ok(()); 125 | } 126 | (Some(p1), Some(p)) if p < p1 => { 127 | // Write everything up to and including the closing brace 128 | read_consume_output(input, output, p + 1)?; 129 | return Ok(()); 130 | } 131 | (Some(p), None) => { 132 | // Load everything up to the cell (which will include the 133 | // preceding comma. 134 | if start_of_list { 135 | input.consume(p); 136 | } else { 137 | read_consume_output(input, &mut cell_buf, p)?; 138 | } 139 | if parse_cell(input, &mut cell_buf)? { 140 | output.write_all(&cell_buf)?; 141 | start_of_list = false; 142 | } 143 | } 144 | (Some(p), Some(p2)) if p < p2 => { 145 | // Load everything up to the cell (which will include the 146 | // preceding comma. 147 | if start_of_list { 148 | input.consume(p); 149 | } else { 150 | read_consume_output(input, &mut cell_buf, p)?; 151 | } 152 | if parse_cell(input, &mut cell_buf)? { 153 | output.write_all(&cell_buf)?; 154 | start_of_list = false; 155 | } 156 | } 157 | _ => unreachable!("Unexpected branch reached. This is a bug and should be reported."), 158 | } 159 | } 160 | } 161 | 162 | /// Parse a `Cell[]`, and only send it to the output if it is not an output 163 | /// cell. This function also removes metadata associated with the cell. 164 | /// 165 | /// The input must be at the start of the Cell function. 166 | /// 167 | /// If anything was outputted by the function, the function will return `true` 168 | /// (and `false` otherwise) so that the parsing of list of cells can omit commas 169 | /// as appropriate. 170 | /// 171 | /// Background 172 | /// ========== 173 | /// 174 | /// The `Cell` functions takes one of two forms: 175 | /// 176 | /// ```mathematica 177 | /// Cell[contents] 178 | /// ``` 179 | /// 180 | /// and 181 | /// 182 | /// ```mathematica 183 | /// Cell[contents, "style"] 184 | /// ``` 185 | /// 186 | /// and optional arguments can be specified at the end. We will assume that 187 | /// optional arguments are *only* used in the latter format. 188 | /// 189 | /// The omitted styles are: 190 | /// 191 | /// - Output 192 | /// - Print 193 | /// - Message 194 | pub fn parse_cell(input: &mut I, output: &mut O) -> Result 195 | where 196 | I: io::BufRead, 197 | O: io::Write, 198 | { 199 | debug!("Parsing Cell."); 200 | 201 | if !check_start(input, b"Cell[")? { 202 | return Err(io::Error::new( 203 | io::ErrorKind::InvalidInput, 204 | "Expected the start of a Cell[].", 205 | )); 206 | } 207 | 208 | // The input is now at the start of the cell. We load the full function 209 | // into one vector, and also locate its various arguments. 210 | let (cell_bytes, args) = load_function(input)?; 211 | let num_args = args.len() - 1; 212 | 213 | // Check the second argument of `Cell[]` to see whether it is to be deleted 214 | // in which case we can ignore the Cell completely. 215 | if num_args >= 2 { 216 | let is_to_ignore = CELL_STYLE_TO_IGNORE.iter().any(|&cell_type| { 217 | cell_bytes[args[1]..args[2]] 218 | .windows(cell_type.len()) 219 | .any(|w| w == cell_type) 220 | }); 221 | if is_to_ignore { 222 | return Ok(false); 223 | } 224 | } 225 | 226 | // At this stage, we know we are outputting the cell. 227 | 228 | // Inspect the start of the first argument and see if it contains 229 | // `CellGroupData`. Because of formatting it need not be right at the start 230 | // of the first argument, but we also want to avoid inspecting too far into 231 | // the cell in case `CellGroupData[]` was inputted by the user. 232 | let cell_group_data_bytes = b"CellGroupData["; 233 | let pos = cell_bytes[args[0]..cmp::min(args[1], args[0] + 2 * cell_group_data_bytes.len())] 234 | .windows(cell_group_data_bytes.len()) 235 | .position(|w| w == cell_group_data_bytes); 236 | 237 | // When outputting the arguments, we specifically omit the trailing comma. 238 | match (pos, num_args) { 239 | (_, 0) => { 240 | return Err(io::Error::new( 241 | io::ErrorKind::InvalidInput, 242 | "Cell[] must have at least one argument.", 243 | )); 244 | } 245 | (None, 1) => output.write_all(&cell_bytes[..args[1] - 1])?, 246 | (None, _) => output.write_all(&cell_bytes[..args[2] - 1])?, 247 | (Some(p), 1) => { 248 | output.write_all(&cell_bytes[..args[0] + p])?; 249 | parse_cell_group_data(&mut &cell_bytes[args[0] + p..args[1] - 1], output)?; 250 | } 251 | (Some(p), _) => { 252 | output.write_all(&cell_bytes[..args[0] + p])?; 253 | parse_cell_group_data(&mut &cell_bytes[args[0] + p..args[1] - 1], output)?; 254 | output.write_all(&cell_bytes[args[1] - 1..args[2] - 1])?; 255 | } 256 | }; 257 | 258 | // We have now outputted the first two arguments of `Cell`. It remains to 259 | // parse the optional arguments. 260 | for arg in 2..num_args { 261 | let is_to_ignore = CELL_OPT_TO_IGNORE.iter().any(|&opt| { 262 | cell_bytes[args[arg]..args[arg + 1] - 1] 263 | .windows(opt.len()) 264 | .any(|w| w == opt) 265 | }); 266 | if !is_to_ignore { 267 | output.write_all(&cell_bytes[args[arg] - 1..args[arg + 1] - 1])?; 268 | } 269 | } 270 | 271 | // Since we purposefully exclude the trailing comma/bracket, we write it out now. 272 | output.write_all(b"]")?; 273 | 274 | Ok(true) 275 | } 276 | 277 | #[cfg(test)] 278 | mod test { 279 | #[test] 280 | fn cell() { 281 | // Output Cells 282 | //////////////////////////////////////// 283 | let mut output = Vec::new(); 284 | let mut input = &br#"Cell[123, "Output"]"#[..]; 285 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 286 | assert!(input.is_empty()); 287 | assert!(output.is_empty()); 288 | 289 | let mut output = Vec::new(); 290 | let mut input = &br#"Cell[{Cell[1, "Input"], Cell[2, "Output"]}, "Output"]"#[..]; 291 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 292 | assert!(input.is_empty()); 293 | assert!(output.is_empty()); 294 | 295 | let mut output = Vec::new(); 296 | let mut input = &br#"Cell[123, "Output", MetaData->Foo, Timestamp->123]"#[..]; 297 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 298 | assert!(input.is_empty()); 299 | assert!(output.is_empty()); 300 | 301 | // Non-output Cells 302 | //////////////////////////////////////// 303 | let mut output = Vec::new(); 304 | let mut input = &br#"Cell[123, "Input"]"#[..]; 305 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 306 | assert!(input.is_empty()); 307 | assert_eq!(&output, br#"Cell[123, "Input"]"#); 308 | 309 | let mut output = Vec::new(); 310 | let mut input = &br#"Cell[123, "Input", Foo->Bar]"#[..]; 311 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 312 | assert!(input.is_empty()); 313 | assert_eq!(&output, br#"Cell[123, "Input", Foo->Bar]"#); 314 | 315 | let mut output = Vec::new(); 316 | let mut input = &br#"Cell[123, "Input", CellChangeTimes->123]"#[..]; 317 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 318 | assert!(input.is_empty()); 319 | assert_eq!(&output, br#"Cell[123, "Input"]"#); 320 | 321 | let mut output = Vec::new(); 322 | let mut input = &br#"Cell[123, "Input", CellChangeTimes->123, Foo->Bar]"#[..]; 323 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 324 | assert!(input.is_empty()); 325 | assert_eq!(&output, br#"Cell[123, "Input", Foo->Bar]"#); 326 | 327 | // Cell with CellGroupData 328 | //////////////////////////////////////// 329 | let mut output = Vec::new(); 330 | let mut input = 331 | &b"Cell[CellGroupData[{Cell[1, \"Input\"], Cell[2, \"Output\"]}, Open]], Foo"[..]; 332 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 333 | assert_eq!(input, b", Foo"); 334 | assert_eq!(output, &br#"Cell[CellGroupData[{Cell[1, "Input"]}]]"#[..]); 335 | 336 | let mut output = Vec::new(); 337 | let mut input = &br#"Cell[ 338 | CellGroupData[{ 339 | Cell[CellGroupData[{Cell[1, "Input"], Cell[2, "Output"]}]], 340 | Cell[3, "Input"], 341 | Cell[4, "Output"] 342 | }, Open]], 343 | Foo"#[..]; 344 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 345 | assert_eq!(input, &b",\nFoo"[..]); 346 | assert_eq!( 347 | output, 348 | &br#"Cell[ 349 | CellGroupData[{ 350 | Cell[CellGroupData[{Cell[1, "Input"]}]], 351 | Cell[3, "Input"] 352 | }]]"#[..] 353 | ); 354 | 355 | // Invalid Cells 356 | //////////////////////////////////////// 357 | let mut output = Vec::new(); 358 | let mut input = &br#"Foo Cell[123, "Input"]"#[..]; 359 | assert!(super::parse_cell(&mut input, &mut output).is_err()); 360 | 361 | // Although technically invalid from the Mathematica notebook, this is 362 | // outputted fine. 363 | let mut output = Vec::new(); 364 | let mut input = &b"Cell[]"[..]; 365 | assert!(super::parse_cell(&mut input, &mut output).is_ok()); 366 | assert!(input.is_empty()); 367 | assert_eq!(output, b"Cell[]"); 368 | } 369 | 370 | #[test] 371 | fn cell_list() { 372 | // Simple lists 373 | //////////////////////////////////////// 374 | let mut output = Vec::new(); 375 | let mut input = &b"{} Foo"[..]; 376 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 377 | assert_eq!(input, b" Foo"); 378 | assert_eq!(output, b"{}"); 379 | 380 | let mut output = Vec::new(); 381 | let mut input = &b"{Cell[1]} Cell[2]"[..]; 382 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 383 | assert_eq!(input, b" Cell[2]"); 384 | assert_eq!(output, b"{Cell[1]}"); 385 | 386 | // Combinations of Input and Output 387 | //////////////////////////////////////// 388 | // Valid list of 3 cells with anything from 0 to 3 output cells, in all 389 | // possible configurations. 390 | let mut output = Vec::new(); 391 | let mut input = &br#"{Cell[1], Cell[2], Cell[3]}"#[..]; 392 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 393 | assert!(input.is_empty()); 394 | assert_eq!(output, &br#"{Cell[1], Cell[2], Cell[3]}"#[..]); 395 | 396 | let mut output = Vec::new(); 397 | let mut input = &br#"{Cell[1, "Output"], Cell[2], Cell[3]}"#[..]; 398 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 399 | assert!(input.is_empty()); 400 | assert_eq!(output, &br#"{Cell[2], Cell[3]}"#[..]); 401 | 402 | let mut output = Vec::new(); 403 | let mut input = &br#"{Cell[1], Cell[2, "Output"], Cell[3]}"#[..]; 404 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 405 | assert!(input.is_empty()); 406 | assert_eq!(output, &br#"{Cell[1], Cell[3]}"#[..]); 407 | 408 | let mut output = Vec::new(); 409 | let mut input = &br#"{Cell[1], Cell[2], Cell[3, "Output"]}"#[..]; 410 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 411 | assert!(input.is_empty()); 412 | assert_eq!(output, &br#"{Cell[1], Cell[2]}"#[..]); 413 | 414 | let mut output = Vec::new(); 415 | let mut input = &br#"{Cell[1], Cell[2, "Output"], Cell[3, "Output"]}"#[..]; 416 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 417 | assert!(input.is_empty()); 418 | assert_eq!(output, &br#"{Cell[1]}"#[..]); 419 | 420 | let mut output = Vec::new(); 421 | let mut input = &br#"{Cell[1, "Output"], Cell[2], Cell[3, "Output"]}"#[..]; 422 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 423 | assert!(input.is_empty()); 424 | assert_eq!(output, &br#"{Cell[2]}"#[..]); 425 | 426 | let mut output = Vec::new(); 427 | let mut input = &br#"{Cell[1, "Output"], Cell[2, "Output"], Cell[3]}"#[..]; 428 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 429 | assert!(input.is_empty()); 430 | assert_eq!(output, &br#"{Cell[3]}"#[..]); 431 | 432 | let mut output = Vec::new(); 433 | let mut input = &br#"{Cell[1, "Output"], Cell[2, "Output"], Cell[3, "Output"]}"#[..]; 434 | assert!(super::parse_cell_list(&mut input, &mut output).is_ok()); 435 | assert!(input.is_empty()); 436 | assert_eq!(output, &br#"{}"#[..]); 437 | 438 | // Invalid Cell lists 439 | //////////////////////////////////////// 440 | let mut output = Vec::new(); 441 | let mut input = &b"Foo"[..]; 442 | assert!(super::parse_cell_list(&mut input, &mut output).is_err()); 443 | 444 | let mut output = Vec::new(); 445 | let mut input = &b"{Foo"[..]; 446 | assert!(super::parse_cell_list(&mut input, &mut output).is_err()); 447 | } 448 | } 449 | -------------------------------------------------------------------------------- /src/parser/cell_group_data.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | use super::cell::parse_cell_list; 4 | use super::utilities::{check_start, load_rest_of_function}; 5 | 6 | /// Parse a `CellGroupData`. 7 | /// 8 | /// This function requires the input to be at the start of `CellGroupData`. 9 | /// 10 | /// Background 11 | /// ========== 12 | /// 13 | /// Cells in a Mathematica notebook are not just stored one after the other, but 14 | /// can form a hierarchy. At its simplest, there is a hierarchy of 15 | /// input--output pairs, but if the Notebook contains various sections and 16 | /// subsections, there can be quite a complex structure. 17 | /// 18 | /// The grouping of Cells is done in a `CellGroupData[]` function which has the 19 | /// general form: 20 | /// 21 | /// ```mathematica 22 | /// CellGroupData[{ 23 | /// cell1, 24 | /// cell2, 25 | /// ... 26 | /// }] 27 | /// ``` 28 | /// 29 | /// and additionally can have a second argument specifying which cells are open 30 | /// (and all others are closed). 31 | /// 32 | /// In addition, optional arguments can be specified after the required 33 | /// arguments. 34 | pub fn parse_cell_group_data(input: &mut I, output: &mut O) -> Result<(), io::Error> 35 | where 36 | I: io::BufRead, 37 | O: io::Write, 38 | { 39 | debug!("Parsing CellGroupData."); 40 | 41 | if !check_start(input, b"CellGroupData[")? { 42 | Err(io::Error::new( 43 | io::ErrorKind::InvalidInput, 44 | "Expected the start of CellGroupData[].", 45 | )) 46 | } else { 47 | parse_cell_group_data_start(input, output) 48 | .and(parse_cell_list(input, output)) 49 | .and(parse_cell_group_data_end(input, output)) 50 | } 51 | } 52 | 53 | /// Parse and consume the start of the `CellGroupData` up to (but not including) 54 | /// the opening brace of the list of cells, at which point `parse_cell_list` 55 | /// takes over. 56 | fn parse_cell_group_data_start(input: &mut I, output: &mut O) -> Result<(), io::Error> 57 | where 58 | I: io::BufRead, 59 | O: io::Write, 60 | { 61 | debug!("Parsing start of CellGroupData."); 62 | 63 | let brace_pos = { 64 | let buf = input.fill_buf()?; 65 | buf.iter().position(|&c| c == b'{') 66 | }; 67 | 68 | match brace_pos { 69 | Some(brace_pos) => { 70 | { 71 | let buf = input.fill_buf()?; 72 | output.write_all(&buf[..brace_pos])?; 73 | } 74 | input.consume(brace_pos); 75 | Ok(()) 76 | } 77 | None => Err(io::Error::new( 78 | io::ErrorKind::UnexpectedEof, 79 | "EOF reached before finding start of the list of cells within CellGroupData[].", 80 | )), 81 | } 82 | } 83 | 84 | /// Parse the end of the `CellGroupData`. 85 | /// 86 | /// This function assumes that the first argument of `CellGroupData` has just 87 | /// been parsed, and that the function is just after the closing brace (either 88 | /// at a comma, or closing bracket if there are no additional arguments to 89 | /// `CellGroupData`). 90 | /// 91 | /// It appears `CellGroupData` only stores data about which cells are open and 92 | /// closed, so we will strip them and leave only the default (i.e. open). 93 | fn parse_cell_group_data_end(input: &mut I, output: &mut O) -> Result<(), io::Error> 94 | where 95 | I: io::BufRead, 96 | O: io::Write, 97 | { 98 | debug!("Parsing end of CellGroupData."); 99 | 100 | let (s, _) = load_rest_of_function(input)?; 101 | match s.first() { 102 | Some(&b',') | Some(&b']') => output.write_all(&b"]"[..]), 103 | _ => Err(io::Error::new( 104 | io::ErrorKind::InvalidInput, 105 | "Expected to be right after an argument when parsing the end of CellGroupData[].", 106 | )), 107 | } 108 | } 109 | 110 | #[cfg(test)] 111 | mod test { 112 | #[test] 113 | fn cell_group_data_start() { 114 | // Valid with Cell list as first argument 115 | //////////////////////////////////////// 116 | let mut output = Vec::new(); 117 | let mut input = &b"CellGroupData[{\nCell["[..]; 118 | assert!(super::parse_cell_group_data_start(&mut input, &mut output).is_ok()); 119 | assert_eq!(input, &b"{\nCell["[..]); 120 | assert_eq!(output, &b"CellGroupData["[..]); 121 | 122 | // No cell list in first argument 123 | //////////////////////////////////////// 124 | let mut output = Vec::new(); 125 | let mut input = &b"CellGroupData[Cell["[..]; 126 | assert!(super::parse_cell_group_data_start(&mut input, &mut output).is_err()); 127 | } 128 | 129 | #[test] 130 | fn cell_group_data_end() { 131 | // Valid 132 | //////////////////////////////////////// 133 | let mut output = Vec::new(); 134 | let mut input = &b", Open], Cell[{}, \"Output\"]"[..]; 135 | assert!(super::parse_cell_group_data_end(&mut input, &mut output).is_ok()); 136 | assert_eq!(input, &b", Cell[{}, \"Output\"]"[..]); 137 | assert_eq!(output.as_slice(), &b"]"[..]); 138 | 139 | let mut output = Vec::new(); 140 | let mut input = &b"], Cell[{}, \"Output\"]"[..]; 141 | assert!(super::parse_cell_group_data_end(&mut input, &mut output).is_ok()); 142 | assert_eq!(input, &b", Cell[{}, \"Output\"]"[..]); 143 | assert_eq!(output.as_slice(), &b"]"[..]); 144 | 145 | // Invalid 146 | //////////////////////////////////////// 147 | let mut output = Vec::new(); 148 | let mut input = &b"Open], Cell[{}, \"Output\"]"[..]; 149 | assert!(super::parse_cell_group_data_end(&mut input, &mut output).is_err()); 150 | } 151 | 152 | #[test] 153 | fn cell_group_data() { 154 | // Valid 155 | //////////////////////////////////////// 156 | let mut output = Vec::new(); 157 | let mut input = &b"CellGroupData[{Cell[1, \"Input\"], Cell[2, \"Output\"]}, Open], Foo"[..]; 158 | assert!(super::parse_cell_group_data(&mut input, &mut output).is_ok()); 159 | assert_eq!(input, &b", Foo"[..]); 160 | assert_eq!(output, &b"CellGroupData[{Cell[1, \"Input\"]}]"[..]); 161 | 162 | let mut output = Vec::new(); 163 | let mut input = &b"CellGroupData[{Cell[1, \"Input\"], Cell[2, \"Output\"]}], Foo"[..]; 164 | assert!(super::parse_cell_group_data(&mut input, &mut output).is_ok()); 165 | assert_eq!(input, &b", Foo"[..]); 166 | assert_eq!(output, &b"CellGroupData[{Cell[1, \"Input\"]}]"[..]); 167 | 168 | // Invalid Cells 169 | //////////////////////////////////////// 170 | let mut output = Vec::new(); 171 | let mut input = &b"CellGroupData[{Cell[1, \"Input\"], Cell[2, \"Output\"]} Open], Foo"[..]; 172 | assert!(super::parse_cell_group_data(&mut input, &mut output).is_err()); 173 | 174 | let mut output = Vec::new(); 175 | let mut input = 176 | &b"Foo[CellGroupData[{Cell[1, \"Input\"], Cell[2, \"Output\"]} Open], Foo"[..]; 177 | assert!(super::parse_cell_group_data(&mut input, &mut output).is_err()); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/parser/header.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | /// Parse the header of the Notebook file. 4 | /// 5 | /// The header consists of everything up to the beginning of the Mathematica 6 | /// code, which in this case is the function `Notebook[]`. 7 | pub fn parse_header(input: &mut I, output: &mut O) -> Result<(), io::Error> 8 | where 9 | I: io::BufRead, 10 | O: io::Write, 11 | { 12 | debug!("Parsing notebook header."); 13 | 14 | parse_content_type(input, output).and(parse_beginning_notebook(input, output)) 15 | } 16 | 17 | /// Parse the input until the content type specification is reached, and pass 18 | /// that on to the output. 19 | /// 20 | /// ```mathematica 21 | /// (* Content-type: application/vnd.wolfram.mathematica *) 22 | /// ``` 23 | /// 24 | /// The consume everything up to (and including) the closing parenthesis. The 25 | /// output include an extra new line after the content type. 26 | fn parse_content_type(input: &mut I, output: &mut O) -> Result<(), io::Error> 27 | where 28 | I: io::BufRead, 29 | O: io::Write, 30 | { 31 | debug!("Parsing notebook content-type."); 32 | 33 | let content_bytes = b"(* Content-type: "; 34 | 35 | let pos = { 36 | let buf = input.fill_buf()?; 37 | buf.windows(content_bytes.len()) 38 | .position(|w| w == content_bytes) 39 | }; 40 | 41 | match pos { 42 | Some(pos) => { 43 | input.consume(pos); 44 | let mut out = Vec::new(); 45 | input.read_until(b')', &mut out)?; 46 | if out.last() != Some(&b')') { 47 | Err(io::Error::new( 48 | io::ErrorKind::InvalidInput, 49 | "Unable to locate the end content type specification.", 50 | )) 51 | } else { 52 | output.write_all(out.as_slice())?; 53 | output.write_all(b"\n")?; 54 | Ok(()) 55 | } 56 | } 57 | None => Err(io::Error::new( 58 | io::ErrorKind::InvalidInput, 59 | "Unable to locate the content type specification near the start of the file.", 60 | )), 61 | } 62 | } 63 | 64 | /// Parse the input until the beginning of the notebook specification is 65 | /// reached, and pass that on to the output. 66 | /// 67 | /// ```mathematica 68 | /// (* Beginning of Notebook Content *) 69 | /// ``` 70 | /// 71 | /// The consume everything up to (and including) the closing parenthesis. The 72 | /// output includes an extra new line before and after the beginning of notebook 73 | /// specification. 74 | fn parse_beginning_notebook(input: &mut I, output: &mut O) -> Result<(), io::Error> 75 | where 76 | I: io::BufRead, 77 | O: io::Write, 78 | { 79 | debug!("Parsing beginning of notebook specification."); 80 | 81 | let beginning_bytes = &b"(* Beginning of Notebook Content *)"[..]; 82 | 83 | let pos = { 84 | let buf = input.fill_buf()?; 85 | buf.windows(beginning_bytes.len()) 86 | .position(|w| w == beginning_bytes) 87 | }; 88 | 89 | match pos { 90 | Some(pos) => { 91 | input.consume(pos); 92 | let mut out = Vec::new(); 93 | input.read_until(b')', &mut out)?; 94 | output.write_all(b"\n")?; 95 | output.write_all(out.as_slice())?; 96 | output.write_all(b"\n")?; 97 | Ok(()) 98 | } 99 | None => Err(io::Error::new( 100 | io::ErrorKind::InvalidInput, 101 | "Unable to locate the beginning of Notebook content specification.", 102 | )), 103 | } 104 | } 105 | 106 | #[cfg(test)] 107 | mod test { 108 | #[test] 109 | fn content_type() { 110 | // Extra before input 111 | //////////////////////////////////////// 112 | let mut output = Vec::new(); 113 | let mut input = &b"ABC(* Content-type: application/vnd.wolfram.mathematica *)\n"[..]; 114 | assert!(super::parse_content_type(&mut input, &mut output).is_ok()); 115 | assert_eq!(input, b"\n"); 116 | assert_eq!( 117 | output, 118 | &b"(* Content-type: application/vnd.wolfram.mathematica *)\n"[..] 119 | ); 120 | 121 | // Longer valid input 122 | //////////////////////////////////////// 123 | let mut output = Vec::new(); 124 | let mut input = &b"(* Content-type: application/vnd.wolfram.mathematica *)\n\ 125 | \n\ 126 | (*** Wolfram Notebook File ***)\n\ 127 | (* http://www.wolfram.com/nb *)"[..]; 128 | assert!(super::parse_content_type(&mut input, &mut output).is_ok()); 129 | assert_eq!( 130 | input, 131 | &b"\n\n(*** Wolfram Notebook File ***)\n(* http://www.wolfram.com/nb *)"[..] 132 | ); 133 | assert_eq!( 134 | output, 135 | &b"(* Content-type: application/vnd.wolfram.mathematica *)\n"[..] 136 | ); 137 | 138 | // Invalid due to no content type, or invalid form 139 | //////////////////////////////////////// 140 | let mut output = Vec::new(); 141 | let mut input = &b"(*** Wolfram Notebook File ***)\n\ 142 | (* http://www.wolfram.com/nb *)"[..]; 143 | assert!(super::parse_content_type(&mut input, &mut output).is_err()); 144 | 145 | let mut output = Vec::new(); 146 | let mut input = &b"(* Content-type: application/vnd.wolfram.mathematica"[..]; 147 | assert!(super::parse_content_type(&mut input, &mut output).is_err()); 148 | } 149 | 150 | #[test] 151 | fn beginning_notebook() { 152 | // Valid 153 | //////////////////////////////////////// 154 | let mut output = Vec::new(); 155 | let mut input = &b"(* Other stuff *)\n\ 156 | \n\ 157 | (* Beginning of Notebook Content *)\n\ 158 | Notebook[{\n\ 159 | \n"[..]; 160 | assert!(super::parse_beginning_notebook(&mut input, &mut output).is_ok()); 161 | assert_eq!(input, b"\nNotebook[{\n\n"); 162 | assert_eq!(output, &b"\n(* Beginning of Notebook Content *)\n"[..]); 163 | 164 | // Invalid (no Notebook) 165 | //////////////////////////////////////// 166 | let mut output = Vec::new(); 167 | let mut input = &b"Cell[{\n\ 168 | \n"[..]; 169 | assert!(super::parse_beginning_notebook(&mut input, &mut output).is_err()); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/parser/mod.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | mod cell; 4 | mod cell_group_data; 5 | mod header; 6 | mod notebook; 7 | mod utilities; 8 | mod whitespace; 9 | 10 | use self::header::parse_header; 11 | use self::notebook::parse_notebook; 12 | use self::whitespace::WhitespaceCleaner; 13 | 14 | /// Parse the input and write to output the stripped Mathematica notebook. 15 | pub fn parse_input(input: &mut I, output: &mut O) -> Result<(), io::Error> 16 | where 17 | I: io::BufRead, 18 | O: io::Write, 19 | { 20 | debug!("Parsing input."); 21 | 22 | let mut output = WhitespaceCleaner::new(output); 23 | 24 | parse_header(input, &mut output).and(parse_notebook(input, &mut output)) 25 | } 26 | -------------------------------------------------------------------------------- /src/parser/notebook.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | use super::cell::parse_cell_list; 4 | use super::utilities::{load_rest_of_function, read_consume_output}; 5 | 6 | /// Parse the `Notebook[]` function. 7 | /// 8 | /// This function does not require the input to be at the start of the notebook, 9 | /// and instead will consume everything up to it. It does expect that the 10 | /// `Notebook[]` function is coming up soon. 11 | /// 12 | /// Background 13 | /// ========== 14 | /// 15 | /// This is the main function that defines the Notebook's contents. It's 16 | /// general format is: 17 | /// 18 | /// ```mathematica 19 | /// Notebook[{ 20 | /// cell1, 21 | /// cell2, 22 | /// ... 23 | /// }] 24 | /// ``` 25 | /// 26 | /// In addition, optional arguments can be specified such as: 27 | /// 28 | /// ```mathematica 29 | /// WindowSize->{808, 911}, 30 | /// WindowMargins->{{4, Automatic}, {Automatic, 30}}, 31 | /// FrontEndVersion->"11.1 for Linux x86 (64-bit) (April 18, 2017)", 32 | /// ``` 33 | pub fn parse_notebook(input: &mut I, output: &mut O) -> Result<(), io::Error> 34 | where 35 | I: io::BufRead, 36 | O: io::Write, 37 | { 38 | debug!("Parsing Notebook function."); 39 | 40 | let notebook_bytes = b"Notebook["; 41 | let pos = { 42 | let buf = input.fill_buf()?; 43 | buf.windows(notebook_bytes.len()) 44 | .position(|w| w == notebook_bytes) 45 | }; 46 | match pos { 47 | Some(pos) => { 48 | input.consume(pos); 49 | parse_notebook_start(input, output) 50 | .and(parse_cell_list(input, output)) 51 | .and(parse_notebook_end(input, output)) 52 | } 53 | None => Err(io::Error::new( 54 | io::ErrorKind::UnexpectedEof, 55 | "Unable to locate the `Notebook[]` function.", 56 | )), 57 | } 58 | } 59 | 60 | /// Parse the start of the `Notebook[]` function. 61 | /// 62 | /// This function assumes that the input is at the start of the Notebook 63 | /// function. 64 | fn parse_notebook_start(input: &mut I, output: &mut O) -> Result<(), io::Error> 65 | where 66 | I: io::BufRead, 67 | O: io::Write, 68 | { 69 | debug!("Parsing start of Notebook function."); 70 | 71 | let pos = { 72 | let buf = input.fill_buf()?; 73 | buf.iter().position(|&c| c == b'{') 74 | }; 75 | match pos { 76 | Some(pos) => read_consume_output(input, output, pos), 77 | None => Err(io::Error::new( 78 | io::ErrorKind::UnexpectedEof, 79 | "EOF reached before finding start of the list of cells within `Notebook[]`.", 80 | )), 81 | } 82 | } 83 | 84 | /// Parse the end of the `Notebook[]` function. 85 | /// 86 | /// The input should be at the end of the list of cells, just after the closing 87 | /// brace. 88 | /// 89 | /// Since `Notebook` does not appear to store any optional information that 90 | /// ought to be kept, this function simply consumes everything up to the closing 91 | /// bracket of the function. 92 | /// 93 | /// Finally, it adds the information `(* End of Notebook Content *)` to the end 94 | /// of the output. 95 | fn parse_notebook_end(input: &mut I, output: &mut O) -> Result<(), io::Error> 96 | where 97 | I: io::BufRead, 98 | O: io::Write, 99 | { 100 | debug!("Parsing end of Notebook function."); 101 | 102 | let (s, _) = load_rest_of_function(input)?; 103 | match s.first() { 104 | Some(&b',') | Some(&b']') => output.write_all(b"]\n(* End of Notebook Content *)\n"), 105 | _ => Err(io::Error::new( 106 | io::ErrorKind::InvalidInput, 107 | "Expected to be right after an argument when parsing the end of `Notebook[]`.", 108 | )), 109 | } 110 | } 111 | 112 | #[cfg(test)] 113 | mod test { 114 | #[test] 115 | fn notebook_start() { 116 | // Valid 117 | //////////////////////////////////////// 118 | let mut output = Vec::new(); 119 | let mut input = &b"Notebook[{\n\nCell["[..]; 120 | assert!(super::parse_notebook_start(&mut input, &mut output).is_ok()); 121 | assert_eq!(input, b"{\n\nCell["); 122 | assert_eq!(&output, b"Notebook["); 123 | 124 | // Invalid 125 | //////////////////////////////////////// 126 | let mut output = Vec::new(); 127 | let mut input = &b"Notebook[\n\nCell["[..]; 128 | assert!(super::parse_notebook_start(&mut input, &mut output).is_err()); 129 | 130 | let mut output = Vec::new(); 131 | let mut input = &b"Cell[\n\nCell["[..]; 132 | assert!(super::parse_notebook_start(&mut input, &mut output).is_err()); 133 | } 134 | 135 | #[test] 136 | fn notebook_end() { 137 | // Valid 138 | //////////////////////////////////////// 139 | let mut output = Vec::new(); 140 | let mut input = &br#", 141 | WindowSize->{808, 911}, 142 | WindowMargins->{{4, Automatic}, {Automatic, 30}}, 143 | FrontEndVersion->"11.1 for Linux x86 (64-bit) (April 18, 2017)", 144 | StyleDefinitions->FrontEnd`FileName[{$RootDirectory, "home", "josh", "src", 145 | "Mathematica"}, "Stylesheet.nb", CharacterEncoding -> "UTF-8"] 146 | ] 147 | (* End of Notebook Content *) 148 | 149 | (* Internal cache information *) 150 | (*CellTagsOutline 151 | CellTagsIndex->{} 152 | *) 153 | (*CellTagsIndex 154 | CellTagsIndex->{} 155 | *)"#[..]; 156 | assert!(super::parse_notebook_end(&mut input, &mut output).is_ok()); 157 | assert_eq!( 158 | input, 159 | &br#" 160 | (* End of Notebook Content *) 161 | 162 | (* Internal cache information *) 163 | (*CellTagsOutline 164 | CellTagsIndex->{} 165 | *) 166 | (*CellTagsIndex 167 | CellTagsIndex->{} 168 | *)"#[..] 169 | ); 170 | assert_eq!( 171 | output.as_slice(), 172 | &b"]\n(* End of Notebook Content *)\n"[..] 173 | ); 174 | 175 | // Invalid 176 | //////////////////////////////////////// 177 | let mut output = Vec::new(); 178 | let mut input = &br"WindowSize->{808, 911}"[..]; 179 | assert!(super::parse_notebook_end(&mut input, &mut output).is_err()); 180 | } 181 | 182 | #[test] 183 | fn notebook() { 184 | // Valid 185 | //////////////////////////////////////// 186 | let mut output = Vec::new(); 187 | let mut input = &br#" 188 | (* Beginning of Notebook Content *) 189 | Notebook[{ 190 | Cell[1], 191 | Cell[2] 192 | }, 193 | WindowSize->{1272, 1534}, 194 | WindowMargins->{{4, Automatic}, {Automatic, 30}}, 195 | FrontEndVersion->"11.1 for Linux x86 (64-bit) (April 18, 2017)", 196 | StyleDefinitions->FrontEnd`FileName[{$RootDirectory, "home", "josh", "src", 197 | "Mathematica"}, "Stylesheet.nb", CharacterEncoding -> "UTF-8"] 198 | ] 199 | (* End of Notebook Content *) 200 | "#[..]; 201 | assert!(super::parse_notebook(&mut input, &mut output).is_ok()); 202 | assert_eq!(input, &b"\n(* End of Notebook Content *)\n"[..]); 203 | assert_eq!( 204 | output, 205 | &br#"Notebook[{ 206 | Cell[1], 207 | Cell[2] 208 | }] 209 | (* End of Notebook Content *) 210 | "#[..] 211 | ); 212 | 213 | // Invalid 214 | //////////////////////////////////////// 215 | let mut output = Vec::new(); 216 | let mut input = &br#"CellGroupData[{ 217 | Cell[1], 218 | Cell[2] 219 | }]"#[..]; 220 | assert!(super::parse_notebook(&mut input, &mut output).is_err()); 221 | } 222 | 223 | } 224 | -------------------------------------------------------------------------------- /src/parser/utilities.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | /// Parse a function of the form `Foo[...]` from the buffer, and return a slice 4 | /// containing *only* the function (or an error if the input ended before the 5 | /// end of the function). It returns the pair `s: Vec` and `args: 6 | /// Vec`. The first is the list of bytes that make up the full function. 7 | /// The second is a list of indices where the arguments start and end, such that 8 | /// argument `n` starts at index `args[n] + 1` and ends at `args[n+1]`. The 9 | /// `+1` offset is due to the comma (or opening `[`). 10 | /// 11 | /// The function recognized strings, but does **not** recognize comments as 12 | /// Mathematica does not produce any comments within the main `Notebook[]` 13 | /// function itself. 14 | pub fn load_function(input: &mut I) -> Result<(Vec, Vec), io::Error> 15 | where 16 | I: io::BufRead, 17 | { 18 | debug!("Loading function into array."); 19 | 20 | let mut s = Vec::new(); 21 | let mut args = Vec::new(); 22 | 23 | let mut depth = 0; 24 | let mut in_string = false; 25 | let mut idx = 0; 26 | while depth > 0 || args.is_empty() { 27 | let consumed_length = { 28 | let buf = input.fill_buf()?; 29 | 30 | if buf.is_empty() { 31 | return Err(io::Error::new( 32 | io::ErrorKind::UnexpectedEof, 33 | "EOF reached before end of a function.", 34 | )); 35 | } 36 | 37 | let mut buf_idx = 0; 38 | for &c in buf { 39 | // Check if we've gone passed the end of the function; and if 40 | // not, add the byte to the output. 41 | if depth == 0 && !args.is_empty() { 42 | break; 43 | } else { 44 | s.push(c); 45 | idx += 1; 46 | buf_idx += 1; 47 | } 48 | 49 | match (c, depth, in_string) { 50 | (b'"', _, _) => in_string = !in_string, 51 | 52 | (b',', 1, false) => args.push(idx), 53 | 54 | (b'[', 0, false) => { 55 | depth += 1; 56 | args.push(idx); 57 | } 58 | (b'[', _, false) => depth += 1, 59 | 60 | (b']', 1, false) => { 61 | depth -= 1; 62 | args.push(idx); 63 | } 64 | (b']', _, false) => depth -= 1, 65 | 66 | (b'{', _, false) => depth += 1, 67 | (b'}', _, false) => depth -= 1, 68 | 69 | _ => {} 70 | } 71 | } 72 | 73 | buf_idx 74 | }; 75 | 76 | input.consume(consumed_length); 77 | } 78 | 79 | Ok((s, args)) 80 | } 81 | 82 | /// Parse the remainder of function of the form `Foo[...]` from the buffer, with 83 | /// the buffer starting at any point within the square brackets, and return a 84 | /// slice containing *only* the remainder of the (or an error if the input ended 85 | /// before the end of the function). 86 | /// 87 | /// It returns the pair `s: Vec` and `args: Vec`. The first is the 88 | /// list of bytes that make up the full function. The second is a list of 89 | /// indices where the arguments start and end, such that argument `n` starts at 90 | /// index `args[n] + 1` and ends at `args[n+1]`. The `+1` offset is due to the 91 | /// comma (or closing `]`). 92 | /// 93 | /// Note that since it is assumed that the function starts *inside* the 94 | /// function, it does not know which argument it is up to. Furthermore, 95 | /// `args[0]` will indicate only where the next argument starts from where it 96 | /// started parsing. 97 | /// 98 | /// The function recognized strings, but does **not** recognize comments as 99 | /// Mathematica does not produce any comments within the main `Notebook[]` 100 | /// function itself. 101 | pub fn load_rest_of_function(input: &mut I) -> Result<(Vec, Vec), io::Error> 102 | where 103 | I: io::BufRead, 104 | { 105 | debug!("Loading rest of function into array."); 106 | 107 | let mut s = Vec::new(); 108 | let mut args = Vec::new(); 109 | 110 | let mut depth = 1; 111 | let mut in_string = false; 112 | let mut idx = 0; 113 | while depth > 0 { 114 | let consumed_length = { 115 | let buf = input.fill_buf()?; 116 | 117 | if buf.is_empty() { 118 | return Err(io::Error::new( 119 | io::ErrorKind::UnexpectedEof, 120 | "EOF reached before end of a function.", 121 | )); 122 | } 123 | 124 | let mut buf_idx = 0; 125 | for &c in buf { 126 | // Check if we've gone passed the end of the function; and if 127 | // not, add the byte to the output. 128 | if depth == 0 && !args.is_empty() { 129 | break; 130 | } else { 131 | s.push(c); 132 | idx += 1; 133 | buf_idx += 1; 134 | } 135 | 136 | match (c, depth) { 137 | (b'"', _) => in_string = !in_string, 138 | 139 | (b',', 1) => args.push(idx), 140 | 141 | (b'[', 0) => { 142 | depth += 1; 143 | args.push(idx); 144 | } 145 | (b'[', _) => depth += 1, 146 | 147 | (b']', 1) => { 148 | depth -= 1; 149 | args.push(idx); 150 | } 151 | (b']', _) => depth -= 1, 152 | 153 | (b'{', _) => depth += 1, 154 | (b'}', _) => depth -= 1, 155 | 156 | _ => {} 157 | } 158 | } 159 | 160 | buf_idx 161 | }; 162 | 163 | input.consume(consumed_length); 164 | } 165 | 166 | Ok((s, args)) 167 | } 168 | 169 | /// Read, consume the specified number of bytes from the input, and output them 170 | /// to the specified output. 171 | pub fn read_consume_output(input: &mut I, output: &mut O, len: usize) -> Result<(), io::Error> 172 | where 173 | I: io::BufRead, 174 | O: io::Write, 175 | { 176 | { 177 | let buf = input.fill_buf()?; 178 | if buf.len() < len { 179 | return Err(io::Error::new( 180 | io::ErrorKind::UnexpectedEof, 181 | "EOF reached before being able to read specified number of bytes.", 182 | )); 183 | } else { 184 | output.write_all(&buf[..len])?; 185 | } 186 | } 187 | input.consume(len); 188 | 189 | Ok(()) 190 | } 191 | 192 | /// Check the start of the input and make sure it contains the specified bytes. 193 | /// 194 | /// If the input is too short for the match, an error will be raised as opposed 195 | /// to an invalid match. 196 | pub fn check_start(input: &mut I, pat: &[u8]) -> Result 197 | where 198 | I: io::BufRead, 199 | { 200 | { 201 | let buf = input.fill_buf()?; 202 | if buf.len() < pat.len() { 203 | return Err(io::Error::new( 204 | io::ErrorKind::UnexpectedEof, 205 | "EOF reached before being able to read specified number of bytes.", 206 | )); 207 | } 208 | 209 | Ok(&buf[..pat.len()] == pat) 210 | } 211 | } 212 | 213 | #[cfg(test)] 214 | mod test { 215 | #[test] 216 | fn load_function() { 217 | // Simple function 218 | //////////////////////////////////////// 219 | let mut input = &b"Foo[x, y, z] Bar[x, y, z]"[..]; 220 | let (s, args) = super::load_function(&mut input).unwrap(); 221 | assert_eq!(input, &b" Bar[x, y, z]"[..]); 222 | assert_eq!(s, b"Foo[x, y, z]"); 223 | assert_eq!(args, vec![4, 6, 9, 12]); 224 | assert_eq!(&s[args[0]..args[1]], b"x,"); 225 | assert_eq!(&s[args[1]..args[2]], b" y,"); 226 | assert_eq!(&s[args[2]..args[3]], b" z]"); 227 | 228 | // Nested functions 229 | //////////////////////////////////////// 230 | let mut input = &b"Foo[Bar[Sin[x, y], z], P[x]]"[..]; 231 | let (s, args) = super::load_function(&mut input).unwrap(); 232 | assert!(input.is_empty()); 233 | assert_eq!(s, b"Foo[Bar[Sin[x, y], z], P[x]]"); 234 | assert_eq!(args, vec![4, 22, 28]); 235 | assert_eq!(&s[args[0]..args[1]], b"Bar[Sin[x, y], z],"); 236 | assert_eq!(&s[args[1]..args[2]], b" P[x]]"); 237 | 238 | // With list 239 | //////////////////////////////////////// 240 | let mut input = &b"Foo[{x, y, z}, {1, 2, 3}]"[..]; 241 | let (s, args) = super::load_function(&mut input).unwrap(); 242 | assert!(input.is_empty()); 243 | assert_eq!(s, b"Foo[{x, y, z}, {1, 2, 3}]"); 244 | assert_eq!(args, vec![4, 14, 25]); 245 | assert_eq!(&s[args[0]..args[1]], b"{x, y, z},"); 246 | assert_eq!(&s[args[1]..args[2]], b" {1, 2, 3}]"); 247 | 248 | // Without end 249 | //////////////////////////////////////// 250 | let mut input = &b"Foo[{x, y, z}, {1, 2, 3}"[..]; 251 | assert!(super::load_function(&mut input).is_err()); 252 | } 253 | 254 | #[test] 255 | fn load_rest_of_function() { 256 | // Simple function 257 | //////////////////////////////////////// 258 | let mut input = &b"x, y, z] Bar[x, y, z]"[..]; 259 | let (s, args) = super::load_rest_of_function(&mut input).unwrap(); 260 | assert_eq!(input, b" Bar[x, y, z]"); 261 | assert_eq!(s, b"x, y, z]"); 262 | assert_eq!(args, vec![2, 5, 8]); 263 | assert_eq!(&s[..args[0]], b"x,"); 264 | assert_eq!(&s[args[0]..args[1]], b" y,"); 265 | assert_eq!(&s[args[1]..args[2]], b" z]"); 266 | 267 | // Nested functions 268 | //////////////////////////////////////// 269 | let mut input = &b"Bar[Sin[x, y], z], P[x]]"[..]; 270 | let (s, args) = super::load_rest_of_function(&mut input).unwrap(); 271 | assert!(input.is_empty()); 272 | assert_eq!(s, b"Bar[Sin[x, y], z], P[x]]"); 273 | assert_eq!(args, vec![18, 24]); 274 | assert_eq!(&s[..args[0]], b"Bar[Sin[x, y], z],"); 275 | assert_eq!(&s[args[0]..args[1]], b" P[x]]"); 276 | 277 | // With list 278 | //////////////////////////////////////// 279 | let mut input = &b"{x, y, z}, {1, 2, 3}]"[..]; 280 | let (s, args) = super::load_rest_of_function(&mut input).unwrap(); 281 | assert!(input.is_empty()); 282 | assert_eq!(s, b"{x, y, z}, {1, 2, 3}]"); 283 | assert_eq!(args, vec![10, 21]); 284 | assert_eq!(&s[..args[0]], b"{x, y, z},"); 285 | assert_eq!(&s[args[0]..args[1]], b" {1, 2, 3}]"); 286 | 287 | // Without End 288 | //////////////////////////////////////// 289 | let mut input = &b"x, y, Foo[z], Bar[x, y, z]"[..]; 290 | assert!(super::load_rest_of_function(&mut input).is_err()); 291 | } 292 | 293 | #[test] 294 | fn read_consume_output() { 295 | let mut input = &b"FooBar 1234567890"[..]; 296 | let mut output = Vec::new(); 297 | assert!(super::read_consume_output(&mut input, &mut output, 3).is_ok()); 298 | assert_eq!(input, b"Bar 1234567890"); 299 | assert_eq!(&output, b"Foo"); 300 | 301 | assert!(super::read_consume_output(&mut input, &mut output, 3).is_ok()); 302 | assert_eq!(input, b" 1234567890"); 303 | assert_eq!(&output, b"FooBar"); 304 | 305 | assert!(super::read_consume_output(&mut input, &mut output, 100).is_err()); 306 | } 307 | 308 | #[test] 309 | fn check_start() { 310 | let mut input = &b"FooBar"[..]; 311 | assert!(super::check_start(&mut input, b"Foo").is_ok()); 312 | assert_eq!(super::check_start(&mut input, b"Foo").unwrap(), true); 313 | assert!(super::check_start(&mut input, b"Bar").is_ok()); 314 | assert_eq!(super::check_start(&mut input, b"Bar").unwrap(), false); 315 | assert!(super::check_start(&mut input, b"FooBar123").is_err()); 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /src/parser/whitespace.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use std::io::BufRead; 3 | 4 | /// A simple intermediate buffer that removes trailing whitespaces on each line 5 | /// that it is given before passing it on to the underlying output. 6 | /// 7 | /// This assumes that the contents of the file can be separated into lines and 8 | /// thus assumes that it is valid UTF8. 9 | pub struct WhitespaceCleaner { 10 | line_buffer: String, 11 | output: O, 12 | } 13 | 14 | impl WhitespaceCleaner 15 | where 16 | O: io::Write, 17 | { 18 | /// Create a new instance of `WhitespaceCleaner` with the underlying output. 19 | pub fn new(output: O) -> Self { 20 | WhitespaceCleaner { 21 | line_buffer: String::with_capacity(1024 * 8), 22 | output, 23 | } 24 | } 25 | } 26 | 27 | impl io::Write for WhitespaceCleaner 28 | where 29 | O: io::Write, 30 | { 31 | fn write(&mut self, buf: &[u8]) -> io::Result { 32 | let mut bytes_read = 0; 33 | while !(&buf[bytes_read..]).is_empty() { 34 | bytes_read += (&buf[bytes_read..]).read_line(&mut self.line_buffer)?; 35 | // read_line will read up to the next newline, or the end of the 36 | // buffer. We only want to strip trailing whitespaces if it *is* 37 | // the end of the line and not the end of the buffer. 38 | if self.line_buffer.as_bytes().last() == Some(&0xA) { 39 | { 40 | let s = self.line_buffer.trim_end(); 41 | self.output.write_all(s.as_bytes())?; 42 | self.output.write_all(&[0xA])?; 43 | } 44 | self.line_buffer.clear(); 45 | } 46 | } 47 | 48 | Ok(bytes_read) 49 | } 50 | 51 | /// Flush the current content of the buffer and force it to be given to the 52 | /// underlying output. 53 | /// 54 | /// # Warning 55 | /// 56 | /// Unless the internal buffer is was empty, there is no guarantee that the 57 | /// output will have trailing whitespaces removed. 58 | fn flush(&mut self) -> io::Result<()> { 59 | if self.line_buffer.is_empty() { 60 | Ok(()) 61 | } else { 62 | self.output.write_all(self.line_buffer.as_bytes())?; 63 | self.line_buffer.clear(); 64 | Ok(()) 65 | } 66 | } 67 | } 68 | 69 | #[cfg(test)] 70 | mod test { 71 | use std::io::Write; 72 | 73 | use super::WhitespaceCleaner; 74 | 75 | #[test] 76 | fn write() { 77 | // First with nicely terminated lines 78 | let mut output: Vec = Vec::new(); 79 | let input = &br#" 80 | the quick 81 | brown fox 82 | jump 83 | over 84 | the 85 | lazy dog. 86 | "#[..]; 87 | 88 | { 89 | let mut wc = WhitespaceCleaner::new(&mut output); 90 | wc.write_all(input).is_ok(); 91 | wc.flush().is_ok(); 92 | } 93 | assert_eq!( 94 | &String::from_utf8(output).unwrap(), 95 | r#" 96 | the quick 97 | brown fox 98 | jump 99 | over 100 | the 101 | lazy dog. 102 | "# 103 | ); 104 | 105 | // Try a slightly messier output 106 | let mut output: Vec = Vec::new(); 107 | let input = "abc \n123 \n456"; 108 | 109 | { 110 | let mut wc = WhitespaceCleaner::new(&mut output); 111 | wc.write_all(input.as_bytes()).is_ok(); 112 | wc.flush().is_ok(); 113 | } 114 | assert_eq!(&String::from_utf8(output).unwrap(), "abc\n123\n456"); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | out-*.nb -------------------------------------------------------------------------------- /tests/notebook.nb: -------------------------------------------------------------------------------- 1 | (* Content-type: application/vnd.wolfram.mathematica *) 2 | 3 | (*** Wolfram Notebook File ***) 4 | (* http://www.wolfram.com/nb *) 5 | 6 | (* CreatedBy='Mathematica 11.1' *) 7 | 8 | (*CacheID: 234*) 9 | (* Internal cache information: 10 | NotebookFileLineBreakTest 11 | NotebookFileLineBreakTest 12 | NotebookDataPosition[ 158, 7] 13 | NotebookDataLength[ 36445, 820] 14 | NotebookOptionsPosition[ 31620, 700] 15 | NotebookOutlinePosition[ 32069, 716] 16 | CellTagsIndexPosition[ 32026, 713] 17 | WindowFrame->Normal*) 18 | 19 | (* Beginning of Notebook Content *) 20 | Notebook[{ 21 | 22 | Cell[CellGroupData[{ 23 | Cell["Test Notebook", "Title",ExpressionUUID->"1376908b-4a40-4de4-a53f-0d15d9a99a7b"], 24 | 25 | Cell["\<\ 26 | This is a simple test notebook. It features many different kind of cells.\ 27 | \>", "Text",ExpressionUUID->"19ea30eb-725d-4965-b150-04e4a979540a"], 28 | 29 | Cell[BoxData[ 30 | RowBox[{ 31 | RowBox[{"(*", " ", 32 | RowBox[{"Initialization", " ", "cell"}], " ", "*)"}], 33 | "\[IndentingNewLine]", 34 | RowBox[{ 35 | RowBox[{"f", "[", "x_", "]"}], ":=", 36 | FractionBox[ 37 | RowBox[{"Sin", "[", "x", "]"}], "x"]}]}]], "Input", 38 | InitializationCell-> 39 | True,ExpressionUUID->"f9f2c72e-9519-4211-9e6e-4fbe0a1fb293"], 40 | 41 | Cell[CellGroupData[{ 42 | 43 | Cell[BoxData[ 44 | RowBox[{ 45 | RowBox[{"(*", " ", 46 | RowBox[{"Simple", " ", "input", " ", "cell"}], " ", "*)"}], 47 | "\[IndentingNewLine]", 48 | RowBox[{ 49 | RowBox[{"Plot", "[", 50 | RowBox[{ 51 | FractionBox[ 52 | RowBox[{"Sin", "[", "x", "]"}], "x"], ",", 53 | RowBox[{"{", 54 | RowBox[{"x", ",", 55 | RowBox[{ 56 | RowBox[{"-", "4"}], "\[Pi]"}], ",", 57 | RowBox[{"4", "\[Pi]"}]}], "}"}]}], "]"}], "\[IndentingNewLine]", 58 | RowBox[{"Plot", "[", 59 | RowBox[{ 60 | FractionBox["1", 61 | RowBox[{"x", "-", "x"}]], ",", 62 | RowBox[{"{", 63 | RowBox[{"x", ",", 64 | RowBox[{"-", "2"}], ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", 65 | 66 | RowBox[{ 67 | "Print", "[", "\"\\"", "]"}]}]}]], "Input",Expre\ 68 | ssionUUID->"ce415ae6-d359-4181-aeab-042280ba951b"], 69 | 70 | Cell[BoxData[ 71 | FormBox[ 72 | GraphicsBox[{{{{}, {}, 73 | TagBox[ 74 | {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], 75 | Opacity[1.], LineBox[CompressedData[" 76 | 1:eJwVl3k4Vd8Xxs3JfK8p00Xci5KICqmtDEUypZKkUhLKUKhQhqQBoSRKqq8x 77 | JPM172UerspclESJiKvMU37n99d53uc9Z+33s9dez7OPvKOHtRMbCwvLKCsL 78 | y/+fpiYCBsvyKjAmtGMQfjlV7SoKmOKmqMBMueTKkrQhVpUffy4mqQL9Bde8 79 | 22VtsMBi44IGWQU+G30K86aew+0ZwTkX2FTAJ7XpZ9ZWb2zLPSvRM6QMa8cv 80 | PjqLQrFz4+ep3GRleDPq+iHoYCy21TRNqnqhDO+yhpNgIhYfeFFysPWZMmjl 81 | PZkYinqMN119nDbySBmOpE8p1nfG4UmahT0lVBkCD1jllx1PwL5hNY3h55RB 82 | cO7WdWSfhEONXiedpypDi6+5vZpoCoZwP0tZeWXo+rjIuH0hBa+0H2T7JK0M 83 | 2K3H9nl5Cr7iMOlkIqIMr3o6HnKdScWOVzW3qLIrg5vFJaW4jDSMXleW//mm 84 | BN8SuBSsVF7jJb6OTwGJStC9b9980s83eMfh5Pvb45Xg+wspC66tOfhygrfe 85 | 5CMlMBJJzF/1zcG/qOIvT4UrQdQ8aTSO8y3+tMfeeZ+fEiiStEtSBXJxsefP 86 | 2XW2SuCsFJpYI5mHvbqWyI+EleCwz7vtv9fycZy1hV2soBLobrLsnJcowBVt 87 | ya8e8yqBfd4ZLdAswFzvzNTj2ZVABmla3D5fgBPrkw49n6bBd09Jv86mAtxU 88 | vO9ueicNJL8/pokHFeJJrScfMj7QwJ2R7Vv8uBALF4yLZTJosKv8/CberELs 89 | 8DY2NbuWBoc6szk7uwrxdPrPmrwCGjRuvlHdpliEKQn3V8sf0eA82cBGpbgI 90 | G4oPGFZG0UBHsC54oqEIuzzWjKgKp4Fv97o3pz8W4cKYL5LVt2gA3/3uWs8X 91 | YZP7atoNV2hwAD10tNMsxu7ctwIbPWiQu1MwLGJvMY4N+9jQ5EaDD3NPPrta 92 | FOOvIUFHGGdpoCro37rJtRh7+3dcbjtMg72L+7tynhXjp4u0snYLGux/MvxA 93 | J70Y46v+rJ0HaTB4c//ipfxizOOtGN1tQAMhv8L8jsZivPXvtY89iAZ81l4e 94 | bB3F2MbzHeXTLhpsXrKl930uxi8u+r7p06TB1wCP9luTxbhurGXm81YamJJE 95 | pGzmi/HYBVm9/s00SG5o/8pYK8ZaTk0tAwo02FBIa88VpGO779LkQVliPy9S 96 | g2XE6TjwjNfxISkasLIK5qhT6LjlpOToD2EatLNaRZlspmOLF3poSZAGC7uH 97 | vDQ06Ljrm0OcIB8NApILLtbsoGPbjcETitw0iNo9cHBlFx33n0021OWggSJf 98 | 7pev+nTsmFr/zIKFBi8VkidcjOj458+Rv+dWqBDcdMH8uQkduynzmPotUEHh 99 | zvCHa4foeMpF9VXUDBXC92sarljSsU+W+ULKFBXUT/53U8mGjpd+e1qU/aZC 100 | y8Oyw0tHifxqj9I+jFKBd5tegvdxOubwLFr98YMKzuvkaXEn6Phe3kebpW9U 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VOJXl4yhP208N 118 | d4m8B7U3bnmWj9UyHKP2BynCrUa5kIQT+fiS+NXVAx6KkLbluff0xzw8Nvui 119 | 9+AhRTBHmea8OBd/z/8TY7VeEU6F6gTqx2bjRK6lEDtORbgxobvplVE2PmrH 120 | 5n2WVREKOrHPlbks3MQqfNRnUQFmNb90eh7NwjmWWpIJvxSAm+d4wJhgJr42 121 | 6fvft2YFGPoXMI5d0jHfppV8j/sKcPxsS9YreIV3vOLqiuRVAD6LjnLntVCs 122 | t7FDLXxBHlxeRz+L0MtAL4V5tQ7PyMOhOfn+0ZwMxM5pqCM1JQ+u1h0rfPKv 123 | UctIkUHWiDzo7lHPSeHIRLZvEmwZPfKwqHC9+lNTFvLWPhPCWyQPXOE1V8MN 124 | 3qJs86nucC95uMjd5jm3mI+E9FU+H74kD3nXvHSythSgKxqO36Rc5KH69H/p 125 | CmcKkK5I11jWaXmYeOV360RjAWrqpa8xLOQh9f03zIguRD/OBarwqcmDNevf 126 | 211ixUjaX+BGxJgc7Nd4Rv86WoJcUlrEn/+Ug6TnnAtHhUpR8buw/DdDcqBs 127 | CYFBO0uRldzayPs+OUiwoN3+EVqKwuqZ1iSGHDiJ3Pb5IlWGmILtynFZhNY8 128 | pczUKUd6OpG1aelyoOXUdlLJvhzddzRxoCfLQb2BWxXnzXKkWFT96NMzOUhW 129 | NrLLh3Jka5f/TzJCDqKcjFJK9lagmpRHXS8uygFZboQyplGJBN9beORekIPY 130 | QoG4neaVyH6el6f6nBy83fVPRN61Es2bhKIhezkw17zTWP+yEqkyvTMVD8mB 131 | F+lGpNH6KnR9g4bRdhM5eJe7o9lxYxVq2DsxYGQkB2nT3U7iu6rQ6VgnUefd 132 | ciDlLHXb0K0KPdY5GvR6ixxo37+zkNRQhYYcyVJlKnIwq172wflLFVKPeF/U 133 | QpUDbxf2t7V/qlDLV+PxcRk5+BaY77VNCqN/t3YeVROQg72yMnX9FzA6+GZ6 134 | ag+PHLDYPo1S98covudtuAWXHPRju5PkSIzOW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 201 | l/RFdyFoHcrcl5nSjNmEChvlnIVga+HEyGxkM87I/DzifkwInqUnKyieasYz 202 | A5uUebWFYPeBhtuflpvw/jd7tLepC8H0zODWj4NN+Kmf9YHjykKQVbk/xb6x 203 | CeuL+l1I3yAEQoE6AcvRTVjs8UOrO38FIWbXWdkwShOu2Frm1T0kCIO7Zk1K 204 | WJqwY8tgjEKnIFzhPBnoOdSI36ypd+ACQWAR8q25nNKIDV0/WC94C4LzA9pc 205 | xcZGfAXx2bjMC8BJv+uxDtwN2NAA3z77UwA2ie7rLBuox2L7L9NPdguAXciO 206 | v2HF9bjE/JOkdYEA2OTf+uLuWI9XTqYM6noIQFrN4oabBXU4NEDPg2+EH7zB 207 | rCRVtxYfCWK+5Orhh8g7JF7O9bWYFvpfB0s9P3hx4l3dPTW4KZx7x+x//LC9 208 | uaWwybMG8z/rWul34IcMveHPa8+rcVzpxftve/hg9W/cpvRyjJ0rZSte1/PB 209 | x7yukDRjjLWrOyaSC/lgU+pZpci2KtzXpG0V/5APTGeddpIHKzHlE8eGYHM+ 210 | kOTJcFk/W47T5xJTrRt4obZxPErpFx2XaL6D2SIe2FRjNn6FPweri0ceIKfx 211 | wP1B1jzGdDbOWDJrU4vjAcVaDrvTn7JwfHXrgLMvD1jUOxgaJ77GVy1a//Xu 212 | 4IHMpbeKWwVT8Q43hl4VfT24a6f9LTZ6ggv/ay4JK+WG0C45m30/otFbUkOu 213 | eCUXiDQlGyVEliFrB5LptywuaNBhXDlwohzNZdp/z3jKBSNdqd/yVCqQnuG0 214 | qO41LphW6kvLbqpETb5y/vaaXFBWIvPu7h3i/+Kzn9Gr15xwMMXtC9fXWkRK 215 | 29q3KY4DtNz2F87UtaArugnsezzYwPp9m2rUqy6ke/vUgVHXFWwdETIWkDyI 216 | mhdupDocXMFp/Px8JlWDyPZiIlv35hUczn1pird3EPkc7q2o/r2MQz45SvgI 217 | DKFc+cMaz9yXceIxs9j314aQUpWxpPnlJaz+9Fqc28HvSGR+y++C6wvY+pWy 218 | ccXPHyjZ1cxkk90CFjr9xPDP2g+07atr2kvdBWzLITsoKjGMLOvTT0cuz+N/ 219 | Qc9FtxwcRuGP5LvP35jHsfVFdpE5w4hNXbRKIngOf9oxv2XY6ydiXliJCrw7 220 | gwU3NXVd/TWCunI0hMzPz+D/3FlOy7GNorKZ89HShjOY3B1R/UZyFIUGtUeX 221 | rk3j6WO57L4HR5FkfFrMtO80Xj7R41uUNYoMGy0fOTv9xXfPn4gsOf8LxVNT 222 | 4yz2TeGL6dfIG+vH0A23PjGK3BQ+vKpa8Lt3DNU7yqr1LjNxzpro49jJMWTn 223 | N6MmfIWJb99hQ/7i4+j26yT1O2cm8b1LhupJzuOob920psee3/iixMV+Xtbf 224 | 6FbdM120MILTKP55iuITaPS9ziOnkhF85IRYgQJtApn3fhwPvzaClbIusK9p 225 | TSDJSeHnnxZ+4lMDJA5T6wmUKx6x5rU4jNPPl9VsCZ9A/a4BdSlL3/Hdre81 226 | Becm0D4fSRlG2Xfssr3asZZtEmUElvj88fuOD2eo9FgJTiLv2BnanuUhbKgS 227 | L7yqNIl4qi7e+7g8iIuHVivuHZtE7hvLEkWWBrC2R2n02beTSGfn3KEzfgM4 228 | I/lId07pJOIw27b2ZukrZvIKZ3fUTqJnPpln9i/34+utX94mf5xETU1PaX4r 229 | nzFHaljohdVJ9Ki/52NDwGf8ly+Q4cPFRA5/yfeEV/twGfPPhJ0gE81KhY9n 230 | r/bi6wXTntlyTLTRwz934N9HLCm2sN11LxNN3KKfUQ38iF+9q5LWMmGikvhp 231 | 8vW1Hhycy6/fbclEFjVuPmSWHmwXMzGdeIqJAkTtdY1Yu7D2VPRmfX8m2r8p 232 | fjwmuBP372gXqAlmIjLqSvzK2omH7remS95lotcXzNausnXgW8feV1nEMlFP 233 | uV5dJnsbTjwX8Kcxk4mkrzt+/cv3AVegEcUfb5kowu+gVjT5PX4+fAJ9KmQi 234 | txsy31pkWvH6oEMr+6uYqO8m144LCgzsVki9V1vDRKZBzHBOlRZs517VLtbI 235 | RJtuVe/U12rC4Zf73Q0/MNHT0MzIfp1GrPDiZS6lk4l4wh5990MNWMck6W5b 236 | DxON3XWKKiLu6VX9Fb1l/Uxkd9982NqyFssHr+2b/sZELeE7d00dqcF6CDay 237 | /yB4Hqwf2XQG8IGjqyqvfzHRNrnh69HvqvCVmRBD9JvgV6BTGZ8qsN6JhPLs 238 | SSb6S73XzvmjDCtK5dz7M8VE7conbugzSzAXf8Rr/mkmyt28RcV/qRgfPn1C 239 | jHWWiaLV1rqKOIuwdcYrBmOOiTw12oOmhArwkdG99ZcWmMhSK1l1s3QeXksK 240 | WPu5yESn3MdyGeY5OLiN6btzmYko3g+49zpl4k7BJ8qnVpjo6/Vtp4v90/BC 241 | GIPksMpEzwN76Jsf/of1/hmoa/0j+s0zS9ln9Rz7DImEDBJ6p9ju96o3H2MD 242 | 01zO82vE/hvwLKsdDcf7l4ZLqwn9cKdbYZNLEJFvOuIXof8HyCTPKg== 243 | "]], 244 | LineBox[CompressedData[" 245 | 1:eJwVVnk4lG8XlrJlHXv2MGMtP4VK8hwqWQoJKW0USgiVSoulskQS2SV7yq4x 246 | I9szZTd2QjuSnUG2JH3z/fVe9/U855z73Oc+7/tudbxi5cTKwsIyv4GF5f/P 247 | qF2XyY2X/JFVzq/w8X8M1JkpKHrsWgIqOL+RU5mJXx122knOSEXBQg6fI9YZ 248 | aMLo3Wf9x5monuPQYMtfBlI1kH7Q5JODtGK9JYfWGOjy3lvq1ufy0NeK9bC2 249 | PwzUm+jqylAsQiZiF7SjVhloKS6+mrylBL0bvCmx7TcDicbUC/rykVHoqKf+ 250 | i2UG2hW14Iw2UpCC39fMsUUGsnsiX7FphYpC/fKPci0w0M1wS/7mqbfopvY2 251 | kw3zDFQWlEe17q1CPKtI7cY0A/Xf/8QtQcdIzl9fbnGCge7ApiLGdxqSj6i5 252 | ZjrGQM/37dhU2vMeOVH32NweYqDteiYFYu01yLPFb8b2OwNV656z822qRc92 253 | L23Y/IWBvu2KyEPV9SjnkRRlqYeBPHSybNPLGtDPLE6X/zoZaF2rkoXtTSPy 254 | sn1eYtDKQDI7JqybXzajvoKd+pO1DHRW3eiv9dM29Ij9iq59CQPpxWdHLKW2 255 | oy31otk/8hiIJ3CjwGG7DvTXcXVM7yUDjU+fT5t26UQvEhY1HZMYKL1Osfa/ 256 | 4G7Eas9IvBXAQJF/esI38Pcg49/bgx/5MtA9zYc2XbE9aEXCv8vtKgPZP/85 257 | cjX7A4oWievOusBAwtezuah1fehUZSZ18gADsebadgUf6UdePnydoXoMNDvA 258 | nmT3oR85PyqY/b2TgVoPu6ivDn9EbrnHXljKM1CQorLFvk1fUMuKxZlPazNo 259 | bdy62WHrALL5uSzo82oG/dqUv93UaQAJzZJdIWUGTciyRe94NYB4FAq8v0XN 260 | oH6bUvuNmoPIZXg7X+ztGVT6TmQ6E4bQZ7nVsSXTGeSR0Ms/dnYYsf8i2CYP 261 | TiMn8vZrHRnDaNuRCxzF3dPoVHtQf9noMJoRKQhJqptGZmy70kKv/EReuyKj 262 | 5nOmkbJX3A41vxG0FnPnX577NBo0trPxSBlDR064BPgwppD+zzsOrV/HUEg9 263 | eV5kYAolBqS5q0uPI3T+wLeojilkVT7xcCJpHPWcLScTi6fQe7W7FOeECXRt 264 | pe/8G88plM6XLnb22RSqmKmaeDI+iXZMLE4pHZxFfB1+mU41E+jcbs6rfRdm 265 | Ue4ur+F/hRMoIkjid9CDWaQssbnwTvIEmpBHbCM1s+hM/654mesTKN0+RDrT 266 | cA5JBniROYkTSKhVwlwO5lF47JH8FL9xtFCICsX3LqCdckkn5beOoRa1vYKe 267 | pxdQ0NPkOX/OMZTxUud6g98CEp18RqhljCKrF9v2+tQuoPC1DYsrVaOoOEKy 268 | ofvIIjqw0BOteGIUebgvf4s4t4T8gleMqx+NoFHVQj62oBWkV9qT9/3LMPqU 269 | JeMx17GGOl45WD4+PIhue1QY27xghZ5nZZo717qRIVq8wFfICnM/uEv067vR 270 | ZgGNgIZqVhAPTIu2i+xG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Lc+CPWac1D 404 | xhevrdrKblaCPjcYktn3BufbB6sI8ylB6ARjZ6HCGzxvKLzGKagEC2fLnP9y 405 | vcG3CdvT5rcowTmTOdsPH0pwRIHDZJ2KEugkPR3ydy3BpWONfm4mSnCmzGm3 406 | dkgxZj0dl/M2RAkspHQU7TUL8aEDircLwpUg/Y9HxBijAIerFR/JiGTW49i5 407 | LFhQgEVWm+fD45WA18zaYL9KAVaOW9c7l6MEcW4mZzQl87F5p1Mne6MS9Coe 408 | 1z0w8xonHdRaPcahDG+Xws/fOJGNX+cfj6vmVoaqok9dwmzZuEzktpaKgDIs 409 | Tr5nOBVl4d6f7zzWxZWh12NiXYU9CwsEWfzIUVWGkdtOOy8VZOCgeteWv0eU 410 | IU21l/fAr1TsfSgt5eUzZfghQN7EXhqLAwpr9womKEOuVZl9778YHCk21n/n 411 | ORPzCjy4YxqD80e3C1llK4PvdLui3fdoPBZcGbxGVYb7fuph+RxP8ZnGPs+j 412 | n5UhJ6GHkJsbhN3/+8Nb+V0ZQu45BBiih/hOvEwuaVgZPtDjyn513ccJF51+ 413 | /plSBrGHMdTqVX/cw/nrRPa6MrRD89tLCT74h6fossBGFXhFFdxUXHMVz/fv 414 | eXabQwWoPkgyfsYT87/yb7MUUIHnt+WfLIU7YxlC5uUKYRVI3/BFWXH0HFa/ 415 | 1cBJ2qIC5lJJ11Ye2uK9gxNZkdIqUOz044BToBE2NeHb/2erCkwI6AzSxp2q 416 | /wdwzi0s 417 | "]]}, 418 | Annotation[#, 419 | "Charting`Private`Tag$1767#1"]& ], {}}, {{}, {}, {}}}, {}, {}}, 420 | AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], 421 | Axes->{True, True}, 422 | AxesLabel->{None, None}, 423 | AxesOrigin->{0, 0}, 424 | DisplayFunction->Identity, 425 | Frame->{{False, False}, {False, False}}, 426 | FrameLabel->{{None, None}, {None, None}}, 427 | FrameTicks->{{Automatic, 428 | Charting`ScaledFrameTicks[{Identity, Identity}]}, {Automatic, 429 | Charting`ScaledFrameTicks[{Identity, Identity}]}}, 430 | GridLines->{None, None}, 431 | GridLinesStyle->Directive[ 432 | GrayLevel[0.5, 0.4]], 433 | ImagePadding->All, 434 | Method->{ 435 | "DefaultBoundaryStyle" -> Automatic, "DefaultMeshStyle" -> 436 | AbsolutePointSize[6], "ScalingFunctions" -> None, 437 | "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ 438 | (Identity[#]& )[ 439 | Part[#, 1]], 440 | (Identity[#]& )[ 441 | Part[#, 2]]}& ), "CopiedValueFunction" -> ({ 442 | (Identity[#]& )[ 443 | Part[#, 1]], 444 | (Identity[#]& )[ 445 | Part[#, 2]]}& )}}, 446 | PlotRange-> 447 | NCache[{{(-4) Pi, 4 Pi}, {-0.21723358083481298`, 448 | 0.9999892952885239}}, {{-12.566370614359172`, 449 | 12.566370614359172`}, {-0.21723358083481298`, 0.9999892952885239}}], 450 | PlotRangeClipping->True, 451 | PlotRangePadding->{{ 452 | Scaled[0.02], 453 | Scaled[0.02]}, { 454 | Scaled[0.05], 455 | Scaled[0.05]}}, 456 | Ticks->{Automatic, Automatic}], TraditionalForm]], "Output", 457 | CellChangeTimes->{ 458 | 3.7135980165967712`*^9},ExpressionUUID->"a6d57e30-5bd6-4b6f-b462-\ 459 | 5d3c0480154c"], 460 | 461 | Cell[BoxData[ 462 | FormBox[ 463 | TemplateBox[{ 464 | "Power","infy", 465 | "\"Infinite expression \\!\\(\\*FormBox[FractionBox[\\\"1\\\", \ 466 | \\\"0.`\\\"], TraditionalForm]\\) encountered.\"",2,3,1,18936013414348090244, 467 | "Local"}, 468 | "MessageTemplate"], TraditionalForm]], "Message", "MSG", 469 | CellChangeTimes->{ 470 | 3.713598016988731*^9},ExpressionUUID->"23e46942-bb37-470a-a504-\ 471 | 741b46fb168f"], 472 | 473 | Cell[BoxData[ 474 | FormBox[ 475 | TemplateBox[{ 476 | "Power","infy", 477 | "\"Infinite expression \\!\\(\\*FormBox[FractionBox[\\\"1\\\", \ 478 | \\\"0.`\\\"], TraditionalForm]\\) encountered.\"",2,3,2,18936013414348090244, 479 | "Local"}, 480 | "MessageTemplate"], TraditionalForm]], "Message", "MSG", 481 | CellChangeTimes->{ 482 | 3.7135980169946404`*^9},ExpressionUUID->"47bf6efb-3bcc-44e9-a240-\ 483 | 5f3ef701c143"], 484 | 485 | Cell[BoxData[ 486 | FormBox[ 487 | TemplateBox[{ 488 | "Power","infy", 489 | "\"Infinite expression \\!\\(\\*FormBox[FractionBox[\\\"1\\\", \ 490 | \\\"0.`\\\"], TraditionalForm]\\) encountered.\"",2,3,3,18936013414348090244, 491 | "Local"}, 492 | "MessageTemplate"], TraditionalForm]], "Message", "MSG", 493 | CellChangeTimes->{ 494 | 3.713598017000257*^9},ExpressionUUID->"a50090f8-3444-4769-9913-\ 495 | c824fbd6093f"], 496 | 497 | Cell[BoxData[ 498 | FormBox[ 499 | TemplateBox[{ 500 | "General","stop", 501 | "\"Further output of \\!\\(\\*FormBox[StyleBox[RowBox[{\\\"Power\\\", \ 502 | \\\"::\\\", \\\"infy\\\"}], \\\"MessageName\\\"], TraditionalForm]\\) will be \ 503 | suppressed during this calculation.\"",2,3,4,18936013414348090244,"Local"}, 504 | "MessageTemplate"], TraditionalForm]], "Message", "MSG", 505 | CellChangeTimes->{ 506 | 3.713598017006473*^9},ExpressionUUID->"6aed1ce1-21a6-4c66-8d16-\ 507 | 8ecc7c3b708d"], 508 | 509 | Cell[BoxData[ 510 | FormBox[ 511 | GraphicsBox[{{}, {}, {}}, 512 | AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], 513 | Axes->{True, True}, 514 | AxesLabel->{None, None}, 515 | AxesOrigin->{0, 0}, 516 | DisplayFunction->Identity, 517 | Frame->{{False, False}, {False, False}}, 518 | FrameLabel->{{None, None}, {None, None}}, 519 | FrameTicks->{{Automatic, 520 | Charting`ScaledFrameTicks[{Identity, Identity}]}, {Automatic, 521 | Charting`ScaledFrameTicks[{Identity, Identity}]}}, 522 | GridLines->{None, None}, 523 | GridLinesStyle->Directive[ 524 | GrayLevel[0.5, 0.4]], 525 | ImagePadding->All, 526 | Method->{ 527 | "DefaultBoundaryStyle" -> Automatic, "DefaultMeshStyle" -> 528 | AbsolutePointSize[6], "ScalingFunctions" -> None, 529 | "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ 530 | (Identity[#]& )[ 531 | Part[#, 1]], 532 | (Identity[#]& )[ 533 | Part[#, 2]]}& ), "CopiedValueFunction" -> ({ 534 | (Identity[#]& )[ 535 | Part[#, 1]], 536 | (Identity[#]& )[ 537 | Part[#, 2]]}& )}}, 538 | PlotRange->{{-2, 2}, {0., 0.}}, 539 | PlotRangeClipping->True, 540 | PlotRangePadding->{{ 541 | Scaled[0.02], 542 | Scaled[0.02]}, { 543 | Scaled[0.05], 544 | Scaled[0.05]}}, 545 | Ticks->{Automatic, Automatic}], TraditionalForm]], "Output", 546 | CellChangeTimes->{ 547 | 3.713598017008987*^9},ExpressionUUID->"b16a784c-e8e0-4ae9-bcd7-\ 548 | 14c375829476"], 549 | 550 | Cell[BoxData[ 551 | FormBox["\<\"This statement is false.\"\>", TraditionalForm]], "Print", 552 | CellChangeTimes->{ 553 | 3.713598017009987*^9},ExpressionUUID->"855aca59-2b82-4e81-a494-\ 554 | ac3cfead4027"] 555 | }, Open ]], 556 | 557 | Cell[CellGroupData[{ 558 | 559 | Cell["Chapter", "Chapter",ExpressionUUID->"c4c6b8c7-05a1-42ef-8d7f-d9a36b9b49ff"], 560 | 561 | Cell[CellGroupData[{ 562 | 563 | Cell["Subchapter", "Subchapter",ExpressionUUID->"ce9534f1-6d5e-49b8-9bf6-f0c79db5f242"], 564 | 565 | Cell[CellGroupData[{ 566 | 567 | Cell["Section (closed group)", "Section",ExpressionUUID->"02fc9cc7-1818-4b1f-a53a-6fba79b45eff"], 568 | 569 | Cell[CellGroupData[{ 570 | 571 | Cell["Subsection", "Subsection",ExpressionUUID->"244d5a08-3730-4d27-b27f-bb4b17041ae2"], 572 | 573 | Cell["Subsubsection", "Subsubsection",ExpressionUUID->"93b45fb7-ce82-4eec-8e52-84d5f26e06f8"] 574 | }, Closed]] 575 | }, Closed]], 576 | 577 | Cell[CellGroupData[{ 578 | 579 | Cell["Section (open group)", "Section",ExpressionUUID->"7fd40190-2a68-4c43-958b-a5505ac2de0b"], 580 | 581 | Cell[CellGroupData[{ 582 | 583 | Cell["Subsection", "Subsection",ExpressionUUID->"724b7e9b-3430-4949-bbe6-87b942ed1d1f"], 584 | 585 | Cell[CellGroupData[{ 586 | 587 | Cell["Subsubsection", "Subsubsection",ExpressionUUID->"ae711093-6fb7-427e-bfda-ac3baf2d3524"], 588 | 589 | Cell["Text: Lorem Ipsum dolor sit amet", "Text",ExpressionUUID->"bd0e67ab-9c9f-48d8-9d65-9426e9854831"], 590 | 591 | Cell[BoxData[ 592 | RowBox[{ 593 | RowBox[{"(*", " ", 594 | RowBox[{"Sample", " ", "code"}], " ", "*)"}], "\n", 595 | RowBox[{ 596 | RowBox[{"f", "[", "x_", "]"}], ":=", 597 | FractionBox[ 598 | RowBox[{"Sin", "[", "x", "]"}], "x"]}]}]], "Code",ExpressionUUID->\ 599 | "d596caea-e3e2-406e-91db-a6b6172a58a4"], 600 | 601 | Cell[CellGroupData[{ 602 | 603 | Cell[BoxData[ 604 | FormBox[ 605 | RowBox[{"Manually", " ", "entered", " ", "output", " ", "cell"}], 606 | TraditionalForm]], "Input",ExpressionUUID->"6656aa22-6087-4f86-aa7e-\ 607 | 5e4315b04b9b"], 608 | 609 | Cell[BoxData[ 610 | FormBox[ 611 | RowBox[{"cell", " ", "entered", " ", "Manually", " ", "output"}], 612 | TraditionalForm]], "Output", 613 | CellChangeTimes->{ 614 | 3.713598017185604*^9},ExpressionUUID->"d6efdfe0-2fe8-4411-99ef-\ 615 | 96b2507fc967"] 616 | }, Open ]] 617 | }, Open ]] 618 | }, Open ]] 619 | }, Open ]] 620 | }, Open ]] 621 | }, Open ]], 622 | 623 | Cell[CellGroupData[{ 624 | 625 | Cell["Subtitle", "Subtitle",ExpressionUUID->"e63d0837-5932-4492-850a-185c29a65465"], 626 | 627 | Cell["Subsubtitle", "Subsubtitle",ExpressionUUID->"147ffc62-9c50-42e0-8bb6-4e6f341917ff"], 628 | 629 | Cell[CellGroupData[{ 630 | 631 | Cell["Item", "Item",ExpressionUUID->"34b9351e-10a2-44f9-96ad-83cc61f5de1d"], 632 | 633 | Cell["Item paragraph", "ItemParagraph",ExpressionUUID->"951d0623-f8eb-468f-9725-fd25339b0927"], 634 | 635 | Cell[CellGroupData[{ 636 | 637 | Cell["Subitem", "Subitem",ExpressionUUID->"e768f431-c1a5-4efd-967b-57610de6e0fd"], 638 | 639 | Cell["Subitem paragraph", "SubitemParagraph",ExpressionUUID->"f4f97d73-271b-4cb9-907a-82f0c322c66f"], 640 | 641 | Cell[CellGroupData[{ 642 | 643 | Cell["Subsubitem", "Subsubitem",ExpressionUUID->"7a5202ea-b4fe-42c0-a728-2651c2e3de6a"], 644 | 645 | Cell["subsubitem paragraph", "SubsubitemParagraph",ExpressionUUID->"929584ed-4c57-4d92-aad4-44aa5b6f50b2"] 646 | }, Open ]] 647 | }, Open ]], 648 | 649 | Cell["Numbered item", "ItemNumbered",ExpressionUUID->"0c015301-f354-4503-a0f0-5fecc1365a73"], 650 | 651 | Cell[CellGroupData[{ 652 | 653 | Cell["Numbered subitem", "SubitemNumbered",ExpressionUUID->"cf8b8d5c-b269-43ca-9d06-5cce172f36d2"], 654 | 655 | Cell["Numbered subsubitem", "SubsubitemNumbered",ExpressionUUID->"bd4e2993-585b-4c12-b3e5-803a82339010"] 656 | }, Open ]] 657 | }, Open ]], 658 | 659 | Cell[TextData[{ 660 | "G(p, m) := ", 661 | Cell[BoxData[ 662 | FormBox[ 663 | FractionBox["1", 664 | RowBox[{ 665 | SuperscriptBox["p", "2"], "-", 666 | SuperscriptBox["m", "2"]}]], TraditionalForm]],ExpressionUUID-> 667 | "5c7a0b68-e4f7-488d-bee6-756128c625a2"] 668 | }], "InlineFormula",ExpressionUUID->"23a7b620-71de-4d57-b9c4-21d6d1b62c9b"], 669 | 670 | Cell[BoxData[ 671 | RowBox[{ 672 | RowBox[{"G", 673 | RowBox[{"(", 674 | RowBox[{"p", ",", " ", "m"}], ")"}]}], ":=", 675 | FractionBox["1", 676 | RowBox[{ 677 | SuperscriptBox["p", "2"], "-", 678 | SuperscriptBox["m", "2"]}]]}]], "DisplayFormula",ExpressionUUID->\ 679 | "30a560f7-f497-4494-b8b0-495f9b331b8c"], 680 | 681 | Cell[BoxData[ 682 | RowBox[{ 683 | RowBox[{"G", 684 | RowBox[{"(", 685 | RowBox[{"p", ",", " ", "m"}], ")"}]}], ":=", 686 | FractionBox["1", 687 | RowBox[{ 688 | SuperscriptBox["p", "2"], "-", 689 | SuperscriptBox["m", "2"]}]]}]], "DisplayFormulaNumbered",ExpressionUUID->\ 690 | "0a8a6170-16fa-40ca-a6f7-8149e6b6e65e"], 691 | 692 | Cell["\<\ 693 | Program 1: 694 | if true { 695 | return false 696 | }\ 697 | \>", "Program",ExpressionUUID->"276f47a0-cae2-469e-ac16-09f84352c8a5"] 698 | }, Open ]] 699 | }, Open ]] 700 | }, 701 | WindowSize->{808, 911}, 702 | WindowMargins->{{Automatic, 1748}, {Automatic, 30}}, 703 | FrontEndVersion->"11.1 for Linux x86 (64-bit) (April 18, 2017)", 704 | StyleDefinitions->FrontEnd`FileName[{$RootDirectory, "home", "josh", "src", 705 | "Mathematica"}, "Stylesheet.nb", CharacterEncoding -> "UTF-8"] 706 | ] 707 | (* End of Notebook Content *) 708 | 709 | (* Internal cache information *) 710 | (*CellTagsOutline 711 | CellTagsIndex->{} 712 | *) 713 | (*CellTagsIndex 714 | CellTagsIndex->{} 715 | *) 716 | (*NotebookFileOutline 717 | Notebook[{ 718 | Cell[CellGroupData[{ 719 | Cell[580, 22, 85, 0, 197, "Title", "ExpressionUUID" -> \ 720 | "1376908b-4a40-4de4-a53f-0d15d9a99a7b"], 721 | Cell[668, 24, 153, 2, 62, "Text", "ExpressionUUID" -> \ 722 | "19ea30eb-725d-4965-b150-04e4a979540a"], 723 | Cell[824, 28, 338, 10, 205, "Input", "ExpressionUUID" -> \ 724 | "f9f2c72e-9519-4211-9e6e-4fbe0a1fb293", 725 | InitializationCell->True], 726 | Cell[CellGroupData[{ 727 | Cell[1187, 42, 799, 25, 341, "Input", "ExpressionUUID" -> \ 728 | "ce415ae6-d359-4181-aeab-042280ba951b"], 729 | Cell[1989, 69, 22413, 389, 503, "Output", "ExpressionUUID" -> \ 730 | "a6d57e30-5bd6-4b6f-b462-5d3c0480154c"], 731 | Cell[24405, 460, 381, 10, 80, "Message", "ExpressionUUID" -> \ 732 | "23e46942-bb37-470a-a504-741b46fb168f"], 733 | Cell[24789, 472, 383, 10, 80, "Message", "ExpressionUUID" -> \ 734 | "47bf6efb-3bcc-44e9-a240-5f3ef701c143"], 735 | Cell[25175, 484, 381, 10, 80, "Message", "ExpressionUUID" -> \ 736 | "a50090f8-3444-4769-9913-c824fbd6093f"], 737 | Cell[25559, 496, 454, 10, 43, "Message", "ExpressionUUID" -> \ 738 | "6aed1ce1-21a6-4c66-8d16-8ecc7c3b708d"], 739 | Cell[26016, 508, 1335, 39, 503, "Output", "ExpressionUUID" -> \ 740 | "b16a784c-e8e0-4ae9-bcd7-14c375829476"], 741 | Cell[27354, 549, 188, 4, 45, "Print", "ExpressionUUID" -> \ 742 | "855aca59-2b82-4e81-a494-ac3cfead4027"] 743 | }, Open ]], 744 | Cell[CellGroupData[{ 745 | Cell[27579, 558, 81, 0, 141, "Chapter", "ExpressionUUID" -> \ 746 | "c4c6b8c7-05a1-42ef-8d7f-d9a36b9b49ff"], 747 | Cell[CellGroupData[{ 748 | Cell[27685, 562, 87, 0, 132, "Subchapter", "ExpressionUUID" -> \ 749 | "ce9534f1-6d5e-49b8-9bf6-f0c79db5f242"], 750 | Cell[CellGroupData[{ 751 | Cell[27797, 566, 96, 0, 138, "Section", "ExpressionUUID" -> \ 752 | "02fc9cc7-1818-4b1f-a53a-6fba79b45eff"], 753 | Cell[CellGroupData[{ 754 | Cell[27918, 570, 87, 0, 70, "Subsection", "ExpressionUUID" -> \ 755 | "244d5a08-3730-4d27-b27f-bb4b17041ae2"], 756 | Cell[28008, 572, 93, 0, 70, "Subsubsection", "ExpressionUUID" -> \ 757 | "93b45fb7-ce82-4eec-8e52-84d5f26e06f8"] 758 | }, Closed]] 759 | }, Closed]], 760 | Cell[CellGroupData[{ 761 | Cell[28150, 578, 94, 0, 106, "Section", "ExpressionUUID" -> \ 762 | "7fd40190-2a68-4c43-958b-a5505ac2de0b"], 763 | Cell[CellGroupData[{ 764 | Cell[28269, 582, 87, 0, 94, "Subsection", "ExpressionUUID" -> \ 765 | "724b7e9b-3430-4949-bbe6-87b942ed1d1f"], 766 | Cell[CellGroupData[{ 767 | Cell[28381, 586, 93, 0, 76, "Subsubsection", "ExpressionUUID" -> \ 768 | "ae711093-6fb7-427e-bfda-ac3baf2d3524"], 769 | Cell[28477, 588, 103, 0, 62, "Text", "ExpressionUUID" -> \ 770 | "bd0e67ab-9c9f-48d8-9d65-9426e9854831"], 771 | Cell[28583, 590, 281, 8, 215, "Code", "ExpressionUUID" -> \ 772 | "d596caea-e3e2-406e-91db-a6b6172a58a4"], 773 | Cell[CellGroupData[{ 774 | Cell[28889, 602, 179, 4, 124, "Input", "ExpressionUUID" -> \ 775 | "6656aa22-6087-4f86-aa7e-5e4315b04b9b"], 776 | Cell[29071, 608, 225, 6, 122, "Output", "ExpressionUUID" -> \ 777 | "d6efdfe0-2fe8-4411-99ef-96b2507fc967"] 778 | }, Open ]] 779 | }, Open ]] 780 | }, Open ]] 781 | }, Open ]] 782 | }, Open ]] 783 | }, Open ]], 784 | Cell[CellGroupData[{ 785 | Cell[29393, 624, 83, 0, 109, "Subtitle", "ExpressionUUID" -> \ 786 | "e63d0837-5932-4492-850a-185c29a65465"], 787 | Cell[29479, 626, 89, 0, 64, "Subsubtitle", "ExpressionUUID" -> \ 788 | "147ffc62-9c50-42e0-8bb6-4e6f341917ff"], 789 | Cell[CellGroupData[{ 790 | Cell[29593, 630, 75, 0, 58, "Item", "ExpressionUUID" -> \ 791 | "34b9351e-10a2-44f9-96ad-83cc61f5de1d"], 792 | Cell[29671, 632, 94, 0, 44, "ItemParagraph", "ExpressionUUID" -> \ 793 | "951d0623-f8eb-468f-9725-fd25339b0927"], 794 | Cell[CellGroupData[{ 795 | Cell[29790, 636, 81, 0, 49, "Subitem", "ExpressionUUID" -> \ 796 | "e768f431-c1a5-4efd-967b-57610de6e0fd"], 797 | Cell[29874, 638, 100, 0, 43, "SubitemParagraph", "ExpressionUUID" -> \ 798 | "f4f97d73-271b-4cb9-907a-82f0c322c66f"], 799 | Cell[CellGroupData[{ 800 | Cell[29999, 642, 87, 0, 48, "Subsubitem", "ExpressionUUID" -> \ 801 | "7a5202ea-b4fe-42c0-a728-2651c2e3de6a"], 802 | Cell[30089, 644, 106, 0, 42, "SubsubitemParagraph", "ExpressionUUID" -> \ 803 | "929584ed-4c57-4d92-aad4-44aa5b6f50b2"] 804 | }, Open ]] 805 | }, Open ]], 806 | Cell[30222, 648, 92, 0, 61, "ItemNumbered", "ExpressionUUID" -> \ 807 | "0c015301-f354-4503-a0f0-5fecc1365a73"], 808 | Cell[CellGroupData[{ 809 | Cell[30339, 652, 98, 0, 49, "SubitemNumbered", "ExpressionUUID" -> \ 810 | "cf8b8d5c-b269-43ca-9d06-5cce172f36d2"], 811 | Cell[30440, 654, 104, 0, 48, "SubsubitemNumbered", "ExpressionUUID" -> \ 812 | "bd4e2993-585b-4c12-b3e5-803a82339010"] 813 | }, Open ]] 814 | }, Open ]], 815 | Cell[30571, 658, 315, 9, 96, "InlineFormula", "ExpressionUUID" -> \ 816 | "23a7b620-71de-4d57-b9c4-21d6d1b62c9b"], 817 | Cell[30889, 669, 285, 9, 120, "DisplayFormula", "ExpressionUUID" -> \ 818 | "30a560f7-f497-4494-b8b0-495f9b331b8c"], 819 | Cell[31177, 680, 293, 9, 120, "DisplayFormulaNumbered", "ExpressionUUID" -> \ 820 | "0a8a6170-16fa-40ca-a6f7-8149e6b6e65e"], 821 | Cell[31473, 691, 119, 5, 197, "Program", "ExpressionUUID" -> \ 822 | "276f47a0-cae2-469e-ac16-09f84352c8a5"] 823 | }, Open ]] 824 | }, Open ]] 825 | } 826 | ] 827 | *) 828 | 829 | -------------------------------------------------------------------------------- /tests/notebook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Echo all commands before executing them 4 | set -o xtrace 5 | # Forbid any unset variables 6 | set -o nounset 7 | # Exit on any error 8 | set -o errexit 9 | 10 | TESTS=() 11 | KCOV_BIN="./target/kcov-master/build/src/kcov" 12 | RS_BIN=$(cargo run 2>&1 | grep 'Running' | sed 's/.*`\(.*\)`/\1/') 13 | INPUT_NOTEBOOK="tests/notebook.nb" 14 | 15 | TESTS+=("valid_notebook") 16 | valid_notebook() { 17 | local out_dir="target/kcov-${FUNCNAME[0]}" 18 | mkdir -p $out_dir 19 | $KCOV_BIN \ 20 | --verify \ 21 | --exclude-pattern=/.cargo \ 22 | $out_dir \ 23 | $RS_BIN -i $INPUT_NOTEBOOK -o tests/out-notebook.nb 24 | } 25 | 26 | TESTS+=("valid_pipe") 27 | valid_pipe() { 28 | local out_dir="target/kcov-${FUNCNAME[0]}" 29 | mkdir -p $out_dir 30 | $KCOV_BIN \ 31 | --verify \ 32 | --exclude-pattern=/.cargo \ 33 | $out_dir \ 34 | $RS_BIN <$INPUT_NOTEBOOK >tests/out-pipe.nb 35 | } 36 | 37 | TESTS+=("valid_notebook_v") 38 | valid_notebook_v() { 39 | local out_dir="target/kcov-${FUNCNAME[0]}" 40 | mkdir -p $out_dir 41 | $KCOV_BIN \ 42 | --verify \ 43 | --exclude-pattern=/.cargo \ 44 | $out_dir \ 45 | $RS_BIN -i $INPUT_NOTEBOOK -o tests/out-v.nb 46 | } 47 | 48 | TESTS+=("valid_notebook_vv") 49 | valid_notebook_vv() { 50 | local out_dir="target/kcov-${FUNCNAME[0]}" 51 | mkdir -p $out_dir 52 | $KCOV_BIN \ 53 | --verify \ 54 | --exclude-pattern=/.cargo \ 55 | $out_dir \ 56 | $RS_BIN -i $INPUT_NOTEBOOK -o tests/out-vv.nb 57 | } 58 | 59 | TESTS+=("valid_notebook_vvv") 60 | valid_notebook_vvv() { 61 | local out_dir="target/kcov-${FUNCNAME[0]}" 62 | mkdir -p $out_dir 63 | $KCOV_BIN \ 64 | --verify \ 65 | --exclude-pattern=/.cargo \ 66 | $out_dir \ 67 | $RS_BIN -i $INPUT_NOTEBOOK -o tests/out-vvv.nb 68 | } 69 | 70 | TESTS+=("invalid_argument") 71 | invalid_argument() { 72 | local out_dir="target/kcov-${FUNCNAME[0]}" 73 | mkdir -p $out_dir 74 | $KCOV_BIN \ 75 | --verify \ 76 | --exclude-pattern=/.cargo \ 77 | $out_dir \ 78 | $RS_BIN --foobar \ 79 | || true 80 | } 81 | 82 | TESTS+=("inexistent_notebook") 83 | inexistent_notebook() { 84 | local out_dir="target/kcov-${FUNCNAME[0]}" 85 | mkdir -p $out_dir 86 | $KCOV_BIN \ 87 | --verify \ 88 | --exclude-pattern=/.cargo \ 89 | $out_dir \ 90 | $RS_BIN -i tests/not-a-notebook.nb -o tests/out-inexistent.nb \ 91 | || true 92 | } 93 | 94 | TESTS+=("not_notebook") 95 | not_notebook() { 96 | local out_dir="target/kcov-${FUNCNAME[0]}" 97 | mkdir -p $out_dir 98 | $KCOV_BIN \ 99 | --verify \ 100 | --exclude-pattern=/.cargo \ 101 | $out_dir \ 102 | $RS_BIN -i Cargo.toml -o tests/out-not.nb \ 103 | || true 104 | } 105 | 106 | main() { 107 | for t in ${TESTS[@]} ; do 108 | $t 109 | done 110 | 111 | if [[ -d target/kcov ]]; then 112 | mv target/kcov target/kcov-cargo 113 | $KCOV_BIN --coveralls-id $TRAVIS_JOB_ID --merge target/kcov target/kcov-cargo ${TESTS[@]/#/target/kcov-} 114 | rm -rf target/kcov-cargo 115 | else 116 | $KCOV_BIN --coveralls-id $TRAVIS_JOB_ID --merge target/kcov ${TESTS[@]/#/target/kcov-} 117 | fi 118 | 119 | rm -rf ${TESTS[@]/#/target/kcov-} 120 | } 121 | 122 | main 123 | -------------------------------------------------------------------------------- /tests/notebooks.rs: -------------------------------------------------------------------------------- 1 | use std::{env, fs, path, process}; 2 | 3 | const INPUT_NOTEBOOK: &str = "tests/notebook.nb"; 4 | 5 | /// Get name of the binary 6 | fn bin() -> path::PathBuf { 7 | let root = env::current_exe() 8 | .unwrap() 9 | .parent() 10 | .expect("executable's directory") 11 | .parent() 12 | .expect("executable's directory") 13 | .to_path_buf(); 14 | if cfg!(target_os = "windows") { 15 | root.join("mathematica-notebook-filter.exe") 16 | } else { 17 | root.join("mathematica-notebook-filter") 18 | } 19 | } 20 | 21 | /// Check that the minimized file is smaller than the original file. 22 | fn check_is_minimized>(min_file: P) { 23 | let orig_size = fs::metadata(INPUT_NOTEBOOK) 24 | .expect("Input file metadata.") 25 | .len(); 26 | let min_size = fs::metadata(min_file).expect("Output file metadata.").len(); 27 | 28 | assert!( 29 | min_size < orig_size, 30 | "Minimized file is not smaller (original: {}, minimzed: {}).", 31 | orig_size, 32 | min_size 33 | ); 34 | } 35 | 36 | #[test] 37 | fn valid_notebook() { 38 | let mut cmd = process::Command::new(bin()); 39 | cmd.arg("-i"); 40 | cmd.arg(INPUT_NOTEBOOK); 41 | cmd.arg("-o"); 42 | cmd.arg("tests/out-notebook.nb"); 43 | 44 | match cmd.status() { 45 | Err(e) => { 46 | println!("Error: {}.", e); 47 | panic!(); 48 | } 49 | Ok(status) => { 50 | println!("Exited with code {:?}.", status.code()); 51 | assert!(status.success()); 52 | } 53 | } 54 | 55 | check_is_minimized("tests/out-notebook.nb"); 56 | } 57 | 58 | #[test] 59 | fn valid_pipe() { 60 | let in_file = fs::File::open(INPUT_NOTEBOOK).expect("input notebook file"); 61 | let out_file = fs::File::create("tests/out-pipe.nb").expect("output notebook file"); 62 | 63 | let mut cmd = process::Command::new(bin()); 64 | cmd.stdin(in_file); 65 | cmd.stdout(out_file); 66 | 67 | match cmd.status() { 68 | Err(e) => { 69 | println!("Error: {}.", e); 70 | panic!(); 71 | } 72 | Ok(status) => { 73 | println!("Exited with code {:?}.", status.code()); 74 | assert!(status.success()); 75 | } 76 | } 77 | 78 | check_is_minimized("tests/out-pipe.nb"); 79 | } 80 | 81 | #[test] 82 | fn valid_notebook_v() { 83 | let mut cmd = process::Command::new(bin()); 84 | cmd.arg("-i"); 85 | cmd.arg(INPUT_NOTEBOOK); 86 | cmd.arg("-o"); 87 | cmd.arg("tests/out-v.nb"); 88 | cmd.arg("-v"); 89 | 90 | match cmd.status() { 91 | Err(e) => { 92 | println!("Error: {}.", e); 93 | panic!(); 94 | } 95 | Ok(status) => { 96 | println!("Exited with code {:?}.", status.code()); 97 | assert!(status.success()); 98 | } 99 | } 100 | 101 | check_is_minimized("tests/out-v.nb"); 102 | } 103 | 104 | #[test] 105 | fn valid_notebook_vv() { 106 | let mut cmd = process::Command::new(bin()); 107 | cmd.arg("-i"); 108 | cmd.arg(INPUT_NOTEBOOK); 109 | cmd.arg("-o"); 110 | cmd.arg("tests/out-vv.nb"); 111 | cmd.arg("-vv"); 112 | 113 | match cmd.status() { 114 | Err(e) => { 115 | println!("Error: {}.", e); 116 | panic!(); 117 | } 118 | Ok(status) => { 119 | println!("Exited with code {:?}.", status.code()); 120 | assert!(status.success()); 121 | } 122 | } 123 | 124 | check_is_minimized("tests/out-vv.nb"); 125 | } 126 | 127 | #[test] 128 | fn valid_notebook_vvv() { 129 | let mut cmd = process::Command::new(bin()); 130 | cmd.arg("-i"); 131 | cmd.arg(INPUT_NOTEBOOK); 132 | cmd.arg("-o"); 133 | cmd.arg("tests/out-vvv.nb"); 134 | cmd.arg("-vvv"); 135 | 136 | match cmd.status() { 137 | Err(e) => { 138 | println!("Error: {}.", e); 139 | panic!(); 140 | } 141 | Ok(status) => { 142 | println!("Exited with code {:?}.", status.code()); 143 | assert!(status.success()); 144 | } 145 | } 146 | 147 | check_is_minimized("tests/out-vvv.nb"); 148 | } 149 | 150 | #[test] 151 | fn invalid_argument() { 152 | let mut cmd = process::Command::new(bin()); 153 | cmd.arg("--foobar"); 154 | 155 | match cmd.status() { 156 | Err(e) => { 157 | println!("Error: {}.", e); 158 | panic!(); 159 | } 160 | Ok(status) => { 161 | println!("Exited with code {:?}.", status.code()); 162 | assert!(!status.success()); 163 | } 164 | } 165 | } 166 | 167 | #[test] 168 | fn inexistent_notebook() { 169 | let mut cmd = process::Command::new(bin()); 170 | cmd.arg("-i"); 171 | cmd.arg("tests/not-a-notebook.nb"); 172 | cmd.arg("-o"); 173 | cmd.arg("tests/out-inexistent.nb"); 174 | 175 | match cmd.status() { 176 | Err(e) => { 177 | println!("Error: {}.", e); 178 | panic!(); 179 | } 180 | Ok(status) => { 181 | println!("Exited with code {:?}.", status.code()); 182 | assert!(!status.success()); 183 | } 184 | } 185 | } 186 | 187 | #[test] 188 | fn not_notebook() { 189 | let mut cmd = process::Command::new(bin()); 190 | cmd.arg("-i"); 191 | cmd.arg("Cargo.toml"); 192 | cmd.arg("-o"); 193 | cmd.arg("tests/out-not.nb"); 194 | 195 | match cmd.status() { 196 | Err(e) => { 197 | println!("Error: {}.", e); 198 | panic!(); 199 | } 200 | Ok(status) => { 201 | println!("Exited with code {:?}.", status.code()); 202 | assert!(!status.success()); 203 | } 204 | } 205 | } 206 | --------------------------------------------------------------------------------