Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
liulinboyi committed Jan 11, 2021
1 parent 7d20eb7 commit 33129eb
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules/
/src/*.js.map
/dist/*.js.map
/examples/*/*.js.map
/.cache/
3 changes: 3 additions & 0 deletions examples/pineapple/hello-world.pineapple
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

$a = "你好,我是pineapple-ts"
print($a)
19 changes: 19 additions & 0 deletions examples/pineapple/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions examples/pineapple/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Execute } from '../../src/backend'
import fs from "fs";
const args = process.argv.slice(2)
if (args[0]) {
let code = ''

try {
code = fs.readFileSync(args[0], { encoding: 'utf-8' })
} catch (error) {
console.log(`Error reading file: ${args[0]}`)
}

if (code.length > 0) {
Execute(code)
}
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"devDependencies": {
"@types/node": "^14.14.20",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"scripts": {
"test": "ts-node ./src/backend.ts"
"test": "ts-node ./examples/pineapple/main.ts ./examples/pineapple/hello-world.pineapple"
}
}
}
8 changes: 5 additions & 3 deletions src/backend.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function NewGlobalVariables() {
}


function Execute(code: string) {
export function Execute(code: string) {
var ast = {}

let g = NewGlobalVariables()
Expand Down Expand Up @@ -77,6 +77,6 @@ function resolvePrint(g: any, print: any) {


// test
Execute(`$a = "你好,我是pineapple11"
print($a)
`)
// Execute(`$a = "你好,我是pineapple11"
// print($a)
// `)

0 comments on commit 33129eb

Please sign in to comment.