vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
inform.lua
(4149B)
1 -- Copyright 2010-2025 Jeff Stone. See LICENSE.
2 -- Inform 6 LPeg lexer for Scintillua.
3 -- JMS 2010-04-25.
4
5 local lexer = require('lexer')
6 local token, word_match = lexer.token, lexer.word_match
7 local P, S = lpeg.P, lpeg.S
8
9 local lex = lexer.new('inform')
10
11 -- Whitespace.
12 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
13
14 -- Keywords.
15 lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
16 'Abbreviate', 'Array', 'Attribute', 'Class', 'Constant', 'Default', 'End', 'Endif', 'Extend',
17 'Global', 'Ifdef', 'Iffalse', 'Ifndef', 'Ifnot', 'Iftrue', 'Import', 'Include', 'Link',
18 'Lowstring', 'Message', 'Object', 'Property', 'Release', 'Replace', 'Serial', 'StartDaemon',
19 'Statusline', 'StopDaemon', 'Switches', 'Verb', --
20 'absent', 'action', 'actor', 'add_to_scope', 'address', 'additive', 'after', 'and', 'animate',
21 'article', 'articles', 'before', 'bold', 'box', 'break', 'cant_go', 'capacity', 'char', 'class',
22 'child', 'children', 'clothing', 'concealed', 'container', 'continue', 'creature', 'daemon',
23 'deadflag', 'default', 'describe', 'description', 'do', 'door', 'door_dir', 'door_to', 'd_to',
24 'd_obj', 'e_to', 'e_obj', 'each_turn', 'edible', 'else', 'enterable', 'false', 'female', 'first',
25 'font', 'for', 'found_in', 'general', 'give', 'grammar', 'has', 'hasnt', 'held', 'if', 'in',
26 'in_to', 'in_obj', 'initial', 'inside_description', 'invent', 'jump', 'last', 'life', 'light',
27 'list_together', 'location', 'lockable', 'locked', 'male', 'move', 'moved', 'multi',
28 'multiexcept', 'multiheld', 'multiinside', 'n_to', 'n_obj', 'ne_to', 'ne_obj', 'nw_to', 'nw_obj',
29 'name', 'neuter', 'new_line', 'nothing', 'notin', 'noun', 'number', 'objectloop', 'ofclass',
30 'off', 'on', 'only', 'open', 'openable', 'or', 'orders', 'out_to', 'out_obj', 'parent',
31 'parse_name', 'player', 'plural', 'pluralname', 'print', 'print_ret', 'private', 'proper',
32 'provides', 'random', 'react_after', 'react_before', 'remove', 'replace', 'return', 'reverse',
33 'rfalseroman', 'rtrue', 's_to', 's_obj', 'se_to', 'se_obj', 'sw_to', 'sw_obj', 'scenery', 'scope',
34 'score', 'scored', 'second', 'self', 'short_name', 'short_name_indef', 'sibling', 'spaces',
35 'static', 'string', 'style', 'supporter', 'switch', 'switchable', 'talkable', 'thedark',
36 'time_left', 'time_out', 'to', 'topic', 'transparent', 'true', 'underline', 'u_to', 'u_obj',
37 'visited', 'w_to', 'w_obj', 'when_closed', 'when_off', 'when_on', 'when_open', 'while', 'with',
38 'with_key', 'workflag', 'worn'
39 }))
40
41 -- Library actions.
42 lex:add_rule('action', token(lexer.FUNCTION_BUILTIN, word_match{
43 'Answer', 'Ask', 'AskFor', 'Attack', 'Blow', 'Burn', 'Buy', 'Climb', 'Close', 'Consult', 'Cut',
44 'Dig', 'Disrobe', 'Drink', 'Drop', 'Eat', 'Empty', 'EmptyT', 'Enter', 'Examine', 'Exit', 'Fill',
45 'FullScore', 'GetOff', 'Give', 'Go', 'GoIn', 'Insert', 'Inv', 'InvTall', 'InvWide', 'Jump',
46 'JumpOver', 'Kiss', 'LetGo', 'Listen', 'LMode1', 'LMode2', 'LMode3', 'Lock', 'Look', 'LookUnder',
47 'Mild', 'No', 'NotifyOff', 'NotifyOn', 'Objects', 'Open', 'Order', 'Places', 'Pray', 'Pronouns',
48 'Pull', 'Push', 'PushDir', 'PutOn', 'Quit', 'Receive', 'Remove', 'Restart', 'Restore', 'Rub',
49 'Save', 'Score', 'ScriptOff', 'ScriptOn', 'Search', 'Set', 'SetTo', 'Show', 'Sing', 'Sleep',
50 'Smell', 'Sorry', 'Squeeze', 'Strong', 'Swim', 'Swing', 'SwitchOff', 'SwitchOn', 'Take', 'Taste',
51 'Tell', 'Think', 'ThrowAt', 'ThrownAt', 'Tie', 'Touch', 'Transfer', 'Turn', 'Unlock', 'VagueGo',
52 'Verify', 'Version', 'Wait', 'Wake', 'WakeOther', 'Wave', 'WaveHands', 'Wear', 'Yes'
53 }))
54
55 -- Identifiers.
56 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
57
58 -- Strings.
59 local sq_str = lexer.range("'")
60 local dq_str = lexer.range('"')
61 lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
62
63 -- Comments.
64 lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('!')))
65
66 -- Numbers.
67 local inform_hex = '$' * lexer.xdigit^1
68 local inform_bin = '$$' * S('01')^1
69 lex:add_rule('number', token(lexer.NUMBER, lexer.integer + inform_hex + inform_bin))
70
71 -- Operators.
72 lex:add_rule('operator', token(lexer.OPERATOR, S('@~=+-*/%^#=<>;:,.{}[]()&|?')))
73
74 lexer.property['scintillua.comment'] = '!'
75
76 return lex