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

pascal.lua (2756B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Pascal LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('pascal')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
  11. 'and', 'array', 'as', 'at', 'asm', 'begin', 'case', 'class', 'const', 'constructor', 'destructor',
  12. 'dispinterface', 'div', 'do', 'downto', 'else', 'end', 'except', 'exports', 'file', 'final',
  13. 'finalization', 'finally', 'for', 'function', 'goto', 'if', 'implementation', 'in', 'inherited',
  14. 'initialization', 'inline', 'interface', 'is', 'label', 'mod', 'not', 'object', 'of', 'on', 'or',
  15. 'out', 'packed', 'procedure', 'program', 'property', 'raise', 'record', 'repeat',
  16. 'resourcestring', 'set', 'sealed', 'shl', 'shr', 'static', 'string', 'then', 'threadvar', 'to',
  17. 'try', 'type', 'unit', 'unsafe', 'until', 'uses', 'var', 'while', 'with', 'xor', 'absolute',
  18. 'abstract', 'assembler', 'automated', 'cdecl', 'contains', 'default', 'deprecated', 'dispid',
  19. 'dynamic', 'export', 'external', 'far', 'forward', 'implements', 'index', 'library', 'local',
  20. 'message', 'name', 'namespaces', 'near', 'nodefault', 'overload', 'override', 'package', 'pascal',
  21. 'platform', 'private', 'protected', 'public', 'published', 'read', 'readonly', 'register',
  22. 'reintroduce', 'requires', 'resident', 'safecall', 'stdcall', 'stored', 'varargs', 'virtual',
  23. 'write', 'writeonly', --
  24. 'false', 'nil', 'self', 'true'
  25. }, true)))
  26. -- Functions.
  27. lex:add_rule('function', token(lexer.FUNCTION, word_match({
  28. 'chr', 'ord', 'succ', 'pred', 'abs', 'round', 'trunc', 'sqr', 'sqrt', 'arctan', 'cos', 'sin',
  29. 'exp', 'ln', 'odd', 'eof', 'eoln'
  30. }, true)))
  31. -- Types.
  32. lex:add_rule('type', token(lexer.TYPE, word_match({
  33. 'shortint', 'byte', 'char', 'smallint', 'integer', 'word', 'longint', 'cardinal', 'boolean',
  34. 'bytebool', 'wordbool', 'longbool', 'real', 'single', 'double', 'extended', 'comp', 'currency',
  35. 'pointer'
  36. }, true)))
  37. -- Strings.
  38. lex:add_rule('string', token(lexer.STRING, S('uUrR')^-1 * lexer.range("'", true, false)))
  39. -- Identifiers.
  40. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  41. -- Comments.
  42. local line_comment = lexer.to_eol('//', true)
  43. local bblock_comment = lexer.range('{', '}')
  44. local pblock_comment = lexer.range('(*', '*)')
  45. lex:add_rule('comment', token(lexer.COMMENT, line_comment + bblock_comment + pblock_comment))
  46. -- Numbers.
  47. lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlDdFf')^-1))
  48. -- Operators.
  49. lex:add_rule('operator', token(lexer.OPERATOR, S('.,;^@:=<>+-/*()[]')))
  50. lexer.property['scintillua.comment'] = '//'
  51. return lex