Skip to content

Commit

Permalink
Merge branch 'main' into schema_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaith authored Oct 7, 2024
2 parents ea9f9c3 + a9c586b commit e694b8d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 21 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Test

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm test
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"bracketSpacing": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"tabWidth": 2
}
2 changes: 1 addition & 1 deletion antlr/Schema.g4
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ yorkieArrayType:
yorkieCounterType: YORKIE_COUNTER;
yorkieTextType:
YORKIE_TEXT LT (typeReference | objectLiteralType) GT;
yorkieTreeType: YORKIE_TREE LT GT;
yorkieTreeType: YORKIE_TREE LT GT;
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"antlr4ts": "^0.5.0-alpha.4",
"antlr4ts-cli": "^0.5.0-alpha.4",
"prettier": "^3.3.3",
"typescript": "^5.5.3",
"vite": "^5.4.1",
"vite-plugin-node-polyfills": "^0.22.0",
Expand Down
12 changes: 6 additions & 6 deletions src/counter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function setupCounter(element: HTMLButtonElement) {
let counter = 0
let counter = 0;
const setCounter = (count: number) => {
counter = count
element.innerHTML = `count is ${counter}`
}
element.addEventListener('click', () => setCounter(counter + 1))
setCounter(0)
counter = count;
element.innerHTML = `count is ${counter}`;
};
element.addEventListener('click', () => setCounter(counter + 1));
setCounter(0);
}
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './style.css'
import typescriptLogo from './typescript.svg'
import viteLogo from '/vite.svg'
import { setupCounter } from './counter.ts'
import './style.css';
import typescriptLogo from './typescript.svg';
import viteLogo from '/vite.svg';
import { setupCounter } from './counter.ts';

document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
Expand All @@ -19,6 +19,6 @@ document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
Click on the Vite and TypeScript logos to learn more
</p>
</div>
`
`;

setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
setupCounter(document.querySelector<HTMLButtonElement>('#counter')!);
11 changes: 6 additions & 5 deletions src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CharStreams, CommonTokenStream } from "antlr4ts";
import { ParseTree } from "antlr4ts/tree/ParseTree";
import { SchemaLexer } from "../antlr/SchemaLexer";
import { SchemaVisitor } from "../antlr/SchemaVisitor";
import { CharStreams, CommonTokenStream } from 'antlr4ts';
import { ParseTree } from 'antlr4ts/tree/ParseTree';
import { SchemaLexer } from '../antlr/SchemaLexer';
import { SchemaVisitor } from '../antlr/SchemaVisitor';
import {
DocumentContext,

Check failure on line 6 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Module '"../antlr/SchemaParser"' has no exported member 'DocumentContext'.

Check failure on line 6 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Module '"../antlr/SchemaParser"' has no exported member 'DocumentContext'.
DefinitionListContext,

Check failure on line 7 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'"../antlr/SchemaParser"' has no exported member named 'DefinitionListContext'. Did you mean 'TypeDefinitionsContext'?

Check failure on line 7 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'"../antlr/SchemaParser"' has no exported member named 'DefinitionListContext'. Did you mean 'TypeDefinitionsContext'?
Expand Down Expand Up @@ -71,11 +71,12 @@ class Visitor implements SchemaVisitor<Node> {
const child = node.getChild(i);
this.visit(child);
}
return new Node("children");
return new Node('children');
}
visitTerminal(node: TerminalNode): Node {
return new Node(node.text);
}

visitErrorNode(node: ErrorNode): Node {
throw new Error(`Syntax error at: ${node.text}`);
}
Expand Down
6 changes: 4 additions & 2 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, assert } from "vitest";
import { validate } from "../src/validator";
import { describe, it, assert } from 'vitest';
import { validate } from '../src/validator';


describe("Use Grammar Similar to TypeScript", () => {
it("value restriction with literal types", () => {
Expand Down Expand Up @@ -228,6 +229,7 @@ describe("User Defined Types", () => {
};
`;
assert.isTrue(validate(schema));

});
});

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedLocals": false,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
Expand Down

0 comments on commit e694b8d

Please sign in to comment.