Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use react + typescript #69

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5303242
create react app, display dismissible toast
ericvergnaud Jan 17, 2023
18b1f1e
shows 2 columns that can be resized
ericvergnaud Jan 18, 2023
7b30dd6
migrate to typescript
ericvergnaud Jan 18, 2023
0a50361
able to load samples and select one
ericvergnaud Jan 18, 2023
b3b009b
displays help
ericvergnaud Jan 18, 2023
f57dfa0
support antlr-mode in grammar editor
ericvergnaud Jan 19, 2023
9b7d546
switches lexer/parser sessions
ericvergnaud Jan 19, 2023
ba9736f
loads editor with remote grammars
ericvergnaud Jan 19, 2023
053be1b
supports input selector
ericvergnaud Jan 19, 2023
f031bcf
adds input editor and loads input at startup, when selecting grammar …
ericvergnaud Jan 20, 2023
cf2990e
removes animation when resizing
ericvergnaud Jan 20, 2023
31d0a80
displays tool errors, parse errors, input markers and input annotations
ericvergnaud Jan 20, 2023
e67121d
I'm running the server from docker, and the UI from desktop, which is…
ericvergnaud Jan 20, 2023
1caf1c9
displays token details when hovering over input
ericvergnaud Jan 21, 2023
c0153bb
fix typo
ericvergnaud Jan 21, 2023
dc89070
fix react warning
ericvergnaud Jan 21, 2023
caf496f
adds annotations to grammar editor, clears errors on grammar change
ericvergnaud Jan 21, 2023
d1302f1
supports drag & drop
ericvergnaud Jan 21, 2023
cfdfffa
displays svg tree and hierarchy
ericvergnaud Jan 21, 2023
6013e39
add Profiler table
ericvergnaud Jan 21, 2023
7f45331
build to "static" folder"
ericvergnaud Jan 21, 2023
8099ba7
drop static content now built from "web" folder
ericvergnaud Jan 21, 2023
4b002d8
build react app to 'web' to avoid confusion since it contains a 'stat…
ericvergnaud Jan 21, 2023
a70e01f
update instructions
ericvergnaud Jan 21, 2023
a101c4e
re-enable splash screen
ericvergnaud Jan 21, 2023
6fbab09
set left pane width to 300px min
ericvergnaud Jan 23, 2023
1b59fc5
set left pane width to 300px min
ericvergnaud Jan 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
hs_err_pid*
target/
nohup.out
static
web
antlr4-lab.iml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN apt install -y openjdk-11-jre

COPY src /app/src
COPY resources /app/resources
COPY static /app/static
COPY web /app/web
COPY pom.xml /app/pom.xml

# Assumes mvn install was run prior to build Dockerfile
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,30 @@ sudo nohup java -cp ~/.m2/repository/org/antlr/antlr4-lab/0.2-SNAPSHOT/antlr4-la

If you are running the server locally on your box, visit [http://localhost/index.html](http://localhost/index.html) to run the client.

### React

The UI is now build using react/typescript.

To build the UI, you'll need node 16.17+ and yarn 1.22+.

````bash
cd react
yarn install # fetches the dependencies
yarn build # builds the web app into the parent 'web' folder
````

To work on the UI, run the backend in Docker, and open your favorite UI dev tool (WebStorm, VSCode...)

````bash
cd react
yarn install # fetches the dependencies
yarn start # runs the UI on port 3000, redirecting backend calls to 80
````


### Docker

I created a [Dockerfile](Dockerfile), although I'm not sure how useful it will be to people. This might be useful for deploying in the cloud later.
I created a [Dockerfile](Dockerfile), which is useful when working on the UI, you can run the backend locally in docker and the UI on port 3000. This might also be useful for deploying in the cloud later.

Here's how to build the docker file:

Expand Down
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jetty.version>11.0.13</jetty.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -60,13 +61,18 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.11</version>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>11.0.11</version>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -105,8 +111,8 @@
<directory>resources</directory>
</resource>
<resource>
<directory>static</directory>
<targetPath>static</targetPath>
<directory>web</directory>
<targetPath>web</targetPath>
</resource>
</resources>
<testResources>
Expand Down
23 changes: 23 additions & 0 deletions react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `yarn build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
43 changes: 43 additions & 0 deletions react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "static",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"ace-builds": "^1.14.0",
"csstype": "^3.1.1",
"react": "^18.2.0",
"react-ace": "^10.1.0",
"react-bootstrap": "^2.7.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.4",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "BUILD_PATH='../web' react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
File renamed without changes
55 changes: 55 additions & 0 deletions react/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6BBQE9CZKG"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-6BBQE9CZKG');
</script>

<title>ANTLR Lab: learn, test, and experiment with ANTLR grammars online!</title>
<!-- META -->
<!-- LinkedIn meta -->
<meta property='og:title' content="ANTLR Lab"/>
<meta property='og:image' content="http://lab.antlr.org/images/antlrlogo.png">
<meta property='og:description' content="Learn, test, and experiment with ANTLR grammars online!"/>
<meta property='og:url' content="http://lab.antlr.org"/>

<!-- Facebook meta -->
<meta property="og:type" content="website" />

<!-- Twitter meta -->
<meta name="twitter:title" content="ANTLR Lab">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@the_antlr_guy">
<meta name="twitter:creator" content="@the_antlr_guy">
<meta name="twitter:description" content="Learn, test, and experiment with ANTLR grammars online!">
<meta name="twitter:image" content="http://lab.antlr.org/images/antlrlogo.png">
<!-- END META -->

<meta name="viewport" content="width=device-width, initial-scale=1">

<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>

<link rel="icon" href="%PUBLIC_URL%/antlricon.png" />
<meta
name="description"
content="ANTLR Lab: learn, test, and experiment with ANTLR grammars online!"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
3 changes: 3 additions & 0 deletions react/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
56 changes: 56 additions & 0 deletions react/src/ace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.ace_editor { /* grammar and input editors */
border: solid .5px #7F7F7F;
height: 100%;
min-width: 300px;
min-height:120px;
font-family: 'Inconsolata', 'Menlo', monospace;
font-size: 12px;
}

.lexical_error_class {
position: absolute;
/*background-color: #D72D26;*/
background-color: #9A2E06;
opacity: .3;
}

.syntax_error_class {
position: absolute;
/*background-color: #D72D26;*/
background-color: #9A2E06;
opacity: .3;
}

.token_range_class {
position: absolute;
border-bottom: 2px solid grey;
}

.ace_gutter-cell {
position: absolute;
top: 0;
left: 0;
right: 0;
background-color: white;
padding-left: 1px;
padding-right: 0px;
font-size: 9px;
color: #8C8C8C;
}

.ace_gutter-cell.ace_error {
background-image: none;
color: black;
border: .5px solid red;
transform: translateY(-7%);
}

.ace_gutter-layer {
background-color: white;
position: relative;
width: auto;
text-align: right;
pointer-events: auto;
height: 1000000px;
contain: style size layout;
}
16 changes: 16 additions & 0 deletions react/src/ace/AceUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Ace} from "ace-builds";

export function clearSessionExtras(session: Ace.EditSession) {
session.setAnnotations(null);
clearSessionMarkers(session);
}

export function clearSessionMarkers(session: Ace.EditSession) {
const markers = session.getMarkers();
if(markers) {
const keys = Object.keys(markers);
for(let key of keys)
// @ts-ignore
session.removeMarker(markers[key].id);
}
}
Loading