lc2-compiler
Advanced tools
Comparing version 1.0.0 to 1.1.0
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LCP = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});exports.keywordRegexp=void 0;var _identifier=require('./lib/identifier');Object.defineProperty(exports,'keywordRegexp',{enumerable:!0,get:function(){return _identifier.keywordRegexp}});exports.parse=parse;exports.tokenizer=tokenizer;exports.parseFragment=parseFragment;var _lib=require('./lib'),_lib2=_interopRequireDefault(_lib);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function parse(a,b){return new _lib2.default(b,a).parse()}function tokenizer(a,b){return new _lib2.default(b,a)}function parseFragment(a,b){const c=new _lib2.default(b,a);return c.nextToken(),c.parseStatement()} | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});exports.parseAt=exports.plugins=exports.keywordRegexp=exports.types=void 0;var _tokentype=require('./lib/tokentype');Object.defineProperty(exports,'types',{enumerable:!0,get:function(){return _tokentype.types}});var _identifier=require('./lib/identifier');Object.defineProperty(exports,'keywordRegexp',{enumerable:!0,get:function(){return _identifier.keywordRegexp}});exports.parse=parse;exports.tokenizer=tokenizer;exports.parseFragment=parseFragment;var _lib=require('./lib');const plugins=exports.plugins=_lib.pluginTable;function parse(a,b){return new _lib.Parser(b,a).parse()}function tokenizer(a,b){return new _lib.Parser(b,a)}function parseFragment(a,b){const c=new _lib.Parser(b,a);return c.nextToken(),c.parseStatement()}const parseAt=exports.parseAt=parseFragment; | ||
},{"./lib":4,"./lib/identifier":3}],2:[function(require,module,exports){ | ||
},{"./lib":4,"./lib/identifier":3,"./lib/tokentype":7}],2:[function(require,module,exports){ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});const astTypeTable={CLICK:'click',PROCESS:'process',RETURN:'return',LOG:'log',EXPRESSION:'expr',CALL:'call',WAIT:'wait',TRIGGER:'trig',ASSERT:'assert',JUMPTO:'jumpto',REFRESH:'refresh'};exports.default=astTypeTable; | ||
@@ -11,3 +11,3 @@ | ||
},{}],4:[function(require,module,exports){ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _options=require('./options'),_locutil=require('./locutil'),_tokentype=require('./tokentype'),_identifier=require('./identifier'),_whitespace=require('./whitespace'),_ast=require('./ast'),_ast2=_interopRequireDefault(_ast);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}class Parser{constructor(a,b){this.options=(0,_options.getOptions)(a),this.keywords=_identifier.keywordRegexp,this.macros=_identifier.macroRegexp,this.input=b+'',this.pos=0,this.type=_tokentype.types.eof,this.value=null,this.start=this.end=this.pos,this.lastTokStart=this.lastTokEnd=this.pos,this.exprAllowed=!1,this.genAllowed=!1,this.labels=[],this.conf={},this.keys={},this.nextID=0,this.pcs={},this.pcsTable={},this.inTag=!1}parse(){this.nextToken();let a={CONFIG:this.conf,DATA_KEYS:this.keys,PROCESSES:this.pcs};return this.parseTopLevel(a)}raise(a,b){const c=(0,_locutil.getLineInfo)(this.input,a);b+=' ('+c.line+':'+c.column+')';const d=this.options.left,f=this.options.right;b=d||f?d+b+f:(0,_locutil.empowerErrMsg)(this.input,c,b);const g=this.pos;throw new _locutil.Lc2SyntaxError(b,a,c,g)}next(){this.lastTokEnd=this.end,this.lastTokStart=this.start,this.nextToken()}nextToken(){return this.skipSpace(),this.start=this.pos,this.pos>=this.input.length?this.finishToken(_tokentype.types.eof):void this.readToken(this.fullCharCodeAtPos())}readToken(a){return(0,_identifier.isIdentifierStart)(a)?this.readWord():this.getTokenFromCode(a)}fullCharCodeAtPos(){const a=this.input.charCodeAt(this.pos);if(55295>=a||57344<=a)return a;const b=this.input.charCodeAt(this.pos+1);return(a<<10)+b-56613888}skipBlockComment(){let a=this.pos,b=this.input.indexOf('*/',this.pos+=2);-1===b&&this.raise(this.pos-2,'unterminated comment'),this.pos=b+2,this.options.onComment&&this.options.onComment(!0,this.input.slice(a+2,b),a,this.pos)}skipLineComment(a){let b=this.pos,c=this.input.charCodeAt(this.pos+=a);for(;this.pos<this.input.length&&10!==c&&13!==c&&8232!==c&&8233!==c;)++this.pos,c=this.input.charCodeAt(this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(b+=a,this.pos),b,this.pos)}skipSpace(){loop:for(;this.pos<this.input.length;){let a=this.input.charCodeAt(this.pos);switch(a){case 32:case 160:++this.pos;break;case 13:10===this.input.charCodeAt(this.pos+1)&&++this.pos;case 10:case 8232:case 8233:++this.pos;break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:}break;default:if(8<a&&14>a)++this.pos;else break loop;}}}readTokenSlash(){const a=this.input.charCodeAt(this.pos+1);return this.exprAllowed||this.genAllowed?(++this.pos,this.readRegexp(this.genAllowed)):61===a?this.finishOp(_tokentype.types.assign,2):62===a?this.finishOp(_tokentype.types.tagR,2):this.finishOp(_tokentype.types.slash,1)}readTokenMultModuloExp(a){const b=this.input.charCodeAt(this.pos+1),c=1,d=42===a?_tokentype.types.star:_tokentype.types.modulo;return 61===b?this.finishOp(_tokentype.types.assign,c+1):this.finishOp(d,c)}readTokenPipeAmp(a){const b=this.input.charCodeAt(this.pos+1);return b===a?this.finishOp(124===a?_tokentype.types.logicalOR:_tokentype.types.logicalAND,2):124===a?this.finishOp(_tokentype.types.pipe,1):void this.raise(this.pos,'bitwise operator is not allowed')}readTokenPlusMin(a){const b=this.input.charCodeAt(this.pos+1);return b===a?this.finishOp(_tokentype.types.incDec,2):61===b?this.finishOp(_tokentype.types.assign,2):this.finishOp(_tokentype.types.plusMin,1)}readTokenLtGt(a){const b=this.input.charCodeAt(this.pos+1);let c=1;if(b===a&&this.raise(this.pos,'bitwise operator is not allowed'),60===a){if(35===b)return this.finishOp(_tokentype.types.tagNumL,2);if(64===b)return this.finishOp(_tokentype.types.tagAtL,2);if(33===b)return this.finishOp(_tokentype.types.tagFacL,2)}return 61===b&&(c=2),this.finishOp(_tokentype.types.relational,c)}readTokenEqExcl(a){const b=this.input.charCodeAt(this.pos+1);return 126===b&&33===a?this.finishOp(_tokentype.types.match,2):61===b?this.finishOp(_tokentype.types.equality,61===this.input.charCodeAt(this.pos+2)?3:2):this.finishOp(61===a?_tokentype.types.eq:_tokentype.types.prefix,1)}getTokenFromCode(a){switch(a){case 35:return++this.pos,this.readMacro();case 40:return++this.pos,this.finishToken(_tokentype.types.parenL);case 41:return++this.pos,this.finishToken(_tokentype.types.parenR);case 59:return++this.pos,this.finishToken(_tokentype.types.semi);case 44:return++this.pos,this.finishToken(_tokentype.types.comma);case 91:return++this.pos,this.finishToken(_tokentype.types.bracketL);case 93:return++this.pos,this.finishToken(_tokentype.types.bracketR);case 123:return++this.pos,this.finishToken(_tokentype.types.braceL);case 125:return++this.pos,this.finishToken(_tokentype.types.braceR);case 58:return++this.pos,this.finishToken(_tokentype.types.colon);case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(a);case 47:return this.readTokenSlash();case 37:case 42:return this.readTokenMultModuloExp(a);case 124:case 38:return this.readTokenPipeAmp(a);case 43:case 45:return this.readTokenPlusMin(a);case 60:case 62:return this.readTokenLtGt(a);case 61:case 33:return this.readTokenEqExcl(a);case 126:var b=this.input.charCodeAt(this.pos+1);return 126!==b&&this.raise(this.pos,'bitwise operator is not allowed'),this.finishOp(_tokentype.types.match,2);default:this.raise(this.pos,'Unexpected character "'+this.input[this.pos]+'"');}}finishOp(a,b){const c=this.input.slice(this.pos,this.pos+=b);return this.finishToken(a,c)}finishToken(a,b){this.end=this.pos,this.type=a,this.value=b,this.genAllowed=a.beforeGen,this.exprAllowed=a.beforeExpr}readRegexp(a){let b,c,d=this.pos;for(;;){this.pos>=this.input.length&&this.raise(d,'Unterminated regular expression');let h=this.input.charAt(this.pos);if(_whitespace.lineBreak.test(h)&&this.raise(d,'Unterminated regular expression'),b)b=!1;else{if('['===h)c=!0;else if(']'===h&&c)c=!1;else if('/'===h&&!c)break;b='\\'===h}++this.pos}const f=this.input.slice(d,this.pos);++this.pos;const g=this.readWord1();if(g){let h=/^[gim]*$/;h.test(g)||this.raise(d,'Invalid regular expression flag')}return this.finishToken(_tokentype.types.regexp,{pattern:f,flags:g,isGenerate:a})}readInt(a,b=null){let c=this.pos,d=0;for(let f=0,g=null===b?1/0:b;f<g;++f){let j,h=this.fullCharCodeAtPos();if(j=97<=h?h-97+10:65<=h?h-65+10:48<=h&&57>=h?h-48:1/0,j>=a)break;++this.pos,d=d*a+j}return this.pos===c||null!==b&&this.pos-c!==b?null:d}readNumber(a){let b=this.pos,c=!1;a||null!==this.readInt(10)||this.raise(b,'Invalid Number');let d=this.fullCharCodeAtPos();46===d&&(++this.pos,this.readInt(10),c=!0,d=this.fullCharCodeAtPos()),(69===d||101===d)&&(d=this.input.charCodeAt(++this.pos),(43===d||45===d)&&++this.pos,null===this.readInt(10)&&this.raise(b,'Invalid number'),c=!0),(0,_identifier.isIdentifierStart)(this.fullCharCodeAtPos())&&this.raise(this.pos,'Identifier directly after number');let g,f=this.input.slice(b,this.pos);return g=c?parseFloat(f):parseInt(f,10),this.finishToken(_tokentype.types.num,g)}readString(a){let b='',c=this.start,d=++this.pos;for(;;){this.pos>=this.input.length&&this.raise(c,'Unterminated string');let f=this.fullCharCodeAtPos();if(f===a)break;92===f?(b+=this.input.slice(d,this.pos),b+=this.readEscapedChar(),d=this.pos):((0,_whitespace.isNewLine)(f)&&this.raise(c,'Unterminated string'),++this.pos)}return b+=this.input.slice(d,this.pos++),this.finishToken(_tokentype.types.string,b)}readEscapedChar(){const a=this.input.charCodeAt(++this.pos);switch(++this.pos,a){case 110:return'\n';case 114:return'\r';case 116:return'\t';case 98:return'\b';case 118:return'\x0B';case 102:return'\f';case 13:10===this.fullCharCodeAtPos()&&++this.pos;case 10:return'';default:return String.fromCharCode(a);}}readWord1(){let a='',b=this.pos;for(;this.pos<this.input.length;){let c=this.fullCharCodeAtPos();if((0,_identifier.isIdentifierChar)(c))++this.pos;else break}return a+=this.input.slice(b,this.pos),a}readWord(){const a=this.readWord1(),b=this.keywords.test(a)?_tokentype.keywordTypes[a]:_tokentype.types.name;return this.finishToken(b,a)}readMacro(){var a=this.pos,b=this.readWord1();this.macros.test(b)||this.raise(a,'invalid macros');for(var c=_tokentype.keywordTypes[b],d=this.pos,f=this.fullCharCodeAtPos();this.pos<this.input.length&&10!==f&&13!==f&&8232!==f&&8233!==f;)++this.pos,f=this.input.charCodeAt(this.pos);var g=this.input.slice(d,this.pos).trim();return this.finishToken(c,g)}parseTopLevel(a){let b=this.pcsTable;for(b.main={pos:0};this.type!==_tokentype.types.eof;)this.parseStructure();for(var c in b)b[c]&&this.raise(b[c].pos,'Invalid process call at');return a}parseStructure(){const a=this.type;return a.macro?this.parseSet():a===_tokentype.types._process?this.parseProcess():void this.raise(this.start,'Expect a macro or process')}parseSet(){const a=this.type;a.macro||this.unexpected();const b=a.label.toLowerCase();this.writeConfig(b),this.next()}writeConfig(a){let b;const c=this.conf;c[a]&&this.raise(this.start,this.type.keyword+' was defined already');let d,f,g=this.value.split(',');'screen'===a?(2!==g.length&&this.raise('Invalid arguments'),d=~~parseInt(g[0],10),f=~~parseInt(g[1],10),b={width:d,height:f}):'autoscroll'===a||'autocapture'===a||'autowait'===a?b=!0:b=parseInt(this.value,10);c[a]=b}parseProcess(){let a={LINE:(0,_locutil.getLineInfo)(this.input,this.start),TYPE:_ast2.default.PROCESS,BODY:{}},b=this.pcs,c=this.pcsTable;this.next();const d=this.parseIndent().name;b[d]&&this.raise(this.start,d+' process was defined already'),b[d]=a,c[d]=!1,this.parsePcParam(a),this.parsePcBlock(a)}parsePcParam(a){this.eat(_tokentype.types.parenL)&&(a.BODY.params=this.parseBindingList(_tokentype.types.parenR,!1,!1))}parsePcBlock(a){const b=this.parseBlock();b.push({LINE:-1,TYPE:_ast2.default.RETURN}),a.BODY.segment=b}parseBlock(){this.expect(_tokentype.types.braceL);const a=[];for(;!this.eat(_tokentype.types.braceR);){const b=this.parseStatement(!0);a.push(b)}return a}parseStatement(){let a=this.type,b=this.startNode();return a===_tokentype.types._click||a===_tokentype.types._rclick||a===_tokentype.types._dblclick||a===_tokentype.types._movein||a===_tokentype.types._moveout?this.parseMouseAction(b,a.keyword):a===_tokentype.types._select?this.parseSelectAction(b):a===_tokentype.types._scroll?this.parseScrollAction(b,a.keyword):a===_tokentype.types._input?this.parseInputAction(b,a.keyword):a===_tokentype.types._check||a===_tokentype.types._uncheck?this.parseCheck(b,a.keyword):a===_tokentype.types._return?this.parseReturnStatement(b):a===_tokentype.types._wait?this.parseWaitStatement(b):a===_tokentype.types._assert?this.parseAssertStatement(b):a===_tokentype.types._log||a===_tokentype.types._console?this.parseLogStatement(b,_ast2.default.LOG):a===_tokentype.types._jumpto?this.parseGotoStatement(b):a===_tokentype.types._refresh?this.parseRefreshStatement(b):a===_tokentype.types._var?this.parseVarStatement(b):a===_tokentype.types.name?this.parseExprStatement(b):a===_tokentype.types._if?this.parseIfStatement(b):a===_tokentype.types._while?this.parseWhileStatement(b):a===_tokentype.types.braceL?this.parseBlock():this.parseEvaluation(b)}parseReturnStatement(a){return this.next(),this.eat(_tokentype.types.semi),this.finishNode(a,_ast2.default.RETURN)}parseVarStatement(a){return this.next(),this.parseVar(a),this.semicolon(),this.finishNode(a,_ast2.default.EXPRESSION)}parseVar(a){const b=[];for(;;){let c={};if(c.id=this.parseIndent().name,c.init=this.eat(_tokentype.types.eq)?this.parseMaybeAssign():null,b.push(c),!this.eat(_tokentype.types.comma))break}a.BODY.raw={declarations:b,type:'varDecl'}}parseExprStatement(a){const b=this.parseExpression();if(this.semicolon(),'CallExpr'===b.type){var c=b.callee.name;return!1!==this.pcsTable[c]&&(this.pcsTable[c]={pos:this.lastTokStart}),a.BODY.identifier=c,this.finishNode(a,_ast2.default.CALL)}return a.BODY.raw=b,this.finishNode(a,_ast2.default.EXPRESSION)}parseEvaluation(a){const b=this.parseExpression();return this.semicolon(),a.BODY.raw=b,this.finishNode(a,_ast2.default.EXPRESSION)}parseWaitStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,_ast2.default.WAIT)}parseMouseAction(a,b){if(this.next(),a.BODY.raw=this.parseExpression(),a.BODY.action=b,this.eat(_tokentype.types._to)){let c,d;c=this.parseMaybeAssign(),this.expect(_tokentype.types.comma),d=this.parseMaybeAssign(),a.BODY.posX=c,a.BODY.posY=d}return this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseScrollAction(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action=b,this.finishNode(a,_ast2.default.TRIGGER)}parseSelectAction(a){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action='select',this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseInputAction(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action=b,this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseCheck(a,b){return this.next(),a.BODY.raw=this.parseExpression(),a.BODY.action=b,this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseAssertStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.eat(_tokentype.types._in)&&(this.type===_tokentype.types.num?a.BODY.timeout=this.value:this.unexpected(),this.next()),this.semicolon(),a.BODY.key=this.getUID('#'),this.keys[a.BODY.key]=!!a.BODY.timeout,this.finishNode(a,_ast2.default.ASSERT)}parseGotoStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,_ast2.default.JUMPTO)}parseRefreshStatement(a){return this.next(),this.semicolon(),this.finishNode(a,_ast2.default.REFRESH)}parseLogStatement(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,b)}parseIfStatement(a){return this.next(),a.test=this.parseExpression(),a.consequent=this.parseBlock(),a.alternate=this.eat(_tokentype.types._else)?this.parseStatement():null,this.finishNode(a,'If')}parseWhileStatement(a){return this.next(),a.test=this.parseExpression(),a.body=this.parseStatement(),this.finishNode(a,'While')}startNode(){return{LINE:(0,_locutil.getLineInfo)(this.input,this.start).line,TYPE:0,BODY:{},start:this.start,end:0}}finishNode(a,b){return a.TYPE=b,a.end=this.lastTokEnd,a}eat(a){return this.type===a&&(this.next(),!0)}semicolon(){this.eat(_tokentype.types.semi)||this.expected(_tokentype.types.semi)}expect(a){return this.eat(a)||this.expected(a)}unexpected(a=this.start){this.raise(a,'Unexpected token')}expected(a){this.raise(this.lastTokEnd,'Expect a "'+a.label+'" after')}getUID(a){return a+this.nextID++}parseExpression(){var a=this.parseMaybeAssign();if(this.type===_tokentype.types.comma){var b={type:'SequenceExpr'};for(b.expressions=[a];this.eat(_tokentype.types.comma);){var c=this.parseMaybeAssign();b.expressions.push(c)}return b}return a}parseMaybeAssign(){var a=this.parseMaybeConditional();if(this.type.isAssign){var b={type:'AssignmentExpr',left:a,operator:this.value};return this.next(),b.right=this.parseMaybeAssign(),b}return a}parseMaybeConditional(){return this.parseExprOps()}parseExprOps(){var a=this.start,b=this.parseMaybeUnary(!1);return this.parseExprOp(b,a,-1)}parseExprOp(a,b,c){var d=this.type.binop;if(null!==d&&d>c){var f=this.type,g=this.value;this.next();var h=this.start,j=this.parseExprOp(this.parseMaybeUnary(!1),h,d),k=this.buildBinary(a,j,g,f);return this.parseExprOp(k,b,c)}return a}buildBinary(a,b,c,d){var f={left:a,operator:c,right:b};return f.type=d===_tokentype.types.logicalAND||d===_tokentype.types.logicalOR?'LogicalExpr':d===_tokentype.types.match?'MatchExpr':'BinaryExpr',f}parseMaybeUnary(){let a;if(this.type.prefix){const b={},c=this.type===_tokentype.types.incDec;b.operator=this.value,b.prefix=!0,this.next(),b.argument=this.parseMaybeUnary(!1),b.type=c?'UpdateExpr':'UnaryExpr',a=b}else for(a=this.parseExprSubscripts();this.type.postfix;){let b={};b.operator=this.value,b.prefix=!1,b.argument=a,this.next(),b.type='UpdateExpr',a=b}return a}parseExprSubscripts(){var a=this.parseExprAtom();return this.parseSubscripts(a)}parseSubscripts(a){for(;;){if(this.eat(_tokentype.types.parenL)){let b={type:'CallExpr',callee:a};return this.expect(_tokentype.types.parenR),b}if(this.eat(_tokentype.types.pipe)){let b={type:'FilterExpr',object:a,filter:this.parseIndent().name};this.expect(_tokentype.types.parenL),b.params=this.parseExprList(_tokentype.types.parenR,!1,!1),a=b}else return a}}parseExprAtom(){let a;switch(this.type){case _tokentype.types.name:return this.parseIndent(this.type!==_tokentype.types.name);case _tokentype.types.regexp:var b=this.value;return a=this.parseLiteral('regexp'),a.regexp=b,a;case _tokentype.types.num:case _tokentype.types.string:return this.parseLiteral('literal',this.value);case _tokentype.types._true:case _tokentype.types._false:return this.parseLiteral('literal',this.value);case _tokentype.types.objectAt:case _tokentype.types.dict:return this.parseExtLiteral(this.type);case _tokentype.types.parenL:return this.parseParenExpression();case _tokentype.types.tagAtL:case _tokentype.types.tagNumL:case _tokentype.types.tagFacL:return this.parseTagExpression();default:return this.inTag?this.raise(this.lastTokStart,'(missing `/` before `>` ?) Unexpected token'):this.unexpected();}}parseLiteral(a,b){var c={type:a,value:b,raw:this.input.slice(this.start,this.end)};return this.next(),c}parseExtLiteral(a){var b={type:a.label,value:this.value};return this.next(),b}parseParenExpression(){this.expect(_tokentype.types.parenL);var a=this.parseExpression();return this.expect(_tokentype.types.parenR),{type:'ParenthesizedExpr',expression:a}}parseTagExpression(){var a={type:this.type.label};return this.inTag=!0,this.next(),a.val=this.parseExpression(),this.expect(_tokentype.types.tagR),this.inTag=!1,a}parseExprList(a,b){const c=[];for(let d=!0;!this.eat(a);)if(d?d=!1:this.expect(_tokentype.types.comma),b&&this.type===_tokentype.types.comma)c.push(null);else{var f=this.parseMaybeAssign();c.push(f)}return c}parseIndent(){var a;return this.type===_tokentype.types.name?a=this.value:this.unexpected(),this.next(),{type:'Identifier',name:a}}parseBindingList(a,b,c){const d=[];for(let f=!0;!this.eat(a);)if(f?f=!1:this.expect(_tokentype.types.comma),b&&this.type===_tokentype.types.comma)d.push(null);else if(c)break;else{var g=this.parseIndent();d.push(g)}return d}}exports.default=Parser; | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});exports.Parser=exports.pluginTable=void 0;var _options=require('./options'),_locutil=require('./locutil'),_tokentype=require('./tokentype'),_identifier=require('./identifier'),_whitespace=require('./whitespace'),_ast=require('./ast'),_ast2=_interopRequireDefault(_ast);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const pluginTable=exports.pluginTable={};class Parser{constructor(a,b){this.options=a=(0,_options.getOptions)(a),this.keywords=_identifier.keywordRegexp,this.macros=_identifier.macroRegexp,this.input=b+'',this.loadPlugins(a.pluginList),this.pos=0,this.type=_tokentype.types.eof,this.value=null,this.start=this.end=this.pos,this.lastTokStart=this.lastTokEnd=this.pos,this.exprAllowed=!1,this.genAllowed=!1,this.labels=[],this.conf={},this.keys={},this.nextID=0,this.pcs={},this.pcsTable={},this.inTag=!1}extend(a,b){this[a]=b(this[a])}loadPlugins(a){a.forEach(b=>{const c=pluginTable[b];if(!c)throw new Error('Plugin ['+b+'] not found');c(this,b)})}parse(){this.nextToken();let a={CONFIG:this.conf,DATA_KEYS:this.keys,PROCESSES:this.pcs};return this.parseTopLevel(a)}raise(a,b){const c=(0,_locutil.getLineInfo)(this.input,a);b+=' ('+c.line+':'+c.column+')';const d=this.options.left,f=this.options.right;b=d||f?d+b+f:(0,_locutil.empowerErrMsg)(this.input,c,b);const g=this.pos;throw new _locutil.Lc2SyntaxError(b,a,c,g)}next(){this.lastTokEnd=this.end,this.lastTokStart=this.start,this.nextToken()}nextToken(){return this.skipSpace(),this.start=this.pos,this.pos>=this.input.length?this.finishToken(_tokentype.types.eof):void this.readToken(this.fullCharCodeAtPos())}readToken(a){return(0,_identifier.isIdentifierStart)(a)?this.readWord():this.getTokenFromCode(a)}fullCharCodeAtPos(){const a=this.input.charCodeAt(this.pos);if(55295>=a||57344<=a)return a;const b=this.input.charCodeAt(this.pos+1);return(a<<10)+b-56613888}skipBlockComment(){let a=this.pos,b=this.input.indexOf('*/',this.pos+=2);-1===b&&this.raise(this.pos-2,'unterminated comment'),this.pos=b+2,this.options.onComment&&this.options.onComment(!0,this.input.slice(a+2,b),a,this.pos)}skipLineComment(a){let b=this.pos,c=this.input.charCodeAt(this.pos+=a);for(;this.pos<this.input.length&&10!==c&&13!==c&&8232!==c&&8233!==c;)++this.pos,c=this.input.charCodeAt(this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(b+=a,this.pos),b,this.pos)}skipSpace(){loop:for(;this.pos<this.input.length;){let a=this.input.charCodeAt(this.pos);switch(a){case 32:case 160:++this.pos;break;case 13:10===this.input.charCodeAt(this.pos+1)&&++this.pos;case 10:case 8232:case 8233:++this.pos;break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:}break;default:if(8<a&&14>a)++this.pos;else break loop;}}}readTokenSlash(){const a=this.input.charCodeAt(this.pos+1);return this.exprAllowed||this.genAllowed?(++this.pos,this.readRegexp(this.genAllowed)):61===a?this.finishOp(_tokentype.types.assign,2):62===a?this.finishOp(_tokentype.types.tagR,2):this.finishOp(_tokentype.types.slash,1)}readTokenMultModuloExp(a){const b=this.input.charCodeAt(this.pos+1),c=1,d=42===a?_tokentype.types.star:_tokentype.types.modulo;return 61===b?this.finishOp(_tokentype.types.assign,c+1):this.finishOp(d,c)}readTokenPipeAmp(a){const b=this.input.charCodeAt(this.pos+1);return b===a?this.finishOp(124===a?_tokentype.types.logicalOR:_tokentype.types.logicalAND,2):124===a?this.finishOp(_tokentype.types.pipe,1):void this.raise(this.pos,'bitwise operator is not allowed')}readTokenPlusMin(a){const b=this.input.charCodeAt(this.pos+1);return b===a?this.finishOp(_tokentype.types.incDec,2):61===b?this.finishOp(_tokentype.types.assign,2):this.finishOp(_tokentype.types.plusMin,1)}readTokenLtGt(a){const b=this.input.charCodeAt(this.pos+1);let c=1;if(b===a&&this.raise(this.pos,'bitwise operator is not allowed'),60===a){if(35===b)return this.finishOp(_tokentype.types.tagNumL,2);if(64===b)return this.finishOp(_tokentype.types.tagAtL,2);if(33===b)return this.finishOp(_tokentype.types.tagFacL,2)}return 61===b&&(c=2),this.finishOp(_tokentype.types.relational,c)}readTokenEqExcl(a){const b=this.input.charCodeAt(this.pos+1);return 126===b&&33===a?this.finishOp(_tokentype.types.match,2):61===b?this.finishOp(_tokentype.types.equality,61===this.input.charCodeAt(this.pos+2)?3:2):this.finishOp(61===a?_tokentype.types.eq:_tokentype.types.prefix,1)}getTokenFromCode(a){switch(a){case 35:return++this.pos,this.readMacro();case 40:return++this.pos,this.finishToken(_tokentype.types.parenL);case 41:return++this.pos,this.finishToken(_tokentype.types.parenR);case 59:return++this.pos,this.finishToken(_tokentype.types.semi);case 44:return++this.pos,this.finishToken(_tokentype.types.comma);case 91:return++this.pos,this.finishToken(_tokentype.types.bracketL);case 93:return++this.pos,this.finishToken(_tokentype.types.bracketR);case 123:return++this.pos,this.finishToken(_tokentype.types.braceL);case 125:return++this.pos,this.finishToken(_tokentype.types.braceR);case 58:return++this.pos,this.finishToken(_tokentype.types.colon);case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(a);case 47:return this.readTokenSlash();case 37:case 42:return this.readTokenMultModuloExp(a);case 124:case 38:return this.readTokenPipeAmp(a);case 43:case 45:return this.readTokenPlusMin(a);case 60:case 62:return this.readTokenLtGt(a);case 61:case 33:return this.readTokenEqExcl(a);case 126:var b=this.input.charCodeAt(this.pos+1);return 126!==b&&this.raise(this.pos,'bitwise operator is not allowed'),this.finishOp(_tokentype.types.match,2);default:this.raise(this.pos,'Unexpected character "'+this.input[this.pos]+'"');}}finishOp(a,b){const c=this.input.slice(this.pos,this.pos+=b);return this.finishToken(a,c)}finishToken(a,b){this.end=this.pos,this.type=a,this.value=b,this.genAllowed=a.beforeGen,this.exprAllowed=a.beforeExpr}readRegexp(a){let b,c,d=this.pos;for(;;){this.pos>=this.input.length&&this.raise(d,'Unterminated regular expression');let h=this.input.charAt(this.pos);if(_whitespace.lineBreak.test(h)&&this.raise(d,'Unterminated regular expression'),b)b=!1;else{if('['===h)c=!0;else if(']'===h&&c)c=!1;else if('/'===h&&!c)break;b='\\'===h}++this.pos}const f=this.input.slice(d,this.pos);++this.pos;const g=this.readWord1();if(g){let h=/^[gim]*$/;h.test(g)||this.raise(d,'Invalid regular expression flag')}return this.finishToken(_tokentype.types.regexp,{pattern:f,flags:g,isGenerate:a})}readInt(a,b=null){let c=this.pos,d=0;for(let f=0,g=null===b?1/0:b;f<g;++f){let j,h=this.fullCharCodeAtPos();if(j=97<=h?h-97+10:65<=h?h-65+10:48<=h&&57>=h?h-48:1/0,j>=a)break;++this.pos,d=d*a+j}return this.pos===c||null!==b&&this.pos-c!==b?null:d}readNumber(a){let b=this.pos,c=!1;a||null!==this.readInt(10)||this.raise(b,'Invalid Number');let d=this.fullCharCodeAtPos();46===d&&(++this.pos,this.readInt(10),c=!0,d=this.fullCharCodeAtPos()),(69===d||101===d)&&(d=this.input.charCodeAt(++this.pos),(43===d||45===d)&&++this.pos,null===this.readInt(10)&&this.raise(b,'Invalid number'),c=!0),(0,_identifier.isIdentifierStart)(this.fullCharCodeAtPos())&&this.raise(this.pos,'Identifier directly after number');let g,f=this.input.slice(b,this.pos);return g=c?parseFloat(f):parseInt(f,10),this.finishToken(_tokentype.types.num,g)}readString(a){let b='',c=this.start,d=++this.pos;for(;;){this.pos>=this.input.length&&this.raise(c,'Unterminated string');let f=this.fullCharCodeAtPos();if(f===a)break;92===f?(b+=this.input.slice(d,this.pos),b+=this.readEscapedChar(),d=this.pos):((0,_whitespace.isNewLine)(f)&&this.raise(c,'Unterminated string'),++this.pos)}return b+=this.input.slice(d,this.pos++),this.finishToken(_tokentype.types.string,b)}readEscapedChar(){const a=this.input.charCodeAt(++this.pos);switch(++this.pos,a){case 110:return'\n';case 114:return'\r';case 116:return'\t';case 98:return'\b';case 118:return'\x0B';case 102:return'\f';case 13:10===this.fullCharCodeAtPos()&&++this.pos;case 10:return'';default:return String.fromCharCode(a);}}readWord1(){let a='',b=this.pos;for(;this.pos<this.input.length;){let c=this.fullCharCodeAtPos();if((0,_identifier.isIdentifierChar)(c))++this.pos;else break}return a+=this.input.slice(b,this.pos),a}readWord(){const a=this.readWord1(),b=this.keywords.test(a)?_tokentype.keywordTypes[a]:_tokentype.types.name;return this.finishToken(b,a)}readMacro(){var a=this.pos,b=this.readWord1();this.macros.test(b)||this.raise(a,'invalid macros');for(var c=_tokentype.keywordTypes[b],d=this.pos,f=this.fullCharCodeAtPos();this.pos<this.input.length&&10!==f&&13!==f&&8232!==f&&8233!==f;)++this.pos,f=this.input.charCodeAt(this.pos);var g=this.input.slice(d,this.pos).trim();return this.finishToken(c,g)}parseTopLevel(a){let b=this.pcsTable;for(b.main={pos:0};this.type!==_tokentype.types.eof;)this.parseStructure();for(var c in b)b[c]&&this.raise(b[c].pos,'Invalid process call at');return a}parseStructure(){const a=this.type;return a.macro?this.parseSet():a===_tokentype.types._process?this.parseProcess():void this.raise(this.start,'Expect a macro or process')}parseSet(){const a=this.type;a.macro||this.unexpected();const b=a.label.toLowerCase();this.writeConfig(b),this.next()}writeConfig(a){let b;const c=this.conf;c[a]&&this.raise(this.start,this.type.keyword+' was defined already');let d,f,g=this.value.split(',');'screen'===a?(2!==g.length&&this.raise('Invalid arguments'),d=~~parseInt(g[0],10),f=~~parseInt(g[1],10),b={width:d,height:f}):'autoscroll'===a||'autocapture'===a||'autowait'===a?b=!0:b=parseInt(this.value,10);c[a]=b}parseProcess(){let a={LINE:(0,_locutil.getLineInfo)(this.input,this.start),TYPE:_ast2.default.PROCESS,BODY:{}},b=this.pcs,c=this.pcsTable;this.next();const d=this.parseIndent().name;b[d]&&this.raise(this.start,d+' process was defined already'),b[d]=a,c[d]=!1,this.parsePcParam(a),this.parsePcBlock(a)}parsePcParam(a){this.eat(_tokentype.types.parenL)&&(a.BODY.params=this.parseBindingList(_tokentype.types.parenR,!1,!1))}parsePcBlock(a){const b=this.parseBlock();b.push({LINE:-1,TYPE:_ast2.default.RETURN}),a.BODY.segment=b}parseBlock(){this.expect(_tokentype.types.braceL);const a=[];for(;!this.eat(_tokentype.types.braceR);){const b=this.parseStatement(!0);a.push(b)}return a}parseStatement(){let a=this.type,b=this.startNode();return a===_tokentype.types._click||a===_tokentype.types._rclick||a===_tokentype.types._dblclick||a===_tokentype.types._movein||a===_tokentype.types._moveout?this.parseMouseAction(b,a.keyword):a===_tokentype.types._select?this.parseSelectAction(b):a===_tokentype.types._scroll?this.parseScrollAction(b,a.keyword):a===_tokentype.types._input?this.parseInputAction(b,a.keyword):a===_tokentype.types._check||a===_tokentype.types._uncheck?this.parseCheck(b,a.keyword):a===_tokentype.types._return?this.parseReturnStatement(b):a===_tokentype.types._wait?this.parseWaitStatement(b):a===_tokentype.types._assert?this.parseAssertStatement(b):a===_tokentype.types._log||a===_tokentype.types._console?this.parseLogStatement(b,_ast2.default.LOG):a===_tokentype.types._jumpto?this.parseGotoStatement(b):a===_tokentype.types._refresh?this.parseRefreshStatement(b):a===_tokentype.types.name?this.parseExprStatement(b):a===_tokentype.types._if?this.parseIfStatement(b):a===_tokentype.types._while?this.parseWhileStatement(b):a===_tokentype.types.braceL?this.parseBlock():this.parseEvaluation(b)}parseReturnStatement(a){return this.next(),this.eat(_tokentype.types.semi),this.finishNode(a,_ast2.default.RETURN)}parseVarStatement(a){return this.next(),this.parseVar(a),this.semicolon(),this.finishNode(a,_ast2.default.EXPRESSION)}parseVar(a){const b=[];for(;;){let c={};if(c.id=this.parseIndent().name,c.init=this.eat(_tokentype.types.eq)?this.parseMaybeAssign():null,b.push(c),!this.eat(_tokentype.types.comma))break}a.BODY.raw={declarations:b,type:'varDecl'}}parseExprStatement(a){const b=this.parseExpression();if(this.semicolon(),'CallExpr'===b.type){var c=b.callee.name;return!1!==this.pcsTable[c]&&(this.pcsTable[c]={pos:this.lastTokStart}),a.BODY.identifier=c,this.finishNode(a,_ast2.default.CALL)}return a.BODY.raw=b,this.finishNode(a,_ast2.default.EXPRESSION)}parseEvaluation(a){const b=this.parseExpression();return this.semicolon(),a.BODY.raw=b,this.finishNode(a,_ast2.default.EXPRESSION)}parseWaitStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,_ast2.default.WAIT)}parseMouseAction(a,b){if(this.next(),a.BODY.raw=this.parseExpression(),a.BODY.action=b,this.eat(_tokentype.types._to)){let c,d;c=this.parseMaybeAssign(),this.expect(_tokentype.types.comma),d=this.parseMaybeAssign(),a.BODY.posX=c,a.BODY.posY=d}return this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseScrollAction(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action=b,this.finishNode(a,_ast2.default.TRIGGER)}parseSelectAction(a){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action='select',this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseInputAction(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.expect(_tokentype.types._by),a.BODY.raw1=this.parseExpression(),a.BODY.action=b,this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseCheck(a,b){return this.next(),a.BODY.raw=this.parseExpression(),a.BODY.action=b,this.semicolon(),this.finishNode(a,_ast2.default.TRIGGER)}parseAssertStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.eat(_tokentype.types._in)&&(this.type===_tokentype.types.num?a.BODY.timeout=this.value:this.unexpected(),this.next()),this.semicolon(),a.BODY.key=this.getUID('#'),this.keys[a.BODY.key]=!!a.BODY.timeout,this.finishNode(a,_ast2.default.ASSERT)}parseGotoStatement(a){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,_ast2.default.JUMPTO)}parseRefreshStatement(a){return this.next(),this.semicolon(),this.finishNode(a,_ast2.default.REFRESH)}parseLogStatement(a,b){return this.next(),a.BODY.raw=this.parseExpression(),this.semicolon(),this.finishNode(a,b)}parseIfStatement(a){return this.next(),a.test=this.parseExpression(),a.consequent=this.parseBlock(),a.alternate=this.eat(_tokentype.types._else)?this.parseStatement():null,this.finishNode(a,'If')}parseWhileStatement(a){return this.next(),a.test=this.parseExpression(),a.body=this.parseStatement(),this.finishNode(a,'While')}startNode(){return{LINE:(0,_locutil.getLineInfo)(this.input,this.start).line,TYPE:0,BODY:{},start:this.start,end:0}}finishNode(a,b){return a.TYPE=b,a.end=this.lastTokEnd,a}eat(a){return this.type===a&&(this.next(),!0)}semicolon(){this.eat(_tokentype.types.semi)||this.expected(_tokentype.types.semi)}expect(a){return this.eat(a)||this.expected(a)}unexpected(a=this.start){this.raise(a,'Unexpected token')}expected(a){this.raise(this.lastTokEnd,'Expect a "'+a.label+'" after')}getUID(a){return a+this.nextID++}parseExpression(){var a=this.parseMaybeAssign();if(this.type===_tokentype.types.comma){var b={type:'SequenceExpr'};for(b.expressions=[a];this.eat(_tokentype.types.comma);){var c=this.parseMaybeAssign();b.expressions.push(c)}return b}return a}parseMaybeAssign(){var a=this.parseMaybeConditional();if(this.type.isAssign){var b={type:'AssignmentExpr',left:a,operator:this.value};return this.next(),b.right=this.parseMaybeAssign(),b}return a}parseMaybeConditional(){return this.parseExprOps()}parseExprOps(){var a=this.start,b=this.parseMaybeUnary(!1);return this.parseExprOp(b,a,-1)}parseExprOp(a,b,c){var d=this.type.binop;if(null!==d&&d>c){var f=this.type,g=this.value;this.next();var h=this.start,j=this.parseExprOp(this.parseMaybeUnary(!1),h,d),k=this.buildBinary(a,j,g,f);return this.parseExprOp(k,b,c)}return a}buildBinary(a,b,c,d){var f={left:a,operator:c,right:b};return f.type=d===_tokentype.types.logicalAND||d===_tokentype.types.logicalOR?'LogicalExpr':d===_tokentype.types.match?'MatchExpr':'BinaryExpr',f}parseMaybeUnary(){let a;if(this.type.prefix){const b={},c=this.type===_tokentype.types.incDec;b.operator=this.value,b.prefix=!0,this.next(),b.argument=this.parseMaybeUnary(!1),b.type=c?'UpdateExpr':'UnaryExpr',a=b}else for(a=this.parseExprSubscripts();this.type.postfix;){let b={};b.operator=this.value,b.prefix=!1,b.argument=a,this.next(),b.type='UpdateExpr',a=b}return a}parseExprSubscripts(){var a=this.parseExprAtom();return this.parseSubscripts(a)}parseSubscripts(a){for(;;){if(this.eat(_tokentype.types.parenL)){let b={type:'CallExpr',callee:a};return this.expect(_tokentype.types.parenR),b}if(this.eat(_tokentype.types.pipe)){let b={type:'FilterExpr',object:a,filter:this.parseIndent().name};this.expect(_tokentype.types.parenL),b.params=this.parseExprList(_tokentype.types.parenR,!1,!1),a=b}else return a}}parseExprAtom(){let a;switch(this.type){case _tokentype.types.name:return this.parseIndent(this.type!==_tokentype.types.name);case _tokentype.types.regexp:var b=this.value;return a=this.parseLiteral('regexp'),a.regexp=b,a;case _tokentype.types.num:case _tokentype.types.string:return this.parseLiteral('literal',this.value);case _tokentype.types._true:case _tokentype.types._false:return this.parseLiteral('literal',this.value);case _tokentype.types.objectAt:case _tokentype.types.dict:return this.parseExtLiteral(this.type);case _tokentype.types.parenL:return this.parseParenExpression();case _tokentype.types.tagAtL:case _tokentype.types.tagNumL:case _tokentype.types.tagFacL:return this.parseTagExpression();default:return this.inTag?this.raise(this.lastTokStart,'(missing `/` before `>` ?) Unexpected token'):this.unexpected();}}parseLiteral(a,b){var c={type:a,value:b,raw:this.input.slice(this.start,this.end)};return this.next(),c}parseExtLiteral(a){var b={type:a.label,value:this.value};return this.next(),b}parseParenExpression(){this.expect(_tokentype.types.parenL);var a=this.parseExpression();return this.expect(_tokentype.types.parenR),{type:'ParenthesizedExpr',expression:a}}parseTagExpression(){var a={type:this.type.label};return this.inTag=!0,this.next(),a.val=this.parseExpression(),this.expect(_tokentype.types.tagR),this.inTag=!1,a}parseExprList(a,b){const c=[];for(let d=!0;!this.eat(a);)if(d?d=!1:this.expect(_tokentype.types.comma),b&&this.type===_tokentype.types.comma)c.push(null);else{var f=this.parseMaybeAssign();c.push(f)}return c}parseIndent(){var a;return this.type===_tokentype.types.name?a=this.value:this.unexpected(),this.next(),{type:'Identifier',name:a}}parseBindingList(a,b,c){const d=[];for(let f=!0;!this.eat(a);)if(f?f=!1:this.expect(_tokentype.types.comma),b&&this.type===_tokentype.types.comma)d.push(null);else if(c)break;else{var g=this.parseIndent();d.push(g)}return d}}exports.Parser=Parser; | ||
@@ -18,3 +18,3 @@ },{"./ast":2,"./identifier":3,"./locutil":5,"./options":6,"./tokentype":7,"./whitespace":8}],5:[function(require,module,exports){ | ||
},{"./whitespace":8}],6:[function(require,module,exports){ | ||
'use strict';const defaultOptions={insertReturn:!0,onComment:function(){},left:'',right:'',plugins:{}};function getOptions(a={}){return Object.assign({},defaultOptions,a)}module.exports={defaultOptions:defaultOptions,getOptions:getOptions}; | ||
'use strict';const defaultOptions={insertReturn:!0,onComment:function(){},left:'',right:'',pluginList:[]};function getOptions(a={}){return Object.assign({},defaultOptions,a)}module.exports={defaultOptions:defaultOptions,getOptions:getOptions}; | ||
@@ -21,0 +21,0 @@ },{}],7:[function(require,module,exports){ |
@@ -6,2 +6,10 @@ export namespace lc2 { | ||
export function parseAt(input: string, options?: Object): Object; | ||
// returns the tokenizer | ||
export function tokenizer(input: string, options?: Object): Object; | ||
// plugins | ||
export const plugins: Object; | ||
// token types | ||
export const types: Object; | ||
// keyword regexp | ||
export const keywordRegexp: RegExp; | ||
} |
@@ -1,4 +0,6 @@ | ||
import Parser from './lib'; | ||
import {Parser, pluginTable} from './lib'; | ||
export {types} from './lib/tokentype'; | ||
export {keywordRegexp} from './lib/identifier'; | ||
export const plugins = pluginTable; | ||
export function parse(input, options) { | ||
@@ -16,1 +18,2 @@ return new Parser(options, input).parse(); | ||
} | ||
export const parseAt = parseFragment; |
@@ -10,5 +10,7 @@ import {getOptions} from './options'; | ||
export default class Parser { | ||
export const pluginTable = {}; | ||
export class Parser { | ||
constructor(options, input) { | ||
this.options = getOptions(options); | ||
this.options = options = getOptions(options); | ||
this.keywords = keywordRegexp; | ||
@@ -18,2 +20,4 @@ this.macros = macroRegexp; | ||
this.loadPlugins(options.pluginList); | ||
this.pos = 0; | ||
@@ -45,2 +49,17 @@ | ||
extend(name, fn) { | ||
this[name] = fn(this[name]); | ||
} | ||
loadPlugins(pluginList) { | ||
pluginList.forEach(pluginName => { | ||
const plugin = pluginTable[pluginName]; | ||
if (!plugin) { | ||
throw new Error('Plugin [' + pluginName + '] not found'); | ||
} | ||
plugin(this, pluginName); | ||
}); | ||
} | ||
parse() { | ||
@@ -186,3 +205,3 @@ this.nextToken(); | ||
} | ||
/* eslint-enable no-labels */ | ||
readTokenSlash() { | ||
@@ -739,4 +758,2 @@ const next = this.input.charCodeAt(this.pos + 1); | ||
return this.parseRefreshStatement(node); | ||
case tt._var: | ||
return this.parseVarStatement(node); | ||
case tt.name: | ||
@@ -743,0 +760,0 @@ return this.parseExprStatement(node); |
@@ -6,3 +6,3 @@ const defaultOptions = { | ||
right: '', | ||
plugins: {} | ||
pluginList: [] | ||
}; | ||
@@ -9,0 +9,0 @@ |
{ | ||
"name": "lc2-compiler", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "lemoncase2 parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
169679
20
1621