Ver código fonte

Initial doc and code commit

master
Piotr Orzechowski 4 anos atrás
pai
commit
5690ea3841
2 arquivos alterados com 115 adições e 0 exclusões
  1. 3
    0
      www/index.wiki
  2. 112
    0
      xtend.lua

+ 3
- 0
www/index.wiki Ver arquivo

@@ -0,0 +1,3 @@
1
+<title>Home</title>
2
+
3
+<center><h1>Xtend LPeg lexer for Textadept</h1></center>

+ 112
- 0
xtend.lua Ver arquivo

@@ -0,0 +1,112 @@
1
+-- Copyright (c)2014 Piotr Orzechowski [drzewo.org]. See LICENSE.
2
+-- Xtend LPeg lexer.
3
+
4
+local l = require('lexer')
5
+local token, word_match = l.token, l.word_match
6
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
7
+
8
+local M = {_NAME = 'xtend'}
9
+
10
+-- Whitespace.
11
+local ws = token(l.WHITESPACE, l.space^1)
12
+
13
+-- Comments.
14
+local line_comment = '//' * l.nonnewline_esc^0
15
+local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
16
+local comment = token(l.COMMENT, line_comment + block_comment)
17
+
18
+-- Strings.
19
+local sq_str = l.delimited_range("'", true)
20
+local dq_str = l.delimited_range('"', true)
21
+local string = token(l.STRING, sq_str + dq_str)
22
+
23
+-- Templates.
24
+local templ_str = "'''" * (l.any - P("'''"))^0 * P("'''")^-1
25
+local template = token('template', templ_str, true)
26
+
27
+-- Numbers.
28
+local small_suff = S('lL')
29
+local med_suff = P(S('bB') * S('iI'))
30
+local large_suff = S('dD') + S('fF') + P(S('bB') * S('dD'))
31
+local exp = S('eE') * l.digit^1
32
+
33
+local dec_inf = ('_' * l.digit^1)^0
34
+local hex_inf = ('_' * l.xdigit^1)^0
35
+local float_pref = l.digit^1 * '.' * l.digit^1
36
+local float_suff = exp^-1 * med_suff^-1 * large_suff^-1
37
+
38
+local dec = l.digit * dec_inf * (small_suff^-1 + float_suff)
39
+local hex = l.hex_num * hex_inf * P('#' * (small_suff + med_suff))^-1
40
+local float = float_pref * dec_inf * float_suff
41
+
42
+local number = token(l.NUMBER, float + hex + dec)
43
+
44
+-- Keywords.
45
+local keyword = token(l.KEYWORD, word_match{
46
+  -- General.
47
+  'abstract', 'annotation', 'as', 'case', 'catch', 'class', 'create', 'def',
48
+  'default', 'dispatch', 'do', 'else', 'enum', 'extends', 'extension', 'final',
49
+  'finally', 'for', 'if', 'implements', 'import', 'interface', 'instanceof',
50
+  'it', 'new', 'override', 'package', 'private', 'protected', 'public',
51
+  'return', 'self', 'static', 'super', 'switch', 'synchronized', 'this',
52
+  'throw', 'throws', 'try', 'typeof', 'val', 'var', 'while',
53
+  -- Templates.
54
+  -- 'AFTER', 'BEFORE', 'ENDFOR', 'ENDIF', 'FOR', 'IF', 'SEPARATOR',
55
+  -- Literals.
56
+  'true', 'false', 'null'
57
+})
58
+
59
+-- Types.
60
+local type = token(l.TYPE, word_match{
61
+  'boolean', 'byte', 'char', 'double', 'float', 'int', 'long', 'short', 'void',
62
+  'Boolean', 'Byte', 'Character', 'Double', 'Float', 'Integer', 'Long', 'Short',
63
+  'String'
64
+})
65
+
66
+-- Identifiers.
67
+local identifier = token(l.IDENTIFIER, l.word)
68
+
69
+-- Operators.
70
+local operator = token(l.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}#'))
71
+
72
+-- Annotations.
73
+local annotation = token('annotation', '@' * l.word)
74
+
75
+-- Functions.
76
+local func = token(l.FUNCTION, l.word) * #P('(')
77
+
78
+-- Classes.
79
+local class = token(l.KEYWORD, P('class')) * ws^1 * token(l.CLASS, l.word)
80
+
81
+-- Rules.
82
+M._rules = {
83
+  {'whitespace', ws},
84
+  {'class', class},
85
+  {'keyword', keyword},
86
+  {'type', type},
87
+  {'function', func},
88
+  {'identifier', identifier},
89
+  {'template', template},
90
+  {'string', string},
91
+  {'comment', comment},
92
+  {'number', number},
93
+  {'annotation', annotation},
94
+  {'operator', operator},
95
+  {'error', token(l.ERROR, l.any)},
96
+}
97
+
98
+-- Token styles.
99
+M._tokenstyles = {
100
+  annotation = l.STYLE_PREPROCESSOR,
101
+  template = l.STYLE_EMBEDDED
102
+}
103
+
104
+-- Folding.
105
+M._foldsymbols = {
106
+  _patterns = {'[{}]', '/%*', '%*/', '//', 'import'},
107
+  [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
108
+  [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')},
109
+  [l.KEYWORD] = {['import'] = l.fold_line_comments('import')}
110
+}
111
+
112
+return M

Carregando…
Cancelar
Salvar