FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
modelscript/packages/language/src/codegen/wit.ts at main · modelscript/modelscript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
modelscript
/
modelscript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
3
Star
12
Code
Issues
1
Pull requests
5
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
modelscript
/
packages
/
language
/
src
/
codegen
/
wit.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (29 loc) · 1.55 KB
Breadcrumbs
modelscript
/
packages
/
language
/
src
/
codegen
/
wit.ts
Copy path
File metadata and controls
33 lines (29 loc) · 1.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import
{
LanguageOptions
}
from
"../dsl.js"
;
export
function
generateWit
(
grammarDef
:
LanguageOptions
,
normalized
?:
any
)
:
string
{
const
packageName
=
grammarDef
.
targets
?.
wit
?.
package
||
`modelscript:
${
grammarDef
.
name
||
"parser"
}
`
;
const
worldName
=
grammarDef
.
targets
?.
wit
?.
world
||
"language-runner"
;
let
code
=
`// Wasm Interface Type (WIT) IDL for
${
packageName
}
\n`
;
code
+=
`package
${
packageName
}
;\n\n`
;
code
+=
`world
${
worldName
}
{\n`
;
code
+=
` export parse: func(source: string) -> u32;\n`
;
code
+=
` export get-node-first-child: func(node: u32) -> u32;\n`
;
code
+=
` export get-node-next-sibling: func(node: u32) -> u32;\n`
;
code
+=
` export get-node-type: func(node: u32) -> u32;\n`
;
code
+=
` export get-node-start: func(node: u32) -> u32;\n`
;
code
+=
` export get-node-end: func(node: u32) -> u32;\n`
;
code
+=
` export emit-ast: func(root-instance: u32) -> u32;\n`
;
code
+=
` export clone-node-shadowed: func(ast-ptr: u32, instance-ctx: u32) -> u32;\n`
;
if
(
grammarDef
.
model
)
{
for
(
const
[
modelName
,
fields
]
of
Object
.
entries
(
grammarDef
.
model
)
)
{
if
(
!
fields
)
continue
;
const
modelFields
=
fields
as
Record
<
string
,
any
>
;
for
(
const
fieldName
of
Object
.
keys
(
modelFields
)
)
{
const
kebabModelName
=
modelName
.
replace
(
/
(
[
a
-
z
0
-
9
]
)
(
[
A
-
Z
]
)
/
g
,
"$1-$2"
)
.
toLowerCase
(
)
;
const
kebabFieldName
=
fieldName
.
replace
(
/
(
[
a
-
z
0
-
9
]
)
(
[
A
-
Z
]
)
/
g
,
"$1-$2"
)
.
toLowerCase
(
)
;
code
+=
` export get-
${
kebabModelName
}
-
${
kebabFieldName
}
: func(node: u32) -> u32;\n`
;
}
}
}
code
+=
`}\n`
;
return
code
;
}
Back
|
FazBrowse Home
|
New Git URL