AST: intro
今の状態だとせいぜいタグの名前、属性、テキストの内容ぐらいしか表せない。
もっと複雑なHTMLをtemplateに書けるようにしたい
code: ts
const app = createApp({
template: `
<div class="container" style="text-align: center">
<h2>Hello, chibivue!</h2>
<img
width="150px"
alt="Vue.js Logo"
/>
<p><b>chibivue</b> is the minimal Vue.js</p>
<style>
.container {
height: 100vh;
padding: 16px;
}
</style>
</div>
`,
})
app.mount('#app')
これを正規表現でパースするのは難しいので、本格的なパーサーを実装する!
ASTを使う
Abstract Syntax Tree (抽象構文木)
構文を表現する木構造のデータ表現