1local info = {
2 version = 1.002,
3 comment = "scintilla lpeg lexer for web snippets",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files",
7}
8
9local P, R, S, C, Cg, Cb, Cs, Cmt, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cg, lpeg.Cb, lpeg.Cs, lpeg.Cmt, lpeg.match
10
11local lexer = require("scite-context-lexer")
12local context = lexer.context
13local patterns = context.patterns
14
15local token = lexer.token
16
17local websnippets = { }
18
19local space = patterns.space
20local any = patterns.any
21local restofline = patterns.restofline
22local startofline = patterns.startofline
23
24local squote = P("'")
25local dquote = P('"')
26local period = P(".")
27
28local t_whitespace = token(whitespace, space^1)
29local t_spacing = token("default", space^1)
30local t_rest = token("default", any)
31
32
33
34local p_beginofweb = P("@")
35local p_endofweb = P("@>")
36
37
38
39local p_directive_1 = p_beginofweb * S(",/|#+;[]")
40local t_directive_1 = token("label",p_directive_1)
41
42
43
44
45
46
47
48
49local p_typeset = p_beginofweb * S(".:=!tq")
50local t_typeset = token("label",p_typeset) * token("warning",(1-p_endofweb)^1) * token("label",p_endofweb)
51
52
53
54local p_index = p_beginofweb * P("^")
55local t_index = token("label",p_index) * token("function",(1-p_endofweb)^1) * token("label",p_endofweb)
56
57
58
59local p_render = p_beginofweb * S("f")
60local t_render = token("label",p_render) * t_spacing * token("warning",(1-space)^1) * t_spacing * token("label",(1-space)^1)
61
62
63
64
65
66
67local p_directive_2 = p_beginofweb * S("sp&h")
68local t_directive_2 = token("label",p_directive_2)
69
70
71
72
73local p_reference = p_beginofweb * S("<(")
74local t_reference = token("label",p_reference) * token("function",(1-p_endofweb)^1) * token("label",p_endofweb * (P("+=") + P("="))^-1)
75
76
77
78local p_character = p_beginofweb * squote
79local t_character = token("label",p_character) * token("reserved",(1-squote)^1) * token("label",squote)
80
81
82
83local p_nonascii = p_beginofweb * S("l")
84local t_nonascii = token("label",p_nonascii) * t_spacing * token("reserved",(1-space)^1)
85
86
87
88
89local p_filename = p_beginofweb * S("xyzi")
90local t_filename = token("label",p_filename) * t_spacing * token("reserved",(1-space)^1)
91
92
93
94local p_escape = p_beginofweb * p_beginofweb
95local t_escape = token("text",p_escape)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119websnippets.pattern = P (
120 t_typeset
121 + t_index
122 + t_render
123 + t_reference
124 + t_filename
125 + t_directive_1
126 + t_directive_2
127 + t_character
128 + t_nonascii
129 + t_escape
130)
131
132return websnippets
133 |