meh lexer
@@ -59,36 +59,3 @@ onMouseMove() {
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
whatdoesthisdo() {
|
||||
clear();
|
||||
this.curve.drawSkeleton(curve);
|
||||
this.curve.drawCurve(curve);
|
||||
let w = this.height;
|
||||
let h = this.height;
|
||||
let bbox = this.curve.bbox();
|
||||
let x = this.cursor.x;
|
||||
|
||||
if (bbox.x.min < x && x < bbox.x.max) {
|
||||
setStroke("red");
|
||||
|
||||
// The root finder is based on normal x/y coordinates,
|
||||
// so we can "trick" it by giving it "t" values as x
|
||||
// values, and "x" values as y values. Since it won't
|
||||
// even look at the x dimension, we can also just leave it.
|
||||
let roots = api.utils.roots(curve.points.map(v => {
|
||||
return { x: v.x, y: v.x-x};
|
||||
}));
|
||||
roots = roots.filter(t => t>=0 && t<=1.0);
|
||||
let t = roots[0];
|
||||
|
||||
let p = this.curve.get(t);
|
||||
line({ x: p.x, y: p.y }, { x: p.x, y: h });
|
||||
line({ x: p.x, y: p.y }, { x: 0, y: p.y });
|
||||
text(`y=${p.y|0}`, { x: p.x/2, y: p.y - 5 });
|
||||
text(`x=${p.x|0}`, { x: x + 5, y: h - (h-p.y)/2 });
|
||||
text(`t=${((t*100)|0)/100}`, { x: x + 15, y: p.y });
|
||||
}
|
||||
}
|
||||
*/
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 18 KiB |
BIN
docs/images/chapters/yforx/8485670c070ddd7964871ae418a7da4e.png
Normal file
After Width: | Height: | Size: 19 KiB |
9745
docs/index.html
91
docs/js/custom-element/lib/lexer.js
Normal file
@@ -0,0 +1,91 @@
|
||||
function splitSymbols(v) {
|
||||
if (v.match(/\w/)) return v;
|
||||
return v.split(``);
|
||||
}
|
||||
|
||||
class Lexer {
|
||||
constructor(code) {
|
||||
this.scope = 0;
|
||||
this.pos = 0;
|
||||
this.tokens = code.split(/\b/).map(splitSymbols).flat();
|
||||
this.scopes = [];
|
||||
console.log(this.tokens);
|
||||
}
|
||||
|
||||
parse() {
|
||||
while (this.pos < this.tokens.length) {
|
||||
let token = this.tokens[this.pos++];
|
||||
|
||||
if ([`const`, `let`, "var"].includes(token)) {
|
||||
this.parseVariable(token);
|
||||
}
|
||||
|
||||
// ...
|
||||
else if ([`'`, `"`, "`"].includes(token)) {
|
||||
this.parseString(token);
|
||||
}
|
||||
|
||||
// ...
|
||||
else if (token === `(`) {
|
||||
let functor,
|
||||
i = 2;
|
||||
do {
|
||||
functor = this.tokens[this.pos - i++];
|
||||
} while (functor.match(/\s+/));
|
||||
|
||||
// TODO: maths is fun?
|
||||
|
||||
console.log(`[${this.scope}]: ${functor}(...`);
|
||||
} else if (token === `)`) {
|
||||
}
|
||||
|
||||
// ...
|
||||
else if (token === `{`) {
|
||||
this.scopes[this.pos] = ++this.scope;
|
||||
}
|
||||
|
||||
// ...
|
||||
else if (token === `}`) {
|
||||
this.scopes[this.pos] = --this.scope;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(this.scopes);
|
||||
}
|
||||
|
||||
parseVariable(type) {
|
||||
let name;
|
||||
do {
|
||||
name = this.tokens[this.pos++];
|
||||
} while (name.match(/\s+/));
|
||||
console.log(`[${this.scope}]: ${type} ${name}`);
|
||||
}
|
||||
|
||||
parseString(symbol) {
|
||||
// we technically don't really care about the contents
|
||||
// of strings, as they don't introduce new variables
|
||||
// or functions that we need to care about.
|
||||
let token;
|
||||
let buffer = [symbol];
|
||||
let blen = 1;
|
||||
do {
|
||||
token = this.tokens[this.pos++];
|
||||
buffer.push(token);
|
||||
blen++;
|
||||
} while (
|
||||
token !== symbol &&
|
||||
buffer[blen - 2] !== `\\` &&
|
||||
this.pos < this.tokens.length
|
||||
);
|
||||
// buffer = buffer.join(``);
|
||||
// if (symbol === "`") {
|
||||
// this.parseTemplateString(buffer);
|
||||
// }
|
||||
}
|
||||
|
||||
// parseTemplateString(buffer) {
|
||||
// // console.log(buffer);
|
||||
// }
|
||||
}
|
||||
|
||||
export { Lexer };
|
@@ -1,9 +1,8 @@
|
||||
import { GraphicsAPI } from "../api/graphics-api.js";
|
||||
|
||||
export default function performCodeSurgery(code) {
|
||||
// 0. strip out block comments and whitespace
|
||||
// 0. strip out superfluous whitespace
|
||||
|
||||
code = code.replace(/\\\*[\w\s\r\n]+?\*\\/, ``);
|
||||
code = code.replace(/\r?\n(\r?\n)+/, `\n`);
|
||||
|
||||
// 1. ensure that anything that needs to run by first calling its super function, does so.
|
||||
|
@@ -3,6 +3,10 @@
|
||||
* We're going to regexp our way to flawed victory here.
|
||||
*/
|
||||
export default function splitCodeSections(code) {
|
||||
// removs comments and superfluous white space.
|
||||
code = code.replace(/\\\*[\w\s\r\n]+?\*\\/, ``);
|
||||
code = code.replace(/\r?\n(\r?\n)+/, `\n`);
|
||||
|
||||
const re = /\b[\w\W][^\s]*?\([^)]*\)[\r\n\s]*{/;
|
||||
const cuts = [];
|
||||
for (let result = code.match(re); result; result = code.match(re)) {
|
||||
|
@@ -14,15 +14,15 @@
|
||||
"url": "https://github.com/Pomax/BezierInfo-2/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cls && run-s clean time lint:* build pretty time && rm -f .timing",
|
||||
"start": "run-s clean time lint:* build pretty time && rm -f .timing",
|
||||
"test": "run-s start && run-p watch server browser",
|
||||
"------": "--- note that due to github's naming policy, the public dir is called 'docs' rather than 'public' ---",
|
||||
"browser": "open-cli http://localhost:8000",
|
||||
"build": "node ./src/build.js",
|
||||
"clean": "rm -f .timing && rm -rf ./temp",
|
||||
"lint:tools": "prettier ./src/**/*.js --write",
|
||||
"lint:lib": "prettier ./docs/js/**/*.js --write",
|
||||
"pretty": "echo not running `prettier ./docs/**/index.html --write` as it increases filesize by 30%",
|
||||
"lint:tools": "prettier \"./src/**/*.js\" --write",
|
||||
"lint:lib": "prettier \"./docs/js/**/*.js\" --write",
|
||||
"pretty": "echo not running `prettier \"./docs/**/index.html\" --write` as it increases filesize by 30%",
|
||||
"server": "cd docs && http-server -p 8000 --cors",
|
||||
"watch": "run-p watch:*",
|
||||
"watch:chapters": "chokidar \"./docs/chapters/**/*.*\" -c \"npm run build\"",
|
||||
|
@@ -73,6 +73,8 @@ async function createIndexPages(locale, localeStrings, chapters) {
|
||||
fs.ensureDirSync(localeDir);
|
||||
fs.writeFileSync(path.join(localeDir, `index.html`), index, `utf8`);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export { createIndexPages };
|
||||
|
@@ -5,7 +5,9 @@ import { generateGraphicsModule } from "./generate-graphics-module.js";
|
||||
import paths from "../../project-paths.js";
|
||||
|
||||
const thisModuleURL = new URL(import.meta.url);
|
||||
const thisModuleDir = path.dirname(thisModuleURL.href.replace(`file:///`, ``));
|
||||
const thisModuleDir = path.dirname(
|
||||
thisModuleURL.href.replace(`file:///`, process.win32 ? `` : `/`)
|
||||
);
|
||||
|
||||
/**
|
||||
* ...docs go here...
|
||||
|
@@ -10,7 +10,10 @@ import path from "path";
|
||||
**/
|
||||
|
||||
const moduleURL = new URL(import.meta.url);
|
||||
const src = path.dirname(moduleURL.href.replace(`file:///`, ``));
|
||||
const src = path.dirname(
|
||||
moduleURL.href.replace(`file:///`, process.win32 ? `` : `/`)
|
||||
);
|
||||
|
||||
const project = path.join(src, `..`);
|
||||
const publicDir = path.join(project, `docs`); // yeah... "docs". Because Github is fairly stupid here.
|
||||
const images = path.join(publicDir, `images`);
|
||||
|