// Generated automatically by nearley, version 2.19.5 // http://github.com/Hardmath123/nearley (function () { function id(x) { return x[0]; } function getValue(d) { return d[0].value } function literals(list) { var rules = {} for (var lit of list) { rules[lit] = {match: lit, next: 'main'} } return rules } var moo = require('moo') var rules = Object.assign({ ws: {match: /\s+/, lineBreaks: true, next: 'main'}, comment: /\#.*/, arrow: {match: /[=-]+\>/, next: 'main'}, js: { match: /\{\%(?:[^%]|\%[^}])*\%\}/, value: x => x.slice(2, -2), lineBreaks: true, }, word: {match: /[\w\?\+]+/, next: 'afterWord'}, string: { match: /"(?:[^\\"\n]|\\["\\/bfnrt]|\\u[a-fA-F0-9]{4})*"/, value: x => JSON.parse(x), next: 'main', }, btstring: { match: /`[^`]*`/, value: x => x.slice(1, -1), next: 'main', lineBreaks: true, }, }, literals([ ",", "|", "$", "%", "(", ")", ":?", ":*", ":+", "@include", "@builtin", "@", "]", ])) var lexer = moo.states({ main: Object.assign({}, rules, { charclass: { match: /\.|\[(?:\\.|[^\\\n])+?\]/, value: x => new RegExp(x), }, }), // Both macro arguments and charclasses are both enclosed in [ ]. // We disambiguate based on whether the previous token was a `word`. afterWord: Object.assign({}, rules, { "[": {match: "[", next: 'main'}, }), }) function insensitive(sl) { var s = sl.literal; var result = []; for (var i=0; i ({literal: d[0].value})}, {"name": "string", "symbols": [(lexer.has("btstring") ? {type: "btstring"} : btstring)], "postprocess": d => ({literal: d[0].value})}, {"name": "charclass", "symbols": [(lexer.has("charclass") ? {type: "charclass"} : charclass)], "postprocess": getValue}, {"name": "js", "symbols": [(lexer.has("js") ? {type: "js"} : js)], "postprocess": getValue}, {"name": "_$ebnf$1", "symbols": ["ws"], "postprocess": id}, {"name": "_$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "_", "symbols": ["_$ebnf$1"]}, {"name": "ws", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)]}, {"name": "ws$ebnf$1", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": id}, {"name": "ws$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}}, {"name": "ws", "symbols": ["ws$ebnf$1", (lexer.has("comment") ? {type: "comment"} : comment), "_"]} ] , ParserStart: "final" } if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') { module.exports = grammar; } else { window.grammar = grammar; } })();