我在字符串中有一个函数:
def sum(num):
end
我想将其转换为:
function sum(num) {
}
const grammar = {
"lex": {
"macros": {
"function": "def ",
"name_function":"(_*[a-zA-Z][a-zA-Z0-9_]*)\\(",
"arguments_function": "(\\s*_*[a-zA-Z][a-zA-Z0-9_]*\\s*,?)*\\):"
},
"rules": [
["{", "return '{'"],
[":", "return ':'"],
["}", "return '}'"],
["end", "return '}'"],
['\\/\\/.*', "/* ignore comment */"],
["\\s+", "/* skip whitespace */"],
["{function}", "return 'FUNCTION'"],
["{name_function}", "return 'NAME_FUNCTION'"],
["{arguments_function}","return 'ARGS_FUNCTION'"],
["$", "return 'EOF'"]
]
},
"operators": [
["left", "UMINUS"]
],
"bnf": {
"expressions": [
["e EOF", "return $1"]
],
"e" :[
["FUNCTION NAME_FUNCTION ARGS_FUNCTION :", "$$ = 'function ' + $NAME_FUNCTION.trim() + $ARGS_FUNCTION.trim() + '{';"],
["}", "$$ = '}';"]
]
}
};
module.exports = grammar;
我没有在定义的正则表达式中找到错误,或者我不知道它是否是一个jison错误。
感谢。