-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ce2b512
Showing
51 changed files
with
1,358 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
yarn.lock -diff linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: npm publish | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- run: yarn && yarn test && yarn compile | ||
|
||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Upload Assets | ||
|
||
on: | ||
pull_request: {} | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
upload-assets: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v1 | ||
|
||
- name: Get yarn cache | ||
id: yarn-cache | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.yarn-cache.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- run: yarn && yarn test | ||
name: Tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
node_modules/ | ||
typings/ | ||
.idea/ | ||
.vscode/ | ||
dist/ | ||
webpack/dll/* | ||
.awcache/ | ||
|
||
.DS_Store | ||
*.swp | ||
*.log | ||
|
||
.cache-loader/* | ||
lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.cache-loader | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.prettierrc | ||
dist | ||
example | ||
template.ejs | ||
tsconfig.json | ||
webpack | ||
yarn.lock | ||
tests/ | ||
src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"printWidth": 120, | ||
"trailingComma": "es5", | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Cirru Writer in TypeScript | ||
|
||
### Usages | ||
|
||
_TODO_ | ||
|
||
### License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@cirru/writer.ts", | ||
"version": "0.1.0-a1", | ||
"description": "Cirru Writer in TS", | ||
"main": "lib/writer.js", | ||
"author": "Cirru", | ||
"license": "MIT", | ||
"scripts": { | ||
"compile": "tsc --outDir lib/", | ||
"test": "ts-node tests/test-writer.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.30", | ||
"prettier": "^2.2.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CirruWriterNode, CirruWriterNodeKind } from "./types"; | ||
|
||
export function toWriterList(xs: any): CirruWriterNode { | ||
if (typeof xs === "string") { | ||
return { | ||
kind: CirruWriterNodeKind.writerItem, | ||
item: xs, | ||
}; | ||
} else if (Array.isArray(xs)) { | ||
return { | ||
kind: CirruWriterNodeKind.writerList, | ||
list: xs.map(toWriterList), | ||
}; | ||
} else { | ||
throw new Error("unexpected type to gen list"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function isADigit(c: string): boolean { | ||
let n = c.charCodeAt(0); | ||
// ascii table https://tool.oschina.net/commons?type=4 | ||
return n >= 48 && n <= 57; | ||
} | ||
|
||
export function isALetter(c: string): boolean { | ||
let n = c.charCodeAt(0); | ||
if (n >= 65 && n <= 90) { | ||
return true; | ||
} | ||
if (n >= 97 && n <= 122) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export enum CirruWriterNodeKind { | ||
writerItem, | ||
writerList, | ||
} | ||
|
||
export type CirruWriterNode = | ||
| { | ||
kind: CirruWriterNodeKind.writerItem; | ||
item: string; | ||
} | ||
| { | ||
kind: CirruWriterNodeKind.writerList; | ||
list: Array<CirruWriterNode>; | ||
}; | ||
|
||
export enum WriterNodeKind { | ||
writerKindNil = "nil", | ||
writerKindLeaf = "leaf", | ||
writerKindSimpleExpr = "simple", | ||
writerKindBoxedExpr = "boxed", | ||
writerKindExpr = "expr", | ||
} | ||
|
||
export function toString(xs: CirruWriterNode): string { | ||
let result = ""; | ||
if (xs.kind == CirruWriterNodeKind.writerItem) { | ||
return xs.item; | ||
} else { | ||
for (let idx = 0; idx < xs.list.length; idx++) { | ||
let item = xs.list[idx]; | ||
if (idx > 0) { | ||
result = result + " "; | ||
} | ||
if (item.kind == CirruWriterNodeKind.writerItem) { | ||
result = result + item.item; | ||
} else { | ||
result = result + "(" + toString(item) + ")"; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
export function isSimpleExpr(xs: CirruWriterNode): boolean { | ||
if (xs.kind == CirruWriterNodeKind.writerList) { | ||
for (let x of xs.list) { | ||
if (x.kind != CirruWriterNodeKind.writerItem) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.