aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/ansi_c.lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-25 20:48:51 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-25 21:14:28 +0100
commit3751586e1fbf044fa798737e9c59a0235c5aaee7 (patch)
tree417e30516500092e4002d3a6c2dacdd6b3050d90 /lua/lexers/ansi_c.lua
parentb44f174cccd4cd2b1b975f2767335ce636ee273b (diff)
downloadvis-3751586e1fbf044fa798737e9c59a0235c5aaee7.tar.gz
vis-3751586e1fbf044fa798737e9c59a0235c5aaee7.tar.xz
lexers: sync with scintillua changeset 594 rev 6e29a8d2a783
Stuff which was left out / our local changes include: - lexer.lua: different loading mechanism and style handling - ansi_c.lua: for now we keep the separate token definitions with references to the respective standards. This should highlight file names after #include directives. It will also treat simple, non-nested occurrences of #if 0 ... #endif as a comment. - pkgbuild.lua: the arch specific fields have been kept - all scintilla $(style variables) have been replaced
Diffstat (limited to 'lua/lexers/ansi_c.lua')
-rw-r--r--lua/lexers/ansi_c.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/lua/lexers/ansi_c.lua b/lua/lexers/ansi_c.lua
index 4f82ab9..f35d4ea 100644
--- a/lua/lexers/ansi_c.lua
+++ b/lua/lexers/ansi_c.lua
@@ -12,7 +12,10 @@ local ws = token(l.WHITESPACE, l.space^1)
-- Comments.
local line_comment = '//' * l.nonnewline_esc^0
-local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
+local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1 +
+ l.starts_line('#if') * S(' \t')^0 * '0' * l.space *
+ (l.any - l.starts_line('#endif'))^0 *
+ (l.starts_line('#endif'))^-1
local comment = token(l.COMMENT, line_comment + block_comment)
-- Strings.
@@ -25,11 +28,14 @@ local number = token(l.NUMBER, l.float + l.integer)
-- Preprocessor.
local preproc_word = word_match{
- 'define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef',
- 'include', 'line', 'pragma', 'undef', 'warning',
+ 'define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'line',
+ 'pragma', 'undef', 'warning'
}
-local preproc = token(l.PREPROCESSOR,
- l.starts_line('#') * S('\t ')^0 * preproc_word)
+local preproc = #l.starts_line('#') *
+ (token(l.PREPROCESSOR, '#' * S('\t ')^0 * preproc_word) +
+ token(l.PREPROCESSOR, '#' * S('\t ')^0 * 'include') *
+ (token(l.WHITESPACE, S('\t ')^1) *
+ token(l.STRING, l.delimited_range('<>', true, true)))^-1)
-- Keywords.
local storage_class = word_match{
@@ -110,10 +116,13 @@ M._rules = {
}
M._foldsymbols = {
- _patterns = {'%l+', '[{}]', '/%*', '%*/', '//'},
+ _patterns = {'#?%l+', '[{}]', '/%*', '%*/', '//'},
[l.PREPROCESSOR] = {['if'] = 1, ifdef = 1, ifndef = 1, endif = -1},
[l.OPERATOR] = {['{'] = 1, ['}'] = -1},
- [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
+ [l.COMMENT] = {
+ ['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//'),
+ ['#if'] = 1, ['#endif'] = -1
+ }
}
return M