Browse files

Initial commit.

  • Loading branch information...
0 parents commit ca152e8ca53a90460cf449f68c99bb91da92951c @arcfide committed Apr 14, 2012
Showing with 70 additions and 0 deletions.
  1. +50 −0 ConTeXtLP.dyalog
  2. +20 −0 test.tex
50 ConTeXtLP.dyalog
@@ -0,0 +1,50 @@
+:Namespace ConTeXtLP
+
+ ⎕IO ⎕ML0 0
+
+ Main;file;chunk
+ file(FileMsg)FileMsg'Enter the name of the file to tangle: '
+ chunk(ChunkMsg)ChunkMsg'Enter the name of the chunk to tangle: '
+ chunk Tangle file
+
+
+ Tangle{
+ chunk '*' in out
+ tiein⎕NTIE 0
+ pat'^\\startChunk{\s*(.*[^\s])\s*}\s*\n'
+ pat,'((?:.|\n)*?)\\endChunk\s*\n'
+ ns cs[0](pat⎕S Extract'Mode' 'M') tie
+ tie⎕NUNTIE tie
+ ns cs(ns[sv]),cs[svns]
+ ns cs(pv/ns),(,/)¨(pv1,2/ns)cs
+ outputns cs Resolve cs[nschunk]
+ 'Tangling complete.'output Write out
+ }
+
+ Extract{
+ 1.Offsets:
+ no co1.Offsets
+ nl cl1.Lengths
+ (.Block[no+nl])(.Block[co+cl])
+ }
+
+ Resolve{
+ ns cs body
+ pat'/BTEX\\chunkRef{\s*(.*)\s*}/ETEX'
+ nbody(pat⎕R (ns csSubst)'ResultText' 'Simple') body
+ nbodybody: body
+ ns cs nbody
+ }
+
+ Subst{
+ ns cs
+ cs[ns.Block[(1.Offsets)+1.Lengths]]
+ }
+
+ Write{
+ 22:: ⎕NCREATE 0
+ _0 ⎕NRESIZE tie ⎕NTIE 0
+ (⎕UCS 'UTF-8'⎕UCS )⎕NREPLACE tie,0,80
+ }
+
+:EndNamespace
20 test.tex
@@ -0,0 +1,20 @@
+\starttext
+
+\startChunk{Main}
+⍝ This is a test
+⎕←'Here are the primes'
+\endChunk
+
+This is something that I am not sure will work, but I intend to find
+out if I can make it work nonetheless.
+
+\startChunk{Primes less than 50}
+(2=+⌿0=(⍳X)∘.|⍳X)/⍳X←50
+\endChunk
+
+\startChunk{Main }
+⎕←/BTEX\chunkRef{Primes less than 50}/ETEX
+I wonder what other things there are.
+\endChunk
+
+\endtext

0 comments on commit ca152e8

Please sign in to comment.