@algosail/parser 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/load.js +1 -1
- package/lib/symbolTable.js +12 -8
- package/lib/tokens.js +1 -1
- package/package.json +1 -1
package/lib/load.js
CHANGED
|
@@ -72,7 +72,7 @@ export async function resolveModulePath(execPath, packageImport) {
|
|
|
72
72
|
|
|
73
73
|
const sailPath = resolveExportsCondition(packageJson.exports, path)
|
|
74
74
|
if (sailPath) {
|
|
75
|
-
return
|
|
75
|
+
return { type: 'js', path: join(packageDir, sailPath) }
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
const importId = path === '.' ? name : `${name}/${path.slice(2)}`
|
package/lib/symbolTable.js
CHANGED
|
@@ -7,11 +7,12 @@ import { getWordNodes } from './word.js'
|
|
|
7
7
|
import { resolveModulePath, resolveFilePath } from './load.js'
|
|
8
8
|
|
|
9
9
|
export async function buildSymbolTable(uri, text, parser) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const {
|
|
14
|
-
const {
|
|
10
|
+
const { tokenizer, language } = parser.sailTokenizer
|
|
11
|
+
const rootNode = tokenizer.parse(text)
|
|
12
|
+
const imports = getImportNodes(rootNode, language)
|
|
13
|
+
const { groups, tags } = getTagNodes(rootNode, language)
|
|
14
|
+
const { maps } = getMapNodes(rootNode, language)
|
|
15
|
+
const { words } = getWordNodes(rootNode, language)
|
|
15
16
|
const errors = getErrors(rootNode)
|
|
16
17
|
|
|
17
18
|
const modules = await getModules(imports, uri, parser)
|
|
@@ -55,9 +56,12 @@ async function getModules(imports, uri, parser) {
|
|
|
55
56
|
|
|
56
57
|
for (const imp of imports) {
|
|
57
58
|
if (imp.type === 'package') {
|
|
58
|
-
const moduleUri = await resolveModulePath(imp.path
|
|
59
|
+
const { type, path: moduleUri } = await resolveModulePath(uri, imp.path)
|
|
59
60
|
const content = await readFile(moduleUri, 'utf8')
|
|
60
|
-
const res =
|
|
61
|
+
const res =
|
|
62
|
+
type === 'js'
|
|
63
|
+
? await parser.parseJs(moduleUri, content)
|
|
64
|
+
: await parser.parseSail(moduleUri, content)
|
|
61
65
|
modules[imp.module] = {
|
|
62
66
|
...res,
|
|
63
67
|
uri: moduleUri,
|
|
@@ -67,7 +71,7 @@ async function getModules(imports, uri, parser) {
|
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
if (imp.type === 'file') {
|
|
70
|
-
const { type, path: fileUri } = await resolveFilePath(imp.path
|
|
74
|
+
const { type, path: fileUri } = await resolveFilePath(uri, imp.path)
|
|
71
75
|
const content = await readFile(fileUri, 'utf8')
|
|
72
76
|
if (type === 'sail') {
|
|
73
77
|
const res = await parser.parseSail(fileUri, content)
|
package/lib/tokens.js
CHANGED
|
@@ -15,7 +15,7 @@ export const fieldDef = (node) => node?.text?.slice(1) ?? null
|
|
|
15
15
|
export const fieldRef = (node) => {
|
|
16
16
|
if (!node) return null
|
|
17
17
|
const [map, field] = node.text.split('.')
|
|
18
|
-
return { map:
|
|
18
|
+
return { map: map.slice(1), field }
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const wordDef = (node) => node?.text?.slice(1) ?? null
|