@junnyontop-pixel/neo-app 1.1.4 → 1.1.6
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/compiler/NeoParser.js +63 -33
- package/compiler/index.js +17 -11
- package/package.json +1 -1
- package/src/App.js +3 -4
package/compiler/NeoParser.js
CHANGED
|
@@ -1,52 +1,82 @@
|
|
|
1
1
|
export class NeoParser {
|
|
2
|
-
static parse(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const scriptMatch = code.match(/@Script\s*\{([\s\S]*?)\}(?=\s*@|$)/);
|
|
2
|
+
static parse(source) {
|
|
3
|
+
const lines = source.split('\n');
|
|
4
|
+
let root = null;
|
|
6
5
|
let scriptContent = "";
|
|
7
|
-
|
|
6
|
+
const stack = [];
|
|
7
|
+
|
|
8
|
+
// 1. 스크립트 영역 추출 (@Script { ... })
|
|
9
|
+
const scriptMatch = source.match(/@Script\s*\{([\s\S]*?)\}/);
|
|
8
10
|
if (scriptMatch) {
|
|
9
11
|
scriptContent = scriptMatch[1].trim();
|
|
10
|
-
// 만약 사용자가 적은 마지막 } 가 잘려 나갔다면 복구하거나,
|
|
11
|
-
// 원본에서 블록 전체를 가져오는 로직으로 보강
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// 2.
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
// 2. 태그 파싱
|
|
15
|
+
const tagRegex = /@(\w+):(\w+)\s*\{/g;
|
|
16
|
+
let match;
|
|
17
|
+
const tags = [];
|
|
18
|
+
|
|
19
|
+
// 소스에서 태그 블록들을 찾아내기 위한 단순화된 로직
|
|
20
|
+
const tokens = source.split(/(@\w+:\w+\s*\{)/).filter(t => t.trim());
|
|
21
21
|
|
|
22
22
|
tokens.forEach(token => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const tagMatch = token.match(/@(\w+):(\w+)\s*\{/);
|
|
24
|
+
|
|
25
|
+
if (tagMatch) {
|
|
26
|
+
const node = {
|
|
27
|
+
id: tagMatch[1],
|
|
28
|
+
tag: tagMatch[2],
|
|
29
|
+
styles: {},
|
|
30
|
+
events: {},
|
|
31
|
+
innerHtml: "",
|
|
32
|
+
children: []
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Style 추출 (안전 장치 추가)
|
|
36
|
+
const styleMatch = token.match(/Style\((.*?)\)/s);
|
|
37
|
+
if (styleMatch && styleMatch[1]) {
|
|
38
|
+
node.styles = this.parseKV(styleMatch[1]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Event 추출 (안전 장치 추가)
|
|
42
|
+
const eventMatch = token.match(/Event\((.*?)\)/s);
|
|
43
|
+
if (eventMatch && eventMatch[1]) {
|
|
44
|
+
node.events = this.parseKV(eventMatch[1]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Innerhtml 추출
|
|
48
|
+
const htmlMatch = token.match(/Innerhtml:\s*"(.*?)"/);
|
|
49
|
+
if (htmlMatch) {
|
|
50
|
+
node.innerHtml = htmlMatch[1];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!root) {
|
|
54
|
+
root = node;
|
|
55
|
+
} else {
|
|
56
|
+
stack[stack.length - 1].children.push(node);
|
|
57
|
+
}
|
|
28
58
|
stack.push(node);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
stack[stack.length - 1].events = this.parseKV(token.match(/Event\((.*?)\)/)[1]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (token.includes('}')) {
|
|
62
|
+
const closeCount = (token.match(/\}/g) || []).length;
|
|
63
|
+
for (let i = 0; i < closeCount; i++) {
|
|
64
|
+
if (stack.length > 0) stack.pop();
|
|
65
|
+
}
|
|
37
66
|
}
|
|
38
67
|
});
|
|
39
68
|
|
|
40
69
|
return { root, scriptContent };
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
static parseKV(
|
|
72
|
+
static parseKV(kvString) {
|
|
73
|
+
if (!kvString || !kvString.trim()) return {};
|
|
44
74
|
const obj = {};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
obj[
|
|
75
|
+
const pairs = kvString.split(';');
|
|
76
|
+
pairs.forEach(pair => {
|
|
77
|
+
if (pair.includes(':')) {
|
|
78
|
+
const [key, value] = pair.split(':').map(s => s.trim());
|
|
79
|
+
if (key && value) obj[key] = value;
|
|
50
80
|
}
|
|
51
81
|
});
|
|
52
82
|
return obj;
|
package/compiler/index.js
CHANGED
|
@@ -14,32 +14,38 @@ if (!inputFile) {
|
|
|
14
14
|
const source = fs.readFileSync(inputFile, 'utf8');
|
|
15
15
|
const { root, scriptContent } = NeoParser.parse(source);
|
|
16
16
|
|
|
17
|
-
function generateCode(node) {
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function generateCode(node, indent = " ") {
|
|
18
|
+
// 자식 노드들을 재귀적으로 호출하며 들여쓰기를 한 단계 더 깊게(indent + " ") 적용합니다.
|
|
19
|
+
const childrenCode = node.children
|
|
20
|
+
.map(child => generateCode(child, indent + " "))
|
|
21
|
+
.join(',\n');
|
|
22
|
+
|
|
23
|
+
// 이벤트 처리 로직 (보내주신 로직 유지)
|
|
20
24
|
const eventProps = {};
|
|
21
25
|
for (const [evt, action] of Object.entries(node.events)) {
|
|
22
26
|
const propName = `on${evt.charAt(0).toUpperCase() + evt.slice(1)}`;
|
|
23
|
-
|
|
24
27
|
let processedAction = action;
|
|
28
|
+
|
|
29
|
+
// 단순 연산(++) 대응
|
|
25
30
|
if (action.includes('++')) processedAction = `state.${action}`;
|
|
26
31
|
|
|
32
|
+
// 괄호 자동 보정
|
|
27
33
|
if (processedAction.includes('(') && !processedAction.includes(')')) {
|
|
28
34
|
processedAction += ')';
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
eventProps[propName] = `() => { ${processedAction} }`;
|
|
36
|
+
eventProps[propName] = `() => { ${processedAction}; renderApp(); }`; // renderApp() 호출 추가로 화면 갱신 유도
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
const eventString = Object.entries(eventProps)
|
|
35
40
|
.map(([k, v]) => `${k}: ${v}`)
|
|
36
41
|
.join(', ');
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// 템플릿 리터럴을 사용하여 들여쓰기가 적용된 문자열 생성
|
|
44
|
+
return `${indent}h('${node.tag}', {
|
|
45
|
+
${indent} id: '${node.id}',
|
|
46
|
+
${indent} style: ${JSON.stringify(node.styles)},
|
|
47
|
+
${indent} innerHtml: \`${node.innerHtml.replace(/\$(\w+)/g, '${state.$1}')}\`${eventString ? ',\n' + indent + ' ' + eventString : ''}
|
|
48
|
+
${indent}}, [${childrenCode ? '\n' + childrenCode + '\n' + indent : ''}])`;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
// compiler/index.js 내부
|
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -4,13 +4,12 @@ import { h } from '@junnyontop-pixel/neo-app/core/NeoCore.js';
|
|
|
4
4
|
|
|
5
5
|
// [User Script]
|
|
6
6
|
function sayHello() {
|
|
7
|
-
alert("안녕하세요!");
|
|
8
|
-
}
|
|
7
|
+
alert("안녕하세요!");
|
|
9
8
|
|
|
10
9
|
export default function render(state) {
|
|
11
|
-
return
|
|
10
|
+
return h('button', {
|
|
12
11
|
id: 'Btn',
|
|
13
12
|
style: {},
|
|
14
|
-
innerHtml:
|
|
13
|
+
innerHtml: ``
|
|
15
14
|
}, []);
|
|
16
15
|
}
|