Skip to content

Commit

Permalink
deploy to github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Azpillaga Aldalur committed Nov 28, 2023
1 parent 92aab15 commit 085a807
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 36 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/onpush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Deploy to GitHub Pages

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build project
run: npm install && npm run generateParser && npm run createDistribution && npm run bundle && npm run fix

- name: Test project
run: npm test

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: dist
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
},
"devDependencies": {
"antlr4ts-cli": "0.5.0-alpha.4",
"chai": "4.3.10",
"esbuild": "0.19.7",
"jest": "^29.7.0",
"serve": "14.2.1",

"ts-jest": "^29.1.1",
"ts-mocha": "10.0.0",
"chai": "4.3.10",
"ts-node": "^10.9.1",
"typescript": "5.3.2"
},
"scripts": {
"all": "npm install && npm run generateParser && npm run createDistribution && npm run bundle && npm run fix && npm run serve",
"generateParser": "antlr4ts src/main/antlr/JSON.g4",
"createDistribution": "mkdir -p dist && cp src/main/resources/index.html dist/index.html",
"createDistribution": "mkdir -p dist && cp src/main/resources/* dist/",
"bundle": "esbuild src/main/typescript/web/main.ts --bundle --define:process.env.NODE_DEBUG=false --loader:.ttf=file --outfile=dist/index.js --external:fs",
"fix": "sed -i '13d' dist/index.js",
"serve": "serve dist",
Expand Down
12 changes: 3 additions & 9 deletions src/main/resources/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<head>
<link rel="stylesheet" href="./index.css">
<link rel="stylesheet" href="./styles.css">
<script src="index.js" type="module" defer></script>
</head>
<body style="margin: 0">
<section id="editor" style="height: 100vh;"></section>
<body>
<section id="editor"/>
</body>

<style>
.updated-highlight
{
color: red;
}
</style>
39 changes: 39 additions & 0 deletions src/main/resources/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
body
{
margin: 0;
}

#editor
{
height: 100vh;
}

.number-member
{
color: plum !important;
}

.string-member
{
color: burlywood !important;
}

.boolean-member
{
color: cadetblue !important;
}

.null-member
{
color: gray !important;
}

.object-member
{
color: lightgreen !important;
}

.array-member
{
color: lightsalmon !important;
}
25 changes: 21 additions & 4 deletions src/main/typescript/ast/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,45 @@ export class JSONValue extends Node {}
export class JSONObject extends JSONValue
{
@Children()
members : JSONMember[] = [];
members : JSONMember[];

constructor(...members: JSONMember[])
{
super();
this.members = members;
}
}

export class JSONMember extends JSONValue
{
@Property()
name : string;
@Child()
value : JSONValue = new JSONValue();
value : JSONValue;

constructor(name: string)
constructor(name: string, value: JSONValue = new JSONValue())
{
super();
this.name = name;
this.value = value;
}
}

export class JSONArray extends JSONValue
{
@Children()
elements : JSONValue[] = [];
elements : JSONValue[];

constructor(...elements : JSONValue[])
{
super();
this.elements = elements;
}
}

export class JSONString extends JSONValue
{
@Property()
value : string;

constructor(value: string)
Expand All @@ -40,6 +55,7 @@ export class JSONString extends JSONValue

export class JSONNumber extends JSONValue
{
@Property()
value : number;

constructor(value: number)
Expand All @@ -51,6 +67,7 @@ export class JSONNumber extends JSONValue

export class JSONBoolean extends JSONValue
{
@Property()
value : boolean;

constructor(value: boolean)
Expand Down
2 changes: 1 addition & 1 deletion src/main/typescript/ast/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createTransformer } from "./transformer";
import { Issue, IssueSeverity, IssueType, Source } from "@strumenta/tylasu";
import { JSONParser, JsonContext } from "../../antlr/JSONParser";
import { JSONLexer } from "../../antlr/JSONLexer";
import { schema } from "../web/schema";
import { schema } from "../validation/schema";

export class JSONASTParser extends TylasuParser<JSONValue, JSONParser, JsonContext, TylasuANTLRToken>
{
Expand Down
File renamed without changes.
32 changes: 27 additions & 5 deletions src/main/typescript/web/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as monaco from "monaco-editor";
import { JSONGenerator } from "@strumenta/tylasu";
import { JSONASTParser } from "../ast/parser";
import { JSONMember } from "../ast/ast";
import { JSONArray, JSONBoolean, JSONMember, JSONNull, JSONNumber, JSONObject, JSONString } from "../ast/ast";

let editor = monaco.editor.create(document.getElementById("editor") as HTMLElement, {theme: "vs-dark"});
let parser = new JSONASTParser();
let decorations = [];
let generator = new JSONGenerator();

editor.onDidChangeModelContent(() =>
{
Expand All @@ -30,10 +28,34 @@ editor.onDidChangeModelContent(() =>
{
if (node instanceof JSONMember)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "updated-highlight"}});
if (node.value instanceof JSONNumber)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "number-member"}});
}
else if (node.value instanceof JSONString)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "string-member"}});
}
else if (node.value instanceof JSONBoolean)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "boolean-member"}});
}
else if (node.value instanceof JSONNull)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "null-member"}});
}
else if (node.value instanceof JSONObject)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "object-member"}});
}
else if (node.value instanceof JSONArray)
{
newDecorations.push({range: new monaco.Range(node.position.start.line, node.position.start.column + 2, node.position.start.line, node.position.start.column + 2 + node.name.length), options: {inlineClassName: "array-member"}});
}
}
}

decorations = editor.deltaDecorations(decorations, newDecorations);

sessionStorage.setItem("ast", generator.toJSON(ast.data))
localStorage.setItem("code", editor.getValue());
});
2 changes: 1 addition & 1 deletion src/test/resources/comprehensive.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"integer": 123,
"number": 123,
"string": "abc",
"boolean": true,
"null": null,
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"fontSize": 22,
"fontFamily": "monospace",
"cursorStyle": "block",
"theme": "vs-dark",
"lineNumbers": false,
"minimap": { "enabled": false },
"scrollbar": { "horizontal": "off", "vertical": "off" }
}
48 changes: 48 additions & 0 deletions src/test/typescript/ast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { assertASTsAreEqual } from "./testing";

import { test } from "mocha"
import { JSONASTParser } from "../../main/typescript/ast/parser";
import { JSONArray, JSONBoolean, JSONMember, JSONNull, JSONNumber, JSONObject, JSONString } from "../../main/typescript/ast/ast";
import assert from "assert";
import { readFileSync } from "fs";
import { CharStreams, CommonTokenStream } from "antlr4ts";
import { JSONLexer } from "../../main/antlr/JSONLexer";
import { JSONParser } from "../../main/antlr/JSONParser";

test("comprehensive ast", () =>
{
let code = readFileSync(__dirname + "/../resources/comprehensive.json").toString();
let parser = new JSONASTParser();
let ast = parser.parse(code);

let expected = new JSONObject
(
new JSONMember("number", new JSONNumber(123)),
new JSONMember("string", new JSONString("abc")),
new JSONMember("boolean", new JSONBoolean(true)),
new JSONMember("null", new JSONNull()),
new JSONMember("object", new JSONObject()),
new JSONMember("array", new JSONArray
(
new JSONNumber(123),
new JSONString("abc"),
new JSONBoolean(false),
new JSONNull(),
new JSONObject(),
new JSONArray()
))
);

assertASTsAreEqual(expected, ast.data);
});

test("antlr", () =>
{
let code = readFileSync(__dirname + "/../resources/comprehensive.json").toString();
let characters = CharStreams.fromString(code);
let lexer = new JSONLexer(characters);
let tokens = new CommonTokenStream(lexer);
let parser = new JSONParser(tokens);
let tree = parser.json();
console.log(tree.value().obj().pair());
});
13 changes: 0 additions & 13 deletions src/test/typescript/synthetic.ts

This file was deleted.

2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"compilerOptions":
{
"target": "ES6",
"module": "NodeNext",
"experimentalDecorators": true
}
}

0 comments on commit 085a807

Please sign in to comment.