1local info = {
2 version = 1.001,
3 comment = "scintilla lpeg lexer for sas",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files",
7}
8
9
10
11local P, R, S = lpeg.P, lpeg.R, lpeg.S
12
13local lexers = require("scite-context-lexer")
14
15local patterns = lexers.patterns
16local token = lexers.token
17
18local saslexer = lexers.new("sas","scite-context-lexer-sAs")
19local saswhitespace = saslexer.whitespace
20
21local keywords_standard = {
22 "anova", "data", "run", "proc",
23}
24
25local keywords_dialects = {
26 "class", "do", "end", "int", "for", "model", "rannor", "to", "output",
27}
28
29local space = patterns.space
30local any = patterns.any
31local restofline = patterns.restofline
32local startofline = patterns.startofline
33local exactmatch = patterns.exactmatch
34
35local squote = P("'")
36local dquote = P('"')
37local bquote = P('`')
38local escaped = P("\\") * P(1)
39
40local begincomment = P("/*")
41local endcomment = P("*/")
42
43local decimal = patterns.decimal
44local float = patterns.float
45local integer = P("-")^-1 * decimal
46
47local spacing = token(saswhitespace, space^1)
48
49local rest = token("default", any)
50
51local shortcomment = token("comment", (P("#") + P("--")) * restofline^0)
52local longcomment = token("comment", begincomment * (1-endcomment)^0 * endcomment^-1)
53
54local identifier = token("default", lexer.helpers.utfidentifier)
55
56local shortstring = token("quote", dquote)
57 * token("string", (escaped + (1-dquote))^0)
58 * token("quote", dquote)
59 + token("quote", squote)
60 * token("string", (escaped + (1-squote))^0)
61 * token("quote", squote)
62 + token("quote", bquote)
63 * token("string", (escaped + (1-bquote))^0)
64 * token("quote", bquote)
65
66local p_keywords_s = exactmatch(keywords_standard,true)
67local p_keywords_d = exactmatch(keywords_dialects,true)
68
69local keyword_s = token("keyword", p_keywords_s)
70local keyword_d = token("command", p_keywords_d)
71
72local number = token("number", float + integer)
73local operator = token("special", S("+-*/%^!=<>;:{}[]().&|?~"))
74
75saslexer.folding = {
76 ["/*"] = { ["comment"] = 1 },
77 ["*/"] = { ["comment"] = -1 },
78
79
80}
81
82saslexer.rules = {
83 { "whitespace", spacing },
84 { "keyword-s", keyword_s },
85 { "keyword-d", keyword_d },
86 { "identifier", identifier },
87 { "string", shortstring },
88 { "longcomment", longcomment },
89 { "shortcomment", shortcomment },
90 { "number", number },
91 { "operator", operator },
92 { "rest", rest },
93}
94
95return saslexer
96 |