UNPKG

lua_to_cpls

Version:

A tool capable of compiling a subset of Lua to Please lang compiled files

53 lines (51 loc) 1.28 kB
const {makeLexer, moo} = require('moo-ignore'); const lexer = makeLexer({ whitespace: {match: /\s+|--.*/, lineBreaks: true}, identifier: {match: /[_a-zA-Z]\w*/, type: moo.keywords( [ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while' ].reduce((keywords, s) => { keywords['keywords_' + s] = s; return keywords; }, {}), )}, string: {match: /'(?:[^'\\]|\\.)*?'|"(?:[^"\\]|\\.)*?"/, value: string => JSON.parse(string)}, number: {match: /[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/, value: num => Number(num)}, plus: '+', minus: '-', star: '*', slash: '/', modulo: '%', power: '^', comparison: '==', equal: '=', greaterEqual: '>=', tildeEqual: '~=', lesserEqual: '<=', greater: '>', lesser: '<', leftParenthesis: '(', rightParenthesis: ')', leftBrace: '{', rightBrace: '}', leftBracket: '[', rightBracket: ']', semicolon: ';', dobleColon: '::', colon: ':', comma: ',', hash: '#', ampersand: '&', tilde: '~', or: '|', leftShift: '<<', rightShift: '>>', doubleSlash: '//', spread: '...', doubleDot: '..', dot: '.', }); module.exports = {lexer};