如何在c#中解析javascript以分离代码文件?
下面是我要分析的示例脚本文件:如何在c#中解析javascript以分离代码文件?,javascript,c#,asp.net,Javascript,C#,Asp.net,下面是我要分析的示例脚本文件: <script> module.exports = function() { internals: function() { return { key: "value", anotherKey: "some other value" } }, fruit: { apples: function() { return "Don't like
<script>
module.exports = function() {
internals: function() {
return {
key: "value",
anotherKey: "some other value"
}
},
fruit: {
apples: function() {
return "Don't like them";
},
bananas: function() {
return "Yuck";
}
},
drinks: {
water: function(ice) {
return ice ? "water with ice" : "just water";
}
}
}
</script>
和水果
将包含:
Key: "key" Value: "value"
Key: "anotherKey" Value: "some other value"
Key: "apples" Value: "function() {\n return "Don't like them"; \n}
Key: "bananas" Value: "function() {\n return "Yuck"; \n}
等等
但仍然能够解析:
water(ice) {
return ice ? "water with ice" : "just water";
}
我基本上想抽象所有的内部结构、水果和饮料,这样我就可以迭代它们,然后写回一个文件。。。因此,我可能会这样做:
foreach(var f in fruit) {
// etc.
}
这样我就可以按原样重新创建脚本文件
我希望能够解析它,而不考虑箭头函数和更新的
js
语法。我只想了解每一部分的内容。希望这是有意义的。你自己做这件事是我的专长。你看过预构建的解析器吗?看过。他们中的大多数都是关于执行实际的代码。。。net等。
foreach(var f in fruit) {
// etc.
}