We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var jcon = require('jcon'); var epsilon = jcon.string(''); var num = jcon.regex(/\d+/).setAst('num'); var sum_operator = jcon.regex(/[\+\-]/).setAst('operator'); var product_operator = jcon.regex(/[\*\/]/).setAst('operator'); var skips = jcon.regex(/\s*/).skip(); var product = jcon.lazy(function(){ return jcon.or( num, jcon.seq(num, product_rest) ); }).setAst('product'); var product_rest = jcon.or(epsilon, jcon.seq(skips, product_operator, skips, product)); var sum = jcon.lazy(function(){ return jcon.or(product, jcon.seq(product, sum_rest) ); }).setAst('sum'); var sum_rest = jcon.or(epsilon, jcon.seq(skips, sum_operator, skips, sum)); var s = sum.parse('1+2*3+4/5').ast(); console.log(JSON.stringify(s, null, ' '));
The text was updated successfully, but these errors were encountered:
sum和product的ast设置错误,应该设置在seq rest的节点上,lazy只是为了在rest定义前使用rest定义sum或product
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: