scite-context-lexer-web-snippets.lua /size: 3471 b    last modification: 2020-07-01 14:35
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 -- S(" \n\r\t\f\v")
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-- the web subset
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-- @.text @>(monospaced)
43-- @:text @>(macro driven)
44-- @= verbose@>
45-- @! underlined @>
46-- @t text @> (hbox)
47-- @q ignored @>
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-- @^index@>
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-- @f text renderclass
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-- @s idem
63-- @p idem
64-- @& strip (spaces before)
65-- @h
66
67local p_directive_2 = p_beginofweb * S("sp&h")
68local t_directive_2 = token("label",p_directive_2)
69
70-- @< ... @> [=|+=|]
71-- @(foo@>
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-- @'char' (ascii code)
77
78local p_character = p_beginofweb * squote
79local t_character = token("label",p_character) * token("reserved",(1-squote)^1) * token("label",squote)
80
81-- @l nonascii
82
83local p_nonascii = p_beginofweb * S("l")
84local t_nonascii = token("label",p_nonascii) * t_spacing * token("reserved",(1-space)^1)
85
86-- @x @y @z changefile
87-- @i webfile
88
89local p_filename = p_beginofweb * S("xyzi")
90local t_filename = token("label",p_filename) * t_spacing * token("reserved",(1-space)^1)
91
92-- @@  escape
93
94local p_escape = p_beginofweb * p_beginofweb
95local t_escape = token("text",p_escape)
96
97-- structure
98
99-- @* title.
100
101-- local p_section = p_beginofweb * P("*")^1
102-- local t_section = token("label",p_section) * t_spacing * token("function",(1-period)^1) * token("label",period)
103
104-- @  explanation
105
106-- local p_explanation = p_beginofweb
107-- local t_explanation = token("label",p_explanation) * t_spacing^1
108
109-- @d macro
110
111-- local p_macro = p_beginofweb * P("d")
112-- local t_macro = token("label",p_macro)
113
114-- @c code
115
116-- local p_code = p_beginofweb * P("c")
117-- local t_code = token("label",p_code)
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