logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

inform.lua (4182B)


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