scite-context-lexer-web-snippets.lua /size: 3444 b    last modification: 2021-10-28 13:49
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 lexers       = require("scite-context-lexer")
12
13local patterns     = lexers.patterns
14local token        = lexers.token
15
16local websnippets  = { }
17
18local space        = patterns.space -- S(" \n\r\t\f\v")
19local any          = patterns.any
20local restofline   = patterns.restofline
21local startofline  = patterns.startofline
22
23local squote       = P("'")
24local dquote       = P('"')
25local period       = P(".")
26
27local t_whitespace = token("whitespace", space^1)
28local t_spacing    = token("default",    space^1)
29local t_rest       = token("default",    any)
30
31-- the web subset
32
33local p_beginofweb = P("@")
34local p_endofweb   = P("@>")
35
36-- @, @/ @| @# @+ @; @[ @]
37
38local p_directive_1 = p_beginofweb * S(",/|#+;[]")
39local t_directive_1 = token("label",p_directive_1)
40
41-- @.text @>(monospaced)
42-- @:text @>(macro driven)
43-- @= verbose@>
44-- @! underlined @>
45-- @t text @> (hbox)
46-- @q ignored @>
47
48local p_typeset = p_beginofweb * S(".:=!tq")
49local t_typeset = token("label",p_typeset) * token("warning",(1-p_endofweb)^1) * token("label",p_endofweb)
50
51-- @^index@>
52
53local p_index = p_beginofweb * P("^")
54local t_index = token("label",p_index) * token("function",(1-p_endofweb)^1) * token("label",p_endofweb)
55
56-- @f text renderclass
57
58local p_render = p_beginofweb * S("f")
59local t_render = token("label",p_render) * t_spacing * token("warning",(1-space)^1) * t_spacing * token("label",(1-space)^1)
60
61-- @s idem
62-- @p idem
63-- @& strip (spaces before)
64-- @h
65
66local p_directive_2 = p_beginofweb * S("sp&h")
67local t_directive_2 = token("label",p_directive_2)
68
69-- @< ... @> [=|+=|]
70-- @(foo@>
71
72local p_reference = p_beginofweb * S("<(")
73local t_reference = token("label",p_reference) * token("function",(1-p_endofweb)^1) * token("label",p_endofweb * (P("+=") + P("="))^-1)
74
75-- @'char' (ascii code)
76
77local p_character = p_beginofweb * squote
78local t_character = token("label",p_character) * token("reserved",(1-squote)^1) * token("label",squote)
79
80-- @l nonascii
81
82local p_nonascii = p_beginofweb * S("l")
83local t_nonascii = token("label",p_nonascii) * t_spacing * token("reserved",(1-space)^1)
84
85-- @x @y @z changefile
86-- @i webfile
87
88local p_filename = p_beginofweb * S("xyzi")
89local t_filename = token("label",p_filename) * t_spacing * token("reserved",(1-space)^1)
90
91-- @@  escape
92
93local p_escape = p_beginofweb * p_beginofweb
94local t_escape = token("text",p_escape)
95
96-- structure
97
98-- @* title.
99
100-- local p_section = p_beginofweb * P("*")^1
101-- local t_section = token("label",p_section) * t_spacing * token("function",(1-period)^1) * token("label",period)
102
103-- @  explanation
104
105-- local p_explanation = p_beginofweb
106-- local t_explanation = token("label",p_explanation) * t_spacing^1
107
108-- @d macro
109
110-- local p_macro = p_beginofweb * P("d")
111-- local t_macro = token("label",p_macro)
112
113-- @c code
114
115-- local p_code = p_beginofweb * P("c")
116-- local t_code = token("label",p_code)
117
118websnippets.pattern = P (
119    t_typeset
120  + t_index
121  + t_render
122  + t_reference
123  + t_filename
124  + t_directive_1
125  + t_directive_2
126  + t_character
127  + t_nonascii
128  + t_escape
129)
130
131return websnippets
132