Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.exists('lex') then
- shell.run('pastebin get edyuQ5xY lex')
- end
- local lexSuccess = os.loadAPI('lex')
- if not lexSuccess or not lex or not lex.lex then
- print('A valid lexer is required (file `lex` seems to be broken or not a lexer)')
- return
- end
- local input = dofile('input')
- local lex = dofile('lex')
- local apis = {
- -- tables
- bit = true,
- bit32 = true,
- bitop = true,
- colors = true,
- colours = true,
- coroutine = true,
- disk = true,
- fs = true,
- gps = true,
- help = true,
- http = true,
- io = true,
- keys = true,
- math = true,
- os = true,
- paintutils = true,
- parallel = true,
- peripheral = true,
- rednet = true,
- redstone = true,
- rs = true,
- settings = true,
- shell = true,
- socket = true,
- string = true,
- table = true,
- term = true,
- textutils = true,
- vector = true,
- window = true,
- -- functions
- assert = true,
- collectgarbage = true,
- dofile = true,
- error = true,
- getfenv = true,
- getmetatable = true,
- ipairs = true,
- loadfile = true,
- loadstring = true,
- module = true,
- next = true,
- pairs = true,
- pcall = true,
- print = true,
- rawequal = true,
- rawget = true,
- rawset = true,
- require = true,
- select = true,
- setfenv = true,
- setmetatable = true,
- tonumber = true,
- tostring = true,
- type = true,
- unpack = true,
- xpcall = true,
- printError = true,
- write = true
- }
- input(nil, nil, nil, nil, nil, nil, nil, function(_sLine, _nPos, _nScroll, _bLast, _sCompletion)
- -- _sLine, _nPos, _nScroll, _bLast, _sCompletion
- local fg = ''
- local bg = ''
- local tokens = lex(_sLine)[1]
- if #tokens > 0 then
- for t = 1, #tokens do
- local color = '0'
- local token = tokens[t]
- if token.type == 'keyword' or token.type == 'operator' then
- color = '4' -- yellow
- elseif token.type == 'number' or token.type == 'value' or token.type == 'escape' then
- color = 'a' -- purple
- elseif token.type == 'comment' then
- color = 'd' -- green
- elseif token.type == 'ident' and apis[token.data] then
- color = '8' -- lightGray
- elseif token.type == 'string' then
- color = '9' -- cyan
- elseif token.type == 'unidentified' then
- color = 'e' -- red
- end
- for i = 1, #token.data do
- fg = fg .. color
- bg = bg .. 'f'
- end
- end
- end
- for i = 1, #_sCompletion do
- fg = fg .. 'f'
- bg = bg .. '7'
- end
- return fg, bg
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement