Skip to content

Commit

Permalink
Added loxfmt. Added eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berezin committed Jun 7, 2019
1 parent 27c20da commit f2459a6
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 251 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/*
**/*.test.js
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "commonjs"
},
"rules": {
"no-console": 0
}
};
21 changes: 15 additions & 6 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const examplePrograms = exampleProgramSource.map(program => {

const handleError = (e, source = '') => {
if (!e) {
document.getElementById('error').style.display = 'none'
document.getElementById('error').style.maxHeight = '0'
return null
}
console.error(e)
Expand All @@ -37,7 +37,7 @@ const handleError = (e, source = '') => {
errorStr += '<br />'
errorStr += `${preErrorSection}<span class="error">${errorSection}</span>${postErrorSection}`
}
document.getElementById('error').style.display = ''
document.getElementById('error').style.maxHeight = '150px'
document.getElementById('errorText').innerHTML = errorStr
}

Expand All @@ -51,9 +51,13 @@ exampleProgram.onchange = e => {
const selectedProgram = e.target.value
code.value = examplePrograms[selectedProgram].program
}

// Pick default program to load
let defaultProgram = 0
if (window.location.hash) {
defaultProgram = +window.location.hash.replace(/[^\w\s]/gi, '').trim()
let hashValue = +window.location.hash.replace(/[^\w\s]/gi, '').trim()
if (hashValue < exampleProgram.length) defaultProgram = hashValue
exampleProgram.value = defaultProgram
}
code.value = examplePrograms[defaultProgram].program

Expand Down Expand Up @@ -89,7 +93,12 @@ button.onclick = () => {

const formatButton = document.getElementById('format')
formatButton.onclick = () => {
code.value = parse(code.value)
.map(stmt => printLoxAST(stmt))
.join('\n')
try {
code.value = parse(code.value)
.map(stmt => printLoxAST(stmt))
.join('\n')
handleError(null)
} catch (e) {
handleError(e, code.value)
}
}
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const main = argv => {
const args = processOptions(argv.slice(2))
if (options.debug) console.log(options)
if (args.length > 1) {
console.error('Usage: jlox [script]')
console.error('Usage: yali [script]')
return 64
} else if (args.length === 1) {
runFile(args[0])
Expand Down
41 changes: 0 additions & 41 deletions docs/browser.4a180639.js

This file was deleted.

21 changes: 0 additions & 21 deletions docs/browser.5d1cf53e.js

This file was deleted.

41 changes: 0 additions & 41 deletions docs/browser.5da0a6dc.js

This file was deleted.

41 changes: 0 additions & 41 deletions docs/browser.993001ea.js

This file was deleted.

41 changes: 0 additions & 41 deletions docs/browser.b0516530.js

This file was deleted.

43 changes: 0 additions & 43 deletions docs/browser.da209bc9.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/browser.3e1d6a44.js → docs/browser.e9f8be96.js

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

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>YALI.js</title><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css"><style>textarea{height:250px}.code-area{display:flex;flex-wrap:wrap-reverse}pre#error{margin-top:-12px}.error{color:#d24b46;background-color:#ffeff0}.col{width:100%}@media (min-width:600px){.code-area{flex-wrap:nowrap}.col:first-child{margin-right:1em}}</style></head><body> <h2> YALI.js: Yet Another Lox Interpreter. Javascript Implementation </h2> <div> <label for="exampleProgram">Example Program:</label> <select name="exampleProgram" id="exampleProgram"></select> </div> <div class="code-area"> <div class="col"> <label for="code">Code: </label> <textarea id="code" cols="50" rows="15"></textarea> </div> <div class="col"> <label for="output">Output: </label> <textarea id="output" cols="50" rows="15" readonly></textarea> <pre id="error" style="display:none"><code id="errorText"></code></pre> </div> </div> <div> <button id="run"> Run </button> <button id="format" class="button-outline"> Format </button> </div> <div> <small> Please open your javascript console with <key>Command + Option + J (Mac) or Control + Shift + J (Windows, Linux, Chrome OS)</key> </small> </div> <script src="browser.3e1d6a44.js"></script>
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>YALI.js</title><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.min.css"><style>textarea{height:250px}.code-area{display:flex;flex-wrap:wrap-reverse}pre#error{margin-top:-12px;transition:max-height 1s}.error{color:#d24b46;background-color:#ffeff0}.col{width:100%}@media (min-width:600px){.code-area{flex-wrap:nowrap}.col:first-child{margin-right:1em}}</style></head><body> <h2> YALI.js: Yet Another Lox Interpreter. Javascript Implementation </h2> <div> <label for="exampleProgram">Example Program:</label> <select name="exampleProgram" id="exampleProgram"></select> </div> <div class="code-area"> <div class="col"> <label for="code">Code: </label> <textarea id="code" cols="50" rows="15"></textarea> <div> <button id="run"> Run </button> <button id="format" class="button-outline"> Format </button> </div> </div> <div class="col"> <label for="output">Output: </label> <textarea id="output" cols="50" rows="15" readonly></textarea> <pre id="error" style="max-height:0"><code id="errorText"></code></pre> </div> </div> <div> <small> Please open your javascript console with <key>Command + Option + J (Mac) or Control + Shift + J (Windows, Linux, Chrome OS)</key> </small> </div> <script src="browser.e9f8be96.js"></script>
</body></html>
Loading

0 comments on commit f2459a6

Please sign in to comment.