123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- module.exports = (function(){function _waka(parser, startRule) {
- if(startRule && ! parser.rules[startRule])
- throw new Error('start rule missing: ' + JSON.stringify(startRule))
- return {
- getState: function() {
- return parser.state
- },
- getTrace: function(message) {
- return (message ? message + '\n' : '') + parser.state.traceLine()
- },
- exec: function(input) {
- if(! startRule)
- throw new Error('no start rule given')
- parser.state.setInput(input)
- try {
- var value = parser.rules[startRule]()
- }
- catch(err) {
- var error = err
- }
- if(error == null) {
- if(! parser.state.adv || ! parser.state.isEOF())
- var error = new Error('Unexpected syntax in top')
- }
- return {
- success: error == null,
- value: ! error ? value : undefined,
- error: error
- }
- },
- startWith: function(rule) {
- return _waka(parser, rule)
- },
- }
- };
- return _waka((function(){'use strict';
- var _rules={};
- _rules.NameStartChar = function() {
- var _R=_P.match(":");
- if(!_P.adv){ _P.adv=true;
- var $0=_P.cur();
- if($0==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("A"<=$0&&$0<="Z");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("_");
- }
- if(!_P.adv){ _P.adv=true;
- var $1=_P.cur();
- if($1==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("a"<=$1&&$1<="z");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $2=_P.cur();
- if($2==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00C0"<=$2&&$2<="\u00D6");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $3=_P.cur();
- if($3==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00D8"<=$3&&$3<="\u00F6");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $4=_P.cur();
- if($4==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00F8"<=$4&&$4<="\u02FF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $5=_P.cur();
- if($5==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u0370"<=$5&&$5<="\u037D");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $6=_P.cur();
- if($6==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u037F"<=$6&&$6<="\u1FFF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $7=_P.cur();
- if($7==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u200C"<=$7&&$7<="\u200D");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $8=_P.cur();
- if($8==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u2070"<=$8&&$8<="\u218F");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $9=_P.cur();
- if($9==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u2C00"<=$9&&$9<="\u2FEF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $a=_P.cur();
- if($a==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u3001"<=$a&&$a<="\uD7FF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $b=_P.cur();
- if($b==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\uF900"<=$b&&$b<="\uFDCF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $c=_P.cur();
- if($c==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\uFDF0"<=$c&&$c<="\uFFFD");
- }
- }
- if(!_P.adv){ _P.adv=true;
- $d:{var $e=_P.pos;
- var $f=_P.cur();
- if($f==null){_P.adv=false;
- null;
- }else{
- _P.step("\uD800"<=$f&&$f<="\uDB7F");
- }
- if(!_P.adv) break $d;
- var $g=_P.cur();
- if($g==null){_P.adv=false;
- null;
- }else{
- _P.step("\uDC00"<=$g&&$g<="\uDFFF");
- }
- var _R=_P.doc.substring($e,_P.pos);
- }
- if(!_P.adv) _P.pos=$e;
- }
- return _R;
- }
- _rules.NameChar = function() {
- var _R=_rules.NameStartChar();
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("-");
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match(".");
- }
- if(!_P.adv){ _P.adv=true;
- var $0=_P.cur();
- if($0==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("0"<=$0&&$0<="9");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("\u00B7");
- }
- if(!_P.adv){ _P.adv=true;
- var $1=_P.cur();
- if($1==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u0300"<=$1&&$1<="\u036F");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $2=_P.cur();
- if($2==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u203F"<=$2&&$2<="\u2040");
- }
- }
- return _R;
- }
- _rules.Name = function() {
- $0:{var $1=_P.pos;
- _rules.NameStartChar();
- if(!_P.adv) break $0;
- var $2=false;
- for(;;) {
- _rules.NameChar();
- if(!_P.adv) break;
- $2=true;
- }; _P.adv=true;
- var _R=_P.doc.substring($1,_P.pos);
- }
- if(!_P.adv) _P.pos=$1;
- return _R;
- }
- _rules.QName = function() {
- var _R=_rules.PrefixedName();
- if(!_P.adv){ _P.adv=true;
- var _R=_rules.UnprefixedName();
- }
- return _R;
- }
- _rules.PrefixedName = function() {
- $0:{var $1=_P.pos;
- _rules.Prefix();
- if(!_P.adv) break $0;
- _P.match(":");
- if(!_P.adv) break $0;
- _rules.LocalPart();
- var _R=_P.doc.substring($1,_P.pos);
- }
- if(!_P.adv) _P.pos=$1;
- return _R;
- }
- _rules.UnprefixedName = function() {
- var _R=_rules.LocalPart();
- return _R;
- }
- _rules.Prefix = function() {
- var _R=_rules.NCName();
- return _R;
- }
- _rules.LocalPart = function() {
- var _R=_rules.NCName();
- return _R;
- }
- _rules.NCNameStartChar = function() {
- var $0=_P.cur();
- if($0==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("A"<=$0&&$0<="Z");
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("_");
- }
- if(!_P.adv){ _P.adv=true;
- var $1=_P.cur();
- if($1==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("a"<=$1&&$1<="z");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $2=_P.cur();
- if($2==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00C0"<=$2&&$2<="\u00D6");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $3=_P.cur();
- if($3==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00D8"<=$3&&$3<="\u00F6");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $4=_P.cur();
- if($4==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u00F8"<=$4&&$4<="\u02FF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $5=_P.cur();
- if($5==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u0370"<=$5&&$5<="\u037D");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $6=_P.cur();
- if($6==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u037F"<=$6&&$6<="\u1FFF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $7=_P.cur();
- if($7==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u200C"<=$7&&$7<="\u200D");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $8=_P.cur();
- if($8==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u2070"<=$8&&$8<="\u218F");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $9=_P.cur();
- if($9==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u2C00"<=$9&&$9<="\u2FEF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $a=_P.cur();
- if($a==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u3001"<=$a&&$a<="\uD7FF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $b=_P.cur();
- if($b==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\uF900"<=$b&&$b<="\uFDCF");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $c=_P.cur();
- if($c==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\uFDF0"<=$c&&$c<="\uFFFD");
- }
- }
- if(!_P.adv){ _P.adv=true;
- $d:{var $e=_P.pos;
- var $f=_P.cur();
- if($f==null){_P.adv=false;
- null;
- }else{
- _P.step("\uD800"<=$f&&$f<="\uDB7F");
- }
- if(!_P.adv) break $d;
- var $g=_P.cur();
- if($g==null){_P.adv=false;
- null;
- }else{
- _P.step("\uDC00"<=$g&&$g<="\uDFFF");
- }
- var _R=_P.doc.substring($e,_P.pos);
- }
- if(!_P.adv) _P.pos=$e;
- }
- return _R;
- }
- _rules.NCNameChar = function() {
- var _R=_rules.NCNameStartChar();
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("-");
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match(".");
- }
- if(!_P.adv){ _P.adv=true;
- var $0=_P.cur();
- if($0==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("0"<=$0&&$0<="9");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var _R=_P.match("\u00B7");
- }
- if(!_P.adv){ _P.adv=true;
- var $1=_P.cur();
- if($1==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u0300"<=$1&&$1<="\u036F");
- }
- }
- if(!_P.adv){ _P.adv=true;
- var $2=_P.cur();
- if($2==null){_P.adv=false;
- var _R=null;
- }else{
- var _R=_P.step("\u203F"<=$2&&$2<="\u2040");
- }
- }
- return _R;
- }
- _rules.NCName = function() {
- $0:{var $1=_P.pos;
- _rules.NCNameStartChar();
- if(!_P.adv) break $0;
- var $2=false;
- for(;;) {
- _rules.NCNameChar();
- if(!_P.adv) break;
- $2=true;
- }; _P.adv=true;
- var _R=_P.doc.substring($1,_P.pos);
- }
- if(!_P.adv) _P.pos=$1;
- return _R;
- }
- function ParserState() {
- this.doc = ''
- this.pos = 0
- this.adv = true
- this.setInput = function(doc) {
- this.doc = doc
- this.pos = 0
- this.adv = true
- }
- this.isEOF = function() {
- return this.pos == this.doc.length
- }
- this.cur = function() {
- return _P.doc[_P.pos]
- }
- this.match = function(str) {
- if(_P.adv = _P.doc.substr(_P.pos, str.length) == str) {
- _P.pos += str.length
- return str
- }
- }
- this.step = function(flag) {
- if(_P.adv = flag) {
- _P.pos++
- return _P.doc[_P.pos - 1]
- }
- }
- this.unexpected = function(rule) {
- throw new Error('Unexpected syntax in ' + rule)
- }
- this.traceLine = function(pos) {
- if(! pos) pos = _P.pos
- var from = _P.doc.lastIndexOf('\n', pos), to = _P.doc.indexOf('\n', pos)
-
- if(from == -1)
- from = 0
- else
- from++
-
- if(to == -1)
- to = pos.length
- var lineNo = _P.doc.substring(0, from).split('\n').length
- var line = _P.doc.substring(from, to)
- var pointer = Array(200).join(' ').substr(0, pos - from) + '^^^'
- return (
- 'Line ' + lineNo + ':\n' +
- line + '\n' +
- pointer
- )
- }
- }
- var _P = new ParserState
- return {
- state: _P,
- rules: _rules,
- }
- })(),null)})()
|