FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
modelscript/packages/language/src/api.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
/
api.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (100 loc) · 3.94 KB
Breadcrumbs
modelscript
/
packages
/
language
/
src
/
api.ts
Copy path
File metadata and controls
112 lines (100 loc) · 3.94 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import
type
{
GrammarConflictDiagnostic
}
from
"./automata.js"
;
import
{
generateJavaScriptWrapper
}
from
"./bindings/javascript/index.js"
;
import
{
compileMcpConfig
,
type
McpManifest
}
from
"./codegen/compile_mcp.js"
;
import
type
{
GeneratedFile
}
from
"./codegen/parser.js"
;
import
{
generateParser
,
generateParserTables
}
from
"./codegen/parser.js"
;
import
{
generateTextMate
}
from
"./codegen/textmate.js"
;
import
{
LanguageOptions
,
SOURCE_PATH_SYMBOL
,
SOURCE_TEXT_SYMBOL
}
from
"./dsl.js"
;
export
type
{
GrammarConflictDiagnostic
}
from
"./automata.js"
;
export
type
{
McpManifest
}
from
"./codegen/compile_mcp.js"
;
/**
* Options for configuring language parser build and source AST extraction.
*/
export
interface
BuildOptions
{
/** Source file path for Direct Source AST extraction */
sourcePath
?:
string
;
/** Source code text for in-memory Direct Source AST extraction */
sourceText
?:
string
;
}
/**
* Metadata about the generated grammar parser.
*/
export
interface
ParserResult
{
/** The name of the language. */
name
:
string
;
/** The root start symbol of the grammar. */
startSymbol
:
string
;
/** An array of all non-terminal symbols extracted from the grammar. */
nonTerminals
:
string
[
]
;
/** An array of all terminal symbols (tokens) extracted from the grammar. */
terminals
:
string
[
]
;
/** The total number of states in the generated GLR action table. */
statesCount
:
number
;
}
/**
* The full build output generated by the ModelScript language compiler.
*/
export
interface
BuildResult
{
/** Metadata and statistics about the generated parser. */
parserInfo
:
ParserResult
;
/** The generated AssemblyScript files (action/goto tables, automata, grammar) to be compiled to WASM. */
assemblyScriptFiles
:
GeneratedFile
[
]
;
/** The generated JavaScript wrapper code and TypeScript typings to interface with the WASM parser. */
javascriptWrapper
:
{
js
:
string
;
dts
:
string
;
syntaxNames
?:
string
[
]
;
fieldNames
?:
string
[
]
;
semanticLegend
?:
{
tokenTypes
:
string
[
]
;
tokenModifiers
:
string
[
]
}
;
}
;
table
?:
any
;
/** Any unresolved grammar conflicts (shift/reduce or reduce/reduce). */
conflicts
?:
GrammarConflictDiagnostic
[
]
;
/** Compiled Model Context Protocol (MCP) tool and resource manifest. */
mcpManifest
?:
McpManifest
;
}
/**
* Compiles a DSL grammar definition into a set of AssemblyScript source files,
* JavaScript wrappers, and LR automata tables ready for WASM compilation.
*
*
@param
languageDef The grammar definition created using the DSL functions
*
@returns
The final build result containing code strings and parser metadata
*/
export
function
buildParser
(
languageDef
:
LanguageOptions
,
options
?:
BuildOptions
)
:
BuildResult
{
if
(
options
?.
sourcePath
)
{
(
languageDef
as
any
)
[
SOURCE_PATH_SYMBOL
]
=
options
.
sourcePath
;
}
if
(
options
?.
sourceText
)
{
(
languageDef
as
any
)
[
SOURCE_TEXT_SYMBOL
]
=
options
.
sourceText
;
}
const
result
=
generateParser
(
languageDef
)
;
const
parserInfo
=
{
name
:
languageDef
.
name
,
startSymbol
:
result
.
grammar
.
startSymbol
,
nonTerminals
:
Array
.
from
(
result
.
grammar
.
nonTerminals
)
,
terminals
:
Array
.
from
(
result
.
grammar
.
terminals
)
,
statesCount
:
result
.
table
.
actionTable
.
size
,
}
;
const
assemblyScriptFiles
=
generateParserTables
(
languageDef
,
result
.
grammar
,
result
.
table
,
languageDef
.
recovery
?.
sync
||
[
]
,
)
;
const
javascriptWrapper
=
generateJavaScriptWrapper
(
languageDef
,
result
.
grammar
)
;
const
textMateContent
=
generateTextMate
(
languageDef
)
;
assemblyScriptFiles
.
push
(
{
filename
:
"tmLanguage.json"
,
content
:
textMateContent
.
tm
}
)
;
assemblyScriptFiles
.
push
(
{
filename
:
"monarch.json"
,
content
:
textMateContent
.
monarch
}
)
;
let
mcpManifest
:
McpManifest
|
undefined
;
if
(
languageDef
.
mcp
)
{
mcpManifest
=
compileMcpConfig
(
languageDef
.
mcp
,
languageDef
.
name
)
.
manifest
;
}
return
{
parserInfo
,
assemblyScriptFiles
,
javascriptWrapper
,
table
:
result
.
table
,
conflicts
:
result
.
table
.
diagnostics
||
[
]
,
mcpManifest
,
}
;
}
Back
|
FazBrowse Home
|
New Git URL