From 0f54a000f6a5f9a0e64e9236cf8bf9780cf7e01d Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 09:08:18 -0700 Subject: [PATCH 01/17] Add shell.nix for Nix(OS) users --- shell.nix | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..c1af262 --- /dev/null +++ b/shell.nix @@ -0,0 +1,4 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + buildInputs = with pkgs; [ go ]; +} From 6a5d20b3acd5ae531ba153832dbc5011116380ad Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 10:08:13 -0700 Subject: [PATCH 02/17] Add GitHub action --- .github/workflows/tangle.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/tangle.yml diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml new file mode 100644 index 0000000..d75b584 --- /dev/null +++ b/.github/workflows/tangle.yml @@ -0,0 +1,43 @@ +name: LMT Tangle + +on: + push: + branches: + - master + paths: + - '**.md' + - '!README.md' + +jobs: + tangle: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Go setup + uses: actions/setup-go@v2 + with: + go-version: '^1.16' + + - name: Build bootstrapping file + run: | + go build main.go + mv main lmt + + - name: Tangle main using the bootstrapping file + run: ./lmt Implementation.md WhitespacePreservation.md SubdirectoryFiles.md LineNumbers.md IndentedBlocks.md + + - name: Commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "github-actions[bot]" + git add main.go + git commit -m 'retangle main[bot]' + + - name: Push new main.go + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} From 034288acc0bdce13993a0f20a8312988b5846adf Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 10:11:45 -0700 Subject: [PATCH 03/17] Test md modify --- Implementation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Implementation.md b/Implementation.md index 6831ac4..0797239 100644 --- a/Implementation.md +++ b/Implementation.md @@ -1,7 +1,7 @@ # lmt - literate markdown tangle This file implements a tangle program for a literate programming style -where the code is weaved into markdown code blocks. There is no corresponding +where the code is tangled from markdown code blocks. There is no corresponding weave, because the markdown itself can already be read as the documentation, either through a text editor or through an online system that already renders markdown such as GitHub. From a9114bdb1cc8753bf8c57f29f21b42b7d7303c09 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 14 Mar 2021 17:12:22 +0000 Subject: [PATCH 04/17] retangle main[bot] --- main.go | 121 ++++++++++++++++++++++++++------------------------------ 1 file changed, 55 insertions(+), 66 deletions(-) diff --git a/main.go b/main.go index 8594ed2..e28827e 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,20 @@ -//line README.md:65 +//line Implementation.md:60 package main import ( -//line README.md:149 +//line Implementation.md:157 "fmt" - "io" "os" -//line README.md:212 + "io" +//line Implementation.md:223 "bufio" -//line README.md:385 +//line Implementation.md:406 "regexp" -//line README.md:510 +//line Implementation.md:542 "strings" //line SubdirectoryFiles.md:35 "path/filepath" -//line README.md:69 +//line Implementation.md:64 ) //line LineNumbers.md:25 @@ -22,7 +22,6 @@ type File string type CodeBlock []CodeLine type BlockName string type language string - //line LineNumbers.md:36 type CodeLine struct { text string @@ -30,25 +29,19 @@ type CodeLine struct { lang language number int } - //line LineNumbers.md:30 var blocks map[BlockName]CodeBlock var files map[File]CodeBlock - -//line README.md:402 +//line Implementation.md:424 var namedBlockRe *regexp.Regexp - -//line README.md:432 +//line Implementation.md:458 var fileBlockRe *regexp.Regexp - -//line README.md:516 +//line Implementation.md:549 var replaceRe *regexp.Regexp - -//line IndentedBlocks.md:69 +//line IndentedBlocks.md:68 var blockStartRe *regexp.Regexp - -//line README.md:72 +//line Implementation.md:67 //line LineNumbers.md:118 // Updates the blocks and files map for the markdown read from r. @@ -64,7 +57,7 @@ func ProcessFile(r io.Reader, inputfilename string) error { var bname BlockName var fname File var block CodeBlock -//line IndentedBlocks.md:92 +//line IndentedBlocks.md:91 var blockPrefix string //line LineNumbers.md:99 for { @@ -78,53 +71,52 @@ func ProcessFile(r io.Reader, inputfilename string) error { default: return err } -//line IndentedBlocks.md:119 +//line IndentedBlocks.md:118 if inBlock { - line.text = strings.TrimPrefix(line.text, blockPrefix) - if line.text == "```\n" { + line.text = strings.TrimPrefix(line.text, blockPrefix) + if line.text == "```\n" { //line LineNumbers.md:56 - inBlock = false - // Update the files map if it's a file. - if fname != "" { - if appending { - files[fname] = append(files[fname], block...) - } else { - files[fname] = block - } - } - - // Update the named block map if it's a named block. - if bname != "" { - if appending { - blocks[bname] = append(blocks[bname], block...) - } else { - blocks[bname] = block - } - } -//line IndentedBlocks.md:123 - continue - } + inBlock = false + // Update the files map if it's a file. + if fname != "" { + if appending { + files[fname] = append(files[fname], block...) + } else { + files[fname] = block + } + } + + // Update the named block map if it's a named block. + if bname != "" { + if appending { + blocks[bname] = append(blocks[bname], block...) + } else { + blocks[bname] = block + } + } +//line IndentedBlocks.md:122 + continue + } //line LineNumbers.md:48 - block = append(block, line) -//line IndentedBlocks.md:126 - continue + block = append(block, line) +//line IndentedBlocks.md:125 + continue } -//line IndentedBlocks.md:56 +//line IndentedBlocks.md:55 if matches := blockStartRe.FindStringSubmatch(line.text); matches != nil { - inBlock = true - blockPrefix = matches[1] - line.text = strings.TrimPrefix(line.text, blockPrefix) - // We were outside of a block, so just blindly reset it. - block = make(CodeBlock, 0) + inBlock = true + blockPrefix = matches[1] + line.text = strings.TrimPrefix(line.text, blockPrefix) + // We were outside of a block, so just blindly reset it. + block = make(CodeBlock, 0) //line LineNumbers.md:181 - fname, bname, appending, line.lang = parseHeader(line.text) -//line IndentedBlocks.md:63 + fname, bname, appending, line.lang = parseHeader(line.text) +//line IndentedBlocks.md:62 } //line LineNumbers.md:111 } //line LineNumbers.md:121 } - //line LineNumbers.md:190 func parseHeader(line string) (File, BlockName, bool, language) { line = strings.TrimSpace(line) @@ -139,7 +131,6 @@ func parseHeader(line string) (File, BlockName, bool, language) { return "", "", false, "" //line LineNumbers.md:193 } - //line WhitespacePreservation.md:34 // Replace expands all macros in a CodeBlock and returns a CodeBlock with no // references to macros. @@ -170,7 +161,6 @@ func (c CodeBlock) Replace(prefix string) (ret CodeBlock) { return //line WhitespacePreservation.md:38 } - //line LineNumbers.md:277 // Finalize extract the textual lines from CodeBlocks and (if needed) prepend a @@ -188,7 +178,7 @@ func (c CodeBlock) Finalize() (ret string) { formatstring = "//line %[2]v:%[1]v\n" case "C", "c", "cpp": formatstring = "#line %v \"%v\"\n" - default: + default: ret += l.text continue } @@ -200,11 +190,10 @@ func (c CodeBlock) Finalize() (ret string) { } return } - -//line README.md:74 +//line Implementation.md:69 func main() { -//line README.md:157 +//line Implementation.md:166 // Initialize the maps blocks = make(map[BlockName]CodeBlock) files = make(map[File]CodeBlock) @@ -214,9 +203,9 @@ func main() { fileBlockRe = regexp.MustCompile("^`{3,}\\s?([\\w\\+]+)\\s+([\\w\\.\\-\\/]+)\\s*([+][=])?$") //line WhitespacePreservation.md:11 replaceRe = regexp.MustCompile(`^([\s]*)<<<(.+)>>>[\s]*$`) -//line IndentedBlocks.md:83 +//line IndentedBlocks.md:82 blockStartRe = regexp.MustCompile("^([\\s]*)```") -//line README.md:136 +//line Implementation.md:144 // os.Args[0] is the command name, "lmt". We don't want to process it. for _, file := range os.Args[1:] { @@ -233,7 +222,7 @@ func main() { // Don't defer since we're in a loop, we don't want to wait until the function // exits. f.Close() -//line README.md:140 +//line Implementation.md:148 } //line LineNumbers.md:311 @@ -253,5 +242,5 @@ func main() { // We don't defer this so that it'll get closed before the loop finishes. f.Close() } -//line README.md:77 +//line Implementation.md:72 } From 3547a9688d6a860cbcdabe3aa839bbe6d4192d28 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 10:18:01 -0700 Subject: [PATCH 05/17] Update tangle.yml to only listen for relevant files --- .github/workflows/tangle.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index d75b584..f56c73b 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -5,8 +5,11 @@ on: branches: - master paths: - - '**.md' - - '!README.md' + - 'Implementation.md' + - 'WhitespacePreservation.md' + - 'SubdirectoryFiles.md' + - 'LineNumbers.md' + - 'IndentedBlocks.md' jobs: tangle: From 22e63846b5bb38aae119a663e6209ed7550bd844 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 12:21:22 -0700 Subject: [PATCH 06/17] Significant refactor as per comments, also finally found context and expression docs --- .github/workflows/tangle.yml | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index f56c73b..766179b 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -1,15 +1,14 @@ name: LMT Tangle +env: + FILES: [ Implementation.md, WhitespacePreservation.md, SubdirectoryFiles.md, LineNumbers.md, IndentedBlocks.md ] + GOVER: '^1.16' + on: push: branches: - master - paths: - - 'Implementation.md' - - 'WhitespacePreservation.md' - - 'SubdirectoryFiles.md' - - 'LineNumbers.md' - - 'IndentedBlocks.md' + paths: ${{ env.FILES }} jobs: tangle: @@ -22,25 +21,19 @@ jobs: - name: Go setup uses: actions/setup-go@v2 with: - go-version: '^1.16' + go-version: env.GOVER - - name: Build bootstrapping file + - name: Build lmt run: | go build main.go mv main lmt - - name: Tangle main using the bootstrapping file - run: ./lmt Implementation.md WhitespacePreservation.md SubdirectoryFiles.md LineNumbers.md IndentedBlocks.md - - - name: Commit files + - name: Make sure main.go has not changed unintentionally + env: + FILES: ${{ join( env.FILES, ' ' ) }} run: | - git config --local user.email "action@github.com" - git config --local user.name "github-actions[bot]" - git add main.go - git commit -m 'retangle main[bot]' - - - name: Push new main.go - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} + mv main.go main.go.orig + ./lmt ${{ }} + cmp -s main.go main.go.orig + + From 72acdb6878af363b47488454cfe04be681d47ac3 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 12:31:08 -0700 Subject: [PATCH 07/17] Add markdown version of shell.nix --- Nix-Shell.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Nix-Shell.md diff --git a/Nix-Shell.md b/Nix-Shell.md new file mode 100644 index 0000000..38e9579 --- /dev/null +++ b/Nix-Shell.md @@ -0,0 +1,20 @@ +# Nix Shell +Nix development shells can be used to get development environments which can be accessed using the `nix-shell` command. + +Firstly, we must define a function. Nix expressions are written in a functional language (also called Nix) and use the function as their basic unit. This one takes a parameter called `pkgs` with a default value of the primary Nix package collection. +```nix "Function definition" +{ pkgs ? import {} }: +``` + +Now, we can create a shell using the `pkgs.mkShell` function. This function creates the shell that will be accessed and defines properties of it. In our case, we use the `buildInputs` parameter to include our build dependencies (ie. Golang) in this shell. +```nix "Create shell" +pkgs.mkShell { + buildInputs = with pkgs; [ go ]; +} +``` + + From 3648f05bb4f672e837263d4ccc9aeb71641083a2 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 12:33:50 -0700 Subject: [PATCH 08/17] Make note in README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 23b967f..e4bddf4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ directory. You can use the `-o $path` argument to `go build` to build the binary in a different location. (i.e. `go build -o ~/bin/` to put the binary in `~/bin/`.) +#### A note for Nix(OS) users +This repo also comes with a `shell.nix` file. While an existing version is included, like lmt itself, this is mainly for bootstrapping purposes. To compile it, use `lmt Nix-Shell.md` + ## Demo To observe `lmt` at work, put this file in an empty directory, cd to that From a2e9a9e1fa12ae3136d7685f504113694bd28f15 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 12:42:38 -0700 Subject: [PATCH 09/17] Add a bit more to the Nix shell markdown --- Nix-Shell.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Nix-Shell.md b/Nix-Shell.md index 38e9579..987c8ed 100644 --- a/Nix-Shell.md +++ b/Nix-Shell.md @@ -18,3 +18,6 @@ pkgs.mkShell { <<>> <<>> --> + +# About Nix +Nix is a package manager designed to allow for completely reproducible builds. It allows for developers to ensure that software builds the same on 1 computer as it does on any other. For more information, see From b86ffa6776ab302b71acaa985f3e200af335a715 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 12:51:10 -0700 Subject: [PATCH 10/17] Small formatting fixes --- Nix-Shell.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Nix-Shell.md b/Nix-Shell.md index 987c8ed..5963d02 100644 --- a/Nix-Shell.md +++ b/Nix-Shell.md @@ -2,22 +2,16 @@ Nix development shells can be used to get development environments which can be accessed using the `nix-shell` command. Firstly, we must define a function. Nix expressions are written in a functional language (also called Nix) and use the function as their basic unit. This one takes a parameter called `pkgs` with a default value of the primary Nix package collection. -```nix "Function definition" +```nix shell.nix+= { pkgs ? import {} }: ``` Now, we can create a shell using the `pkgs.mkShell` function. This function creates the shell that will be accessed and defines properties of it. In our case, we use the `buildInputs` parameter to include our build dependencies (ie. Golang) in this shell. -```nix "Create shell" +```nix shell.nix+= pkgs.mkShell { buildInputs = with pkgs; [ go ]; } ``` - - # About Nix -Nix is a package manager designed to allow for completely reproducible builds. It allows for developers to ensure that software builds the same on 1 computer as it does on any other. For more information, see +Nix is a package manager designed to allow for completely reproducible builds. It allows for developers to ensure that software builds the same on 1 computer as it does on any other. For more information, see . From 3c9ed25fae7b9e0050f5f0d5a729e6f4a58a2e35 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 13:04:42 -0700 Subject: [PATCH 11/17] Fix stupid mistakes --- .github/workflows/tangle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index 766179b..daca15d 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -21,7 +21,7 @@ jobs: - name: Go setup uses: actions/setup-go@v2 with: - go-version: env.GOVER + go-version: ${{ env.GOVER }} - name: Build lmt run: | @@ -33,7 +33,7 @@ jobs: FILES: ${{ join( env.FILES, ' ' ) }} run: | mv main.go main.go.orig - ./lmt ${{ }} + ./lmt $FILES cmp -s main.go main.go.orig From 58d477bf4ebb0ab3bc37ed4e81a10b493a1f9576 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 13:06:46 -0700 Subject: [PATCH 12/17] Test commit --- SubdirectoryFiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubdirectoryFiles.md b/SubdirectoryFiles.md index 4192e6e..f02d5f2 100644 --- a/SubdirectoryFiles.md +++ b/SubdirectoryFiles.md @@ -9,7 +9,7 @@ a little help from the Go standard library `path/filepath` functions. We'll get the directory of the string, and if it's not "." (filepath.Dir returns ".", not "" for empty paths) call `os.MkdirAll` on it in order to create -the directory before creating the file. +the directory before creating the file ```go "Output files" for filename, codeblock := range files { From d2f43fb94d4f2b65853d7850a98d11f7b649d189 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 13:17:54 -0700 Subject: [PATCH 13/17] Run script on any update, probably for the best --- .github/workflows/tangle.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index daca15d..fda89fa 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -1,15 +1,10 @@ name: LMT Tangle +on: push env: FILES: [ Implementation.md, WhitespacePreservation.md, SubdirectoryFiles.md, LineNumbers.md, IndentedBlocks.md ] GOVER: '^1.16' -on: - push: - branches: - - master - paths: ${{ env.FILES }} - jobs: tangle: runs-on: ubuntu-latest From 3df24be37e126349c454addbc4b8a4eb2c02169b Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 13:19:45 -0700 Subject: [PATCH 14/17] Run script on any update, probably for the best --- .github/workflows/tangle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index fda89fa..d40e523 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -2,7 +2,7 @@ name: LMT Tangle on: push env: - FILES: [ Implementation.md, WhitespacePreservation.md, SubdirectoryFiles.md, LineNumbers.md, IndentedBlocks.md ] + FILES: ${{ join([ Implementation.md, WhitespacePreservation.md, SubdirectoryFiles.md, LineNumbers.md, IndentedBlocks.md ], ' ') }} GOVER: '^1.16' jobs: From 20cb3180283147727eb3d9179e6968ec8affe453 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Sun, 14 Mar 2021 13:20:29 -0700 Subject: [PATCH 15/17] Run script on any update, probably for the best --- .github/workflows/tangle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tangle.yml b/.github/workflows/tangle.yml index d40e523..6ae3118 100644 --- a/.github/workflows/tangle.yml +++ b/.github/workflows/tangle.yml @@ -2,7 +2,7 @@ name: LMT Tangle on: push env: - FILES: ${{ join([ Implementation.md, WhitespacePreservation.md, SubdirectoryFiles.md, LineNumbers.md, IndentedBlocks.md ], ' ') }} + FILES: 'Implementation.md WhitespacePreservation.md SubdirectoryFiles.md LineNumbers.md IndentedBlocks.md' GOVER: '^1.16' jobs: From 3f0c53db0923c4a2c6681a796789eeab477d4da4 Mon Sep 17 00:00:00 2001 From: Enderger Date: Mon, 29 Mar 2021 07:53:52 -0700 Subject: [PATCH 16/17] Improve Nix-Shell.md --- Nix-Shell.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Nix-Shell.md b/Nix-Shell.md index 5963d02..4096c22 100644 --- a/Nix-Shell.md +++ b/Nix-Shell.md @@ -1,3 +1,6 @@ +# About Nix +Nix is a package manager designed to allow for completely reproducible builds. It allows for developers to have reproducible build environments in order to ensure consistency. For more information, see . + # Nix Shell Nix development shells can be used to get development environments which can be accessed using the `nix-shell` command. @@ -13,5 +16,3 @@ pkgs.mkShell { } ``` -# About Nix -Nix is a package manager designed to allow for completely reproducible builds. It allows for developers to ensure that software builds the same on 1 computer as it does on any other. For more information, see . From fe7853c629f789c2d321ebb30738d5d4a8a2a3d2 Mon Sep 17 00:00:00 2001 From: Daniel Hutzley Date: Tue, 13 Apr 2021 13:26:45 -0700 Subject: [PATCH 17/17] Revert change made during testing --- SubdirectoryFiles.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SubdirectoryFiles.md b/SubdirectoryFiles.md index f02d5f2..4192e6e 100644 --- a/SubdirectoryFiles.md +++ b/SubdirectoryFiles.md @@ -9,7 +9,7 @@ a little help from the Go standard library `path/filepath` functions. We'll get the directory of the string, and if it's not "." (filepath.Dir returns ".", not "" for empty paths) call `os.MkdirAll` on it in order to create -the directory before creating the file +the directory before creating the file. ```go "Output files" for filename, codeblock := range files {