Skip to content

Commit

Permalink
Parser TS bindings (#7881)
Browse files Browse the repository at this point in the history
Generate TS bindings and lazy deserialization for the parser types.

# Important Notes
- The new API is imported into `ffi.ts`, but not yet used.
- I have tested the generated code in isolation, but cannot commit tests as we are not currently able to load WASM modules when running in `vitest`.
  • Loading branch information
kazcw authored Oct 11, 2023
1 parent a2c8940 commit 9fd1ab9
Show file tree
Hide file tree
Showing 56 changed files with 2,874 additions and 822 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"lib/rust/parser/src/syntax/tree/visitor",
"lib/rust/parser/jni",
"lib/rust/parser/generate-java",
"lib/rust/parser/schema",
"lib/rust/parser/debug",
"lib/rust/ensogl/pack",
"lib/rust/profiler/data",
Expand Down
4 changes: 2 additions & 2 deletions app/gui/language/parser/src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Translate {
let space = span.left_offset.code.repr.len();
self.space_after.insert(self.offset, space);
self.offset += space;
span.left_offset.visible.width_in_spaces
usize::try_from(span.left_offset.visible.width_in_spaces).unwrap()
}

/// This must be called at the beginning of each [`Token`], as they are processed in depth-first
Expand All @@ -93,7 +93,7 @@ impl Translate {
/// This must be called at the beginning of each [`Token`], as they are processed in depth-first
/// order. It updates the internal counter for the token's bytes, and returns its contents.
fn visit_token_ref<T>(&mut self, token: syntax::token::Ref<T>) -> WithInitialSpace<String> {
let space = token.left_offset.visible.width_in_spaces;
let space = usize::try_from(token.left_offset.visible.width_in_spaces).unwrap();
let body = token.code.to_string();
self.space_after.insert(self.offset, space);
self.offset += token.left_offset.code.repr.len();
Expand Down
4 changes: 3 additions & 1 deletion app/gui2/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.html
*.css
*.css

**/generated
2 changes: 1 addition & 1 deletion app/gui2/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="vite/client" />

declare const PROJECT_MANAGER_URL: string
declare const RUNNING_VTEST: boolean
declare const RUNNING_VITEST: boolean

// This is an augmentation to the built-in `ImportMeta` interface.
// This file MUST NOT contain any top-level imports.
Expand Down
3 changes: 2 additions & 1 deletion app/gui2/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DIR_NAME = path.dirname(url.fileURLToPath(import.meta.url))

const conf = [
{
ignores: ['rust-ffi/pkg', 'dist'],
ignores: ['rust-ffi/pkg', 'dist', 'src/generated'],
},
...compat.extends('plugin:vue/vue3-recommended'),
eslintJs.configs.recommended,
Expand All @@ -26,6 +26,7 @@ const conf = [
'./tsconfig.server.json',
'./tsconfig.app.vitest.json',
'./tsconfig.server.vitest.json',
'./parser-codegen/tsconfig.json',
],
},
},
Expand Down
8 changes: 6 additions & 2 deletions app/gui2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"typecheck": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
"lint": "eslint .",
"format": "prettier --write src/ && eslint . --fix",
"build-rust-ffi": "cd rust-ffi && wasm-pack build --release --target web",
"preinstall": "npm run build-rust-ffi"
"build-rust-ffi": "wasm-pack build ./rust-ffi --release --target web",
"generate-ast-schema": "cargo run -p enso-parser-schema > src/generated/ast-schema.json",
"generate-ast-types": "tsx ./parser-codegen/index.ts src/generated/ast-schema.json src/generated/ast.ts",
"preinstall": "npm run build-rust-ffi && npm run generate-ast-schema && npm run generate-ast-types"
},
"dependencies": {
"@babel/parser": "^7.22.16",
Expand Down Expand Up @@ -75,6 +77,7 @@
"@vue/tsconfig": "^0.4.0",
"ag-grid-community": "^30.1.0",
"ag-grid-enterprise": "^30.1.0",
"change-case": "^5.0.2",
"d3": "^7.4.0",
"esbuild": "^0.19.3",
"eslint": "^8.49.0",
Expand All @@ -86,6 +89,7 @@
"shuffle-seed": "^1.1.6",
"sql-formatter": "^13.0.0",
"tailwindcss": "^3.2.7",
"tsx": "^3.12.6",
"typescript": "~5.2.2",
"vite": "^4.4.9",
"vite-plugin-inspect": "^0.7.38",
Expand Down
Loading

0 comments on commit 9fd1ab9

Please sign in to comment.