Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Jan 12, 2021
0 parents commit fb09c35
Show file tree
Hide file tree
Showing 11 changed files with 3,045 additions and 0 deletions.
118 changes: 118 additions & 0 deletions .gitignore
@@ -0,0 +1,118 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

/test/integration-tests/*/actual.*
9 changes: 9 additions & 0 deletions bin/lima
@@ -0,0 +1,9 @@
#!/usr/bin/env node
const { exit } = require("process")
let lima = require("../dist/lima")

lima.cli(process.argv.slice(2))
.catch(error => {
process.stderr.write(error.message)
exit(22)
})
28 changes: 28 additions & 0 deletions package.json
@@ -0,0 +1,28 @@
{
"name": "lima",
"version": "1.0.0-alpha.0",
"description": "",
"main": "index.js",
"bin": {
"lima": "bin/lima"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"watch": "tsc -w"
},
"author": "chee <chee@snoot.club>",
"license": "GPL-3.0+",
"devDependencies": {
"@tsconfig/node14": "^1.0.0",
"@tsconfig/recommended": "^1.0.1",
"@types/node": "^14.14.20",
"tap": "^14.11.0",
"typescript": "^4.1.3"
},
"dependencies": {
"make-dir": "^2.1.0",
"mdast-util-from-markdown": "^0.8.4",
"micromark": "^2.11.2"
}
}
57 changes: 57 additions & 0 deletions readme.md
@@ -0,0 +1,57 @@
# lima

lima is the minimal implementation of **li**terate **ma**rkdown.

## tangle

```shell
$ lima tangle file.md
```

the syntax is inspired by org-mode. noweb is currently unsupported, though will be added as a parser extension.

```markdown
# welcome to my file

here is some code:

```c++ filename="main.cc", name="sum"
auto sum (std::vector<int> numbers) {
int result = 0;
for (auto i : numbers) {
result += i;
}
return result;
}
```

```
you see the option is passed in the info string after the file type.
### valid options
| option | type | info |
| -- | -- | -- |
| filename | string | required for the block to be tangled, but optional |
| chmod | octal number or `ls -l`-like string | the mode the file should have |
| chown | string or number | the user name or id the file should have |
| chgrp | string or number | the group name or id the file should have |
| shebang | string | the shebang to put at the top of the file. if `chmod` is unset, this will set the executable bit |
| sudo | bool | if the file should be written as root |
| if | string | an environment variable that must be present for the file to be written
| unless | string | an environment variable that must not be present for the file to be written |
| name | string | a name for this codeblock |
## weave
lima markdown files are valid commonmark, any markdown renderer that support fenced code blocks should be able to be used as weavers.
there is room for a future `lima weave` sub-command allowing more exciting things to happen.
## todo
- add noweb support
- add the ability to execute codeblocks during weave
- add library-of-babel-like functions
82 changes: 82 additions & 0 deletions src/lib/meta-parser.ts
@@ -0,0 +1,82 @@
enum MetaParserState {
begin,
property,
value,
end
}

export default class MetaParser {
state = MetaParserState.begin
result: {[s: string]: any} = {}
source = ""
property = ""
constructor(source: string) {
this.source = source
}
parse() {
while (this.source.length) {
this.next()
}
return this.result
}
next() {
switch (this.state) {
case MetaParserState.begin: {
this.source = this.source.replace(/^\s+/, "")
let f = this.source[0]
if (f == "=" || f == '"' || f == ",") {
// TODO store problem and move alone
throw new Error(`invalid char at 0: ${f}`)
} else {
this.state = MetaParserState.property
}
break;
}
case MetaParserState.property: {
let match = this.source.match(/^[^=]+/)
if (!match) {
throw new Error("i don't know")
}
this.property = match[0]
// remove property and equals sign
this.source = this.source.slice(this.property.length + 1)
this.state = MetaParserState.value
break
}
case MetaParserState.value: {
if (this.source[0] == '"') {
let string = this.source.match(/^"((?:\\"|[^"])*)/)
if (!string) {
throw new Error("couldn't find closing quote")
}
let value = string[1]
this.result[this.property] = value
this.source = this.source.slice(2 + value.length)
} else if (this.source.match(/^false[,\s]/)) {
this.result[this.property] = false
this.source = this.source.slice(5)
} else if (this.source.match(/^true[,\s]/)) {
this.result[this.property] = true
this.source = this.source.slice(4)
} else {
let numbers = this.source.match(/^(\d+)(?:\s|,|$)/)
if (numbers) {
let value = numbers[1]
this.result[this.property] = Number(value)
this.source = this.source.slice(value.length)
} else {
throw new Error(`bad value for ${this.property}`)
}
}
let commaetc = this.source.match(/^,\s*/)
if (commaetc) {
this.state = MetaParserState.property
this.source = this.source.slice(commaetc[0].length)
} else if (this.source.match(/\s*$/)) {
this.state = MetaParserState.end
this.source = ""
}
}
}
}
}

0 comments on commit fb09c35

Please sign in to comment.