From 80f3cef5b4a1922dcdb8e8bf60fe54f37be94111 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Sun, 9 Apr 2023 14:57:08 +0200 Subject: [PATCH] feat: Update lexers to Scintillua 5.3 --- Makefile | 8 +- README.md | 4 +- syntaxhighlight-dev-1.rockspec | 18 + syntaxhighlight/textadept/LICENSE | 2 +- syntaxhighlight/textadept/actionscript.lua | 33 +- syntaxhighlight/textadept/ada.lua | 35 +- syntaxhighlight/textadept/ansi_c.lua | 79 +- syntaxhighlight/textadept/antlr.lua | 32 +- syntaxhighlight/textadept/apdl.lua | 72 +- syntaxhighlight/textadept/apl.lua | 20 +- syntaxhighlight/textadept/applescript.lua | 54 +- syntaxhighlight/textadept/asm.lua | 557 +++---- syntaxhighlight/textadept/asp.lua | 15 +- syntaxhighlight/textadept/autoit.lua | 173 ++- syntaxhighlight/textadept/awk.lua | 82 +- syntaxhighlight/textadept/bash.lua | 27 +- syntaxhighlight/textadept/batch.lua | 27 +- syntaxhighlight/textadept/bibtex.lua | 31 +- syntaxhighlight/textadept/boo.lua | 47 +- syntaxhighlight/textadept/caml.lua | 61 +- syntaxhighlight/textadept/chuck.lua | 44 +- syntaxhighlight/textadept/clojure.lua | 148 ++ syntaxhighlight/textadept/cmake.lua | 196 ++- syntaxhighlight/textadept/coffeescript.lua | 23 +- syntaxhighlight/textadept/container.lua | 2 +- syntaxhighlight/textadept/context.lua | 27 +- syntaxhighlight/textadept/cpp.lua | 43 +- syntaxhighlight/textadept/crystal.lua | 77 +- syntaxhighlight/textadept/csharp.lua | 37 +- syntaxhighlight/textadept/css.lua | 242 ++- syntaxhighlight/textadept/cuda.lua | 96 +- syntaxhighlight/textadept/dart.lua | 26 +- syntaxhighlight/textadept/desktop.lua | 34 +- syntaxhighlight/textadept/diff.lua | 21 +- syntaxhighlight/textadept/django.lua | 35 +- syntaxhighlight/textadept/dmd.lua | 253 ++- syntaxhighlight/textadept/dockerfile.lua | 16 +- syntaxhighlight/textadept/dot.lua | 35 +- syntaxhighlight/textadept/eiffel.lua | 37 +- syntaxhighlight/textadept/elixir.lua | 114 +- syntaxhighlight/textadept/elm.lua | 44 + syntaxhighlight/textadept/erlang.lua | 72 +- syntaxhighlight/textadept/fantom.lua | 85 ++ syntaxhighlight/textadept/faust.lua | 22 +- syntaxhighlight/textadept/fennel.lua | 39 + syntaxhighlight/textadept/fish.lua | 28 +- syntaxhighlight/textadept/forth.lua | 44 +- syntaxhighlight/textadept/fortran.lua | 62 +- syntaxhighlight/textadept/fsharp.lua | 48 +- syntaxhighlight/textadept/fstab.lua | 127 ++ syntaxhighlight/textadept/gap.lua | 17 +- syntaxhighlight/textadept/gettext.lua | 9 +- syntaxhighlight/textadept/gherkin.lua | 20 +- syntaxhighlight/textadept/gleam.lua | 120 ++ syntaxhighlight/textadept/glsl.lua | 155 +- syntaxhighlight/textadept/gnuplot.lua | 56 +- syntaxhighlight/textadept/go.lua | 35 +- syntaxhighlight/textadept/groovy.lua | 49 +- syntaxhighlight/textadept/gtkrc.lua | 37 +- syntaxhighlight/textadept/haskell.lua | 19 +- syntaxhighlight/textadept/html.lua | 124 +- syntaxhighlight/textadept/icon.lua | 37 +- syntaxhighlight/textadept/idl.lua | 28 +- syntaxhighlight/textadept/inform.lua | 82 +- syntaxhighlight/textadept/ini.lua | 14 +- syntaxhighlight/textadept/io_lang.lua | 25 +- syntaxhighlight/textadept/java.lua | 35 +- syntaxhighlight/textadept/javascript.lua | 64 +- syntaxhighlight/textadept/jq.lua | 84 + syntaxhighlight/textadept/json.lua | 10 +- syntaxhighlight/textadept/jsp.lua | 6 +- syntaxhighlight/textadept/julia.lua | 111 ++ syntaxhighlight/textadept/latex.lua | 33 +- syntaxhighlight/textadept/ledger.lua | 24 +- syntaxhighlight/textadept/less.lua | 7 +- syntaxhighlight/textadept/lexer.lua | 1604 ++++++++++---------- syntaxhighlight/textadept/lilypond.lua | 4 +- syntaxhighlight/textadept/lisp.lua | 52 +- syntaxhighlight/textadept/litcoffee.lua | 9 +- syntaxhighlight/textadept/logtalk.lua | 94 +- syntaxhighlight/textadept/lua.lua | 155 +- syntaxhighlight/textadept/makefile.lua | 95 +- syntaxhighlight/textadept/man.lua | 16 +- syntaxhighlight/textadept/markdown.lua | 100 +- syntaxhighlight/textadept/matlab.lua | 74 +- syntaxhighlight/textadept/mediawiki.lua | 42 +- syntaxhighlight/textadept/meson.lua | 127 ++ syntaxhighlight/textadept/moonscript.lua | 142 +- syntaxhighlight/textadept/myrddin.lua | 32 +- syntaxhighlight/textadept/nemerle.lua | 41 +- syntaxhighlight/textadept/networkd.lua | 102 ++ syntaxhighlight/textadept/nim.lua | 110 +- syntaxhighlight/textadept/nsis.lua | 167 +- syntaxhighlight/textadept/null.lua | 2 +- syntaxhighlight/textadept/objective_c.lua | 42 +- syntaxhighlight/textadept/pascal.lua | 56 +- syntaxhighlight/textadept/perl.lua | 103 +- syntaxhighlight/textadept/php.lua | 62 +- syntaxhighlight/textadept/pico8.lua | 16 +- syntaxhighlight/textadept/pike.lua | 27 +- syntaxhighlight/textadept/pkgbuild.lua | 45 +- syntaxhighlight/textadept/pony.lua | 95 ++ syntaxhighlight/textadept/powershell.lua | 44 +- syntaxhighlight/textadept/prolog.lua | 14 +- syntaxhighlight/textadept/props.lua | 13 +- syntaxhighlight/textadept/protobuf.lua | 21 +- syntaxhighlight/textadept/ps.lua | 22 +- syntaxhighlight/textadept/pure.lua | 46 +- syntaxhighlight/textadept/python.lua | 101 +- syntaxhighlight/textadept/rails.lua | 71 +- syntaxhighlight/textadept/rc.lua | 26 +- syntaxhighlight/textadept/reason.lua | 66 + syntaxhighlight/textadept/rebol.lua | 134 +- syntaxhighlight/textadept/rest.lua | 10 +- syntaxhighlight/textadept/rexx.lua | 74 +- syntaxhighlight/textadept/rhtml.lua | 6 +- syntaxhighlight/textadept/routeros.lua | 60 + syntaxhighlight/textadept/rstats.lua | 20 +- syntaxhighlight/textadept/ruby.lua | 69 +- syntaxhighlight/textadept/rust.lua | 72 +- syntaxhighlight/textadept/sass.lua | 8 +- syntaxhighlight/textadept/scala.lua | 30 +- syntaxhighlight/textadept/scheme.lua | 194 ++- syntaxhighlight/textadept/smalltalk.lua | 14 +- syntaxhighlight/textadept/sml.lua | 164 +- syntaxhighlight/textadept/snobol4.lua | 110 +- syntaxhighlight/textadept/spin.lua | 69 + syntaxhighlight/textadept/sql.lua | 56 +- syntaxhighlight/textadept/systemd.lua | 134 ++ syntaxhighlight/textadept/taskpaper.lua | 81 +- syntaxhighlight/textadept/tcl.lua | 24 +- syntaxhighlight/textadept/tex.lua | 14 +- syntaxhighlight/textadept/texinfo.lua | 190 ++- syntaxhighlight/textadept/text.lua | 10 +- syntaxhighlight/textadept/toml.lua | 16 +- syntaxhighlight/textadept/txt2tags.lua | 123 +- syntaxhighlight/textadept/typescript.lua | 24 + syntaxhighlight/textadept/vala.lua | 34 +- syntaxhighlight/textadept/vb.lua | 47 +- syntaxhighlight/textadept/vcard.lua | 119 +- syntaxhighlight/textadept/verilog.lua | 55 +- syntaxhighlight/textadept/vhdl.lua | 69 +- syntaxhighlight/textadept/wsf.lua | 46 +- syntaxhighlight/textadept/xml.lua | 58 +- syntaxhighlight/textadept/xs.lua | 60 + syntaxhighlight/textadept/xtend.lua | 40 +- syntaxhighlight/textadept/yaml.lua | 115 +- syntaxhighlight/textadept/zig.lua | 94 ++ 148 files changed, 6181 insertions(+), 4755 deletions(-) create mode 100644 syntaxhighlight/textadept/clojure.lua create mode 100644 syntaxhighlight/textadept/elm.lua create mode 100644 syntaxhighlight/textadept/fantom.lua create mode 100644 syntaxhighlight/textadept/fennel.lua create mode 100644 syntaxhighlight/textadept/fstab.lua create mode 100644 syntaxhighlight/textadept/gleam.lua create mode 100644 syntaxhighlight/textadept/jq.lua create mode 100644 syntaxhighlight/textadept/julia.lua create mode 100644 syntaxhighlight/textadept/meson.lua create mode 100644 syntaxhighlight/textadept/networkd.lua create mode 100644 syntaxhighlight/textadept/pony.lua create mode 100644 syntaxhighlight/textadept/reason.lua create mode 100644 syntaxhighlight/textadept/routeros.lua create mode 100644 syntaxhighlight/textadept/spin.lua create mode 100644 syntaxhighlight/textadept/systemd.lua create mode 100644 syntaxhighlight/textadept/typescript.lua create mode 100644 syntaxhighlight/textadept/xs.lua create mode 100644 syntaxhighlight/textadept/zig.lua diff --git a/Makefile b/Makefile index 199c2fa..82881d5 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ vendor: -rm -r tmp mkdir tmp - cd tmp; curl -O https://foicica.com/textadept/download/textadept_NIGHTLY.x86_64.tgz - cd tmp; tar xzf textadept_NIGHTLY.x86_64.tgz + cd tmp; curl -L -O https://github.com/orbitalquark/scintillua/releases/download/scintillua_5.3/scintillua_5.3.zip + cd tmp; unzip scintillua_5.3.zip mkdir -p syntaxhighlight/textadept - cp tmp/textadept_NIGHTLY*/lexers/*.lua syntaxhighlight/textadept + cp tmp/scintillua_5.3*/lexers/*.lua syntaxhighlight/textadept sed -i -e "s/require('lexer')/require('syntaxhighlight.textadept.lexer')/" syntaxhighlight/textadept/*.lua sed -i -e "1ilocal lpeg = require('lpeg')" $$(find syntaxhighlight/textadept/*.lua | grep -v '/lexer.lua') - cp tmp/textadept_NIGHTLY*/LICENSE syntaxhighlight/textadept + cp tmp/scintillua_5.3*/LICENSE syntaxhighlight/textadept local: build luarocks make --lua-version=5.1 --local syntaxhighlight-dev-1.rockspec diff --git a/README.md b/README.md index 3771511..61127bf 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![test](https://github.com/leafo/lua-syntaxhighlight/workflows/test/badge.svg) -Highlights code into HTML using lexers from [Textadept](https://foicica.com/textadept/). +Highlights code into HTML using lexers from [Scintillua](https://github.com/orbitalquark/scintillua) (a component of Textadept/Scintilla). ```lua @@ -55,7 +55,7 @@ Options: The MIT License -Copyright (c) 2007-2019 Mitchell +Copyright (c) 2006-2021 Mitchell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/syntaxhighlight-dev-1.rockspec b/syntaxhighlight-dev-1.rockspec index 6c41efb..ead6d47 100644 --- a/syntaxhighlight-dev-1.rockspec +++ b/syntaxhighlight-dev-1.rockspec @@ -35,6 +35,7 @@ build = { ["syntaxhighlight.textadept.boo"] = "syntaxhighlight/textadept/boo.lua", ["syntaxhighlight.textadept.caml"] = "syntaxhighlight/textadept/caml.lua", ["syntaxhighlight.textadept.chuck"] = "syntaxhighlight/textadept/chuck.lua", + ["syntaxhighlight.textadept.clojure"] = "syntaxhighlight/textadept/clojure.lua", ["syntaxhighlight.textadept.cmake"] = "syntaxhighlight/textadept/cmake.lua", ["syntaxhighlight.textadept.coffeescript"] = "syntaxhighlight/textadept/coffeescript.lua", ["syntaxhighlight.textadept.container"] = "syntaxhighlight/textadept/container.lua", @@ -53,15 +54,20 @@ build = { ["syntaxhighlight.textadept.dot"] = "syntaxhighlight/textadept/dot.lua", ["syntaxhighlight.textadept.eiffel"] = "syntaxhighlight/textadept/eiffel.lua", ["syntaxhighlight.textadept.elixir"] = "syntaxhighlight/textadept/elixir.lua", + ["syntaxhighlight.textadept.elm"] = "syntaxhighlight/textadept/elm.lua", ["syntaxhighlight.textadept.erlang"] = "syntaxhighlight/textadept/erlang.lua", + ["syntaxhighlight.textadept.fantom"] = "syntaxhighlight/textadept/fantom.lua", ["syntaxhighlight.textadept.faust"] = "syntaxhighlight/textadept/faust.lua", + ["syntaxhighlight.textadept.fennel"] = "syntaxhighlight/textadept/fennel.lua", ["syntaxhighlight.textadept.fish"] = "syntaxhighlight/textadept/fish.lua", ["syntaxhighlight.textadept.forth"] = "syntaxhighlight/textadept/forth.lua", ["syntaxhighlight.textadept.fortran"] = "syntaxhighlight/textadept/fortran.lua", ["syntaxhighlight.textadept.fsharp"] = "syntaxhighlight/textadept/fsharp.lua", + ["syntaxhighlight.textadept.fstab"] = "syntaxhighlight/textadept/fstab.lua", ["syntaxhighlight.textadept.gap"] = "syntaxhighlight/textadept/gap.lua", ["syntaxhighlight.textadept.gettext"] = "syntaxhighlight/textadept/gettext.lua", ["syntaxhighlight.textadept.gherkin"] = "syntaxhighlight/textadept/gherkin.lua", + ["syntaxhighlight.textadept.gleam"] = "syntaxhighlight/textadept/gleam.lua", ["syntaxhighlight.textadept.glsl"] = "syntaxhighlight/textadept/glsl.lua", ["syntaxhighlight.textadept.gnuplot"] = "syntaxhighlight/textadept/gnuplot.lua", ["syntaxhighlight.textadept.go"] = "syntaxhighlight/textadept/go.lua", @@ -76,8 +82,10 @@ build = { ["syntaxhighlight.textadept.io_lang"] = "syntaxhighlight/textadept/io_lang.lua", ["syntaxhighlight.textadept.java"] = "syntaxhighlight/textadept/java.lua", ["syntaxhighlight.textadept.javascript"] = "syntaxhighlight/textadept/javascript.lua", + ["syntaxhighlight.textadept.jq"] = "syntaxhighlight/textadept/jq.lua", ["syntaxhighlight.textadept.json"] = "syntaxhighlight/textadept/json.lua", ["syntaxhighlight.textadept.jsp"] = "syntaxhighlight/textadept/jsp.lua", + ["syntaxhighlight.textadept.julia"] = "syntaxhighlight/textadept/julia.lua", ["syntaxhighlight.textadept.latex"] = "syntaxhighlight/textadept/latex.lua", ["syntaxhighlight.textadept.ledger"] = "syntaxhighlight/textadept/ledger.lua", ["syntaxhighlight.textadept.less"] = "syntaxhighlight/textadept/less.lua", @@ -92,9 +100,11 @@ build = { ["syntaxhighlight.textadept.markdown"] = "syntaxhighlight/textadept/markdown.lua", ["syntaxhighlight.textadept.matlab"] = "syntaxhighlight/textadept/matlab.lua", ["syntaxhighlight.textadept.mediawiki"] = "syntaxhighlight/textadept/mediawiki.lua", + ["syntaxhighlight.textadept.meson"] = "syntaxhighlight/textadept/meson.lua", ["syntaxhighlight.textadept.moonscript"] = "syntaxhighlight/textadept/moonscript.lua", ["syntaxhighlight.textadept.myrddin"] = "syntaxhighlight/textadept/myrddin.lua", ["syntaxhighlight.textadept.nemerle"] = "syntaxhighlight/textadept/nemerle.lua", + ["syntaxhighlight.textadept.networkd"] = "syntaxhighlight/textadept/networkd.lua", ["syntaxhighlight.textadept.nim"] = "syntaxhighlight/textadept/nim.lua", ["syntaxhighlight.textadept.nsis"] = "syntaxhighlight/textadept/nsis.lua", ["syntaxhighlight.textadept.null"] = "syntaxhighlight/textadept/null.lua", @@ -105,6 +115,7 @@ build = { ["syntaxhighlight.textadept.pico8"] = "syntaxhighlight/textadept/pico8.lua", ["syntaxhighlight.textadept.pike"] = "syntaxhighlight/textadept/pike.lua", ["syntaxhighlight.textadept.pkgbuild"] = "syntaxhighlight/textadept/pkgbuild.lua", + ["syntaxhighlight.textadept.pony"] = "syntaxhighlight/textadept/pony.lua", ["syntaxhighlight.textadept.powershell"] = "syntaxhighlight/textadept/powershell.lua", ["syntaxhighlight.textadept.prolog"] = "syntaxhighlight/textadept/prolog.lua", ["syntaxhighlight.textadept.props"] = "syntaxhighlight/textadept/props.lua", @@ -114,10 +125,12 @@ build = { ["syntaxhighlight.textadept.python"] = "syntaxhighlight/textadept/python.lua", ["syntaxhighlight.textadept.rails"] = "syntaxhighlight/textadept/rails.lua", ["syntaxhighlight.textadept.rc"] = "syntaxhighlight/textadept/rc.lua", + ["syntaxhighlight.textadept.reason"] = "syntaxhighlight/textadept/reason.lua", ["syntaxhighlight.textadept.rebol"] = "syntaxhighlight/textadept/rebol.lua", ["syntaxhighlight.textadept.rest"] = "syntaxhighlight/textadept/rest.lua", ["syntaxhighlight.textadept.rexx"] = "syntaxhighlight/textadept/rexx.lua", ["syntaxhighlight.textadept.rhtml"] = "syntaxhighlight/textadept/rhtml.lua", + ["syntaxhighlight.textadept.routeros"] = "syntaxhighlight/textadept/routeros.lua", ["syntaxhighlight.textadept.rstats"] = "syntaxhighlight/textadept/rstats.lua", ["syntaxhighlight.textadept.ruby"] = "syntaxhighlight/textadept/ruby.lua", ["syntaxhighlight.textadept.rust"] = "syntaxhighlight/textadept/rust.lua", @@ -127,7 +140,9 @@ build = { ["syntaxhighlight.textadept.smalltalk"] = "syntaxhighlight/textadept/smalltalk.lua", ["syntaxhighlight.textadept.sml"] = "syntaxhighlight/textadept/sml.lua", ["syntaxhighlight.textadept.snobol4"] = "syntaxhighlight/textadept/snobol4.lua", + ["syntaxhighlight.textadept.spin"] = "syntaxhighlight/textadept/spin.lua", ["syntaxhighlight.textadept.sql"] = "syntaxhighlight/textadept/sql.lua", + ["syntaxhighlight.textadept.systemd"] = "syntaxhighlight/textadept/systemd.lua", ["syntaxhighlight.textadept.taskpaper"] = "syntaxhighlight/textadept/taskpaper.lua", ["syntaxhighlight.textadept.tcl"] = "syntaxhighlight/textadept/tcl.lua", ["syntaxhighlight.textadept.tex"] = "syntaxhighlight/textadept/tex.lua", @@ -135,6 +150,7 @@ build = { ["syntaxhighlight.textadept.text"] = "syntaxhighlight/textadept/text.lua", ["syntaxhighlight.textadept.toml"] = "syntaxhighlight/textadept/toml.lua", ["syntaxhighlight.textadept.txt2tags"] = "syntaxhighlight/textadept/txt2tags.lua", + ["syntaxhighlight.textadept.typescript"] = "syntaxhighlight/textadept/typescript.lua", ["syntaxhighlight.textadept.vala"] = "syntaxhighlight/textadept/vala.lua", ["syntaxhighlight.textadept.vb"] = "syntaxhighlight/textadept/vb.lua", ["syntaxhighlight.textadept.vbscript"] = "syntaxhighlight/textadept/vbscript.lua", @@ -144,6 +160,8 @@ build = { ["syntaxhighlight.textadept.wsf"] = "syntaxhighlight/textadept/wsf.lua", ["syntaxhighlight.textadept.xml"] = "syntaxhighlight/textadept/xml.lua", ["syntaxhighlight.textadept.xtend"] = "syntaxhighlight/textadept/xtend.lua", + ["syntaxhighlight.textadept.xs"] = "syntaxhighlight/textadept/xs.lua", ["syntaxhighlight.textadept.yaml"] = "syntaxhighlight/textadept/yaml.lua", + ["syntaxhighlight.textadept.zig"] = "syntaxhighlight/textadept/zig.lua", } } diff --git a/syntaxhighlight/textadept/LICENSE b/syntaxhighlight/textadept/LICENSE index bd8d739..933d47a 100644 --- a/syntaxhighlight/textadept/LICENSE +++ b/syntaxhighlight/textadept/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2007-2019 Mitchell +Copyright (c) 2007-2021 Mitchell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/syntaxhighlight/textadept/actionscript.lua b/syntaxhighlight/textadept/actionscript.lua index a453358..4ad2013 100644 --- a/syntaxhighlight/textadept/actionscript.lua +++ b/syntaxhighlight/textadept/actionscript.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Actionscript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('actionscript') @@ -12,23 +12,24 @@ local lex = lexer.new('actionscript') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break continue delete do else for function if in new on return this typeof var - void while with NaN Infinity false null true undefined +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'continue', 'delete', 'do', 'else', 'for', 'function', 'if', 'in', 'new', 'on', 'return', + 'this', 'typeof', 'var', 'void', 'while', 'with', 'NaN', 'Infinity', 'false', 'null', 'true', + 'undefined', -- Reserved for future use. - abstract case catch class const debugger default export extends final finally - goto implements import instanceof interface native package private Void - protected public dynamic static super switch synchonized throw throws - transient try volatile -]])) + 'abstract', 'case', 'catch', 'class', 'const', 'debugger', 'default', 'export', 'extends', + 'final', 'finally', 'goto', 'implements', 'import', 'instanceof', 'interface', 'native', + 'package', 'private', 'Void', 'protected', 'public', 'dynamic', 'static', 'super', 'switch', + 'synchonized', 'throw', 'throws', 'transient', 'try', 'volatile' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - Array Boolean Color Date Function Key MovieClip Math Mouse Number Object - Selection Sound String XML XMLNode XMLSocket +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'Array', 'Boolean', 'Color', 'Date', 'Function', 'Key', 'MovieClip', 'Math', 'Mouse', 'Number', + 'Object', 'Selection', 'Sound', 'String', 'XML', 'XMLNode', 'XMLSocket', -- Reserved for future use. - boolean byte char double enum float int long short -]])) + 'boolean', 'byte', 'char', 'double', 'enum', 'float', 'int', 'long', 'short' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -53,7 +54,7 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*%&|^~.,;?()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) lex:add_fold_point(lexer.STRING, '') return lex diff --git a/syntaxhighlight/textadept/ada.lua b/syntaxhighlight/textadept/ada.lua index 35481c4..3766e86 100644 --- a/syntaxhighlight/textadept/ada.lua +++ b/syntaxhighlight/textadept/ada.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Ada LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ada') @@ -12,27 +12,28 @@ local lex = lexer.new('ada') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abort abs accept all and begin body case declare delay do else elsif end entry - exception exit for generic goto if in is loop mod new not null or others out - protected raise record rem renames requeue reverse select separate subtype - task terminate then type until when while xor +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abort', 'abs', 'accept', 'all', 'and', 'begin', 'body', 'case', 'declare', 'delay', 'do', 'else', + 'elsif', 'end', 'entry', 'exception', 'exit', 'for', 'generic', 'goto', 'if', 'in', 'is', 'loop', + 'mod', 'new', 'not', 'null', 'or', 'others', 'out', 'protected', 'raise', 'record', 'rem', + 'renames', 'requeue', 'reverse', 'select', 'separate', 'subtype', 'task', 'terminate', 'then', + 'type', 'until', 'when', 'while', 'xor', -- Preprocessor. - package pragma use with + 'package', 'pragma', 'use', 'with', -- Function. - function procedure return + 'function', 'procedure', 'return', -- Storage class. - abstract access aliased array at constant delta digits interface limited of - private range tagged synchronized + 'abstract', 'access', 'aliased', 'array', 'at', 'constant', 'delta', 'digits', 'interface', + 'limited', 'of', 'private', 'range', 'tagged', 'synchronized', -- Boolean. - true false -]])) + 'true', 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - boolean character count duration float integer long_float long_integer - priority short_float short_integer string -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'boolean', 'character', 'count', 'duration', 'float', 'integer', 'long_float', 'long_integer', + 'priority', 'short_float', 'short_integer', 'string' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/ansi_c.lua b/syntaxhighlight/textadept/ansi_c.lua index 263d2f6..5412760 100644 --- a/syntaxhighlight/textadept/ansi_c.lua +++ b/syntaxhighlight/textadept/ansi_c.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- C LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ansi_c') @@ -13,47 +13,59 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - auto break case const continue default do else extern for goto if inline - register restrict return sizeof static switch typedef volatile while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', + 'goto', 'if', 'inline', 'register', 'restrict', 'return', 'sizeof', 'static', 'switch', 'typedef', + 'volatile', 'while', + -- C99. + 'false', 'true', -- C11. - _Alignas _Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local -]])) + '_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn', '_Static_assert', '_Thread_local', + -- Compiler. + 'asm', '__asm', '__asm__', '__restrict__', '__inline', '__inline__', '__attribute__', '__declspec' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - char double enum float int long short signed struct union unsigned void - _Bool _Complex _Imaginary +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'char', 'double', 'float', 'int', 'long', 'short', 'signed', 'struct', 'union', + 'unsigned', 'void', '_Bool', '_Complex', '_Imaginary', -- Stdlib types. - ptrdiff_t size_t max_align_t wchar_t intptr_t uintptr_t intmax_t uintmax_t -]] + P('u')^-1 * 'int' * (P('_least') + '_fast')^-1 * R('09')^1 * '_t')) + 'ptrdiff_t', 'size_t', 'max_align_t', 'wchar_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t' +} + P('u')^-1 * 'int' * (P('_least') + '_fast')^-1 * lexer.digit^1 * '_t')) -- Constants. -lex:add_rule('constants', token(lexer.CONSTANT, word_match[[ - NULL +lex:add_rule('constants', token(lexer.CONSTANT, word_match{ + 'NULL', -- Preprocessor. - __DATE__ __FILE__ __LINE__ __TIME__ __func__ + '__DATE__', '__FILE__', '__LINE__', '__TIME__', '__func__', -- errno.h. - E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF - EBADMSG EBUSY ECANCELED ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK - EDESTADDRREQ EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM EILSEQ - EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE - EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS ENODATA - ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR - ENOSTR ENOSYS ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP - ENOTTY ENXIO EOPNOTSUPP EOVERFLOW EOWNERDEAD EPERM EPIPE EPROTO - EPROTONOSUPPORT EPROTOTYPE ERANGE EROFS ESPIPE ESRCH ESTALE ETIME ETIMEDOUT - ETXTBSY EWOULDBLOCK EXDEV -]])) + 'E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADF', + 'EBADMSG', 'EBUSY', 'ECANCELED', 'ECHILD', 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', + 'EDEADLK', 'EDESTADDRREQ', 'EDOM', 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTUNREACH', 'EIDRM', + 'EILSEQ', 'EINPROGRESS', 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', 'ELOOP', 'EMFILE', + 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', + 'ENFILE', 'ENOBUFS', 'ENODATA', 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', 'ENOMEM', + 'ENOMSG', 'ENOPROTOOPT', 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTCONN', 'ENOTDIR', + 'ENOTEMPTY', 'ENOTRECOVERABLE', 'ENOTSOCK', 'ENOTSUP', 'ENOTTY', 'ENXIO', 'EOPNOTSUPP', + 'EOVERFLOW', 'EOWNERDEAD', 'EPERM', 'EPIPE', 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', 'ERANGE', + 'EROFS', 'ESPIPE', 'ESRCH', 'ESTALE', 'ETIME', 'ETIMEDOUT', 'ETXTBSY', 'EWOULDBLOCK', 'EXDEV', + -- stdint.h. + 'PTRDIFF_MIN', 'PTRDIFF_MAX', 'SIZE_MAX', 'SIG_ATOMIC_MIN', 'SIG_ATOMIC_MAX', 'WINT_MIN', + 'WINT_MAX', 'WCHAR_MIN', 'WCHAR_MAX' +} + P('U')^-1 * 'INT' * ((P('_LEAST') + '_FAST')^-1 * lexer.digit^1 + 'PTR' + 'MAX') * + (P('_MIN') + '_MAX'))) --- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) +-- Labels. +lex:add_rule('label', token(lexer.LABEL, lexer.starts_line(lexer.word * ':'))) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) local dq_str = P('L')^-1 * lexer.range('"', true) lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + -- Comments. local line_comment = lexer.to_eol('//', true) local block_comment = lexer.range('/*', '*/') + @@ -61,14 +73,15 @@ local block_comment = lexer.range('/*', '*/') + lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.number)) +local integer = lexer.integer * word_match('u l ll ul ull lu llu', true)^-1 +local float = lexer.float * P('f')^-1 +lex:add_rule('number', token(lexer.NUMBER, float + integer)) -- Preprocessor. local include = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * 'include') * (ws * token(lexer.STRING, lexer.range('<', '>', true)))^-1 -local preproc = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * word_match[[ - define elif else endif if ifdef ifndef line pragma undef -]]) +local preproc = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * + word_match('define elif else endif if ifdef ifndef line pragma undef')) lex:add_rule('preprocessor', include + preproc) -- Operators. @@ -80,6 +93,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, '#ifdef', '#endif') lex:add_fold_point(lexer.PREPROCESSOR, '#ifndef', '#endif') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/antlr.lua b/syntaxhighlight/textadept/antlr.lua index 45b034d..dd29386 100644 --- a/syntaxhighlight/textadept/antlr.lua +++ b/syntaxhighlight/textadept/antlr.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- ANTLR LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('antlr') @@ -12,18 +12,17 @@ local lex = lexer.new('antlr') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract break case catch continue default do else extends final finally for - if implements instanceof native new private protected public return static - switch synchronized throw throws transient try volatile - while package import header options tokens strictfp - false null super this true -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'break', 'case', 'catch', 'continue', 'default', 'do', 'else', 'extends', 'final', + 'finally', 'for', 'if', 'implements', 'instanceof', 'native', 'new', 'private', 'protected', + 'public', 'return', 'static', 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', + 'volatile', 'while', 'package', 'import', 'header', 'options', 'tokens', 'strictfp', 'false', + 'null', 'super', 'this', 'true' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - boolean byte char class double float int interface long short void -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'boolean byte char class double float int interface long short void'))) -- Functions. lex:add_rule('func', token(lexer.FUNCTION, 'assert')) @@ -37,9 +36,10 @@ local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Actions. -lex:add_rule('action', token(lexer.OPERATOR, P('{')) * - token('action', (1 - P('}'))^0) * token(lexer.OPERATOR, P('}'))^-1) -lex:add_style('action', lexer.STYLE_NOTHING) +local open_brace = token(lexer.OPERATOR, '{') +local close_brace = token(lexer.OPERATOR, '}') +lex:add_rule('action', open_brace * token('action', (1 - P('}'))^0) * close_brace^-1) +lex:add_style('action', lexer.styles.nothing) -- Strings. lex:add_rule('string', token(lexer.STRING, lexer.range("'", true))) @@ -52,6 +52,6 @@ lex:add_fold_point(lexer.OPERATOR, ':', ';') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/apdl.lua b/syntaxhighlight/textadept/apdl.lua index 8867c4f..9242a71 100644 --- a/syntaxhighlight/textadept/apdl.lua +++ b/syntaxhighlight/textadept/apdl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- APDL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('apdl', {case_insensitive_fold_points = true}) @@ -12,36 +12,42 @@ local lex = lexer.new('apdl', {case_insensitive_fold_points = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - *abbr *abb *afun *afu *ask *cfclos *cfc *cfopen *cfo *cfwrite *cfw *create - *cre *cycle *cyc *del *dim *do *elseif *else *enddo *endif *end *eval *eva - *exit *exi *get *go *if *list *lis *mfouri *mfo *mfun *mfu *mooney *moo *moper - *mop *msg *repeat *rep *set *status *sta *tread *tre *ulib *uli *use *vabs - *vab *vcol *vco *vcum *vcu *vedit *ved *vfact *vfa *vfill *vfi *vfun *vfu - *vget *vge *vitrp *vit *vlen *vle *vmask *vma *voper *vop *vplot *vpl *vput - *vpu *vread *vre *vscfun *vsc *vstat *vst *vwrite *vwr - /anfile /anf /angle /ang /annot /ann /anum /anu /assign /ass /auto /aut /aux15 - /aux2 /aux /axlab /axl /batch /bat /clabel /cla /clear /cle /clog /clo /cmap - /cma /color /col /com /config /contour /con /copy /cop /cplane /cpl /ctype - /cty /cval /cva /delete /del /devdisp /device /dev /dist /dis /dscale /dsc - /dv3d /dv3 /edge /edg /efacet /efa /eof /erase /era /eshape /esh /exit /exi - /expand /exp /facet /fac /fdele /fde /filname /fil /focus /foc /format /for - /ftype /fty /gcmd /gcm /gcolumn /gco /gfile /gfi /gformat /gfo /gline /gli - /gmarker /gma /golist /gol /gopr /gop /go /graphics /gra /gresume /gre /grid - /gri /gropt /gro /grtyp /grt /gsave /gsa /gst /gthk /gth /gtype /gty /header - /hea /input /inp /larc /lar /light /lig /line /lin /lspec /lsp /lsymbol /lsy - /menu /men /mplib /mpl /mrep /mre /mstart /mst /nerr /ner /noerase /noe - /nolist /nol /nopr /nop /normal /nor /number /num /opt /output /out /page /pag - /pbc /pbf /pcircle /pci /pcopy /pco /plopts /plo /pmacro /pma /pmeth /pme - /pmore /pmo /pnum /pnu /polygon /pol /post26 /post1 /pos /prep7 /pre /psearch - /pse /psf /pspec /psp /pstatus /pst /psymb /psy /pwedge /pwe /quit /qui /ratio - /rat /rename /ren /replot /rep /reset /res /rgb /runst /run /seclib /sec /seg - /shade /sha /showdisp /show /sho /shrink /shr /solu /sol /sscale /ssc /status - /sta /stitle /sti /syp /sys /title /tit /tlabel /tla /triad /tri /trlcy /trl - /tspec /tsp /type /typ /ucmd /ucm /uis /ui /units /uni /user /use /vcone /vco - /view /vie /vscale /vsc /vup /wait /wai /window /win /xrange /xra /yrange /yra - /zoom /zoo -]], true)) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + '*abbr', '*abb', '*afun', '*afu', '*ask', '*cfclos', '*cfc', '*cfopen', '*cfo', '*cfwrite', + '*cfw', '*create', '*cre', '*cycle', '*cyc', '*del', '*dim', '*do', '*elseif', '*else', '*enddo', + '*endif', '*end', '*eval', '*eva', '*exit', '*exi', '*get', '*go', '*if', '*list', '*lis', + '*mfouri', '*mfo', '*mfun', '*mfu', '*mooney', '*moo', '*moper', '*mop', '*msg', '*repeat', + '*rep', '*set', '*status', '*sta', '*tread', '*tre', '*ulib', '*uli', '*use', '*vabs', '*vab', + '*vcol', '*vco', '*vcum', '*vcu', '*vedit', '*ved', '*vfact', '*vfa', '*vfill', '*vfi', '*vfun', + '*vfu', '*vget', '*vge', '*vitrp', '*vit', '*vlen', '*vle', '*vmask', '*vma', '*voper', '*vop', + '*vplot', '*vpl', '*vput', '*vpu', '*vread', '*vre', '*vscfun', '*vsc', '*vstat', '*vst', + '*vwrite', '*vwr', -- + '/anfile', '/anf', '/angle', '/ang', '/annot', '/ann', '/anum', '/anu', '/assign', '/ass', + '/auto', '/aut', '/aux15', '/aux2', '/aux', '/axlab', '/axl', '/batch', '/bat', '/clabel', '/cla', + '/clear', '/cle', '/clog', '/clo', '/cmap', '/cma', '/color', '/col', '/com', '/config', + '/contour', '/con', '/copy', '/cop', '/cplane', '/cpl', '/ctype', '/cty', '/cval', '/cva', + '/delete', '/del', '/devdisp', '/device', '/dev', '/dist', '/dis', '/dscale', '/dsc', '/dv3d', + '/dv3', '/edge', '/edg', '/efacet', '/efa', '/eof', '/erase', '/era', '/eshape', '/esh', '/exit', + '/exi', '/expand', '/exp', '/facet', '/fac', '/fdele', '/fde', '/filname', '/fil', '/focus', + '/foc', '/format', '/for', '/ftype', '/fty', '/gcmd', '/gcm', '/gcolumn', '/gco', '/gfile', + '/gfi', '/gformat', '/gfo', '/gline', '/gli', '/gmarker', '/gma', '/golist', '/gol', '/gopr', + '/gop', '/go', '/graphics', '/gra', '/gresume', '/gre', '/grid', '/gri', '/gropt', '/gro', + '/grtyp', '/grt', '/gsave', '/gsa', '/gst', '/gthk', '/gth', '/gtype', '/gty', '/header', '/hea', + '/input', '/inp', '/larc', '/lar', '/light', '/lig', '/line', '/lin', '/lspec', '/lsp', + '/lsymbol', '/lsy', '/menu', '/men', '/mplib', '/mpl', '/mrep', '/mre', '/mstart', '/mst', + '/nerr', '/ner', '/noerase', '/noe', '/nolist', '/nol', '/nopr', '/nop', '/normal', '/nor', + '/number', '/num', '/opt', '/output', '/out', '/page', '/pag', '/pbc', '/pbf', '/pcircle', '/pci', + '/pcopy', '/pco', '/plopts', '/plo', '/pmacro', '/pma', '/pmeth', '/pme', '/pmore', '/pmo', + '/pnum', '/pnu', '/polygon', '/pol', '/post26', '/post1', '/pos', '/prep7', '/pre', '/psearch', + '/pse', '/psf', '/pspec', '/psp', '/pstatus', '/pst', '/psymb', '/psy', '/pwedge', '/pwe', + '/quit', '/qui', '/ratio', '/rat', '/rename', '/ren', '/replot', '/rep', '/reset', '/res', '/rgb', + '/runst', '/run', '/seclib', '/sec', '/seg', '/shade', '/sha', '/showdisp', '/show', '/sho', + '/shrink', '/shr', '/solu', '/sol', '/sscale', '/ssc', '/status', '/sta', '/stitle', '/sti', + '/syp', '/sys', '/title', '/tit', '/tlabel', '/tla', '/triad', '/tri', '/trlcy', '/trl', '/tspec', + '/tsp', '/type', '/typ', '/ucmd', '/ucm', '/uis', '/ui', '/units', '/uni', '/user', '/use', + '/vcone', '/vco', '/view', '/vie', '/vscale', '/vsc', '/vup', '/wait', '/wai', '/window', '/win', + '/xrange', '/xra', '/yrange', '/yra', '/zoom', '/zoo' +}, true))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -68,6 +74,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/$=,;()'))) lex:add_fold_point(lexer.KEYWORD, '*if', '*endif') lex:add_fold_point(lexer.KEYWORD, '*do', '*enddo') lex:add_fold_point(lexer.KEYWORD, '*dowhile', '*enddo') -lex:add_fold_point(lexer.COMMENT, '!', lexer.fold_line_comments('!')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('!')) return lex diff --git a/syntaxhighlight/textadept/apl.lua b/syntaxhighlight/textadept/apl.lua index 1a505d1..eee3ac0 100644 --- a/syntaxhighlight/textadept/apl.lua +++ b/syntaxhighlight/textadept/apl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 David B. Lamkins . See License.txt. +-- Copyright 2015-2021 David B. Lamkins . See LICENSE. -- APL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('apl') @@ -12,8 +12,7 @@ local lex = lexer.new('apl') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, (P('⍝') + '#') * - lexer.nonnewline^0)) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(P('⍝') + '#'))) -- Strings. local sq_str = lexer.range("'", false, false) @@ -21,23 +20,22 @@ local dq_str = lexer.range('"') lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Numbers. -local dig = R('09') +local dig = lexer.digit local rad = P('.') local exp = S('eE') local img = S('jJ') local sgn = P('¯')^-1 -local float = sgn * (dig^0 * rad * dig^1 + dig^1 * rad * dig^0 + dig^1) * - (exp * sgn *dig^1)^-1 +local float = sgn * (dig^0 * rad * dig^1 + dig^1 * rad * dig^0 + dig^1) * (exp * sgn * dig^1)^-1 lex:add_rule('number', token(lexer.NUMBER, float * img * float + float)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, P('⍞') + 'χ' + '⍺' + '⍶' + '⍵' + - '⍹' + '⎕' * R('AZ', 'az')^0)) +lex:add_rule('keyword', token(lexer.KEYWORD, + P('⍞') + 'χ' + '⍺' + '⍶' + '⍵' + '⍹' + '⎕' * lexer.alpha^0)) -- Names. -local n1l = R('AZ', 'az') +local n1l = lexer.alpha local n1b = P('_') + '∆' + '⍙' -local n2l = n1l + R('09') +local n2l = n1l + lexer.digit local n2b = n1b + '¯' local n1 = n1l + n1b local n2 = n2l + n2b diff --git a/syntaxhighlight/textadept/applescript.lua b/syntaxhighlight/textadept/applescript.lua index 88f5917..5eab481 100644 --- a/syntaxhighlight/textadept/applescript.lua +++ b/syntaxhighlight/textadept/applescript.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Applescript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('applescript') @@ -12,43 +12,43 @@ local lex = lexer.new('applescript') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - script property prop end copy to set global local on to of in given with - without return continue tell if then else repeat times while until from exit - try error considering ignoring timeout transaction my get put into is +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'script', 'property', 'prop', 'end', 'copy', 'to', 'set', 'global', 'local', 'on', 'to', 'of', + 'in', 'given', 'with', 'without', 'return', 'continue', 'tell', 'if', 'then', 'else', 'repeat', + 'times', 'while', 'until', 'from', 'exit', 'try', 'error', 'considering', 'ignoring', 'timeout', + 'transaction', 'my', 'get', 'put', 'into', 'is', -- References. - each some every whose where id index first second third fourth fifth sixth - seventh eighth ninth tenth last front back st nd rd th middle named through - thru before after beginning the + 'each', 'some', 'every', 'whose', 'where', 'id', 'index', 'first', 'second', 'third', 'fourth', + 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'last', 'front', 'back', 'st', 'nd', + 'rd', 'th', 'middle', 'named', 'through', 'thru', 'before', 'after', 'beginning', 'the', -- Commands. - close copy count delete duplicate exists launch make move open print quit - reopen run save saving + 'close', 'copy', 'count', 'delete', 'duplicate', 'exists', 'launch', 'make', 'move', 'open', + 'print', 'quit', 'reopen', 'run', 'save', 'saving', -- Operators. - div mod and not or as contains equal equals isn't -]], true)) + 'div', 'mod', 'and', 'not', 'or', 'as', 'contains', 'equal', 'equals', 'isn\'t' +}, true))) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - case diacriticals expansion hyphens punctuation +lex:add_rule('constant', token(lexer.CONSTANT, word_match({ + 'case', 'diacriticals', 'expansion', 'hyphens', 'punctuation', -- Predefined variables. - it me version pi result space tab anything + 'it', 'me', 'version', 'pi', 'result', 'space', 'tab', 'anything', -- Text styles. - bold condensed expanded hidden italic outline plain shadow strikethrough - subscript superscript underline + 'bold', 'condensed', 'expanded', 'hidden', 'italic', 'outline', 'plain', 'shadow', + 'strikethrough', 'subscript', 'superscript', 'underline', -- Save options. - ask no yes + 'ask', 'no', 'yes', -- Booleans. - false true + 'false', 'true', -- Date and time. - weekday monday mon tuesday tue wednesday wed thursday thu friday fri saturday - sat sunday sun month january jan february feb march mar april apr may june jun - july jul august aug september sep october oct november nov december dec - minutes hours days weeks -]], true)) + 'weekday', 'monday', 'mon', 'tuesday', 'tue', 'wednesday', 'wed', 'thursday', 'thu', 'friday', + 'fri', 'saturday', 'sat', 'sunday', 'sun', 'month', 'january', 'jan', 'february', 'feb', 'march', + 'mar', 'april', 'apr', 'may', 'june', 'jun', 'july', 'jul', 'august', 'aug', 'september', 'sep', + 'october', 'oct', 'november', 'nov', 'december', 'dec', 'minutes', 'hours', 'days', 'weeks' +}, true))) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * - (lexer.alnum + '_')^0)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + '_')^0)) -- Strings. lex:add_rule('string', token(lexer.STRING, lexer.range('"', true))) diff --git a/syntaxhighlight/textadept/asm.lua b/syntaxhighlight/textadept/asm.lua index 9ffd6b4..0e5e2a6 100644 --- a/syntaxhighlight/textadept/asm.lua +++ b/syntaxhighlight/textadept/asm.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- NASM Assembly LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('asm') @@ -12,310 +12,335 @@ local lex = lexer.new('asm') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- Preprocessor macros. - struc endstruc istruc at iend align alignb sectalign .nolist + 'struc', 'endstruc', 'istruc', 'at', 'iend', 'align', 'alignb', 'sectalign', '.nolist', -- Preprocessor Packages. - --altreg smartalign fp ifunc + 'altreg', 'smartalign', 'fp', 'ifunc', -- Directives. - absolute bits class common common cpu default export extern float global group - import osabi overlay private public __SECT__ section segment stack use16 use32 - use64 + 'absolute', 'bits', 'class', 'common', 'common', 'cpu', 'default', 'export', 'extern', 'float', + 'global', 'group', 'import', 'osabi', 'overlay', 'private', 'public', '__SECT__', 'section', + 'segment', 'stack', 'use16', 'use32', 'use64', -- Section Names. - .bss .comment .data .lbss .ldata .lrodata .rdata .rodata .tbss .tdata .text + '.bss', '.comment', '.data', '.lbss', '.ldata', '.lrodata', '.rdata', '.rodata', '.tbss', + '.tdata', '.text', -- Section Qualifiers. - alloc bss code exec data noalloc nobits noexec nowrite progbits rdata tls - write + 'alloc', 'bss', 'code', 'exec', 'data', 'noalloc', 'nobits', 'noexec', 'nowrite', 'progbits', + 'rdata', 'tls', 'write', -- Operators. - abs rel seg wrt strict - __utf16__ __utf16be__ __utf16le__ __utf32__ __utf32be__ __utf32le__ -]])) + 'abs', 'rel', 'seg', 'wrt', 'strict', '__utf16__', '__utf16be__', '__utf16le__', '__utf32__', + '__utf32be__', '__utf32le__' +})) -- Instructions. -- awk '{print $1}'|uniq|tr '[:upper:]' '[:lower:]'| --- lua -e "for l in io.lines() do print(\"'\"..l..\"',\") end"|fmt -w 78 -lex:add_rule('instruction', token('instruction', word_match[[ +-- lua -e "for l in io.lines() do print(\"'\"..l..\"',\") end"|fmt -w 98 +lex:add_rule('instruction', token('instruction', word_match{ -- Special Instructions. - db dd do dq dt dw dy resb resd reso resq rest resw resy + 'db', 'dd', 'do', 'dq', 'dt', 'dw', 'dy', 'resb', 'resd', 'reso', 'resq', 'rest', 'resw', 'resy', -- Conventional Instructions. - aaa aad aam aas adc add and arpl bb0_reset bb1_reset bound bsf bsr bswap bt - btc btr bts call cbw cdq cdqe clc cld cli clts cmc cmp cmpsb cmpsd cmpsq cmpsw - cmpxchg cmpxchg486 cmpxchg8b cmpxchg16b cpuid cpu_read cpu_write cqo cwd cwde - daa das dec div dmint emms enter equ f2xm1 fabs fadd faddp fbld fbstp fchs - fclex fcmovb fcmovbe fcmove fcmovnb fcmovnbe fcmovne fcmovnu fcmovu fcom fcomi - fcomip fcomp fcompp fcos fdecstp fdisi fdiv fdivp fdivr fdivrp femms feni - ffree ffreep fiadd ficom ficomp fidiv fidivr fild fimul fincstp finit fist - fistp fisttp fisub fisubr fld fld1 fldcw fldenv fldl2e fldl2t fldlg2 fldln2 - fldpi fldz fmul fmulp fnclex fndisi fneni fninit fnop fnsave fnstcw fnstenv - fnstsw fpatan fprem fprem1 fptan frndint frstor fsave fscale fsetpm fsin - fsincos fsqrt fst fstcw fstenv fstp fstsw fsub fsubp fsubr fsubrp ftst fucom - fucomi fucomip fucomp fucompp fxam fxch fxtract fyl2x fyl2xp1 hlt ibts icebp - idiv imul in inc incbin insb insd insw int int01 int1 int03 int3 into invd - invpcid invlpg invlpga iret iretd iretq iretw jcxz jecxz jrcxz jmp jmpe lahf - lar lds lea leave les lfence lfs lgdt lgs lidt lldt lmsw loadall loadall286 - lodsb lodsd lodsq lodsw loop loope loopne loopnz loopz lsl lss ltr mfence - monitor mov movd movq movsb movsd movsq movsw movsx movsxd movsx movzx mul - mwait neg nop not or out outsb outsd outsw packssdw packsswb packuswb paddb - paddd paddsb paddsiw paddsw paddusb paddusw paddw pand pandn pause paveb - pavgusb pcmpeqb pcmpeqd pcmpeqw pcmpgtb pcmpgtd pcmpgtw pdistib pf2id pfacc - pfadd pfcmpeq pfcmpge pfcmpgt pfmax pfmin pfmul pfrcp pfrcpit1 pfrcpit2 - pfrsqit1 pfrsqrt pfsub pfsubr pi2fd pmachriw pmaddwd pmagw pmulhriw pmulhrwa - pmulhrwc pmulhw pmullw pmvgezb pmvlzb pmvnzb pmvzb pop popa popad popaw popf - popfd popfq popfw por prefetch prefetchw pslld psllq psllw psrad psraw psrld - psrlq psrlw psubb psubd psubsb psubsiw psubsw psubusb psubusw psubw punpckhbw - punpckhdq punpckhwd punpcklbw punpckldq punpcklwd push pusha pushad pushaw - pushf pushfd pushfq pushfw pxor rcl rcr rdshr rdmsr rdpmc rdtsc rdtscp ret - retf retn rol ror rdm rsdc rsldt rsm rsts sahf sal salc sar sbb scasb scasd - scasq scasw sfence sgdt shl shld shr shrd sidt sldt skinit smi smint smintold - smsw stc std sti stosb stosd stosq stosw str sub svdc svldt svts swapgs - syscall sysenter sysexit sysret test ud0 ud1 ud2b ud2 ud2a umov verr verw - fwait wbinvd wrshr wrmsr xadd xbts xchg xlatb xlat xor cmovcc jcc setcc + 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl', 'bb0_reset', 'bb1_reset', 'bound', 'bsf', + 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts', 'call', 'cbw', 'cdq', 'cdqe', 'clc', 'cld', 'cli', + 'clts', 'cmc', 'cmp', 'cmpsb', 'cmpsd', 'cmpsq', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b', + 'cmpxchg16b', 'cpuid', 'cpu_read', 'cpu_write', 'cqo', 'cwd', 'cwde', 'daa', 'das', 'dec', 'div', + 'dmint', 'emms', 'enter', 'equ', 'f2xm1', 'fabs', 'fadd', 'faddp', 'fbld', 'fbstp', 'fchs', + 'fclex', 'fcmovb', 'fcmovbe', 'fcmove', 'fcmovnb', 'fcmovnbe', 'fcmovne', 'fcmovnu', 'fcmovu', + 'fcom', 'fcomi', 'fcomip', 'fcomp', 'fcompp', 'fcos', 'fdecstp', 'fdisi', 'fdiv', 'fdivp', + 'fdivr', 'fdivrp', 'femms', 'feni', 'ffree', 'ffreep', 'fiadd', 'ficom', 'ficomp', 'fidiv', + 'fidivr', 'fild', 'fimul', 'fincstp', 'finit', 'fist', 'fistp', 'fisttp', 'fisub', 'fisubr', + 'fld', 'fld1', 'fldcw', 'fldenv', 'fldl2e', 'fldl2t', 'fldlg2', 'fldln2', 'fldpi', 'fldz', 'fmul', + 'fmulp', 'fnclex', 'fndisi', 'fneni', 'fninit', 'fnop', 'fnsave', 'fnstcw', 'fnstenv', 'fnstsw', + 'fpatan', 'fprem', 'fprem1', 'fptan', 'frndint', 'frstor', 'fsave', 'fscale', 'fsetpm', 'fsin', + 'fsincos', 'fsqrt', 'fst', 'fstcw', 'fstenv', 'fstp', 'fstsw', 'fsub', 'fsubp', 'fsubr', 'fsubrp', + 'ftst', 'fucom', 'fucomi', 'fucomip', 'fucomp', 'fucompp', 'fxam', 'fxch', 'fxtract', 'fyl2x', + 'fyl2xp1', 'hlt', 'ibts', 'icebp', 'idiv', 'imul', 'in', 'inc', 'incbin', 'insb', 'insd', 'insw', + 'int', 'int01', 'int1', 'int03', 'int3', 'into', 'invd', 'invpcid', 'invlpg', 'invlpga', 'iret', + 'iretd', 'iretq', 'iretw', 'jcxz', 'jecxz', 'jrcxz', 'jmp', 'jmpe', 'lahf', 'lar', 'lds', 'lea', + 'leave', 'les', 'lfence', 'lfs', 'lgdt', 'lgs', 'lidt', 'lldt', 'lmsw', 'loadall', 'loadall286', + 'lodsb', 'lodsd', 'lodsq', 'lodsw', 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss', + 'ltr', 'mfence', 'monitor', 'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsq', 'movsw', 'movsx', + 'movsxd', 'movsx', 'movzx', 'mul', 'mwait', 'neg', 'nop', 'not', 'or', 'out', 'outsb', 'outsd', + 'outsw', 'packssdw', 'packsswb', 'packuswb', 'paddb', 'paddd', 'paddsb', 'paddsiw', 'paddsw', + 'paddusb', 'paddusw', 'paddw', 'pand', 'pandn', 'pause', 'paveb', 'pavgusb', 'pcmpeqb', 'pcmpeqd', + 'pcmpeqw', 'pcmpgtb', 'pcmpgtd', 'pcmpgtw', 'pdistib', 'pf2id', 'pfacc', 'pfadd', 'pfcmpeq', + 'pfcmpge', 'pfcmpgt', 'pfmax', 'pfmin', 'pfmul', 'pfrcp', 'pfrcpit1', 'pfrcpit2', 'pfrsqit1', + 'pfrsqrt', 'pfsub', 'pfsubr', 'pi2fd', 'pmachriw', 'pmaddwd', 'pmagw', 'pmulhriw', 'pmulhrwa', + 'pmulhrwc', 'pmulhw', 'pmullw', 'pmvgezb', 'pmvlzb', 'pmvnzb', 'pmvzb', 'pop', 'popa', 'popad', + 'popaw', 'popf', 'popfd', 'popfq', 'popfw', 'por', 'prefetch', 'prefetchw', 'pslld', 'psllq', + 'psllw', 'psrad', 'psraw', 'psrld', 'psrlq', 'psrlw', 'psubb', 'psubd', 'psubsb', 'psubsiw', + 'psubsw', 'psubusb', 'psubusw', 'psubw', 'punpckhbw', 'punpckhdq', 'punpckhwd', 'punpcklbw', + 'punpckldq', 'punpcklwd', 'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd', 'pushfq', + 'pushfw', 'pxor', 'rcl', 'rcr', 'rdshr', 'rdmsr', 'rdpmc', 'rdtsc', 'rdtscp', 'ret', 'retf', + 'retn', 'rol', 'ror', 'rdm', 'rsdc', 'rsldt', 'rsm', 'rsts', 'sahf', 'sal', 'salc', 'sar', 'sbb', + 'scasb', 'scasd', 'scasq', 'scasw', 'sfence', 'sgdt', 'shl', 'shld', 'shr', 'shrd', 'sidt', + 'sldt', 'skinit', 'smi', 'smint', 'smintold', 'smsw', 'stc', 'std', 'sti', 'stosb', 'stosd', + 'stosq', 'stosw', 'str', 'sub', 'svdc', 'svldt', 'svts', 'swapgs', 'syscall', 'sysenter', + 'sysexit', 'sysret', 'test', 'ud0', 'ud1', 'ud2b', 'ud2', 'ud2a', 'umov', 'verr', 'verw', 'fwait', + 'wbinvd', 'wrshr', 'wrmsr', 'xadd', 'xbts', 'xchg', 'xlatb', 'xlat', 'xor', 'xor', 'cmova', + 'cmovae', 'cmovb', 'cmovbe', 'cmovc', 'cmove', 'cmovg', 'cmovge', 'cmovl', 'cmovle', 'cmovna', + 'cmovnae', 'cmovnb', 'cmovnbe', 'cmovnc', 'cmovne', 'cmovng', 'cmovnge', 'cmovnl', 'cmovnle', + 'cmovno', 'cmovnp', 'cmovns', 'cmovnz', 'cmovo', 'cmovp', 'cmovpe', 'cmovpo', 'cmovs', 'cmovz', + 'cmovcc', 'ja', 'jae', 'jb', 'jbe', 'jc', 'je', 'jg', 'jge', 'jl', 'jle', 'jna', 'jnae', 'jnb', + 'jnbe', 'jnc', 'jne', 'jng', 'jnge', 'jnl', 'jnle', 'jno', 'jnp', 'jns', 'jnz', 'jo', 'jp', 'jpe', + 'jpo', 'js', 'jz', 'seta', 'setae', 'setb', 'setbe', 'setc', 'sete', 'setg', 'setge', 'setl', + 'setle', 'setna', 'setnae', 'setnb', 'setnbe', 'setnc', 'setne', 'setng', 'setnge', 'setnl', + 'setnle', 'setno', 'setnp', 'setns', 'setnz', 'seto', 'setp', 'setpe', 'setpo', 'sets', 'setz', -- Katmai Streaming SIMD instructions (SSE -- a.k.a. KNI XMM MMX2). - addps addss andnps andps cmpeqps cmpeqss cmpleps cmpless cmpltps cmpltss - cmpneqps cmpneqss cmpnleps cmpnless cmpnltps cmpnltss cmpordps cmpordss - cmpunordps cmpunordss cmpps cmpss comiss cvtpi2ps cvtps2pi cvtsi2ss cvtss2si - cvttps2pi cvttss2si divps divss ldmxcsr maxps maxss minps minss movaps movhps - movlhps movlps movhlps movmskps movntps movss movups mulps mulss orps rcpps - rcpss rsqrtps rsqrtss shufps sqrtps sqrtss stmxcsr subps subss ucomiss - unpckhps unpcklps xorps + 'addps', 'addss', 'andnps', 'andps', 'cmpeqps', 'cmpeqss', 'cmpleps', 'cmpless', 'cmpltps', + 'cmpltss', 'cmpneqps', 'cmpneqss', 'cmpnleps', 'cmpnless', 'cmpnltps', 'cmpnltss', 'cmpordps', + 'cmpordss', 'cmpunordps', 'cmpunordss', 'cmpps', 'cmpss', 'comiss', 'cvtpi2ps', 'cvtps2pi', + 'cvtsi2ss', 'cvtss2si', 'cvttps2pi', 'cvttss2si', 'divps', 'divss', 'ldmxcsr', 'maxps', 'maxss', + 'minps', 'minss', 'movaps', 'movhps', 'movlhps', 'movlps', 'movhlps', 'movmskps', 'movntps', + 'movss', 'movups', 'mulps', 'mulss', 'orps', 'rcpps', 'rcpss', 'rsqrtps', 'rsqrtss', 'shufps', + 'sqrtps', 'sqrtss', 'stmxcsr', 'subps', 'subss', 'ucomiss', 'unpckhps', 'unpcklps', 'xorps', -- Introduced in Deschutes but necessary for SSE support. - fxrstor fxrstor64 fxsave fxsave64 + 'fxrstor', 'fxrstor64', 'fxsave', 'fxsave64', -- XSAVE group (AVX and extended state). - xgetbv xsetbv xsave xsave64 xsaveopt xsaveopt64 xrstor xrstor64 + 'xgetbv', 'xsetbv', 'xsave', 'xsave64', 'xsaveopt', 'xsaveopt64', 'xrstor', 'xrstor64', -- Generic memory operations. - prefetchnta prefetcht0 prefetcht1 prefetcht2 sfence + 'prefetchnta', 'prefetcht0', 'prefetcht1', 'prefetcht2', 'sfence', -- New MMX instructions introduced in Katmai. - maskmovq movntq pavgb pavgw pextrw pinsrw pmaxsw pmaxub pminsw pminub pmovmskb - pmulhuw psadbw pshufw + 'maskmovq', 'movntq', 'pavgb', 'pavgw', 'pextrw', 'pinsrw', 'pmaxsw', 'pmaxub', 'pminsw', + 'pminub', 'pmovmskb', 'pmulhuw', 'psadbw', 'pshufw', -- AMD Enhanced 3DNow! (Athlon) instructions. - pf2iw pfnacc pfpnacc pi2fw pswapd + 'pf2iw', 'pfnacc', 'pfpnacc', 'pi2fw', 'pswapd', -- Willamette SSE2 Cacheability Instructions. - maskmovdqu clflush movntdq movnti movntpd lfence mfence + 'maskmovdqu', 'clflush', 'movntdq', 'movnti', 'movntpd', 'lfence', 'mfence', -- Willamette MMX instructions (SSE2 SIMD Integer Instructions). - movd movdqa movdqu movdq2q movq movq2dq packsswb packssdw packuswb paddb paddw - paddd paddq paddsb paddsw paddusb paddusw pand pandn pavgb pavgw pcmpeqb - pcmpeqw pcmpeqd pcmpgtb pcmpgtw pcmpgtd pextrw pinsrw pmaddwd pmaxsw pmaxub - pminsw pminub pmovmskb pmulhuw pmulhw pmullw pmuludq por psadbw pshufd pshufhw - pshuflw pslldq psllw pslld psllq psraw psrad psrldq psrlw psrld psrlq psubb - psubw psubd psubq psubsb psubsw psubusb psubusw punpckhbw punpckhwd punpckhdq - punpckhqdq punpcklbw punpcklwd punpckldq punpcklqdq pxor + 'movd', 'movdqa', 'movdqu', 'movdq2q', 'movq', 'movq2dq', 'packsswb', 'packssdw', 'packuswb', + 'paddb', 'paddw', 'paddd', 'paddq', 'paddsb', 'paddsw', 'paddusb', 'paddusw', 'pand', 'pandn', + 'pavgb', 'pavgw', 'pcmpeqb', 'pcmpeqw', 'pcmpeqd', 'pcmpgtb', 'pcmpgtw', 'pcmpgtd', 'pextrw', + 'pinsrw', 'pmaddwd', 'pmaxsw', 'pmaxub', 'pminsw', 'pminub', 'pmovmskb', 'pmulhuw', 'pmulhw', + 'pmullw', 'pmuludq', 'por', 'psadbw', 'pshufd', 'pshufhw', 'pshuflw', 'pslldq', 'psllw', 'pslld', + 'psllq', 'psraw', 'psrad', 'psrldq', 'psrlw', 'psrld', 'psrlq', 'psubb', 'psubw', 'psubd', + 'psubq', 'psubsb', 'psubsw', 'psubusb', 'psubusw', 'punpckhbw', 'punpckhwd', 'punpckhdq', + 'punpckhqdq', 'punpcklbw', 'punpcklwd', 'punpckldq', 'punpcklqdq', 'pxor', -- Willamette Streaming SIMD instructions (SSE2). - addpd addsd andnpd andpd cmpeqpd cmpeqsd cmplepd cmplesd cmpltpd cmpltsd - cmpneqpd cmpneqsd cmpnlepd cmpnlesd cmpnltpd cmpnltsd cmpordpd cmpordsd - cmpunordpd cmpunordsd cmppd cmpsd comisd cvtdq2pd cvtdq2ps cvtpd2dq cvtpd2pi - cvtpd2ps cvtpi2pd cvtps2dq cvtps2pd cvtsd2si cvtsd2ss cvtsi2sd cvtss2sd - cvttpd2pi cvttpd2dq cvttps2dq cvttsd2si divpd divsd maxpd maxsd minpd minsd - movapd movhpd movlpd movmskpd movsd movupd mulpd mulsd orpd shufpd sqrtpd - sqrtsd subpd subsd ucomisd unpckhpd unpcklpd xorpd + 'addpd', 'addsd', 'andnpd', 'andpd', 'cmpeqpd', 'cmpeqsd', 'cmplepd', 'cmplesd', 'cmpltpd', + 'cmpltsd', 'cmpneqpd', 'cmpneqsd', 'cmpnlepd', 'cmpnlesd', 'cmpnltpd', 'cmpnltsd', 'cmpordpd', + 'cmpordsd', 'cmpunordpd', 'cmpunordsd', 'cmppd', 'cmpsd', 'comisd', 'cvtdq2pd', 'cvtdq2ps', + 'cvtpd2dq', 'cvtpd2pi', 'cvtpd2ps', 'cvtpi2pd', 'cvtps2dq', 'cvtps2pd', 'cvtsd2si', 'cvtsd2ss', + 'cvtsi2sd', 'cvtss2sd', 'cvttpd2pi', 'cvttpd2dq', 'cvttps2dq', 'cvttsd2si', 'divpd', 'divsd', + 'maxpd', 'maxsd', 'minpd', 'minsd', 'movapd', 'movhpd', 'movlpd', 'movmskpd', 'movsd', 'movupd', + 'mulpd', 'mulsd', 'orpd', 'shufpd', 'sqrtpd', 'sqrtsd', 'subpd', 'subsd', 'ucomisd', 'unpckhpd', + 'unpcklpd', 'xorpd', -- Prescott New Instructions (SSE3). - addsubpd addsubps haddpd haddps hsubpd hsubps lddqu movddup movshdup movsldup + 'addsubpd', 'addsubps', 'haddpd', 'haddps', 'hsubpd', 'hsubps', 'lddqu', 'movddup', 'movshdup', + 'movsldup', -- VMX/SVM Instructions. - clgi stgi vmcall vmclear vmfunc vmlaunch vmload vmmcall vmptrld vmptrst vmread - vmresume vmrun vmsave vmwrite vmxoff vmxon + 'clgi', 'stgi', 'vmcall', 'vmclear', 'vmfunc', 'vmlaunch', 'vmload', 'vmmcall', 'vmptrld', + 'vmptrst', 'vmread', 'vmresume', 'vmrun', 'vmsave', 'vmwrite', 'vmxoff', 'vmxon', -- Extended Page Tables VMX instructions. - invept invvpid + 'invept', 'invvpid', -- Tejas New Instructions (SSSE3). - pabsb pabsw pabsd palignr phaddw phaddd phaddsw phsubw phsubd phsubsw - pmaddubsw pmulhrsw pshufb psignb psignw psignd + 'pabsb', 'pabsw', 'pabsd', 'palignr', 'phaddw', 'phaddd', 'phaddsw', 'phsubw', 'phsubd', + 'phsubsw', 'pmaddubsw', 'pmulhrsw', 'pshufb', 'psignb', 'psignw', 'psignd', -- AMD SSE4A. - extrq insertq movntsd movntss + 'extrq', 'insertq', 'movntsd', 'movntss', -- New instructions in Barcelona. - lzcnt + 'lzcnt', -- Penryn New Instructions (SSE4.1). - blendpd blendps blendvpd blendvps dppd dpps extractps insertps movntdqa - mpsadbw packusdw pblendvb pblendw pcmpeqq pextrb pextrd pextrq pextrw - phminposuw pinsrb pinsrd pinsrq pmaxsb pmaxsd pmaxud pmaxuw pminsb pminsd - pminud pminuw pmovsxbw pmovsxbd pmovsxbq pmovsxwd pmovsxwq pmovsxdq pmovzxbw - pmovzxbd pmovzxbq pmovzxwd pmovzxwq pmovzxdq pmuldq pmulld ptest roundpd - roundps roundsd roundss + 'blendpd', 'blendps', 'blendvpd', 'blendvps', 'dppd', 'dpps', 'extractps', 'insertps', 'movntdqa', + 'mpsadbw', 'packusdw', 'pblendvb', 'pblendw', 'pcmpeqq', 'pextrb', 'pextrd', 'pextrq', 'pextrw', + 'phminposuw', 'pinsrb', 'pinsrd', 'pinsrq', 'pmaxsb', 'pmaxsd', 'pmaxud', 'pmaxuw', 'pminsb', + 'pminsd', 'pminud', 'pminuw', 'pmovsxbw', 'pmovsxbd', 'pmovsxbq', 'pmovsxwd', 'pmovsxwq', + 'pmovsxdq', 'pmovzxbw', 'pmovzxbd', 'pmovzxbq', 'pmovzxwd', 'pmovzxwq', 'pmovzxdq', 'pmuldq', + 'pmulld', 'ptest', 'roundpd', 'roundps', 'roundsd', 'roundss', -- Nehalem New Instructions (SSE4.2). - crc32 pcmpestri pcmpestrm pcmpistri pcmpistrm pcmpgtq popcnt + 'crc32', 'pcmpestri', 'pcmpestrm', 'pcmpistri', 'pcmpistrm', 'pcmpgtq', 'popcnt', -- Intel SMX. - getsec + 'getsec', -- Geode (Cyrix) 3DNow! additions. - pfrcpv pfrsqrtv + 'pfrcpv', 'pfrsqrtv', -- Intel new instructions in ???. - movbe + 'movbe', -- Intel AES instructions. - aesenc aesenclast aesdec aesdeclast aesimc aeskeygenassist + 'aesenc', 'aesenclast', 'aesdec', 'aesdeclast', 'aesimc', 'aeskeygenassist', -- Intel AVX AES instructions. - vaesenc vaesenclast vaesdec vaesdeclast vaesimc vaeskeygenassist + 'vaesenc', 'vaesenclast', 'vaesdec', 'vaesdeclast', 'vaesimc', 'vaeskeygenassist', -- Intel AVX instructions. - vaddpd vaddps vaddsd vaddss vaddsubpd vaddsubps vandpd vandps vandnpd vandnps - vblendpd vblendps vblendvpd vblendvps vbroadcastss vbroadcastsd vbroadcastf128 - vcmpeq_ospd vcmpeqpd vcmplt_ospd vcmpltpd vcmple_ospd vcmplepd vcmpunord_qpd - vcmpunordpd vcmpneq_uqpd vcmpneqpd vcmpnlt_uspd vcmpnltpd vcmpnle_uspd - vcmpnlepd vcmpord_qpd vcmpordpd vcmpeq_uqpd vcmpnge_uspd vcmpngepd - vcmpngt_uspd vcmpngtpd vcmpfalse_oqpd vcmpfalsepd vcmpneq_oqpd vcmpge_ospd - vcmpgepd vcmpgt_ospd vcmpgtpd vcmptrue_uqpd vcmptruepd vcmpeq_ospd vcmplt_oqpd - vcmple_oqpd vcmpunord_spd vcmpneq_uspd vcmpnlt_uqpd vcmpnle_uqpd vcmpord_spd - vcmpeq_uspd vcmpnge_uqpd vcmpngt_uqpd vcmpfalse_ospd vcmpneq_ospd vcmpge_oqpd - vcmpgt_oqpd vcmptrue_uspd vcmppd vcmpeq_osps vcmpeqps vcmplt_osps vcmpltps - vcmple_osps vcmpleps vcmpunord_qps vcmpunordps vcmpneq_uqps vcmpneqps - vcmpnlt_usps vcmpnltps vcmpnle_usps vcmpnleps vcmpord_qps vcmpordps - vcmpeq_uqps vcmpnge_usps vcmpngeps vcmpngt_usps vcmpngtps vcmpfalse_oqps - vcmpfalseps vcmpneq_oqps vcmpge_osps vcmpgeps vcmpgt_osps vcmpgtps - vcmptrue_uqps vcmptrueps vcmpeq_osps vcmplt_oqps vcmple_oqps vcmpunord_sps - vcmpneq_usps vcmpnlt_uqps vcmpnle_uqps vcmpord_sps vcmpeq_usps vcmpnge_uqps - vcmpngt_uqps vcmpfalse_osps vcmpneq_osps vcmpge_oqps vcmpgt_oqps vcmptrue_usps - vcmpps vcmpeq_ossd vcmpeqsd vcmplt_ossd vcmpltsd vcmple_ossd vcmplesd - vcmpunord_qsd vcmpunordsd vcmpneq_uqsd vcmpneqsd vcmpnlt_ussd vcmpnltsd - vcmpnle_ussd vcmpnlesd vcmpord_qsd vcmpordsd vcmpeq_uqsd vcmpnge_ussd - vcmpngesd vcmpngt_ussd vcmpngtsd vcmpfalse_oqsd vcmpfalsesd vcmpneq_oqsd - vcmpge_ossd vcmpgesd vcmpgt_ossd vcmpgtsd vcmptrue_uqsd vcmptruesd vcmpeq_ossd - vcmplt_oqsd vcmple_oqsd vcmpunord_ssd vcmpneq_ussd vcmpnlt_uqsd vcmpnle_uqsd - vcmpord_ssd vcmpeq_ussd vcmpnge_uqsd vcmpngt_uqsd vcmpfalse_ossd vcmpneq_ossd - vcmpge_oqsd vcmpgt_oqsd vcmptrue_ussd vcmpsd vcmpeq_osss vcmpeqss vcmplt_osss - vcmpltss vcmple_osss vcmpless vcmpunord_qss vcmpunordss vcmpneq_uqss vcmpneqss - vcmpnlt_usss vcmpnltss vcmpnle_usss vcmpnless vcmpord_qss vcmpordss - vcmpeq_uqss vcmpnge_usss vcmpngess vcmpngt_usss vcmpngtss vcmpfalse_oqss - vcmpfalsess vcmpneq_oqss vcmpge_osss vcmpgess vcmpgt_osss vcmpgtss - vcmptrue_uqss vcmptruess vcmpeq_osss vcmplt_oqss vcmple_oqss vcmpunord_sss - vcmpneq_usss vcmpnlt_uqss vcmpnle_uqss vcmpord_sss vcmpeq_usss vcmpnge_uqss - vcmpngt_uqss vcmpfalse_osss vcmpneq_osss vcmpge_oqss vcmpgt_oqss vcmptrue_usss - vcmpss vcomisd vcomiss vcvtdq2pd vcvtdq2ps vcvtpd2dq vcvtpd2ps vcvtps2dq - vcvtps2pd vcvtsd2si vcvtsd2ss vcvtsi2sd vcvtsi2ss vcvtss2sd vcvtss2si - vcvttpd2dq vcvttps2dq vcvttsd2si vcvttss2si vdivpd vdivps vdivsd vdivss vdppd - vdpps vextractf128 vextractps vhaddpd vhaddps vhsubpd vhsubps vinsertf128 - vinsertps vlddqu vldqqu vlddqu vldmxcsr vmaskmovdqu vmaskmovps vmaskmovpd - vmaxpd vmaxps vmaxsd vmaxss vminpd vminps vminsd vminss vmovapd vmovaps vmovd - vmovq vmovddup vmovdqa vmovqqa vmovdqa vmovdqu vmovqqu vmovdqu vmovhlps - vmovhpd vmovhps vmovlhps vmovlpd vmovlps vmovmskpd vmovmskps vmovntdq vmovntqq - vmovntdq vmovntdqa vmovntpd vmovntps vmovsd vmovshdup vmovsldup vmovss vmovupd - vmovups vmpsadbw vmulpd vmulps vmulsd vmulss vorpd vorps vpabsb vpabsw vpabsd - vpacksswb vpackssdw vpackuswb vpackusdw vpaddb vpaddw vpaddd vpaddq vpaddsb - vpaddsw vpaddusb vpaddusw vpalignr vpand vpandn vpavgb vpavgw vpblendvb - vpblendw vpcmpestri vpcmpestrm vpcmpistri vpcmpistrm vpcmpeqb vpcmpeqw - vpcmpeqd vpcmpeqq vpcmpgtb vpcmpgtw vpcmpgtd vpcmpgtq vpermilpd vpermilps - vperm2f128 vpextrb vpextrw vpextrd vpextrq vphaddw vphaddd vphaddsw - vphminposuw vphsubw vphsubd vphsubsw vpinsrb vpinsrw vpinsrd vpinsrq vpmaddwd - vpmaddubsw vpmaxsb vpmaxsw vpmaxsd vpmaxub vpmaxuw vpmaxud vpminsb vpminsw - vpminsd vpminub vpminuw vpminud vpmovmskb vpmovsxbw vpmovsxbd vpmovsxbq - vpmovsxwd vpmovsxwq vpmovsxdq vpmovzxbw vpmovzxbd vpmovzxbq vpmovzxwd - vpmovzxwq vpmovzxdq vpmulhuw vpmulhrsw vpmulhw vpmullw vpmulld vpmuludq - vpmuldq vpor vpsadbw vpshufb vpshufd vpshufhw vpshuflw vpsignb vpsignw vpsignd - vpslldq vpsrldq vpsllw vpslld vpsllq vpsraw vpsrad vpsrlw vpsrld vpsrlq vptest - vpsubb vpsubw vpsubd vpsubq vpsubsb vpsubsw vpsubusb vpsubusw vpunpckhbw - vpunpckhwd vpunpckhdq vpunpckhqdq vpunpcklbw vpunpcklwd vpunpckldq vpunpcklqdq - vpxor vrcpps vrcpss vrsqrtps vrsqrtss vroundpd vroundps vroundsd vroundss - vshufpd vshufps vsqrtpd vsqrtps vsqrtsd vsqrtss vstmxcsr vsubpd vsubps vsubsd - vsubss vtestps vtestpd vucomisd vucomiss vunpckhpd vunpckhps vunpcklpd - vunpcklps vxorpd vxorps vzeroall vzeroupper + 'vaddpd', 'vaddps', 'vaddsd', 'vaddss', 'vaddsubpd', 'vaddsubps', 'vandpd', 'vandps', 'vandnpd', + 'vandnps', 'vblendpd', 'vblendps', 'vblendvpd', 'vblendvps', 'vbroadcastss', 'vbroadcastsd', + 'vbroadcastf128', 'vcmpeq_ospd', 'vcmpeqpd', 'vcmplt_ospd', 'vcmpltpd', 'vcmple_ospd', 'vcmplepd', + 'vcmpunord_qpd', 'vcmpunordpd', 'vcmpneq_uqpd', 'vcmpneqpd', 'vcmpnlt_uspd', 'vcmpnltpd', + 'vcmpnle_uspd', 'vcmpnlepd', 'vcmpord_qpd', 'vcmpordpd', 'vcmpeq_uqpd', 'vcmpnge_uspd', + 'vcmpngepd', 'vcmpngt_uspd', 'vcmpngtpd', 'vcmpfalse_oqpd', 'vcmpfalsepd', 'vcmpneq_oqpd', + 'vcmpge_ospd', 'vcmpgepd', 'vcmpgt_ospd', 'vcmpgtpd', 'vcmptrue_uqpd', 'vcmptruepd', + 'vcmpeq_ospd', 'vcmplt_oqpd', 'vcmple_oqpd', 'vcmpunord_spd', 'vcmpneq_uspd', 'vcmpnlt_uqpd', + 'vcmpnle_uqpd', 'vcmpord_spd', 'vcmpeq_uspd', 'vcmpnge_uqpd', 'vcmpngt_uqpd', 'vcmpfalse_ospd', + 'vcmpneq_ospd', 'vcmpge_oqpd', 'vcmpgt_oqpd', 'vcmptrue_uspd', 'vcmppd', 'vcmpeq_osps', + 'vcmpeqps', 'vcmplt_osps', 'vcmpltps', 'vcmple_osps', 'vcmpleps', 'vcmpunord_qps', 'vcmpunordps', + 'vcmpneq_uqps', 'vcmpneqps', 'vcmpnlt_usps', 'vcmpnltps', 'vcmpnle_usps', 'vcmpnleps', + 'vcmpord_qps', 'vcmpordps', 'vcmpeq_uqps', 'vcmpnge_usps', 'vcmpngeps', 'vcmpngt_usps', + 'vcmpngtps', 'vcmpfalse_oqps', 'vcmpfalseps', 'vcmpneq_oqps', 'vcmpge_osps', 'vcmpgeps', + 'vcmpgt_osps', 'vcmpgtps', 'vcmptrue_uqps', 'vcmptrueps', 'vcmpeq_osps', 'vcmplt_oqps', + 'vcmple_oqps', 'vcmpunord_sps', 'vcmpneq_usps', 'vcmpnlt_uqps', 'vcmpnle_uqps', 'vcmpord_sps', + 'vcmpeq_usps', 'vcmpnge_uqps', 'vcmpngt_uqps', 'vcmpfalse_osps', 'vcmpneq_osps', 'vcmpge_oqps', + 'vcmpgt_oqps', 'vcmptrue_usps', 'vcmpps', 'vcmpeq_ossd', 'vcmpeqsd', 'vcmplt_ossd', 'vcmpltsd', + 'vcmple_ossd', 'vcmplesd', 'vcmpunord_qsd', 'vcmpunordsd', 'vcmpneq_uqsd', 'vcmpneqsd', + 'vcmpnlt_ussd', 'vcmpnltsd', 'vcmpnle_ussd', 'vcmpnlesd', 'vcmpord_qsd', 'vcmpordsd', + 'vcmpeq_uqsd', 'vcmpnge_ussd', 'vcmpngesd', 'vcmpngt_ussd', 'vcmpngtsd', 'vcmpfalse_oqsd', + 'vcmpfalsesd', 'vcmpneq_oqsd', 'vcmpge_ossd', 'vcmpgesd', 'vcmpgt_ossd', 'vcmpgtsd', + 'vcmptrue_uqsd', 'vcmptruesd', 'vcmpeq_ossd', 'vcmplt_oqsd', 'vcmple_oqsd', 'vcmpunord_ssd', + 'vcmpneq_ussd', 'vcmpnlt_uqsd', 'vcmpnle_uqsd', 'vcmpord_ssd', 'vcmpeq_ussd', 'vcmpnge_uqsd', + 'vcmpngt_uqsd', 'vcmpfalse_ossd', 'vcmpneq_ossd', 'vcmpge_oqsd', 'vcmpgt_oqsd', 'vcmptrue_ussd', + 'vcmpsd', 'vcmpeq_osss', 'vcmpeqss', 'vcmplt_osss', 'vcmpltss', 'vcmple_osss', 'vcmpless', + 'vcmpunord_qss', 'vcmpunordss', 'vcmpneq_uqss', 'vcmpneqss', 'vcmpnlt_usss', 'vcmpnltss', + 'vcmpnle_usss', 'vcmpnless', 'vcmpord_qss', 'vcmpordss', 'vcmpeq_uqss', 'vcmpnge_usss', + 'vcmpngess', 'vcmpngt_usss', 'vcmpngtss', 'vcmpfalse_oqss', 'vcmpfalsess', 'vcmpneq_oqss', + 'vcmpge_osss', 'vcmpgess', 'vcmpgt_osss', 'vcmpgtss', 'vcmptrue_uqss', 'vcmptruess', + 'vcmpeq_osss', 'vcmplt_oqss', 'vcmple_oqss', 'vcmpunord_sss', 'vcmpneq_usss', 'vcmpnlt_uqss', + 'vcmpnle_uqss', 'vcmpord_sss', 'vcmpeq_usss', 'vcmpnge_uqss', 'vcmpngt_uqss', 'vcmpfalse_osss', + 'vcmpneq_osss', 'vcmpge_oqss', 'vcmpgt_oqss', 'vcmptrue_usss', 'vcmpss', 'vcomisd', 'vcomiss', + 'vcvtdq2pd', 'vcvtdq2ps', 'vcvtpd2dq', 'vcvtpd2ps', 'vcvtps2dq', 'vcvtps2pd', 'vcvtsd2si', + 'vcvtsd2ss', 'vcvtsi2sd', 'vcvtsi2ss', 'vcvtss2sd', 'vcvtss2si', 'vcvttpd2dq', 'vcvttps2dq', + 'vcvttsd2si', 'vcvttss2si', 'vdivpd', 'vdivps', 'vdivsd', 'vdivss', 'vdppd', 'vdpps', + 'vextractf128', 'vextractps', 'vhaddpd', 'vhaddps', 'vhsubpd', 'vhsubps', 'vinsertf128', + 'vinsertps', 'vlddqu', 'vldqqu', 'vlddqu', 'vldmxcsr', 'vmaskmovdqu', 'vmaskmovps', 'vmaskmovpd', + 'vmaxpd', 'vmaxps', 'vmaxsd', 'vmaxss', 'vminpd', 'vminps', 'vminsd', 'vminss', 'vmovapd', + 'vmovaps', 'vmovd', 'vmovq', 'vmovddup', 'vmovdqa', 'vmovqqa', 'vmovdqa', 'vmovdqu', 'vmovqqu', + 'vmovdqu', 'vmovhlps', 'vmovhpd', 'vmovhps', 'vmovlhps', 'vmovlpd', 'vmovlps', 'vmovmskpd', + 'vmovmskps', 'vmovntdq', 'vmovntqq', 'vmovntdq', 'vmovntdqa', 'vmovntpd', 'vmovntps', 'vmovsd', + 'vmovshdup', 'vmovsldup', 'vmovss', 'vmovupd', 'vmovups', 'vmpsadbw', 'vmulpd', 'vmulps', + 'vmulsd', 'vmulss', 'vorpd', 'vorps', 'vpabsb', 'vpabsw', 'vpabsd', 'vpacksswb', 'vpackssdw', + 'vpackuswb', 'vpackusdw', 'vpaddb', 'vpaddw', 'vpaddd', 'vpaddq', 'vpaddsb', 'vpaddsw', + 'vpaddusb', 'vpaddusw', 'vpalignr', 'vpand', 'vpandn', 'vpavgb', 'vpavgw', 'vpblendvb', + 'vpblendw', 'vpcmpestri', 'vpcmpestrm', 'vpcmpistri', 'vpcmpistrm', 'vpcmpeqb', 'vpcmpeqw', + 'vpcmpeqd', 'vpcmpeqq', 'vpcmpgtb', 'vpcmpgtw', 'vpcmpgtd', 'vpcmpgtq', 'vpermilpd', 'vpermilps', + 'vperm2f128', 'vpextrb', 'vpextrw', 'vpextrd', 'vpextrq', 'vphaddw', 'vphaddd', 'vphaddsw', + 'vphminposuw', 'vphsubw', 'vphsubd', 'vphsubsw', 'vpinsrb', 'vpinsrw', 'vpinsrd', 'vpinsrq', + 'vpmaddwd', 'vpmaddubsw', 'vpmaxsb', 'vpmaxsw', 'vpmaxsd', 'vpmaxub', 'vpmaxuw', 'vpmaxud', + 'vpminsb', 'vpminsw', 'vpminsd', 'vpminub', 'vpminuw', 'vpminud', 'vpmovmskb', 'vpmovsxbw', + 'vpmovsxbd', 'vpmovsxbq', 'vpmovsxwd', 'vpmovsxwq', 'vpmovsxdq', 'vpmovzxbw', 'vpmovzxbd', + 'vpmovzxbq', 'vpmovzxwd', 'vpmovzxwq', 'vpmovzxdq', 'vpmulhuw', 'vpmulhrsw', 'vpmulhw', 'vpmullw', + 'vpmulld', 'vpmuludq', 'vpmuldq', 'vpor', 'vpsadbw', 'vpshufb', 'vpshufd', 'vpshufhw', 'vpshuflw', + 'vpsignb', 'vpsignw', 'vpsignd', 'vpslldq', 'vpsrldq', 'vpsllw', 'vpslld', 'vpsllq', 'vpsraw', + 'vpsrad', 'vpsrlw', 'vpsrld', 'vpsrlq', 'vptest', 'vpsubb', 'vpsubw', 'vpsubd', 'vpsubq', + 'vpsubsb', 'vpsubsw', 'vpsubusb', 'vpsubusw', 'vpunpckhbw', 'vpunpckhwd', 'vpunpckhdq', + 'vpunpckhqdq', 'vpunpcklbw', 'vpunpcklwd', 'vpunpckldq', 'vpunpcklqdq', 'vpxor', 'vrcpps', + 'vrcpss', 'vrsqrtps', 'vrsqrtss', 'vroundpd', 'vroundps', 'vroundsd', 'vroundss', 'vshufpd', + 'vshufps', 'vsqrtpd', 'vsqrtps', 'vsqrtsd', 'vsqrtss', 'vstmxcsr', 'vsubpd', 'vsubps', 'vsubsd', + 'vsubss', 'vtestps', 'vtestpd', 'vucomisd', 'vucomiss', 'vunpckhpd', 'vunpckhps', 'vunpcklpd', + 'vunpcklps', 'vxorpd', 'vxorps', 'vzeroall', 'vzeroupper', -- Intel Carry-Less Multiplication instructions (CLMUL). - pclmullqlqdq pclmulhqlqdq pclmullqhqdq pclmulhqhqdq pclmulqdq + 'pclmullqlqdq', 'pclmulhqlqdq', 'pclmullqhqdq', 'pclmulhqhqdq', 'pclmulqdq', -- Intel AVX Carry-Less Multiplication instructions (CLMUL). - vpclmullqlqdq vpclmulhqlqdq vpclmullqhqdq vpclmulhqhqdq vpclmulqdq + 'vpclmullqlqdq', 'vpclmulhqlqdq', 'vpclmullqhqdq', 'vpclmulhqhqdq', 'vpclmulqdq', -- Intel Fused Multiply-Add instructions (FMA). - vfmadd132ps vfmadd132pd vfmadd312ps vfmadd312pd vfmadd213ps vfmadd213pd - vfmadd123ps vfmadd123pd vfmadd231ps vfmadd231pd vfmadd321ps vfmadd321pd - vfmaddsub132ps vfmaddsub132pd vfmaddsub312ps vfmaddsub312pd vfmaddsub213ps - vfmaddsub213pd vfmaddsub123ps vfmaddsub123pd vfmaddsub231ps vfmaddsub231pd - vfmaddsub321ps vfmaddsub321pd vfmsub132ps vfmsub132pd vfmsub312ps vfmsub312pd - vfmsub213ps vfmsub213pd vfmsub123ps vfmsub123pd vfmsub231ps vfmsub231pd - vfmsub321ps vfmsub321pd vfmsubadd132ps vfmsubadd132pd vfmsubadd312ps - vfmsubadd312pd vfmsubadd213ps vfmsubadd213pd vfmsubadd123ps vfmsubadd123pd - vfmsubadd231ps vfmsubadd231pd vfmsubadd321ps vfmsubadd321pd vfnmadd132ps - vfnmadd132pd vfnmadd312ps vfnmadd312pd vfnmadd213ps vfnmadd213pd vfnmadd123ps - vfnmadd123pd vfnmadd231ps vfnmadd231pd vfnmadd321ps vfnmadd321pd vfnmsub132ps - vfnmsub132pd vfnmsub312ps vfnmsub312pd vfnmsub213ps vfnmsub213pd vfnmsub123ps - vfnmsub123pd vfnmsub231ps vfnmsub231pd vfnmsub321ps vfnmsub321pd vfmadd132ss - vfmadd132sd vfmadd312ss vfmadd312sd vfmadd213ss vfmadd213sd vfmadd123ss - vfmadd123sd vfmadd231ss vfmadd231sd vfmadd321ss vfmadd321sd vfmsub132ss - vfmsub132sd vfmsub312ss vfmsub312sd vfmsub213ss vfmsub213sd vfmsub123ss - vfmsub123sd vfmsub231ss vfmsub231sd vfmsub321ss vfmsub321sd vfnmadd132ss - vfnmadd132sd vfnmadd312ss vfnmadd312sd vfnmadd213ss vfnmadd213sd vfnmadd123ss - vfnmadd123sd vfnmadd231ss vfnmadd231sd vfnmadd321ss vfnmadd321sd vfnmsub132ss - vfnmsub132sd vfnmsub312ss vfnmsub312sd vfnmsub213ss vfnmsub213sd vfnmsub123ss - vfnmsub123sd vfnmsub231ss vfnmsub231sd vfnmsub321ss vfnmsub321sd + 'vfmadd132ps', 'vfmadd132pd', 'vfmadd312ps', 'vfmadd312pd', 'vfmadd213ps', 'vfmadd213pd', + 'vfmadd123ps', 'vfmadd123pd', 'vfmadd231ps', 'vfmadd231pd', 'vfmadd321ps', 'vfmadd321pd', + 'vfmaddsub132ps', 'vfmaddsub132pd', 'vfmaddsub312ps', 'vfmaddsub312pd', 'vfmaddsub213ps', + 'vfmaddsub213pd', 'vfmaddsub123ps', 'vfmaddsub123pd', 'vfmaddsub231ps', 'vfmaddsub231pd', + 'vfmaddsub321ps', 'vfmaddsub321pd', 'vfmsub132ps', 'vfmsub132pd', 'vfmsub312ps', 'vfmsub312pd', + 'vfmsub213ps', 'vfmsub213pd', 'vfmsub123ps', 'vfmsub123pd', 'vfmsub231ps', 'vfmsub231pd', + 'vfmsub321ps', 'vfmsub321pd', 'vfmsubadd132ps', 'vfmsubadd132pd', 'vfmsubadd312ps', + 'vfmsubadd312pd', 'vfmsubadd213ps', 'vfmsubadd213pd', 'vfmsubadd123ps', 'vfmsubadd123pd', + 'vfmsubadd231ps', 'vfmsubadd231pd', 'vfmsubadd321ps', 'vfmsubadd321pd', 'vfnmadd132ps', + 'vfnmadd132pd', 'vfnmadd312ps', 'vfnmadd312pd', 'vfnmadd213ps', 'vfnmadd213pd', 'vfnmadd123ps', + 'vfnmadd123pd', 'vfnmadd231ps', 'vfnmadd231pd', 'vfnmadd321ps', 'vfnmadd321pd', 'vfnmsub132ps', + 'vfnmsub132pd', 'vfnmsub312ps', 'vfnmsub312pd', 'vfnmsub213ps', 'vfnmsub213pd', 'vfnmsub123ps', + 'vfnmsub123pd', 'vfnmsub231ps', 'vfnmsub231pd', 'vfnmsub321ps', 'vfnmsub321pd', 'vfmadd132ss', + 'vfmadd132sd', 'vfmadd312ss', 'vfmadd312sd', 'vfmadd213ss', 'vfmadd213sd', 'vfmadd123ss', + 'vfmadd123sd', 'vfmadd231ss', 'vfmadd231sd', 'vfmadd321ss', 'vfmadd321sd', 'vfmsub132ss', + 'vfmsub132sd', 'vfmsub312ss', 'vfmsub312sd', 'vfmsub213ss', 'vfmsub213sd', 'vfmsub123ss', + 'vfmsub123sd', 'vfmsub231ss', 'vfmsub231sd', 'vfmsub321ss', 'vfmsub321sd', 'vfnmadd132ss', + 'vfnmadd132sd', 'vfnmadd312ss', 'vfnmadd312sd', 'vfnmadd213ss', 'vfnmadd213sd', 'vfnmadd123ss', + 'vfnmadd123sd', 'vfnmadd231ss', 'vfnmadd231sd', 'vfnmadd321ss', 'vfnmadd321sd', 'vfnmsub132ss', + 'vfnmsub132sd', 'vfnmsub312ss', 'vfnmsub312sd', 'vfnmsub213ss', 'vfnmsub213sd', 'vfnmsub123ss', + 'vfnmsub123sd', 'vfnmsub231ss', 'vfnmsub231sd', 'vfnmsub321ss', 'vfnmsub321sd', -- Intel post-32 nm processor instructions. - rdfsbase rdgsbase rdrand wrfsbase wrgsbase vcvtph2ps vcvtps2ph adcx adox - rdseed clac stac + 'rdfsbase', 'rdgsbase', 'rdrand', 'wrfsbase', 'wrgsbase', 'vcvtph2ps', 'vcvtps2ph', 'adcx', + 'adox', 'rdseed', 'clac', 'stac', -- VIA (Centaur) security instructions. - xstore xcryptecb xcryptcbc xcryptctr xcryptcfb xcryptofb montmul xsha1 xsha256 + 'xstore', 'xcryptecb', 'xcryptcbc', 'xcryptctr', 'xcryptcfb', 'xcryptofb', 'montmul', 'xsha1', + 'xsha256', -- AMD Lightweight Profiling (LWP) instructions. - llwpcb slwpcb lwpval lwpins + 'llwpcb', 'slwpcb', 'lwpval', 'lwpins', -- AMD XOP and FMA4 instructions (SSE5). - vfmaddpd vfmaddps vfmaddsd vfmaddss vfmaddsubpd vfmaddsubps vfmsubaddpd - vfmsubaddps vfmsubpd vfmsubps vfmsubsd vfmsubss vfnmaddpd vfnmaddps vfnmaddsd - vfnmaddss vfnmsubpd vfnmsubps vfnmsubsd vfnmsubss vfrczpd vfrczps vfrczsd - vfrczss vpcmov vpcomb vpcomd vpcomq vpcomub vpcomud vpcomuq vpcomuw vpcomw - vphaddbd vphaddbq vphaddbw vphadddq vphaddubd vphaddubq vphaddubw vphaddudq - vphadduwd vphadduwq vphaddwd vphaddwq vphsubbw vphsubdq vphsubwd vpmacsdd - vpmacsdqh vpmacsdql vpmacssdd vpmacssdqh vpmacssdql vpmacsswd vpmacssww - vpmacswd vpmacsww vpmadcsswd vpmadcswd vpperm vprotb vprotd vprotq vprotw - vpshab vpshad vpshaq vpshaw vpshlb vpshld vpshlq vpshlw + 'vfmaddpd', 'vfmaddps', 'vfmaddsd', 'vfmaddss', 'vfmaddsubpd', 'vfmaddsubps', 'vfmsubaddpd', + 'vfmsubaddps', 'vfmsubpd', 'vfmsubps', 'vfmsubsd', 'vfmsubss', 'vfnmaddpd', 'vfnmaddps', + 'vfnmaddsd', 'vfnmaddss', 'vfnmsubpd', 'vfnmsubps', 'vfnmsubsd', 'vfnmsubss', 'vfrczpd', + 'vfrczps', 'vfrczsd', 'vfrczss', 'vpcmov', 'vpcomb', 'vpcomd', 'vpcomq', 'vpcomub', 'vpcomud', + 'vpcomuq', 'vpcomuw', 'vpcomw', 'vphaddbd', 'vphaddbq', 'vphaddbw', 'vphadddq', 'vphaddubd', + 'vphaddubq', 'vphaddubw', 'vphaddudq', 'vphadduwd', 'vphadduwq', 'vphaddwd', 'vphaddwq', + 'vphsubbw', 'vphsubdq', 'vphsubwd', 'vpmacsdd', 'vpmacsdqh', 'vpmacsdql', 'vpmacssdd', + 'vpmacssdqh', 'vpmacssdql', 'vpmacsswd', 'vpmacssww', 'vpmacswd', 'vpmacsww', 'vpmadcsswd', + 'vpmadcswd', 'vpperm', 'vprotb', 'vprotd', 'vprotq', 'vprotw', 'vpshab', 'vpshad', 'vpshaq', + 'vpshaw', 'vpshlb', 'vpshld', 'vpshlq', 'vpshlw', -- Intel AVX2 instructions. - vmpsadbw vpabsb vpabsw vpabsd vpacksswb vpackssdw vpackusdw vpackuswb vpaddb - vpaddw vpaddd vpaddq vpaddsb vpaddsw vpaddusb vpaddusw vpalignr vpand vpandn - vpavgb vpavgw vpblendvb vpblendw vpcmpeqb vpcmpeqw vpcmpeqd vpcmpeqq vpcmpgtb - vpcmpgtw vpcmpgtd vpcmpgtq vphaddw vphaddd vphaddsw vphsubw vphsubd vphsubsw - vpmaddubsw vpmaddwd vpmaxsb vpmaxsw vpmaxsd vpmaxub vpmaxuw vpmaxud vpminsb - vpminsw vpminsd vpminub vpminuw vpminud vpmovmskb vpmovsxbw vpmovsxbd - vpmovsxbq vpmovsxwd vpmovsxwq vpmovsxdq vpmovzxbw vpmovzxbd vpmovzxbq - vpmovzxwd vpmovzxwq vpmovzxdq vpmuldq vpmulhrsw vpmulhuw vpmulhw vpmullw - vpmulld vpmuludq vpor vpsadbw vpshufb vpshufd vpshufhw vpshuflw vpsignb - vpsignw vpsignd vpslldq vpsllw vpslld vpsllq vpsraw vpsrad vpsrldq vpsrlw - vpsrld vpsrlq vpsubb vpsubw vpsubd vpsubq vpsubsb vpsubsw vpsubusb vpsubusw - vpunpckhbw vpunpckhwd vpunpckhdq vpunpckhqdq vpunpcklbw vpunpcklwd vpunpckldq - vpunpcklqdq vpxor vmovntdqa vbroadcastss vbroadcastsd vbroadcasti128 vpblendd - vpbroadcastb vpbroadcastw vpbroadcastd vpbroadcastq vpermd vpermpd vpermps - vpermq vperm2i128 vextracti128 vinserti128 vpmaskmovd vpmaskmovq vpmaskmovd - vpmaskmovq vpsllvd vpsllvq vpsllvd vpsllvq vpsravd vpsrlvd vpsrlvq vpsrlvd - vpsrlvq vgatherdpd vgatherqpd vgatherdpd vgatherqpd vgatherdps vgatherqps - vgatherdps vgatherqps vpgatherdd vpgatherqd vpgatherdd vpgatherqd vpgatherdq - vpgatherqq vpgatherdq vpgatherqq + 'vmpsadbw', 'vpabsb', 'vpabsw', 'vpabsd', 'vpacksswb', 'vpackssdw', 'vpackusdw', 'vpackuswb', + 'vpaddb', 'vpaddw', 'vpaddd', 'vpaddq', 'vpaddsb', 'vpaddsw', 'vpaddusb', 'vpaddusw', 'vpalignr', + 'vpand', 'vpandn', 'vpavgb', 'vpavgw', 'vpblendvb', 'vpblendw', 'vpcmpeqb', 'vpcmpeqw', + 'vpcmpeqd', 'vpcmpeqq', 'vpcmpgtb', 'vpcmpgtw', 'vpcmpgtd', 'vpcmpgtq', 'vphaddw', 'vphaddd', + 'vphaddsw', 'vphsubw', 'vphsubd', 'vphsubsw', 'vpmaddubsw', 'vpmaddwd', 'vpmaxsb', 'vpmaxsw', + 'vpmaxsd', 'vpmaxub', 'vpmaxuw', 'vpmaxud', 'vpminsb', 'vpminsw', 'vpminsd', 'vpminub', 'vpminuw', + 'vpminud', 'vpmovmskb', 'vpmovsxbw', 'vpmovsxbd', 'vpmovsxbq', 'vpmovsxwd', 'vpmovsxwq', + 'vpmovsxdq', 'vpmovzxbw', 'vpmovzxbd', 'vpmovzxbq', 'vpmovzxwd', 'vpmovzxwq', 'vpmovzxdq', + 'vpmuldq', 'vpmulhrsw', 'vpmulhuw', 'vpmulhw', 'vpmullw', 'vpmulld', 'vpmuludq', 'vpor', + 'vpsadbw', 'vpshufb', 'vpshufd', 'vpshufhw', 'vpshuflw', 'vpsignb', 'vpsignw', 'vpsignd', + 'vpslldq', 'vpsllw', 'vpslld', 'vpsllq', 'vpsraw', 'vpsrad', 'vpsrldq', 'vpsrlw', 'vpsrld', + 'vpsrlq', 'vpsubb', 'vpsubw', 'vpsubd', 'vpsubq', 'vpsubsb', 'vpsubsw', 'vpsubusb', 'vpsubusw', + 'vpunpckhbw', 'vpunpckhwd', 'vpunpckhdq', 'vpunpckhqdq', 'vpunpcklbw', 'vpunpcklwd', 'vpunpckldq', + 'vpunpcklqdq', 'vpxor', 'vmovntdqa', 'vbroadcastss', 'vbroadcastsd', 'vbroadcasti128', 'vpblendd', + 'vpbroadcastb', 'vpbroadcastw', 'vpbroadcastd', 'vpbroadcastq', 'vpermd', 'vpermpd', 'vpermps', + 'vpermq', 'vperm2i128', 'vextracti128', 'vinserti128', 'vpmaskmovd', 'vpmaskmovq', 'vpmaskmovd', + 'vpmaskmovq', 'vpsllvd', 'vpsllvq', 'vpsllvd', 'vpsllvq', 'vpsravd', 'vpsrlvd', 'vpsrlvq', + 'vpsrlvd', 'vpsrlvq', 'vgatherdpd', 'vgatherqpd', 'vgatherdpd', 'vgatherqpd', 'vgatherdps', + 'vgatherqps', 'vgatherdps', 'vgatherqps', 'vpgatherdd', 'vpgatherqd', 'vpgatherdd', 'vpgatherqd', + 'vpgatherdq', 'vpgatherqq', 'vpgatherdq', 'vpgatherqq', -- Transactional Synchronization Extensions (TSX). - xabort xbegin xend xtest + 'xabort', 'xbegin', 'xend', 'xtest', -- Intel BMI1 and BMI2 instructions AMD TBM instructions. - andn bextr blci blcic blsi blsic blcfill blsfill blcmsk blsmsk blsr blcs bzhi - mulx pdep pext rorx sarx shlx shrx tzcnt tzmsk t1mskc + 'andn', 'bextr', 'blci', 'blcic', 'blsi', 'blsic', 'blcfill', 'blsfill', 'blcmsk', 'blsmsk', + 'blsr', 'blcs', 'bzhi', 'mulx', 'pdep', 'pext', 'rorx', 'sarx', 'shlx', 'shrx', 'tzcnt', 'tzmsk', + 't1mskc', -- Systematic names for the hinting nop instructions. - hint_nop0 hint_nop1 hint_nop2 hint_nop3 hint_nop4 hint_nop5 hint_nop6 - hint_nop7 hint_nop8 hint_nop9 hint_nop10 hint_nop11 hint_nop12 hint_nop13 - hint_nop14 hint_nop15 hint_nop16 hint_nop17 hint_nop18 hint_nop19 hint_nop20 - hint_nop21 hint_nop22 hint_nop23 hint_nop24 hint_nop25 hint_nop26 hint_nop27 - hint_nop28 hint_nop29 hint_nop30 hint_nop31 hint_nop32 hint_nop33 hint_nop34 - hint_nop35 hint_nop36 hint_nop37 hint_nop38 hint_nop39 hint_nop40 hint_nop41 - hint_nop42 hint_nop43 hint_nop44 hint_nop45 hint_nop46 hint_nop47 hint_nop48 - hint_nop49 hint_nop50 hint_nop51 hint_nop52 hint_nop53 hint_nop54 hint_nop55 - hint_nop56 hint_nop57 hint_nop58 hint_nop59 hint_nop60 hint_nop61 hint_nop62 - hint_nop63 -]])) -lex:add_style('instruction', lexer.STYLE_FUNCTION) + 'hint_nop0', 'hint_nop1', 'hint_nop2', 'hint_nop3', 'hint_nop4', 'hint_nop5', 'hint_nop6', + 'hint_nop7', 'hint_nop8', 'hint_nop9', 'hint_nop10', 'hint_nop11', 'hint_nop12', 'hint_nop13', + 'hint_nop14', 'hint_nop15', 'hint_nop16', 'hint_nop17', 'hint_nop18', 'hint_nop19', 'hint_nop20', + 'hint_nop21', 'hint_nop22', 'hint_nop23', 'hint_nop24', 'hint_nop25', 'hint_nop26', 'hint_nop27', + 'hint_nop28', 'hint_nop29', 'hint_nop30', 'hint_nop31', 'hint_nop32', 'hint_nop33', 'hint_nop34', + 'hint_nop35', 'hint_nop36', 'hint_nop37', 'hint_nop38', 'hint_nop39', 'hint_nop40', 'hint_nop41', + 'hint_nop42', 'hint_nop43', 'hint_nop44', 'hint_nop45', 'hint_nop46', 'hint_nop47', 'hint_nop48', + 'hint_nop49', 'hint_nop50', 'hint_nop51', 'hint_nop52', 'hint_nop53', 'hint_nop54', 'hint_nop55', + 'hint_nop56', 'hint_nop57', 'hint_nop58', 'hint_nop59', 'hint_nop60', 'hint_nop61', 'hint_nop62', + 'hint_nop63' +})) +lex:add_style('instruction', lexer.styles['function']) -- Registers. -lex:add_rule('register', token('register', word_match[[ +lex:add_rule('register', token('register', word_match{ -- 32-bit registers. - ah al ax bh bl bp bx ch cl cx dh di dl dx eax ebx ebx ecx edi edx esi esp fs - mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 si st0 st1 st2 st3 st4 st5 st6 st7 xmm0 xmm1 - xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 ymm0 ymm1 ymm2 ymm3 ymm4 ymm5 ymm6 ymm7 + 'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cx', 'dh', 'di', 'dl', 'dx', 'eax', 'ebx', + 'ebx', 'ecx', 'edi', 'edx', 'esi', 'esp', 'fs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6', + 'mm7', 'si', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5', 'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', + 'xmm3', 'xmm4', 'xmm5', 'xmm6', 'xmm7', 'ymm0', 'ymm1', 'ymm2', 'ymm3', 'ymm4', 'ymm5', 'ymm6', + 'ymm7', -- 64-bit registers. - bpl dil gs r8 r8b r8w r9 r9b r9w r10 r10b r10w r11 r11b r11w r12 r12b r12w r13 - r13b r13w r14 r14b r14w r15 r15b r15w rax rbp rbx rcx rdi rdx rsi rsp sil xmm8 - xmm9 xmm10 xmm11 xmm12 xmm13 xmm14 xmm15 ymm8 ymm9 ymm10 ymm11 ymm12 ymm13 - ymm14 ymm15 -]])) -lex:add_style('register', lexer.STYLE_CONSTANT) + 'bpl', 'dil', 'gs', 'r8', 'r8b', 'r8w', 'r9', 'r9b', 'r9w', 'r10', 'r10b', 'r10w', 'r11', 'r11b', + 'r11w', 'r12', 'r12b', 'r12w', 'r13', 'r13b', 'r13w', 'r14', 'r14b', 'r14w', 'r15', 'r15b', + 'r15w', 'rax', 'rbp', 'rbx', 'rcx', 'rdi', 'rdx', 'rsi', 'rsp', 'sil', 'xmm8', 'xmm9', 'xmm10', + 'xmm11', 'xmm12', 'xmm13', 'xmm14', 'xmm15', 'ymm8', 'ymm9', 'ymm10', 'ymm11', 'ymm12', 'ymm13', + 'ymm14', 'ymm15' +})) +lex:add_style('register', lexer.styles.constant) -- Types. -local sizes = word_match[[ - byte word dword qword tword oword yword - a16 a32 a64 o16 o32 o64 -- instructions -]] -local wrt_types = '..' * word_match[[ - start gotpc gotoff gottpoff got plt sym tlsie -]] +local sizes = word_match{ + 'byte', 'word', 'dword', 'qword', 'tword', 'oword', 'yword', + -- Instructions. + 'a16', 'a32', 'a64', 'o16', 'o32', 'o64' +} +local wrt_types = '..' * word_match('start gotpc gotoff gottpoff got plt sym tlsie') lex:add_rule('type', token(lexer.TYPE, sizes + wrt_types)) -local word = (lexer.alpha + S('$._?')) * (lexer.alnum + S('$._?#@~'))^0 - -- Constants. -local constants = word_match[[ - __float128h__ __float128l__ __float16__ __float32__ __float64__ __float8__ - __float80e__ __float80m__ __Infinity__ __NaN__ __QNaN__ __SNaN__ -]] -lex:add_rule('constant', token(lexer.CONSTANT, constants + - '$' * P('$')^-1 * -word)) +local word = (lexer.alpha + S('$._?')) * (lexer.alnum + S('$._?#@~'))^0 +local constants = word_match{ + '__float128h__', '__float128l__', '__float16__', '__float32__', '__float64__', '__float8__', + '__float80e__', '__float80m__', '__Infinity__', '__NaN__', '__QNaN__', '__SNaN__' +} +lex:add_rule('constant', token(lexer.CONSTANT, constants + '$' * P('$')^-1 * -word)) -- Labels. lex:add_rule('label', token(lexer.LABEL, word * ':')) @@ -335,18 +360,20 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(';'))) lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('hqb')^-1)) -- Preprocessor. -local pp_word = word_match[[ - arg assign clear define defstr deftok depend elif elifctx elifdef elifempty - elifenv elifid elifidn elifidni elifmacro elifn elifnctx elifndef elifnempty - elifnenv elifnid elifnidn elifnidni elifnmacro elifnnum elifnstr elifntoken - elifnum elifstr eliftoken else endif endmacro endrep endwhile error exitmacro - exitrep exitwhile fatal final idefine idefstr ideftok if ifctx ifdef ifempty - ifenv ifid ifidn ifidni ifmacro ifn ifnctx ifndef ifnempty ifnenv ifnid ifnidn - ifnidni ifnmacro ifnnum ifnstr ifntoken ifnum ifstr iftoken imacro include - ixdefine line local macro pathsearch pop push rep repl rmacro rotate stacksize - strcat strlen substr undef unmacro use warning while xdefine -]] -local pp_symbol = '??' + S('!$+?') + '%' * -lexer.space + R('09')^1 +local pp_word = word_match{ + 'arg', 'assign', 'clear', 'define', 'defstr', 'deftok', 'depend', 'elif', 'elifctx', 'elifdef', + 'elifempty', 'elifenv', 'elifid', 'elifidn', 'elifidni', 'elifmacro', 'elifn', 'elifnctx', + 'elifndef', 'elifnempty', 'elifnenv', 'elifnid', 'elifnidn', 'elifnidni', 'elifnmacro', + 'elifnnum', 'elifnstr', 'elifntoken', 'elifnum', 'elifstr', 'eliftoken', 'else', 'endif', + 'endmacro', 'endrep', 'endwhile', 'error', 'exitmacro', 'exitrep', 'exitwhile', 'fatal', 'final', + 'idefine', 'idefstr', 'ideftok', 'if', 'ifctx', 'ifdef', 'ifempty', 'ifenv', 'ifid', 'ifidn', + 'ifidni', 'ifmacro', 'ifn', 'ifnctx', 'ifndef', 'ifnempty', 'ifnenv', 'ifnid', 'ifnidn', + 'ifnidni', 'ifnmacro', 'ifnnum', 'ifnstr', 'ifntoken', 'ifnum', 'ifstr', 'iftoken', 'imacro', + 'include', 'ixdefine', 'line', 'local', 'macro', 'pathsearch', 'pop', 'push', 'rep', 'repl', + 'rmacro', 'rotate', 'stacksize', 'strcat', 'strlen', 'substr', 'undef', 'unmacro', 'use', + 'warning', 'while', 'xdefine' +} +local pp_symbol = '??' + S('!$+?') + '%' * -lexer.space + lexer.digit^1 lex:add_rule('preproc', token(lexer.PREPROCESSOR, '%' * (pp_word + pp_symbol))) -- Operators. @@ -358,6 +385,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, '%macro', '%endmacro') lex:add_fold_point(lexer.PREPROCESSOR, '%rep', '%endrep') lex:add_fold_point(lexer.PREPROCESSOR, '%while', '%endwhile') lex:add_fold_point(lexer.KEYWORD, 'struc', 'endstruc') -lex:add_fold_point(lexer.COMMENT, ';', lexer.fold_line_comments(';')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines(';')) return lex diff --git a/syntaxhighlight/textadept/asp.lua b/syntaxhighlight/textadept/asp.lua index 389b3a3..2132534 100644 --- a/syntaxhighlight/textadept/asp.lua +++ b/syntaxhighlight/textadept/asp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- ASP LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local html = lexer.load('html') local lex = lexer.new('asp', {inherit = html}) -- proxy for HTML @@ -14,19 +14,16 @@ local vb = lexer.load('vb') local vb_start_rule = token('asp_tag', '<%' * P('=')^-1) local vb_end_rule = token('asp_tag', '%>') lex:embed(vb, vb_start_rule, vb_end_rule) -lex:add_style('asp_tag', lexer.STYLE_EMBEDDED) +lex:add_style('asp_tag', lexer.styles.embedded) -- Embedded VBScript. -local vbs = lexer.load('vbscript') +local vbs = lexer.load('vb', 'vbscript') local script_element = word_match('script', true) local vbs_start_rule = #(P('<') * script_element * (P(function(input, index) if input:find('^%s+language%s*=%s*(["\'])vbscript%1', index) or - input:find('^%s+type%s*=%s*(["\'])text/vbscript%1', index) then - return index - end + input:find('^%s+type%s*=%s*(["\'])text/vbscript%1', index) then return index end end) + '>')) * html.embed_start_tag -- +local vbs_end_rule = #('') * html.embed_end_tag -- lex:embed(vbs, vbs_start_rule, vbs_end_rule) -- Fold points. diff --git a/syntaxhighlight/textadept/autoit.lua b/syntaxhighlight/textadept/autoit.lua index fcc8e9b..df8765f 100644 --- a/syntaxhighlight/textadept/autoit.lua +++ b/syntaxhighlight/textadept/autoit.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- AutoIt LPeg lexer. -- Contributed by Jeff Stone. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('autoit') @@ -13,101 +13,100 @@ local lex = lexer.new('autoit') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - False True And Or Not ContinueCase ContinueLoop Default Dim Global Local Const - Do Until Enum Exit ExitLoop For To Step Next In Func Return EndFunc If Then - ElseIf Else EndIf Null ReDim Select Case EndSelect Static Switch EndSwitch - Volatile While WEnd With EndWith -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'False', 'True', 'And', 'Or', 'Not', 'ContinueCase', 'ContinueLoop', 'Default', 'Dim', 'Global', + 'Local', 'Const', 'Do', 'Until', 'Enum', 'Exit', 'ExitLoop', 'For', 'To', 'Step', 'Next', 'In', + 'Func', 'Return', 'EndFunc', 'If', 'Then', 'ElseIf', 'Else', 'EndIf', 'Null', 'ReDim', 'Select', + 'Case', 'EndSelect', 'Static', 'Switch', 'EndSwitch', 'Volatile', 'While', 'WEnd', 'With', + 'EndWith' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ - Abs ACos AdlibRegister AdlibUnRegister Asc AscW ASin Assign ATan - AutoItSetOption AutoItWinGetTitle AutoItWinSetTitle Beep Binary BinaryLen - BinaryMid BinaryToString BitAND BitNOT BitOR BitRotate BitShift BitXOR - BlockInput Break Call CDTray Ceiling Chr ChrW ClipGet ClipPut ConsoleRead - ConsoleWrite ConsoleWriteError ControlClick ControlCommand ControlDisable - ControlEnable ControlFocus ControlGetFocus ControlGetHandle ControlGetPos - ControlGetText ControlHide ControlListView ControlMove ControlSend - ControlSetText ControlShow ControlTreeView Cos Dec DirCopy DirCreate - DirGetSize DirMove DirRemove DllCall DllCallAddress DllCallbackFree - DllCallbackGetPtr DllCallbackRegister DllClose DllOpen DllStructCreate - DllStructGetData DllStructGetPtr DllStructGetSize DllStructSetData - DriveGetDrive DriveGetFileSystem DriveGetLabel DriveGetSerial DriveGetType - DriveMapAdd DriveMapDel DriveMapGet DriveSetLabel DriveSpaceFree - DriveSpaceTotal DriveStatus EnvGet EnvSet EnvUpdate Eval Execute Exp - FileChangeDir FileClose FileCopy FileCreateNTFSLink FileCreateShortcut - FileDelete FileExists FileFindFirstFile FileFindNextFile FileFlush - FileGetAttrib FileGetEncoding FileGetLongName FileGetPos FileGetShortcut - FileGetShortName FileGetSize FileGetTime FileGetVersion FileInstall FileMove - FileOpen FileOpenDialog FileRead FileReadLine FileReadToArray FileRecycle - FileRecycleEmpty FileSaveDialog FileSelectFolder FileSetAttrib FileSetEnd - FileSetPos FileSetTime FileWrite FileWriteLine Floor FtpSetProxy FuncName - GUICreate GUICtrlCreateAvi GUICtrlCreateButton GUICtrlCreateCheckbox - GUICtrlCreateCombo GUICtrlCreateContextMenu GUICtrlCreateDate - GUICtrlCreateDummy GUICtrlCreateEdit GUICtrlCreateGraphic GUICtrlCreateGroup - GUICtrlCreateIcon GUICtrlCreateInput GUICtrlCreateLabel GUICtrlCreateList - GUICtrlCreateListView GUICtrlCreateListViewItem GUICtrlCreateMenu - GUICtrlCreateMenuItem GUICtrlCreateMonthCal GUICtrlCreateObj GUICtrlCreatePic - GUICtrlCreateProgress GUICtrlCreateRadio GUICtrlCreateSlider GUICtrlCreateTab - GUICtrlCreateTabItem GUICtrlCreateTreeView GUICtrlCreateTreeViewItem - GUICtrlCreateUpdown GUICtrlDelete GUICtrlGetHandle GUICtrlGetState GUICtrlRead - GUICtrlRecvMsg GUICtrlRegisterListViewSort GUICtrlSendMsg GUICtrlSendToDummy - GUICtrlSetBkColor GUICtrlSetColor GUICtrlSetCursor GUICtrlSetData - GUICtrlSetDefBkColor GUICtrlSetDefColor GUICtrlSetFont GUICtrlSetGraphic - GUICtrlSetImage GUICtrlSetLimit GUICtrlSetOnEvent GUICtrlSetPos - GUICtrlSetResizing GUICtrlSetState GUICtrlSetStyle GUICtrlSetTip GUIDelete - GUIGetCursorInfo GUIGetMsg GUIGetStyle GUIRegisterMsg GUISetAccelerators - GUISetBkColor GUISetCoord GUISetCursor GUISetFont GUISetHelp GUISetIcon - GUISetOnEvent GUISetState GUISetStyle GUIStartGroup GUISwitch Hex HotKeySet - HttpSetProxy HttpSetUserAgent HWnd InetClose InetGet InetGetInfo InetGetSize - InetRead IniDelete IniRead IniReadSection IniReadSectionNames IniRenameSection - IniWrite IniWriteSection InputBox Int IsAdmin IsArray IsBinary IsBool - IsDeclared IsDllStruct IsFloat IsFunc IsHWnd IsInt IsKeyword IsNumber IsObj - IsPtr IsString Log MemGetStats Mod MouseClick MouseClickDrag MouseDown - MouseGetCursor MouseGetPos MouseMove MouseUp MouseWheel MsgBox Number - ObjCreate ObjCreateInterface ObjEvent ObjGet ObjName OnAutoItExitRegister - OnAutoItExitUnRegister Ping PixelChecksum PixelGetColor PixelSearch - ProcessClose ProcessExists ProcessGetStats ProcessList ProcessSetPriority - ProcessWait ProcessWaitClose ProgressOff ProgressOn ProgressSet Ptr Random - RegDelete RegEnumKey RegEnumVal RegRead RegWrite Round Run RunAs RunAsWait - RunWait Send SendKeepActive SetError SetExtended ShellExecute ShellExecuteWait - Shutdown Sin Sleep SoundPlay SoundSetWaveVolume SplashImageOn SplashOff - SplashTextOn Sqrt SRandom StatusbarGetText StderrRead StdinWrite StdioClose - StdoutRead String StringAddCR StringCompare StringFormat StringFromASCIIArray - StringInStr StringIsAlNum StringIsAlpha StringIsASCII StringIsDigit - StringIsFloat StringIsInt StringIsLower StringIsSpace StringIsUpper - StringIsXDigit StringLeft StringLen StringLower StringMid StringRegExp - StringRegExpReplace StringReplace StringReverse StringRight StringSplit - StringStripCR StringStripWS StringToASCIIArray StringToBinary StringTrimLeft - StringTrimRight StringUpper Tan TCPAccept TCPCloseSocket TCPConnect - TCPListen TCPNameToIP TCPRecv TCPSend TCPShutdown TCPStartup TimerDiff - TimerInit ToolTip TrayCreateItem TrayCreateMenu TrayGetMsg TrayItemDelete - TrayItemGetHandle TrayItemGetState TrayItemGetText TrayItemSetOnEvent - TrayItemSetState TrayItemSetText TraySetClick TraySetIcon TraySetOnEvent - TraySetPauseIcon TraySetState TraySetToolTip TrayTip UBound UDPBind - UDPCloseSocket UDPOpen UDPRecv UDPSend UDPShutdown UDPStartup VarGetType - WinActivate WinActive WinClose WinExists WinFlash WinGetCaretPos - WinGetClassList WinGetClientSize WinGetHandle WinGetPos WinGetProcess - WinGetState WinGetText WinGetTitle WinKill WinList WinMenuSelectItem - WinMinimizeAll WinMinimizeAllUndo WinMove WinSetOnTop WinSetState WinSetTitle - WinSetTrans WinWait WinWaitActive WinWaitClose WinWaitNotActive -]], true))) +lex:add_rule('function', token(lexer.FUNCTION, word_match({ + 'Abs', 'ACos', 'AdlibRegister', 'AdlibUnRegister', 'Asc', 'AscW', 'ASin', 'Assign', 'ATan', + 'AutoItSetOption', 'AutoItWinGetTitle', 'AutoItWinSetTitle', 'Beep', 'Binary', 'BinaryLen', + 'BinaryMid', 'BinaryToString', 'BitAND', 'BitNOT', 'BitOR', 'BitRotate', 'BitShift', 'BitXOR', + 'BlockInput', 'Break', 'Call', 'CDTray', 'Ceiling', 'Chr', 'ChrW', 'ClipGet', 'ClipPut', + 'ConsoleRead', 'ConsoleWrite', 'ConsoleWriteError', 'ControlClick', 'ControlCommand', + 'ControlDisable', 'ControlEnable', 'ControlFocus', 'ControlGetFocus', 'ControlGetHandle', + 'ControlGetPos', 'ControlGetText', 'ControlHide', 'ControlListView', 'ControlMove', 'ControlSend', + 'ControlSetText', 'ControlShow', 'ControlTreeView', 'Cos', 'Dec', 'DirCopy', 'DirCreate', + 'DirGetSize', 'DirMove', 'DirRemove', 'DllCall', 'DllCallAddress', 'DllCallbackFree', + 'DllCallbackGetPtr', 'DllCallbackRegister', 'DllClose', 'DllOpen', 'DllStructCreate', + 'DllStructGetData', 'DllStructGetPtr', 'DllStructGetSize', 'DllStructSetData', 'DriveGetDrive', + 'DriveGetFileSystem', 'DriveGetLabel', 'DriveGetSerial', 'DriveGetType', 'DriveMapAdd', + 'DriveMapDel', 'DriveMapGet', 'DriveSetLabel', 'DriveSpaceFree', 'DriveSpaceTotal', 'DriveStatus', + 'EnvGet', 'EnvSet', 'EnvUpdate', 'Eval', 'Execute', 'Exp', 'FileChangeDir', 'FileClose', + 'FileCopy', 'FileCreateNTFSLink', 'FileCreateShortcut', 'FileDelete', 'FileExists', + 'FileFindFirstFile', 'FileFindNextFile', 'FileFlush', 'FileGetAttrib', 'FileGetEncoding', + 'FileGetLongName', 'FileGetPos', 'FileGetShortcut', 'FileGetShortName', 'FileGetSize', + 'FileGetTime', 'FileGetVersion', 'FileInstall', 'FileMove', 'FileOpen', 'FileOpenDialog', + 'FileRead', 'FileReadLine', 'FileReadToArray', 'FileRecycle', 'FileRecycleEmpty', + 'FileSaveDialog', 'FileSelectFolder', 'FileSetAttrib', 'FileSetEnd', 'FileSetPos', 'FileSetTime', + 'FileWrite', 'FileWriteLine', 'Floor', 'FtpSetProxy', 'FuncName', 'GUICreate', 'GUICtrlCreateAvi', + 'GUICtrlCreateButton', 'GUICtrlCreateCheckbox', 'GUICtrlCreateCombo', 'GUICtrlCreateContextMenu', + 'GUICtrlCreateDate', 'GUICtrlCreateDummy', 'GUICtrlCreateEdit', 'GUICtrlCreateGraphic', + 'GUICtrlCreateGroup', 'GUICtrlCreateIcon', 'GUICtrlCreateInput', 'GUICtrlCreateLabel', + 'GUICtrlCreateList', 'GUICtrlCreateListView', 'GUICtrlCreateListViewItem', 'GUICtrlCreateMenu', + 'GUICtrlCreateMenuItem', 'GUICtrlCreateMonthCal', 'GUICtrlCreateObj', 'GUICtrlCreatePic', + 'GUICtrlCreateProgress', 'GUICtrlCreateRadio', 'GUICtrlCreateSlider', 'GUICtrlCreateTab', + 'GUICtrlCreateTabItem', 'GUICtrlCreateTreeView', 'GUICtrlCreateTreeViewItem', + 'GUICtrlCreateUpdown', 'GUICtrlDelete', 'GUICtrlGetHandle', 'GUICtrlGetState', 'GUICtrlRead', + 'GUICtrlRecvMsg', 'GUICtrlRegisterListViewSort', 'GUICtrlSendMsg', 'GUICtrlSendToDummy', + 'GUICtrlSetBkColor', 'GUICtrlSetColor', 'GUICtrlSetCursor', 'GUICtrlSetData', + 'GUICtrlSetDefBkColor', 'GUICtrlSetDefColor', 'GUICtrlSetFont', 'GUICtrlSetGraphic', + 'GUICtrlSetImage', 'GUICtrlSetLimit', 'GUICtrlSetOnEvent', 'GUICtrlSetPos', 'GUICtrlSetResizing', + 'GUICtrlSetState', 'GUICtrlSetStyle', 'GUICtrlSetTip', 'GUIDelete', 'GUIGetCursorInfo', + 'GUIGetMsg', 'GUIGetStyle', 'GUIRegisterMsg', 'GUISetAccelerators', 'GUISetBkColor', + 'GUISetCoord', 'GUISetCursor', 'GUISetFont', 'GUISetHelp', 'GUISetIcon', 'GUISetOnEvent', + 'GUISetState', 'GUISetStyle', 'GUIStartGroup', 'GUISwitch', 'Hex', 'HotKeySet', 'HttpSetProxy', + 'HttpSetUserAgent', 'HWnd', 'InetClose', 'InetGet', 'InetGetInfo', 'InetGetSize', 'InetRead', + 'IniDelete', 'IniRead', 'IniReadSection', 'IniReadSectionNames', 'IniRenameSection', 'IniWrite', + 'IniWriteSection', 'InputBox', 'Int', 'IsAdmin', 'IsArray', 'IsBinary', 'IsBool', 'IsDeclared', + 'IsDllStruct', 'IsFloat', 'IsFunc', 'IsHWnd', 'IsInt', 'IsKeyword', 'IsNumber', 'IsObj', 'IsPtr', + 'IsString', 'Log', 'MemGetStats', 'Mod', 'MouseClick', 'MouseClickDrag', 'MouseDown', + 'MouseGetCursor', 'MouseGetPos', 'MouseMove', 'MouseUp', 'MouseWheel', 'MsgBox', 'Number', + 'ObjCreate', 'ObjCreateInterface', 'ObjEvent', 'ObjGet', 'ObjName', 'OnAutoItExitRegister', + 'OnAutoItExitUnRegister', 'Ping', 'PixelChecksum', 'PixelGetColor', 'PixelSearch', 'ProcessClose', + 'ProcessExists', 'ProcessGetStats', 'ProcessList', 'ProcessSetPriority', 'ProcessWait', + 'ProcessWaitClose', 'ProgressOff', 'ProgressOn', 'ProgressSet', 'Ptr', 'Random', 'RegDelete', + 'RegEnumKey', 'RegEnumVal', 'RegRead', 'RegWrite', 'Round', 'Run', 'RunAs', 'RunAsWait', + 'RunWait', 'Send', 'SendKeepActive', 'SetError', 'SetExtended', 'ShellExecute', + 'ShellExecuteWait', 'Shutdown', 'Sin', 'Sleep', 'SoundPlay', 'SoundSetWaveVolume', + 'SplashImageOn', 'SplashOff', 'SplashTextOn', 'Sqrt', 'SRandom', 'StatusbarGetText', 'StderrRead', + 'StdinWrite', 'StdioClose', 'StdoutRead', 'String', 'StringAddCR', 'StringCompare', + 'StringFormat', 'StringFromASCIIArray', 'StringInStr', 'StringIsAlNum', 'StringIsAlpha', + 'StringIsASCII', 'StringIsDigit', 'StringIsFloat', 'StringIsInt', 'StringIsLower', + 'StringIsSpace', 'StringIsUpper', 'StringIsXDigit', 'StringLeft', 'StringLen', 'StringLower', + 'StringMid', 'StringRegExp', 'StringRegExpReplace', 'StringReplace', 'StringReverse', + 'StringRight', 'StringSplit', 'StringStripCR', 'StringStripWS', 'StringToASCIIArray', + 'StringToBinary', 'StringTrimLeft', 'StringTrimRight', 'StringUpper', 'Tan', 'TCPAccept', + 'TCPCloseSocket', 'TCPConnect', 'TCPListen', 'TCPNameToIP', 'TCPRecv', 'TCPSend', 'TCPShutdown', + 'TCPStartup', 'TimerDiff', 'TimerInit', 'ToolTip', 'TrayCreateItem', 'TrayCreateMenu', + 'TrayGetMsg', 'TrayItemDelete', 'TrayItemGetHandle', 'TrayItemGetState', 'TrayItemGetText', + 'TrayItemSetOnEvent', 'TrayItemSetState', 'TrayItemSetText', 'TraySetClick', 'TraySetIcon', + 'TraySetOnEvent', 'TraySetPauseIcon', 'TraySetState', 'TraySetToolTip', 'TrayTip', 'UBound', + 'UDPBind', 'UDPCloseSocket', 'UDPOpen', 'UDPRecv', 'UDPSend', 'UDPShutdown', 'UDPStartup', + 'VarGetType', 'WinActivate', 'WinActive', 'WinClose', 'WinExists', 'WinFlash', 'WinGetCaretPos', + 'WinGetClassList', 'WinGetClientSize', 'WinGetHandle', 'WinGetPos', 'WinGetProcess', + 'WinGetState', 'WinGetText', 'WinGetTitle', 'WinKill', 'WinList', 'WinMenuSelectItem', + 'WinMinimizeAll', 'WinMinimizeAllUndo', 'WinMove', 'WinSetOnTop', 'WinSetState', 'WinSetTitle', + 'WinSetTrans', 'WinWait', 'WinWaitActive', 'WinWaitClose', 'WinWaitNotActive' +}, true))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Comments. local line_comment = lexer.to_eol(';') -local block_comment = lexer.range('#comments-start', '#comments-end') + - lexer.range('#cs', '#ce') +local block_comment = lexer.range('#comments-start', '#comments-end') + lexer.range('#cs', '#ce') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Preprocessor. -lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * word_match([[ - include-once include pragma forceref RequireAdmin NoTrayIcon - OnAutoItStartRegister -]], true))) +lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * word_match({ + 'include-once', 'include', 'pragma', 'forceref', 'RequireAdmin', 'NoTrayIcon', + 'OnAutoItStartRegister' +}, true))) -- Strings. local dq_str = lexer.range('"', true, false) @@ -117,7 +116,7 @@ lex:add_rule('string', token(lexer.STRING, dq_str + sq_str + inc)) -- Macros. lex:add_rule('macro', token('macro', '@' * (lexer.alnum + '_')^1)) -lex:add_style('macro', lexer.STYLE_PREPROCESSOR) +lex:add_style('macro', lexer.styles.preprocessor) -- Variables. lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.alnum + '_')^1)) diff --git a/syntaxhighlight/textadept/awk.lua b/syntaxhighlight/textadept/awk.lua index 43c70e7..f439127 100644 --- a/syntaxhighlight/textadept/awk.lua +++ b/syntaxhighlight/textadept/awk.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- AWK LPeg lexer. -- Modified by Wolfgang Seeberg 2012, 2013. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('awk') @@ -21,14 +21,13 @@ local DQUOTE = '"' local DELIMITER_MATCHES = {['('] = ')', ['['] = ']'} local COMPANION = {['('] = '[', ['['] = '('} local CC = { - alnum = 1, alpha = 1, blank = 1, cntrl = 1, digit = 1, graph = 1, lower = 1, - print = 1, punct = 1, space = 1, upper = 1, xdigit = 1 + alnum = 1, alpha = 1, blank = 1, cntrl = 1, digit = 1, graph = 1, lower = 1, print = 1, punct = 1, + space = 1, upper = 1, xdigit = 1 } local LastRegexEnd = 0 local BackslashAtCommentEnd = 0 local KW_BEFORE_RX = { - case = 1, ['do'] = 1, ['else'] = 1, exit = 1, print = 1, printf = 1, - ['return'] = 1 + case = 1, ['do'] = 1, ['else'] = 1, exit = 1, print = 1, printf = 1, ['return'] = 1 } local function findKeyword(input, e) @@ -147,9 +146,7 @@ local function scanGawkRegex(input, index) return false end -- Is only called immediately after scanGawkRegex(). -local function scanRegex() - return ScanRegexResult -end +local function scanRegex() return ScanRegexResult end local function scanString(input, index) local i = index @@ -169,8 +166,7 @@ local function scanString(input, index) return false end --- purpose: prevent isRegex() from entering a comment line that ends with a --- backslash. +-- purpose: prevent isRegex() from entering a comment line that ends with a backslash. local function scanComment(input, index) local _, i = input:find('[^\r\n]*', index) if input:sub(i, i) == BACKSLASH then BackslashAtCommentEnd = i end @@ -230,59 +226,51 @@ lex:add_rule('comment', token(lexer.COMMENT, '#' * P(scanComment))) lex:add_rule('string', token(lexer.STRING, DQUOTE * P(scanString))) -- No leading sign because it might be binary. -local float = - ((lexer.digit^1 * ('.' * lexer.digit^0)^-1) + ('.' * lexer.digit^1)) * +local float = ((lexer.digit^1 * ('.' * lexer.digit^0)^-1) + ('.' * lexer.digit^1)) * (S('eE') * S('+-')^-1 * lexer.digit^1)^-1 -- Fields. E.g. $1, $a, $(x), $a(x), $a[x], $"1", $$a, etc. -lex:add_rule('field', token('field', P('$') * S('$+-')^0 * ( - float + - lexer.word^0 * '(' * P(scanFieldDelimiters) + - lexer.word^1 * ('[' * P(scanFieldDelimiters))^-1 + - '"' * P(scanString) + - '/' * P(eatRegex) * '/'))) -lex:add_style('field', lexer.STYLE_LABEL) +lex:add_rule('field', token('field', '$' * S('$+-')^0 * + (float + lexer.word^0 * '(' * P(scanFieldDelimiters) + lexer.word^1 * + ('[' * P(scanFieldDelimiters))^-1 + '"' * P(scanString) + '/' * P(eatRegex) * '/'))) +lex:add_style('field', lexer.styles.label) -- Regular expressions. --- Slash delimited regular expressions are preceded by most operators or --- the keywords 'print' and 'case', possibly on a preceding line. They --- can contain unescaped slashes and brackets in brackets. Some escape --- sequences like '\S', '\s' have special meanings with Gawk. Tokens that --- contain them are displayed differently. +-- Slash delimited regular expressions are preceded by most operators or the keywords 'print' +-- and 'case', possibly on a preceding line. They can contain unescaped slashes and brackets +-- in brackets. Some escape sequences like '\S', '\s' have special meanings with Gawk. Tokens +-- that contain them are displayed differently. lex:add_rule('gawkRegex', token('gawkRegex', SLASH * P(scanGawkRegex))) -lex:add_style('gawkRegex', lexer.STYLE_PREPROCESSOR .. ',underlined') +lex:add_style('gawkRegex', lexer.styles.preprocessor .. {underlined = true}) lex:add_rule('regex', token(lexer.REGEX, SLASH * P(scanRegex))) -- Operators. -lex:add_rule('gawkOperator', token('gawkOperator', P("|&") + "@" + "**=" + - "**")) -lex:add_style('gawkOperator', lexer.STYLE_OPERATOR .. ',underlined') +lex:add_rule('gawkOperator', token('gawkOperator', P("|&") + "@" + "**=" + "**")) +lex:add_style('gawkOperator', lexer.styles.operator .. {underlined = true}) lex:add_rule('operator', token(lexer.OPERATOR, S('!%&()*+,-/:;<=>?[\\]^{|}~'))) -- Numbers. lex:add_rule('gawkNumber', token('gawkNumber', lexer.hex_num + lexer.oct_num)) -lex:add_style('gawkNumber', lexer.STYLE_NUMBER .. ',underlined') +lex:add_style('gawkNumber', lexer.styles.number .. {underlined = true}) lex:add_rule('number', token(lexer.NUMBER, float)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - BEGIN END atan2 break close continue cos delete do else exit exp fflush for - function getline gsub if in index int length log match next nextfile print - printf rand return sin split sprintf sqrt srand sub substr system tolower - toupper while -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'BEGIN', 'END', 'atan2', 'break', 'close', 'continue', 'cos', 'delete', 'do', 'else', 'exit', + 'exp', 'fflush', 'for', 'function', 'getline', 'gsub', 'if', 'in', 'index', 'int', 'length', + 'log', 'match', 'next', 'nextfile', 'print', 'printf', 'rand', 'return', 'sin', 'split', + 'sprintf', 'sqrt', 'srand', 'sub', 'substr', 'system', 'tolower', 'toupper', 'while' +})) -lex:add_rule('builtInVariable', token('builtInVariable', word_match[[ - ARGC ARGV CONVFMT ENVIRON FILENAME FNR FS NF NR OFMT OFS ORS RLENGTH RS RSTART - SUBSEP -]])) -lex:add_style('builtInVariable', lexer.STYLE_CONSTANT) +lex:add_rule('builtInVariable', token('builtInVariable', word_match( + 'ARGC ARGV CONVFMT ENVIRON FILENAME FNR FS NF NR OFMT OFS ORS RLENGTH RS RSTART SUBSEP'))) +lex:add_style('builtInVariable', lexer.styles.constant) -lex:add_rule('gawkBuiltInVariable', token('gawkBuiltInVariable', word_match[[ - ARGIND BINMODE ERRNO FIELDWIDTHS FPAT FUNCTAB IGNORECASE LINT PREC PROCINFO - ROUNDMODE RT SYMTAB TEXTDOMAIN -]])) -lex:add_style('gawkBuiltInVariable', lexer.STYLE_CONSTANT .. ',underlined') +lex:add_rule('gawkBuiltInVariable', token('gawkBuiltInVariable', word_match{ + 'ARGIND', 'BINMODE', 'ERRNO', 'FIELDWIDTHS', 'FPAT', 'FUNCTAB', 'IGNORECASE', 'LINT', 'PREC', + 'PROCINFO', 'ROUNDMODE', 'RT', 'SYMTAB', 'TEXTDOMAIN' +})) +lex:add_style('gawkBuiltInVariable', lexer.styles.constant .. {underlined = true}) -- Functions. lex:add_rule('function', token(lexer.FUNCTION, lexer.word * #P('('))) @@ -292,6 +280,6 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/bash.lua b/syntaxhighlight/textadept/bash.lua index 1c9e247..6a9f1a3 100644 --- a/syntaxhighlight/textadept/bash.lua +++ b/syntaxhighlight/textadept/bash.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Shell LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('bash') @@ -12,13 +12,14 @@ local lex = lexer.new('bash') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - if then elif else fi case in esac while for do done continue local return - select +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'if', 'then', 'elif', 'else', 'fi', 'case', 'in', 'esac', 'while', 'for', 'do', 'done', + 'continue', 'local', 'return', 'select', -- Operators. - -a -b -c -d -e -f -g -h -k -p -r -s -t -u -w -x -O -G -L -S -N -nt -ot -ef -o - -z -n -eq -ne -lt -le -gt -ge -]])) + '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-k', '-p', '-r', '-s', '-t', '-u', '-w', '-x', + '-O', '-G', '-L', '-S', '-N', '-nt', '-ot', '-ef', '-o', '-z', '-n', '-eq', '-ne', '-lt', '-le', + '-gt', '-ge' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -28,8 +29,7 @@ local sq_str = lexer.range("'", false, false) local dq_str = lexer.range('"') local ex_str = lexer.range('`') local heredoc = '<<' * P(function(input, index) - local _, e, _, delimiter = input:find( - '^%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index) + local _, e, _, delimiter = input:find('^%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index) if not delimiter then return end _, e = input:find('[\n\r\f]+' .. delimiter, e) return e and e + 1 or #input + 1 @@ -43,9 +43,8 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '$' * ( - S('!#?*@$') + lexer.digit^1 + lexer.word + lexer.range('{', '}', true) -))) +lex:add_rule('variable', token(lexer.VARIABLE, '$' * + (S('!#?*@$') + lexer.digit^1 + lexer.word + lexer.range('{', '}', true, false, true)))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*^&|~.,:;?()[]{}'))) @@ -55,6 +54,6 @@ lex:add_fold_point(lexer.KEYWORD, 'if', 'fi') lex:add_fold_point(lexer.KEYWORD, 'case', 'esac') lex:add_fold_point(lexer.KEYWORD, 'do', 'done') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/batch.lua b/syntaxhighlight/textadept/batch.lua index cd4d849..be8abae 100644 --- a/syntaxhighlight/textadept/batch.lua +++ b/syntaxhighlight/textadept/batch.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Batch LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('batch', {case_insensitive_fold_points = true}) @@ -12,19 +12,20 @@ local lex = lexer.new('batch', {case_insensitive_fold_points = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - cd chdir md mkdir cls for if echo echo. move copy ren del set call exit - setlocal shift endlocal pause defined exist errorlevel else in do NUL AUX PRN - not goto pushd popd -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'cd', 'chdir', 'md', 'mkdir', 'cls', 'for', 'if', 'echo', 'echo.', 'move', 'copy', 'ren', 'del', + 'set', 'call', 'exit', 'setlocal', 'shift', 'endlocal', 'pause', 'defined', 'exist', 'errorlevel', + 'else', 'in', 'do', 'NUL', 'AUX', 'PRN', 'not', 'goto', 'pushd', 'popd' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ - APPEND ATTRIB CHKDSK CHOICE DEBUG DEFRAG DELTREE DISKCOMP DISKCOPY DOSKEY - DRVSPACE EMM386 EXPAND FASTOPEN FC FDISK FIND FORMAT GRAPHICS KEYB LABEL - LOADFIX MEM MODE MORE MOVE MSCDEX NLSFUNC POWER PRINT RD REPLACE RESTORE - SETVER SHARE SORT SUBST SYS TREE UNDELETE UNFORMAT VSAFE XCOPY -]], true))) +lex:add_rule('function', token(lexer.FUNCTION, word_match({ + 'APPEND', 'ATTRIB', 'CHKDSK', 'CHOICE', 'DEBUG', 'DEFRAG', 'DELTREE', 'DISKCOMP', 'DISKCOPY', + 'DOSKEY', 'DRVSPACE', 'EMM386', 'EXPAND', 'FASTOPEN', 'FC', 'FDISK', 'FIND', 'FORMAT', 'GRAPHICS', + 'KEYB', 'LABEL', 'LOADFIX', 'MEM', 'MODE', 'MORE', 'MOVE', 'MSCDEX', 'NLSFUNC', 'POWER', 'PRINT', + 'RD', 'REPLACE', 'RESTORE', 'SETVER', 'SHARE', 'SORT', 'SUBST', 'SYS', 'TREE', 'UNDELETE', + 'UNFORMAT', 'VSAFE', 'XCOPY' +}, true))) -- Comments. local rem = (P('REM') + 'rem') * #lexer.space diff --git a/syntaxhighlight/textadept/bibtex.lua b/syntaxhighlight/textadept/bibtex.lua index 7a300de..f4cd5e6 100644 --- a/syntaxhighlight/textadept/bibtex.lua +++ b/syntaxhighlight/textadept/bibtex.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Bibtex LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('bibtex') @@ -12,12 +12,13 @@ local lex = lexer.new('bibtex') local ws = token(lexer.WHITESPACE, lexer.space^1) -- Fields. -lex:add_rule('field', token('field', word_match[[ - author title journal year volume number pages month note key publisher editor - series address edition howpublished booktitle organization chapter school - institution type isbn issn affiliation issue keyword url -]])) -lex:add_style('field', lexer.STYLE_CONSTANT) +lex:add_rule('field', token('field', word_match{ + 'author', 'title', 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note', 'key', + 'publisher', 'editor', 'series', 'address', 'edition', 'howpublished', 'booktitle', + 'organization', 'chapter', 'school', 'institution', 'type', 'isbn', 'issn', 'affiliation', + 'issue', 'keyword', 'url' +})) +lex:add_style('field', lexer.styles.constant) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -34,13 +35,13 @@ lex:add_rule('operator', token(lexer.OPERATOR, S(',='))) local latex = lexer.load('latex') -- Embedded Bibtex. -local entry = token('entry', P('@') * word_match([[ - book article booklet conference inbook incollection inproceedings manual - mastersthesis lambda misc phdthesis proceedings techreport unpublished -]], true)) -lex:add_style('entry', lexer.STYLE_PREPROCESSOR) -local bibtex_start_rule = entry * ws^0 * token(lexer.OPERATOR, P('{')) -local bibtex_end_rule = token(lexer.OPERATOR, P('}')) +local entry = token('entry', '@' * word_match({ + 'book', 'article', 'booklet', 'conference', 'inbook', 'incollection', 'inproceedings', 'manual', + 'mastersthesis', 'lambda', 'misc', 'phdthesis', 'proceedings', 'techreport', 'unpublished' +}, true)) +lex:add_style('entry', lexer.styles.preprocessor) +local bibtex_start_rule = entry * ws^0 * token(lexer.OPERATOR, '{') +local bibtex_end_rule = token(lexer.OPERATOR, '}') latex:embed(lex, bibtex_start_rule, bibtex_end_rule) return lex diff --git a/syntaxhighlight/textadept/boo.lua b/syntaxhighlight/textadept/boo.lua index 4e6e2cf..fb5c006 100644 --- a/syntaxhighlight/textadept/boo.lua +++ b/syntaxhighlight/textadept/boo.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Boo LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('boo') @@ -12,31 +12,32 @@ local lex = lexer.new('boo') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and break cast continue elif else ensure except for given goto if in isa is - not or otherwise pass raise ref try unless when while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'break', 'cast', 'continue', 'elif', 'else', 'ensure', 'except', 'for', 'given', 'goto', + 'if', 'in', 'isa', 'is', 'not', 'or', 'otherwise', 'pass', 'raise', 'ref', 'try', 'unless', + 'when', 'while', -- Definitions. - abstract callable class constructor def destructor do enum event final get - interface internal of override partial private protected public return set - static struct transient virtual yield + 'abstract', 'callable', 'class', 'constructor', 'def', 'destructor', 'do', 'enum', 'event', + 'final', 'get', 'interface', 'internal', 'of', 'override', 'partial', 'private', 'protected', + 'public', 'return', 'set', 'static', 'struct', 'transient', 'virtual', 'yield', -- Namespaces. - as from import namespace + 'as', 'from', 'import', 'namespace', -- Other. - self super null true false -]])) + 'self', 'super', 'null', 'true', 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool byte char date decimal double duck float int long object operator regex - sbyte short single string timespan uint ulong ushort -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'byte', 'char', 'date', 'decimal', 'double', 'duck', 'float', 'int', 'long', 'object', + 'operator', 'regex', 'sbyte', 'short', 'single', 'string', 'timespan', 'uint', 'ulong', 'ushort' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - array assert checked enumerate __eval__ filter getter len lock map matrix max - min normalArrayIndexing print property range rawArrayIndexing required - __switch__ typeof unchecked using yieldAll zip -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'array', 'assert', 'checked', 'enumerate', '__eval__', 'filter', 'getter', 'len', 'lock', 'map', + 'matrix', 'max', 'min', 'normalArrayIndexing', 'print', 'property', 'range', 'rawArrayIndexing', + 'required', '__switch__', 'typeof', 'unchecked', 'using', 'yieldAll', 'zip' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -46,8 +47,7 @@ local sq_str = lexer.range("'", true) local dq_str = lexer.range('"', true) local tq_str = lexer.range('"""') local string = token(lexer.STRING, tq_str + sq_str + dq_str) -local regex_str = #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * - lexer.range('/', true) +local regex_str = #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * lexer.range('/', true) local regex = token(lexer.REGEX, regex_str) lex:add_rule('string', string + regex) @@ -57,8 +57,7 @@ local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.number * - (S('msdhsfFlL') + 'ms')^-1)) +lex:add_rule('number', token(lexer.NUMBER, lexer.number * (S('msdhsfFlL') + 'ms')^-1)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~`'))) diff --git a/syntaxhighlight/textadept/caml.lua b/syntaxhighlight/textadept/caml.lua index c465dde..948d2c2 100644 --- a/syntaxhighlight/textadept/caml.lua +++ b/syntaxhighlight/textadept/caml.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- OCaml LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('caml') @@ -12,37 +12,37 @@ local lex = lexer.new('caml') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and as asr begin class closed constraint do done downto else end exception - external failwith false flush for fun function functor if in include incr - inherit land let load los lsl lsr lxor match method mod module mutable new not - of open option or parser private raise rec ref regexp sig stderr stdin stdout - struct then to true try type val virtual when while with -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'as', 'asr', 'begin', 'class', 'closed', 'constraint', 'do', 'done', 'downto', 'else', + 'end', 'exception', 'external', 'failwith', 'false', 'flush', 'for', 'fun', 'function', 'functor', + 'if', 'in', 'include', 'incr', 'inherit', 'land', 'let', 'load', 'los', 'lsl', 'lsr', 'lxor', + 'match', 'method', 'mod', 'module', 'mutable', 'new', 'not', 'of', 'open', 'option', 'or', + 'parser', 'private', 'raise', 'rec', 'ref', 'regexp', 'sig', 'stderr', 'stdin', 'stdout', + 'struct', 'then', 'to', 'true', 'try', 'type', 'val', 'virtual', 'when', 'while', 'with' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool char float int string unit -]])) +lex:add_rule('type', token(lexer.TYPE, word_match('bool char float int string unit'))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs abs_float acos asin atan atan2 at_exit bool_of_string ceil char_of_int - classify_float close_in close_in_noerr close_out close_out_noerr compare cos - cosh decr epsilon_float exit exp failwith float float_of_int float_of_string - floor flush flush_all format_of_string frexp fst ignore in_channel_length incr - infinity input input_binary_int input_byte input_char input_line input_value - int_of_char int_of_float int_of_string invalid_arg ldexp log log10 max - max_float max_int min min_float min_int mod modf mod_float nan open_in - open_in_bin open_in_gen open_out open_out_bin open_out_gen out_channel_length - output output_binary_int output_byte output_char output_string output_value - pos_in pos_out pred prerr_char prerr_endline prerr_float prerr_int - prerr_newline prerr_string print_char print_endline print_float print_int - print_newline print_string raise read_float read_int read_line really_input - seek_in seek_out set_binary_mode_in set_binary_mode_out sin sinh snd sqrt - stderr stdin stdout string_of_bool string_of_float string_of_format - string_of_int succ tan tanh truncate -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'abs_float', 'acos', 'asin', 'atan', 'atan2', 'at_exit', 'bool_of_string', 'ceil', + 'char_of_int', 'classify_float', 'close_in', 'close_in_noerr', 'close_out', 'close_out_noerr', + 'compare', 'cos', 'cosh', 'decr', 'epsilon_float', 'exit', 'exp', 'failwith', 'float', + 'float_of_int', 'float_of_string', 'floor', 'flush', 'flush_all', 'format_of_string', 'frexp', + 'fst', 'ignore', 'in_channel_length', 'incr', 'infinity', 'input', 'input_binary_int', + 'input_byte', 'input_char', 'input_line', 'input_value', 'int_of_char', 'int_of_float', + 'int_of_string', 'invalid_arg', 'ldexp', 'log', 'log10', 'max', 'max_float', 'max_int', 'min', + 'min_float', 'min_int', 'mod', 'modf', 'mod_float', 'nan', 'open_in', 'open_in_bin', + 'open_in_gen', 'open_out', 'open_out_bin', 'open_out_gen', 'out_channel_length', 'output', + 'output_binary_int', 'output_byte', 'output_char', 'output_string', 'output_value', 'pos_in', + 'pos_out', 'pred', 'prerr_char', 'prerr_endline', 'prerr_float', 'prerr_int', 'prerr_newline', + 'prerr_string', 'print_char', 'print_endline', 'print_float', 'print_int', 'print_newline', + 'print_string', 'raise', 'read_float', 'read_int', 'read_line', 'really_input', 'seek_in', + 'seek_out', 'set_binary_mode_in', 'set_binary_mode_out', 'sin', 'sinh', 'snd', 'sqrt', 'stderr', + 'stdin', 'stdout', 'string_of_bool', 'string_of_float', 'string_of_format', 'string_of_int', + 'succ', 'tan', 'tanh', 'truncate' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -53,8 +53,7 @@ local dq_str = lexer.range('"', true) lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, - lexer.range('(*', '*)', false, false, true))) +lex:add_rule('comment', token(lexer.COMMENT, lexer.range('(*', '*)', false, false, true))) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.number)) diff --git a/syntaxhighlight/textadept/chuck.lua b/syntaxhighlight/textadept/chuck.lua index 3b81b05..1e63a2c 100644 --- a/syntaxhighlight/textadept/chuck.lua +++ b/syntaxhighlight/textadept/chuck.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2010-2020 Martin Morawetz. See License.txt. +-- Copyright 2010-2021 Martin Morawetz. See LICENSE. -- ChucK LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('chuck') @@ -12,44 +12,40 @@ local lex = lexer.new('chuck') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- Control structures. - break continue else for if repeat return switch until while + 'break', 'continue', 'else', 'for', 'if', 'repeat', 'return', 'switch', 'until', 'while', -- Other chuck keywords. - function fun spork const new -]])) + 'function', 'fun', 'spork', 'const', 'new' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ -- Special values. - false maybe me null NULL pi true -]])) + 'false', 'maybe', 'me', 'null', 'NULL', 'pi', 'true' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - float int time dur void same -]])) +lex:add_rule('type', token(lexer.TYPE, word_match('float int time dur void same'))) -- Classes. -lex:add_rule('class', token(lexer.CLASS, word_match[[ +lex:add_rule('class', token(lexer.CLASS, word_match{ -- Class keywords. - class extends implements interface private protected public pure static super - this -]])) + 'class', 'extends', 'implements', 'interface', 'private', 'protected', 'public', 'pure', 'static', + 'super', 'this' +})) -- Global ugens. -lex:add_rule('ugen', token('ugen', word_match[[dac adc blackhole]])) -lex:add_style('ugen', lexer.STYLE_CONSTANT) +lex:add_rule('ugen', token('ugen', word_match('dac adc blackhole'))) +lex:add_style('ugen', lexer.styles.constant) -- Times. -lex:add_rule('time', token('time', word_match[[ - samp ms second minute hour day week -]])) -lex:add_style('time', lexer.STYLE_NUMBER) +lex:add_rule('time', token('time', word_match('samp ms second minute hour day week'))) +lex:add_style('time', lexer.styles.number) -- Special special value. -lex:add_rule('now', token('now', P('now'))) -lex:add_style('now', lexer.STYLE_CONSTANT .. ',bold') +lex:add_rule('now', token('now', 'now')) +lex:add_style('now', lexer.styles.constant .. {bold = true}) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) diff --git a/syntaxhighlight/textadept/clojure.lua b/syntaxhighlight/textadept/clojure.lua new file mode 100644 index 0000000..3ee42a7 --- /dev/null +++ b/syntaxhighlight/textadept/clojure.lua @@ -0,0 +1,148 @@ +local lpeg = require('lpeg') +-- Copyright 2018-2021 Mitchell. See LICENSE. +-- Clojure LPeg lexer. +-- Contributed by Christos Chatzifountas. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('clojure') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'fn', 'try', 'catch', 'finaly', 'defonce', 'and', 'case', 'cond', 'def', 'defn', 'defmacro', 'do', + 'else', 'when', 'when-let', 'if-let', 'if', 'let', 'loop', 'or', 'recur', 'quote' +})) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + '*', '+', '-', '->ArrayChunk', '->Eduction', '->Vec', '->VecNode', '->VecSeq', '/', '<', '<=', + '=', '==', '>', '>=', 'StackTraceElement->vec', 'Throwable->map', 'accessor', 'aclone', + 'add-classpath', 'add-watch', 'agent', 'agent-error', 'agent-errors', 'aget', 'alength', 'alias', + 'all-ns', 'alter', 'alter-meta!', 'alter-var-root', 'ancestors', 'any?', 'apply', 'array-map', + 'aset', 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float', 'aset-int', + 'aset-long', 'aset-short', 'assoc', 'assoc!', 'assoc-in', 'associative?', 'atom', 'await', + 'await-for', 'bases', 'bean', 'bigdec', 'bigint', 'biginteger', 'bit-and', 'bit-and-not', + 'bit-clear', 'bit-flip', 'bit-not', 'bit-or', 'bit-set', 'bit-shift-left', 'bit-shift-right', + 'bit-test', 'bit-xor', 'boolean', 'boolean-array', 'boolean?', 'booleans', 'bound-fn*', 'bound?', + 'bounded-count', 'butlast', 'byte', 'byte-array', 'bytes', 'bytes?', 'cast', 'cat', 'char', + 'char-array', 'char?', 'chars', 'class', 'class?', 'clear-agent-errors', 'clojure-version', + 'coll?', 'commute', 'comp', 'comparator', 'compare', 'compare-and-set!', 'compile', 'complement', + 'completing', 'concat', 'conj', 'conj!', 'cons', 'constantly', 'construct-proxy', 'contains?', + 'count', 'counted?', 'create-ns', 'create-struct', 'cycle', 'dec', 'decimal?', 'dedupe', 'delay?', + 'deliver', 'denominator', 'deref', 'derive', 'descendants', 'disj', 'disj!', 'dissoc', 'dissoc!', + 'distinct', 'distinct?', 'doall', 'dorun', 'double', 'double-array', 'double?', 'doubles', 'drop', + 'drop-last', 'drop-while', 'eduction', 'empty', 'empty?', 'ensure', 'ensure-reduced', + 'enumeration-seq', 'error-handler', 'error-mode', 'eval', 'even?', 'every-pred', 'every?', + 'ex-data', 'ex-info', 'extend', 'extenders', 'extends?', 'false?', 'ffirst', 'file-seq', 'filter', + 'filterv', 'find', 'find-keyword', 'find-ns', 'find-var', 'first', 'flatten', 'float', + 'float-array', 'float?', 'floats', 'flush', 'fn?', 'fnext', 'fnil', 'force', 'format', + 'frequencies', 'future-call', 'future-cancel', 'future-cancelled?', 'future-done?', 'future?', + 'gensym', 'get', 'get-in', 'get-method', 'get-proxy-class', 'get-thread-bindings', + 'get-validator', 'group-by', 'halt-when', 'hash', 'hash-map', 'hash-ordered-coll', 'hash-set', + 'hash-unordered-coll', 'ident?', 'identical?', 'identity', 'ifn?', 'in-ns', 'inc', 'inc', + 'indexed?', 'init-proxy', 'inst-ms', 'inst?', 'instance?', 'int', 'int-array', 'int?', 'integer?', + 'interleave', 'intern', 'interpose', 'into', 'into-array', 'ints', 'isa?', 'iterate', + 'iterator-seq', 'juxt', 'keep', 'keep-indexed', 'key', 'keys', 'keyword', 'keyword?', 'last', + 'line-seq', 'list', 'list*', 'list?', 'load', 'load-file', 'load-reader', 'load-string', + 'loaded-libs', 'long', 'long-array', 'longs', 'macroexpand', 'macroexpand-1', 'make-array', + 'make-hierarchy', 'map', 'map-entry?', 'map-indexed', 'map?', 'mapcat', 'mapv', 'max', 'max-key', + 'memoize', 'merge', 'merge-with', 'meta', 'methods', 'min', 'min-key', 'mix-collection-hash', + 'mod', 'name', 'namespace', 'namespace-munge', 'nat-int?', 'neg-int?', 'neg?', 'newline', 'next', + 'nfirst', 'nil?', 'nnext', 'not', 'not-any?', 'not-empty', 'not-every?', 'not=', 'ns-aliases', + 'ns-imports', 'ns-interns', 'ns-map', 'ns-name', 'ns-publics', 'ns-refers', 'ns-resolve', + 'ns-unalias', 'ns-unmap', 'nth', 'nthnext', 'nthrest', 'num', 'number?', 'numerator', + 'object-array', 'odd?', 'parents', 'partial', 'partition', 'partition-all', 'partition-by', + 'pcalls', 'peek', 'persistent!', 'pmap', 'pop', 'pop!', 'pop-thread-bindings', 'pos-int?', 'pos?', + 'pr-str', 'prefer-method', 'prefers', 'print', 'print-str', 'printf', 'println', 'println-str', + 'prn', 'prn-str', 'promise', 'proxy-mappings', 'push-thread-bindings', 'qualified-ident?', + 'qualified-keyword?', 'qualified-symbol?', 'quot', 'rand', 'rand-int', 'rand-nth', + 'random-sample', 'range', 'ratio?', 'rational?', 'rationalize', 're-find', 're-groups', + 're-matcher', 're-matches', 're-pattern', 're-seq', 'read', 'read-line', 'read-string', + 'reader-conditional', 'reader-conditional?', 'realized?', 'record?', 'reduce', 'reduce-kv', + 'reduced', 'reduced?', 'reductions', 'ref', 'ref-history-count', 'ref-max-history', + 'ref-min-history', 'ref-set', 'refer', 'release-pending-sends', 'rem', 'remove', + 'remove-all-methods', 'remove-method', 'remove-ns', 'remove-watch', 'repeat', 'repeatedly', + 'replace', 'replicate', 'require', 'reset!', 'reset-meta!', 'reset-vals!', 'resolve', 'rest', + 'restart-agent', 'resultset-seq', 'reverse', 'reversible?', 'rseq', 'rsubseq', 'run!', + 'satisfies?', 'second', 'select-keys', 'send', 'send-off', 'send-via', 'seq', 'seq?', 'seqable?', + 'seque', 'sequence', 'sequential?', 'set', 'set-agent-send-executor!', + 'set-agent-send-off-executor!', 'set-error-handler!', 'set-error-mode!', 'set-validator!', 'set?', + 'short', 'short-array', 'shorts', 'shuffle', 'shutdown-agents', 'simple-ident?', + 'simple-keyword?', 'simple-symbol?', 'slurp', 'some', 'some-fn', 'some?', 'sort', 'sort-by', + 'sorted-map', 'sorted-map-by', 'sorted-set', 'sorted-set-by', 'sorted?', 'special-symbol?', + 'spit', 'split-at', 'split-with', 'str', 'string?', 'struct', 'struct-map', 'subs', 'subseq', + 'subvec', 'supers', 'swap!', 'swap-vals!', 'symbol', 'symbol?', 'tagged-literal', + 'tagged-literal?', 'take', 'take-last', 'take-nth', 'take-while', 'test', 'the-ns', + 'thread-bound?', 'to-array', 'to-array-2d', 'trampoline', 'transduce', 'transient', 'tree-seq', + 'true?', 'type', 'unchecked-add', 'unchecked-add-int', 'unchecked-byte', 'unchecked-char', + 'unchecked-dec', 'unchecked-dec-int', 'unchecked-divide-int', 'unchecked-double', + 'unchecked-float', 'unchecked-inc', 'unchecked-inc-int', 'unchecked-int', 'unchecked-long', + 'unchecked-multiply', 'unchecked-multiply-int', 'unchecked-negate', 'unchecked-negate-int', + 'unchecked-remainder-int', 'unchecked-short', 'unchecked-subtract', 'unchecked-subtract-int', + 'underive', 'unreduced', 'unsigned-bit-shift-right', 'update', 'update-in', 'update-proxy', + 'uri?', 'use', 'uuid?', 'val', 'vals', 'var-get', 'var-set', 'var?', 'vary-meta', 'vec', 'vector', + 'vector-of', 'vector?', 'volatile!', 'volatile?', 'vreset!', 'with-bindings*', 'with-meta', + 'with-redefs-fn', 'xml-seq', 'zero?', 'zipmap', 'diff-similar', 'equality-partition', 'diff', + 'inspect', 'inspect-table', 'inspect-tree', 'validated', 'browse-url', 'as-file', 'as-url', + 'make-input-stream', 'make-output-stream', 'make-reader', 'make-writer', 'as-relative-path', + 'copy', 'delete-file', 'file', 'input-stream', 'make-parents', 'output-stream', 'reader', + 'resource', 'writer', 'add-local-javadoc', 'add-remote-javadoc', 'javadoc', 'sh', 'demunge', + 'load-script', 'main', 'repl', 'repl-caught', 'repl-exception', 'repl-prompt', 'repl-read', + 'root-cause', 'skip-if-eol', 'skip-whitespace', 'stack-element-str', 'cl-format', 'fresh-line', + 'get-pretty-writer', 'pprint', 'pprint-indent', 'pprint-newline', 'pprint-tab', 'print-table', + 'set-pprint-dispatch', 'write', 'write-out', 'resolve-class', 'do-reflect', 'typename', + '->AsmReflector', '->Constructor', '->Field', '->JavaReflector', '->Method', 'map->Constructor', + 'map->Field', 'map->Method', 'reflect', 'type-reflect', 'apropos', 'dir-fn', 'find-doc', 'pst', + 'set-break-handler!', 'source-fn', 'thread-stopper', 'difference', 'index', 'intersection', + 'join', 'map-invert', 'project', 'rename', 'rename-keys', 'select', 'subset?', 'superset?', + 'union', 'e', 'print-cause-trace', 'print-stack-trace', 'print-throwable', 'print-trace-element', + 'blank?', 'capitalize', 'ends-with?', 'escape', 'includes?', 'index-of', 'last-index-of', + 'lower-case', 're-quote-replacement', 'replace-first', 'split', 'split-lines', 'starts-with?', + 'trim', 'trim-newline', 'triml', 'trimr', 'upper-case', 'apply-template', 'assert-any', + 'assert-predicate', 'compose-fixtures', 'do-report', 'file-position', 'function?', + 'get-possibly-unbound-var', 'inc-report-counter', 'join-fixtures', 'run-all-tests', 'run-tests', + 'successful?', 'test-all-vars', 'test-ns', 'test-vars', 'testing-contexts-str', + 'testing-vars-str', 'keywordize-keys', 'macroexpand-all', 'postwalk', 'postwalk-demo', + 'postwalk-replace', 'prewalk', 'prewalk-demo', 'prewalk-replace', 'stringify-keys', 'walk', + 'append-child', 'branch?', 'children', 'down', 'edit', 'end?', 'insert-child', 'insert-left', + 'insert-right', 'left', 'leftmost', 'lefts', 'make-node', 'node', 'path', 'prev', 'right', + 'rightmost', 'rights', 'root', 'seq-zip', 'up', 'vector-zip', 'xml-zip', 'zipper' +})) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * (S('./') * lexer.digit^1)^-1)) + +-- Identifiers. +local word = (lexer.alpha + S('-!?*$=-')) * (lexer.alnum + S('.-!?*$+-'))^0 +lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) + +-- Comments. +local line_comment = lexer.to_eol(';') +local block_comment = lexer.range('#_(', ')') +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('`@()'))) + +-- Clojure keywords. +lex:add_rule('clojure_keyword', token('clojure_keyword', ':' * S(':')^-1 * word * ('/' * word)^-1)) +lex:add_style('clojure_keyword', lexer.styles.type) +lex:add_rule('clojure_symbol', token('clojure_symbol', "\'" * word * ('/' * word)^-1)) +lex:add_style('clojure_symbol', lexer.styles.type .. {bold = true}) + +-- Fold points. +lex:add_fold_point(lexer.COMMENT, '#_(', ')') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines(';')) +lex:add_fold_point(lexer.OPERATOR, '(', ')') +lex:add_fold_point(lexer.OPERATOR, '[', ']') +lex:add_fold_point(lexer.OPERATOR, '{', '}') + +return lex diff --git a/syntaxhighlight/textadept/cmake.lua b/syntaxhighlight/textadept/cmake.lua index 6bebe38..c7deee9 100644 --- a/syntaxhighlight/textadept/cmake.lua +++ b/syntaxhighlight/textadept/cmake.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- CMake LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('cmake') @@ -12,113 +12,105 @@ local lex = lexer.new('cmake') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - IF ENDIF FOREACH ENDFOREACH WHILE ENDWHILE ELSE ELSEIF -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'IF ENDIF FOREACH ENDFOREACH WHILE ENDWHILE ELSE ELSEIF', true))) -- Commands. -lex:add_rule('command', token(lexer.FUNCTION, word_match([[ - ADD_CUSTOM_COMMAND ADD_CUSTOM_TARGET ADD_DEFINITIONS ADD_DEPENDENCIES - ADD_EXECUTABLE ADD_LIBRARY ADD_SUBDIRECTORY ADD_TEST AUX_SOURCE_DIRECTORY - BUILD_COMMAND BUILD_NAME CMAKE_MINIMUM_REQUIRED CONFIGURE_FILE - CREATE_TEST_SOURCELIST ENABLE_LANGUAGE ENABLE_TESTING ENDMACRO EXEC_PROGRAM - EXECUTE_PROCESS EXPORT_LIBRARY_DEPENDENCIES FILE FIND_FILE FIND_LIBRARY - FIND_PACKAGE FIND_PATH FIND_PROGRAM FLTK_WRAP_UI GET_CMAKE_PROPERTY - GET_DIRECTORY_PROPERTY GET_FILENAME_COMPONENT GET_SOURCE_FILE_PROPERTY - GET_TARGET_PROPERTY GET_TEST_PROPERTY INCLUDE INCLUDE_DIRECTORIES - INCLUDE_EXTERNAL_MSPROJECT INCLUDE_REGULAR_EXPRESSION INSTALL INSTALL_FILES - INSTALL_PROGRAMS INSTALL_TARGETS LINK_DIRECTORIES LINK_LIBRARIES LIST - LOAD_CACHE LOAD_COMMAND MACRO MAKE_DIRECTORY MARK_AS_ADVANCED MATH MESSAGE - OPTION OUTPUT_REQUIRED_FILES PROJECT QT_WRAP_CPP QT_WRAP_UI REMOVE - REMOVE_DEFINITIONS SEPARATE_ARGUMENTS SET SET_DIRECTORY_PROPERTIES - SET_SOURCE_FILES_PROPERTIES SET_TARGET_PROPERTIES SET_TESTS_PROPERTIES - SITE_NAME SOURCE_GROUP STRING SUBDIR_DEPENDS SUBDIRS TARGET_LINK_LIBRARIES - TRY_COMPILE TRY_RUN USE_MANGLED_MESA UTILITY_SOURCE VARIABLE_REQUIRES - VTK_MAKE_INSTANTIATOR VTK_WRAP_JAVA VTK_WRAP_PYTHON VTK_WRAP_TCL WRITE_FILE -]], true))) +lex:add_rule('command', token(lexer.FUNCTION, word_match({ + 'ADD_CUSTOM_COMMAND', 'ADD_CUSTOM_TARGET', 'ADD_DEFINITIONS', 'ADD_DEPENDENCIES', + 'ADD_EXECUTABLE', 'ADD_LIBRARY', 'ADD_SUBDIRECTORY', 'ADD_TEST', 'AUX_SOURCE_DIRECTORY', + 'BUILD_COMMAND', 'BUILD_NAME', 'CMAKE_MINIMUM_REQUIRED', 'CONFIGURE_FILE', + 'CREATE_TEST_SOURCELIST', 'ENABLE_LANGUAGE', 'ENABLE_TESTING', 'ENDMACRO', 'EXEC_PROGRAM', + 'EXECUTE_PROCESS', 'EXPORT_LIBRARY_DEPENDENCIES', 'FILE', 'FIND_FILE', 'FIND_LIBRARY', + 'FIND_PACKAGE', 'FIND_PATH', 'FIND_PROGRAM', 'FLTK_WRAP_UI', 'GET_CMAKE_PROPERTY', + 'GET_DIRECTORY_PROPERTY', 'GET_FILENAME_COMPONENT', 'GET_SOURCE_FILE_PROPERTY', + 'GET_TARGET_PROPERTY', 'GET_TEST_PROPERTY', 'INCLUDE', 'INCLUDE_DIRECTORIES', + 'INCLUDE_EXTERNAL_MSPROJECT', 'INCLUDE_REGULAR_EXPRESSION', 'INSTALL', 'INSTALL_FILES', + 'INSTALL_PROGRAMS', 'INSTALL_TARGETS', 'LINK_DIRECTORIES', 'LINK_LIBRARIES', 'LIST', 'LOAD_CACHE', + 'LOAD_COMMAND', 'MACRO', 'MAKE_DIRECTORY', 'MARK_AS_ADVANCED', 'MATH', 'MESSAGE', 'OPTION', + 'OUTPUT_REQUIRED_FILES', 'PROJECT', 'QT_WRAP_CPP', 'QT_WRAP_UI', 'REMOVE', 'REMOVE_DEFINITIONS', + 'SEPARATE_ARGUMENTS', 'SET', 'SET_DIRECTORY_PROPERTIES', 'SET_SOURCE_FILES_PROPERTIES', + 'SET_TARGET_PROPERTIES', 'SET_TESTS_PROPERTIES', 'SITE_NAME', 'SOURCE_GROUP', 'STRING', + 'SUBDIR_DEPENDS', 'SUBDIRS', 'TARGET_LINK_LIBRARIES', 'TRY_COMPILE', 'TRY_RUN', + 'USE_MANGLED_MESA', 'UTILITY_SOURCE', 'VARIABLE_REQUIRES', 'VTK_MAKE_INSTANTIATOR', + 'VTK_WRAP_JAVA', 'VTK_WRAP_PYTHON', 'VTK_WRAP_TCL', 'WRITE_FILE' +}, true))) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match([[ - BOOL CACHE FALSE N NO ON OFF NOTFOUND TRUE -]], true))) +lex:add_rule('constant', + token(lexer.CONSTANT, word_match('BOOL CACHE FALSE N NO ON OFF NOTFOUND TRUE', true))) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, word_match[[ - APPLE ARGS BORLAND CMAKE_AR CMAKE_BACKWARDS_COMPATIBILITY CMAKE_BASE_NAME - CMAKE_BINARY_DIR CMAKE_BUILD_TOOL CMAKE_BUILD_TYPE CMAKE_CACHEFILE_DIR - CMAKE_CACHE_MAJOR_VERSION CMAKE_CACHE_MINOR_VERSION - CMAKE_CACHE_RELEASE_VERSION CMAKE_C_COMPILE_OBJECT CMAKE_C_COMPILER - CMAKE_C_COMPILER_ARG1 CMAKE_C_COMPILER_ENV_VAR CMAKE_C_COMPILER_FULLPATH - CMAKE_C_COMPILER_LOADED CMAKE_C_COMPILER_WORKS CMAKE_C_CREATE_SHARED_LIBRARY - CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS CMAKE_C_CREATE_SHARED_MODULE - CMAKE_C_CREATE_STATIC_LIBRARY CMAKE_CFG_INTDIR CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT CMAKE_C_FLAGS_INIT - CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_MINSIZEREL_INIT CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELEASE_INIT CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_RELWITHDEBINFO_INIT CMAKE_C_IGNORE_EXTENSIONS - CMAKE_C_INFORMATION_LOADED CMAKE_C_LINKER_PREFERENCE CMAKE_C_LINK_EXECUTABLE - CMAKE_C_LINK_FLAGS CMAKE_COLOR_MAKEFILE CMAKE_COMMAND CMAKE_COMPILER_IS_GNUCC - CMAKE_COMPILER_IS_GNUCC_RUN CMAKE_COMPILER_IS_GNUCXX - CMAKE_COMPILER_IS_GNUCXX_RUN CMAKE_C_OUTPUT_EXTENSION - CMAKE_C_SOURCE_FILE_EXTENSIONS CMAKE_CTEST_COMMAND CMAKE_CURRENT_BINARY_DIR - CMAKE_CURRENT_SOURCE_DIR CMAKE_CXX_COMPILE_OBJECT CMAKE_CXX_COMPILER - CMAKE_CXX_COMPILER_ARG1 CMAKE_CXX_COMPILER_ENV_VAR CMAKE_CXX_COMPILER_FULLPATH - CMAKE_CXX_COMPILER_LOADED CMAKE_CXX_COMPILER_WORKS - CMAKE_CXX_CREATE_SHARED_LIBRARY - CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS CMAKE_CXX_CREATE_SHARED_MODULE - CMAKE_CXX_CREATE_STATIC_LIBRARY CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_DEBUG_INIT CMAKE_CXX_FLAGS_INIT CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_MINSIZEREL_INIT CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELEASE_INIT CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT CMAKE_CXX_IGNORE_EXTENSIONS - CMAKE_CXX_INFORMATION_LOADED CMAKE_CXX_LINKER_PREFERENCE - CMAKE_CXX_LINK_EXECUTABLE CMAKE_CXX_LINK_FLAGS CMAKE_CXX_OUTPUT_EXTENSION - CMAKE_CXX_SOURCE_FILE_EXTENSIONS CMAKE_DL_LIBS CMAKE_EDIT_COMMAND - CMAKE_EXECUTABLE_SUFFIX CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS_DEBUG - CMAKE_EXE_LINKER_FLAGS_MINSIZEREL CMAKE_EXE_LINKER_FLAGS_RELEASE - CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO CMAKE_FILES_DIRECTORY - CMAKE_FIND_APPBUNDLE CMAKE_FIND_FRAMEWORK CMAKE_FIND_LIBRARY_PREFIXES - CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_GENERATOR CMAKE_HOME_DIRECTORY - CMAKE_INCLUDE_FLAG_C CMAKE_INCLUDE_FLAG_C_SEP CMAKE_INCLUDE_FLAG_CXX - CMAKE_INIT_VALUE CMAKE_INSTALL_PREFIX CMAKE_LIBRARY_PATH_FLAG - CMAKE_LINK_LIBRARY_FLAG CMAKE_LINK_LIBRARY_SUFFIX - CMAKE_MacOSX_Content_COMPILE_OBJECT CMAKE_MAJOR_VERSION CMAKE_MAKE_PROGRAM - CMAKE_MINOR_VERSION CMAKE_MODULE_EXISTS CMAKE_MODULE_LINKER_FLAGS - CMAKE_MODULE_LINKER_FLAGS_DEBUG CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL - CMAKE_MODULE_LINKER_FLAGS_RELEASE CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO - CMAKE_NUMBER_OF_LOCAL_GENERATORS CMAKE_OSX_ARCHITECTURES _CMAKE_OSX_MACHINE - CMAKE_OSX_SYSROOT CMAKE_PARENT_LIST_FILE CMAKE_PATCH_VERSION - CMAKE_PLATFORM_HAS_INSTALLNAME CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES - CMAKE_PLATFORM_ROOT_BIN CMAKE_PROJECT_NAME CMAKE_RANLIB CMAKE_ROOT - CMAKE_SHARED_LIBRARY_C_FLAGS CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS - CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS CMAKE_SHARED_LIBRARY_CXX_FLAGS - CMAKE_SHARED_LIBRARY_LINK_C_FLAGS CMAKE_SHARED_LIBRARY_PREFIX - CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP - CMAKE_SHARED_LIBRARY_SONAME_C_FLAG CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG - CMAKE_SHARED_LIBRARY_SUFFIX CMAKE_SHARED_LINKER_FLAGS - CMAKE_SHARED_LINKER_FLAGS_DEBUG CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL - CMAKE_SHARED_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO - CMAKE_SHARED_MODULE_CREATE_C_FLAGS CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS - CMAKE_SHARED_MODULE_PREFIX CMAKE_SHARED_MODULE_SUFFIX CMAKE_SIZEOF_VOID_P - CMAKE_SKIP_RPATH CMAKE_SOURCE_DIR CMAKE_STATIC_LIBRARY_PREFIX - CMAKE_STATIC_LIBRARY_SUFFIX CMAKE_SYSTEM CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE - CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE CMAKE_SYSTEM_APPBUNDLE_PATH - CMAKE_SYSTEM_FRAMEWORK_PATH CMAKE_SYSTEM_INCLUDE_PATH CMAKE_SYSTEM_INFO_FILE - CMAKE_SYSTEM_LIBRARY_PATH CMAKE_SYSTEM_LOADED CMAKE_SYSTEM_NAME - CMAKE_SYSTEM_PROCESSOR CMAKE_SYSTEM_PROGRAM_PATH - CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED CMAKE_SYSTEM_VERSION CMAKE_UNAME - CMAKE_USE_RELATIVE_PATHS CMAKE_VERBOSE_MAKEFILE CYGWIN EXECUTABLE_OUTPUT_PATH - FORCE HAVE_CMAKE_SIZEOF_VOID_P LIBRARY_OUTPUT_PATH LOCATION MACOSX_BUNDLE - MINGW MSVC MSVC60 MSVC70 MSVC71 MSVC80 MSVC_IDE POST_BUILD PRE_BUILD - PROJECT_BINARY_DIR PROJECT_NAME PROJECT_SOURCE_DIR RUN_CONFIGURE TARGET - UNIX WIN32 -]] + P('$') * lexer.range('{', '}'))) +lex:add_rule('variable', token(lexer.VARIABLE, word_match{ + 'APPLE', 'ARGS', 'BORLAND', 'CMAKE_AR', 'CMAKE_BACKWARDS_COMPATIBILITY', 'CMAKE_BASE_NAME', + 'CMAKE_BINARY_DIR', 'CMAKE_BUILD_TOOL', 'CMAKE_BUILD_TYPE', 'CMAKE_CACHEFILE_DIR', + 'CMAKE_CACHE_MAJOR_VERSION', 'CMAKE_CACHE_MINOR_VERSION', 'CMAKE_CACHE_RELEASE_VERSION', + 'CMAKE_C_COMPILE_OBJECT', 'CMAKE_C_COMPILER', 'CMAKE_C_COMPILER_ARG1', 'CMAKE_C_COMPILER_ENV_VAR', + 'CMAKE_C_COMPILER_FULLPATH', 'CMAKE_C_COMPILER_LOADED', 'CMAKE_C_COMPILER_WORKS', + 'CMAKE_C_CREATE_SHARED_LIBRARY', 'CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS', + 'CMAKE_C_CREATE_SHARED_MODULE', 'CMAKE_C_CREATE_STATIC_LIBRARY', 'CMAKE_CFG_INTDIR', + 'CMAKE_C_FLAGS', 'CMAKE_C_FLAGS_DEBUG', 'CMAKE_C_FLAGS_DEBUG_INIT', 'CMAKE_C_FLAGS_INIT', + 'CMAKE_C_FLAGS_MINSIZEREL', 'CMAKE_C_FLAGS_MINSIZEREL_INIT', 'CMAKE_C_FLAGS_RELEASE', + 'CMAKE_C_FLAGS_RELEASE_INIT', 'CMAKE_C_FLAGS_RELWITHDEBINFO', 'CMAKE_C_FLAGS_RELWITHDEBINFO_INIT', + 'CMAKE_C_IGNORE_EXTENSIONS', 'CMAKE_C_INFORMATION_LOADED', 'CMAKE_C_LINKER_PREFERENCE', + 'CMAKE_C_LINK_EXECUTABLE', 'CMAKE_C_LINK_FLAGS', 'CMAKE_COLOR_MAKEFILE', 'CMAKE_COMMAND', + 'CMAKE_COMPILER_IS_GNUCC', 'CMAKE_COMPILER_IS_GNUCC_RUN', 'CMAKE_COMPILER_IS_GNUCXX', + 'CMAKE_COMPILER_IS_GNUCXX_RUN', 'CMAKE_C_OUTPUT_EXTENSION', 'CMAKE_C_SOURCE_FILE_EXTENSIONS', + 'CMAKE_CTEST_COMMAND', 'CMAKE_CURRENT_BINARY_DIR', 'CMAKE_CURRENT_SOURCE_DIR', + 'CMAKE_CXX_COMPILE_OBJECT', 'CMAKE_CXX_COMPILER', 'CMAKE_CXX_COMPILER_ARG1', + 'CMAKE_CXX_COMPILER_ENV_VAR', 'CMAKE_CXX_COMPILER_FULLPATH', 'CMAKE_CXX_COMPILER_LOADED', + 'CMAKE_CXX_COMPILER_WORKS', 'CMAKE_CXX_CREATE_SHARED_LIBRARY', + 'CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS', 'CMAKE_CXX_CREATE_SHARED_MODULE', + 'CMAKE_CXX_CREATE_STATIC_LIBRARY', 'CMAKE_CXX_FLAGS', 'CMAKE_CXX_FLAGS_DEBUG', + 'CMAKE_CXX_FLAGS_DEBUG_INIT', 'CMAKE_CXX_FLAGS_INIT', 'CMAKE_CXX_FLAGS_MINSIZEREL', + 'CMAKE_CXX_FLAGS_MINSIZEREL_INIT', 'CMAKE_CXX_FLAGS_RELEASE', 'CMAKE_CXX_FLAGS_RELEASE_INIT', + 'CMAKE_CXX_FLAGS_RELWITHDEBINFO', 'CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT', + 'CMAKE_CXX_IGNORE_EXTENSIONS', 'CMAKE_CXX_INFORMATION_LOADED', 'CMAKE_CXX_LINKER_PREFERENCE', + 'CMAKE_CXX_LINK_EXECUTABLE', 'CMAKE_CXX_LINK_FLAGS', 'CMAKE_CXX_OUTPUT_EXTENSION', + 'CMAKE_CXX_SOURCE_FILE_EXTENSIONS', 'CMAKE_DL_LIBS', 'CMAKE_EDIT_COMMAND', + 'CMAKE_EXECUTABLE_SUFFIX', 'CMAKE_EXE_LINKER_FLAGS', 'CMAKE_EXE_LINKER_FLAGS_DEBUG', + 'CMAKE_EXE_LINKER_FLAGS_MINSIZEREL', 'CMAKE_EXE_LINKER_FLAGS_RELEASE', + 'CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO', 'CMAKE_FILES_DIRECTORY', 'CMAKE_FIND_APPBUNDLE', + 'CMAKE_FIND_FRAMEWORK', 'CMAKE_FIND_LIBRARY_PREFIXES', 'CMAKE_FIND_LIBRARY_SUFFIXES', + 'CMAKE_GENERATOR', 'CMAKE_HOME_DIRECTORY', 'CMAKE_INCLUDE_FLAG_C', 'CMAKE_INCLUDE_FLAG_C_SEP', + 'CMAKE_INCLUDE_FLAG_CXX', 'CMAKE_INIT_VALUE', 'CMAKE_INSTALL_PREFIX', 'CMAKE_LIBRARY_PATH_FLAG', + 'CMAKE_LINK_LIBRARY_FLAG', 'CMAKE_LINK_LIBRARY_SUFFIX', 'CMAKE_MacOSX_Content_COMPILE_OBJECT', + 'CMAKE_MAJOR_VERSION', 'CMAKE_MAKE_PROGRAM', 'CMAKE_MINOR_VERSION', 'CMAKE_MODULE_EXISTS', + 'CMAKE_MODULE_LINKER_FLAGS', 'CMAKE_MODULE_LINKER_FLAGS_DEBUG', + 'CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL', 'CMAKE_MODULE_LINKER_FLAGS_RELEASE', + 'CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO', 'CMAKE_NUMBER_OF_LOCAL_GENERATORS', + 'CMAKE_OSX_ARCHITECTURES', '_CMAKE_OSX_MACHINE', 'CMAKE_OSX_SYSROOT', 'CMAKE_PARENT_LIST_FILE', + 'CMAKE_PATCH_VERSION', 'CMAKE_PLATFORM_HAS_INSTALLNAME', + 'CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES', 'CMAKE_PLATFORM_ROOT_BIN', 'CMAKE_PROJECT_NAME', + 'CMAKE_RANLIB', 'CMAKE_ROOT', 'CMAKE_SHARED_LIBRARY_C_FLAGS', + 'CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS', 'CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS', + 'CMAKE_SHARED_LIBRARY_CXX_FLAGS', 'CMAKE_SHARED_LIBRARY_LINK_C_FLAGS', + 'CMAKE_SHARED_LIBRARY_PREFIX', 'CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG', + 'CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP', 'CMAKE_SHARED_LIBRARY_SONAME_C_FLAG', + 'CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG', 'CMAKE_SHARED_LIBRARY_SUFFIX', + 'CMAKE_SHARED_LINKER_FLAGS', 'CMAKE_SHARED_LINKER_FLAGS_DEBUG', + 'CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL', 'CMAKE_SHARED_LINKER_FLAGS_RELEASE', + 'CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO', 'CMAKE_SHARED_MODULE_CREATE_C_FLAGS', + 'CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS', 'CMAKE_SHARED_MODULE_PREFIX', + 'CMAKE_SHARED_MODULE_SUFFIX', 'CMAKE_SIZEOF_VOID_P', 'CMAKE_SKIP_RPATH', 'CMAKE_SOURCE_DIR', + 'CMAKE_STATIC_LIBRARY_PREFIX', 'CMAKE_STATIC_LIBRARY_SUFFIX', 'CMAKE_SYSTEM', + 'CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE', 'CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE', + 'CMAKE_SYSTEM_APPBUNDLE_PATH', 'CMAKE_SYSTEM_FRAMEWORK_PATH', 'CMAKE_SYSTEM_INCLUDE_PATH', + 'CMAKE_SYSTEM_INFO_FILE', 'CMAKE_SYSTEM_LIBRARY_PATH', 'CMAKE_SYSTEM_LOADED', 'CMAKE_SYSTEM_NAME', + 'CMAKE_SYSTEM_PROCESSOR', 'CMAKE_SYSTEM_PROGRAM_PATH', 'CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED', + 'CMAKE_SYSTEM_VERSION', 'CMAKE_UNAME', 'CMAKE_USE_RELATIVE_PATHS', 'CMAKE_VERBOSE_MAKEFILE', + 'CYGWIN', 'EXECUTABLE_OUTPUT_PATH', 'FORCE', 'HAVE_CMAKE_SIZEOF_VOID_P', 'LIBRARY_OUTPUT_PATH', + 'LOCATION', 'MACOSX_BUNDLE', 'MINGW', 'MSVC', 'MSVC60', 'MSVC70', 'MSVC71', 'MSVC80', 'MSVC_IDE', + 'POST_BUILD', 'PRE_BUILD', 'PROJECT_BINARY_DIR', 'PROJECT_NAME', 'PROJECT_SOURCE_DIR', + 'RUN_CONFIGURE', 'TARGET', 'UNIX', 'WIN32' +} + P('$') * lexer.range('{', '}'))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, word_match[[ - AND COMMAND DEFINED DOC EQUAL EXISTS GREATER INTERNAL LESS MATCHES NAME NAMES - NAME_WE NOT OR PATH PATHS PROGRAM STREQUAL STRGREATER STRINGS STRLESS -]] + S('=(){}'))) +lex:add_rule('operator', token(lexer.OPERATOR, word_match{ + 'AND', 'COMMAND', 'DEFINED', 'DOC', 'EQUAL', 'EXISTS', 'GREATER', 'INTERNAL', 'LESS', 'MATCHES', + 'NAME', 'NAMES', 'NAME_WE', 'NOT', 'OR', 'PATH', 'PATHS', 'PROGRAM', 'STREQUAL', 'STRGREATER', + 'STRINGS', 'STRLESS' +} + S('=(){}'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -136,6 +128,6 @@ lex:add_fold_point(lexer.KEYWORD, 'WHILE', 'ENDWHILE') lex:add_fold_point(lexer.FUNCTION, 'MACRO', 'ENDMACRO') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/coffeescript.lua b/syntaxhighlight/textadept/coffeescript.lua index d0f8225..fdeb92c 100644 --- a/syntaxhighlight/textadept/coffeescript.lua +++ b/syntaxhighlight/textadept/coffeescript.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- CoffeeScript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') @@ -12,16 +12,17 @@ local lex = lexer.new('coffeescript', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - all and bind break by case catch class const continue default delete do each - else enum export extends false finally for function if import in instanceof is - isnt let loop native new no not of off on or return super switch then this - throw true try typeof unless until var void when while with yes -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'all', 'and', 'bind', 'break', 'by', 'case', 'catch', 'class', 'const', 'continue', 'default', + 'delete', 'do', 'each', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', + 'function', 'if', 'import', 'in', 'instanceof', 'is', 'isnt', 'let', 'loop', 'native', 'new', + 'no', 'not', 'of', 'off', 'on', 'or', 'return', 'super', 'switch', 'then', 'this', 'throw', + 'true', 'try', 'typeof', 'unless', 'until', 'var', 'void', 'when', 'while', 'with', 'yes' +})) -- Fields: object properties and methods. -lex:add_rule('field', token(lexer.FUNCTION, '.' * (S('_$') + lexer.alpha) * - (S('_$') + lexer.alnum)^0)) +lex:add_rule('field', + token(lexer.FUNCTION, '.' * (S('_$') + lexer.alpha) * (S('_$') + lexer.alnum)^0)) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -30,8 +31,8 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) local sq_str = lexer.range("'") local dq_str = lexer.range('"') local string = token(lexer.STRING, sq_str + dq_str) -local regex_str = #P('/') * lexer.last_char_includes('+-*%<>!=^&|?~:;,([{') * - lexer.range('/', true) * S('igm')^0 +local regex_str = + #P('/') * lexer.last_char_includes('+-*%<>!=^&|?~:;,([{') * lexer.range('/', true) * S('igm')^0 local regex = token(lexer.REGEX, regex_str) lex:add_rule('string', string + regex) diff --git a/syntaxhighlight/textadept/container.lua b/syntaxhighlight/textadept/container.lua index 17311b9..ef35595 100644 --- a/syntaxhighlight/textadept/container.lua +++ b/syntaxhighlight/textadept/container.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Container LPeg lexer. -- This is SciTE's plain text lexer. diff --git a/syntaxhighlight/textadept/context.lua b/syntaxhighlight/textadept/context.lua index ca07aa3..8523fd1 100644 --- a/syntaxhighlight/textadept/context.lua +++ b/syntaxhighlight/textadept/context.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke, Lars Otter. See License.txt. +-- Copyright 2006-2021 Robert Gieseke, Lars Otter. See LICENSE. -- ConTeXt LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('context') @@ -19,25 +19,20 @@ lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) -- Sections. -local wm_section = word_match[[ - chapter part section subject subsection subsubject subsubsection subsubsubject - subsubsubsection subsubsubsubject title -]] -local section = token(lexer.CLASS, '\\' * - (wm_section + (startstop * wm_section))) +local wm_section = word_match{ + 'chapter', 'part', 'section', 'subject', 'subsection', 'subsubject', 'subsubsection', + 'subsubsubject', 'subsubsubsection', 'subsubsubsubject', 'title' +} +local section = token(lexer.CLASS, '\\' * startstop^-1 * wm_section) lex:add_rule('section', section) -- TeX and ConTeXt mkiv environments. -local environment = token(lexer.STRING, '\\' * (beginend + startstop) * - lexer.alpha^1) +local environment = token(lexer.STRING, '\\' * (beginend + startstop) * lexer.alpha^1) lex:add_rule('environment', environment) -- Commands. -local command = token(lexer.KEYWORD, '\\' * ( - lexer.alpha^1 * P('\\') * lexer.space^1 + - lexer.alpha^1 + - S('!"#$%&\',./;=[\\]_{|}~`^-') -)) +local command = token(lexer.KEYWORD, '\\' * + (lexer.alpha^1 * P('\\') * lexer.space^1 + lexer.alpha^1 + S('!"#$%&\',./;=[\\]_{|}~`^-'))) lex:add_rule('command', command) -- Operators. @@ -48,7 +43,7 @@ lex:add_rule('operator', operator) lex:add_fold_point('environment', '\\start', '\\stop') lex:add_fold_point('environment', '\\begin', '\\end') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '%', lexer.fold_line_comments('%')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%')) -- Embedded Lua. local luatex = lexer.load('lua') diff --git a/syntaxhighlight/textadept/cpp.lua b/syntaxhighlight/textadept/cpp.lua index 565cd50..89ea40f 100644 --- a/syntaxhighlight/textadept/cpp.lua +++ b/syntaxhighlight/textadept/cpp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- C++ LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('cpp') @@ -13,26 +13,27 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - asm auto break case catch class const const_cast continue default delete do - dynamic_cast else explicit export extern false for friend goto if inline - mutable namespace new operator private protected public register - reinterpret_cast return sizeof static static_cast switch template this throw - true try typedef typeid typename using virtual volatile while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'asm', 'auto', 'break', 'case', 'catch', 'class', 'const', 'const_cast', 'continue', 'default', + 'delete', 'do', 'dynamic_cast', 'else', 'explicit', 'export', 'extern', 'false', 'for', 'friend', + 'goto', 'if', 'inline', 'mutable', 'namespace', 'new', 'operator', 'private', 'protected', + 'public', 'register', 'reinterpret_cast', 'return', 'sizeof', 'static', 'static_cast', 'switch', + 'template', 'this', 'throw', 'true', 'try', 'typedef', 'typeid', 'typename', 'using', 'virtual', + 'volatile', 'while', -- Operators. - and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq + 'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not', 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq', -- C++11. - alignas alignof constexpr decltype final noexcept override static_assert - thread_local -]])) + 'alignas', 'alignof', 'constexpr', 'decltype', 'final', 'noexcept', 'override', 'static_assert', + 'thread_local' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool char double enum float int long short signed struct union unsigned void - wchar_t +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'char', 'double', 'enum', 'float', 'int', 'long', 'short', 'signed', 'struct', 'union', + 'unsigned', 'void', 'wchar_t', -- C++11. - char16_t char32_t nullptr -]])) + 'char16_t', 'char32_t', 'nullptr' +})) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) @@ -57,10 +58,8 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) -- Preprocessor. local include = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * 'include') * (ws * token(lexer.STRING, lexer.range('<', '>', true)))^-1 -local preproc = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * word_match[[ - define elif else endif error if ifdef ifndef import line pragma undef using - warning -]]) +local preproc = token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * + word_match('define elif else endif error if ifdef ifndef import line pragma undef using warning')) lex:add_rule('preprocessor', include + preproc) -- Operators. @@ -72,6 +71,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif') lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/crystal.lua b/syntaxhighlight/textadept/crystal.lua index e80115c..86c1a48 100644 --- a/syntaxhighlight/textadept/crystal.lua +++ b/syntaxhighlight/textadept/crystal.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Copyright 2017 Michel Martens. -- Crystal LPeg lexer (based on Ruby). local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('crystal') @@ -13,42 +13,26 @@ local lex = lexer.new('crystal') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - alias begin break case class def defined? do else elsif end ensure false for - if in module next nil not redo rescue retry return self super then true undef - unless until when while yield __FILE__ __LINE__ -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'alias', 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else', 'elsif', 'end', + 'ensure', 'false', 'for', 'if', 'in', 'module', 'next', 'nil', 'not', 'redo', 'rescue', 'retry', + 'return', 'self', 'super', 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield', + '__FILE__', '__LINE__' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abort at_exit caller delay exit fork future get_stack_top gets lazy loop main - p print printf puts raise rand read_line require sleep spawn sprintf system - with_color +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abort', 'at_exit', 'caller', 'delay', 'exit', 'fork', 'future', 'get_stack_top', 'gets', 'lazy', + 'loop', 'main', 'p', 'print', 'printf', 'puts', 'raise', 'rand', 'read_line', 'require', 'sleep', + 'spawn', 'sprintf', 'system', 'with_color', -- Macros. - assert_responds_to debugger parallel pp record redefine_main -]]) * -S('.:|')) + 'assert_responds_to', 'debugger', 'parallel', 'pp', 'record', 'redefine_main' +}) * -S('.:|')) -- Identifiers. local word_char = lexer.alnum + S('_!?') local word = (lexer.alpha + '_') * word_char^0 -local identifier = token(lexer.IDENTIFIER, word) - -local delimiter_matches = {['('] = ')', ['['] = ']', ['{'] = '}'} -local literal_delimitted = P(function(input, index) - local delimiter = input:sub(index, index) - if not delimiter:find('[%w\r\n\f\t ]') then -- only non alpha-numerics - local match_pos, patt - if delimiter_matches[delimiter] then - -- Handle nested delimiter/matches in strings. - local s, e = delimiter, delimiter_matches[delimiter] - patt = lexer.range(s, e, false, true, true) - else - patt = lexer.range(delimiter) - end - match_pos = lpeg.match(patt, input, index) - return match_pos or #input + 1 - end -end) +lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) @@ -58,18 +42,16 @@ local cmd_str = lexer.range('`') local sq_str = lexer.range("'") local dq_str = lexer.range('"') local heredoc = '<<' * P(function(input, index) - local _, e, indented, _, delimiter = input:find( - '^(%-?)(["`]?)([%a_][%w_]*)%2[\n\r\f;]+', index) + local _, e, indented, _, delimiter = input:find('^(%-?)(["`]?)([%a_][%w_]*)%2[\n\r\f;]+', index) if not delimiter then return end local end_heredoc = (#indented > 0 and '[\n\r\f]+ *' or '[\n\r\f]+') _, e = input:find(end_heredoc .. delimiter, e) return e and e + 1 or #input + 1 end) -local string = token(lexer.STRING, (sq_str + dq_str + heredoc + cmd_str) * - S('f')^-1) +local string = token(lexer.STRING, (sq_str + dq_str + heredoc + cmd_str) * S('f')^-1) -- TODO: regex_str fails with `obj.method /patt/` syntax. -local regex_str = #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * - lexer.range('/', true) * S('iomx')^0 +local regex_str = + #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * lexer.range('/', true) * S('iomx')^0 local regex = token(lexer.REGEX, regex_str) lex:add_rule('string', string + regex) @@ -79,33 +61,28 @@ local bin = '0b' * S('01')^1 * ('_' * S('01')^1)^0 local integer = S('+-')^-1 * (bin + lexer.hex_num + lexer.oct_num + dec) -- TODO: meta, control, etc. for numeric_literal. local numeric_literal = '?' * (lexer.any - lexer.space) * -word_char -lex:add_rule('number', token(lexer.NUMBER, lexer.float * S('ri')^-1 + integer + - numeric_literal)) +lex:add_rule('number', token(lexer.NUMBER, lexer.float * S('ri')^-1 + integer + numeric_literal)) -- Variables. -local global_var = '$' * ( - word + S('!@L+`\'=~/\\,.;<>_*"$?:') + - lexer.digit + - '-' * S('0FadiIKlpvw') -) +local global_var = '$' * + (word + S('!@L+`\'=~/\\,.;<>_*"$?:') + lexer.digit + '-' * S('0FadiIKlpvw')) local class_var = '@@' * word local inst_var = '@' * word -lex:add_rule('variable', token(lexer.VARIABLE, global_var + class_var + - inst_var)) +lex:add_rule('variable', token(lexer.VARIABLE, global_var + class_var + inst_var)) -- Symbols. lex:add_rule('symbol', token('symbol', ':' * P(function(input, index) if input:sub(index - 2, index - 2) ~= ':' then return index end end) * (word_char^1 + sq_str + dq_str))) -lex:add_style('symbol', lexer.STYLE_CONSTANT) +lex:add_style('symbol', lexer.styles.constant) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~'))) -- Fold points. local function disambiguate(text, pos, line, s) - return line:sub(1, s - 1):match('^%s*$') and - not text:sub(1, pos - 1):match('\\[ \t]*\r?\n$') and 1 or 0 + return line:sub(1, s - 1):match('^%s*$') and not text:sub(1, pos - 1):match('\\[ \t]*\r?\n$') and + 1 or 0 end lex:add_fold_point(lexer.KEYWORD, 'begin', 'end') lex:add_fold_point(lexer.KEYWORD, 'case', 'end') @@ -121,6 +98,6 @@ lex:add_fold_point(lexer.KEYWORD, 'until', disambiguate) lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.OPERATOR, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/csharp.lua b/syntaxhighlight/textadept/csharp.lua index 990225c..6dcc0e1 100644 --- a/syntaxhighlight/textadept/csharp.lua +++ b/syntaxhighlight/textadept/csharp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- C# LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('csharp') @@ -12,21 +12,22 @@ local lex = lexer.new('csharp') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - class delegate enum event interface namespace struct using abstract const - explicit extern fixed implicit internal lock out override params partial - private protected public ref sealed static readonly unsafe virtual volatile - add as assembly base break case catch checked continue default do else finally - for foreach get goto if in is new remove return set sizeof stackalloc super - switch this throw try typeof unchecked value var void while yield - null true false -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'class', 'delegate', 'enum', 'event', 'interface', 'namespace', 'struct', 'using', 'abstract', + 'const', 'explicit', 'extern', 'fixed', 'implicit', 'internal', 'lock', 'out', 'override', + 'params', 'partial', 'private', 'protected', 'public', 'ref', 'sealed', 'static', 'readonly', + 'unsafe', 'virtual', 'volatile', 'add', 'as', 'assembly', 'base', 'break', 'case', 'catch', + 'checked', 'continue', 'default', 'do', 'else', 'finally', 'for', 'foreach', 'get', 'goto', 'if', + 'in', 'is', 'new', 'remove', 'return', 'set', 'sizeof', 'stackalloc', 'super', 'switch', 'this', + 'throw', 'try', 'typeof', 'unchecked', 'value', 'var', 'void', 'while', 'yield', 'null', 'true', + 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool byte char decimal double float int long object operator sbyte short - string uint ulong ushort -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'byte', 'char', 'decimal', 'double', 'float', 'int', 'long', 'object', 'operator', + 'sbyte', 'short', 'string', 'uint', 'ulong', 'ushort' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -47,9 +48,7 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('lLdDfFmM')^-1)) -- Preprocessor. lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * - word_match[[ - define elif else endif error if line undef warning region endregion - ]])) + word_match('define elif else endif error if line undef warning region endregion'))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('~!.,:;+-*/<>=\\^|&%?()[]{}'))) @@ -61,6 +60,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif') lex:add_fold_point(lexer.PREPROCESSOR, 'region', 'endregion') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/css.lua b/syntaxhighlight/textadept/css.lua index 1f79687..8e0e757 100644 --- a/syntaxhighlight/textadept/css.lua +++ b/syntaxhighlight/textadept/css.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- CSS LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('css') @@ -12,134 +12,133 @@ local lex = lexer.new('css') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Properties. -lex:add_rule('property', token('property', word_match[[ +lex:add_rule('property', token('property', word_match{ -- CSS 1. - color background-color background-image background-repeat - background-attachment background-position background font-family font-style - font-variant font-weight font-size font word-spacing letter-spacing - text-decoration vertical-align text-transform text-align text-indent - line-height margin-top margin-right margin-bottom margin-left margin - padding-top padding-right padding-bottom padding-left padding border-top-width - border-right-width border-bottom-width border-left-width border-width - border-top border-right border-bottom border-left border border-color - border-style width height float clear display white-space list-style-type - list-style-image list-style-position list-style + 'color', 'background-color', 'background-image', 'background-repeat', 'background-attachment', + 'background-position', 'background', 'font-family', 'font-style', 'font-variant', 'font-weight', + 'font-size', 'font', 'word-spacing', 'letter-spacing', 'text-decoration', 'vertical-align', + 'text-transform', 'text-align', 'text-indent', 'line-height', 'margin-top', 'margin-right', + 'margin-bottom', 'margin-left', 'margin', 'padding-top', 'padding-right', 'padding-bottom', + 'padding-left', 'padding', 'border-top-width', 'border-right-width', 'border-bottom-width', + 'border-left-width', 'border-width', 'border-top', 'border-right', 'border-bottom', 'border-left', + 'border', 'border-color', 'border-style', 'width', 'height', 'float', 'clear', 'display', + 'white-space', 'list-style-type', 'list-style-image', 'list-style-position', 'list-style', -- CSS 2. - border-top-color border-right-color border-bottom-color border-left-color - border-color border-top-style border-right-style border-bottom-style - border-left-style border-style top right bottom left position z-index - direction unicode-bidi min-width max-width min-height max-height overflow clip - visibility content quotes counter-reset counter-increment marker-offset size - marks page-break-before page-break-after page-break-inside page orphans widows - font-stretch font-size-adjust unicode-range units-per-em src panose-1 stemv - stemh slope cap-height x-height ascent descent widths bbox definition-src - baseline centerline mathline topline text-shadow caption-side table-layout - border-collapse border-spacing empty-cells speak-header cursor outline - outline-width outline-style outline-color volume speak pause-before - pause-after pause cue-before cue-after cue play-during azimuth elevation - speech-rate voice-family pitch pitch-range stress richness speak-punctuation - speak-numeral + 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', + 'border-color', 'border-top-style', 'border-right-style', 'border-bottom-style', + 'border-left-style', 'border-style', 'top', 'right', 'bottom', 'left', 'position', 'z-index', + 'direction', 'unicode-bidi', 'min-width', 'max-width', 'min-height', 'max-height', 'overflow', + 'clip', 'visibility', 'content', 'quotes', 'counter-reset', 'counter-increment', 'marker-offset', + 'size', 'marks', 'page-break-before', 'page-break-after', 'page-break-inside', 'page', 'orphans', + 'widows', 'font-stretch', 'font-size-adjust', 'unicode-range', 'units-per-em', 'src', 'panose-1', + 'stemv', 'stemh', 'slope', 'cap-height', 'x-height', 'ascent', 'descent', 'widths', 'bbox', + 'definition-src', 'baseline', 'centerline', 'mathline', 'topline', 'text-shadow', 'caption-side', + 'table-layout', 'border-collapse', 'border-spacing', 'empty-cells', 'speak-header', 'cursor', + 'outline', 'outline-width', 'outline-style', 'outline-color', 'volume', 'speak', 'pause-before', + 'pause-after', 'pause', 'cue-before', 'cue-after', 'cue', 'play-during', 'azimuth', 'elevation', + 'speech-rate', 'voice-family', 'pitch', 'pitch-range', 'stress', 'richness', 'speak-punctuation', + 'speak-numeral', -- CSS 3. - flex flex-basis flex-direction flex-flow flex-grow flex-shrink flex-wrap - align-content align-items align-self justify-content order border-radius - transition transform box-shadow filter opacity resize word-break word-wrap - box-sizing animation text-overflow -]])) -lex:add_style('property', lexer.STYLE_KEYWORD) + 'flex', 'flex-basis', 'flex-direction', 'flex-flow', 'flex-grow', 'flex-shrink', 'flex-wrap', + 'align-content', 'align-items', 'align-self', 'justify-content', 'order', 'border-radius', + 'transition', 'transform', 'box-shadow', 'filter', 'opacity', 'resize', 'word-break', 'word-wrap', + 'box-sizing', 'animation', 'text-overflow' +})) +lex:add_style('property', lexer.styles.keyword) -- Values. -lex:add_rule('value', token('value', word_match[[ +lex:add_rule('value', token('value', word_match{ -- CSS 1. - auto none normal italic oblique small-caps bold bolder lighter xx-small - x-small small medium large x-large xx-large larger smaller transparent repeat - repeat-x repeat-y no-repeat scroll fixed top bottom left center right justify - both underline overline line-through blink baseline sub super text-top middle - text-bottom capitalize uppercase lowercase thin medium thick dotted dashed - solid double groove ridge inset outset block inline list-item pre no-wrap - inside outside disc circle square decimal lower-roman upper-roman lower-alpha - upper-alpha aqua black blue fuchsia gray green lime maroon navy olive purple - red silver teal white yellow + 'auto', 'none', 'normal', 'italic', 'oblique', 'small-caps', 'bold', 'bolder', 'lighter', + 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'larger', 'smaller', + 'transparent', 'repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'scroll', 'fixed', 'top', 'bottom', + 'left', 'center', 'right', 'justify', 'both', 'underline', 'overline', 'line-through', 'blink', + 'baseline', 'sub', 'super', 'text-top', 'middle', 'text-bottom', 'capitalize', 'uppercase', + 'lowercase', 'thin', 'medium', 'thick', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', + 'inset', 'outset', 'block', 'inline', 'list-item', 'pre', 'no-wrap', 'inside', 'outside', 'disc', + 'circle', 'square', 'decimal', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha', 'aqua', + 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', + 'silver', 'teal', 'white', 'yellow', -- CSS 2. - inherit run-in compact marker table inline-table table-row-group - table-header-group table-footer-group table-row table-column-group - table-column table-cell table-caption static relative absolute fixed ltr rtl - embed bidi-override visible hidden scroll collapse open-quote close-quote - no-open-quote no-close-quote decimal-leading-zero lower-greek lower-latin - upper-latin hebrew armenian georgian cjk-ideographic hiragana katakana - hiragana-iroha katakana-iroha landscape portrait crop cross always avoid wider - narrower ultra-condensed extra-condensed condensed semi-condensed - semi-expanded expanded extra-expanded ultra-expanded caption icon menu - message-box small-caption status-bar separate show hide once crosshair default - pointer move text wait help e-resize ne-resize nw-resize n-resize se-resize - sw-resize s-resize w-resize ActiveBorder ActiveCaption AppWorkspace Background - ButtonFace ButtonHighlight ButtonShadow InactiveCaptionText ButtonText - CaptionText GrayText Highlight HighlightText InactiveBorder InactiveCaption - InfoBackground InfoText Menu MenuText Scrollbar ThreeDDarkShadow ThreeDFace - ThreeDHighlight ThreeDLightShadow ThreeDShadow Window WindowFrame WindowText - silent x-soft soft medium loud x-loud spell-out mix left-side far-left - center-left center-right far-right right-side behind leftwards rightwards - below level above higher lower x-slow slow medium fast x-fast faster slower - male female child x-low low high x-high code digits continous + 'inherit', 'run-in', 'compact', 'marker', 'table', 'inline-table', 'table-row-group', + 'table-header-group', 'table-footer-group', 'table-row', 'table-column-group', 'table-column', + 'table-cell', 'table-caption', 'static', 'relative', 'absolute', 'fixed', 'ltr', 'rtl', 'embed', + 'bidi-override', 'visible', 'hidden', 'scroll', 'collapse', 'open-quote', 'close-quote', + 'no-open-quote', 'no-close-quote', 'decimal-leading-zero', 'lower-greek', 'lower-latin', + 'upper-latin', 'hebrew', 'armenian', 'georgian', 'cjk-ideographic', 'hiragana', 'katakana', + 'hiragana-iroha', 'katakana-iroha', 'landscape', 'portrait', 'crop', 'cross', 'always', 'avoid', + 'wider', 'narrower', 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', + 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded', 'caption', 'icon', 'menu', + 'message-box', 'small-caption', 'status-bar', 'separate', 'show', 'hide', 'once', 'crosshair', + 'default', 'pointer', 'move', 'text', 'wait', 'help', 'e-resize', 'ne-resize', 'nw-resize', + 'n-resize', 'se-resize', 'sw-resize', 's-resize', 'w-resize', 'ActiveBorder', 'ActiveCaption', + 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', + 'InactiveCaptionText', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', + 'InactiveBorder', 'InactiveCaption', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', + 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', + 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText', 'silent', 'x-soft', 'soft', 'medium', + 'loud', 'x-loud', 'spell-out', 'mix', 'left-side', 'far-left', 'center-left', 'center-right', + 'far-right', 'right-side', 'behind', 'leftwards', 'rightwards', 'below', 'level', 'above', + 'higher', 'lower', 'x-slow', 'slow', 'medium', 'fast', 'x-fast', 'faster', 'slower', 'male', + 'female', 'child', 'x-low', 'low', 'high', 'x-high', 'code', 'digits', 'continous', -- CSS 3. - flex row column ellipsis inline-block -]])) -lex:add_style('value', lexer.STYLE_CONSTANT) + 'flex', 'row', 'column', 'ellipsis', 'inline-block' +})) +lex:add_style('value', lexer.styles.constant) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - attr blackness blend blenda blur brightness calc circle color-mod contrast - counter cubic-bezier device-cmyk drop-shadow ellipse gray grayscale hsl hsla - hue hue-rotate hwb image inset invert lightness linear-gradient matrix - matrix3d opacity perspective polygon radial-gradient rect - repeating-linear-gradient repeating-radial-gradient rgb rgba rotate rotate3d - rotateX rotateY rotateZ saturate saturation scale scale3d scaleX scaleY scaleZ - sepia shade skewX skewY steps tint toggle translate translate3d translateX - translateY translateZ url whiteness var -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'attr', 'blackness', 'blend', 'blenda', 'blur', 'brightness', 'calc', 'circle', 'color-mod', + 'contrast', 'counter', 'cubic-bezier', 'device-cmyk', 'drop-shadow', 'ellipse', 'gray', + 'grayscale', 'hsl', 'hsla', 'hue', 'hue-rotate', 'hwb', 'image', 'inset', 'invert', 'lightness', + 'linear-gradient', 'matrix', 'matrix3d', 'opacity', 'perspective', 'polygon', 'radial-gradient', + 'rect', 'repeating-linear-gradient', 'repeating-radial-gradient', 'rgb', 'rgba', 'rotate', + 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'saturate', 'saturation', 'scale', 'scale3d', + 'scaleX', 'scaleY', 'scaleZ', 'sepia', 'shade', 'skewX', 'skewY', 'steps', 'tint', 'toggle', + 'translate', 'translate3d', 'translateX', 'translateY', 'translateZ', 'url', 'whiteness', 'var' +})) -- Colors. local xdigit = lexer.xdigit -lex:add_rule('color', token('color', word_match[[ - aliceblue antiquewhite aqua aquamarine azure beige bisque black - blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate - coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod - darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange - darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray - darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey - dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold - goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory - khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral - lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink - lightsalmon lightseagreen lightskyblue lightslategray lightslategrey - lightsteelblue lightyellow lime limegreen linen magenta maroon - mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen - mediumslateblue mediumspringgreen mediumturquoise mediumvioletred - midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive - olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise - palevioletred papayawhip peachpuff peru pink plum powderblue purple - rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen - seashell sienna silver skyblue slateblue slategray slategrey snow springgreen - steelblue tan teal thistle tomato transparent turquoise violet wheat white - whitesmoke yellow yellowgreen -]] + '#' * xdigit * xdigit * xdigit * (xdigit * xdigit * xdigit)^-1)) -lex:add_style('color', lexer.STYLE_NUMBER) +lex:add_rule('color', token('color', word_match{ + 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', + 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', + 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', + 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', + 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', + 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', + 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', + 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey', + 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', + 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', + 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', + 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', + 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', + 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', + 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', + 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', + 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', + 'purple', 'rebeccapurple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', + 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', + 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'transparent', + 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen' +} + '#' * xdigit * xdigit * xdigit * (xdigit * xdigit * xdigit)^-1)) +lex:add_style('color', lexer.styles.number) -- Identifiers. -local word = lexer.alpha * (lexer.alnum + S('_-'))^0 -lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('_-'))^0)) -- Pseudo classes and pseudo elements. -lex:add_rule('pseudoclass', ':' * token('pseudoclass', word_match[[ - active checked disabled empty enabled first-child first-of-type focus hover - in-range invalid lang last-child last-of-type link not nth-child - nth-last-child nth-last-of-type nth-of-type only-of-type only-child optional - out-of-range read-only read-write required root target valid visited -]])) -lex:add_style('pseudoclass', lexer.STYLE_CONSTANT) -lex:add_rule('pseudoelement', '::' * token('pseudoelement', word_match[[ - after before first-letter first-line selection -]])) -lex:add_style('pseudoelement', lexer.STYLE_CONSTANT) +lex:add_rule('pseudoclass', ':' * token('pseudoclass', word_match{ + 'active', 'checked', 'disabled', 'empty', 'enabled', 'first-child', 'first-of-type', 'focus', + 'hover', 'in-range', 'invalid', 'lang', 'last-child', 'last-of-type', 'link', 'not', 'nth-child', + 'nth-last-child', 'nth-last-of-type', 'nth-of-type', 'only-of-type', 'only-child', 'optional', + 'out-of-range', 'read-only', 'read-write', 'required', 'root', 'target', 'valid', 'visited' +})) +lex:add_style('pseudoclass', lexer.styles.constant) +lex:add_rule('pseudoelement', '::' * + token('pseudoelement', word_match('after before first-letter first-line selection'))) +lex:add_style('pseudoelement', lexer.styles.constant) -- Strings. local sq_str = lexer.range("'") @@ -150,21 +149,18 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.range('/*', '*/'))) -- Numbers. -local unit = token('unit', word_match[[ - ch cm deg dpcm dpi dppx em ex grad Hz in kHz mm ms pc pt px q rad rem s turn - vh vmax vmin vw -]]) -lex:add_style('unit', lexer.STYLE_NUMBER) -lex:add_rule('number', token(lexer.NUMBER, lexer.digit^1) * unit^-1) +local unit = token('unit', word_match( + 'ch cm deg dpcm dpi dppx em ex grad Hz in kHz mm ms pc pt px q rad rem s turn vh vmax vmin vw')) +lex:add_style('unit', lexer.styles.number) +lex:add_rule('number', token(lexer.NUMBER, lexer.dec_num) * unit^-1) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('~!#*>+=|.,:;()[]{}'))) -- At rule. -lex:add_rule('at_rule', token('at_rule', P('@') * word_match[[ - charset font-face media page import namespace keyframes -]])) -lex:add_style('at_rule', lexer.STYLE_PREPROCESSOR) +lex:add_rule('at_rule', token('at_rule', '@' * + word_match('charset font-face media page import namespace keyframes'))) +lex:add_style('at_rule', lexer.styles.preprocessor) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') diff --git a/syntaxhighlight/textadept/cuda.lua b/syntaxhighlight/textadept/cuda.lua index 51188b5..c60ec6a 100644 --- a/syntaxhighlight/textadept/cuda.lua +++ b/syntaxhighlight/textadept/cuda.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- CUDA LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('cuda', {inherit = lexer.load('cpp')}) @@ -12,61 +12,59 @@ local lex = lexer.new('cuda', {inherit = lexer.load('cpp')}) lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:modify_rule('keyword', token(lexer.KEYWORD, word_match[[ - __global__ __host__ __device__ __constant__ __shared__ -]]) + lex:get_rule('keyword')) +local keyword = token(lexer.KEYWORD, + word_match('__global__ __host__ __device__ __constant__ __shared__')) +lex:modify_rule('keyword', keyword + lex:get_rule('keyword')) -- Types. -lex:modify_rule('type', token(lexer.TYPE, word_match[[ - uint int1 uint1 int2 uint2 int3 uint3 int4 uint4 float1 float2 float3 float4 - char1 char2 char3 char4 uchar1 uchar2 uchar3 uchar4 short1 short2 short3 - short4 dim1 dim2 dim3 dim4 -]]) + lex:get_rule('type') + +lex:modify_rule('type', token(lexer.TYPE, word_match{ + 'uint', 'int1', 'uint1', 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'float1', 'float2', + 'float3', 'float4', 'char1', 'char2', 'char3', 'char4', 'uchar1', 'uchar2', 'uchar3', 'uchar4', + 'short1', 'short2', 'short3', 'short4', 'dim1', 'dim2', 'dim3', 'dim4' +}) + lex:get_rule('type') + -- Functions. -token(lexer.FUNCTION, word_match[[ +token(lexer.FUNCTION, word_match{ -- Atom. - atomicAdd atomicAnd atomicCAS atomicDec atomicExch atomicInc atomicMax - atomicMin atomicOr atomicSub atomicXor + 'atomicAdd', 'atomicAnd', 'atomicCAS', 'atomicDec', 'atomicExch', 'atomicInc', 'atomicMax', + 'atomicMin', 'atomicOr', 'atomicSub', 'atomicXor', -- -- Dev. - tex1D tex1Dfetch tex2D __float_as_int __int_as_float __float2int_rn - __float2int_rz __float2int_ru __float2int_rd __float2uint_rn __float2uint_rz - __float2uint_ru __float2uint_rd __int2float_rn __int2float_rz __int2float_ru - __int2float_rd __uint2float_rn __uint2float_rz __uint2float_ru __uint2float_rd - __fadd_rz __fmul_rz __fdividef __mul24 __umul24 __mulhi __umulhi __mul64hi - __umul64hi min umin fminf fmin max umax fmaxf fmax abs fabsf fabs sqrtf sqrt - sinf __sinf sin cosf __cosf cos sincosf __sincosf expf __expf exp logf __logf - log + 'tex1D', 'tex1Dfetch', 'tex2D', '__float_as_int', '__int_as_float', '__float2int_rn', + '__float2int_rz', '__float2int_ru', '__float2int_rd', '__float2uint_rn', '__float2uint_rz', + '__float2uint_ru', '__float2uint_rd', '__int2float_rn', '__int2float_rz', '__int2float_ru', + '__int2float_rd', '__uint2float_rn', '__uint2float_rz', '__uint2float_ru', '__uint2float_rd', + '__fadd_rz', '__fmul_rz', '__fdividef', '__mul24', '__umul24', '__mulhi', '__umulhi', '__mul64hi', + '__umul64hi', 'min', 'umin', 'fminf', 'fmin', 'max', 'umax', 'fmaxf', 'fmax', 'abs', 'fabsf', + 'fabs', 'sqrtf', 'sqrt', 'sinf', '__sinf', 'sin', 'cosf', '__cosf', 'cos', 'sincosf', '__sincosf', + 'expf', '__expf', 'exp', 'logf', '__logf', 'log', -- -- Runtime. - cudaBindTexture cudaBindTextureToArray cudaChooseDevice cudaConfigureCall - cudaCreateChannelDesc cudaD3D10GetDevice cudaD3D10MapResources - cudaD3D10RegisterResource cudaD3D10ResourceGetMappedArray - cudaD3D10ResourceGetMappedPitch cudaD3D10ResourceGetMappedPointer - cudaD3D10ResourceGetMappedSize cudaD3D10ResourceGetSurfaceDimensions - cudaD3D10ResourceSetMapFlags cudaD3D10SetDirect3DDevice - cudaD3D10UnmapResources cudaD3D10UnregisterResource cudaD3D9GetDevice - cudaD3D9GetDirect3DDevice cudaD3D9MapResources cudaD3D9RegisterResource - cudaD3D9ResourceGetMappedArray cudaD3D9ResourceGetMappedPitch - cudaD3D9ResourceGetMappedPointer cudaD3D9ResourceGetMappedSize - cudaD3D9ResourceGetSurfaceDimensions cudaD3D9ResourceSetMapFlags - cudaD3D9SetDirect3DDevice cudaD3D9UnmapResources cudaD3D9UnregisterResource - cudaEventCreate cudaEventDestroy cudaEventElapsedTime cudaEventQuery - cudaEventRecord cudaEventSynchronize cudaFree cudaFreeArray cudaFreeHost - cudaGetChannelDesc cudaGetDevice cudaGetDeviceCount cudaGetDeviceProperties - cudaGetErrorString cudaGetLastError cudaGetSymbolAddress cudaGetSymbolSize - cudaGetTextureAlignmentOffset cudaGetTextureReference cudaGLMapBufferObject - cudaGLRegisterBufferObject cudaGLSetGLDevice cudaGLUnmapBufferObject - cudaGLUnregisterBufferObject cudaLaunch cudaMalloc cudaMalloc3D - cudaMalloc3DArray cudaMallocArray cudaMallocHost cudaMallocPitch cudaMemcpy - cudaMemcpy2D cudaMemcpy2DArrayToArray cudaMemcpy2DFromArray - cudaMemcpy2DToArray cudaMemcpy3D cudaMemcpyArrayToArray cudaMemcpyFromArray - cudaMemcpyFromSymbol cudaMemcpyToArray cudaMemcpyToSymbol cudaMemset - cudaMemset2D cudaMemset3D cudaSetDevice cudaSetupArgument cudaStreamCreate - cudaStreamDestroy cudaStreamQuery cudaStreamSynchronize cudaThreadExit - cudaThreadSynchronize cudaUnbindTexture -]]) + + 'cudaBindTexture', 'cudaBindTextureToArray', 'cudaChooseDevice', 'cudaConfigureCall', + 'cudaCreateChannelDesc', 'cudaD3D10GetDevice', 'cudaD3D10MapResources', + 'cudaD3D10RegisterResource', 'cudaD3D10ResourceGetMappedArray', 'cudaD3D10ResourceGetMappedPitch', + 'cudaD3D10ResourceGetMappedPointer', 'cudaD3D10ResourceGetMappedSize', + 'cudaD3D10ResourceGetSurfaceDimensions', 'cudaD3D10ResourceSetMapFlags', + 'cudaD3D10SetDirect3DDevice', 'cudaD3D10UnmapResources', 'cudaD3D10UnregisterResource', + 'cudaD3D9GetDevice', 'cudaD3D9GetDirect3DDevice', 'cudaD3D9MapResources', + 'cudaD3D9RegisterResource', 'cudaD3D9ResourceGetMappedArray', 'cudaD3D9ResourceGetMappedPitch', + 'cudaD3D9ResourceGetMappedPointer', 'cudaD3D9ResourceGetMappedSize', + 'cudaD3D9ResourceGetSurfaceDimensions', 'cudaD3D9ResourceSetMapFlags', + 'cudaD3D9SetDirect3DDevice', 'cudaD3D9UnmapResources', 'cudaD3D9UnregisterResource', + 'cudaEventCreate', 'cudaEventDestroy', 'cudaEventElapsedTime', 'cudaEventQuery', + 'cudaEventRecord', 'cudaEventSynchronize', 'cudaFree', 'cudaFreeArray', 'cudaFreeHost', + 'cudaGetChannelDesc', 'cudaGetDevice', 'cudaGetDeviceCount', 'cudaGetDeviceProperties', + 'cudaGetErrorString', 'cudaGetLastError', 'cudaGetSymbolAddress', 'cudaGetSymbolSize', + 'cudaGetTextureAlignmentOffset', 'cudaGetTextureReference', 'cudaGLMapBufferObject', + 'cudaGLRegisterBufferObject', 'cudaGLSetGLDevice', 'cudaGLUnmapBufferObject', + 'cudaGLUnregisterBufferObject', 'cudaLaunch', 'cudaMalloc', 'cudaMalloc3D', 'cudaMalloc3DArray', + 'cudaMallocArray', 'cudaMallocHost', 'cudaMallocPitch', 'cudaMemcpy', 'cudaMemcpy2D', + 'cudaMemcpy2DArrayToArray', 'cudaMemcpy2DFromArray', 'cudaMemcpy2DToArray', 'cudaMemcpy3D', + 'cudaMemcpyArrayToArray', 'cudaMemcpyFromArray', 'cudaMemcpyFromSymbol', 'cudaMemcpyToArray', + 'cudaMemcpyToSymbol', 'cudaMemset', 'cudaMemset2D', 'cudaMemset3D', 'cudaSetDevice', + 'cudaSetupArgument', 'cudaStreamCreate', 'cudaStreamDestroy', 'cudaStreamQuery', + 'cudaStreamSynchronize', 'cudaThreadExit', 'cudaThreadSynchronize', 'cudaUnbindTexture' +}) + -- Variables. -token(lexer.VARIABLE, word_match[[gridDim blockIdx blockDim threadIdx]])) +token(lexer.VARIABLE, word_match('gridDim blockIdx blockDim threadIdx'))) return lex diff --git a/syntaxhighlight/textadept/dart.lua b/syntaxhighlight/textadept/dart.lua index 0532b24..d908d07 100644 --- a/syntaxhighlight/textadept/dart.lua +++ b/syntaxhighlight/textadept/dart.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2013-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2013-2021 Mitchell. See LICENSE. -- Dart LPeg lexer. -- Written by Brian Schott (@Hackerpilot on Github). local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('dart') @@ -13,17 +13,17 @@ local lex = lexer.new('dart') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - assert break case catch class const continue default do else enum extends - false final finally for if in is new null rethrow return super switch this - throw true try var void while with -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do', 'else', 'enum', + 'extends', 'false', 'final', 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow', + 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void', 'while', 'with' +})) -- Built-ins. -lex:add_rule('builtin', token(lexer.CONSTANT, word_match[[ - abstract as dynamic export external factory get implements import library - operator part set static typedef -]])) +lex:add_rule('builtin', token(lexer.CONSTANT, word_match{ + 'abstract', 'as', 'dynamic', 'export', 'external', 'factory', 'get', 'implements', 'import', + 'library', 'operator', 'part', 'set', 'static', 'typedef' +})) -- Strings. local sq_str = S('r')^-1 * lexer.range("'", true) @@ -47,11 +47,11 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('#?=!<>+-*$/%&|^~.,;()[]{}'))) -- Annotations. lex:add_rule('annotation', token('annotation', '@' * lexer.word^1)) -lex:add_style('annotation', lexer.STYLE_PREPROCESSOR) +lex:add_style('annotation', lexer.styles.preprocessor) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/desktop.lua b/syntaxhighlight/textadept/desktop.lua index a4c16d0..063a384 100644 --- a/syntaxhighlight/textadept/desktop.lua +++ b/syntaxhighlight/textadept/desktop.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Desktop Entry LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('desktop') @@ -12,30 +12,28 @@ local lex = lexer.new('desktop') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keys. -lex:add_rule('key', token('key', word_match[[ - Type Version Name GenericName NoDisplay Comment Icon Hidden OnlyShowIn - NotShowIn TryExec Exec Exec Path Terminal MimeType Categories StartupNotify - StartupWMClass URL -]])) -lex:add_style('key', lexer.STYLE_KEYWORD) +lex:add_rule('key', token('key', word_match{ + 'Type', 'Version', 'Name', 'GenericName', 'NoDisplay', 'Comment', 'Icon', 'Hidden', 'OnlyShowIn', + 'NotShowIn', 'TryExec', 'Exec', 'Exec', 'Path', 'Terminal', 'MimeType', 'Categories', + 'StartupNotify', 'StartupWMClass', 'URL' +})) +lex:add_style('key', lexer.styles.keyword) -- Values. -lex:add_rule('value', token('value', word_match[[true false]])) -lex:add_style('value', lexer.STYLE_CONSTANT) +lex:add_rule('value', token('value', word_match('true false'))) +lex:add_style('value', lexer.styles.constant) -- Identifiers. -local word = lexer.alpha * (lexer.alnum + S('_-'))^0 -lex:add_rule('identifier', lexer.token(lexer.IDENTIFIER, word)) - -local bracketed = lexer.range('[', ']') +lex:add_rule('identifier', lexer.token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('_-'))^0)) -- Group headers. +local bracketed = lexer.range('[', ']') lex:add_rule('header', lexer.starts_line(token('header', bracketed))) -lex:add_style('header', lexer.STYLE_LABEL) +lex:add_style('header', lexer.styles.label) -- Locales. lex:add_rule('locale', token('locale', bracketed)) -lex:add_style('locale', lexer.STYLE_CLASS) +lex:add_style('locale', lexer.styles.class) -- Strings. lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) @@ -47,8 +45,8 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Field codes. -lex:add_rule('code', lexer.token('code', P('%') * S('fFuUdDnNickvm'))) -lex:add_style('code', lexer.STYLE_VARIABLE) +lex:add_rule('code', lexer.token('code', '%' * S('fFuUdDnNickvm'))) +lex:add_style('code', lexer.styles.variable) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('='))) diff --git a/syntaxhighlight/textadept/diff.lua b/syntaxhighlight/textadept/diff.lua index 59e03f5..56c8b50 100644 --- a/syntaxhighlight/textadept/diff.lua +++ b/syntaxhighlight/textadept/diff.lua @@ -1,32 +1,29 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Diff LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('diff', {lex_by_line = true}) -- Text, separators, and file headers. lex:add_rule('index', token(lexer.COMMENT, 'Index: ' * lexer.any^0 * -1)) -lex:add_rule('separator', token(lexer.COMMENT, ('---' + P('*')^4 + P('=')^1) * - lexer.space^0 * -1)) -lex:add_rule('header', token('header', (P('*** ') + '--- ' + '+++ ') * - lexer.any^1)) -lex:add_style('header', lexer.STYLE_COMMENT) +lex:add_rule('separator', token(lexer.COMMENT, ('---' + P('*')^4 + P('=')^1) * lexer.space^0 * -1)) +lex:add_rule('header', token('header', (P('*** ') + '--- ' + '+++ ') * lexer.any^1)) +lex:add_style('header', lexer.styles.comment) -- Location. -lex:add_rule('location', token(lexer.NUMBER, ('@@' + lexer.digit^1 + '****') * - lexer.any^1)) +lex:add_rule('location', token(lexer.NUMBER, ('@@' + lexer.dec_num + '****') * lexer.any^1)) -- Additions, deletions, and changes. lex:add_rule('addition', token('addition', S('>+') * lexer.any^0)) -lex:add_style('addition', 'fore:$(color.green)') +lex:add_style('addition', {fore = lexer.colors.green}) lex:add_rule('deletion', token('deletion', S('<-') * lexer.any^0)) -lex:add_style('deletion', 'fore:$(color.red)') +lex:add_style('deletion', {fore = lexer.colors.red}) lex:add_rule('change', token('change', '!' * lexer.any^0)) -lex:add_style('change', 'fore:$(color.yellow)') +lex:add_style('change', {fore = lexer.colors.yellow}) lex:add_rule('any_line', token(lexer.DEFAULT, lexer.any^1)) diff --git a/syntaxhighlight/textadept/django.lua b/syntaxhighlight/textadept/django.lua index 84a1f4b..69f74ae 100644 --- a/syntaxhighlight/textadept/django.lua +++ b/syntaxhighlight/textadept/django.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Django LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('django') @@ -12,22 +12,23 @@ local lex = lexer.new('django') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - as block blocktrans by endblock endblocktrans comment endcomment cycle date - debug else extends filter endfilter firstof for endfor if endif ifchanged - endifchanged ifnotequal endifnotequal in load not now or parsed regroup ssi - trans with widthratio -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'as', 'block', 'blocktrans', 'by', 'endblock', 'endblocktrans', 'comment', 'endcomment', 'cycle', + 'date', 'debug', 'else', 'extends', 'filter', 'endfilter', 'firstof', 'for', 'endfor', 'if', + 'endif', 'ifchanged', 'endifchanged', 'ifnotequal', 'endifnotequal', 'in', 'load', 'not', 'now', + 'or', 'parsed', 'regroup', 'ssi', 'trans', 'with', 'widthratio' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - add addslashes capfirst center cut date default dictsort dictsortreversed - divisibleby escape filesizeformat first fix_ampersands floatformat get_digit - join length length_is linebreaks linebreaksbr linenumbers ljust lower - make_list phone2numeric pluralize pprint random removetags rjust slice slugify - stringformat striptags time timesince title truncatewords unordered_list upper - urlencode urlize urlizetrunc wordcount wordwrap yesno -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'add', 'addslashes', 'capfirst', 'center', 'cut', 'date', 'default', 'dictsort', + 'dictsortreversed', 'divisibleby', 'escape', 'filesizeformat', 'first', 'fix_ampersands', + 'floatformat', 'get_digit', 'join', 'length', 'length_is', 'linebreaks', 'linebreaksbr', + 'linenumbers', 'ljust', 'lower', 'make_list', 'phone2numeric', 'pluralize', 'pprint', 'random', + 'removetags', 'rjust', 'slice', 'slugify', 'stringformat', 'striptags', 'time', 'timesince', + 'title', 'truncatewords', 'unordered_list', 'upper', 'urlencode', 'urlize', 'urlizetrunc', + 'wordcount', 'wordwrap', 'yesno' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -46,7 +47,7 @@ html:modify_rule('comment', token(lexer.COMMENT, html_comment + django_comment)) local django_start_rule = token('django_tag', '{' * S('{%')) local django_end_rule = token('django_tag', S('%}') * '}') html:embed(lex, django_start_rule, django_end_rule) -lex:add_style('django_tag', lexer.STYLE_EMBEDDED) +lex:add_style('django_tag', lexer.styles.embedded) -- Fold points. lex:add_fold_point('django_tag', '{{', '}}') diff --git a/syntaxhighlight/textadept/dmd.lua b/syntaxhighlight/textadept/dmd.lua index 20253d6..2bdb73a 100644 --- a/syntaxhighlight/textadept/dmd.lua +++ b/syntaxhighlight/textadept/dmd.lua @@ -1,23 +1,100 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- D LPeg lexer. -- Heavily modified by Brian Schott (@Hackerpilot on Github). local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S -local M = {_NAME = 'dmd'} +local lex = lexer.new('dmd') -- Whitespace. local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', ws) + +-- Class names. +lex:add_rule('class', + token(lexer.TYPE, P('class') + 'struct') * ws^-1 * token(lexer.CLASS, lexer.word)) + +-- Versions. +local version = word_match{ + 'AArch64', 'AIX', 'all', 'Alpha', 'Alpha_HardFloat', 'Alpha_SoftFloat', 'Android', 'ARM', + 'ARM_HardFloat', 'ARM_SoftFloat', 'ARM_SoftFP', 'ARM_Thumb', 'assert', 'BigEndian', 'BSD', + 'Cygwin', 'D_Coverage', 'D_Ddoc', 'D_HardFloat', 'DigitalMars', 'D_InlineAsm_X86', + 'D_InlineAsm_X86_64', 'D_LP64', 'D_NoBoundsChecks', 'D_PIC', 'DragonFlyBSD', 'D_SIMD', + 'D_SoftFloat', 'D_Version2', 'D_X32', 'FreeBSD', 'GNU', 'Haiku', 'HPPA', 'HPPA64', 'Hurd', 'IA64', + 'LDC', 'linux', 'LittleEndian', 'MIPS32', 'MIPS64', 'MIPS_EABI', 'MIPS_HardFloat', 'MIPS_N32', + 'MIPS_N64', 'MIPS_O32', 'MIPS_O64', 'MIPS_SoftFloat', 'NetBSD', 'none', 'OpenBSD', 'OSX', 'Posix', + 'PPC', 'PPC64', 'PPC_HardFloat', 'PPC_SoftFloat', 'S390', 'S390X', 'SDC', 'SH', 'SH64', 'SkyOS', + 'Solaris', 'SPARC', 'SPARC64', 'SPARC_HardFloat', 'SPARC_SoftFloat', 'SPARC_V8Plus', 'SysV3', + 'SysV4', 'unittest', 'Win32', 'Win64', 'Windows', 'X86', 'X86_64' +} +local open_paren = token(lexer.OPERATOR, '(') +lex:add_rule('version', token(lexer.KEYWORD, 'version') * ws^-1 * open_paren * ws^-1 * + token('versions', version)) +lex:add_style('versions', lexer.styles.constant) --- Comments. -local line_comment = lexer.to_eol('//', true) -local block_comment = lexer.range('/*', '*/') -local nested_comment = lexer.range('/+', '+/', false, false, true) -local comment = token(lexer.COMMENT, line_comment + block_comment + - nested_comment) +-- Scopes. +local scope = word_match('exit success failure') +lex:add_rule('scope', + token(lexer.KEYWORD, 'scope') * ws^-1 * open_paren * ws^-1 * token('scopes', scope)) +lex:add_style('scopes', lexer.styles.constant) + +-- Traits. +local trait = word_match{ + 'allMembers', 'classInstanceSize', 'compiles', 'derivedMembers', 'getAttributes', 'getMember', + 'getOverloads', 'getProtection', 'getUnitTests', 'getVirtualFunctions', 'getVirtualIndex', + 'getVirtualMethods', 'hasMember', 'identifier', 'isAbstractClass', 'isAbstractFunction', + 'isArithmetic', 'isAssociativeArray', 'isFinalClass', 'isFinalFunction', 'isFloating', + 'isIntegral', 'isLazy', 'isNested', 'isOut', 'isOverrideFunction', 'isPOD', 'isRef', 'isSame', + 'isScalar', 'isStaticArray', 'isStaticFunction', 'isUnsigned', 'isVirtualFunction', + 'isVirtualMethod', 'parent' +} +lex:add_rule('trait', + token(lexer.KEYWORD, '__traits') * ws^-1 * open_paren * ws^-1 * token('traits', trait)) +lex:add_style('traits', {fore = lexer.colors.yellow}) + +-- Function names. +lex:add_rule('function', + token(lexer.FUNCTION, lexer.word) * #(ws^-1 * ('!' * lexer.word^-1 * ws^-1)^-1 * '(')) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'align', 'asm', 'assert', 'auto', 'body', 'break', 'case', 'cast', 'catch', 'const', + 'continue', 'debug', 'default', 'delete', 'deprecated', 'do', 'else', 'extern', 'export', 'false', + 'final', 'finally', 'for', 'foreach', 'foreach_reverse', 'goto', 'if', 'import', 'immutable', + 'in', 'inout', 'invariant', 'is', 'lazy', 'macro', 'mixin', 'new', 'nothrow', 'null', 'out', + 'override', 'pragma', 'private', 'protected', 'public', 'pure', 'ref', 'return', 'scope', + 'shared', 'static', 'super', 'switch', 'synchronized', 'this', 'throwtrue', 'try', 'typeid', + 'typeof', 'unittest', 'version', 'virtual', 'volatile', 'while', 'with', '__gshared', '__thread', + '__traits', '__vector', '__parameters' +})) + +-- Types. +local type = token(lexer.TYPE, word_match{ + 'alias', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'creal', 'dchar', + 'delegate', 'double', 'enum', 'float', 'function', 'idouble', 'ifloat', 'int', 'interface', + 'ireal', 'long', 'module', 'package', 'ptrdiff_t', 'real', 'short', 'size_t', 'struct', + 'template', 'typedef', 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'ushort', 'void', 'wchar', + 'string', 'wstring', 'dstring', 'hash_t', 'equals_t' +}) +lex:add_rule('type', type) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + '__FILE__', '__LINE__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', '__VENDOR__', + '__VERSION__', '__FUNCTION__', '__PRETTY_FUNCTION__', '__MODULE__' +})) + +-- Properties. +local dot = token(lexer.OPERATOR, '.') +lex:add_rule('property', lpeg.B(lexer.alnum + ')') * dot * token(lexer.VARIABLE, word_match{ + 'alignof', 'dig', 'dup', 'epsilon', 'idup', 'im', 'init', 'infinity', 'keys', 'length', + 'mangleof', 'mant_dig', 'max', 'max_10_exp', 'max_exp', 'min', 'min_normal', 'min_10_exp', + 'min_exp', 'nan', 'offsetof', 'ptr', 're', 'rehash', 'reverse', 'sizeof', 'sort', 'stringof', + 'tupleof', 'values' +})) -- Strings. local sq_str = lexer.range("'", true) * S('cwd')^-1 @@ -28,10 +105,18 @@ local hex_str = 'x' * lexer.range('"') * S('cwd')^-1 local other_hex_str = '\\x' * (lexer.xdigit * lexer.xdigit)^1 local str = sq_str + dq_str + lit_str + bt_str + hex_str + other_hex_str for left, right in pairs{['['] = ']', ['('] = ')', ['{'] = '}', ['<'] = '>'} do - str = str + lexer.range('q"' .. left, right .. '"', false, false, true) * - S('cwd')^-1 + str = str + lexer.range('q"' .. left, right .. '"', false, false, true) * S('cwd')^-1 end -local string = token(lexer.STRING, str) +lex:add_rule('string', token(lexer.STRING, str)) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +local line_comment = lexer.to_eol('//', true) +local block_comment = lexer.range('/*', '*/') +local nested_comment = lexer.range('/+', '+/', false, false, true) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment + nested_comment)) -- Numbers. local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 @@ -39,140 +124,20 @@ local hex_num = lexer.hex_num * ('_' * lexer.xdigit^1)^0 local bin_num = '0' * S('bB') * S('01_')^1 local oct_num = '0' * S('01234567_')^1 local integer = S('+-')^-1 * (hex_num + oct_num + bin_num + dec) -local number = token(lexer.NUMBER, (lexer.float + integer) * S('uULdDfFi')^-1) - --- Keywords. -local keyword = token(lexer.KEYWORD, word_match{ - 'abstract', 'align', 'asm', 'assert', 'auto', 'body', 'break', 'case', 'cast', - 'catch', 'const', 'continue', 'debug', 'default', 'delete', - 'deprecated', 'do', 'else', 'extern', 'export', 'false', 'final', 'finally', - 'for', 'foreach', 'foreach_reverse', 'goto', 'if', 'import', 'immutable', - 'in', 'inout', 'invariant', 'is', 'lazy', 'macro', 'mixin', 'new', 'nothrow', - 'null', 'out', 'override', 'pragma', 'private', 'protected', 'public', 'pure', - 'ref', 'return', 'scope', 'shared', 'static', 'super', 'switch', - 'synchronized', 'this', 'throw','true', 'try', 'typeid', 'typeof', 'unittest', - 'version', 'virtual', 'volatile', 'while', 'with', '__gshared', '__thread', - '__traits', '__vector', '__parameters' -}) - --- Types. -local type = token(lexer.TYPE, word_match{ - 'alias', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'class', - 'creal', 'dchar', 'delegate', 'double', 'enum', 'float', 'function', - 'idouble', 'ifloat', 'int', 'interface', 'ireal', 'long', 'module', 'package', - 'ptrdiff_t', 'real', 'short', 'size_t', 'struct', 'template', 'typedef', - 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'ushort', 'void', 'wchar', - 'string', 'wstring', 'dstring', 'hash_t', 'equals_t' -}) +lex:add_rule('number', token(lexer.NUMBER, (lexer.float + integer) * S('uULdDfFi')^-1)) --- Constants. -local constant = token(lexer.CONSTANT, word_match{ - '__FILE__', '__LINE__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', - '__VENDOR__', '__VERSION__', '__FUNCTION__', '__PRETTY_FUNCTION__', - '__MODULE__', -}) - -local class_sequence = token(lexer.TYPE, P('class') + P('struct')) * ws^1 * - token(lexer.CLASS, lexer.word) - --- Identifiers. -local identifier = token(lexer.IDENTIFIER, lexer.word) +-- Preprocessor. +lex:add_rule('annotation', token('annotation', '@' * lexer.word^1)) +lex:add_style('annotation', lexer.styles.preprocessor) +lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, lexer.to_eol('#'))) -- Operators. -local operator = token(lexer.OPERATOR, '..' + S('?=!<>+-*$/%&|^~.,;:()[]{}')) - --- Properties. -local properties = (type + identifier + operator) * token(lexer.OPERATOR, '.') * - token(lexer.VARIABLE, word_match{ - 'alignof', 'dig', 'dup', 'epsilon', 'idup', 'im', 'init', 'infinity', - 'keys', 'length', 'mangleof', 'mant_dig', 'max', 'max_10_exp', 'max_exp', - 'min', 'min_normal', 'min_10_exp', 'min_exp', 'nan', 'offsetof', 'ptr', - 're', 'rehash', 'reverse', 'sizeof', 'sort', 'stringof', 'tupleof', - 'values' - }) - --- Preprocs. -local annotation = token('annotation', '@' * lexer.word^1) -local preproc = token(lexer.PREPROCESSOR, '#' * lexer.nonnewline^0) +lex:add_rule('operator', token(lexer.OPERATOR, S('?=!<>+-*$/%&|^~.,;:()[]{}'))) --- Traits. -local traits_list = token('traits', word_match{ - 'allMembers', 'classInstanceSize', 'compiles', 'derivedMembers', - 'getAttributes', 'getMember', 'getOverloads', 'getProtection', 'getUnitTests', - 'getVirtualFunctions', 'getVirtualIndex', 'getVirtualMethods', 'hasMember', - 'identifier', 'isAbstractClass', 'isAbstractFunction', 'isArithmetic', - 'isAssociativeArray', 'isFinalClass', 'isFinalFunction', 'isFloating', - 'isIntegral', 'isLazy', 'isNested', 'isOut', 'isOverrideFunction', 'isPOD', - 'isRef', 'isSame', 'isScalar', 'isStaticArray', 'isStaticFunction', - 'isUnsigned', 'isVirtualFunction', 'isVirtualMethod', 'parent' -}) - -local scopes_list = token('scopes', word_match{'exit', 'success', 'failure'}) - --- versions -local versions_list = token('versions', word_match{ - 'AArch64', 'AIX', 'all', 'Alpha', 'Alpha_HardFloat', 'Alpha_SoftFloat', - 'Android', 'ARM', 'ARM_HardFloat', 'ARM_SoftFloat', 'ARM_SoftFP', 'ARM_Thumb', - 'assert', 'BigEndian', 'BSD', 'Cygwin', 'D_Coverage', 'D_Ddoc', 'D_HardFloat', - 'DigitalMars', 'D_InlineAsm_X86', 'D_InlineAsm_X86_64', 'D_LP64', - 'D_NoBoundsChecks', 'D_PIC', 'DragonFlyBSD', 'D_SIMD', 'D_SoftFloat', - 'D_Version2', 'D_X32', 'FreeBSD', 'GNU', 'Haiku', 'HPPA', 'HPPA64', 'Hurd', - 'IA64', 'LDC', 'linux', 'LittleEndian', 'MIPS32', 'MIPS64', 'MIPS_EABI', - 'MIPS_HardFloat', 'MIPS_N32', 'MIPS_N64', 'MIPS_O32', 'MIPS_O64', - 'MIPS_SoftFloat', 'NetBSD', 'none', 'OpenBSD', 'OSX', 'Posix', 'PPC', 'PPC64', - 'PPC_HardFloat', 'PPC_SoftFloat', 'S390', 'S390X', 'SDC', 'SH', 'SH64', - 'SkyOS', 'Solaris', 'SPARC', 'SPARC64', 'SPARC_HardFloat', 'SPARC_SoftFloat', - 'SPARC_V8Plus', 'SysV3', 'SysV4', 'unittest', 'Win32', 'Win64', 'Windows', - 'X86', 'X86_64' -}) - -local versions = token(lexer.KEYWORD, 'version') * lexer.space^0 * - token(lexer.OPERATOR, '(') * lexer.space^0 * versions_list - -local scopes = token(lexer.KEYWORD, 'scope') * lexer.space^0 * - token(lexer.OPERATOR, '(') * lexer.space^0 * scopes_list - -local traits = token(lexer.KEYWORD, '__traits') * lexer.space^0 * - token(lexer.OPERATOR, '(') * lexer.space^0 * traits_list - -local func = token(lexer.FUNCTION, lexer.word) * #( - lexer.space^0 * (P('!') * lexer.word^-1 * lexer.space^-1)^-1 * P('(') -) - -M._rules = { - {'whitespace', ws}, - {'class', class_sequence}, - {'traits', traits}, - {'versions', versions}, - {'scopes', scopes}, - {'keyword', keyword}, - {'variable', properties}, - {'type', type}, - {'function', func}, - {'constant', constant}, - {'string', string}, - {'identifier', identifier}, - {'comment', comment}, - {'number', number}, - {'preproc', preproc}, - {'operator', operator}, - {'annotation', annotation}, -} - -M._tokenstyles = { - annotation = lexer.STYLE_PREPROCESSOR, - traits = 'fore:$(color.yellow)', - versions = lexer.STYLE_CONSTANT, - scopes = lexer.STYLE_CONSTANT -} - -M._foldsymbols = { - _patterns = {'[{}]', '/[*+]', '[*+]/', '//'}, - [lexer.OPERATOR] = {['{'] = 1, ['}'] = -1}, - [lexer.COMMENT] = { - ['/*'] = 1, ['*/'] = -1, ['/+'] = 1, ['+/'] = -1, - ['//'] = lexer.fold_line_comments('//') - } -} +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, '/*', '*/') +lex:add_fold_point(lexer.COMMENT, '/+', '+/') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) -return M +return lex diff --git a/syntaxhighlight/textadept/dockerfile.lua b/syntaxhighlight/textadept/dockerfile.lua index bb6cda1..46d4dd5 100644 --- a/syntaxhighlight/textadept/dockerfile.lua +++ b/syntaxhighlight/textadept/dockerfile.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2016-2020 Alejandro Baez (https://keybase.io/baez). See License.txt. +-- Copyright 2016-2021 Alejandro Baez (https://keybase.io/baez). See LICENSE. -- Dockerfile LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('dockerfile', {fold_by_indentation = true}) @@ -12,17 +12,17 @@ local lex = lexer.new('dockerfile', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - ADD ARG CMD COPY ENTRYPOINT ENV EXPOSE FROM LABEL MAINTAINER ONBUILD RUN - STOPSIGNAL USER VOLUME WORKDIR -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'ADD', 'ARG', 'CMD', 'COPY', 'ENTRYPOINT', 'ENV', 'EXPOSE', 'FROM', 'LABEL', 'MAINTAINER', + 'ONBUILD', 'RUN', 'STOPSIGNAL', 'USER', 'VOLUME', 'WORKDIR' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Variable. -lex:add_rule('variable', token(lexer.VARIABLE, S('$')^1 * - (S('{')^1 * lexer.word * S('}')^1 + lexer.word))) +lex:add_rule('variable', + token(lexer.VARIABLE, S('$')^1 * (P('{')^1 * lexer.word * P('}')^1 + lexer.word))) -- Strings. local sq_str = lexer.range("'", false, false) diff --git a/syntaxhighlight/textadept/dot.lua b/syntaxhighlight/textadept/dot.lua index 001b070..d81179b 100644 --- a/syntaxhighlight/textadept/dot.lua +++ b/syntaxhighlight/textadept/dot.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Brian "Sir Alaran" Schott. See License.txt. +-- Copyright 2006-2021 Brian "Sir Alaran" Schott. See LICENSE. -- Dot LPeg lexer. -- Based off of lexer code by Mitchell. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('dot') @@ -13,21 +13,22 @@ local lex = lexer.new('dot') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - graph node edge digraph fontsize rankdir fontname shape label arrowhead - arrowtail arrowsize color comment constraint decorate dir headlabel headport - headURL labelangle labeldistance labelfloat labelfontcolor labelfontname - labelfontsize layer lhead ltail minlen samehead sametail style taillabel - tailport tailURL weight subgraph -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'graph', 'node', 'edge', 'digraph', 'fontsize', 'rankdir', 'fontname', 'shape', 'label', + 'arrowhead', 'arrowtail', 'arrowsize', 'color', 'comment', 'constraint', 'decorate', 'dir', + 'headlabel', 'headport', 'headURL', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor', + 'labelfontname', 'labelfontsize', 'layer', 'lhead', 'ltail', 'minlen', 'samehead', 'sametail', + 'style', 'taillabel', 'tailport', 'tailURL', 'weight', 'subgraph' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - box polygon ellipse circle point egg triangle plaintext diamond trapezium - parallelogram house pentagon hexagon septagon octagon doublecircle - doubleoctagon tripleoctagon invtriangle invtrapezium invhouse Mdiamond Msquare - Mcircle rect rectangle none note tab folder box3d record -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + ' box', 'polygon', 'ellipse', 'circle', 'point', 'egg', 'triangle', 'plaintext', 'diamond', + 'trapezium', 'parallelogram', 'house', 'pentagon', 'hexagon', 'septagon', 'octagon', + 'doublecircle', 'doubleoctagon', 'tripleoctagon', 'invtriangle', 'invtrapezium', 'invhouse', + 'Mdiamond', 'Msquare', 'Mcircle', 'rect', 'rectangle', 'none', 'note', 'tab', 'folder', 'box3d', + 'record' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -43,7 +44,7 @@ local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.digit^1 + lexer.float)) +lex:add_rule('number', token(lexer.NUMBER, lexer.dec_num + lexer.float)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('->()[]{};'))) @@ -51,6 +52,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('->()[]{};'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/eiffel.lua b/syntaxhighlight/textadept/eiffel.lua index a10cd98..180e2aa 100644 --- a/syntaxhighlight/textadept/eiffel.lua +++ b/syntaxhighlight/textadept/eiffel.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Eiffel LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('eiffel') @@ -12,19 +12,18 @@ local lex = lexer.new('eiffel') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - alias all and as check class creation debug deferred do else elseif end ensure - expanded export external feature from frozen if implies indexing infix inherit - inspect invariant is like local loop not obsolete old once or prefix redefine - rename require rescue retry select separate then undefine until variant when - xor - current false precursor result strip true unique void -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'alias', 'all', 'and', 'as', 'check', 'class', 'creation', 'debug', 'deferred', 'do', 'else', + 'elseif', 'end', 'ensure', 'expanded', 'export', 'external', 'feature', 'from', 'frozen', 'if', + 'implies', 'indexing', 'infix', 'inherit', 'inspect', 'invariant', 'is', 'like', 'local', 'loop', + 'not', 'obsolete', 'old', 'once', 'or', 'prefix', 'redefine', 'rename', 'require', 'rescue', + 'retry', 'select', 'separate', 'then', 'undefine', 'until', 'variant', 'when', 'xor', -- + 'current', 'false', 'precursor', 'result', 'strip', 'true', 'unique', 'void' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - character string bit boolean integer real none any -]])) +lex:add_rule('type', + token(lexer.TYPE, word_match('character string bit boolean integer real none any'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -46,17 +45,15 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*%&|^~.,:;?()[]{}'))) -- Fold points. lex:add_fold_point(lexer.KEYWORD, 'check', 'end') lex:add_fold_point(lexer.KEYWORD, 'debug', 'end') -lex:add_fold_point(lexer.KEYWORD, 'deferred', function(text, pos, line, s) - return line:find('deferred%s+class') and 0 or 1 -end) +lex:add_fold_point(lexer.KEYWORD, 'deferred', + function(text, pos, line, s) return line:find('deferred%s+class') and 0 or 1 end) lex:add_fold_point(lexer.KEYWORD, 'do', 'end') lex:add_fold_point(lexer.KEYWORD, 'from', 'end') lex:add_fold_point(lexer.KEYWORD, 'if', 'end') lex:add_fold_point(lexer.KEYWORD, 'inspect', 'end') lex:add_fold_point(lexer.KEYWORD, 'once', 'end') -lex:add_fold_point(lexer.KEYWORD, 'class', function(text, pos, line, s) - return line:find('deferred%s+class') and 0 or 1 -end) -lex:add_fold_point(lexer.COMMENT, '--', lexer.fold_line_comments('--')) +lex:add_fold_point(lexer.KEYWORD, 'class', + function(text, pos, line, s) return line:find('deferred%s+class') and 0 or 1 end) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('--')) return lex diff --git a/syntaxhighlight/textadept/elixir.lua b/syntaxhighlight/textadept/elixir.lua index 93c534d..3768542 100644 --- a/syntaxhighlight/textadept/elixir.lua +++ b/syntaxhighlight/textadept/elixir.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2015-2021 Mitchell. See LICENSE. -- Contributed by Richard Philips. -- Elixir LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local B, P, R, S = lpeg.B, lpeg.P, lpeg.R, lpeg.S +local B, P, S = lpeg.B, lpeg.P, lpeg.S local lex = lexer.new('elixir', {fold_by_indentation = true}) @@ -13,39 +13,37 @@ local lex = lexer.new('elixir', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Sigils. -local sigil11 = P("~") * S("CRSW") * lexer.range('<', '>', false) -local sigil12 = P("~") * S("CRSW") * lexer.range('{', '}', false) -local sigil13 = P("~") * S("CRSW") * lexer.range('[', ']', false) -local sigil14 = P("~") * S("CRSW") * lexer.range('(', ')', false) -local sigil15 = P("~") * S("CRSW") * lexer.range('|', false, false) -local sigil16 = P("~") * S("CRSW") * lexer.range('/', false, false) -local sigil17 = P("~") * S("CRSW") * lexer.range('"', false, false) -local sigil18 = P("~") * S("CRSW") * lexer.range("'", false, false) -local sigil19 = P("~") * S("CRSW") * lexer.range('"""') -local sigil10 = P("~") * S("CRSW") * lexer.range("'''") -local sigil21 = P("~") * S("crsw") * lexer.range('<', '>', false, true) -local sigil22 = P("~") * S("crsw") * lexer.range('{', '}', false, true) -local sigil23 = P("~") * S("crsw") * lexer.range('[', ']', false, true) -local sigil24 = P("~") * S("crsw") * lexer.range('(', ')', false, true) -local sigil25 = P("~") * S("crsw") * lexer.range('|', false) -local sigil26 = P("~") * S("crsw") * lexer.range('/', false) -local sigil27 = P("~") * S("crsw") * lexer.range('"', false) -local sigil28 = P("~") * S("crsw") * lexer.range("'", false) -local sigil29 = P("~") * S("crsw") * lexer.range('"""') -local sigil20 = P("~") * S("crsw") * lexer.range("'''") -local sigil_token = token(lexer.REGEX, sigil10 + sigil19 + sigil11 + sigil12 + - sigil13 + sigil14 + sigil15 + sigil16 + sigil17 + sigil18 + sigil20 + - sigil29 + sigil21 + sigil22 + sigil23 + sigil24 + sigil25 + sigil26 + - sigil27 + sigil28) -local sigiladdon_token = token(lexer.EMBEDDED, R('az', 'AZ')^0) +local sigil11 = '~' * S('CRSW') * lexer.range('<', '>') +local sigil12 = '~' * S('CRSW') * lexer.range('{', '}') +local sigil13 = '~' * S('CRSW') * lexer.range('[', ']') +local sigil14 = '~' * S('CRSW') * lexer.range('(', ')') +local sigil15 = '~' * S('CRSW') * lexer.range('|', false, false) +local sigil16 = '~' * S('CRSW') * lexer.range('/', false, false) +local sigil17 = '~' * S('CRSW') * lexer.range('"', false, false) +local sigil18 = '~' * S('CRSW') * lexer.range("'", false, false) +local sigil19 = '~' * S('CRSW') * lexer.range('"""') +local sigil10 = '~' * S('CRSW') * lexer.range("'''") +local sigil21 = '~' * S('crsw') * lexer.range('<', '>') +local sigil22 = '~' * S('crsw') * lexer.range('{', '}') +local sigil23 = '~' * S('crsw') * lexer.range('[', ']') +local sigil24 = '~' * S('crsw') * lexer.range('(', ')') +local sigil25 = '~' * S('crsw') * lexer.range('|') +local sigil26 = '~' * S('crsw') * lexer.range('/') +local sigil27 = '~' * S('crsw') * lexer.range('"') +local sigil28 = '~' * S('crsw') * lexer.range("'") +local sigil29 = '~' * S('crsw') * lexer.range('"""') +local sigil20 = '~' * S('crsw') * lexer.range("'''") +local sigil_token = token(lexer.REGEX, + sigil10 + sigil19 + sigil11 + sigil12 + sigil13 + sigil14 + sigil15 + sigil16 + sigil17 + sigil18 + + sigil20 + sigil29 + sigil21 + sigil22 + sigil23 + sigil24 + sigil25 + sigil26 + sigil27 + + sigil28) +local sigiladdon_token = token(lexer.EMBEDDED, lexer.alpha^0) lex:add_rule('sigil', sigil_token * sigiladdon_token) -- Atoms. -local atom1 = B(1 - P(':')) * P(':') * lexer.range('"', false) -local atom2 = B(1 - P(':')) * P(':') * R('az', 'AZ') * - R('az', 'AZ', '__', '@@', '09')^0 * S('?!')^-1 -local atom3 = B(1 - R('az', 'AZ', '__', '09', '::')) * - R('AZ') * R('az', 'AZ', '__', '@@', '09')^0 * S('?!')^-1 +local atom1 = B(1 - P(':')) * ':' * lexer.range('"') +local atom2 = B(1 - P(':')) * ':' * lexer.alpha * (lexer.alnum + S('_@'))^0 * S('?!')^-1 +local atom3 = B(1 - (lexer.alnum + S('_:'))) * lexer.upper * (lexer.alnum + S('_@'))^0 * S('?!')^-1 lex:add_rule('atom', token(lexer.CONSTANT, atom1 + atom2 + atom3)) -- Strings. @@ -57,48 +55,44 @@ lex:add_rule('string', token(lexer.STRING, triple_dq_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) -- Attributes. -lex:add_rule('attribute', token(lexer.LABEL, B(1 - R('az', 'AZ', '__')) * - P('@') * R('az','AZ') * R('az','AZ','09','__')^0)) +lex:add_rule('attribute', token(lexer.LABEL, B(1 - (lexer.alnum + '_')) * '@' * lexer.alpha * + (lexer.alnum + '_')^0)) -- Booleans. -lex:add_rule('boolean', token(lexer.NUMBER, P(':')^-1 * - word_match[[true false nil]])) +lex:add_rule('boolean', token(lexer.NUMBER, P(':')^-1 * word_match('true false nil'))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - defstruct defrecordp defrecord defprotocol defp defoverridable defmodule - defmacrop defmacro defimpl defexception defdelegate defcallback def -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'defstruct', 'defrecordp', 'defrecord', 'defprotocol', 'defp', 'defoverridable', 'defmodule', + 'defmacrop', 'defmacro', 'defimpl', 'defexception', 'defdelegate', 'defcallback', 'def' +})) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - is_atom is_binary is_bitstring is_boolean is_float is_function is_integer - is_list is_map is_number is_pid is_port is_record is_reference is_tuple - is_exception case when cond for if unless try receive send exit raise throw - after rescue catch else do end quote unquote super import require alias use - self with fn -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean', 'is_float', 'is_function', 'is_integer', + 'is_list', 'is_map', 'is_number', 'is_pid', 'is_port', 'is_record', 'is_reference', 'is_tuple', + 'is_exception', 'case', 'when', 'cond', 'for', 'if', 'unless', 'try', 'receive', 'send', 'exit', + 'raise', 'throw', 'after', 'rescue', 'catch', 'else', 'do', 'end', 'quote', 'unquote', 'super', + 'import', 'require', 'alias', 'use', 'self', 'with', 'fn' +})) -- Operators -local operator1 = word_match[[and or not when xor in]] -local operator2 = P('!==') + '!=' + '!' + '=~' + '===' + '==' + '=' + '<<<' + - '<<' + '<=' + '<-' + '<' + '>>>' + '>>' + '>=' + '>' + '->' + '--' + '-' + - '++' + '+' + '&&&' + '&&' + '&' + '|||' + '||' + '|>' + '|' + '..' + '.' + - '^^^' + '^' + '\\\\' + '::' + '*' + '/' + '~~~' + '@' +local operator1 = word_match('and or not when xor in') +local operator2 = P('!==') + '!=' + '!' + '=~' + '===' + '==' + '=' + '<<<' + '<<' + '<=' + '<-' + + '<' + '>>>' + '>>' + '>=' + '>' + '->' + '--' + '-' + '++' + '+' + '&&&' + '&&' + '&' + '|||' + + '||' + '|>' + '|' + '..' + '.' + '^^^' + '^' + '\\\\' + '::' + '*' + '/' + '~~~' + '@' lex:add_rule('operator', token(lexer.OPERATOR, operator1 + operator2)) -- Identifiers -lex:add_rule('identifier', token(lexer.IDENTIFIER, R('az', '__') * - R('az', 'AZ', '__', '09')^0 * S('?!')^-1)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word * S('?!')^-1)) -- Numbers -local dec = lexer.digit * (lexer.digit + P("_"))^0 +local dec = lexer.digit * (lexer.digit + '_')^0 local bin = '0b' * S('01')^1 -local oct = '0o' * R('07')^1 +local oct = '0o' * lpeg.R('07')^1 local integer = bin + lexer.hex_num + oct + dec -local float = lexer.digit^1 * P(".") * lexer.digit^1 * S("eE") * - (S('+-')^-1 * lexer.digit^1)^-1 -lex:add_rule('number', B(1 - R('az', 'AZ', '__')) * S('+-')^-1 * - token(lexer.NUMBER, float + integer)) +local float = lexer.digit^1 * '.' * lexer.digit^1 * S('eE') * (S('+-')^-1 * lexer.digit^1)^-1 +lex:add_rule('number', + B(1 - (lexer.alpha + '_')) * S('+-')^-1 * token(lexer.NUMBER, float + integer)) return lex diff --git a/syntaxhighlight/textadept/elm.lua b/syntaxhighlight/textadept/elm.lua new file mode 100644 index 0000000..95a5c80 --- /dev/null +++ b/syntaxhighlight/textadept/elm.lua @@ -0,0 +1,44 @@ +local lpeg = require('lpeg') +-- Copyright 2020-2021 Mitchell. See LICENSE. +-- Elm LPeg lexer +-- Adapted from Haskell LPeg lexer by Karl Schultheisz. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('elm', {fold_by_indentation = true}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'if then else case of let in module import as exposing type alias port'))) + +-- Types & type constructors. +local word = (lexer.alnum + S("._'#"))^0 +local op = lexer.punct - S('()[]{}') +lex:add_rule('type', token(lexer.TYPE, lexer.upper * word + ':' * (op^1 - ':'))) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) + +-- Chars. +lex:add_rule('character', token(lexer.STRING, lexer.range("'", true))) + +-- Comments. +local line_comment = lexer.to_eol('--', true) +local block_comment = lexer.range('{-', '-}', false, false, true) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, op)) + +return lex diff --git a/syntaxhighlight/textadept/erlang.lua b/syntaxhighlight/textadept/erlang.lua index fd9beb1..ffa354f 100644 --- a/syntaxhighlight/textadept/erlang.lua +++ b/syntaxhighlight/textadept/erlang.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Erlang LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('erlang') @@ -12,55 +12,55 @@ local lex = lexer.new('erlang') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - after begin case catch cond end fun if let of query receive try when +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if', 'let', 'of', 'query', 'receive', + 'try', 'when', -- Operators. - div rem or xor bor bxor bsl bsr and band not bnot badarg nocookie orelse - andalso false true -]])) + 'div', 'rem', 'or', 'xor', 'bor', 'bxor', 'bsl', 'bsr', 'and', 'band', 'not', 'bnot', 'badarg', + 'nocookie', 'orelse', 'andalso', 'false', 'true' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs alive apply atom_to_list binary_to_list binary_to_term concat_binary date - disconnect_node element erase exit float float_to_list get get_keys - group_leader halt hd integer_to_list is_alive is_record length link - list_to_atom list_to_binary list_to_float list_to_integer list_to_pid - list_to_tuple load_module make_ref monitor_node node nodes now open_port - pid_to_list process_flag process_info process put register registered round - self setelement size spawn spawn_link split_binary statistics term_to_binary - throw time tl trunc tuple_to_list unlink unregister whereis +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'alive', 'apply', 'atom_to_list', 'binary_to_list', 'binary_to_term', 'concat_binary', + 'date', 'disconnect_node', 'element', 'erase', 'exit', 'float', 'float_to_list', 'get', + 'get_keys', 'group_leader', 'halt', 'hd', 'integer_to_list', 'is_alive', 'is_record', 'length', + 'link', 'list_to_atom', 'list_to_binary', 'list_to_float', 'list_to_integer', 'list_to_pid', + 'list_to_tuple', 'load_module', 'make_ref', 'monitor_node', 'node', 'nodes', 'now', 'open_port', + 'pid_to_list', 'process_flag', 'process_info', 'process', 'put', 'register', 'registered', + 'round', 'self', 'setelement', 'size', 'spawn', 'spawn_link', 'split_binary', 'statistics', + 'term_to_binary', 'throw', 'time', 'tl', 'trunc', 'tuple_to_list', 'unlink', 'unregister', + 'whereis', -- Others. - any atom binary bitstring byte constant function integer list map mfa - non_neg_integer number pid ports port_close port_info pos_integer reference - record + 'any', 'atom', 'binary', 'bitstring', 'byte', 'constant', 'function', 'integer', 'list', 'map', + 'mfa', 'non_neg_integer', 'number', 'pid', 'ports', 'port_close', 'port_info', 'pos_integer', + 'reference', 'record', -- Erlang. - check_process_code delete_module get_cookie hash math module_loaded preloaded - processes purge_module set_cookie set_node + 'check_process_code', 'delete_module', 'get_cookie', 'hash', 'math', 'module_loaded', 'preloaded', + 'processes', 'purge_module', 'set_cookie', 'set_node', -- Math. - acos asin atan atan2 cos cosh exp log log10 min max pi pow power sin sinh sqrt - tan tanh -]])) + 'acos', 'asin', 'atan', 'atan2', 'cos', 'cosh', 'exp', 'log', 'log10', 'min', 'max', 'pi', 'pow', + 'power', 'sin', 'sinh', 'sqrt', 'tan', 'tanh' +})) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.lower * - ('_' + lexer.alnum)^0)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.lower * ('_' + lexer.alnum)^0)) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, P('_')^0 * lexer.upper * - ('_' + lexer.alnum)^0)) +lex:add_rule('variable', token(lexer.VARIABLE, P('_')^0 * lexer.upper * ('_' + lexer.alnum)^0)) -- Directives. -lex:add_rule('directive', token('directive', '-' * word_match[[ - author behaviour behavior compile copyright define doc else endif export file - ifdef ifndef import include include_lib module record spec type undef -]])) -lex:add_style('directive', lexer.STYLE_PREPROCESSOR) +lex:add_rule('directive', token('directive', '-' * word_match{ + 'author', 'behaviour', 'behavior', 'compile', 'copyright', 'define', 'doc', 'else', 'endif', + 'export', 'file', 'ifdef', 'ifndef', 'import', 'include', 'include_lib', 'module', 'record', + 'spec', 'type', 'undef' +})) +lex:add_style('directive', lexer.styles.preprocessor) -- Strings. local sq_str = lexer.range("'", true) local dq_str = lexer.range('"') -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + - '$' * lexer.any * lexer.alnum^0)) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + '$' * lexer.any * lexer.alnum^0)) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) @@ -86,6 +86,6 @@ lex:add_fold_point(lexer.KEYWORD, 'receive', 'end') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '%', lexer.fold_line_comments('%')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%')) return lex diff --git a/syntaxhighlight/textadept/fantom.lua b/syntaxhighlight/textadept/fantom.lua new file mode 100644 index 0000000..ccb1c07 --- /dev/null +++ b/syntaxhighlight/textadept/fantom.lua @@ -0,0 +1,85 @@ +local lpeg = require('lpeg') +-- Copyright 2018-2021 Simeon Maryasin (MarSoft). See LICENSE. +-- Fantom LPeg lexer. +-- Based on Java LPeg lexer by Mitchell and Vim's Fantom syntax. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('fantom') + +-- Whitespace. +local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', ws) + +-- Classes. +local type = token(lexer.TYPE, lexer.word) +lex:add_rule('class_sequence', + token(lexer.KEYWORD, 'class') * ws * type * ( -- at most one inheritance spec + ws * token(lexer.OPERATOR, ':') * ws * type * + ( -- at least 0 (i.e. any number) of additional classes + ws^-1 * token(lexer.OPERATOR, ',') * ws^-1 * type)^0)^-1) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'using', 'native', -- external + 'goto', 'void', 'serializable', 'volatile', -- error + 'if', 'else', 'switch', -- conditional + 'do', 'while', 'for', 'foreach', 'each', -- repeat + 'true', 'false', -- boolean + 'null', -- constant + 'this', 'super', -- typedef + 'new', 'is', 'isnot', 'as', -- operator + 'plus', 'minus', 'mult', 'div', 'mod', 'get', 'set', 'slice', 'lshift', 'rshift', 'and', 'or', + 'xor', 'inverse', 'negate', -- + 'increment', 'decrement', 'equals', 'compare', -- long operator + 'return', -- stmt + 'static', 'const', 'final', -- storage class + 'virtual', 'override', 'once', -- slot + 'readonly', -- field + 'throw', 'try', 'catch', 'finally', -- exceptions + 'assert', -- assert + 'class', 'enum', 'mixin', -- typedef + 'break', 'continue', -- branch + 'default', 'case', -- labels + 'public', 'internal', 'protected', 'private', 'abstract' -- scope decl +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match( + 'Void Bool Int Float Decimal Str Duration Uri Type Range List Map Obj Err Env'))) + +-- Functions. +-- lex:add_rule('function', token(lexer.FUNCTION, lexer.word) * #P('(')) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +local bq_str = lexer.range('`', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str)) + +-- Comments. +local line_comment = lexer.to_eol('//', true) +local block_comment = lexer.range('/*', '*/') +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlFfDd')^-1)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}#'))) + +-- Annotations. +lex:add_rule('facet', token('facet', '@' * lexer.word)) +lex:add_style('facet', lexer.styles.preprocessor) + +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, '/*', '*/') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) + +return lex diff --git a/syntaxhighlight/textadept/faust.lua b/syntaxhighlight/textadept/faust.lua index 4cfd6da..d13f780 100644 --- a/syntaxhighlight/textadept/faust.lua +++ b/syntaxhighlight/textadept/faust.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 David B. Lamkins . See License.txt. +-- Copyright 2015-2021 David B. Lamkins . See LICENSE. -- Faust LPeg lexer, see http://faust.grame.fr/ local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('faust') @@ -12,11 +12,11 @@ local lex = lexer.new('faust') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - declare import mdoctags dependencies distributed inputs outputs par seq sum - prod xor with environment library component ffunction fvariable fconstant int - float case waveform h: v: t: -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'declare', 'import', 'mdoctags', 'dependencies', 'distributed', 'inputs', 'outputs', 'par', 'seq', + 'sum', 'prod', 'xor', 'with', 'environment', 'library', 'component', 'ffunction', 'fvariable', + 'fconstant', 'int', 'float', 'case', 'waveform', 'h:', 'v:', 't:' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -30,18 +30,16 @@ local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -local int = R('09')^1 +local int = lexer.digit^1 local rad = P('.') local exp = (P('e') * S('+-')^-1 * int)^-1 local flt = int * (rad * int)^-1 * exp + int^-1 * rad * int * exp lex:add_rule('number', token(lexer.NUMBER, flt + int)) -- Pragmas. -lex:add_rule('pragma', token(lexer.PREPROCESSOR, P('') * - (lexer.any - P(''))^0 * P('')^-1)) +lex:add_rule('pragma', token(lexer.PREPROCESSOR, lexer.range('', ''))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\''))) +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\''))) return lex diff --git a/syntaxhighlight/textadept/fennel.lua b/syntaxhighlight/textadept/fennel.lua new file mode 100644 index 0000000..64a6365 --- /dev/null +++ b/syntaxhighlight/textadept/fennel.lua @@ -0,0 +1,39 @@ +local lpeg = require('lpeg') +-- Copyright 2006-2021 Mitchell. See LICENSE. +-- Fennel LPeg lexer. +-- Contributed by Momohime Honda. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('fennel', {inherit = lexer.load('lua')}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:modify_rule('keyword', token(lexer.KEYWORD, word_match{ + '%', '*', '+', '-', '->>', '->', '-?>>', '-?>', '..', '.', '//', '/', ':', '<=', '<', '=', '>=', + '>', '^', '~=', 'λ', 'and', 'comment', 'do', 'doc', 'doto', 'each', 'eval-compiler', 'fn', 'for', + 'global', 'hashfn', 'if', 'include', 'lambda', 'length', 'let', 'local', 'lua', 'macro', 'macros', + 'match', 'not', 'not=', 'or', 'partial', 'quote', 'require-macros', 'set', 'set-forcibly!', + 'tset', 'values', 'var', 'when', 'while' +})) + +-- Identifiers. +local initial = lexer.alpha + S('|$%&#*+-./:<=>?~^_λ!') +local subsequent = initial + lexer.digit +lex:modify_rule('identifier', token(lexer.IDENTIFIER, initial * subsequent^0)) + +-- Strings. +lex:modify_rule('string', token(lexer.STRING, lexer.range('"'))) + +-- Comments. +lex:modify_rule('comment', token(lexer.COMMENT, lexer.to_eol(';'))) + +-- Ignore these rules. +lex:modify_rule('label', P(false)) +lex:modify_rule('operator', P(false)) + +return lex diff --git a/syntaxhighlight/textadept/fish.lua b/syntaxhighlight/textadept/fish.lua index fc3a29b..39af19d 100644 --- a/syntaxhighlight/textadept/fish.lua +++ b/syntaxhighlight/textadept/fish.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Jason Schindler. See License.txt. +-- Copyright 2015-2021 Jason Schindler. See LICENSE. -- Fish (http://fishshell.com/) script LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('fish') @@ -12,22 +12,22 @@ local lex = lexer.new('fish') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - alias and begin bg bind block break breakpoint builtin case cd command - commandline complete contains continue count dirh dirs echo else emit end eval - exec exit fg fish fish_config fishd fish_indent fish_pager fish_prompt - fish_right_prompt fish_update_completions for funced funcsave function - functions help history if in isatty jobs math mimedb nextd not open or popd - prevd psub pushd pwd random read return set set_color source status switch - test trap type ulimit umask vared while -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'alias', 'and', 'begin', 'bg', 'bind', 'block', 'break', 'breakpoint', 'builtin', 'case', 'cd', + 'command', 'commandline', 'complete', 'contains', 'continue', 'count', 'dirh', 'dirs', 'echo', + 'else', 'emit', 'end', 'eval', 'exec', 'exit', 'fg', 'fish', 'fish_config', 'fishd', + 'fish_indent', 'fish_pager', 'fish_prompt', 'fish_right_prompt', 'fish_update_completions', 'for', + 'funced', 'funcsave', 'function', 'functions', 'help', 'history', 'if', 'in', 'isatty', 'jobs', + 'math', 'mimedb', 'nextd', 'not', 'open', 'or', 'popd', 'prevd', 'psub', 'pushd', 'pwd', 'random', + 'read', 'return', 'set', 'set_color', 'source', 'status', 'switch', 'test', 'trap', 'type', + 'ulimit', 'umask', 'vared', 'while' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.word + - lexer.range('{', '}', true)))) +lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.word + lexer.range('{', '}', true)))) -- Strings. local sq_str = lexer.range("'", false, false) @@ -36,7 +36,7 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Shebang. lex:add_rule('shebang', token('shebang', lexer.to_eol('#!/'))) -lex:add_style('shebang', lexer.STYLE_LABEL) +lex:add_style('shebang', lexer.styles.label) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) diff --git a/syntaxhighlight/textadept/forth.lua b/syntaxhighlight/textadept/forth.lua index 2bde972..73be852 100644 --- a/syntaxhighlight/textadept/forth.lua +++ b/syntaxhighlight/textadept/forth.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Forth LPeg lexer. -- Contributions from Joseph Eib. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('forth') @@ -19,28 +19,29 @@ local s_bs_str = 's\\' * lexer.range('"', true) local dot_str = '.' * lexer.range('"', true, false) local dot_paren_str = '.' * lexer.range('(', ')', true) local abort_str = 'abort' * lexer.range('"', true, false) -lex:add_rule('string', token(lexer.STRING, c_str + s_str + s_bs_str + dot_str + - dot_paren_str + abort_str)) +lex:add_rule('string', + token(lexer.STRING, c_str + s_str + s_bs_str + dot_str + dot_paren_str + abort_str)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - #> #s */ */mod +loop , . .r /mod 0< 0<> 0> 0= 1+ 1- 2! 2* 2/ 2>r 2@ 2drop 2dup - 2over 2r> 2r@ 2swap :noname <# <> >body >in >number >r ?do ?dup @ abort abs - accept action-of again align aligned allot and base begin bl buffer: c! c, c@ - case cell+ cells char char+ chars compile, constant, count cr create decimal - defer defer! defer@ depth do does> drop dup else emit endcase endof - environment? erase evaluate execute exit false fill find fm/mod here hex hold - holds i if immediate invert is j key leave literal loop lshift m* marker max - min mod move negate nip of or over pad parse parse-name pick postpone quit r> - r@ recurse refill restore-input roll rot rshift s>d save-input sign sm/rem - source source-id space spaces state swap to then true tuck type u. u.r u> u< - um* um/mod unloop until unused value variable while within word xor ['] [char] - [compile] -]], true)) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + '#>', '#s', '*/', '*/mod', '+loop', ',', '.', '.r', '/mod', '0<', '0<>', '0>', '0=', '1+', '1-', + '2!', '2*', '2/', '2>r', '2@', '2drop', '2dup', '2over', '2r>', '2r@', '2swap', ':noname', '<#', + '<>', '>body', '>in', '>number', '>r', '?do', '?dup', '@', 'abort', 'abs', 'accept', 'action-of', + 'again', 'align', 'aligned', 'allot', 'and', 'base', 'begin', 'bl', 'buffer:', 'c!', 'c,', 'c@', + 'case', 'cell+', 'cells', 'char', 'char+', 'chars', 'compile,', 'constant,', 'count', 'cr', + 'create', 'decimal', 'defer', 'defer!', 'defer@', 'depth', 'do', 'does>', 'drop', 'dup', 'else', + 'emit', 'endcase', 'endof', 'environment?', 'erase', 'evaluate', 'execute', 'exit', 'false', + 'fill', 'find', 'fm/mod', 'here', 'hex', 'hold', 'holds', 'i', 'if', 'immediate', 'invert', 'is', + 'j', 'key', 'leave', 'literal', 'loop', 'lshift', 'm*', 'marker', 'max', 'min', 'mod', 'move', + 'negate', 'nip', 'of', 'or', 'over', 'pad', 'parse', 'parse-name', 'pick', 'postpone', 'quit', + 'r>', 'r@', 'recurse', 'refill', 'restore-input', 'roll', 'rot', 'rshift', 's>d', 'save-input', + 'sign', 'sm/rem', 'source', 'source-id', 'space', 'spaces', 'state', 'swap', 'to', 'then', 'true', + 'tuck', 'type', 'u.', 'u.r', 'u>', 'u<', 'um*', 'um/mod', 'unloop', 'until', 'unused', 'value', + 'variable', 'while', 'within', 'word', 'xor', "[']", '[char]', '[compile]' +}, true))) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, - (lexer.alnum + S('+-*=<>.?/\'%,_$#'))^1)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alnum + S('+-*=<>.?/\'%,_$#'))^1)) -- Comments. local line_comment = lexer.to_eol(S('|\\')) @@ -48,8 +49,7 @@ local block_comment = lexer.range('(', ')') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * - (S('./') * lexer.digit^1)^-1)) +lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * (S('./') * lexer.digit^1)^-1)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S(':;<>+*-/[]#'))) diff --git a/syntaxhighlight/textadept/fortran.lua b/syntaxhighlight/textadept/fortran.lua index 088af37..b4f87ae 100644 --- a/syntaxhighlight/textadept/fortran.lua +++ b/syntaxhighlight/textadept/fortran.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Fortran LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('fortran') @@ -12,47 +12,45 @@ local lex = lexer.new('fortran') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments. -local c_comment = lexer.to_eol(lexer.starts_line(S('Cc'))) -local d_comment = lexer.to_eol(lexer.starts_line(S('Dd'))) -local ex_comment = lexer.to_eol(lexer.starts_line('!')) -local ast_comment = lexer.to_eol(lexer.starts_line('*')) -local line_comment = lexer.to_eol('!') -lex:add_rule('comment', token(lexer.COMMENT, c_comment + d_comment + - ex_comment + ast_comment + line_comment)) +local line_comment = lexer.to_eol(lexer.starts_line(S('CcDd!*')) + '!') +lex:add_rule('comment', token(lexer.COMMENT, line_comment)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - include program module subroutine function contains use call return +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'include', 'program', 'module', 'subroutine', 'function', 'contains', 'use', 'call', 'return', -- Statements. - case select default continue cycle do while else if elseif then elsewhere end - endif enddo forall where exit goto pause stop + 'case', 'select', 'default', 'continue', 'cycle', 'do', 'while', 'else', 'if', 'elseif', 'then', + 'elsewhere', 'end', 'endif', 'enddo', 'forall', 'where', 'exit', 'goto', 'pause', 'stop', -- Operators. - .not. .and. .or. .xor. .eqv. .neqv. .eq. .ne. .gt. .ge. .lt. .le. + '.not.', '.and.', '.or.', '.xor.', '.eqv.', '.neqv.', '.eq.', '.ne.', '.gt.', '.ge.', '.lt.', + '.le.', -- Logical. - .false. .true. -]], true))) + '.false.', '.true.' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ +lex:add_rule('function', token(lexer.FUNCTION, word_match({ -- I/O. - backspace close endfile inquire open print read rewind write format + 'backspace', 'close', 'endfile', 'inquire', 'open', 'print', 'read', 'rewind', 'write', 'format', -- Type conversion utility and math. - aimag aint amax0 amin0 anint ceiling cmplx conjg dble dcmplx dfloat dim dprod - float floor ifix imag int logical modulo nint real sign sngl transfer zext abs - acos aimag aint alog alog10 amax0 amax1 amin0 amin1 amod anint asin atan atan2 - cabs ccos char clog cmplx conjg cos cosh csin csqrt dabs dacos dasin datan - datan2 dble dcos dcosh ddim dexp dim dint dlog dlog10 dmax1 dmin1 dmod dnint - dprod dreal dsign dsin dsinh dsqrt dtan dtanh exp float iabs ichar idim idint - idnint ifix index int isign len lge lgt lle llt log log10 max max0 max1 min - min0 min1 mod nint real sign sin sinh sngl sqrt tan tanh -]], true))) + 'aimag', 'aint', 'amax0', 'amin0', 'anint', 'ceiling', 'cmplx', 'conjg', 'dble', 'dcmplx', + 'dfloat', 'dim', 'dprod', 'float', 'floor', 'ifix', 'imag', 'int', 'logical', 'modulo', 'nint', + 'real', 'sign', 'sngl', 'transfer', 'zext', 'abs', 'acos', 'aimag', 'aint', 'alog', 'alog10', + 'amax0', 'amax1', 'amin0', 'amin1', 'amod', 'anint', 'asin', 'atan', 'atan2', 'cabs', 'ccos', + 'char', 'clog', 'cmplx', 'conjg', 'cos', 'cosh', 'csin', 'csqrt', 'dabs', 'dacos', 'dasin', + 'datan', 'datan2', 'dble', 'dcos', 'dcosh', 'ddim', 'dexp', 'dim', 'dint', 'dlog', 'dlog10', + 'dmax1', 'dmin1', 'dmod', 'dnint', 'dprod', 'dreal', 'dsign', 'dsin', 'dsinh', 'dsqrt', 'dtan', + 'dtanh', 'exp', 'float', 'iabs', 'ichar', 'idim', 'idint', 'idnint', 'ifix', 'index', 'int', + 'isign', 'len', 'lge', 'lgt', 'lle', 'llt', 'log', 'log10', 'max', 'max0', 'max1', 'min', 'min0', + 'min1', 'mod', 'nint', 'real', 'sign', 'sin', 'sinh', 'sngl', 'sqrt', 'tan', 'tanh' +}, true))) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match([[ - implicit explicit none data parameter allocate allocatable allocated - deallocate integer real double precision complex logical character dimension - kind -]], true))) +lex:add_rule('type', token(lexer.TYPE, word_match({ + 'implicit', 'explicit', 'none', 'data', 'parameter', 'allocate', 'allocatable', 'allocated', + 'deallocate', 'integer', 'real', 'double', 'precision', 'complex', 'logical', 'character', + 'dimension', 'kind' +}, true))) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.number * -lexer.alpha)) diff --git a/syntaxhighlight/textadept/fsharp.lua b/syntaxhighlight/textadept/fsharp.lua index fade6e0..eb97e7b 100644 --- a/syntaxhighlight/textadept/fsharp.lua +++ b/syntaxhighlight/textadept/fsharp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- F# LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('fsharp', {fold_by_indentation = true}) @@ -12,24 +12,25 @@ local lex = lexer.new('fsharp', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract and as assert asr begin class default delegate do done downcast - downto else end enum exception false finaly for fun function if in iherit - interface land lazy let lor lsl lsr lxor match member mod module mutable - namespace new null of open or override sig static struct then to true try type - val when inline upcast while with async atomic break checked component const - constructor continue eager event external fixed functor include method mixin - process property protected public pure readonly return sealed switch virtual - void volatile where +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'and', 'as', 'assert', 'asr', 'begin', 'class', 'default', 'delegate', 'do', 'done', + 'downcast', 'downto', 'else', 'end', 'enum', 'exception', 'false', 'finaly', 'for', 'fun', + 'function', 'if', 'in', 'iherit', 'interface', 'land', 'lazy', 'let', 'lor', 'lsl', 'lsr', 'lxor', + 'match', 'member', 'mod', 'module', 'mutable', 'namespace', 'new', 'null', 'of', 'open', 'or', + 'override', 'sig', 'static', 'struct', 'then', 'to', 'true', 'try', 'type', 'val', 'when', + 'inline', 'upcast', 'while', 'with', 'async', 'atomic', 'break', 'checked', 'component', 'const', + 'constructor', 'continue', 'eager', 'event', 'external', 'fixed', 'functor', 'include', 'method', + 'mixin', 'process', 'property', 'protected', 'public', 'pure', 'readonly', 'return', 'sealed', + 'switch', 'virtual', 'void', 'volatile', 'where', -- Booleans. - true false -]])) + 'true', 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool byte sbyte int16 uint16 int uint32 int64 uint64 nativeint unativeint char - string decimal unit void float32 single float double -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'byte', 'sbyte', 'int16', 'uint16', 'int', 'uint32', 'int64', 'uint64', 'nativeint', + 'unativeint', 'char', 'string', 'decimal', 'unit', 'void', 'float32', 'single', 'float', 'double' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -45,18 +46,13 @@ local block_comment = lexer.range('(*', '*)', false, false, true) lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, - (lexer.float + lexer.integer * S('uUlL')^-1))) +lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer * S('uUlL')^-1)) -- Preprocessor. -local preproc_word = word_match[[ - else endif endregion if ifdef ifndef light region -]] -lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * - S('\t ')^0 * preproc_word)) +lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * S('\t ')^0 * + word_match('else endif endregion if ifdef ifndef light region'))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('=<>+-*/^.,:;~!@#%^&|?[](){}'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/^.,:;~!@#%^&|?[](){}'))) return lex diff --git a/syntaxhighlight/textadept/fstab.lua b/syntaxhighlight/textadept/fstab.lua new file mode 100644 index 0000000..8fd4ac7 --- /dev/null +++ b/syntaxhighlight/textadept/fstab.lua @@ -0,0 +1,127 @@ +local lpeg = require('lpeg') +-- Copyright 2016-2021 Christian Hesse. See LICENSE. +-- fstab LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('fstab', {lex_by_line = true}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Basic filesystem-independent mount options. + 'async', 'atime', 'auto', 'comment', 'context', 'defaults', 'defcontext', 'dev', 'dirsync', + 'exec', 'fscontext', 'group', 'iversion', 'lazytime', 'loud', 'mand', '_netdev', 'noatime', + 'noauto', 'nodev', 'nodiratime', 'noexec', 'nofail', 'noiversion', 'nolazytime', 'nomand', + 'norelatime', 'nostrictatime', 'nosuid', 'nouser', 'owner', 'relatime', 'remount', 'ro', + 'rootcontext', 'rw', 'silent', 'strictatime', 'suid', 'sync', 'user', 'users', + -- Mount options for systemd see systemd.mount(5). + 'x-systemd.automount', 'x-systemd.device-timeout', 'x-systemd.idle-timeout', + 'x-systemd.mount-timeout', 'x-systemd.requires', 'x-systemd.requires-mounts-for', + 'x-initrd.mount', + -- Mount options for adfs. + 'uid', 'gid', 'ownmask', 'othmask', + -- Mount options for affs. + 'uid', 'gid', 'setuid', 'setgid', 'mode', 'protect', 'usemp', 'verbose', 'prefix', 'volume', + 'reserved', 'root', 'bs', 'grpquota', 'noquota', 'quota', 'usrquota', + -- Mount options for btrfs. + 'alloc_start', 'autodefrag', 'check_int', 'check_int_data', 'check_int_print_mask', 'commit', + 'compress', 'zlib', 'lzo', 'no', 'compress-force', 'degraded', 'device', 'discard', + 'enospc_debug', 'fatal_errors', 'bug', 'panic', 'flushoncommit', 'inode_cache', 'max_inline', + 'metadata_ratio', 'noacl', 'nobarrier', 'nodatacow', 'nodatasum', 'notreelog', 'recovery', + 'rescan_uuid_tree', 'skip_balance', 'nospace_cache', 'clear_cache', 'ssd', 'nossd', 'ssd_spread', + 'subvol', 'subvolid', 'subvolrootid', 'thread_pool', 'user_subvol_rm_allowed', + -- Mount options for devpts. + 'uid', 'gid', 'mode', 'newinstance', 'ptmxmode', + -- Mount options for ext2. + 'acl', 'noacl', 'bsddf', 'minixdf', 'check', 'nocheck', 'debug', 'errors', 'continue', + 'remount-ro', 'panic', 'grpid', 'bsdgroups', 'nogrpid', 'sysvgroups', 'grpquota', 'noquota', + 'quota', 'usrquota', 'nouid32', 'oldalloc', 'orlov', 'resgid', 'resuid', 'sb', 'user_xattr', + 'nouser_xattr', + -- Mount options for ext3. + 'journal', 'update', 'journal_dev', 'journal_path', 'norecoverynoload', 'data', 'journal', + 'ordered', 'writeback', 'data_err', 'ignore', 'abort', 'barrier', 'commit', 'user_xattr', 'acl', + 'usrjquota', 'grpjquota', 'jqfmt', + -- Mount options for ext4. + 'journal_checksum', 'journal_async_commit', 'barrier', 'nobarrier', 'inode_readahead_blks', + 'stripe', 'delalloc', 'nodelalloc', 'max_batch_time', 'min_batch_time', 'journal_ioprio', 'abort', + 'auto_da_alloc', 'noauto_da_alloc', 'noinit_itable', 'init_itable', 'discard', 'nodiscard', + 'nouid32', 'block_validity', 'noblock_validity', 'dioread_lock', 'dioread_nolock', + 'max_dir_size_kb', 'i_version', + -- Mount options for fat (common part of msdos umsdos and vfat). + 'blocksize', 'uid', 'gid', 'umask', 'dmask', 'fmask', 'allow_utime', 'check', 'relaxed', 'normal', + 'strict', 'codepage', 'conv', 'binary', 'text', 'auto', 'cvf_format', 'cvf_option', 'debug', + 'discard', 'dos1xfloppy', 'errors', 'panic', 'continue', 'remount-ro', 'fat', 'iocharset', 'nfs', + 'stale_rw', 'nostale_ro', 'tz', 'time_offset', 'quiet', 'rodir', 'showexec', 'sys_immutable', + 'flush', 'usefree', 'dots', 'nodots', 'dotsOK', + -- Mount options for hfs. + 'creator', 'type', 'uid', 'gid', 'dir_umask', 'file_umask', 'umask', 'session', 'part', 'quiet', + -- Mount options for hpfs. + 'uid', 'gid', 'umask', 'case', 'lower', 'asis', 'conv', 'binary', 'text', 'auto', 'nocheck', + -- Mount options for iso9660. + 'norock', 'nojoliet', 'check', 'relaxed', 'strict', 'uid', 'gid', 'map', 'normal', 'offacorn', + 'mode', 'unhide', 'block', 'conv', 'auto', 'binary', 'mtext', 'text', 'cruft', 'session', + 'sbsector', 'iocharset', 'utf8', + -- Mount options for jfs. + 'iocharset', 'resize', 'nointegrity', 'integrity', 'errors', 'continue', 'remount-ro', 'panic', + 'noquota', 'quota', 'usrquota', 'grpquota', + -- Mount options for ntfs. + 'iocharset', 'nls', 'utf8', 'uni_xlate', 'posix', 'uid', 'gid', 'umask', + -- Mount options for overlay. + 'lowerdir', 'upperdir', 'workdir', + -- Mount options for reiserfs. + 'conv', 'hash', 'rupasov', 'tea', 'r5', 'detect', 'hashed_relocation', 'no_unhashed_relocation', + 'noborder', 'nolog', 'notail', 'replayonly', 'resize', 'user_xattr', 'acl', 'barrier', 'none', + 'flush', + -- Mount options for tmpfs. + 'size', 'nr_blocks', 'nr_inodes', 'mode', 'uid', 'gid', 'mpol', 'default', 'prefer', 'bind', + 'interleave', + -- Mount options for ubifs. + 'bulk_read', 'no_bulk_read', 'chk_data_crc', 'no_chk_data_crc.', 'compr', 'none', 'lzo', 'zlib', + -- Mount options for udf. + 'gid', 'umask', 'uid', 'unhide', 'undelete', 'nostrict', 'iocharset', 'bs', 'novrs', 'session', + 'anchor', 'volume', 'partition', 'lastblock', 'fileset', 'rootdir', + -- Mount options for ufs. + 'ufstype', 'old', '44bsd', 'ufs2', '5xbsd', 'sun', 'sunx86', 'hp', 'nextstep', 'nextstep-cd', + 'openstep', 'onerror', 'lock', 'umount', 'repair', + -- Mount options for vfat. + 'uni_xlate', 'posix', 'nonumtail', 'utf8', 'shortname', 'lower', 'win95', 'winnt', 'mixed', + -- Mount options for usbfs. + 'devuid', 'devgid', 'devmode', 'busuid', 'busgid', 'busmode', 'listuid', 'listgid', 'listmode', + -- Filesystems. + 'adfs', 'ados', 'affs', 'anon_inodefs', 'atfs', 'audiofs', 'auto', 'autofs', 'bdev', 'befs', + 'bfs', 'btrfs', 'binfmt_misc', 'cd9660', 'cfs', 'cgroup', 'cifs', 'coda', 'configfs', 'cpuset', + 'cramfs', 'devfs', 'devpts', 'devtmpfs', 'e2compr', 'efs', 'ext2', 'ext2fs', 'ext3', 'ext4', + 'fdesc', 'ffs', 'filecore', 'fuse', 'fuseblk', 'fusectl', 'hfs', 'hpfs', 'hugetlbfs', 'iso9660', + 'jffs', 'jffs2', 'jfs', 'kernfs', 'lfs', 'linprocfs', 'mfs', 'minix', 'mqueue', 'msdos', 'ncpfs', + 'nfs', 'nfsd', 'nilfs2', 'none', 'ntfs', 'null', 'nwfs', 'overlay', 'ovlfs', 'pipefs', 'portal', + 'proc', 'procfs', 'pstore', 'ptyfs', 'qnx4', 'reiserfs', 'ramfs', 'romfs', 'securityfs', 'shm', + 'smbfs', 'squashfs', 'sockfs', 'sshfs', 'std', 'subfs', 'swap', 'sysfs', 'sysv', 'tcfs', 'tmpfs', + 'udf', 'ufs', 'umap', 'umsdos', 'union', 'usbfs', 'userfs', 'vfat', 'vs3fs', 'vxfs', 'wrapfs', + 'wvfs', 'xenfs', 'xfs', 'zisofs' +})) + +-- Numbers. +local uuid = lexer.xdigit^8 * ('-' * lexer.xdigit^4)^-3 * '-' * lexer.xdigit^12 +local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 +local oct_num = '0' * S('01234567_')^1 +local integer = S('+-')^-1 * (lexer.hex_num + oct_num + dec) +lex:add_rule('number', token(lexer.NUMBER, uuid + lexer.float + integer)) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol('#')))) + +-- Directories. +lex:add_rule('directory', token(lexer.VARIABLE, '/' * (1 - lexer.space)^0)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('=,'))) + +return lex diff --git a/syntaxhighlight/textadept/gap.lua b/syntaxhighlight/textadept/gap.lua index ae49921..c00a3e2 100644 --- a/syntaxhighlight/textadept/gap.lua +++ b/syntaxhighlight/textadept/gap.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Gap LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('gap') @@ -12,10 +12,11 @@ local lex = lexer.new('gap') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and break continue do elif else end fail false fi for function if in infinity - local not od or rec repeat return then true until while -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'break', 'continue', 'do', 'elif', 'else', 'end', 'fail', 'false', 'fi', 'for', 'function', + 'if', 'in', 'infinity', 'local', 'not', 'od', 'or', 'rec', 'repeat', 'return', 'then', 'true', + 'until', 'while' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -29,7 +30,7 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.digit^1 * -lexer.alpha)) +lex:add_rule('number', token(lexer.NUMBER, lexer.dec_num * -lexer.alpha)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('*+-,./:;<=>~^#()[]{}'))) @@ -39,6 +40,6 @@ lex:add_fold_point(lexer.KEYWORD, 'function', 'end') lex:add_fold_point(lexer.KEYWORD, 'do', 'od') lex:add_fold_point(lexer.KEYWORD, 'if', 'fi') lex:add_fold_point(lexer.KEYWORD, 'repeat', 'until') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/gettext.lua b/syntaxhighlight/textadept/gettext.lua index 4a301cb..875c9c7 100644 --- a/syntaxhighlight/textadept/gettext.lua +++ b/syntaxhighlight/textadept/gettext.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Gettext LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('gettext') @@ -12,9 +12,8 @@ local lex = lexer.new('gettext') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - msgid msgid_plural msgstr fuzzy c-format no-c-format -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'msgid msgid_plural msgstr fuzzy c-format no-c-format', true))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/gherkin.lua b/syntaxhighlight/textadept/gherkin.lua index 5eaea5d..8d8b028 100644 --- a/syntaxhighlight/textadept/gherkin.lua +++ b/syntaxhighlight/textadept/gherkin.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Jason Schindler. See License.txt. +-- Copyright 2015-2021 Jason Schindler. See LICENSE. -- Gherkin (https://github.com/cucumber/cucumber/wiki/Gherkin) LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('gherkin', {fold_by_indentation = true}) @@ -12,9 +12,8 @@ local lex = lexer.new('gherkin', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - And Background But Examples Feature Given Outline Scenario Scenarios Then When -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'And Background But Examples Feature Given Outline Scenario Scenarios Then When'))) -- Strings. local doc_str = lexer.range('"""') @@ -25,19 +24,18 @@ lex:add_rule('string', token(lexer.STRING, doc_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) -- Numbers. -local number = token(lexer.NUMBER, lexer.number) +-- lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Tags. lex:add_rule('tag', token('tag', '@' * lexer.word^0)) -lex:add_style('tag', lexer.STYLE_LABEL) +lex:add_style('tag', lexer.styles.label) -- Placeholders. -lex:add_rule('placeholder', token('placeholder', - lexer.range('<', '>', false, false, true))) -lex:add_style('placeholder', lexer.STYLE_VARIABLE) +lex:add_rule('placeholder', token('placeholder', lexer.range('<', '>', false, false, true))) +lex:add_style('placeholder', lexer.styles.variable) -- Examples. lex:add_rule('example', token('example', lexer.to_eol('|'))) -lex:add_style('example', lexer.STYLE_NUMBER) +lex:add_style('example', lexer.styles.number) return lex diff --git a/syntaxhighlight/textadept/gleam.lua b/syntaxhighlight/textadept/gleam.lua new file mode 100644 index 0000000..54bd8ea --- /dev/null +++ b/syntaxhighlight/textadept/gleam.lua @@ -0,0 +1,120 @@ +local lpeg = require('lpeg') +-- Copyright 2021 Mitchell. See LICENSE. +-- Gleam LPeg lexer +-- https://gleam.run/ +-- Contributed by Tynan Beatty + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local KEY, OP = lexer.KEYWORD, lexer.OPERATOR + +local lex = lexer.new('gleam') + +-- Whitespace. +local gleam_ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', gleam_ws) + +-- Types. +local typ_tok = token(lexer.TYPE, lexer.upper * lexer.alnum^0) +lex:add_rule('type', typ_tok) + +-- Modules. +local name = (lexer.lower + '_') * (lexer.lower + lexer.digit + '_')^0 +local fn_name = token(lexer.FUNCTION, name) +local mod_name = token('module', name) +local typ_or_fn = typ_tok + fn_name +local function mod_tok(ws) + return token(KEY, 'import') * ws^1 * mod_name * (ws^0 * token(OP, '/') * ws^0 * mod_name)^0 * + (ws^1 * token(KEY, 'as') * ws^1 * mod_name)^-1 * + (ws^0 * token(OP, '.') * ws^0 * token(OP, '{') * ws^0 * typ_or_fn * + (ws^0 * token(OP, ',') * ws^0 * typ_or_fn)^0 * ws^0 * token(OP, '}'))^-1 +end +lex:add_rule('module', mod_tok(gleam_ws)) +lex:add_style('module', lexer.styles.constant) + +-- Keywords. +local key_tok = token(KEY, word_match( + 'as assert case const external fn if import let opaque pub todo try tuple type')) +lex:add_rule('keyword', key_tok) + +-- Functions. +local function fn_tok(ws) + local mod_name_op = mod_name * ws^0 * token(OP, '.') + local fn_def_call = mod_name_op^-1 * ws^0 * fn_name * ws^0 * #P('(') + local fn_pipe = token(OP, '|>') * ws^0 * (token(KEY, 'fn') + mod_name_op^-1 * fn_name) + return fn_def_call + fn_pipe +end +lex:add_rule('function', fn_tok(gleam_ws)) + +-- Labels. +local id = token(lexer.IDENTIFIER, name) +local function lab_tok(ws) + return token(OP, S('(,')) * ws^0 * token(lexer.LABEL, name) * #(ws^1 * id) +end +lex:add_rule('label', lab_tok(gleam_ws)) + +-- Identifiers. +local discard_id = token('discard', '_' * name) +local id_tok = discard_id + id +lex:add_rule('identifier', id_tok) +lex:add_style('discard', lexer.styles.comment) + +-- Strings. +local str_tok = token(lexer.STRING, lexer.range('"')) +lex:add_rule('string', str_tok) + +-- Comments. +local com_tok = token(lexer.COMMENT, lexer.to_eol('//')) +lex:add_rule('comment', com_tok) + +-- Numbers. +local function can_neg(patt) return (lpeg.B(lexer.space + S('+-/*%<>=&|:,.')) * '-')^-1 * patt end +local function can_sep(patt) return (P('_')^-1 * patt^1)^1 end +local dec = lexer.digit * can_sep(lexer.digit)^0 +local float = dec * '.' * dec^0 +local bin = '0' * S('bB') * can_sep(S('01')) +local oct = '0' * S('oO') * can_sep(lpeg.R('07')) +local hex = '0' * S('xX') * can_sep(lexer.xdigit) +local num_tok = token(lexer.NUMBER, can_neg(float) + bin + oct + hex + can_neg(dec)) +lex:add_rule('number', num_tok) + +-- Operators. +local op_tok = token(OP, S('+-*/%#!=<>&|.,:;{}[]()')) +lex:add_rule('operator', op_tok) + +-- Errors. +local err_tok = token(lexer.ERROR, lexer.any) +lex:add_rule('error', err_tok) + +-- Fold points. +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.OPERATOR, '[', ']') +lex:add_fold_point(lexer.OPERATOR, '(', ')') + +-- Embedded Bit Strings. +-- Mimic lexer.load() by creating a bitstring-specific whitespace style. +local bitstring = lexer.new(lex._NAME .. '_bitstring') +local bitstring_ws = token(bitstring._NAME .. '_whitespace', lexer.space^1) +bitstring:add_rule('whitespace', bitstring_ws) +bitstring:add_style(bitstring._NAME .. '_whitespace', lexer.styles.whitespace) +bitstring:add_rule('type', typ_tok) +bitstring:add_rule('module', mod_tok(bitstring_ws)) +bitstring:add_rule('keyword', key_tok + token(KEY, word_match{ + 'binary', 'bytes', 'int', 'float', 'bit_string', 'bits', 'utf8', 'utf16', 'utf32', + 'utf8_codepoint', 'utf16_codepoint', 'utf32_codepoint', 'signed', 'unsigned', 'big', 'little', + 'native', 'unit', 'size' +})) +bitstring:add_rule('function', fn_tok(bitstring_ws)) +bitstring:add_rule('label', lab_tok(bitstring_ws)) +bitstring:add_rule('identifier', id_tok) +bitstring:add_rule('string', str_tok) +bitstring:add_rule('comment', com_tok) +bitstring:add_rule('number', num_tok) +bitstring:add_rule('operator', op_tok) +bitstring:add_rule('error', err_tok) +lex:embed(bitstring, token(OP, '<<'), token(OP, '>>')) + +return lex diff --git a/syntaxhighlight/textadept/glsl.lua b/syntaxhighlight/textadept/glsl.lua index f76b56c..203da5f 100644 --- a/syntaxhighlight/textadept/glsl.lua +++ b/syntaxhighlight/textadept/glsl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- GLSL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S, R = lpeg.P, lpeg.S, lpeg.R local lex = lexer.new('glsl', {inherit = lexer.load('cpp')}) @@ -12,93 +12,94 @@ local lex = lexer.new('glsl', {inherit = lexer.load('cpp')}) lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:modify_rule('keyword', token(lexer.KEYWORD, word_match[[ - attribute const in inout out uniform varying invariant centroid flat smooth - noperspective layout patch sample subroutine lowp mediump highp precision +lex:modify_rule('keyword', token(lexer.KEYWORD, word_match{ + 'attribute', 'const', 'in', 'inout', 'out', 'uniform', 'varying', 'invariant', 'centroid', 'flat', + 'smooth', 'noperspective', 'layout', 'patch', 'sample', 'subroutine', 'lowp', 'mediump', 'highp', + 'precision', -- Macros. - __VERSION__ __LINE__ __FILE__ -]]) + lex:get_rule('keyword')) + '__VERSION__', '__LINE__', '__FILE__' +}) + lex:get_rule('keyword')) -- Types. -lex:modify_rule('type', token(lexer.TYPE, S('bdiu')^-1 * 'vec' * R('24') + +-- LuaFormatter off +lex:modify_rule('type', token(lexer.TYPE, + S('bdiu')^-1 * 'vec' * R('24') + P('d')^-1 * 'mat' * R('24') * ('x' * R('24')^-1) + S('iu')^-1 * 'sampler' * R('13') * 'D' + 'sampler' * R('12') * 'D' * P('Array')^-1 * 'Shadow' + - S('iu')^-1 * 'sampler' * (R('12') * 'DArray' + word_match[[ - Cube 2DRect Buffer 2DMS 2DMSArray 2DMSCubeArray - ]]) + - word_match[[samplerCubeShadow sampler2DRectShadow samplerCubeArrayShadow]]) + + (S('iu')^-1 * 'sampler' * (R('12') * 'DArray' + + word_match('Cube 2DRect Buffer 2DMS 2DMSArray 2DMSCubeArray'))) + + word_match('samplerCubeShadow sampler2DRectShadow samplerCubeArrayShadow')) + +-- LuaFormatter on lex:get_rule('type') + -- Functions. -token(lexer.FUNCTION, word_match[[ - radians degrees sin cos tan asin acos atan sinh cosh tanh asinh acosh atanh - pow exp log exp2 log2 sqrt inversesqrt abs sign floor trunc round roundEven - ceil fract mod modf min max clamp mix step smoothstep isnan isinf - floatBitsToInt floatBitsToUint intBitsToFloat uintBitsToFloat fma frexp ldexp - packUnorm2x16 packUnorm4x8 packSnorm4x8 unpackUnorm2x16 unpackUnorm4x8 - unpackSnorm4x8 packDouble2x32 unpackDouble2x32 length distance dot cross - normalize ftransform faceforward reflect refract matrixCompMult outerProduct - transpose determinant inverse lessThan lessThanEqual greaterThan - greaterThanEqual equal notEqual any all not uaddCarry usubBorrow umulExtended - imulExtended bitfieldExtract bitfildInsert bitfieldReverse bitCount findLSB - findMSB textureSize textureQueryLOD texture textureProj textureLod - textureOffset texelFetch texelFetchOffset textureProjOffset textureLodOffset - textureProjLod textureProjLodOffset textureGrad textureGradOffset - textureProjGrad textureProjGradOffset textureGather textureGatherOffset - texture1D texture2D texture3D texture1DProj texture2DProj texture3DProj - texture1DLod texture2DLod texture3DLod texture1DProjLod texture2DProjLod - texture3DProjLod textureCube textureCubeLod shadow1D shadow2D shadow1DProj - shadow2DProj shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod dFdx dFdy - fwidth interpolateAtCentroid interpolateAtSample interpolateAtOffset noise1 - noise2 noise3 noise4 EmitStreamVertex EndStreamPrimitive EmitVertex - EndPrimitive barrier -]]) + +token(lexer.FUNCTION, word_match{ + 'radians', 'degrees', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh', + 'asinh', 'acosh', 'atanh', 'pow', 'exp', 'log', 'exp2', 'log2', 'sqrt', 'inversesqrt', 'abs', + 'sign', 'floor', 'trunc', 'round', 'roundEven', 'ceil', 'fract', 'mod', 'modf', 'min', 'max', + 'clamp', 'mix', 'step', 'smoothstep', 'isnan', 'isinf', 'floatBitsToInt', 'floatBitsToUint', + 'intBitsToFloat', 'uintBitsToFloat', 'fma', 'frexp', 'ldexp', 'packUnorm2x16', 'packUnorm4x8', + 'packSnorm4x8', 'unpackUnorm2x16', 'unpackUnorm4x8', 'unpackSnorm4x8', 'packDouble2x32', + 'unpackDouble2x32', 'length', 'distance', 'dot', 'cross', 'normalize', 'ftransform', + 'faceforward', 'reflect', 'refract', 'matrixCompMult', 'outerProduct', 'transpose', 'determinant', + 'inverse', 'lessThan', 'lessThanEqual', 'greaterThan', 'greaterThanEqual', 'equal', 'notEqual', + 'any', 'all', 'not', 'uaddCarry', 'usubBorrow', 'umulExtended', 'imulExtended', 'bitfieldExtract', + 'bitfildInsert', 'bitfieldReverse', 'bitCount', 'findLSB', 'findMSB', 'textureSize', + 'textureQueryLOD', 'texture', 'textureProj', 'textureLod', 'textureOffset', 'texelFetch', + 'texelFetchOffset', 'textureProjOffset', 'textureLodOffset', 'textureProjLod', + 'textureProjLodOffset', 'textureGrad', 'textureGradOffset', 'textureProjGrad', + 'textureProjGradOffset', 'textureGather', 'textureGatherOffset', 'texture1D', 'texture2D', + 'texture3D', 'texture1DProj', 'texture2DProj', 'texture3DProj', 'texture1DLod', 'texture2DLod', + 'texture3DLod', 'texture1DProjLod', 'texture2DProjLod', 'texture3DProjLod', 'textureCube', + 'textureCubeLod', 'shadow1D', 'shadow2D', 'shadow1DProj', 'shadow2DProj', 'shadow1DLod', + 'shadow2DLod', 'shadow1DProjLod', 'shadow2DProjLod', 'dFdx', 'dFdy', 'fwidth', + 'interpolateAtCentroid', 'interpolateAtSample', 'interpolateAtOffset', 'noise1', 'noise2', + 'noise3', 'noise4', 'EmitStreamVertex', 'EndStreamPrimitive', 'EmitVertex', 'EndPrimitive', + 'barrier' +}) + -- Variables. -token(lexer.VARIABLE, word_match[[ - gl_VertexID gl_InstanceID gl_Position gl_PointSize gl_ClipDistance - gl_PrimitiveIDIn gl_InvocationID gl_PrimitiveID gl_Layer gl_PatchVerticesIn - gl_TessLevelOuter gl_TessLevelInner gl_TessCoord gl_FragCoord gl_FrontFacing - gl_PointCoord gl_SampleID gl_SamplePosition gl_FragColor gl_FragData - gl_FragDepth gl_SampleMask gl_ClipVertex gl_FrontColor gl_BackColor - gl_FrontSecondaryColor gl_BackSecondaryColor gl_TexCoord gl_FogFragCoord - gl_Color gl_SecondaryColor gl_Normal gl_Vertex gl_MultiTexCoord0 - gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 gl_MultiTexCoord4 - gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 gl_FogCoord -]]) + +token(lexer.VARIABLE, word_match{ + 'gl_VertexID', 'gl_InstanceID', 'gl_Position', 'gl_PointSize', 'gl_ClipDistance', + 'gl_PrimitiveIDIn', 'gl_InvocationID', 'gl_PrimitiveID', 'gl_Layer', 'gl_PatchVerticesIn', + 'gl_TessLevelOuter', 'gl_TessLevelInner', 'gl_TessCoord', 'gl_FragCoord', 'gl_FrontFacing', + 'gl_PointCoord', 'gl_SampleID', 'gl_SamplePosition', 'gl_FragColor', 'gl_FragData', + 'gl_FragDepth', 'gl_SampleMask', 'gl_ClipVertex', 'gl_FrontColor', 'gl_BackColor', + 'gl_FrontSecondaryColor', 'gl_BackSecondaryColor', 'gl_TexCoord', 'gl_FogFragCoord', 'gl_Color', + 'gl_SecondaryColor', 'gl_Normal', 'gl_Vertex', 'gl_MultiTexCoord0', 'gl_MultiTexCoord1', + 'gl_MultiTexCoord2', 'gl_MultiTexCoord3', 'gl_MultiTexCoord4', 'gl_MultiTexCoord5', + 'gl_MultiTexCoord6', 'gl_MultiTexCoord7', 'gl_FogCoord' +}) + -- Constants. -token(lexer.CONSTANT, word_match[[ - gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats - gl_MaxVaryingComponents gl_MaxVertexOutputComponents - gl_MaxGeometryInputComponents gl_MaxGeometryOutputComponents - gl_MaxFragmentInputComponents gl_MaxVertexTextureImageUnits - gl_MaxCombinedTextureImageUnits gl_MaxTextureImageUnits - gl_MaxFragmentUniformComponents gl_MaxDrawBuffers gl_MaxClipDistances - gl_MaxGeometryTextureImageUnits gl_MaxGeometryOutputVertices - gl_MaxGeometryTotalOutputComponents gl_MaxGeometryUniformComponents - gl_MaxGeometryVaryingComponents gl_MaxTessControlInputComponents - gl_MaxTessControlOutputComponents gl_MaxTessControlTextureImageUnits - gl_MaxTessControlUniformComponents gl_MaxTessControlTotalOutputComponents - gl_MaxTessEvaluationInputComponents gl_MaxTessEvaluationOutputComponents - gl_MaxTessEvaluationTextureImageUnits gl_MaxTessEvaluationUniformComponents - gl_MaxTessPatchComponents gl_MaxPatchVertices gl_MaxTessGenLevel - gl_MaxTextureUnits gl_MaxTextureCoords gl_MaxClipPlanes - - gl_DepthRange gl_ModelViewMatrix gl_ProjectionMatrix - gl_ModelViewProjectionMatrix gl_TextureMatrix gl_NormalMatrix - gl_ModelViewMatrixInverse gl_ProjectionMatrixInverse - gl_ModelViewProjectionMatrixInverse gl_TextureMatrixInverse - gl_ModelViewMatrixTranspose gl_ProjectionMatrixTranspose - gl_ModelViewProjectionMatrixTranspose gl_TextureMatrixTranspose - gl_ModelViewMatrixInverseTranspose gl_ProjectionMatrixInverseTranspose - gl_ModelViewProjectionMatrixInverseTranspose gl_TextureMatrixInverseTranspose - gl_NormalScale gl_ClipPlane gl_Point gl_FrontMaterial gl_BackMaterial - gl_LightSource gl_LightModel gl_FrontLightModelProduct - gl_BackLightModelProduct gl_FrontLightProduct gl_BackLightProduct - gl_TextureEnvColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ - gl_ObjectPlaneS gl_ObjectPlaneT gl_ObjectPlaneR gl_ObjectPlaneQ gl_Fog -]])) +token(lexer.CONSTANT, word_match{ + 'gl_MaxVertexAttribs', 'gl_MaxVertexUniformComponents', 'gl_MaxVaryingFloats', + 'gl_MaxVaryingComponents', 'gl_MaxVertexOutputComponents', 'gl_MaxGeometryInputComponents', + 'gl_MaxGeometryOutputComponents', 'gl_MaxFragmentInputComponents', + 'gl_MaxVertexTextureImageUnits', 'gl_MaxCombinedTextureImageUnits', 'gl_MaxTextureImageUnits', + 'gl_MaxFragmentUniformComponents', 'gl_MaxDrawBuffers', 'gl_MaxClipDistances', + 'gl_MaxGeometryTextureImageUnits', 'gl_MaxGeometryOutputVertices', + 'gl_MaxGeometryTotalOutputComponents', 'gl_MaxGeometryUniformComponents', + 'gl_MaxGeometryVaryingComponents', 'gl_MaxTessControlInputComponents', + 'gl_MaxTessControlOutputComponents', 'gl_MaxTessControlTextureImageUnits', + 'gl_MaxTessControlUniformComponents', 'gl_MaxTessControlTotalOutputComponents', + 'gl_MaxTessEvaluationInputComponents', 'gl_MaxTessEvaluationOutputComponents', + 'gl_MaxTessEvaluationTextureImageUnits', 'gl_MaxTessEvaluationUniformComponents', + 'gl_MaxTessPatchComponents', 'gl_MaxPatchVertices', 'gl_MaxTessGenLevel', 'gl_MaxTextureUnits', + 'gl_MaxTextureCoords', 'gl_MaxClipPlanes', -- + 'gl_DepthRange', 'gl_ModelViewMatrix', 'gl_ProjectionMatrix', 'gl_ModelViewProjectionMatrix', + 'gl_TextureMatrix', 'gl_NormalMatrix', 'gl_ModelViewMatrixInverse', 'gl_ProjectionMatrixInverse', + 'gl_ModelViewProjectionMatrixInverse', 'gl_TextureMatrixInverse', 'gl_ModelViewMatrixTranspose', + 'gl_ProjectionMatrixTranspose', 'gl_ModelViewProjectionMatrixTranspose', + 'gl_TextureMatrixTranspose', 'gl_ModelViewMatrixInverseTranspose', + 'gl_ProjectionMatrixInverseTranspose', 'gl_ModelViewProjectionMatrixInverseTranspose', + 'gl_TextureMatrixInverseTranspose', 'gl_NormalScale', 'gl_ClipPlane', 'gl_Point', + 'gl_FrontMaterial', 'gl_BackMaterial', 'gl_LightSource', 'gl_LightModel', + 'gl_FrontLightModelProduct', 'gl_BackLightModelProduct', 'gl_FrontLightProduct', + 'gl_BackLightProduct', 'gl_TextureEnvColor', 'gl_EyePlaneS', 'gl_EyePlaneT', 'gl_EyePlaneR', + 'gl_EyePlaneQ', 'gl_ObjectPlaneS', 'gl_ObjectPlaneT', 'gl_ObjectPlaneR', 'gl_ObjectPlaneQ', + 'gl_Fog' +})) return lex diff --git a/syntaxhighlight/textadept/gnuplot.lua b/syntaxhighlight/textadept/gnuplot.lua index 265f465..48dc8f6 100644 --- a/syntaxhighlight/textadept/gnuplot.lua +++ b/syntaxhighlight/textadept/gnuplot.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Gnuplot LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('gnuplot') @@ -12,35 +12,37 @@ local lex = lexer.new('gnuplot') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - cd call clear exit fit help history if load pause plot using with index every - smooth thru print pwd quit replot reread reset save set show unset shell splot - system test unset update -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'cd', 'call', 'clear', 'exit', 'fit', 'help', 'history', 'if', 'load', 'pause', 'plot', 'using', + 'with', 'index', 'every', 'smooth', 'thru', 'print', 'pwd', 'quit', 'replot', 'reread', 'reset', + 'save', 'set', 'show', 'unset', 'shell', 'splot', 'system', 'test', 'unset', 'update' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs acos acosh arg asin asinh atan atan2 atanh besj0 besj1 besy0 besy1 ceil - cos cosh erf erfc exp floor gamma ibeta inverf igamma imag invnorm int - lambertw lgamma log log10 norm rand real sgn sin sinh sqrt tan tanh column - defined tm_hour tm_mday tm_min tm_mon tm_sec tm_wday tm_yday tm_year valid -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'acos', 'acosh', 'arg', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'besj0', 'besj1', + 'besy0', 'besy1', 'ceil', 'cos', 'cosh', 'erf', 'erfc', 'exp', 'floor', 'gamma', 'ibeta', + 'inverf', 'igamma', 'imag', 'invnorm', 'int', 'lambertw', 'lgamma', 'log', 'log10', 'norm', + 'rand', 'real', 'sgn', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'column', 'defined', 'tm_hour', + 'tm_mday', 'tm_min', 'tm_mon', 'tm_sec', 'tm_wday', 'tm_yday', 'tm_year', 'valid' +})) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, word_match[[ - angles arrow autoscale bars bmargin border boxwidth clabel clip cntrparam - colorbox contour datafile decimalsign dgrid3d dummy encoding fit fontpath - format functions function grid hidden3d historysize isosamples key label - lmargin loadpath locale logscale mapping margin mouse multiplot mx2tics mxtics - my2tics mytics mztics offsets origin output parametric plot pm3d palette - pointsize polar print rmargin rrange samples size style surface terminal tics - ticslevel ticscale timestamp timefmt title tmargin trange urange variables - version view vrange x2data x2dtics x2label x2mtics x2range x2tics x2zeroaxis - xdata xdtics xlabel xmtics xrange xtics xzeroaxis y2data y2dtics y2label - y2mtics y2range y2tics y2zeroaxis ydata ydtics ylabel ymtics yrange ytics - yzeroaxis zdata zdtics cbdata cbdtics zero zeroaxis zlabel zmtics zrange ztics - cblabel cbmtics cbrange cbtics -]])) +lex:add_rule('variable', token(lexer.VARIABLE, word_match{ + 'angles', 'arrow', 'autoscale', 'bars', 'bmargin', 'border', 'boxwidth', 'clabel', 'clip', + 'cntrparam', 'colorbox', 'contour', 'datafile', 'decimalsign', 'dgrid3d', 'dummy', 'encoding', + 'fit', 'fontpath', 'format', 'functions', 'function', 'grid', 'hidden3d', 'historysize', + 'isosamples', 'key', 'label', 'lmargin', 'loadpath', 'locale', 'logscale', 'mapping', 'margin', + 'mouse', 'multiplot', 'mx2tics', 'mxtics', 'my2tics', 'mytics', 'mztics', 'offsets', 'origin', + 'output', 'parametric', 'plot', 'pm3d', 'palette', 'pointsize', 'polar', 'print', 'rmargin', + 'rrange', 'samples', 'size', 'style', 'surface', 'terminal', 'tics', 'ticslevel', 'ticscale', + 'timestamp', 'timefmt', 'title', 'tmargin', 'trange', 'urange', 'variables', 'version', 'view', + 'vrange', 'x2data', 'x2dtics', 'x2label', 'x2mtics', 'x2range', 'x2tics', 'x2zeroaxis', 'xdata', + 'xdtics', 'xlabel', 'xmtics', 'xrange', 'xtics', 'xzeroaxis', 'y2data', 'y2dtics', 'y2label', + 'y2mtics', 'y2range', 'y2tics', 'y2zeroaxis', 'ydata', 'ydtics', 'ylabel', 'ymtics', 'yrange', + 'ytics', 'yzeroaxis', 'zdata', 'zdtics', 'cbdata', 'cbdtics', 'zero', 'zeroaxis', 'zlabel', + 'zmtics', 'zrange', 'ztics', 'cblabel', 'cbmtics', 'cbrange', 'cbtics' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/go.lua b/syntaxhighlight/textadept/go.lua index 416e2b5..aa40d1a 100644 --- a/syntaxhighlight/textadept/go.lua +++ b/syntaxhighlight/textadept/go.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Go LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('go') @@ -12,27 +12,26 @@ local lex = lexer.new('go') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break case chan const continue default defer else fallthrough for func go goto - if import interface map package range return select struct switch type var -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'case', 'chan', 'const', 'continue', 'default', 'defer', 'else', 'fallthrough', 'for', + 'func', 'go', 'goto', 'if', 'import', 'interface', 'map', 'package', 'range', 'return', 'select', + 'struct', 'switch', 'type', 'var' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - true false iota nil -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match('true false iota nil'))) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool byte complex64 complex128 error float32 float64 int int8 int16 int32 - int64 rune string uint uint8 uint16 uint32 uint64 uintptr -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'byte', 'complex64', 'complex128', 'error', 'float32', 'float64', 'int', 'int8', 'int16', + 'int32', 'int64', 'rune', 'string', 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uintptr' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - append cap close complex copy delete imag len make new panic print println - real recover -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'append', 'cap', 'close', 'complex', 'copy', 'delete', 'imag', 'len', 'make', 'new', 'panic', + 'print', 'println', 'real', 'recover' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -57,6 +56,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/%&|^<>=!:;.,()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/groovy.lua b/syntaxhighlight/textadept/groovy.lua index fa738f3..e97e7fe 100644 --- a/syntaxhighlight/textadept/groovy.lua +++ b/syntaxhighlight/textadept/groovy.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Groovy LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('groovy') @@ -12,30 +12,30 @@ local lex = lexer.new('groovy') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract break case catch continue default do else extends final finally for - if implements instanceof native new private protected public return static - switch synchronized throw throws transient try volatile while strictfp package - import as assert def mixin property test using in - false null super this true it -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'break', 'case', 'catch', 'continue', 'default', 'do', 'else', 'extends', 'final', + 'finally', 'for', 'if', 'implements', 'instanceof', 'native', 'new', 'private', 'protected', + 'public', 'return', 'static', 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', + 'volatile', 'while', 'strictfp', 'package', 'import', 'as', 'assert', 'def', 'mixin', 'property', + 'test', 'using', 'in', 'false', 'null', 'super', 'this', 'true', 'it' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs any append asList asWritable call collect compareTo count div dump each - eachByte eachFile eachLine every find findAll flatten getAt getErr getIn - getOut getText grep immutable inject inspect intersect invokeMethods isCase - join leftShift minus multiply newInputStream newOutputStream newPrintWriter - newReader newWriter next plus pop power previous print println push putAt read - readBytes readLines reverse reverseEach round size sort splitEachLine step - subMap times toInteger toList tokenize upto waitForOrKill withPrintWriter - withReader withStream withWriter withWriterAppend write writeLine -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'any', 'append', 'asList', 'asWritable', 'call', 'collect', 'compareTo', 'count', 'div', + 'dump', 'each', 'eachByte', 'eachFile', 'eachLine', 'every', 'find', 'findAll', 'flatten', + 'getAt', 'getErr', 'getIn', 'getOut', 'getText', 'grep', 'immutable', 'inject', 'inspect', + 'intersect', 'invokeMethods', 'isCase', 'join', 'leftShift', 'minus', 'multiply', + 'newInputStream', 'newOutputStream', 'newPrintWriter', 'newReader', 'newWriter', 'next', 'plus', + 'pop', 'power', 'previous', 'print', 'println', 'push', 'putAt', 'read', 'readBytes', 'readLines', + 'reverse', 'reverseEach', 'round', 'size', 'sort', 'splitEachLine', 'step', 'subMap', 'times', + 'toInteger', 'toList', 'tokenize', 'upto', 'waitForOrKill', 'withPrintWriter', 'withReader', + 'withStream', 'withWriter', 'withWriterAppend', 'write', 'writeLine' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - boolean byte char class double float int interface long short void -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'boolean byte char class double float int interface long short void'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -50,8 +50,7 @@ local sq_str = lexer.range("'") local dq_str = lexer.range('"') local tq_str = lexer.range("'''") + lexer.range('"""') local string = token(lexer.STRING, tq_str + sq_str + dq_str) -local regex_str = #P('/') * lexer.last_char_includes('=~|!<>+-*?&,:;([{') * - lexer.range('/', true) +local regex_str = #P('/') * lexer.last_char_includes('=~|!<>+-*?&,:;([{') * lexer.range('/', true) local regex = token(lexer.REGEX, regex_str) lex:add_rule('string', string + regex) @@ -64,6 +63,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=~|!<>+-/*?&.,:;()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/gtkrc.lua b/syntaxhighlight/textadept/gtkrc.lua index f15881a..9cd9bb4 100644 --- a/syntaxhighlight/textadept/gtkrc.lua +++ b/syntaxhighlight/textadept/gtkrc.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Gtkrc LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('gtkrc') @@ -12,31 +12,25 @@ local lex = lexer.new('gtkrc') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - binding class include module_path pixmap_path im_module_file style widget - widget_class -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'binding class include module_path pixmap_path im_module_file style widget widget_class'))) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, word_match[[ - bg fg base text xthickness ythickness bg_pixmap font fontset font_name stock - color engine -]])) +lex:add_rule('variable', token(lexer.VARIABLE, word_match{ + 'bg', 'fg', 'base', 'text', 'xthickness', 'ythickness', 'bg_pixmap', 'font', 'fontset', + 'font_name', 'stock', 'color', 'engine' +})) -- States. -lex:add_rule('state', token('state', word_match[[ - ACTIVE SELECTED NORMAL PRELIGHT INSENSITIVE TRUE FALSE -]])) -lex:add_style('state', lexer.STYLE_CONSTANT) +lex:add_rule('state', + token('state', word_match('ACTIVE SELECTED NORMAL PRELIGHT INSENSITIVE TRUE FALSE'))) +lex:add_style('state', lexer.styles.constant) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - mix shade lighter darker -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match('mix shade lighter darker'))) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * - (lexer.alnum + S('_-'))^0)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('_-'))^0)) -- Strings. local sq_str = lexer.range("'", true) @@ -47,14 +41,13 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.digit^1 * - ('.' * lexer.digit^1)^-1)) +lex:add_rule('number', token(lexer.NUMBER, lexer.digit^1 * ('.' * lexer.digit^1)^-1)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S(':=,*()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/haskell.lua b/syntaxhighlight/textadept/haskell.lua index 90db20f..a80e624 100644 --- a/syntaxhighlight/textadept/haskell.lua +++ b/syntaxhighlight/textadept/haskell.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Haskell LPeg lexer. -- Modified by Alex Suraci. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('haskell', {fold_by_indentation = true}) @@ -13,17 +13,16 @@ local lex = lexer.new('haskell', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - case class data default deriving do else if import in infix infixl infixr - instance let module newtype of then type where _ as qualified hiding -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'case', 'class', 'data', 'default', 'deriving', 'do', 'else', 'if', 'import', 'in', 'infix', + 'infixl', 'infixr', 'instance', 'let', 'module', 'newtype', 'of', 'then', 'type', 'where', '_', + 'as', 'qualified', 'hiding' +})) +-- Types & type constructors. local word = (lexer.alnum + S("._'#"))^0 local op = lexer.punct - S('()[]{}') - --- Types & type constructors. -lex:add_rule('type', token(lexer.TYPE, (lexer.upper * word) + - (":" * (op^1 - ":")))) +lex:add_rule('type', token(lexer.TYPE, (lexer.upper * word) + (':' * (op^1 - ':')))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * word)) diff --git a/syntaxhighlight/textadept/html.lua b/syntaxhighlight/textadept/html.lua index abe6942..dc7a7c2 100644 --- a/syntaxhighlight/textadept/html.lua +++ b/syntaxhighlight/textadept/html.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- HTML LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('html') @@ -16,58 +16,61 @@ lex:add_rule('whitespace', ws) lex:add_rule('comment', token(lexer.COMMENT, lexer.range(''))) -- Doctype. -lex:add_rule('doctype', token('doctype', - lexer.range(''))) -lex:add_style('doctype', lexer.STYLE_COMMENT) +lex:add_rule('doctype', token('doctype', lexer.range(''))) +lex:add_style('doctype', lexer.styles.comment) -- Elements. -local single_element = token('single_element', '<' * P('/')^-1 * word_match([[ - area base br col command embed hr img input keygen link meta param source - track wbr -]], true)) -local paired_element = token('element', '<' * P('/')^-1 * word_match([[ - a abbr address article aside audio b bdi bdo blockquote body button canvas - caption cite code colgroup content data datalist dd decorator del details - dfn div dl dt element em fieldset figcaption figure footer form h1 h2 h3 h4 - h5 h6 head header html i iframe ins kbd label legend li main map mark menu - menuitem meter nav noscript object ol optgroup option output p pre progress - q rp rt ruby s samp script section select shadow small spacer span strong - style sub summary sup table tbody td template textarea tfoot th thead time - title tr u ul var video -]], true)) +local single_element = token('single_element', '<' * P('/')^-1 * word_match( + { + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', + 'param', 'source', 'track', 'wbr' + }, true)) +local paired_element = token('element', '<' * P('/')^-1 * word_match({ + 'a', 'abbr', 'address', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'blockquote', 'body', + 'button', 'canvas', 'caption', 'cite', 'code', 'colgroup', 'content', 'data', 'datalist', 'dd', + 'decorator', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', + 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', + 'html', 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'menu', + 'menuitem', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', + 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', + 'small', 'spacer', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', + 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'u', 'ul', 'var', 'video' +}, true)) local known_element = single_element + paired_element -local unknown_element = token('unknown_element', '<' * P('/')^-1 * - (lexer.alnum + '-')^1) -local element = known_element + unknown_element +local unknown_element = token('unknown_element', '<' * P('/')^-1 * (lexer.alnum + '-')^1) +local element = (known_element + unknown_element) * -P(':') lex:add_rule('element', element) -lex:add_style('single_element', lexer.STYLE_KEYWORD) -lex:add_style('element', lexer.STYLE_KEYWORD) -lex:add_style('unknown_element', lexer.STYLE_KEYWORD .. ',italics') +lex:add_style('single_element', lexer.styles.keyword) +lex:add_style('element', lexer.styles.keyword) +lex:add_style('unknown_element', lexer.styles.keyword .. {italics = true}) -- Closing tags. local tag_close = token('element', P('/')^-1 * '>') lex:add_rule('tag_close', tag_close) -- Attributes. -local known_attribute = token('attribute', word_match([[ - accept accept-charset accesskey action align alt async autocomplete autofocus - autoplay bgcolor border buffered challenge charset checked cite class code - codebase color cols colspan content contenteditable contextmenu controls - coords data data- datetime default defer dir dirname disabled download - draggable dropzone enctype for form headers height hidden high href hreflang - http-equiv icon id ismap itemprop keytype kind label lang language list loop - low manifest max maxlength media method min multiple name novalidate open - optimum pattern ping placeholder poster preload pubdate radiogroup readonly - rel required reversed role rows rowspan sandbox scope scoped seamless selected - shape size sizes span spellcheck src srcdoc srclang start step style summary - tabindex target title type usemap value width wrap -]], true) + ((P('data-') + 'aria-') * (lexer.alnum + '-')^1)) +local known_attribute = token('attribute', word_match({ + 'accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'async', 'autocomplete', + 'autofocus', 'autoplay', 'bgcolor', 'border', 'buffered', 'challenge', 'charset', 'checked', + 'cite', 'class', 'code', 'codebase', 'color', 'cols', 'colspan', 'content', 'contenteditable', + 'contextmenu', 'controls', 'coords', 'data', 'data-', 'datetime', 'default', 'defer', 'dir', + 'dirname', 'disabled', 'download', 'draggable', 'dropzone', 'enctype', 'for', 'form', 'headers', + 'height', 'hidden', 'high', 'href', 'hreflang', 'http-equiv', 'icon', 'id', 'ismap', 'itemprop', + 'keytype', 'kind', 'label', 'lang', 'language', 'list', 'loop', 'low', 'manifest', 'max', + 'maxlength', 'media', 'method', 'min', 'multiple', 'name', 'novalidate', 'open', 'optimum', + 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', + 'required', 'reversed', 'role', 'rows', 'rowspan', 'sandbox', 'scope', 'scoped', 'seamless', + 'selected', 'shape', 'size', 'sizes', 'span', 'spellcheck', 'src', 'srcdoc', 'srclang', 'start', + 'step', 'style', 'summary', 'tabindppex', 'target', 'title', 'type', 'usemap', 'value', 'width', + 'wrap' +}, true) + ((P('data-') + 'aria-') * (lexer.alnum + '-')^1)) local unknown_attribute = token('unknown_attribute', (lexer.alnum + '-')^1) local attribute = (known_attribute + unknown_attribute) * #(lexer.space^0 * '=') lex:add_rule('attribute', attribute) -lex:add_style('attribute', lexer.STYLE_TYPE) -lex:add_style('unknown_attribute', lexer.STYLE_TYPE .. ',italics') +lex:add_style('attribute', lexer.styles.type) +lex:add_style('unknown_attribute', lexer.styles.type .. {italics = true}) +-- Equals. -- TODO: performance is terrible on large files. local in_tag = P(function(input, index) local before = input:sub(1, index - 1) @@ -77,9 +80,8 @@ local in_tag = P(function(input, index) return input:find('^[^<]->', index) and index or nil end) --- Equals. -local equals = token(lexer.OPERATOR, '=') --* in_tag ---lex:add_rule('equals', equals) +local equals = token(lexer.OPERATOR, '=') -- * in_tag +-- lex:add_rule('equals', equals) -- Strings. local string = #S('\'"') * lexer.last_char_includes('=') * @@ -87,13 +89,12 @@ local string = #S('\'"') * lexer.last_char_includes('=') * lex:add_rule('string', string) -- Numbers. -lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * - token(lexer.NUMBER, lexer.digit^1 * P('%')^-1))--*in_tag) +local number = token(lexer.NUMBER, lexer.dec_num * P('%')^-1) +lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * number) -- *in_tag) -- Entities. -lex:add_rule('entity', token('entity', '&' * (lexer.any - lexer.space - ';')^1 * - ';')) -lex:add_style('entity', lexer.STYLE_COMMENT) +lex:add_rule('entity', token('entity', '&' * (lexer.any - lexer.space - ';')^1 * ';')) +lex:add_style('entity', lexer.styles.comment) -- Fold points. local function disambiguate_lt(text, pos, line, s) @@ -111,43 +112,36 @@ lex:add_fold_point(lexer.COMMENT, '') -- Tags that start embedded languages. -- Export these patterns for proxy lexers (e.g. ASP) that need them. -lex.embed_start_tag = element * - (ws * attribute * ws^-1 * equals * ws^-1 * string)^0 * ws^-1 * tag_close +lex.embed_start_tag = element * (ws * attribute * ws^-1 * equals * ws^-1 * string)^0 * ws^-1 * + tag_close lex.embed_end_tag = element * tag_close -- Embedded CSS (). local css = lexer.load('css') -local style_element = word_match([[style]], true) +local style_element = word_match('style', true) local css_start_rule = #('<' * style_element * ('>' + P(function(input, index) - if input:find('^%s+type%s*=%s*(["\'])text/css%1', index) then - return index - end + if input:find('^%s+type%s*=%s*(["\'])text/css%1', index) then return index end end))) * lex.embed_start_tag local css_end_rule = #('') * lex.embed_end_tag lex:embed(css, css_start_rule, css_end_rule) -- Embedded JavaScript (). local js = lexer.load('javascript') -local script_element = word_match([[script]], true) +local script_element = word_match('script', true) local js_start_rule = #('<' * script_element * ('>' + P(function(input, index) - if input:find('^%s+type%s*=%s*(["\'])text/javascript%1', index) then - return index - end + if input:find('^%s+type%s*=%s*(["\'])text/javascript%1', index) then return index end end))) * lex.embed_start_tag local js_end_rule = #('') * lex.embed_end_tag -local js_line_comment = '//' * (lexer.nonnewline_esc - js_end_rule)^0 +local js_line_comment = '//' * (lexer.nonnewline - js_end_rule)^0 local js_block_comment = '/*' * (lexer.any - '*/' - js_end_rule)^0 * P('*/')^-1 -js:modify_rule('comment', token(lexer.COMMENT, js_line_comment + - js_block_comment)) +js:modify_rule('comment', token(lexer.COMMENT, js_line_comment + js_block_comment)) lex:embed(js, js_start_rule, js_end_rule) -- Embedded CoffeeScript (). local cs = lexer.load('coffeescript') -local script_element = word_match([[script]], true) +script_element = word_match('script', true) local cs_start_rule = #('<' * script_element * P(function(input, index) - if input:find('^[^>]+type%s*=%s*(["\'])text/coffeescript%1', index) then - return index - end + if input:find('^[^>]+type%s*=%s*(["\'])text/coffeescript%1', index) then return index end end)) * lex.embed_start_tag local cs_end_rule = #('') * lex.embed_end_tag lex:embed(cs, cs_start_rule, cs_end_rule) diff --git a/syntaxhighlight/textadept/icon.lua b/syntaxhighlight/textadept/icon.lua index d5fe98e..91d8cec 100644 --- a/syntaxhighlight/textadept/icon.lua +++ b/syntaxhighlight/textadept/icon.lua @@ -1,12 +1,12 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- LPeg lexer for the Icon programming language. -- http://www.cs.arizona.edu/icon -- Contributed by Carl Sturtivant. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('icon') @@ -14,20 +14,21 @@ local lex = lexer.new('icon') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break by case create default do else end every fail global if initial - invocable link local next not of procedure record repeat return static suspend - then to until while -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'by', 'case', 'create', 'default', 'do', 'else', 'end', 'every', 'fail', 'global', 'if', + 'initial', 'invocable', 'link', 'local', 'next', 'not', 'of', 'procedure', 'record', 'repeat', + 'return', 'static', 'suspend', 'then', 'to', 'until', 'while' +})) -- Icon Keywords: unique to Icon. -lex:add_rule('special_keyword', token('special_keyword', P('&') * word_match[[ - allocated ascii clock collections cset current date dateline digits dump e - error errornumber errortext errorvalue errout fail features file host input - lcase letters level line main null output phi pi pos progname random regions - source storage subject time trace ucase version -]])) -lex:add_style('special_keyword', lexer.STYLE_TYPE) +lex:add_rule('special_keyword', token('special_keyword', '&' * word_match{ + 'allocated', 'ascii', 'clock', 'collections', 'cset', 'current', 'date', 'dateline', 'digits', + 'dump', 'e', 'error', 'errornumber', 'errortext', 'errorvalue', 'errout', 'fail', 'features', + 'file', 'host', 'input', 'lcase', 'letters', 'level', 'line', 'main', 'null', 'output', 'phi', + 'pi', 'pos', 'progname', 'random', 'regions', 'source', 'storage', 'subject', 'time', 'trace', + 'ucase', 'version' +})) +lex:add_style('special_keyword', lexer.styles.type) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -45,10 +46,8 @@ local radix_literal = P('-')^-1 * lexer.dec_num * S('rR') * lexer.alnum^1 lex:add_rule('number', token(lexer.NUMBER, radix_literal + lexer.number)) -- Preprocessor. -local preproc_word = word_match[[ - define else endif error ifdef ifndef include line undef -]] -lex:add_rule('preproc', token(lexer.PREPROCESSOR, P('$') * preproc_word)) +lex:add_rule('preproc', token(lexer.PREPROCESSOR, '$' * + word_match('define else endif error ifdef ifndef include line undef'))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~@:;,.()[]{}'))) @@ -57,6 +56,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~@:;,.()[]{}'))) lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif') lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif') lex:add_fold_point(lexer.KEYWORD, 'procedure', 'end') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/idl.lua b/syntaxhighlight/textadept/idl.lua index 280f94c..4671ac1 100644 --- a/syntaxhighlight/textadept/idl.lua +++ b/syntaxhighlight/textadept/idl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- IDL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('idl') @@ -12,17 +12,18 @@ local lex = lexer.new('idl') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract attribute case const context custom default enum exception factory - FALSE in inout interface local module native oneway out private public raises - readonly struct support switch TRUE truncatable typedef union valuetype -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'attribute', 'case', 'const', 'context', 'custom', 'default', 'enum', 'exception', + 'factory', 'FALSE', 'in', 'inout', 'interface', 'local', 'module', 'native', 'oneway', 'out', + 'private', 'public', 'raises', 'readonly', 'struct', 'support', 'switch', 'TRUE', 'truncatable', + 'typedef', 'union', 'valuetype' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - any boolean char double fixed float long Object octet sequence short string - unsigned ValueBase void wchar wstring -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'any', 'boolean', 'char', 'double', 'fixed', 'float', 'long', 'Object', 'octet', 'sequence', + 'short', 'string', 'unsigned', 'ValueBase', 'void', 'wchar', 'wstring' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -41,11 +42,8 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Preprocessor. -local preproc_word = word_match[[ - define undef ifdef ifndef if elif else endif include warning pragma -]] lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * - preproc_word)) + word_match('define undef ifdef ifndef if elif else endif include warning pragma'))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!<>=+-/*%&|^~.,:;?()[]{}'))) diff --git a/syntaxhighlight/textadept/inform.lua b/syntaxhighlight/textadept/inform.lua index 607a8c7..ad29061 100644 --- a/syntaxhighlight/textadept/inform.lua +++ b/syntaxhighlight/textadept/inform.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2010-2020 Jeff Stone. See License.txt. --- Inform LPeg lexer for Scintilla. +-- Copyright 2010-2021 Jeff Stone. See LICENSE. +-- Inform LPeg lexer for Scintillua. -- JMS 2010-04-25. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('inform') @@ -13,43 +13,46 @@ local lex = lexer.new('inform') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - Abbreviate Array Attribute Class Constant Default End Endif Extend Global - Ifdef Iffalse Ifndef Ifnot Iftrue Import Include Link Lowstring Message Object - Property Release Replace Serial StartDaemon Statusline StopDaemon Switches - Verb - absent action actor add_to_scope address additive after and animate article - articles before bold box break cant_go capacity char class child children - clothing concealed container continue creature daemon deadflag default - describe description do door door_dir door_to d_to d_obj e_to e_obj each_turn - edible else enterable false female first font for found_in general give - grammar has hasnt held if in in_to in_obj initial inside_description invent - jump last life light list_together location lockable locked male move moved - multi multiexcept multiheld multiinside n_to n_obj ne_to ne_obj nw_to nw_obj - name neuter new_line nothing notin noun number objectloop ofclass off on only - open openable or orders out_to out_obj parent parse_name player plural - pluralname print print_ret private proper provides random react_after - react_before remove replace return reverse rfalseroman rtrue s_to s_obj se_to - se_obj sw_to sw_obj scenery scope score scored second self short_name - short_name_indef sibling spaces static string style supporter switch - switchable talkable thedark time_left time_out to topic transparent true - underline u_to u_obj visited w_to w_obj when_closed when_off when_on when_open - while with with_key workflag worn -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'Abbreviate', 'Array', 'Attribute', 'Class', 'Constant', 'Default', 'End', 'Endif', 'Extend', + 'Global', 'Ifdef', 'Iffalse', 'Ifndef', 'Ifnot', 'Iftrue', 'Import', 'Include', 'Link', + 'Lowstring', 'Message', 'Object', 'Property', 'Release', 'Replace', 'Serial', 'StartDaemon', + 'Statusline', 'StopDaemon', 'Switches', 'Verb', -- + 'absent', 'action', 'actor', 'add_to_scope', 'address', 'additive', 'after', 'and', 'animate', + 'article', 'articles', 'before', 'bold', 'box', 'break', 'cant_go', 'capacity', 'char', 'class', + 'child', 'children', 'clothing', 'concealed', 'container', 'continue', 'creature', 'daemon', + 'deadflag', 'default', 'describe', 'description', 'do', 'door', 'door_dir', 'door_to', 'd_to', + 'd_obj', 'e_to', 'e_obj', 'each_turn', 'edible', 'else', 'enterable', 'false', 'female', 'first', + 'font', 'for', 'found_in', 'general', 'give', 'grammar', 'has', 'hasnt', 'held', 'if', 'in', + 'in_to', 'in_obj', 'initial', 'inside_description', 'invent', 'jump', 'last', 'life', 'light', + 'list_together', 'location', 'lockable', 'locked', 'male', 'move', 'moved', 'multi', + 'multiexcept', 'multiheld', 'multiinside', 'n_to', 'n_obj', 'ne_to', 'ne_obj', 'nw_to', 'nw_obj', + 'name', 'neuter', 'new_line', 'nothing', 'notin', 'noun', 'number', 'objectloop', 'ofclass', + 'off', 'on', 'only', 'open', 'openable', 'or', 'orders', 'out_to', 'out_obj', 'parent', + 'parse_name', 'player', 'plural', 'pluralname', 'print', 'print_ret', 'private', 'proper', + 'provides', 'random', 'react_after', 'react_before', 'remove', 'replace', 'return', 'reverse', + 'rfalseroman', 'rtrue', 's_to', 's_obj', 'se_to', 'se_obj', 'sw_to', 'sw_obj', 'scenery', 'scope', + 'score', 'scored', 'second', 'self', 'short_name', 'short_name_indef', 'sibling', 'spaces', + 'static', 'string', 'style', 'supporter', 'switch', 'switchable', 'talkable', 'thedark', + 'time_left', 'time_out', 'to', 'topic', 'transparent', 'true', 'underline', 'u_to', 'u_obj', + 'visited', 'w_to', 'w_obj', 'when_closed', 'when_off', 'when_on', 'when_open', 'while', 'with', + 'with_key', 'workflag', 'worn' +})) -- Library actions. -lex:add_rule('action', token('action', word_match[[ - Answer Ask AskFor Attack Blow Burn Buy Climb Close Consult Cut Dig Disrobe - Drink Drop Eat Empty EmptyT Enter Examine Exit Fill FullScore GetOff Give Go - GoIn Insert Inv InvTall InvWide Jump JumpOver Kiss LetGo Listen LMode1 LMode2 - LMode3 Lock Look LookUnder Mild No NotifyOff NotifyOn Objects Open Order - Places Pray Pronouns Pull Push PushDir PutOn Quit Receive Remove Restart - Restore Rub Save Score ScriptOff ScriptOn Search Set SetTo Show Sing Sleep - Smell Sorry Squeeze Strong Swim Swing SwitchOff SwitchOn Take Taste Tell Think - ThrowAt ThrownAt Tie Touch Transfer Turn Unlock VagueGo Verify Version Wait - Wake WakeOther Wave WaveHands Wear Yes -]])) -lex:add_style('action', lexer.STYLE_VARIABLE) +lex:add_rule('action', token('action', word_match{ + 'Answer', 'Ask', 'AskFor', 'Attack', 'Blow', 'Burn', 'Buy', 'Climb', 'Close', 'Consult', 'Cut', + 'Dig', 'Disrobe', 'Drink', 'Drop', 'Eat', 'Empty', 'EmptyT', 'Enter', 'Examine', 'Exit', 'Fill', + 'FullScore', 'GetOff', 'Give', 'Go', 'GoIn', 'Insert', 'Inv', 'InvTall', 'InvWide', 'Jump', + 'JumpOver', 'Kiss', 'LetGo', 'Listen', 'LMode1', 'LMode2', 'LMode3', 'Lock', 'Look', 'LookUnder', + 'Mild', 'No', 'NotifyOff', 'NotifyOn', 'Objects', 'Open', 'Order', 'Places', 'Pray', 'Pronouns', + 'Pull', 'Push', 'PushDir', 'PutOn', 'Quit', 'Receive', 'Remove', 'Restart', 'Restore', 'Rub', + 'Save', 'Score', 'ScriptOff', 'ScriptOn', 'Search', 'Set', 'SetTo', 'Show', 'Sing', 'Sleep', + 'Smell', 'Sorry', 'Squeeze', 'Strong', 'Swim', 'Swing', 'SwitchOff', 'SwitchOn', 'Take', 'Taste', + 'Tell', 'Think', 'ThrowAt', 'ThrownAt', 'Tie', 'Touch', 'Transfer', 'Turn', 'Unlock', 'VagueGo', + 'Verify', 'Version', 'Wait', 'Wake', 'WakeOther', 'Wave', 'WaveHands', 'Wear', 'Yes' +})) +lex:add_style('action', lexer.styles.variable) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -65,8 +68,7 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('!'))) -- Numbers. local inform_hex = '$' * lexer.xdigit^1 local inform_bin = '$$' * S('01')^1 -lex:add_rule('number', token(lexer.NUMBER, lexer.integer + inform_hex + - inform_bin)) +lex:add_rule('number', token(lexer.NUMBER, lexer.integer + inform_hex + inform_bin)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('@~=+-*/%^#=<>;:,.{}[]()&|?'))) diff --git a/syntaxhighlight/textadept/ini.lua b/syntaxhighlight/textadept/ini.lua index 5e59945..898856c 100644 --- a/syntaxhighlight/textadept/ini.lua +++ b/syntaxhighlight/textadept/ini.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Ini LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ini') @@ -12,13 +12,10 @@ local lex = lexer.new('ini') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - true false on off yes no -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match('true false on off yes no'))) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * - (lexer.alnum + S('_.'))^0)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0)) -- Strings. local sq_str = lexer.range("'") @@ -29,8 +26,7 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) lex:add_rule('label', token(lexer.LABEL, lexer.range('[', ']', true))) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, - lexer.to_eol(lexer.starts_line(S(';#'))))) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol(lexer.starts_line(S(';#'))))) -- Numbers. local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 diff --git a/syntaxhighlight/textadept/io_lang.lua b/syntaxhighlight/textadept/io_lang.lua index 62f5523..d39b5b6 100644 --- a/syntaxhighlight/textadept/io_lang.lua +++ b/syntaxhighlight/textadept/io_lang.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Io LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('io_lang') @@ -12,16 +12,16 @@ local lex = lexer.new('io_lang') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - block method while foreach if else do super self clone proto setSlot hasSlot - type write print forward -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'block', 'method', 'while', 'foreach', 'if', 'else', 'do', 'super', 'self', 'clone', 'proto', + 'setSlot', 'hasSlot', 'type', 'write', 'print', 'forward' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - Block Buffer CFunction Date Duration File Future LinkedList List Map Message - Nil Nop Number Object String WeakLink -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'Block', 'Buffer', 'CFunction', 'Date', 'Duration', 'File', 'Future', 'LinkedList', 'List', 'Map', + 'Message', 'Nil', 'Nop', 'Number', 'Object', 'String', 'WeakLink' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -41,12 +41,11 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('`~@$%^&*-+/=\\<>?.,:;()[]{}'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('`~@$%^&*-+/=\\<>?.,:;()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/java.lua b/syntaxhighlight/textadept/java.lua index 48578ec..2ea52c9 100644 --- a/syntaxhighlight/textadept/java.lua +++ b/syntaxhighlight/textadept/java.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Java LPeg lexer. -- Modified by Brian Schott. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('java') @@ -14,24 +14,24 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Classes. -lex:add_rule('classdef', token(lexer.KEYWORD, P('class')) * ws * - token(lexer.CLASS, lexer.word)) +lex:add_rule('classdef', token(lexer.KEYWORD, 'class') * ws * token(lexer.CLASS, lexer.word)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract assert break case catch class const continue default do else enum - extends final finally for goto if implements import instanceof interface - native new package private protected public return static strictfp super - switch synchronized this throw throws transient try while volatile +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do', + 'else', 'enum', 'extends', 'final', 'finally', 'for', 'goto', 'if', 'implements', 'import', + 'instanceof', 'interface', 'native', 'new', 'package', 'private', 'protected', 'public', 'return', + 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', + 'try', 'while', 'volatile', -- Literals. - true false null -]])) + 'true', 'false', 'null' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - boolean byte char double float int long short void - Boolean Byte Character Double Float Integer Long Short String -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'boolean', 'byte', 'char', 'double', 'float', 'int', 'long', 'short', 'void', 'Boolean', 'Byte', + 'Character', 'Double', 'Float', 'Integer', 'Long', 'Short', 'String' +})) -- Functions. lex:add_rule('function', token(lexer.FUNCTION, lexer.word) * #P('(')) @@ -54,7 +54,7 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlFfDd')^-1)) -- Annotations. lex:add_rule('annotation', token('annotation', '@' * lexer.word)) -lex:add_style('annotation', lexer.STYLE_PREPROCESSOR) +lex:add_style('annotation', lexer.styles.preprocessor) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) @@ -62,6 +62,7 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +lex:add_fold_point(lexer.KEYWORD, lexer.fold_consecutive_lines('import')) return lex diff --git a/syntaxhighlight/textadept/javascript.lua b/syntaxhighlight/textadept/javascript.lua index 0ca5273..fcb8e59 100644 --- a/syntaxhighlight/textadept/javascript.lua +++ b/syntaxhighlight/textadept/javascript.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- JavaScript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('javascript') @@ -12,14 +12,52 @@ local lex = lexer.new('javascript') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract boolean break byte case catch char class const continue debugger - default delete do double else enum export extends false final finally float - for function get goto if implements import in instanceof int interface let - long native new null of package private protected public return set short - static super switch synchronized this throw throws transient true try typeof - var void volatile while with yield -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'async', 'await', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', + 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else', 'enum', 'export', + 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'get', 'goto', 'if', + 'implements', 'import', 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new', + 'null', 'of', 'package', 'private', 'protected', 'public', 'return', 'set', 'short', 'static', + 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', + 'typeof', 'var', 'void', 'volatile', 'while', 'with', 'yield' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match{ + -- Fundamental objects. + 'Object', 'Function', 'Boolean', 'Symbol', + -- Error Objects. + 'Error', 'AggregateError', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', + 'SyntaxError', 'TypeError', 'URIError', + -- Numbers and dates. + 'Number', 'BigInt', 'Math', 'Date', + -- Text Processing. + 'String', 'RegExp', + -- Indexed collections. + 'Array', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', + 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array', + -- Keyed collections. + 'Map', 'Set', 'WeakMap', 'WeakSet', + -- Structured data. + 'ArrayBuffer', 'SharedArrayBuffer', 'Atomics', 'DataView', 'JSON', + -- Control abstraction objects. + 'GeneratorFunction', 'AsyncGeneratorFunction', 'Generator', 'AsyncGenerator', 'AsyncFunction', + 'Promise', + -- Reflection. + 'Reflect', 'Proxy', + -- Other. + 'Intl', 'WebAssembly' +})) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', + 'encodeURI', 'encodeURIComponent' +})) + +-- Constants. +lex:add_rule('constant', + token(lexer.CONSTANT, word_match('Infinity NaN undefined globalThis arguments'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -34,8 +72,8 @@ local sq_str = lexer.range("'") local dq_str = lexer.range('"') local bq_str = lexer.range('`') local string = token(lexer.STRING, sq_str + dq_str + bq_str) -local regex_str = #P('/') * lexer.last_char_includes('+-*%^!=&|?:;,([{<>') * - lexer.range('/', true) * S('igm')^0 +local regex_str = + #P('/') * lexer.last_char_includes('+-*%^!=&|?:;,([{<>') * lexer.range('/', true) * S('igm')^0 local regex = token(lexer.REGEX, regex_str) lex:add_rule('string', string + regex) @@ -48,6 +86,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%^!=&|?:;,.()[]{}<>'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/jq.lua b/syntaxhighlight/textadept/jq.lua new file mode 100644 index 0000000..cade43a --- /dev/null +++ b/syntaxhighlight/textadept/jq.lua @@ -0,0 +1,84 @@ +local lpeg = require('lpeg') +-- Copyright 2006-2021 Mitchell. See LICENSE. +-- jq 1.6 Lua lexer -- https://stedolan.github.io/jq/wiki +-- Anonymously contributed. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('jq') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- keywords not listed by jq's "builtins", minus operators 'and' and 'or', plus the '?' shorthand + 'as', 'break', 'catch', 'def', 'elif', 'else', 'end', 'foreach', 'if', 'import', 'include', + 'label', 'module', 'reduce', 'then', 'try' +} + '?')) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + -- jq 1.6 built-in functions (SQL in upper caisse) + 'acos', 'acosh', 'add', 'all', 'any', 'arrays', 'ascii_downcase', 'ascii_upcase', 'asin', 'asinh', + 'atan', 'atan2', 'atanh', 'booleans', 'bsearch', 'builtins', 'capture', 'cbrt', 'ceil', + 'combinations', 'contains', 'copysign', 'cos', 'cosh', 'debug', 'del', 'delpaths', 'drem', + 'empty', 'endswith', 'env', 'erf', 'erfc', 'error', 'exp', 'exp10', 'exp2', 'explode', 'expm1', + 'fabs', 'fdim', 'finites', 'first', 'flatten', 'floor', 'fma', 'fmax', 'fmin', 'fmod', 'format', + 'frexp', 'from_entries', 'fromdate', 'fromdateiso8601', 'fromjson', 'fromstream', 'gamma', + 'get_jq_origin', 'get_prog_origin', 'get_search_list', 'getpath', 'gmtime', 'group_by', 'gsub', + 'halt', 'halt_error', 'has', 'hypot', 'implode', 'IN', 'in', 'INDEX', 'index', 'indices', + 'infinite', 'input', 'input_filename', 'input_line_number', 'inputs', 'inside', 'isempty', + 'isfinite', 'isinfinite', 'isnan', 'isnormal', 'iterables', 'j0', 'j1', 'jn', 'JOIN', 'join', + 'keys', 'keys_unsorted', 'last', 'ldexp', 'leaf_paths', 'length', 'lgamma', 'lgamma_r', 'limit', + 'localtime', 'log', 'log10', 'log1p', 'log2', 'logb', 'ltrimstr', 'map', 'map_values', 'match', + 'max', 'max_by', 'min', 'min_by', 'mktime', 'modf', 'modulemeta', 'nan', 'nearbyint', 'nextafter', + 'nexttoward', 'normals', 'not', 'now', 'nth', 'nulls', 'numbers', 'objects', 'path', 'paths', + 'pow', 'pow10', 'range', 'recurse', 'recurse_down', 'remainder', 'repeat', 'reverse', 'rindex', + 'rint', 'round', 'rtrimstr', 'scalars', 'scalars_or_empty', 'scalb', 'scalbln', 'scan', 'select', + 'setpath', 'significand', 'sin', 'sinh', 'sort', 'sort_by', 'split', 'splits', 'sqrt', + 'startswith', 'stderr', 'strflocaltime', 'strftime', 'strings', 'strptime', 'sub', 'tan', 'tanh', + 'test', 'tgamma', 'to_entries', 'todate', 'todateiso8601', 'tojson', 'tonumber', 'tostream', + 'tostring', 'transpose', 'trunc', 'truncate_stream', 'type', 'unique', 'unique_by', 'until', + 'utf8bytelength', 'values', 'walk', 'while', 'with_entries', 'y0', 'y1', 'yn' +})) + +-- Strings. +local string = token(lexer.STRING, lexer.range('"', true)) +local literal = token(lexer.STRING, word_match('null false true')) +lex:add_rule('string', string + literal) + +-- Operators. +-- 'not' isn't an operator but a function (filter) +lex:add_rule('operator', token(lexer.OPERATOR, + P('.[]') + '?//' + '//=' + 'and' + '[]' + '//' + '==' + '!=' + '>=' + '<=' + '|=' + '+=' + '-=' + + '*=' + '/=' + '%=' + 'or' + S('=+-*/%<>()[]{}.,') + '|' + ';')) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Formats. +lex:add_rule('format', + token('format', '@' * word_match('text json html uri csv tsv sh base64 base64d'))) +lex:add_style('format', lexer.styles.constant) + +-- Variables. +lex:add_rule('sysvar', token('sysvar', '$' * word_match('ENV ORIGIN __loc__'))) +lex:add_style('sysvar', lexer.styles.constant .. {bold = true}) +lex:add_rule('variable', token(lexer.VARIABLE, '$' * lexer.word)) + +-- Fold points. +lex:add_fold_point(lexer.KEYWORD, 'if', 'end') +lex:add_fold_point(lexer.OPERATOR, '[', ']') +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) + +return lex diff --git a/syntaxhighlight/textadept/json.lua b/syntaxhighlight/textadept/json.lua index 010bc55..605c654 100644 --- a/syntaxhighlight/textadept/json.lua +++ b/syntaxhighlight/textadept/json.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Brian "Sir Alaran" Schott. See License.txt. +-- Copyright 2006-2021 Brian "Sir Alaran" Schott. See LICENSE. -- JSON LPeg lexer. -- Based off of lexer code by Mitchell. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('json') @@ -18,7 +18,7 @@ local dq_str = lexer.range('"', true) lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[true false null]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match('true false null'))) -- Comments. local line_comment = lexer.to_eol('//', true) @@ -26,7 +26,7 @@ local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -local integer = S('+-')^-1 * lexer.digit^1 * S('Ll')^-1 +local integer = S('+-')^-1 * lexer.dec_num * S('Ll')^-1 lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) -- Operators. @@ -36,6 +36,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('[]{}:,'))) lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/jsp.lua b/syntaxhighlight/textadept/jsp.lua index 969bdc0..26d177d 100644 --- a/syntaxhighlight/textadept/jsp.lua +++ b/syntaxhighlight/textadept/jsp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- JSP LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('jsp', {inherit = lexer.load('html')}) @@ -13,7 +13,7 @@ local java = lexer.load('java') local java_start_rule = token('jsp_tag', '<%' * P('=')^-1) local java_end_rule = token('jsp_tag', '%>') lex:embed(java, java_start_rule, java_end_rule, true) -lex:add_style('jsp_tag', lexer.STYLE_EMBEDDED) +lex:add_style('jsp_tag', lexer.styles.embedded) -- Fold points. lex:add_fold_point('jsp_tag', '<%', '%>') diff --git a/syntaxhighlight/textadept/julia.lua b/syntaxhighlight/textadept/julia.lua new file mode 100644 index 0000000..4b959a5 --- /dev/null +++ b/syntaxhighlight/textadept/julia.lua @@ -0,0 +1,111 @@ +local lpeg = require('lpeg') +-- Copyright 2020-2021 Tobias Frilling. See LICENSE. +-- Julia lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local B, P, S = lpeg.B, lpeg.P, lpeg.S + +local lex = lexer.new('julia') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +local id = lexer.word * P('!')^0 + +-- Keyword +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'baremodule', 'begin', 'break', 'catch', 'const', 'continue', 'do', 'else', 'elseif', 'end', + 'export', 'finally', 'for', 'function', 'global', 'if', 'in', 'isa', 'import', 'let', 'local', + 'macro', 'module', 'quote', 'return', 'struct', 'try', 'using', 'where', 'while' +} + 'abstract type' + 'mutable struct' + 'primitive type')) + +-- Constant +local const_bool = word_match('true false') +local const_numerical = (P('Inf') + 'NaN') * (P('16') + '32' + '64')^-1 * -lexer.alnum +local const_special = word_match('nothing undef missing') +local const_env = word_match('ARGS ENV ENDIAN_BOM LOAD_PATH VERSION PROGRAM_FILE DEPOT_PATH') +local const_io = word_match('stdout stdin stderr devnull') +lex:add_rule('constant', token(lexer.CONSTANT, + const_bool + const_numerical + const_special + const_env + const_io)) + +-- Type +local type_annotated = (B('::') + B(':: ')) * id +local type_para = id * #P('{') +local type_subtyping = id * #(lexer.space^0 * '<:') + (B('<:') + B('<: ')) * id +local type_struct = B('struct ') * id +-- LuaFormatter off +local type_builtin_numerical = ((P('Abstract') + 'Big') * 'Float' + + 'Float' * (P('16') + '32' + '64') + + P('U')^-1 * 'Int' * (P('8') + '16' + '32' + '64' + '128')^-1 + + P('Abstract')^-1 * 'Irrational' +) * -lexer.alnum + word_match('Number Complex Real Integer Bool Signed Unsigned Rational') +-- LuaFormatter on +local type_builtin_range = ((P('Lin') + 'Ordinal' + (P('Abstract')^-1 * P('Unit')^-1)) * 'Range' + + 'StepRange' * P('Len')^-1 - 'Range' +) * -lexer.alnum +local type_builtin_array = ((P('Abstract') + 'Bit' + 'Dense' + 'PermutedDims' + 'Sub')^-1 * + word_match('Array Vector Matrix VecOrMat') + + (P('Abstract') + 'Sym' + (P('Unit')^-1 * (P('Lower') + 'Upper')))^-1 * 'Triangular' +) * -lexer.alnum + + word_match('Adjoint Bidiagonal Diagonal Hermitian LQPackedQ Symmetric Transpose UpperHessenberg') +lex:add_rule('type', token(lexer.TYPE, + type_para + type_annotated + type_subtyping + type_struct + type_builtin_numerical + + type_builtin_range + type_builtin_array)) + +-- Macro +lex:add_rule('macro', token('macro', '@' * (id + '.'))) +lex:add_style('macro', lexer.styles.preprocessor) + +-- Symbol +lex:add_rule('symbol', token('symbol', -B(P(':') + '<') * ':' * id)) +lex:add_style('symbol', lexer.styles.constant) + +-- Function +lex:add_rule('function', token(lexer.FUNCTION, id * #(P('.')^-1 * '('))) + +-- Identifier +lex:add_rule('identifier', token(lexer.IDENTIFIER, id)) + +-- Comment +local line_comment = lexer.to_eol('#') +local block_comment = lexer.range('#=', '=#') +lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) + +-- Number +local decimal = lexer.digit^1 * ('_' * lexer.digit^1)^0 +local hex_digits = lexer.xdigit^1 * ('_' * lexer.xdigit^1)^0 +local hexadecimal = '0x' * hex_digits +local binary = '0b' * S('01')^1 * ('_' * S('01')^1)^0 +local integer = binary + hexadecimal + decimal + +local float_dec_coeff = decimal^0 * '.' * decimal + decimal * '.' * decimal^0 +local float_dec_expon = S('eEf') * S('+-')^-1 * lexer.digit^1 +local float_dec = float_dec_coeff * float_dec_expon^-1 + decimal * float_dec_expon + +local float_hex_coeff = '0x' * (hex_digits^0 * '.' * hex_digits + hex_digits * '.' * hex_digits^0) +local float_hex_expon = 'p' * S('+-')^-1 * lexer.digit^1 +local float_hex = float_hex_coeff * float_hex_expon^-1 + hexadecimal * float_hex_expon + +local float = float_dec + float_hex + +local imaginary = (float_dec + decimal) * 'im' + +lex:add_rule('number', + token(lexer.NUMBER, S('+-')^-1 * (imaginary + float + integer) * -lexer.alpha)) + +-- String & Character +local doc_str = lexer.range('"""') +local str = lexer.range('"') +lex:add_rule('string', token(lexer.STRING, doc_str + str)) + +local c_esc = '\\' * S('\\"\'nrbtfav') +local unicode = '\\' * S('uU') * lexer.xdigit^1 +local char = "'" * (lexer.alnum + c_esc + unicode) * "'" +lex:add_rule('character', token('character', char)) +lex:add_style('character', lexer.styles.constant) + +-- Operator +lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/÷<>=!≠≈≤≥%^&|⊻~\\\':?.√'))) + +return lex diff --git a/syntaxhighlight/textadept/latex.lua b/syntaxhighlight/textadept/latex.lua index dc8153e..c31fe64 100644 --- a/syntaxhighlight/textadept/latex.lua +++ b/syntaxhighlight/textadept/latex.lua @@ -1,12 +1,12 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Latex LPeg lexer. -- Modified by Brian Schott. -- Modified by Robert Gieseke. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('latex') @@ -20,36 +20,31 @@ local block_comment = lexer.range('\\begin' * P(' ')^0 * '{comment}', lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Math environments. -local math_word = word_match[[ - align displaymath eqnarray equation gather math multline -]] -local math_begin_end = (P('begin') + P('end')) * P(' ')^0 * - '{' * math_word * P('*')^-1 * '}' +local math_word = word_match('align displaymath eqnarray equation gather math multline') +local math_begin_end = (P('begin') + P('end')) * P(' ')^0 * '{' * math_word * P('*')^-1 * '}' lex:add_rule('math', token('math', '$' + '\\' * (S('[]()') + math_begin_end))) -lex:add_style('math', lexer.STYLE_FUNCTION) +lex:add_style('math', lexer.styles['function']) -- LaTeX environments. -lex:add_rule('environment', token('environment', '\\' * - (P('begin') + P('end')) * P(' ')^0 * '{' * lexer.word * P('*')^-1 * '}')) -lex:add_style('environment', lexer.STYLE_KEYWORD) +lex:add_rule('environment', token('environment', '\\' * (P('begin') + 'end') * P(' ')^0 * '{' * + lexer.word * P('*')^-1 * '}')) +lex:add_style('environment', lexer.styles.keyword) -- Sections. -lex:add_rule('section', token('section', '\\' * word_match[[ - part chapter section subsection subsubsection paragraph subparagraph -]] * P('*')^-1)) -lex:add_style('section', lexer.STYLE_CLASS) +lex:add_rule('section', token('section', '\\' * + word_match('part chapter section subsection subsubsection paragraph subparagraph') * P('*')^-1)) +lex:add_style('section', lexer.styles.class) -- Commands. -lex:add_rule('command', token('command', '\\' * - (lexer.alpha^1 + S('#$&~_^%{}')))) -lex:add_style('command', lexer.STYLE_KEYWORD) +lex:add_rule('command', token('command', '\\' * (lexer.alpha^1 + S('#$&~_^%{}\\')))) +lex:add_style('command', lexer.styles.keyword) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('&#{}[]'))) -- Fold points. lex:add_fold_point(lexer.COMMENT, '\\begin', '\\end') -lex:add_fold_point(lexer.COMMENT, '%', lexer.fold_line_comments('%')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%')) lex:add_fold_point('environment', '\\begin', '\\end') lex:add_fold_point(lexer.OPERATOR, '{', '}') diff --git a/syntaxhighlight/textadept/ledger.lua b/syntaxhighlight/textadept/ledger.lua index 5492f12..4688ccf 100644 --- a/syntaxhighlight/textadept/ledger.lua +++ b/syntaxhighlight/textadept/ledger.lua @@ -1,18 +1,17 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Charles Lehner. See License.txt. +-- Copyright 2015-2021 Charles Lehner. See LICENSE. -- ledger journal LPeg lexer, see http://www.ledger-cli.org/ local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ledger', {lex_by_line = true}) local delim = P('\t') + P(' ') -- Account. -lex:add_rule('account', token(lexer.VARIABLE, lexer.starts_line(S(' \t')^1 * - (lexer.print - delim)^1))) +lex:add_rule('account', token(lexer.VARIABLE, lexer.starts_line(S(' \t')^1 * lexer.graph^1))) -- Amount. lex:add_rule('amount', token(lexer.NUMBER, delim * (1 - S(';\r\n'))^1)) @@ -30,19 +29,16 @@ local label = lexer.range('[', ']', true) lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + label)) -- Date. -lex:add_rule('date', token(lexer.CONSTANT, - lexer.starts_line((lexer.digit + S('/-'))^1))) +lex:add_rule('date', token(lexer.CONSTANT, lexer.starts_line((lexer.digit + S('/-'))^1))) -- Automated transactions. -lex:add_rule('auto_tx', token(lexer.PREPROCESSOR, - lexer.to_eol(lexer.starts_line(S('=~'))))) +lex:add_rule('auto_tx', token(lexer.PREPROCESSOR, lexer.to_eol(lexer.starts_line(S('=~'))))) -- Directives. -local directive_word = word_match[[ - account alias assert bucket capture check comment commodity define end fixed - endfixed include payee apply tag test year -]] + S('AYNDCIiOobh') -lex:add_rule('directive', token(lexer.KEYWORD, - lexer.starts_line(S('!@')^-1 * directive_word))) +local directive_word = word_match{ + ' account', 'alias', 'assert', 'bucket', 'capture', 'check', 'comment', 'commodity', 'define', + 'end', 'fixed', 'endfixed', 'include', 'payee', 'apply', 'tag', 'test', 'year' +} + S('AYNDCIiOobh') +lex:add_rule('directive', token(lexer.KEYWORD, lexer.starts_line(S('!@')^-1 * directive_word))) return lex diff --git a/syntaxhighlight/textadept/less.lua b/syntaxhighlight/textadept/less.lua index 5a9164f..032d571 100644 --- a/syntaxhighlight/textadept/less.lua +++ b/syntaxhighlight/textadept/less.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke. See License.txt. +-- Copyright 2006-2021 Robert Gieseke. See LICENSE. -- Less CSS LPeg lexer. -- http://lesscss.org @@ -13,10 +13,9 @@ local lex = lexer.new('less', {inherit = lexer.load('css')}) lex:add_rule('line_comment', token(lexer.COMMENT, lexer.to_eol('//'))) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '@' * - (lexer.alnum + S('_-{}'))^1)) +lex:add_rule('variable', token(lexer.VARIABLE, '@' * (lexer.alnum + S('_-{}'))^1)) -- Fold points. -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/lexer.lua b/syntaxhighlight/textadept/lexer.lua index a14c773..f56d46a 100644 --- a/syntaxhighlight/textadept/lexer.lua +++ b/syntaxhighlight/textadept/lexer.lua @@ -1,4 +1,4 @@ --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. local M = {} @@ -6,71 +6,67 @@ local M = {} --- -- Lexes Scintilla documents and source code with Lua and LPeg. -- --- ## Writing Lua Lexers --- --- Lexers highlight the syntax of source code. Scintilla (the editing component --- behind [Textadept][]) traditionally uses static, compiled C++ lexers which --- are notoriously difficult to create and/or extend. On the other hand, Lua --- makes it easy to to rapidly create new lexers, extend existing ones, and --- embed lexers within one another. Lua lexers tend to be more readable than C++ --- lexers too. --- --- Lexers are Parsing Expression Grammars, or PEGs, composed with the Lua --- [LPeg library][]. The following table comes from the LPeg documentation and --- summarizes all you need to know about constructing basic LPeg patterns. This --- module provides convenience functions for creating and working with other --- more advanced patterns and concepts. --- --- Operator | Description --- ---------------------|------------ --- `lpeg.P(string)` | Matches `string` literally. --- `lpeg.P(`_`n`_`)` | Matches exactly _`n`_ characters. --- `lpeg.S(string)` | Matches any character in set `string`. --- `lpeg.R("`_`xy`_`")` | Matches any character between range `x` and `y`. --- `patt^`_`n`_ | Matches at least _`n`_ repetitions of `patt`. --- `patt^-`_`n`_ | Matches at most _`n`_ repetitions of `patt`. --- `patt1 * patt2` | Matches `patt1` followed by `patt2`. --- `patt1 + patt2` | Matches `patt1` or `patt2` (ordered choice). --- `patt1 - patt2` | Matches `patt1` if `patt2` does not match. --- `-patt` | Equivalent to `("" - patt)`. --- `#patt` | Matches `patt` but consumes no input. --- --- The first part of this document deals with rapidly constructing a simple --- lexer. The next part deals with more advanced techniques, such as custom --- coloring and embedding lexers within one another. Following that is a --- discussion about code folding, or being able to tell Scintilla which code --- blocks are "foldable" (temporarily hideable from view). After that are --- instructions on how to use Lua lexers with the aforementioned Textadept --- editor. Finally there are comments on lexer performance and limitations. +-- ### Writing Lua Lexers +-- +-- Lexers highlight the syntax of source code. Scintilla (the editing component behind +-- [Textadept][] and [SciTE][]) traditionally uses static, compiled C++ lexers which are +-- notoriously difficult to create and/or extend. On the other hand, Lua makes it easy to to +-- rapidly create new lexers, extend existing ones, and embed lexers within one another. Lua +-- lexers tend to be more readable than C++ lexers too. +-- +-- Lexers are Parsing Expression Grammars, or PEGs, composed with the Lua [LPeg library][]. The +-- following table comes from the LPeg documentation and summarizes all you need to know about +-- constructing basic LPeg patterns. This module provides convenience functions for creating +-- and working with other more advanced patterns and concepts. +-- +-- Operator | Description +-- -|- +-- `lpeg.P(string)` | Matches `string` literally. +-- `lpeg.P(`_`n`_`)` | Matches exactly _`n`_ number of characters. +-- `lpeg.S(string)` | Matches any character in set `string`. +-- `lpeg.R("`_`xy`_`")`| Matches any character between range `x` and `y`. +-- `patt^`_`n`_ | Matches at least _`n`_ repetitions of `patt`. +-- `patt^-`_`n`_ | Matches at most _`n`_ repetitions of `patt`. +-- `patt1 * patt2` | Matches `patt1` followed by `patt2`. +-- `patt1 + patt2` | Matches `patt1` or `patt2` (ordered choice). +-- `patt1 - patt2` | Matches `patt1` if `patt2` does not also match. +-- `-patt` | Equivalent to `("" - patt)`. +-- `#patt` | Matches `patt` but consumes no input. +-- +-- The first part of this document deals with rapidly constructing a simple lexer. The next part +-- deals with more advanced techniques, such as custom coloring and embedding lexers within one +-- another. Following that is a discussion about code folding, or being able to tell Scintilla +-- which code blocks are "foldable" (temporarily hideable from view). After that are instructions +-- on how to use Lua lexers with the aforementioned Textadept and SciTE editors. Finally there +-- are comments on lexer performance and limitations. -- -- [LPeg library]: http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html --- [Textadept]: http://foicica.com/textadept +-- [Textadept]: https://orbitalquark.github.io/textadept +-- [SciTE]: https://scintilla.org/SciTE.html -- -- ### Lexer Basics -- --- The *lexers/* directory contains all lexers, including your new one. Before --- attempting to write one from scratch though, first determine if your --- programming language is similar to any of the 100+ languages supported. If --- so, you may be able to copy and modify that lexer, saving some time and --- effort. The filename of your lexer should be the name of your programming --- language in lower case followed by a *.lua* extension. For example, a new Lua --- lexer has the name *lua.lua*. +-- The *lexers/* directory contains all lexers, including your new one. Before attempting to +-- write one from scratch though, first determine if your programming language is similar to +-- any of the 100+ languages supported. If so, you may be able to copy and modify that lexer, +-- saving some time and effort. The filename of your lexer should be the name of your programming +-- language in lower case followed by a *.lua* extension. For example, a new Lua lexer has the +-- name *lua.lua*. -- --- Note: Try to refrain from using one-character language names like "c", "d", --- or "r". For example, Lua lexers for those language names are named "ansi_c", --- "dmd", and "rstats", respectively. +-- Note: Try to refrain from using one-character language names like "c", "d", or "r". For +-- example, Scintillua uses "ansi_c", "dmd", and "rstats", respectively. -- -- #### New Lexer Template -- --- There is a *lexers/template.txt* file that contains a simple template for a --- new lexer. Feel free to use it, replacing the '?'s with the name of your --- lexer. Consider this snippet from the template: +-- There is a *lexers/template.txt* file that contains a simple template for a new lexer. Feel +-- free to use it, replacing the '?'s with the name of your lexer. Consider this snippet from +-- the template: -- -- -- ? LPeg lexer. -- -- local lexer = require('syntaxhighlight.textadept.lexer') -- local token, word_match = lexer.token, lexer.word_match --- local P, R, S = lpeg.P, lpeg.R, lpeg.S +-- local P, S = lpeg.P, lpeg.S -- -- local lex = lexer.new('?') -- @@ -82,104 +78,83 @@ local M = {} -- -- return lex -- --- The first 3 lines of code simply define often used convenience variables. The --- fourth and last lines [define](#lexer.new) and return the lexer object --- Scintilla uses; they are very important and must be part of every lexer. The --- fifth line defines something called a "token", an essential building block of --- lexers. You will learn about tokens shortly. The sixth line defines a lexer --- grammar rule, which you will learn about later, as well as token styles. (Be --- aware that it is common practice to combine these two lines for short rules.) --- Note, however, the `local` prefix in front of variables, which is needed --- so-as not to affect Lua's global environment. All in all, this is a minimal, --- working lexer that you can build on. +-- The first 3 lines of code simply define often used convenience variables. The fourth and +-- last lines [define](#lexer.new) and return the lexer object Scintilla uses; they are very +-- important and must be part of every lexer. The fifth line defines something called a "token", +-- an essential building block of lexers. You will learn about tokens shortly. The sixth line +-- defines a lexer grammar rule, which you will learn about later, as well as token styles. (Be +-- aware that it is common practice to combine these two lines for short rules.) Note, however, +-- the `local` prefix in front of variables, which is needed so-as not to affect Lua's global +-- environment. All in all, this is a minimal, working lexer that you can build on. -- -- #### Tokens -- --- Take a moment to think about your programming language's structure. What kind --- of key elements does it have? In the template shown earlier, one predefined --- element all languages have is whitespace. Your language probably also has --- elements like comments, strings, and keywords. Lexers refer to these elements --- as "tokens". Tokens are the fundamental "building blocks" of lexers. Lexers --- break down source code into tokens for coloring, which results in the syntax --- highlighting familiar to you. It is up to you how specific your lexer is when --- it comes to tokens. Perhaps only distinguishing between keywords and --- identifiers is necessary, or maybe recognizing constants and built-in --- functions, methods, or libraries is desirable. The Lua lexer, for example, --- defines 11 tokens: whitespace, keywords, built-in functions, constants, --- built-in libraries, identifiers, strings, comments, numbers, labels, and --- operators. Even though constants, built-in functions, and built-in libraries --- are subsets of identifiers, Lua programmers find it helpful for the lexer to --- distinguish between them all. It is perfectly acceptable to just recognize --- keywords and identifiers. --- --- In a lexer, tokens consist of a token name and an LPeg pattern that matches a --- sequence of characters recognized as an instance of that token. Create tokens --- using the [`lexer.token()`]() function. Let us examine the "whitespace" token --- defined in the template shown earlier: +-- Take a moment to think about your programming language's structure. What kind of key +-- elements does it have? In the template shown earlier, one predefined element all languages +-- have is whitespace. Your language probably also has elements like comments, strings, and +-- keywords. Lexers refer to these elements as "tokens". Tokens are the fundamental "building +-- blocks" of lexers. Lexers break down source code into tokens for coloring, which results +-- in the syntax highlighting familiar to you. It is up to you how specific your lexer is +-- when it comes to tokens. Perhaps only distinguishing between keywords and identifiers is +-- necessary, or maybe recognizing constants and built-in functions, methods, or libraries is +-- desirable. The Lua lexer, for example, defines 11 tokens: whitespace, keywords, built-in +-- functions, constants, built-in libraries, identifiers, strings, comments, numbers, labels, +-- and operators. Even though constants, built-in functions, and built-in libraries are subsets +-- of identifiers, Lua programmers find it helpful for the lexer to distinguish between them +-- all. It is perfectly acceptable to just recognize keywords and identifiers. +-- +-- In a lexer, tokens consist of a token name and an LPeg pattern that matches a sequence of +-- characters recognized as an instance of that token. Create tokens using the [`lexer.token()`]() +-- function. Let us examine the "whitespace" token defined in the template shown earlier: -- -- local ws = token(lexer.WHITESPACE, lexer.space^1) -- --- At first glance, the first argument does not appear to be a string name and --- the second argument does not appear to be an LPeg pattern. Perhaps you --- expected something like: +-- At first glance, the first argument does not appear to be a string name and the second +-- argument does not appear to be an LPeg pattern. Perhaps you expected something like: -- -- local ws = token('whitespace', S('\t\v\f\n\r ')^1) -- --- The `lexer` module actually provides a convenient list of common token names --- and common LPeg patterns for you to use. Token names include --- [`lexer.DEFAULT`](), [`lexer.WHITESPACE`](), [`lexer.COMMENT`](), --- [`lexer.STRING`](), [`lexer.NUMBER`](), [`lexer.KEYWORD`](), --- [`lexer.IDENTIFIER`](), [`lexer.OPERATOR`](), [`lexer.ERROR`](), --- [`lexer.PREPROCESSOR`](), [`lexer.CONSTANT`](), [`lexer.VARIABLE`](), --- [`lexer.FUNCTION`](), [`lexer.CLASS`](), [`lexer.TYPE`](), [`lexer.LABEL`](), --- [`lexer.REGEX`](), and [`lexer.EMBEDDED`](). Patterns include --- [`lexer.any`](), [`lexer.ascii`](), [`lexer.extend`](), [`lexer.alpha`](), --- [`lexer.digit`](), [`lexer.alnum`](), [`lexer.lower`](), [`lexer.upper`](), --- [`lexer.xdigit`](), [`lexer.cntrl`](), [`lexer.graph`](), [`lexer.print`](), --- [`lexer.punct`](), [`lexer.space`](), [`lexer.newline`](), --- [`lexer.nonnewline`](), [`lexer.nonnewline_esc`](), [`lexer.dec_num`](), --- [`lexer.hex_num`](), [`lexer.oct_num`](), [`lexer.integer`](), --- [`lexer.float`](), [`lexer.number`](), and [`lexer.word`](). You may use your --- own token names if none of the above fit your language, but an advantage to --- using predefined token names is that your lexer's tokens will inherit the --- universal syntax highlighting color theme used by your text editor. +-- The `lexer` module actually provides a convenient list of common token names and common LPeg +-- patterns for you to use. Token names include [`lexer.DEFAULT`](), [`lexer.WHITESPACE`](), +-- [`lexer.COMMENT`](), [`lexer.STRING`](), [`lexer.NUMBER`](), [`lexer.KEYWORD`](), +-- [`lexer.IDENTIFIER`](), [`lexer.OPERATOR`](), [`lexer.ERROR`](), [`lexer.PREPROCESSOR`](), +-- [`lexer.CONSTANT`](), [`lexer.VARIABLE`](), [`lexer.FUNCTION`](), [`lexer.CLASS`](), +-- [`lexer.TYPE`](), [`lexer.LABEL`](), [`lexer.REGEX`](), and [`lexer.EMBEDDED`](). Patterns +-- include [`lexer.any`](), [`lexer.alpha`](), [`lexer.digit`](), [`lexer.alnum`](), +-- [`lexer.lower`](), [`lexer.upper`](), [`lexer.xdigit`](), [`lexer.graph`](), [`lexer.print`](), +-- [`lexer.punct`](), [`lexer.space`](), [`lexer.newline`](), [`lexer.nonnewline`](), +-- [`lexer.dec_num`](), [`lexer.hex_num`](), [`lexer.oct_num`](), [`lexer.integer`](), +-- [`lexer.float`](), [`lexer.number`](), and [`lexer.word`](). You may use your own token names +-- if none of the above fit your language, but an advantage to using predefined token names is +-- that your lexer's tokens will inherit the universal syntax highlighting color theme used by +-- your text editor. -- -- ##### Example Tokens -- --- So, how might you define other tokens like keywords, comments, and strings? --- Here are some examples. +-- So, how might you define other tokens like keywords, comments, and strings? Here are some +-- examples. -- -- **Keywords** -- --- Instead of matching _n_ keywords with _n_ `P('keyword_`_`n`_`')` ordered --- choices, use another convenience function: [`lexer.word_match()`](). It is --- much easier and more efficient to write word matches like: +-- Instead of matching _n_ keywords with _n_ `P('keyword_`_`n`_`')` ordered choices, use another +-- convenience function: [`lexer.word_match()`](). It is much easier and more efficient to +-- write word matches like: -- --- local keyword = token(lexer.KEYWORD, lexer.word_match[[ --- keyword_1 keyword_2 ... keyword_n --- ]]) +-- local keyword = token(lexer.KEYWORD, lexer.word_match{ +-- 'keyword_1', 'keyword_2', ..., 'keyword_n' +-- }) -- --- local case_insensitive_keyword = token(lexer.KEYWORD, lexer.word_match([[ --- KEYWORD_1 keyword_2 ... KEYword_n --- ]], true)) +-- local case_insensitive_keyword = token(lexer.KEYWORD, lexer.word_match({ +-- 'KEYWORD_1', 'keyword_2', ..., 'KEYword_n' +-- }, true)) -- --- local hyphened_keyword = token(lexer.KEYWORD, lexer.word_match[[ --- keyword-1 keyword-2 ... keyword-n --- ]]) +-- local hyphened_keyword = token(lexer.KEYWORD, lexer.word_match{ +-- 'keyword-1', 'keyword-2', ..., 'keyword-n' +-- }) -- --- In order to more easily separate or categorize keyword sets, you can use Lua --- line comments within keyword strings. Such comments will be ignored. For --- example: +-- For short keyword lists, you can use a single string of words. For example: -- --- local keyword = token(lexer.KEYWORD, lexer.word_match[[ --- -- Version 1 keywords. --- keyword_11, keyword_12 ... keyword_1n --- -- Version 2 keywords. --- keyword_21, keyword_22 ... keyword_2n --- ... --- -- Version N keywords. --- keyword_m1, keyword_m2 ... keyword_mn --- ]]) +-- local keyword = token(lexer.KEYWORD, lexer.word_match('key_1 key_2 ... key_n')) -- -- **Comments** -- @@ -188,37 +163,33 @@ local M = {} -- local shell_comment = token(lexer.COMMENT, lexer.to_eol('#')) -- local c_line_comment = token(lexer.COMMENT, lexer.to_eol('//', true)) -- --- The comments above start with a '#' or "//" and go to the end of the line. --- The second comment recognizes the next line also as a comment if the current --- line ends with a '\' escape character. +-- The comments above start with a '#' or "//" and go to the end of the line. The second comment +-- recognizes the next line also as a comment if the current line ends with a '\' escape character. -- --- C-style "block" comments with a start and end delimiter are also easy to --- express: +-- C-style "block" comments with a start and end delimiter are also easy to express: -- -- local c_comment = token(lexer.COMMENT, lexer.range('/*', '*/')) -- --- This comment starts with a "/\*" sequence and contains anything up to and --- including an ending "\*/" sequence. The ending "\*/" is optional so the lexer --- can recognize unfinished comments as comments and highlight them properly. +-- This comment starts with a "/\*" sequence and contains anything up to and including an ending +-- "\*/" sequence. The ending "\*/" is optional so the lexer can recognize unfinished comments +-- as comments and highlight them properly. -- -- **Strings** -- --- Most programming languages allow escape sequences in strings such that a --- sequence like "\\"" in a double-quoted string indicates that the --- '"' is not the end of the string. [`lexer.range()`]() handles escapes --- inherently. +-- Most programming languages allow escape sequences in strings such that a sequence like +-- "\\"" in a double-quoted string indicates that the '"' is not the end of the +-- string. [`lexer.range()`]() handles escapes inherently. -- -- local dq_str = lexer.range('"') -- local sq_str = lexer.range("'") -- local string = token(lexer.STRING, dq_str + sq_str) -- --- In this case, the lexer treats '\' as an escape character in a string --- sequence. +-- In this case, the lexer treats '\' as an escape character in a string sequence. -- -- **Numbers** -- --- Most programming languages have the same format for integer and float tokens, --- so it might be as simple as using a predefined LPeg pattern: +-- Most programming languages have the same format for integer and float tokens, so it might +-- be as simple as using a predefined LPeg pattern: -- -- local number = token(lexer.NUMBER, lexer.number) -- @@ -227,28 +198,24 @@ local M = {} -- local integer = P('-')^-1 * (lexer.dec_num * S('lL')^-1) -- local number = token(lexer.NUMBER, lexer.float + lexer.hex_num + integer) -- --- Your language may need other tweaks, but it is up to you how fine-grained you --- want your highlighting to be. After all, you are not writing a compiler or --- interpreter! +-- Your language may need other tweaks, but it is up to you how fine-grained you want your +-- highlighting to be. After all, you are not writing a compiler or interpreter! -- -- #### Rules -- --- Programming languages have grammars, which specify valid token structure. For --- example, comments usually cannot appear within a string. Grammars consist of --- rules, which are simply combinations of tokens. Recall from the lexer --- template the [`lexer.add_rule()`]() call, which adds a rule to the lexer's --- grammar: +-- Programming languages have grammars, which specify valid token structure. For example, +-- comments usually cannot appear within a string. Grammars consist of rules, which are simply +-- combinations of tokens. Recall from the lexer template the [`lexer.add_rule()`]() call, +-- which adds a rule to the lexer's grammar: -- -- lex:add_rule('whitespace', ws) -- --- Each rule has an associated name, but rule names are completely arbitrary and --- serve only to identify and distinguish between different rules. Rule order is --- important: if text does not match the first rule added to the grammar, the --- lexer tries to match the second rule added, and so on. Right now this lexer --- simply matches whitespace tokens under a rule named "whitespace". +-- Each rule has an associated name, but rule names are completely arbitrary and serve only to +-- identify and distinguish between different rules. Rule order is important: if text does not +-- match the first rule added to the grammar, the lexer tries to match the second rule added, and +-- so on. Right now this lexer simply matches whitespace tokens under a rule named "whitespace". -- --- To illustrate the importance of rule order, here is an example of a --- simplified Lua lexer: +-- To illustrate the importance of rule order, here is an example of a simplified Lua lexer: -- -- lex:add_rule('whitespace', token(lexer.WHITESPACE, ...)) -- lex:add_rule('keyword', token(lexer.KEYWORD, ...)) @@ -259,285 +226,223 @@ local M = {} -- lex:add_rule('label', token(lexer.LABEL, ...)) -- lex:add_rule('operator', token(lexer.OPERATOR, ...)) -- --- Note how identifiers come after keywords. In Lua, as with most programming --- languages, the characters allowed in keywords and identifiers are in the same --- set (alphanumerics plus underscores). If the lexer added the "identifier" --- rule before the "keyword" rule, all keywords would match identifiers and thus --- incorrectly highlight as identifiers instead of keywords. The same idea --- applies to function, constant, etc. tokens that you may want to distinguish --- between: their rules should come before identifiers. +-- Note how identifiers come after keywords. In Lua, as with most programming languages, +-- the characters allowed in keywords and identifiers are in the same set (alphanumerics +-- plus underscores). If the lexer added the "identifier" rule before the "keyword" rule, +-- all keywords would match identifiers and thus incorrectly highlight as identifiers instead +-- of keywords. The same idea applies to function, constant, etc. tokens that you may want to +-- distinguish between: their rules should come before identifiers. -- --- So what about text that does not match any rules? For example in Lua, the '!' --- character is meaningless outside a string or comment. Normally the lexer --- skips over such text. If instead you want to highlight these "syntax errors", --- add an additional end rule: +-- So what about text that does not match any rules? For example in Lua, the '!' character is +-- meaningless outside a string or comment. Normally the lexer skips over such text. If instead +-- you want to highlight these "syntax errors", add an additional end rule: -- -- lex:add_rule('whitespace', ws) -- ... -- lex:add_rule('error', token(lexer.ERROR, lexer.any)) -- --- This identifies and highlights any character not matched by an existing --- rule as a `lexer.ERROR` token. +-- This identifies and highlights any character not matched by an existing rule as a `lexer.ERROR` +-- token. -- --- Even though the rules defined in the examples above contain a single token, --- rules may consist of multiple tokens. For example, a rule for an HTML tag --- could consist of a tag token followed by an arbitrary number of attribute --- tokens, allowing the lexer to highlight all tokens separately. That rule --- might look something like this: +-- Even though the rules defined in the examples above contain a single token, rules may +-- consist of multiple tokens. For example, a rule for an HTML tag could consist of a tag token +-- followed by an arbitrary number of attribute tokens, allowing the lexer to highlight all +-- tokens separately. That rule might look something like this: -- -- lex:add_rule('tag', tag_start * (ws * attributes)^0 * tag_end^-1) -- --- Note however that lexers with complex rules like these are more prone to lose --- track of their state, especially if they span multiple lines. +-- Note however that lexers with complex rules like these are more prone to lose track of their +-- state, especially if they span multiple lines. -- -- #### Summary -- --- Lexers primarily consist of tokens and grammar rules. At your disposal are a --- number of convenience patterns and functions for rapidly creating a lexer. If --- you choose to use predefined token names for your tokens, you do not have to --- define how the lexer highlights them. The tokens will inherit the default --- syntax highlighting color theme your editor uses. +-- Lexers primarily consist of tokens and grammar rules. At your disposal are a number of +-- convenience patterns and functions for rapidly creating a lexer. If you choose to use +-- predefined token names for your tokens, you do not have to define how the lexer highlights +-- them. The tokens will inherit the default syntax highlighting color theme your editor uses. -- -- ### Advanced Techniques -- -- #### Styles and Styling -- --- The most basic form of syntax highlighting is assigning different colors to --- different tokens. Instead of highlighting with just colors, Scintilla allows --- for more rich highlighting, or "styling", with different fonts, font sizes, --- font attributes, and foreground and background colors, just to name a few. --- The unit of this rich highlighting is called a "style". Styles are simply --- strings of comma-separated property settings. By default, lexers associate --- predefined token names like `lexer.WHITESPACE`, `lexer.COMMENT`, --- `lexer.STRING`, etc. with particular styles as part of a universal color --- theme. These predefined styles include [`lexer.STYLE_CLASS`](), --- [`lexer.STYLE_COMMENT`](), [`lexer.STYLE_CONSTANT`](), --- [`lexer.STYLE_ERROR`](), [`lexer.STYLE_EMBEDDED`](), --- [`lexer.STYLE_FUNCTION`](), [`lexer.STYLE_IDENTIFIER`](), --- [`lexer.STYLE_KEYWORD`](), [`lexer.STYLE_LABEL`](), [`lexer.STYLE_NUMBER`](), --- [`lexer.STYLE_OPERATOR`](), [`lexer.STYLE_PREPROCESSOR`](), --- [`lexer.STYLE_REGEX`](), [`lexer.STYLE_STRING`](), [`lexer.STYLE_TYPE`](), --- [`lexer.STYLE_VARIABLE`](), and [`lexer.STYLE_WHITESPACE`](). Like with --- predefined token names and LPeg patterns, you may define your own styles. At --- their core, styles are just strings, so you may create new ones and/or modify --- existing ones. Each style consists of the following comma-separated settings: --- --- Setting | Description --- ---------------|------------ --- font:_name_ | The name of the font the style uses. --- size:_int_ | The size of the font the style uses. --- [not]bold | Whether or not the font face is bold. --- weight:_int_ | The weight or boldness of a font, between 1 and 999. --- [not]italics | Whether or not the font face is italic. --- [not]underlined| Whether or not the font face is underlined. --- fore:_color_ | The foreground color of the font face. --- back:_color_ | The background color of the font face. --- [not]eolfilled | Does the background color extend to the end of the line? --- case:_char_ | The case of the font ('u': upper, 'l': lower, 'm': normal). --- [not]visible | Whether or not the text is visible. --- [not]changeable| Whether the text is changeable or read-only. --- --- Specify font colors in either "#RRGGBB" format, "0xBBGGRR" format, or the --- decimal equivalent of the latter. As with token names, LPeg patterns, and --- styles, there is a set of predefined color names, but they vary depending on --- the current color theme in use. Therefore, it is generally not a good idea to --- manually define colors within styles in your lexer since they might not fit --- into a user's chosen color theme. Try to refrain from even using predefined --- colors in a style because that color may be theme-specific. Instead, the best --- practice is to either use predefined styles or derive new color-agnostic --- styles from predefined ones. For example, Lua "longstring" tokens use the --- existing `lexer.STYLE_STRING` style instead of defining a new one. +-- The most basic form of syntax highlighting is assigning different colors to different +-- tokens. Instead of highlighting with just colors, Scintilla allows for more rich highlighting, +-- or "styling", with different fonts, font sizes, font attributes, and foreground and background +-- colors, just to name a few. The unit of this rich highlighting is called a "style". Styles +-- are simply Lua tables of properties. By default, lexers associate predefined token names like +-- `lexer.WHITESPACE`, `lexer.COMMENT`, `lexer.STRING`, etc. with particular styles as part +-- of a universal color theme. These predefined styles are contained in [`lexer.styles`](), +-- and you may define your own styles. See that table's documentation for more information. As +-- with token names, LPeg patterns, and styles, there is a set of predefined color names, +-- but they vary depending on the current color theme in use. Therefore, it is generally not +-- a good idea to manually define colors within styles in your lexer since they might not fit +-- into a user's chosen color theme. Try to refrain from even using predefined colors in a +-- style because that color may be theme-specific. Instead, the best practice is to either use +-- predefined styles or derive new color-agnostic styles from predefined ones. For example, Lua +-- "longstring" tokens use the existing `lexer.styles.string` style instead of defining a new one. -- -- ##### Example Styles -- --- Defining styles is pretty straightforward. An empty style that inherits the --- default theme settings is simply an empty string: +-- Defining styles is pretty straightforward. An empty style that inherits the default theme +-- settings is simply an empty table: -- --- local style_nothing = '' +-- local style_nothing = {} -- -- A similar style but with a bold font face looks like this: -- --- local style_bold = 'bold' --- --- If you want the same style, but also with an italic font face, define the new --- style in terms of the old one: --- --- local style_bold_italic = style_bold .. ',italics' +-- local style_bold = {bold = true} -- --- This allows you to derive new styles from predefined ones without having to --- rewrite them. This operation leaves the old style unchanged. Thus if you --- had a "static variable" token whose style you wanted to base off of --- `lexer.STYLE_VARIABLE`, it would probably look like: +-- You can derive new styles from predefined ones without having to rewrite them. This operation +-- leaves the old style unchanged. For example, if you had a "static variable" token whose +-- style you wanted to base off of `lexer.styles.variable`, it would probably look like: -- --- local style_static_var = lexer.STYLE_VARIABLE .. ',italics' +-- local style_static_var = lexer.styles.variable .. {italics = true} -- --- The color theme files in the *lexers/themes/* folder give more examples of --- style definitions. +-- The color theme files in the *lexers/themes/* folder give more examples of style definitions. -- -- #### Token Styles -- --- Lexers use the [`lexer.add_style()`]() function to assign styles to --- particular tokens. Recall the token definition and from the lexer template: +-- Lexers use the [`lexer.add_style()`]() function to assign styles to particular tokens. Recall +-- the token definition and from the lexer template: -- -- local ws = token(lexer.WHITESPACE, lexer.space^1) -- lex:add_rule('whitespace', ws) -- --- Why is a style not assigned to the `lexer.WHITESPACE` token? As mentioned --- earlier, lexers automatically associate tokens that use predefined token --- names with a particular style. Only tokens with custom token names need --- manual style associations. As an example, consider a custom whitespace token: +-- Why is a style not assigned to the `lexer.WHITESPACE` token? As mentioned earlier, lexers +-- automatically associate tokens that use predefined token names with a particular style. Only +-- tokens with custom token names need manual style associations. As an example, consider a +-- custom whitespace token: -- -- local ws = token('custom_whitespace', lexer.space^1) -- -- Assigning a style to this token looks like: -- --- lex:add_style('custom_whitespace', lexer.STYLE_WHITESPACE) +-- lex:add_style('custom_whitespace', lexer.styles.whitespace) -- --- Do not confuse token names with rule names. They are completely different --- entities. In the example above, the lexer associates the "custom_whitespace" --- token with the existing style for `lexer.WHITESPACE` tokens. If instead you --- prefer to color the background of whitespace a shade of grey, it might look --- like: +-- Do not confuse token names with rule names. They are completely different entities. In the +-- example above, the lexer associates the "custom_whitespace" token with the existing style +-- for `lexer.WHITESPACE` tokens. If instead you prefer to color the background of whitespace +-- a shade of grey, it might look like: -- --- local custom_style = lexer.STYLE_WHITESPACE .. ',back:$(color.grey)' --- lex:add_style('custom_whitespace', custom_style) +-- lex:add_style('custom_whitespace', lexer.styles.whitespace .. {back = lexer.colors.grey}) -- --- Notice that the lexer peforms Scintilla-style "$()" property expansion. You --- may also use "%()". Remember to refrain from assigning specific colors in --- styles, but in this case, all user color themes probably define the --- "color.grey" property. +-- Remember to refrain from assigning specific colors in styles, but in this case, all user +-- color themes probably define `colors.grey`. -- -- #### Line Lexers -- --- By default, lexers match the arbitrary chunks of text passed to them by --- Scintilla. These chunks may be a full document, only the visible part of a --- document, or even just portions of lines. Some lexers need to match whole --- lines. For example, a lexer for the output of a file "diff" needs to know if --- the line started with a '+' or '-' and then style the entire line --- accordingly. To indicate that your lexer matches by line, create the lexer --- with an extra parameter: +-- By default, lexers match the arbitrary chunks of text passed to them by Scintilla. These +-- chunks may be a full document, only the visible part of a document, or even just portions +-- of lines. Some lexers need to match whole lines. For example, a lexer for the output of a +-- file "diff" needs to know if the line started with a '+' or '-' and then style the entire +-- line accordingly. To indicate that your lexer matches by line, create the lexer with an +-- extra parameter: -- -- local lex = lexer.new('?', {lex_by_line = true}) -- --- Now the input text for the lexer is a single line at a time. Keep in mind --- that line lexers do not have the ability to look ahead at subsequent lines. +-- Now the input text for the lexer is a single line at a time. Keep in mind that line lexers +-- do not have the ability to look ahead at subsequent lines. -- -- #### Embedded Lexers -- --- Lexers embed within one another very easily, requiring minimal effort. In the --- following sections, the lexer being embedded is called the "child" lexer and --- the lexer a child is being embedded in is called the "parent". For example, --- consider an HTML lexer and a CSS lexer. Either lexer stands alone for styling --- their respective HTML and CSS files. However, CSS can be embedded inside --- HTML. In this specific case, the CSS lexer is the "child" lexer with the HTML --- lexer being the "parent". Now consider an HTML lexer and a PHP lexer. This --- sounds a lot like the case with CSS, but there is a subtle difference: PHP --- _embeds itself into_ HTML while CSS is _embedded in_ HTML. This fundamental --- difference results in two types of embedded lexers: a parent lexer that --- embeds other child lexers in it (like HTML embedding CSS), and a child lexer --- that embeds itself into a parent lexer (like PHP embedding itself in HTML). +-- Lexers embed within one another very easily, requiring minimal effort. In the following +-- sections, the lexer being embedded is called the "child" lexer and the lexer a child is +-- being embedded in is called the "parent". For example, consider an HTML lexer and a CSS +-- lexer. Either lexer stands alone for styling their respective HTML and CSS files. However, CSS +-- can be embedded inside HTML. In this specific case, the CSS lexer is the "child" lexer with +-- the HTML lexer being the "parent". Now consider an HTML lexer and a PHP lexer. This sounds +-- a lot like the case with CSS, but there is a subtle difference: PHP _embeds itself into_ +-- HTML while CSS is _embedded in_ HTML. This fundamental difference results in two types of +-- embedded lexers: a parent lexer that embeds other child lexers in it (like HTML embedding CSS), +-- and a child lexer that embeds itself into a parent lexer (like PHP embedding itself in HTML). -- -- ##### Parent Lexer -- --- Before embedding a child lexer into a parent lexer, the parent lexer needs to --- load the child lexer. This is done with the [`lexer.load()`]() function. For --- example, loading the CSS lexer within the HTML lexer looks like: +-- Before embedding a child lexer into a parent lexer, the parent lexer needs to load the child +-- lexer. This is done with the [`lexer.load()`]() function. For example, loading the CSS lexer +-- within the HTML lexer looks like: -- -- local css = lexer.load('css') -- --- The next part of the embedding process is telling the parent lexer when to --- switch over to the child lexer and when to switch back. The lexer refers to --- these indications as the "start rule" and "end rule", respectively, and are --- just LPeg patterns. Continuing with the HTML/CSS example, the transition from --- HTML to CSS is when the lexer encounters a "style" tag with a "type" --- attribute whose value is "text/css": +-- The next part of the embedding process is telling the parent lexer when to switch over +-- to the child lexer and when to switch back. The lexer refers to these indications as the +-- "start rule" and "end rule", respectively, and are just LPeg patterns. Continuing with the +-- HTML/CSS example, the transition from HTML to CSS is when the lexer encounters a "style" +-- tag with a "type" attribute whose value is "text/css": -- -- local css_tag = P(']+type="text/css"', index) then --- return index --- end +-- if input:find('^[^>]+type="text/css"', index) then return index end -- end) -- --- This pattern looks for the beginning of a "style" tag and searches its --- attribute list for the text "`type="text/css"`". (In this simplified example, --- the Lua pattern does not consider whitespace between the '=' nor does it --- consider that using single quotes is valid.) If there is a match, the --- functional pattern returns a value instead of `nil`. In this case, the value --- returned does not matter because we ultimately want to style the "style" tag --- as an HTML tag, so the actual start rule looks like this: +-- This pattern looks for the beginning of a "style" tag and searches its attribute list for +-- the text "`type="text/css"`". (In this simplified example, the Lua pattern does not consider +-- whitespace between the '=' nor does it consider that using single quotes is valid.) If there +-- is a match, the functional pattern returns a value instead of `nil`. In this case, the value +-- returned does not matter because we ultimately want to style the "style" tag as an HTML tag, +-- so the actual start rule looks like this: -- -- local css_start_rule = #css_tag * tag -- --- Now that the parent knows when to switch to the child, it needs to know when --- to switch back. In the case of HTML/CSS, the switch back occurs when the --- lexer encounters an ending "style" tag, though the lexer should still style --- the tag as an HTML tag: +-- Now that the parent knows when to switch to the child, it needs to know when to switch +-- back. In the case of HTML/CSS, the switch back occurs when the lexer encounters an ending +-- "style" tag, though the lexer should still style the tag as an HTML tag: -- -- local css_end_rule = #P('') * tag -- --- Once the parent loads the child lexer and defines the child's start and end --- rules, it embeds the child with the [`lexer.embed()`]() function: +-- Once the parent loads the child lexer and defines the child's start and end rules, it embeds +-- the child with the [`lexer.embed()`]() function: -- -- lex:embed(css, css_start_rule, css_end_rule) -- -- ##### Child Lexer -- --- The process for instructing a child lexer to embed itself into a parent is --- very similar to embedding a child into a parent: first, load the parent lexer --- into the child lexer with the [`lexer.load()`]() function and then create --- start and end rules for the child lexer. However, in this case, call --- [`lexer.embed()`]() with switched arguments. For example, in the PHP lexer: +-- The process for instructing a child lexer to embed itself into a parent is very similar to +-- embedding a child into a parent: first, load the parent lexer into the child lexer with the +-- [`lexer.load()`]() function and then create start and end rules for the child lexer. However, +-- in this case, call [`lexer.embed()`]() with switched arguments. For example, in the PHP lexer: -- -- local html = lexer.load('html') -- local php_start_rule = token('php_tag', '') --- lex:add_style('php_tag', lexer.STYLE_EMBEDDED) +-- lex:add_style('php_tag', lexer.styles.embedded) -- html:embed(lex, php_start_rule, php_end_rule) -- -- #### Lexers with Complex State -- --- A vast majority of lexers are not stateful and can operate on any chunk of --- text in a document. However, there may be rare cases where a lexer does need --- to keep track of some sort of persistent state. Rather than using `lpeg.P` --- function patterns that set state variables, it is recommended to make use of --- Scintilla's built-in, per-line state integers via [`lexer.line_state`](). It --- was designed to accommodate up to 32 bit flags for tracking state. --- [`lexer.line_from_position()`]() will return the line for any position given --- to an `lpeg.P` function pattern. (Any positions derived from that position --- argument will also work.) +-- A vast majority of lexers are not stateful and can operate on any chunk of text in a +-- document. However, there may be rare cases where a lexer does need to keep track of some +-- sort of persistent state. Rather than using `lpeg.P` function patterns that set state +-- variables, it is recommended to make use of Scintilla's built-in, per-line state integers via +-- [`lexer.line_state`](). It was designed to accommodate up to 32 bit flags for tracking state. +-- [`lexer.line_from_position()`]() will return the line for any position given to an `lpeg.P` +-- function pattern. (Any positions derived from that position argument will also work.) -- -- Writing stateful lexers is beyond the scope of this document. -- -- ### Code Folding -- --- When reading source code, it is occasionally helpful to temporarily hide --- blocks of code like functions, classes, comments, etc. This is the concept of --- "folding". In many Scintilla-based editors, such as Textadept, little --- indicators in the editor margins appear next to code that can be folded at --- places called "fold points". When the user clicks an indicator, the editor --- hides the code associated with the indicator until the user clicks the --- indicator again. The lexer specifies these fold points and what code exactly --- to fold. --- --- The fold points for most languages occur on keywords or character sequences. --- Examples of fold keywords are "if" and "end" in Lua and examples of fold --- character sequences are '{', '}', "/\*", and "\*/" in C for code block and --- comment delimiters, respectively. However, these fold points cannot occur --- just anywhere. For example, lexers should not recognize fold keywords that --- appear within strings or comments. The [`lexer.add_fold_point()`]() function --- allows you to conveniently define fold points with such granularity. For --- example, consider C: +-- When reading source code, it is occasionally helpful to temporarily hide blocks of code like +-- functions, classes, comments, etc. This is the concept of "folding". In the Textadept and +-- SciTE editors for example, little indicators in the editor margins appear next to code that +-- can be folded at places called "fold points". When the user clicks an indicator, the editor +-- hides the code associated with the indicator until the user clicks the indicator again. The +-- lexer specifies these fold points and what code exactly to fold. +-- +-- The fold points for most languages occur on keywords or character sequences. Examples of +-- fold keywords are "if" and "end" in Lua and examples of fold character sequences are '{', +-- '}', "/\*", and "\*/" in C for code block and comment delimiters, respectively. However, +-- these fold points cannot occur just anywhere. For example, lexers should not recognize fold +-- keywords that appear within strings or comments. The [`lexer.add_fold_point()`]() function +-- allows you to conveniently define fold points with such granularity. For example, consider C: -- -- lex:add_fold_point(lexer.OPERATOR, '{', '}') -- lex:add_fold_point(lexer.COMMENT, '/*', '*/') -- --- The first assignment states that any '{' or '}' that the lexer recognized as --- an `lexer.OPERATOR` token is a fold point. Likewise, the second assignment --- states that any "/\*" or "\*/" that the lexer recognizes as part of a --- `lexer.COMMENT` token is a fold point. The lexer does not consider any --- occurrences of these characters outside their defined tokens (such as in a --- string) as fold points. How do you specify fold keywords? Here is an example --- for Lua: +-- The first assignment states that any '{' or '}' that the lexer recognized as an `lexer.OPERATOR` +-- token is a fold point. Likewise, the second assignment states that any "/\*" or "\*/" that +-- the lexer recognizes as part of a `lexer.COMMENT` token is a fold point. The lexer does +-- not consider any occurrences of these characters outside their defined tokens (such as in +-- a string) as fold points. How do you specify fold keywords? Here is an example for Lua: -- -- lex:add_fold_point(lexer.KEYWORD, 'if', 'end') -- lex:add_fold_point(lexer.KEYWORD, 'do', 'end') @@ -545,14 +450,13 @@ local M = {} -- lex:add_fold_point(lexer.KEYWORD, 'repeat', 'until') -- -- If your lexer has case-insensitive keywords as fold points, simply add a --- `case_insensitive_fold_points = true` option to [`lexer.new()`](), and --- specify keywords in lower case. +-- `case_insensitive_fold_points = true` option to [`lexer.new()`](), and specify keywords in +-- lower case. -- --- If your lexer needs to do some additional processing in order to determine if --- a token is a fold point, pass a function that returns an integer to --- `lex:add_fold_point()`. Returning `1` indicates the token is a beginning fold --- point and returning `-1` indicates the token is an ending fold point. --- Returning `0` indicates the token is not a fold point. For example: +-- If your lexer needs to do some additional processing in order to determine if a token is +-- a fold point, pass a function that returns an integer to `lex:add_fold_point()`. Returning +-- `1` indicates the token is a beginning fold point and returning `-1` indicates the token is +-- an ending fold point. Returning `0` indicates the token is not a fold point. For example: -- -- local function fold_strange_token(text, pos, line, s, symbol) -- if ... then @@ -565,33 +469,43 @@ local M = {} -- -- lex:add_fold_point('strange_token', '|', fold_strange_token) -- --- Any time the lexer encounters a '|' that is a "strange_token", it calls the --- `fold_strange_token` function to determine if '|' is a fold point. The lexer --- calls these functions with the following arguments: the text to identify fold --- points in, the beginning position of the current line in the text to fold, --- the current line's text, the position in the current line the fold point text --- starts at, and the fold point text itself. +-- Any time the lexer encounters a '|' that is a "strange_token", it calls the `fold_strange_token` +-- function to determine if '|' is a fold point. The lexer calls these functions with the +-- following arguments: the text to identify fold points in, the beginning position of the +-- current line in the text to fold, the current line's text, the position in the current line +-- the fold point text starts at, and the fold point text itself. -- -- #### Fold by Indentation -- --- Some languages have significant whitespace and/or no delimiters that indicate --- fold points. If your lexer falls into this category and you would like to --- mark fold points based on changes in indentation, create the lexer with a --- `fold_by_indentation = true` option: +-- Some languages have significant whitespace and/or no delimiters that indicate fold points. If +-- your lexer falls into this category and you would like to mark fold points based on changes +-- in indentation, create the lexer with a `fold_by_indentation = true` option: -- -- local lex = lexer.new('?', {fold_by_indentation = true}) -- -- ### Using Lexers -- --- #### Textadept +-- **Textadept** -- --- Put your lexer in your *~/.textadept/lexers/* directory so you do not --- overwrite it when upgrading Textadept. Also, lexers in this directory --- override default lexers. Thus, Textadept loads a user *lua* lexer instead of --- the default *lua* lexer. This is convenient for tweaking a default lexer to --- your liking. Then add a [file type][] for your lexer if necessary. +-- Put your lexer in your *~/.textadept/lexers/* directory so you do not overwrite it when +-- upgrading Textadept. Also, lexers in this directory override default lexers. Thus, Textadept +-- loads a user *lua* lexer instead of the default *lua* lexer. This is convenient for tweaking +-- a default lexer to your liking. Then add a [file type](#textadept.file_types) for your lexer +-- if necessary. -- --- [file type]: textadept.file_types.html +-- **SciTE** +-- +-- Create a *.properties* file for your lexer and `import` it in either your *SciTEUser.properties* +-- or *SciTEGlobal.properties*. The contents of the *.properties* file should contain: +-- +-- file.patterns.[lexer_name]=[file_patterns] +-- lexer.$(file.patterns.[lexer_name])=[lexer_name] +-- +-- where `[lexer_name]` is the name of your lexer (minus the *.lua* extension) and +-- `[file_patterns]` is a set of file extensions to use your lexer for. +-- +-- Please note that Lua lexers ignore any styling information in *.properties* files. Your +-- theme file in the *lexers/themes/* directory contains styling information. -- -- ### Migrating Legacy Lexers -- @@ -623,34 +537,27 @@ local M = {} -- -- return M -- --- While such legacy lexers will be handled just fine without any changes, it is --- recommended that you migrate yours. The migration process is fairly --- straightforward: --- --- 1. Replace all instances of `l` with `lexer`, as it's better practice and --- results in less confusion. --- 2. Replace `local M = {_NAME = '?'}` with `local lex = lexer.new('?')`, where --- `?` is the name of your legacy lexer. At the end of the lexer, change --- `return M` to `return lex`. --- 3. Instead of defining rules towards the end of your lexer, define your rules --- as you define your tokens and patterns using --- [`lex:add_rule()`](#lexer.add_rule). --- 4. Similarly, any custom token names should have their styles immediately --- defined using [`lex:add_style()`](#lexer.add_style). --- 5. Convert any table arguments passed to [`lexer.word_match()`]() to a +-- While Scintillua will handle such legacy lexers just fine without any changes, it is +-- recommended that you migrate yours. The migration process is fairly straightforward: +-- +-- 1. Replace all instances of `l` with `lexer`, as it's better practice and results in less +-- confusion. +-- 2. Replace `local M = {_NAME = '?'}` with `local lex = lexer.new('?')`, where `?` is the +-- name of your legacy lexer. At the end of the lexer, change `return M` to `return lex`. +-- 3. Instead of defining rules towards the end of your lexer, define your rules as you define +-- your tokens and patterns using [`lex:add_rule()`](#lexer.add_rule). +-- 4. Similarly, any custom token names should have their styles immediately defined using +-- [`lex:add_style()`](#lexer.add_style). +-- 5. Optionally convert any table arguments passed to [`lexer.word_match()`]() to a -- space-separated string of words. --- 6. Replace any calls to `lexer.embed(M, child, ...)` and --- `lexer.embed(parent, M, ...)` with --- [`lex:embed`](#lexer.embed)`(child, ...)` and `parent:embed(lex, ...)`, --- respectively. --- 7. Define fold points with simple calls to --- [`lex:add_fold_point()`](#lexer.add_fold_point). No need to mess with Lua --- patterns anymore. --- 8. Any legacy lexer options such as `M._FOLDBYINDENTATION`, `M._LEXBYLINE`, --- `M._lexer`, etc. should be added as table options to [`lexer.new()`](). --- 9. Any external lexer rule fetching and/or modifications via `lexer._RULES` --- should be changed to use [`lexer.get_rule()`]() and --- [`lexer.modify_rule()`](). +-- 6. Replace any calls to `lexer.embed(M, child, ...)` and `lexer.embed(parent, M, ...)` with +-- [`lex:embed`](#lexer.embed)`(child, ...)` and `parent:embed(lex, ...)`, respectively. +-- 7. Define fold points with simple calls to [`lex:add_fold_point()`](#lexer.add_fold_point). No +-- need to mess with Lua patterns anymore. +-- 8. Any legacy lexer options such as `M._FOLDBYINDENTATION`, `M._LEXBYLINE`, `M._lexer`, +-- etc. should be added as table options to [`lexer.new()`](). +-- 9. Any external lexer rule fetching and/or modifications via `lexer._RULES` should be changed +-- to use [`lexer.get_rule()`]() and [`lexer.modify_rule()`](). -- -- As an example, consider the following sample legacy lexer: -- @@ -695,14 +602,14 @@ local M = {} -- -- local lexer = require('syntaxhighlight.textadept.lexer') -- local token, word_match = lexer.token, lexer.word_match --- local P, R, S = lpeg.P, lpeg.R, lpeg.S +-- local P, S = lpeg.P, lpeg.S -- -- local lex = lexer.new('legacy') -- -- lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) --- lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[foo bar baz]])) --- lex:add_rule('custom', token('custom', P('quux'))) --- lex:add_style('custom', lexer.STYLE_KEYWORD .. ',bold') +-- lex:add_rule('keyword', token(lexer.KEYWORD, word_match('foo bar baz'))) +-- lex:add_rule('custom', token('custom', 'quux')) +-- lex:add_style('custom', lexer.styles.keyword .. {bold = true}) -- lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) -- lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) @@ -717,25 +624,23 @@ local M = {} -- -- #### Performance -- --- There might be some slight overhead when initializing a lexer, but loading a --- file from disk into Scintilla is usually more expensive. On modern computer --- systems, I see no difference in speed between Lua lexers and Scintilla's C++ --- ones. Optimize lexers for speed by re-arranging `lexer.add_rule()` calls so --- that the most common rules match first. Do keep in mind that order matters --- for similar rules. +-- There might be some slight overhead when initializing a lexer, but loading a file from disk +-- into Scintilla is usually more expensive. On modern computer systems, I see no difference in +-- speed between Lua lexers and Scintilla's C++ ones. Optimize lexers for speed by re-arranging +-- `lexer.add_rule()` calls so that the most common rules match first. Do keep in mind that +-- order matters for similar rules. -- --- In some cases, folding may be far more expensive than lexing, particularly --- in lexers with a lot of potential fold points. If your lexer is exhibiting --- signs of slowness, try disabling folding in your text editor first. If that --- speeds things up, you can try reducing the number of fold points you added, --- overriding `lexer.fold()` with your own implementation, or simply eliminating --- folding support from your lexer. +-- In some cases, folding may be far more expensive than lexing, particularly in lexers with a +-- lot of potential fold points. If your lexer is exhibiting signs of slowness, try disabling +-- folding in your text editor first. If that speeds things up, you can try reducing the number +-- of fold points you added, overriding `lexer.fold()` with your own implementation, or simply +-- eliminating folding support from your lexer. -- -- #### Limitations -- --- Embedded preprocessor languages like PHP cannot completely embed in their --- parent languages in that the parent's tokens do not support start and end --- rules. This mostly goes unnoticed, but code like +-- Embedded preprocessor languages like PHP cannot completely embed in their parent languages +-- in that the parent's tokens do not support start and end rules. This mostly goes unnoticed, +-- but code like -- --
-- @@ -743,23 +648,22 @@ local M = {} -- -- #### Troubleshooting -- --- Errors in lexers can be tricky to debug. Lexers print Lua errors to --- `io.stderr` and `_G.print()` statements to `io.stdout`. Running your editor --- from a terminal is the easiest way to see errors as they occur. +-- Errors in lexers can be tricky to debug. Lexers print Lua errors to `io.stderr` and `_G.print()` +-- statements to `io.stdout`. Running your editor from a terminal is the easiest way to see +-- errors as they occur. -- -- #### Risks -- --- Poorly written lexers have the ability to crash Scintilla (and thus its --- containing application), so unsaved data might be lost. However, I have only --- observed these crashes in early lexer development, when syntax errors or --- pattern errors are present. Once the lexer actually starts styling text --- (either correctly or incorrectly, it does not matter), I have not observed +-- Poorly written lexers have the ability to crash Scintilla (and thus its containing application), +-- so unsaved data might be lost. However, I have only observed these crashes in early lexer +-- development, when syntax errors or pattern errors are present. Once the lexer actually starts +-- styling text (either correctly or incorrectly, it does not matter), I have not observed -- any crashes. -- -- #### Acknowledgements -- --- Thanks to Peter Odding for his [lexer post][] on the Lua mailing list --- that provided inspiration, and thanks to Roberto Ierusalimschy for LPeg. +-- Thanks to Peter Odding for his [lexer post][] on the Lua mailing list that provided inspiration, +-- and thanks to Roberto Ierusalimschy for LPeg. -- -- [lexer post]: http://lua-users.org/lists/lua-l/2007-04/msg00116.html -- @field DEFAULT (string) @@ -796,58 +700,6 @@ local M = {} -- The token name for label tokens. -- @field REGEX (string) -- The token name for regex tokens. --- @field STYLE_CLASS (string) --- The style typically used for class definitions. --- @field STYLE_COMMENT (string) --- The style typically used for code comments. --- @field STYLE_CONSTANT (string) --- The style typically used for constants. --- @field STYLE_ERROR (string) --- The style typically used for erroneous syntax. --- @field STYLE_FUNCTION (string) --- The style typically used for function definitions. --- @field STYLE_KEYWORD (string) --- The style typically used for language keywords. --- @field STYLE_LABEL (string) --- The style typically used for labels. --- @field STYLE_NUMBER (string) --- The style typically used for numbers. --- @field STYLE_OPERATOR (string) --- The style typically used for operators. --- @field STYLE_REGEX (string) --- The style typically used for regular expression strings. --- @field STYLE_STRING (string) --- The style typically used for strings. --- @field STYLE_PREPROCESSOR (string) --- The style typically used for preprocessor statements. --- @field STYLE_TYPE (string) --- The style typically used for static types. --- @field STYLE_VARIABLE (string) --- The style typically used for variables. --- @field STYLE_WHITESPACE (string) --- The style typically used for whitespace. --- @field STYLE_EMBEDDED (string) --- The style typically used for embedded code. --- @field STYLE_IDENTIFIER (string) --- The style typically used for identifier words. --- @field STYLE_DEFAULT (string) --- The style all styles are based off of. --- @field STYLE_LINENUMBER (string) --- The style used for all margins except fold margins. --- @field STYLE_BRACELIGHT (string) --- The style used for highlighted brace characters. --- @field STYLE_BRACEBAD (string) --- The style used for unmatched brace characters. --- @field STYLE_CONTROLCHAR (string) --- The style used for control characters. --- Color attributes are ignored. --- @field STYLE_INDENTGUIDE (string) --- The style used for indentation guides. --- @field STYLE_CALLTIP (string) --- The style used by call tips if [`buffer.call_tip_use_style`]() is set. --- Only the font name, size, and color attributes are used. --- @field STYLE_FOLDDISPLAYTEXT (string) --- The style used for fold display text. -- @field any (pattern) -- A pattern that matches any single character. -- @field ascii (pattern) @@ -859,8 +711,7 @@ local M = {} -- @field digit (pattern) -- A pattern that matches any digit ('0'-'9'). -- @field alnum (pattern) --- A pattern that matches any alphanumeric character ('A'-'Z', 'a'-'z', --- '0'-'9'). +-- A pattern that matches any alphanumeric character ('A'-'Z', 'a'-'z', '0'-'9'). -- @field lower (pattern) -- A pattern that matches any lower case character ('a'-'z'). -- @field upper (pattern) @@ -874,18 +725,14 @@ local M = {} -- @field print (pattern) -- A pattern that matches any printable character (' ' to '~'). -- @field punct (pattern) --- A pattern that matches any punctuation character ('!' to '/', ':' to '@', --- '[' to ''', '{' to '~'). +-- A pattern that matches any punctuation character ('!' to '/', ':' to '@', '[' to ''', +-- '{' to '~'). -- @field space (pattern) --- A pattern that matches any whitespace character ('\t', '\v', '\f', '\n', --- '\r', space). +-- A pattern that matches any whitespace character ('\t', '\v', '\f', '\n', '\r', space). -- @field newline (pattern) -- A pattern that matches a sequence of end of line characters. -- @field nonnewline (pattern) -- A pattern that matches any single, non-newline character. --- @field nonnewline_esc (pattern) --- A pattern that matches any single, non-newline character or any set of end --- of line characters escaped with '\'. -- @field dec_num (pattern) -- A pattern that matches a decimal number. -- @field hex_num (pattern) @@ -897,11 +744,11 @@ local M = {} -- @field float (pattern) -- A pattern that matches a floating point number. -- @field number (pattern) --- A pattern that matches a typical number, either a floating point, decimal, --- hexadecimal, or octal number. +-- A pattern that matches a typical number, either a floating point, decimal, hexadecimal, +-- or octal number. -- @field word (pattern) --- A pattern that matches a typical word. Words begin with a letter or --- underscore and consist of alphanumeric and underscore characters. +-- A pattern that matches a typical word. Words begin with a letter or underscore and consist +-- of alphanumeric and underscore characters. -- @field FOLD_BASE (number) -- The initial (root) fold level. -- @field FOLD_BLANK (number) @@ -910,8 +757,7 @@ local M = {} -- Flag indicating the line is fold point. -- @field fold_level (table, Read-only) -- Table of fold level bit-masks for line numbers starting from 1. --- Fold level masks are composed of an integer level combined with any of the --- following bits: +-- Fold level masks are composed of an integer level combined with any of the following bits: -- -- * `lexer.FOLD_BASE` -- The initial fold level. @@ -920,28 +766,49 @@ local M = {} -- * `lexer.FOLD_HEADER` -- The line is a header, or fold point. -- @field indent_amount (table, Read-only) --- Table of indentation amounts in character columns, for line numbers --- starting from 1. +-- Table of indentation amounts in character columns, for line numbers starting from 1. -- @field line_state (table) -- Table of integer line states for line numbers starting from 1. -- Line states can be used by lexers for keeping track of persistent states. -- @field property (table) -- Map of key-value string pairs. -- @field property_expanded (table, Read-only) --- Map of key-value string pairs with `$()` and `%()` variable replacement --- performed in values. +-- Map of key-value string pairs with `$()` and `%()` variable replacement performed in values. -- @field property_int (table, Read-only) --- Map of key-value pairs with values interpreted as numbers, or `0` if not --- found. +-- Map of key-value pairs with values interpreted as numbers, or `0` if not found. -- @field style_at (table, Read-only) -- Table of style names at positions in the buffer starting from 1. +-- @field folding (boolean) +-- Whether or not folding is enabled for the lexers that support it. +-- This option is disabled by default. +-- This is an alias for `lexer.property['fold'] = '1|0'`. +-- @field fold_on_zero_sum_lines (boolean) +-- Whether or not to mark as a fold point lines that contain both an ending and starting fold +-- point. For example, `} else {` would be marked as a fold point. +-- This option is disabled by default. This is an alias for +-- `lexer.property['fold.on.zero.sum.lines'] = '1|0'`. +-- @field fold_compact (boolean) +-- Whether or not blank lines after an ending fold point are included in that +-- fold. +-- This option is disabled by default. +-- This is an alias for `lexer.property['fold.compact'] = '1|0'`. +-- @field fold_by_indentation (boolean) +-- Whether or not to fold based on indentation level if a lexer does not have +-- a folder. +-- Some lexers automatically enable this option. It is disabled by default. +-- This is an alias for `lexer.property['fold.by.indentation'] = '1|0'`. +-- @field fold_line_groups (boolean) +-- Whether or not to fold multiple, consecutive line groups (such as line comments and import +-- statements) and only show the top line. +-- This option is disabled by default. +-- This is an alias for `lexer.property['fold.line.groups'] = '1|0'`. module('lexer')]=] if not require then - -- Substitute for Lua's require() function, which does not require the package - -- module to be loaded. - -- Note: all modules must be in the global namespace, which is the case in - -- LexerLPeg's default Lua State. + -- Substitute for Lua's require() function, which does not require the package module to + -- be loaded. + -- Note: all modules must be in the global namespace, which is the case in LexerLPeg's default + -- Lua State. function require(name) return name == 'lexer' and M or _G[name] end end @@ -952,8 +819,8 @@ local lpeg_Cmt, lpeg_C = lpeg.Cmt, lpeg.C local lpeg_match = lpeg.match -- Searches for the given *name* in the given *path*. --- This is a safe implementation of Lua 5.2's `package.searchpath()` function --- that does not require the package module to be loaded. +-- This is a safe implementation of Lua 5.2's `package.searchpath()` function that does not +-- require the package module to be loaded. local function searchpath(name, path) local tried = {} for part in path:gmatch('[^;]+') do @@ -965,32 +832,126 @@ local function searchpath(name, path) return nil, table.concat(tried, '\n') end +--- +-- Map of color name strings to color values in `0xBBGGRR` or `"#RRGGBB"` format. +-- Note: for applications running within a terminal emulator, only 16 color values are recognized, +-- regardless of how many colors a user's terminal actually supports. (A terminal emulator's +-- settings determines how to actually display these recognized color values, which may end up +-- being mapped to a completely different color set.) In order to use the light variant of a +-- color, some terminals require a style's `bold` attribute must be set along with that normal +-- color. Recognized color values are black (0x000000), red (0x000080), green (0x008000), yellow +-- (0x008080), blue (0x800000), magenta (0x800080), cyan (0x808000), white (0xC0C0C0), light black +-- (0x404040), light red (0x0000FF), light green (0x00FF00), light yellow (0x00FFFF), light blue +-- (0xFF0000), light magenta (0xFF00FF), light cyan (0xFFFF00), and light white (0xFFFFFF). +-- @name colors +-- @class table +M.colors = setmetatable({}, { + __index = function(_, name) + local color = M.property['color.' .. name] + return tonumber(color) or color + end, __newindex = function(_, name, color) M.property['color.' .. name] = color end +}) + +-- A style object that distills into a property string that can be read by the LPeg lexer. +local style_obj = {} +style_obj.__index = style_obj + +-- Create a style object from a style name, property table, or legacy style string. +function style_obj.new(name_or_props) + local prop_string = tostring(name_or_props) + if type(name_or_props) == 'string' and name_or_props:find('^[%w_]+$') then + prop_string = string.format('$(style.%s)', name_or_props) + elseif type(name_or_props) == 'table' then + local settings = {} + for k, v in pairs(name_or_props) do + settings[#settings + 1] = type(v) ~= 'boolean' and string.format('%s:%s', k, v) or + string.format('%s%s', v and '' or 'not', k) + end + prop_string = table.concat(settings, ',') + end + return setmetatable({prop_string = prop_string}, style_obj) +end + +-- Returns a new style based on this one with the properties defined in the given table or +-- legacy style string. +function style_obj.__concat(self, props) + if type(props) == 'table' then props = tostring(style_obj.new(props)) end + return setmetatable({prop_string = string.format('%s,%s', self.prop_string, props)}, style_obj) +end + +-- Returns this style object as property string for use with the LPeg lexer. +function style_obj.__tostring(self) return self.prop_string end + +--- +-- Map of style names to style definition tables. +-- +-- Style names consist of the following default names as well as the token names defined by lexers. +-- +-- * `default`: The default style all others are based on. +-- * `line_number`: The line number margin style. +-- * `control_char`: The style of control character blocks. +-- * `indent_guide`: The style of indentation guides. +-- * `call_tip`: The style of call tip text. Only the `font`, `size`, `fore`, and `back` style +-- definition fields are supported. +-- * `fold_display_text`: The style of text displayed next to folded lines. +-- * `class`, `comment`, `constant`, `embedded`, `error`, `function`, `identifier`, `keyword`, +-- `label`, `number`, `operator`, `preprocessor`, `regex`, `string`, `type`, `variable`, +-- `whitespace`: Some token names used by lexers. Some lexers may define more token names, +-- so this list is not exhaustive. +-- * *`lang`*`_whitespace`: A special style for whitespace tokens in lexer name *lang*. It +-- inherits from `whitespace`, and is used in place of it for all lexers. +-- +-- Style definition tables may contain the following fields: +-- +-- * `font`: String font name. +-- * `size`: Integer font size. +-- * `bold`: Whether or not the font face is bold. The default value is `false`. +-- * `weight`: Integer weight or boldness of a font, between 1 and 999. +-- * `italics`: Whether or not the font face is italic. The default value is `false`. +-- * `underlined`: Whether or not the font face is underlined. The default value is `false`. +-- * `fore`: Font face foreground color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `back`: Font face background color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `eolfilled`: Whether or not the background color extends to the end of the line. The +-- default value is `false`. +-- * `case`: Font case: `'u'` for upper, `'l'` for lower, and `'m'` for normal, mixed case. The +-- default value is `'m'`. +-- * `visible`: Whether or not the text is visible. The default value is `true`. +-- * `changeable`: Whether the text is changeable instead of read-only. The default value is +-- `true`. +-- @class table +-- @name styles +M.styles = setmetatable({}, { + __index = function(_, name) return style_obj.new(name) end, __newindex = function(_, name, style) + if getmetatable(style) ~= style_obj then style = style_obj.new(style) end + M.property['style.' .. name] = tostring(style) + end +}) + -- Default styles. local default = { - 'nothing', 'whitespace', 'comment', 'string', 'number', 'keyword', - 'identifier', 'operator', 'error', 'preprocessor', 'constant', 'variable', - 'function', 'class', 'type', 'label', 'regex', 'embedded' + 'nothing', 'whitespace', 'comment', 'string', 'number', 'keyword', 'identifier', 'operator', + 'error', 'preprocessor', 'constant', 'variable', 'function', 'class', 'type', 'label', 'regex', + 'embedded' } for _, name in ipairs(default) do M[name:upper()] = name - M['STYLE_' .. name:upper()] = string.format('$(style.%s)', name) + M['STYLE_' .. name:upper()] = style_obj.new(name) -- backward compatibility end -- Predefined styles. local predefined = { - 'default', 'linenumber', 'bracelight', 'bracebad', 'controlchar', - 'indentguide', 'calltip', 'folddisplaytext' + 'default', 'line_number', 'brace_light', 'brace_bad', 'control_char', 'indent_guide', 'call_tip', + 'fold_display_text' } for _, name in ipairs(predefined) do M[name:upper()] = name - M['STYLE_' .. name:upper()] = string.format('$(style.%s)', name) + M['STYLE_' .. name:upper()] = style_obj.new(name) -- backward compatibility end --- --- Adds pattern *rule* identified by string *id* to the ordered list of rules --- for lexer *lexer*. +-- Adds pattern *rule* identified by string *id* to the ordered list of rules for lexer *lexer*. -- @param lexer The lexer to add the given rule to. --- @param id The id associated with this rule. It does not have to be the same --- as the name passed to `token()`. +-- @param id The id associated with this rule. It does not have to be the same as the name +-- passed to `token()`. -- @param rule The LPeg pattern of the rule. -- @see modify_rule -- @name add_rule @@ -998,8 +959,8 @@ function M.add_rule(lexer, id, rule) if lexer._lexer then lexer = lexer._lexer end -- proxy; get true parent if not lexer._RULES then lexer._RULES = {} - -- Contains an ordered list (by numerical index) of rule names. This is used - -- in conjunction with lexer._RULES for building _TOKENRULE. + -- Contains an ordered list (by numerical index) of rule names. This is used in conjunction + -- with lexer._RULES for building _TOKENRULE. lexer._RULEORDER = {} end lexer._RULES[id] = rule @@ -1008,8 +969,7 @@ function M.add_rule(lexer, id, rule) end --- --- Replaces in lexer *lexer* the existing rule identified by string *id* with --- pattern *rule*. +-- Replaces in lexer *lexer* the existing rule identified by string *id* with pattern *rule*. -- @param lexer The lexer to modify. -- @param id The id associated with this rule. -- @param rule The LPeg pattern of the rule. @@ -1032,100 +992,90 @@ function M.get_rule(lexer, id) end --- --- Associates string *token_name* in lexer *lexer* with Scintilla style string --- *style*. --- Style strings are comma-separated property settings. Available property --- settings are: --- --- * `font:name`: Font name. --- * `size:int`: Font size. --- * `bold` or `notbold`: Whether or not the font face is bold. --- * `weight:int`: Font weight (between 1 and 999). --- * `italics` or `notitalics`: Whether or not the font face is italic. --- * `underlined` or `notunderlined`: Whether or not the font face is --- underlined. --- * `fore:color`: Font face foreground color in "#RRGGBB" or 0xBBGGRR format. --- * `back:color`: Font face background color in "#RRGGBB" or 0xBBGGRR format. --- * `eolfilled` or `noteolfilled`: Whether or not the background color --- extends to the end of the line. --- * `case:char`: Font case ('u' for uppercase, 'l' for lowercase, and 'm' for --- mixed case). --- * `visible` or `notvisible`: Whether or not the text is visible. --- * `changeable` or `notchangeable`: Whether or not the text is changeable or --- read-only. --- --- Property settings may also contain "$(property.name)" expansions for --- properties defined in Scintilla, theme files, etc. +-- Associates string *token_name* in lexer *lexer* with style table *style*. +-- *style* may have the following fields: +-- +-- * `font`: String font name. +-- * `size`: Integer font size. +-- * `bold`: Whether or not the font face is bold. The default value is `false`. +-- * `weight`: Integer weight or boldness of a font, between 1 and 999. +-- * `italics`: Whether or not the font face is italic. The default value is `false`. +-- * `underlined`: Whether or not the font face is underlined. The default value is `false`. +-- * `fore`: Font face foreground color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `back`: Font face background color in `0xBBGGRR` or `"#RRGGBB"` format. +-- * `eolfilled`: Whether or not the background color extends to the end of the line. The +-- default value is `false`. +-- * `case`: Font case, `'u'` for upper, `'l'` for lower, and `'m'` for normal, mixed case. The +-- default value is `'m'`. +-- * `visible`: Whether or not the text is visible. The default value is `true`. +-- * `changeable`: Whether the text is changeable instead of read-only. The default value is +-- `true`. +-- +-- Field values may also contain "$(property.name)" expansions for properties defined in Scintilla, +-- theme files, etc. -- @param lexer The lexer to add a style to. -- @param token_name The name of the token to associated with the style. -- @param style A style string for Scintilla. --- @usage lex:add_style('longstring', lexer.STYLE_STRING) --- @usage lex:add_style('deprecated_func', lexer.STYLE_FUNCTION .. ',italics') --- @usage lex:add_style('visible_ws', --- lexer.STYLE_WHITESPACE .. ',back:$(color.grey)') +-- @usage lex:add_style('longstring', lexer.styles.string) +-- @usage lex:add_style('deprecated_func', lexer.styles['function'] .. {italics = true} +-- @usage lex:add_style('visible_ws', lexer.styles.whitespace .. {back = lexer.colors.grey} -- @name add_style function M.add_style(lexer, token_name, style) local num_styles = lexer._numstyles if num_styles == 33 then num_styles = num_styles + 8 end -- skip predefined if num_styles >= 256 then print('Too many styles defined (256 MAX)') end lexer._TOKENSTYLES[token_name], lexer._numstyles = num_styles, num_styles + 1 - lexer._EXTRASTYLES[token_name] = style - -- If the lexer is a proxy or a child that embedded itself, copy this style to - -- the parent lexer. + if type(style) == 'table' and not getmetatable(style) then style = style_obj.new(style) end + lexer._EXTRASTYLES[token_name] = tostring(style) + -- If the lexer is a proxy or a child that embedded itself, copy this style to the parent lexer. if lexer._lexer then lexer._lexer:add_style(token_name, style) end end --- --- Adds to lexer *lexer* a fold point whose beginning and end tokens are string --- *token_name* tokens with string content *start_symbol* and *end_symbol*, --- respectively. --- In the event that *start_symbol* may or may not be a fold point depending on --- context, and that additional processing is required, *end_symbol* may be a --- function that ultimately returns `1` (indicating a beginning fold point), --- `-1` (indicating an ending fold point), or `0` (indicating no fold point). --- That function is passed the following arguments: +-- Adds to lexer *lexer* a fold point whose beginning and end tokens are string *token_name* +-- tokens with string content *start_symbol* and *end_symbol*, respectively. +-- In the event that *start_symbol* may or may not be a fold point depending on context, and that +-- additional processing is required, *end_symbol* may be a function that ultimately returns +-- `1` (indicating a beginning fold point), `-1` (indicating an ending fold point), or `0` +-- (indicating no fold point). That function is passed the following arguments: -- -- * `text`: The text being processed for fold points. --- * `pos`: The position in *text* of the beginning of the line currently --- being processed. +-- * `pos`: The position in *text* of the beginning of the line currently being processed. -- * `line`: The text of the line currently being processed. -- * `s`: The position of *start_symbol* in *line*. -- * `symbol`: *start_symbol* itself. -- @param lexer The lexer to add a fold point to. -- @param token_name The token name of text that indicates a fold point. -- @param start_symbol The text that indicates the beginning of a fold point. --- @param end_symbol Either the text that indicates the end of a fold point, or --- a function that returns whether or not *start_symbol* is a beginning fold --- point (1), an ending fold point (-1), or not a fold point at all (0). +-- @param end_symbol Either the text that indicates the end of a fold point, or a function that +-- returns whether or not *start_symbol* is a beginning fold point (1), an ending fold point +-- (-1), or not a fold point at all (0). -- @usage lex:add_fold_point(lexer.OPERATOR, '{', '}') -- @usage lex:add_fold_point(lexer.KEYWORD, 'if', 'end') --- @usage lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) --- @usage lex:add_fold_point('custom', function(text, pos, line, s, symbol) --- ... end) +-- @usage lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) +-- @usage lex:add_fold_point('custom', function(text, pos, line, s, symbol) ... end) -- @name add_fold_point function M.add_fold_point(lexer, token_name, start_symbol, end_symbol) if not lexer._FOLDPOINTS then lexer._FOLDPOINTS = {_SYMBOLS = {}} end local symbols = lexer._FOLDPOINTS._SYMBOLS - if not symbols[start_symbol] then - symbols[#symbols + 1], symbols[start_symbol] = start_symbol, true - end - if not lexer._FOLDPOINTS[token_name] then - lexer._FOLDPOINTS[token_name] = {} + if not lexer._FOLDPOINTS[token_name] then lexer._FOLDPOINTS[token_name] = {} end + if lexer._CASEINSENSITIVEFOLDPOINTS then + start_symbol = start_symbol:lower() + if type(end_symbol) == 'string' then end_symbol = end_symbol:lower() end end if type(end_symbol) == 'string' then - if not symbols[end_symbol] then - symbols[#symbols + 1], symbols[end_symbol] = end_symbol, true - end + if not symbols[end_symbol] then symbols[#symbols + 1], symbols[end_symbol] = end_symbol, true end lexer._FOLDPOINTS[token_name][start_symbol] = 1 lexer._FOLDPOINTS[token_name][end_symbol] = -1 else lexer._FOLDPOINTS[token_name][start_symbol] = end_symbol -- function or int end - -- If the lexer is a proxy or a child that embedded itself, copy this fold - -- point to the parent lexer. - if lexer._lexer then - lexer._lexer:add_fold_point(token_name, start_symbol, end_symbol) + if not symbols[start_symbol] then + symbols[#symbols + 1], symbols[start_symbol] = start_symbol, true end + -- If the lexer is a proxy or a child that embedded itself, copy this fold point to the + -- parent lexer. + if lexer._lexer then lexer._lexer:add_fold_point(token_name, start_symbol, end_symbol) end end -- (Re)constructs `lexer._TOKENRULE`. @@ -1137,34 +1087,35 @@ local function join_tokens(lexer) return lexer._TOKENRULE end --- Metatable for lexer grammars. +-- Metatable for Scintillua grammars. -- These grammars are just tables ultimately passed to `lpeg.P()`. -local grammar_mt = {__index = { - -- Adds lexer *lexer* and any of its embedded lexers to this grammar. - -- @param lexer The lexer to add. - add_lexer = function(self, lexer) - local lexer_name = lexer._PARENTNAME or lexer._NAME - local token_rule = lexer:join_tokens() - for _, child in ipairs(lexer._CHILDREN) do - if child._CHILDREN then self:add_lexer(child) end - local rules = child._EMBEDDEDRULES[lexer_name] - local rules_token_rule = self['__' .. child._NAME] or rules.token_rule - self[child._NAME] = (-rules.end_rule * rules_token_rule)^0 * - rules.end_rule^-1 * lpeg_V(lexer_name) - local embedded_child = '_' .. child._NAME - self[embedded_child] = rules.start_rule * - (-rules.end_rule * rules_token_rule)^0 * rules.end_rule^-1 - token_rule = lpeg_V(embedded_child) + token_rule +local grammar_mt = { + __index = { + -- Adds lexer *lexer* and any of its embedded lexers to this grammar. + -- @param lexer The lexer to add. + add_lexer = function(self, lexer) + local lexer_name = lexer._PARENTNAME or lexer._NAME + local token_rule = lexer:join_tokens() + for _, child in ipairs(lexer._CHILDREN) do + if child._CHILDREN then self:add_lexer(child) end + local rules = child._EMBEDDEDRULES[lexer_name] + local rules_token_rule = self['__' .. child._NAME] or rules.token_rule + self[child._NAME] = (-rules.end_rule * rules_token_rule)^0 * rules.end_rule^-1 * + lpeg_V(lexer_name) + local embedded_child = '_' .. child._NAME + self[embedded_child] = rules.start_rule * (-rules.end_rule * rules_token_rule)^0 * + rules.end_rule^-1 + token_rule = lpeg_V(embedded_child) + token_rule + end + self['__' .. lexer_name] = token_rule -- can contain embedded lexer rules + self[lexer_name] = token_rule^0 end - self['__' .. lexer_name] = token_rule -- can contain embedded lexer rules - self[lexer_name] = token_rule^0 - end -}} + } +} -- (Re)constructs `lexer._GRAMMAR`. --- @param initial_rule The name of the rule to start lexing with. The default --- value is `lexer._NAME`. Multilang lexers use this to start with a child --- rule if necessary. +-- @param initial_rule The name of the rule to start lexing with. The default value is +-- `lexer._NAME`. Multilang lexers use this to start with a child rule if necessary. local function build_grammar(lexer, initial_rule) if not lexer._RULES then return end if lexer._CHILDREN then @@ -1179,13 +1130,11 @@ local function build_grammar(lexer, initial_rule) end --- --- Embeds child lexer *child* in parent lexer *lexer* using patterns --- *start_rule* and *end_rule*, which signal the beginning and end of the --- embedded lexer, respectively. +-- Embeds child lexer *child* in parent lexer *lexer* using patterns *start_rule* and *end_rule*, +-- which signal the beginning and end of the embedded lexer, respectively. -- @param lexer The parent lexer. -- @param child The child lexer. --- @param start_rule The pattern that signals the beginning of the embedded --- lexer. +-- @param start_rule The pattern that signals the beginning of the embedded lexer. -- @param end_rule The pattern that signals the end of the embedded lexer. -- @usage html:embed(css, css_start_rule, css_end_rule) -- @usage html:embed(lex, php_start_rule, php_end_rule) -- from php lexer @@ -1196,24 +1145,18 @@ function M.embed(lexer, child, start_rule, end_rule) if not child._EMBEDDEDRULES then child._EMBEDDEDRULES = {} end if not child._RULES then error('Cannot embed lexer with no rules') end child._EMBEDDEDRULES[lexer._NAME] = { - ['start_rule'] = start_rule, - token_rule = child:join_tokens(), - ['end_rule'] = end_rule + start_rule = start_rule, token_rule = child:join_tokens(), end_rule = end_rule } if not lexer._CHILDREN then lexer._CHILDREN = {} end local children = lexer._CHILDREN children[#children + 1] = child -- Add child styles. - for token, style in pairs(child._EXTRASTYLES) do - lexer:add_style(token, style) - end + for token, style in pairs(child._EXTRASTYLES) do lexer:add_style(token, style) end -- Add child fold symbols. if child._FOLDPOINTS then for token_name, symbols in pairs(child._FOLDPOINTS) do if token_name ~= '_SYMBOLS' then - for symbol, v in pairs(symbols) do - lexer:add_fold_point(token_name, symbol, v) - end + for symbol, v in pairs(symbols) do lexer:add_fold_point(token_name, symbol, v) end end end end @@ -1222,41 +1165,36 @@ function M.embed(lexer, child, start_rule, end_rule) end --- --- Lexes a chunk of text *text* (that has an initial style number of --- *init_style*) using lexer *lexer*, returning a table of token names and --- positions. +-- Lexes a chunk of text *text* (that has an initial style number of *init_style*) using lexer +-- *lexer*, returning a table of token names and positions. -- @param lexer The lexer to lex text with. -- @param text The text in the buffer to lex. --- @param init_style The current style. Multiple-language lexers use this to --- determine which language to start lexing in. +-- @param init_style The current style. Multiple-language lexers use this to determine which +-- language to start lexing in. -- @return table of token names and positions. -- @name lex function M.lex(lexer, text, init_style) if not lexer._GRAMMAR then return {M.DEFAULT, #text + 1} end if not lexer._LEXBYLINE then - -- For multilang lexers, build a new grammar whose initial_rule is the - -- current language. + -- For multilang lexers, build a new grammar whose initial_rule is the current language. if lexer._CHILDREN then for style, style_num in pairs(lexer._TOKENSTYLES) do if style_num == init_style then - local lexer_name = style:match('^(.+)_whitespace') or - lexer._PARENTNAME or lexer._NAME - if lexer._INITIALRULE ~= lexer_name then - lexer:build_grammar(lexer_name) - end + local lexer_name = style:match('^(.+)_whitespace') or lexer._PARENTNAME or lexer._NAME + if lexer._INITIALRULE ~= lexer_name then lexer:build_grammar(lexer_name) end break end end end return lpeg_match(lexer._GRAMMAR, text) else - local tokens = {} local function append(tokens, line_tokens, offset) for i = 1, #line_tokens, 2 do tokens[#tokens + 1] = line_tokens[i] tokens[#tokens + 1] = line_tokens[i + 1] + offset end end + local tokens = {} local offset = 0 local grammar = lexer._GRAMMAR for line in text:gmatch('[^\r\n]*\r?\n?') do @@ -1273,14 +1211,13 @@ function M.lex(lexer, text, init_style) end --- --- Determines fold points in a chunk of text *text* using lexer *lexer*, --- returning a table of fold levels associated with line numbers. --- *text* starts at position *start_pos* on line number *start_line* with a --- beginning fold level of *start_level* in the buffer. +-- Determines fold points in a chunk of text *text* using lexer *lexer*, returning a table of +-- fold levels associated with line numbers. +-- *text* starts at position *start_pos* on line number *start_line* with a beginning fold +-- level of *start_level* in the buffer. -- @param lexer The lexer to fold text with. -- @param text The text in the buffer to fold. --- @param start_pos The position in the buffer *text* starts at, counting from --- 1. +-- @param start_pos The position in the buffer *text* starts at, counting from 1. -- @param start_line The line number *text* starts on, counting from 1. -- @param start_level The fold level *text* starts on. -- @return table of fold levels associated with line numbers. @@ -1290,12 +1227,10 @@ function M.fold(lexer, text, start_pos, start_line, start_level) if text == '' then return folds end local fold = M.property_int['fold'] > 0 local FOLD_BASE = M.FOLD_BASE - local FOLD_HEADER, FOLD_BLANK = M.FOLD_HEADER, M.FOLD_BLANK + local FOLD_HEADER, FOLD_BLANK = M.FOLD_HEADER, M.FOLD_BLANK if fold and lexer._FOLDPOINTS then local lines = {} - for p, l in (text .. '\n'):gmatch('()(.-)\r?\n') do - lines[#lines + 1] = {p, l} - end + for p, l in (text .. '\n'):gmatch('()(.-)\r?\n') do lines[#lines + 1] = {p, l} end local fold_zero_sum_lines = M.property_int['fold.on.zero.sum.lines'] > 0 local fold_compact = M.property_int['fold.compact'] > 0 local fold_points = lexer._FOLDPOINTS @@ -1307,13 +1242,25 @@ function M.fold(lexer, text, start_pos, start_line, start_level) local pos, line = captures[1], captures[2] if line ~= '' then if lexer._CASEINSENSITIVEFOLDPOINTS then line = line:lower() end + local ranges = {} + local function is_valid_range(s, e) + if not s or not e then return false end + for i = 1, #ranges - 1, 2 do + local range_s, range_e = ranges[i], ranges[i + 1] + if s >= range_s and s <= range_e or e >= range_s and e <= range_e then + return false + end + end + ranges[#ranges + 1] = s + ranges[#ranges + 1] = e + return true + end local level_decreased = false for _, symbol in ipairs(fold_point_symbols) do local word = not symbol:find('[^%w_]') local s, e = line:find(symbol, 1, true) - while s and e do - --if not word or - -- line:find('^%f[%w_]' .. symbol .. '%f[^%w_]', s) then + while is_valid_range(s, e) do + -- if not word or line:find('^%f[%w_]' .. symbol .. '%f[^%w_]', s) then local word_before = s > 1 and line:find('^[%w_]', s - 1) local word_after = line:find('^[%w_]', e + 1) if not word or not (word_before or word_after) then @@ -1325,8 +1272,8 @@ function M.fold(lexer, text, start_pos, start_line, start_level) if type(level) == 'number' then current_level = current_level + level if level < 0 and current_level < prev_level then - -- Potential zero-sum line. If the level were to go back up on - -- the same line, the line may be marked as a fold header. + -- Potential zero-sum line. If the level were to go back up on the same line, + -- the line may be marked as a fold header. level_decreased = true end end @@ -1337,8 +1284,7 @@ function M.fold(lexer, text, start_pos, start_line, start_level) folds[line_num] = prev_level if current_level > prev_level then folds[line_num] = prev_level + FOLD_HEADER - elseif level_decreased and current_level == prev_level and - fold_zero_sum_lines then + elseif level_decreased and current_level == prev_level and fold_zero_sum_lines then if line_num > start_line then folds[line_num] = prev_level - 1 + FOLD_HEADER else @@ -1357,18 +1303,16 @@ function M.fold(lexer, text, start_pos, start_line, start_level) end line_num = line_num + 1 end - elseif fold and (lexer._FOLDBYINDENTATION or - M.property_int['fold.by.indentation'] > 0) then + elseif fold and (lexer._FOLDBYINDENTATION or M.property_int['fold.by.indentation'] > 0) then -- Indentation based folding. -- Calculate indentation per line. local indentation = {} for indent, line in (text .. '\n'):gmatch('([\t ]*)([^\r\n]*)\r?\n') do indentation[#indentation + 1] = line ~= '' and #indent end - -- Find the first non-blank line before start_line. If the current line is - -- indented, make that previous line a header and update the levels of any - -- blank lines inbetween. If the current line is blank, match the level of - -- the previous non-blank line. + -- Find the first non-blank line before start_line. If the current line is indented, make + -- that previous line a header and update the levels of any blank lines inbetween. If the + -- current line is blank, match the level of the previous non-blank line. local current_level = start_level for i = start_line, 1, -1 do local level = M.fold_level[i] @@ -1377,9 +1321,7 @@ function M.fold(lexer, text, start_pos, start_line, start_level) local indent = M.indent_amount[i] if indentation[1] and indentation[1] > indent then folds[i] = FOLD_BASE + indent + FOLD_HEADER - for j = i + 1, start_line - 1 do - folds[j] = start_level + FOLD_BLANK - end + for j = i + 1, start_line - 1 do folds[j] = start_level + FOLD_BLANK end elseif not indentation[1] then current_level = FOLD_BASE + indent end @@ -1419,25 +1361,20 @@ end -- Creates a returns a new lexer with the given name. -- @param name The lexer's name. -- @param opts Table of lexer options. Options currently supported: --- * `lex_by_line`: Whether or not the lexer only processes whole lines of --- text (instead of arbitrary chunks of text) at a time. --- Line lexers cannot look ahead to subsequent lines. --- The default value is `false`. --- * `fold_by_indentation`: Whether or not the lexer does not define any fold --- points and that fold points should be calculated based on changes in line --- indentation. +-- * `lex_by_line`: Whether or not the lexer only processes whole lines of text (instead of +-- arbitrary chunks of text) at a time. Line lexers cannot look ahead to subsequent lines. -- The default value is `false`. +-- * `fold_by_indentation`: Whether or not the lexer does not define any fold points and that +-- fold points should be calculated based on changes in line indentation. The default value +-- is `false`. -- * `case_insensitive_fold_points`: Whether or not fold points added via --- `lexer.add_fold_point()` ignore case. --- The default value is `false`. --- * `inherit`: Lexer to inherit from. --- The default value is `nil`. +-- `lexer.add_fold_point()` ignore case. The default value is `false`. +-- * `inherit`: Lexer to inherit from. The default value is `nil`. -- @usage lexer.new('rhtml', {inherit = lexer.load('html')}) -- @name new function M.new(name, opts) local lexer = { - _NAME = assert(name, 'lexer name expected'), - _LEXBYLINE = opts and opts['lex_by_line'], + _NAME = assert(name, 'lexer name expected'), _LEXBYLINE = opts and opts['lex_by_line'], _FOLDBYINDENTATION = opts and opts['fold_by_indentation'], _CASEINSENSITIVEFOLDPOINTS = opts and opts['case_insensitive_fold_points'], _lexer = opts and opts['inherit'] @@ -1450,21 +1387,21 @@ function M.new(name, opts) lexer._TOKENSTYLES, lexer._numstyles = token_styles, #default + 1 lexer._EXTRASTYLES = {} - return setmetatable(lexer, {__index = { - add_rule = M.add_rule, modify_rule = M.modify_rule, get_rule = M.get_rule, - add_style = M.add_style, add_fold_point = M.add_fold_point, - join_tokens = join_tokens, build_grammar = build_grammar, embed = M.embed, - lex = M.lex, fold = M.fold - }}) + return setmetatable(lexer, { + __index = { + add_rule = M.add_rule, modify_rule = M.modify_rule, get_rule = M.get_rule, + add_style = M.add_style, add_fold_point = M.add_fold_point, join_tokens = join_tokens, + build_grammar = build_grammar, embed = M.embed, lex = M.lex, fold = M.fold + } + }) end -- Legacy support for older lexers. --- Processes the `lex._rules`, `lex._tokenstyles`, and `lex._foldsymbols` --- tables. --- Since legacy lexers may be processed up to twice, ensure their default styles --- and rules are not processed more than once. +-- Processes the `lex._rules`, `lex._tokenstyles`, and `lex._foldsymbols` tables. Since legacy +-- lexers may be processed up to twice, ensure their default styles and rules are not processed +-- more than once. local function process_legacy_lexer(lexer) - local function warn(msg) --[[io.stderr:write(msg, "\n")]] end + local function warn(msg) --[[io.stderr:write(msg, "\n")]]end if not lexer._LEGACY then lexer._LEGACY = true warn("lexers as tables are deprecated; use 'lexer.new()'") @@ -1476,16 +1413,14 @@ local function process_legacy_lexer(lexer) setmetatable(lexer, getmetatable(M.new(''))) if lexer._rules then warn("lexer '_rules' table is deprecated; use 'add_rule()'") - for _, rule in ipairs(lexer._rules) do - lexer:add_rule(rule[1], rule[2]) - end + for _, rule in ipairs(lexer._rules) do lexer:add_rule(rule[1], rule[2]) end end end if lexer._tokenstyles then warn("lexer '_tokenstyles' table is deprecated; use 'add_style()'") for token, style in pairs(lexer._tokenstyles) do - -- If this legacy lexer is being processed a second time, only add styles - -- added since the first processing. + -- If this legacy lexer is being processed a second time, only add styles added since + -- the first processing. if not lexer._TOKENSTYLES[token] then lexer:add_style(token, style) end end end @@ -1493,14 +1428,10 @@ local function process_legacy_lexer(lexer) warn("lexer '_foldsymbols' table is deprecated; use 'add_fold_point()'") for token_name, symbols in pairs(lexer._foldsymbols) do if type(symbols) == 'table' and token_name ~= '_patterns' then - for symbol, v in pairs(symbols) do - lexer:add_fold_point(token_name, symbol, v) - end + for symbol, v in pairs(symbols) do lexer:add_fold_point(token_name, symbol, v) end end end - if lexer._foldsymbols._case_insensitive then - lexer._CASEINSENSITIVEFOLDPOINTS = true - end + if lexer._foldsymbols._case_insensitive then lexer._CASEINSENSITIVEFOLDPOINTS = true end elseif lexer._fold then lexer.fold = function(self, ...) return lexer._fold(...) end end @@ -1509,57 +1440,62 @@ end local lexers = {} -- cache of loaded lexers --- -- Initializes or loads and returns the lexer of string name *name*. --- Scintilla calls this function in order to load a lexer. Parent lexers also --- call this function in order to load child lexers and vice-versa. The user --- calls this function in order to load a lexer when using this module as a Lua --- library. +-- Scintilla calls this function in order to load a lexer. Parent lexers also call this function +-- in order to load child lexers and vice-versa. The user calls this function in order to load +-- a lexer when using Scintillua as a Lua library. -- @param name The name of the lexing language. --- @param alt_name The alternate name of the lexing language. This is useful for --- embedding the same child lexer with multiple sets of start and end tokens. --- @param cache Flag indicating whether or not to load lexers from the cache. --- This should only be `true` when initially loading a lexer (e.g. not from --- within another lexer for embedding purposes). --- The default value is `false`. +-- @param alt_name The alternate name of the lexing language. This is useful for embedding the +-- same child lexer with multiple sets of start and end tokens. +-- @param cache Flag indicating whether or not to load lexers from the cache. This should only +-- be `true` when initially loading a lexer (e.g. not from within another lexer for embedding +-- purposes). The default value is `false`. -- @return lexer object -- @name load function M.load(name, alt_name, cache) if cache and lexers[alt_name or name] then return lexers[alt_name or name] end - -- When using this module as a stand-alone module, the `property` and - -- `property_int` tables do not exist (they are not useful). Create them in - -- order prevent errors from occurring. + -- When using Scintillua as a stand-alone module, the `property`, `property_int`, and + -- `property_expanded` tables do not exist (they are not useful). Create them in order prevent + -- errors from occurring. if not M.property then - M.property = {['lexer.lpeg.home'] = package.path:gsub('/%?%.lua', '')} + M.property = setmetatable({['lexer.lpeg.home'] = package.path:gsub('/%?%.lua', '')}, { + __index = function() return '' end, + __newindex = function(t, k, v) rawset(t, k, tostring(v)) end + }) M.property_int = setmetatable({}, { __index = function(t, k) return tonumber(M.property[k]) or 0 end, __newindex = function() error('read-only property') end }) + M.property_expanded = setmetatable({}, { + __index = function(t, key) + return M.property[key]:gsub('[$%%](%b())', function(key) return t[key:sub(2, -2)] end) + end, __newindex = function() error('read-only property') end + }) end -- Load the language lexer with its rules, styles, etc. - -- However, replace the default `WHITESPACE` style name with a unique - -- whitespace style name (and then automatically add it afterwards), since - -- embedded lexing relies on these unique whitespace style names. Note that - -- loading embedded lexers changes `WHITESPACE` again, so when adding it - -- later, do not reference the potentially incorrect value. + -- However, replace the default `WHITESPACE` style name with a unique whitespace style name + -- (and then automatically add it afterwards), since embedded lexing relies on these unique + -- whitespace style names. Note that loading embedded lexers changes `WHITESPACE` again, + -- so when adding it later, do not reference the potentially incorrect value. M.WHITESPACE = (alt_name or name) .. '_whitespace' local path = M.property['lexer.lpeg.home']:gsub(';', '/?.lua;') .. '/?.lua' local lexer = dofile(assert(searchpath(name, path))) assert(lexer, string.format("'%s.lua' did not return a lexer", name)) if alt_name then lexer._NAME = alt_name end if not getmetatable(lexer) or lexer._LEGACY then - -- A legacy lexer may need to be processed a second time in order to pick up - -- any `_tokenstyles` or `_foldsymbols` added after `lexer.embed_lexer()`. + -- A legacy lexer may need to be processed a second time in order to pick up any `_tokenstyles` + -- or `_foldsymbols` added after `lexer.embed_lexer()`. process_legacy_lexer(lexer) if lexer._lexer and lexer._lexer._LEGACY then process_legacy_lexer(lexer._lexer) -- mainly for `_foldsymbols` edits end end - lexer:add_style((alt_name or name) .. '_whitespace', M.STYLE_WHITESPACE) + lexer:add_style((alt_name or name) .. '_whitespace', M.styles.whitespace) - -- If the lexer is a proxy or a child that embedded itself, set the parent to - -- be the main lexer. Keep a reference to the old parent name since embedded - -- child rules reference and use that name. + -- If the lexer is a proxy or a child that embedded itself, set the parent to be the main + -- lexer. Keep a reference to the old parent name since embedded child rules reference and + -- use that name. if lexer._lexer then lexer = lexer._lexer lexer._PARENTNAME, lexer._NAME = lexer._NAME, alt_name or name @@ -1573,43 +1509,43 @@ end -- Common patterns. M.any = lpeg_P(1) -M.ascii = lpeg_R('\000\127') -M.extend = lpeg_R('\000\255') M.alpha = lpeg_R('AZ', 'az') M.digit = lpeg_R('09') M.alnum = lpeg_R('AZ', 'az', '09') M.lower = lpeg_R('az') M.upper = lpeg_R('AZ') M.xdigit = lpeg_R('09', 'AF', 'af') -M.cntrl = lpeg_R('\000\031') M.graph = lpeg_R('!~') -M.print = lpeg_R(' ~') M.punct = lpeg_R('!/', ':@', '[\'', '{~') M.space = lpeg_S('\t\v\f\n\r ') M.newline = lpeg_P('\r')^-1 * '\n' M.nonnewline = 1 - M.newline -M.nonnewline_esc = 1 - (M.newline + '\\') + '\\' * M.any M.dec_num = M.digit^1 M.hex_num = '0' * lpeg_S('xX') * M.xdigit^1 M.oct_num = '0' * lpeg_R('07')^1 M.integer = lpeg_S('+-')^-1 * (M.hex_num + M.oct_num + M.dec_num) -M.float = lpeg_S('+-')^-1 * ( - (M.digit^0 * '.' * M.digit^1 + M.digit^1 * '.' * M.digit^0 * -lpeg_P('.')) * - (lpeg_S('eE') * lpeg_S('+-')^-1 * M.digit^1)^-1 + - (M.digit^1 * lpeg_S('eE') * lpeg_S('+-')^-1 * M.digit^1)) +M.float = lpeg_S('+-')^-1 * + ((M.digit^0 * '.' * M.digit^1 + M.digit^1 * '.' * M.digit^0 * -lpeg_P('.')) * + (lpeg_S('eE') * lpeg_S('+-')^-1 * M.digit^1)^-1 + + (M.digit^1 * lpeg_S('eE') * lpeg_S('+-')^-1 * M.digit^1)) M.number = M.float + M.integer M.word = (M.alpha + '_') * (M.alnum + '_')^0 +-- Deprecated. +M.nonnewline_esc = 1 - (M.newline + '\\') + '\\' * M.any +M.ascii = lpeg_R('\000\127') +M.extend = lpeg_R('\000\255') +M.cntrl = lpeg_R('\000\031') +M.print = lpeg_R(' ~') + --- --- Creates and returns a token pattern with token name *name* and pattern --- *patt*. --- If *name* is not a predefined token name, its style must be defined via --- `lexer.add_style()`. --- @param name The name of token. If this name is not a predefined token name, --- then a style needs to be assiciated with it via `lexer.add_style()`. +-- Creates and returns a token pattern with token name *name* and pattern *patt*. +-- If *name* is not a predefined token name, its style must be defined via `lexer.add_style()`. +-- @param name The name of token. If this name is not a predefined token name, then a style +-- needs to be assiciated with it via `lexer.add_style()`. -- @param patt The LPeg pattern associated with the token. -- @return pattern -- @usage local ws = token(lexer.WHITESPACE, lexer.space^1) @@ -1620,42 +1556,38 @@ function M.token(name, patt) end --- --- Creates and returns a pattern that matches from string or pattern *prefix* --- until the end of the line. --- *escape* indicates whether the end of the line can be escaped with a '\' --- character. +-- Creates and returns a pattern that matches from string or pattern *prefix* until the end of +-- the line. +-- *escape* indicates whether the end of the line can be escaped with a '\' character. -- @param prefix String or pattern prefix to start matching at. --- @param escape Optional flag indicating whether or not newlines can be escaped --- by a '\' character. The default value is `false`. +-- @param escape Optional flag indicating whether or not newlines can be escaped by a '\' +-- character. The default value is `false`. -- @return pattern -- @usage local line_comment = lexer.to_eol('//') --- @usage local line_comment = lexer.to_eol(P('#') + ';') +-- @usage local line_comment = lexer.to_eol(S('#;')) -- @name to_eol function M.to_eol(prefix, escape) return prefix * (not escape and M.nonnewline or M.nonnewline_esc)^0 end --- --- Creates and returns a pattern that matches a range of text bounded by strings --- or patterns *s* and *e*. --- This is a convenience function for matching more complicated ranges like --- strings with escape characters, balanced parentheses, and block comments --- (nested or not). *e* is optional and defaults to *s*. *single_line* indicates --- whether or not the range must be on a single line; *escapes* indicates --- whether or not to allow '\' as an escape character; and *balanced* indicates --- whether or not to handle balanced ranges like parentheses, and requires *s* --- and *e* to be different. +-- Creates and returns a pattern that matches a range of text bounded by strings or patterns *s* +-- and *e*. +-- This is a convenience function for matching more complicated ranges like strings with escape +-- characters, balanced parentheses, and block comments (nested or not). *e* is optional and +-- defaults to *s*. *single_line* indicates whether or not the range must be on a single line; +-- *escapes* indicates whether or not to allow '\' as an escape character; and *balanced* +-- indicates whether or not to handle balanced ranges like parentheses, and requires *s* and *e* +-- to be different. -- @param s String or pattern start of a range. -- @param e Optional string or pattern end of a range. The default value is *s*. --- @param single_line Optional flag indicating whether or not the range must be --- on a single line. --- @param escapes Optional flag indicating whether or not the range end may --- be escaped by a '\' character. --- The default value is `false` unless *s* and *e* are identical, --- single-character strings. In that case, the default value is `true`. --- @param balanced Optional flag indicating whether or not to match a balanced --- range, like the "%b" Lua pattern. This flag only applies if *s* and *e* are --- different. +-- @param single_line Optional flag indicating whether or not the range must be on a single +-- line. The default value is `false`. +-- @param escapes Optional flag indicating whether or not the range end may be escaped by a '\' +-- character. The default value is `false` unless *s* and *e* are identical, single-character +-- strings. In that case, the default value is `true`. +-- @param balanced Optional flag indicating whether or not to match a balanced range, like the +-- "%b" Lua pattern. This flag only applies if *s* and *e* are different. -- @return pattern -- @usage local dq_str_escapes = lexer.range('"') -- @usage local dq_str_noescapes = lexer.range('"', false, false) @@ -1670,8 +1602,7 @@ function M.range(s, e, single_line, escapes, balanced) if single_line then any = any - '\n' end if balanced then any = any - s end if escapes == nil then - -- Only allow escapes by default for ranges with identical, single-character - -- string delimiters. + -- Only allow escapes by default for ranges with identical, single-character string delimiters. escapes = type(s) == 'string' and #s == 1 and s == e end if escapes then any = any - '\\' + '\\' * M.any end @@ -1683,28 +1614,24 @@ function M.range(s, e, single_line, escapes, balanced) end -- Deprecated function. Use `lexer.range()` instead. --- Creates and returns a pattern that matches a range of text bounded by --- *chars* characters. --- This is a convenience function for matching more complicated delimited ranges --- like strings with escape characters and balanced parentheses. *single_line* --- indicates whether or not the range must be on a single line, *no_escape* --- indicates whether or not to ignore '\' as an escape character, and *balanced* --- indicates whether or not to handle balanced ranges like parentheses and --- requires *chars* to be composed of two characters. +-- Creates and returns a pattern that matches a range of text bounded by *chars* characters. +-- This is a convenience function for matching more complicated delimited ranges like strings +-- with escape characters and balanced parentheses. *single_line* indicates whether or not the +-- range must be on a single line, *no_escape* indicates whether or not to ignore '\' as an +-- escape character, and *balanced* indicates whether or not to handle balanced ranges like +-- parentheses and requires *chars* to be composed of two characters. -- @param chars The character(s) that bound the matched range. --- @param single_line Optional flag indicating whether or not the range must be --- on a single line. --- @param no_escape Optional flag indicating whether or not the range end --- character may be escaped by a '\\' character. --- @param balanced Optional flag indicating whether or not to match a balanced --- range, like the "%b" Lua pattern. This flag only applies if *chars* --- consists of two different characters (e.g. "()"). +-- @param single_line Optional flag indicating whether or not the range must be on a single line. +-- @param no_escape Optional flag indicating whether or not the range end character may be +-- escaped by a '\\' character. +-- @param balanced Optional flag indicating whether or not to match a balanced range, like the +-- "%b" Lua pattern. This flag only applies if *chars* consists of two different characters +-- (e.g. "()"). -- @return pattern -- @usage local dq_str_escapes = lexer.delimited_range('"') -- @usage local dq_str_noescapes = lexer.delimited_range('"', false, true) -- @usage local unbalanced_parens = lexer.delimited_range('()') --- @usage local balanced_parens = lexer.delimited_range('()', false, false, --- true) +-- @usage local balanced_parens = lexer.delimited_range('()', false, false, true) -- @see range -- @name delimited_range function M.delimited_range(chars, single_line, no_escape, balanced) @@ -1729,12 +1656,10 @@ function M.delimited_range(chars, single_line, no_escape, balanced) end --- --- Creates and returns a pattern that matches pattern *patt* only at the --- beginning of a line. +-- Creates and returns a pattern that matches pattern *patt* only at the beginning of a line. -- @param patt The LPeg pattern to match on the beginning of a line. -- @return pattern --- @usage local preproc = token(lexer.PREPROCESSOR, lexer.starts_line('#') * --- lexer.nonnewline^0) +-- @usage local preproc = token(lexer.PREPROCESSOR, lexer.starts_line(lexer.to_eol('#'))) -- @name starts_line function M.starts_line(patt) return lpeg_Cmt(lpeg_C(patt), function(input, index, match, ...) @@ -1746,12 +1671,11 @@ function M.starts_line(patt) end --- --- Creates and returns a pattern that verifies that string set *s* contains the --- first non-whitespace character behind the current match position. +-- Creates and returns a pattern that verifies the first non-whitespace character behind the +-- current match position is in string set *s*. -- @param s String character set like one passed to `lpeg.S()`. -- @return pattern --- @usage local regex = lexer.last_char_includes('+-*!%^&|=,([{') * --- lexer.range('/') +-- @usage local regex = lexer.last_char_includes('+-*!%^&|=,([{') * lexer.range('/') -- @name last_char_includes function M.last_char_includes(s) s = string.format('[%s]', s:gsub('[-%%%[]', '%%%1')) @@ -1764,10 +1688,10 @@ function M.last_char_includes(s) end -- Deprecated function. Use `lexer.range()` instead. --- Returns a pattern that matches a balanced range of text that starts with --- string *start_chars* and ends with string *end_chars*. --- With single-character delimiters, this function is identical to --- `delimited_range(start_chars .. end_chars, false, true, true)`. +-- Returns a pattern that matches a balanced range of text that starts with string *start_chars* +-- and ends with string *end_chars*. +-- With single-character delimiters, this function is identical to `delimited_range(start_chars .. +-- end_chars, false, true, true)`. -- @param start_chars The string starting a nested sequence. -- @param end_chars The string ending a nested sequence. -- @return pattern @@ -1781,39 +1705,37 @@ function M.nested_pair(start_chars, end_chars) end --- --- Creates and returns a pattern that matches any single word in string *words*. --- *case_insensitive* indicates whether or not to ignore case when matching --- words. --- This is a convenience function for simplifying a set of ordered choice word --- patterns. --- If *words* is a multi-line string, it may contain Lua line comments (`--`) --- that will ultimately be ignored. --- @param words A string list of words separated by spaces. --- @param case_insensitive Optional boolean flag indicating whether or not the --- word match is case-insensitive. The default value is `false`. +-- Creates and returns a pattern that matches any single word in list or string *words*. +-- *case_insensitive* indicates whether or not to ignore case when matching words. +-- This is a convenience function for simplifying a set of ordered choice word patterns. +-- @param word_list A list of words or a string list of words separated by spaces. +-- @param case_insensitive Optional boolean flag indicating whether or not the word match is +-- case-insensitive. The default value is `false`. -- @param word_chars Unused legacy parameter. -- @return pattern --- @usage local keyword = token(lexer.KEYWORD, word_match[[foo bar baz]]) --- @usage local keyword = token(lexer.KEYWORD, word_match([[foo-bar foo-baz --- bar-foo bar-baz baz-foo baz-bar]], true)) +-- @usage local keyword = token(lexer.KEYWORD, word_match{'foo', 'bar', 'baz'}) +-- @usage local keyword = token(lexer.KEYWORD, word_match({'foo-bar', 'foo-baz', 'bar-foo', +-- 'bar-baz', 'baz-foo', 'baz-bar'}, true)) +-- @usage local keyword = token(lexer.KEYWORD, word_match('foo bar baz')) -- @name word_match -function M.word_match(words, case_insensitive, word_chars) - local word_list = {} - if type(words) == 'table' then +function M.word_match(word_list, case_insensitive, word_chars) + if type(case_insensitive) == 'string' or type(word_chars) == 'boolean' then -- Legacy `word_match(word_list, word_chars, case_insensitive)` form. - words = table.concat(words, ' ') word_chars, case_insensitive = case_insensitive, word_chars + elseif type(word_list) == 'string' then + local words = word_list -- space-separated list of words + word_list = {} + for word in words:gsub('%-%-[^\n]+', ''):gmatch('%S+') do word_list[#word_list + 1] = word end end - for word in words:gsub('%-%-[^\n]+', ''):gmatch('%S+') do + if not word_chars then word_chars = '' end + for _, word in ipairs(word_list) do word_list[case_insensitive and word:lower() or word] = true - for char in word:gmatch('[^%w_]') do - if not (word_chars or ''):find(char, 1, true) then - word_chars = (word_chars or '') .. char - end + for char in word:gmatch('[^%w_%s]') do + if not word_chars:find(char, 1, true) then word_chars = word_chars .. char end end end local chars = M.alnum + '_' - if (word_chars or '') ~= '' then chars = chars + lpeg_S(word_chars) end + if word_chars ~= '' then chars = chars + lpeg_S(word_chars) end return lpeg_Cmt(chars^1, function(input, index, word) if case_insensitive then word = word:lower() end return word_list[word] and index or nil @@ -1821,13 +1743,11 @@ function M.word_match(words, case_insensitive, word_chars) end -- Deprecated legacy function. Use `parent:embed()` instead. --- Embeds child lexer *child* in parent lexer *parent* using patterns --- *start_rule* and *end_rule*, which signal the beginning and end of the --- embedded lexer, respectively. +-- Embeds child lexer *child* in parent lexer *parent* using patterns *start_rule* and *end_rule*, +-- which signal the beginning and end of the embedded lexer, respectively. -- @param parent The parent lexer. -- @param child The child lexer. --- @param start_rule The pattern that signals the beginning of the embedded --- lexer. +-- @param start_rule The pattern that signals the beginning of the embedded lexer. -- @param end_rule The pattern that signals the end of the embedded lexer. -- @usage lexer.embed_lexer(M, css, css_start_rule, css_end_rule) -- @usage lexer.embed_lexer(html, M, php_start_rule, php_end_rule) @@ -1881,18 +1801,17 @@ local function next_line_is_comment(prefix, text, pos, line, s) end --- --- Returns a fold function (to be passed to `lexer.add_fold_point()`) that folds --- consecutive line comments that start with string *prefix*. --- @param prefix The prefix string defining a line comment. --- @usage lex:add_fold_point(lexer.COMMENT, '--', --- lexer.fold_line_comments('--')) --- @usage lex:add_fold_point(lexer.COMMENT, '//', --- lexer.fold_line_comments('//')) --- @name fold_line_comments -function M.fold_line_comments(prefix) +-- Returns for `lexer.add_fold_point()` the parameters needed to fold consecutive lines that +-- start with string *prefix*. +-- @param prefix The prefix string (e.g. a line comment). +-- @usage lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('--')) +-- @usage lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +-- @usage lex:add_fold_point(lexer.KEYWORD, lexer.fold_consecutive_lines('import')) +-- @name fold_consecutive_lines +function M.fold_consecutive_lines(prefix) local property_int = M.property_int - return function(text, pos, line, s) - if property_int['fold.line.comments'] == 0 then return 0 end + return prefix, function(text, pos, line, s) + if property_int['fold.line.groups'] == 0 then return 0 end if s > 1 and line:match('^%s*()') < s then return 0 end local prev_line_comment = prev_line_is_comment(prefix, text, pos, line, s) local next_line_comment = next_line_is_comment(prefix, text, pos, line, s) @@ -1902,22 +1821,23 @@ function M.fold_line_comments(prefix) end end -M.property_expanded = setmetatable({}, { - -- Returns the string property value associated with string property *key*, - -- replacing any "$()" and "%()" expressions with the values of their keys. - __index = function(t, key) - return M.property[key]:gsub('[$%%]%b()', function(key) - return t[key:sub(3, -2)] - end) - end, - __newindex = function() error('read-only property') end -}) +-- Deprecated legacy function. Use `lexer.fold_consecutive_lines()` instead. +-- Returns a fold function (to be passed to `lexer.add_fold_point()`) that folds consecutive +-- line comments that start with string *prefix*. +-- @param prefix The prefix string defining a line comment. +-- @usage lex:add_fold_point(lexer.COMMENT, '--', lexer.fold_line_comments('--')) +-- @usage lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +-- @name fold_line_comments +function M.fold_line_comments(prefix) + print('lexer.fold_line_comments() is deprecated, use lexer.fold_consecutive_lines()') + return select(2, M.fold_consecutive_lines(prefix)) +end --[[ The functions and fields below were defined in C. --- --- Returns the line number (starting from 1) of the line that contains position --- *pos*, which starts from 1. +-- Returns the line number (starting from 1) of the line that contains position *pos*, which +-- starts from 1. -- @param pos The position to get the line number of. -- @return number local function line_from_position(pos) end diff --git a/syntaxhighlight/textadept/lilypond.lua b/syntaxhighlight/textadept/lilypond.lua index e90f9f1..2fbc731 100644 --- a/syntaxhighlight/textadept/lilypond.lua +++ b/syntaxhighlight/textadept/lilypond.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke. See License.txt. +-- Copyright 2006-2021 Robert Gieseke. See LICENSE. -- Lilypond LPeg lexer. -- TODO Embed Scheme; Notes?, Numbers? local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('lilypond') diff --git a/syntaxhighlight/textadept/lisp.lua b/syntaxhighlight/textadept/lisp.lua index b8584b6..f3713ba 100644 --- a/syntaxhighlight/textadept/lisp.lua +++ b/syntaxhighlight/textadept/lisp.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Lisp LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('lisp') @@ -12,32 +12,31 @@ local lex = lexer.new('lisp') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - defclass defconstant defgeneric define-compiler-macro define-condition - define-method-combination define-modify-macro define-setf-expander - define-symbol-macro defmacro defmethod defpackage defparameter defsetf - defstruct deftype defun defvar - abort assert block break case catch ccase cerror cond ctypecase declaim - declare do do* do-all-symbols do-external-symbols do-symbols dolist dotimes - ecase error etypecase eval-when flet handler-bind handler-case if - ignore-errors in-package labels lambda let let* locally loop macrolet - multiple-value-bind proclaim prog prog* prog1 prog2 progn progv provide - require restart-bind restart-case restart-name return return-from signal - symbol-macrolet tagbody the throw typecase unless unwind-protect when - with-accessors with-compilation-unit with-condition-restarts - with-hash-table-iterator with-input-from-string with-open-file - with-open-stream with-output-to-string with-package-iterator - with-simple-restart with-slots with-standard-io-syntax - t nil -]])) - -local word = lexer.alpha * (lexer.alnum + '_' + '-')^0 +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'defclass', 'defconstant', 'defgeneric', 'define-compiler-macro', 'define-condition', + 'define-method-combination', 'define-modify-macro', 'define-setf-expander', 'define-symbol-macro', + 'defmacro', 'defmethod', 'defpackage', 'defparameter', 'defsetf', 'defstruct', 'deftype', 'defun', + 'defvar', -- + 'abort', 'assert', 'block', 'break', 'case', 'catch', 'ccase', 'cerror', 'cond', 'ctypecase', + 'declaim', 'declare', 'do', 'do*', 'do-all-symbols', 'do-external-symbols', 'do-symbols', + 'dolist', 'dotimes', 'ecase', 'error', 'etypecase', 'eval-when', 'flet', 'handler-bind', + 'handler-case', 'if', 'ignore-errors', 'in-package', 'labels', 'lambda', 'let', 'let*', 'locally', + 'loop', 'macrolet', 'multiple-value-bind', 'proclaim', 'prog', 'prog*', 'prog1', 'prog2', 'progn', + 'progv', 'provide', 'require', 'restart-bind', 'restart-case', 'restart-name', 'return', + 'return-from', 'signal', 'symbol-macrolet', 'tagbody', 'the', 'throw', 'typecase', 'unless', + 'unwind-protect', 'when', 'with-accessors', 'with-compilation-unit', 'with-condition-restarts', + 'with-hash-table-iterator', 'with-input-from-string', 'with-open-file', 'with-open-stream', + 'with-output-to-string', 'with-package-iterator', 'with-simple-restart', 'with-slots', + 'with-standard-io-syntax', -- + 't', 'nil' +})) -- Identifiers. +local word = lexer.alpha * (lexer.alnum + '_' + '-')^0 lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) -- Strings. -lex:add_rule('string', token(lexer.STRING, "'" * word + lexer.range('"'))) +lex:add_rule('string', token(lexer.STRING, "'" * word + lexer.range('"') + '#\\' * lexer.any)) -- Comments. local line_comment = lexer.to_eol(';') @@ -45,12 +44,11 @@ local block_comment = lexer.range('#|', '|#') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * - (S('./') * lexer.digit^1)^-1)) +lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * (S('./') * lexer.digit^1)^-1)) -- Entities. lex:add_rule('entity', token('entity', '&' * word)) -lex:add_style('entity', lexer.STYLE_VARIABLE) +lex:add_style('entity', lexer.styles.variable) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('<>=*/+-`@%()'))) @@ -60,6 +58,6 @@ lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '#|', '|#') -lex:add_fold_point(lexer.COMMENT, ';', lexer.fold_line_comments(';')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines(';')) return lex diff --git a/syntaxhighlight/textadept/litcoffee.lua b/syntaxhighlight/textadept/litcoffee.lua index 770cdc2..341293c 100644 --- a/syntaxhighlight/textadept/litcoffee.lua +++ b/syntaxhighlight/textadept/litcoffee.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke. See License.txt. +-- Copyright 2006-2021 Robert Gieseke. See LICENSE. -- Literate CoffeeScript LPeg lexer. -- http://coffeescript.org/#literate @@ -15,9 +15,8 @@ local coffee_start_rule = token(lexer.STYLE_EMBEDDED, (P(' ')^4 + P('\t'))) local coffee_end_rule = token(lexer.STYLE_EMBEDDED, lexer.newline) lex:embed(coffeescript, coffee_start_rule, coffee_end_rule) --- Use 'markdown_whitespace' instead of lexer.WHITESPACE since the latter would --- expand to 'litcoffee_whitespace'. -lex:modify_rule('whitespace', token('markdown_whitespace', S(' \t')^1 + - S('\r\n')^1)) +-- Use 'markdown_whitespace' instead of lexer.WHITESPACE since the latter would expand to +-- 'litcoffee_whitespace'. +lex:modify_rule('whitespace', token('markdown_whitespace', S(' \t')^1 + S('\r\n')^1)) return lex diff --git a/syntaxhighlight/textadept/logtalk.lua b/syntaxhighlight/textadept/logtalk.lua index ad62bee..901a0ee 100644 --- a/syntaxhighlight/textadept/logtalk.lua +++ b/syntaxhighlight/textadept/logtalk.lua @@ -1,71 +1,63 @@ local lpeg = require('lpeg') --- Copyright © 2017-2020 Michael T. Richter . See License.txt. +-- Copyright © 2017-2021 Michael T. Richter . See LICENSE. -- Logtalk LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('logtalk', {inherit = lexer.load('prolog')}) -- add logtalk keywords to prolog ones -local directives = [[ - set_logtalk_flag object info built_in threaded uses alias use_module - coinductive export reexport public metapredicate mode meta_non_terminal - protected synchronized private module if elif else endif category protocol - end_object end_category end_protocol meta_predicate -]] +local directives = { + 'set_logtalk_flag', 'object', 'info', 'built_in', 'threaded', 'uses', 'alias', 'use_module', + 'coinductive', 'export', 'reexport', 'public', 'metapredicate', 'mode', 'meta_non_terminal', + 'protected', 'synchronized', 'private', 'module', 'if', 'elif', 'else', 'endif', 'category', + 'protocol', 'end_object', 'end_category', 'end_protocol', 'meta_predicate' +} +local indent = token(lexer.WHITESPACE, lexer.starts_line(S(' \t')^1))^-1 lex:modify_rule('directive', - ( - token(lexer.WHITESPACE, lexer.starts_line(S(' \t'))^0) * - token(lexer.OPERATOR, P':-') * - token(lexer.WHITESPACE, (S(' \t')^0)) * - token(lexer.PREPROCESSOR, P(word_match(directives))) - ) + - lex:get_rule('directive') -) + (indent * token(lexer.OPERATOR, ':-') * token(lexer.WHITESPACE, S(' \t')^0) * + token(lexer.PREPROCESSOR, word_match(directives)) +) + lex:get_rule('directive')) -- Whitespace. lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -local zero_arity_keywords = [[ +local zero_arity_keywords = { -- extracted from test document in logtalk distribution - comment argnames arguments author version date parameters parnames copyright - license remarks see_also as logtalk_make instantiation_error system_error -]] -local one_plus_arity_keywords = [[ + 'comment', 'argnames', 'arguments', 'author', 'version', 'date', 'parameters', 'parnames', + 'copyright', 'license', 'remarks', 'see_also', 'as', 'logtalk_make', 'instantiation_error', + 'system_error' +} +local one_plus_arity_keywords = { -- extracted from test document in logtalk distribution - implements imports extends instantiates specializes number_chars number_code - current_category current_object current_protocol create_category - create_object create_protocol abolish_category abolish_object - abolish_protocol category_property object_property protocol_property - extends_category extends_object extends_protocol implements_protocol - imports_category instantiates_class specializes_class complements_object - conforms_to_protocol abolish_events current_event define_events threaded - threaded_call threaded_call threaded_once threaded_ignore threaded_exit - threaded_peek threaded_cancel threaded_wait threaded_notify threaded_engine - threaded_engine_create threaded_engine_destroy threaded_engine_self - threaded_engine_next threaded_engine_next_reified threaded_engine_yield - threaded_engine_post threaded_engine_fetch logtalk_compile logtalk_load - logtalk_library_path logtalk_load_context logtalk_make_target_action - current_logtalk_flag set_logtalk_flag create_logtalk_flag context parameter - self sender this type_error domain_error existence_error permission_error - representation_error evaluation_error resource_error syntax_error bagof - findall forall setof before after forward phrase expand_term expand_goal - term_expansion goal_expansion numbervars put_code put_byte current_op op - ignore repeat number_codes current_prolog_flag set_prolog_flag keysort sort -]] -lex:modify_rule('keyword', token(lexer.KEYWORD, - word_match(zero_arity_keywords) + - (word_match(one_plus_arity_keywords) * #(P'('))) + - lex:get_rule('keyword') -) + 'implements', 'imports', 'extends', 'instantiates', 'specializes', 'number_chars', 'number_code', + 'current_category', 'current_object', 'current_protocol', 'create_category', 'create_object', + 'create_protocol', 'abolish_category', 'abolish_object', 'abolish_protocol', 'category_property', + 'object_property', 'protocol_property', 'extends_category', 'extends_object', 'extends_protocol', + 'implements_protocol', 'imports_category', 'instantiates_class', 'specializes_class', + 'complements_object', 'conforms_to_protocol', 'abolish_events', 'current_event', 'define_events', + 'threaded', 'threaded_call', 'threaded_call', 'threaded_once', 'threaded_ignore', 'threaded_exit', + 'threaded_peek', 'threaded_cancel', 'threaded_wait', 'threaded_notify', 'threaded_engine', + 'threaded_engine_create', 'threaded_engine_destroy', 'threaded_engine_self', + 'threaded_engine_next', 'threaded_engine_next_reified', 'threaded_engine_yield', + 'threaded_engine_post', 'threaded_engine_fetch', 'logtalk_compile', 'logtalk_load', + 'logtalk_library_path', 'logtalk_load_context', 'logtalk_make_target_action', + 'current_logtalk_flag', 'set_logtalk_flag', 'create_logtalk_flag', 'context', 'parameter', 'self', + 'sender', 'this', 'type_error', 'domain_error', 'existence_error', 'permission_error', + 'representation_error', 'evaluation_error', 'resource_error', 'syntax_error', 'bagof', 'findall', + 'forall', 'setof', 'before', 'after', 'forward', 'phrase', 'expand_term', 'expand_goal', + 'term_expansion', 'goal_expansion', 'numbervars', 'put_code', 'put_byte', 'current_op', 'op', + 'ignore', 'repeat', 'number_codes', 'current_prolog_flag', 'set_prolog_flag', 'keysort', 'sort' +} +local keyword = word_match(zero_arity_keywords) + (word_match(one_plus_arity_keywords) * #P('(')) +lex:modify_rule('keyword', token(lexer.KEYWORD, keyword) + lex:get_rule('keyword')) -local operators = [[ +local operators = { -- extracted from test document in logtalk distribution - as -]] -lex:modify_rule('operator', token(lexer.OPERATOR, word_match(operators)) + - lex:get_rule('operator')) + 'as' +} +lex:modify_rule('operator', token(lexer.OPERATOR, word_match(operators)) + lex:get_rule('operator')) return lex diff --git a/syntaxhighlight/textadept/lua.lua b/syntaxhighlight/textadept/lua.lua index 72b7de3..5defcb9 100644 --- a/syntaxhighlight/textadept/lua.lua +++ b/syntaxhighlight/textadept/lua.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Lua LPeg lexer. -- Original written by Peter Odding, 2007/04/04. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local B, P, S = lpeg.B, lpeg.P, lpeg.S local lex = lexer.new('lua') @@ -13,114 +13,117 @@ local lex = lexer.new('lua') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and break do else elseif end false for function if in local nil not or repeat - return then true until while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'if', 'in', 'local', + 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while', -- Added in 5.2. - goto -]])) + 'goto' +})) -- Functions and deprecated functions. -local func = token(lexer.FUNCTION, word_match[[ - assert collectgarbage dofile error getmetatable ipairs load loadfile next - pairs pcall print rawequal rawget rawset require select setmetatable tonumber - tostring type xpcall +local func = token(lexer.FUNCTION, word_match{ + 'assert', 'collectgarbage', 'dofile', 'error', 'getmetatable', 'ipairs', 'load', 'loadfile', + 'next', 'pairs', 'pcall', 'print', 'rawequal', 'rawget', 'rawset', 'require', 'select', + 'setmetatable', 'tonumber', 'tostring', 'type', 'xpcall', -- Added in 5.2. - rawlen -]]) -local deprecated_func = token('deprecated_function', word_match[[ + 'rawlen', + -- Added in 5.4. + 'warn' +}) +local deprecated_func = token('deprecated_function', word_match{ -- Deprecated in 5.2. - getfenv loadstring module setfenv unpack -]]) -lex:add_rule('function', func + deprecated_func) -lex:add_style('deprecated_function', lexer.STYLE_FUNCTION .. ',italics') + 'getfenv', 'loadstring', 'module', 'setfenv', 'unpack' +}) +lex:add_rule('function', -B('.') * (func + deprecated_func)) +lex:add_style('deprecated_function', lexer.styles['function'] .. {italics = true}) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - _G _VERSION +lex:add_rule('constant', token(lexer.CONSTANT, -B('.') * word_match{ + '_G', '_VERSION', -- Added in 5.2. - _ENV -]])) + '_ENV' +})) -- Libraries and deprecated libraries. -local library = token('library', word_match[[ +local library = token('library', word_match{ -- Coroutine. - coroutine coroutine.create coroutine.resume coroutine.running coroutine.status - coroutine.wrap coroutine.yield + 'coroutine', 'coroutine.create', 'coroutine.resume', 'coroutine.running', 'coroutine.status', + 'coroutine.wrap', 'coroutine.yield', -- Coroutine added in 5.3. - coroutine.isyieldable + 'coroutine.isyieldable', + -- Coroutine added in 5.4. + 'coroutine.close', -- Module. - package package.cpath package.loaded package.loadlib package.path - package.preload + 'package', 'package.cpath', 'package.loaded', 'package.loadlib', 'package.path', + 'package.preload', -- Module added in 5.2. - package.config package.searchers package.searchpath + 'package.config', 'package.searchers', 'package.searchpath', -- UTF-8 added in 5.3. - utf8 utf8.char utf8.charpattern utf8.codepoint utf8.codes utf8.len utf8.offset + 'utf8', 'utf8.char', 'utf8.charpattern', 'utf8.codepoint', 'utf8.codes', 'utf8.len', + 'utf8.offset', -- String. - string string.byte string.char string.dump string.find string.format - string.gmatch string.gsub string.len string.lower string.match string.rep - string.reverse string.sub string.upper + 'string', 'string.byte', 'string.char', 'string.dump', 'string.find', 'string.format', + 'string.gmatch', 'string.gsub', 'string.len', 'string.lower', 'string.match', 'string.rep', + 'string.reverse', 'string.sub', 'string.upper', -- String added in 5.3. - string.pack string.packsize string.unpack + 'string.pack', 'string.packsize', 'string.unpack', -- Table. - table table.concat table.insert table.remove table.sort + 'table', 'table.concat', 'table.insert', 'table.remove', 'table.sort', -- Table added in 5.2. - table.pack table.unpack + 'table.pack', 'table.unpack', -- Table added in 5.3. - table.move + 'table.move', -- Math. - math math.abs math.acos math.asin math.atan math.ceil math.cos math.deg - math.exp math.floor math.fmod math.huge math.log math.max math.min math.modf - math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan + 'math', 'math.abs', 'math.acos', 'math.asin', 'math.atan', 'math.ceil', 'math.cos', 'math.deg', + 'math.exp', 'math.floor', 'math.fmod', 'math.huge', 'math.log', 'math.max', 'math.min', + 'math.modf', 'math.pi', 'math.rad', 'math.random', 'math.randomseed', 'math.sin', 'math.sqrt', + 'math.tan', -- Math added in 5.3. - math.maxinteger math.mininteger math.tointeger math.type math.ult + 'math.maxinteger', 'math.mininteger', 'math.tointeger', 'math.type', 'math.ult', -- IO. - io io.close io.flush io.input io.lines io.open io.output io.popen io.read - io.stderr io.stdin io.stdout io.tmpfile io.type io.write + 'io', 'io.close', 'io.flush', 'io.input', 'io.lines', 'io.open', 'io.output', 'io.popen', + 'io.read', 'io.stderr', 'io.stdin', 'io.stdout', 'io.tmpfile', 'io.type', 'io.write', -- OS. - os os.clock os.date os.difftime os.execute os.exit os.getenv os.remove - os.rename os.setlocale os.time os.tmpname + 'os', 'os.clock', 'os.date', 'os.difftime', 'os.execute', 'os.exit', 'os.getenv', 'os.remove', + 'os.rename', 'os.setlocale', 'os.time', 'os.tmpname', -- Debug. - debug debug.debug debug.gethook debug.getinfo debug.getlocal - debug.getmetatable debug.getregistry debug.getupvalue debug.sethook - debug.setlocal debug.setmetatable debug.setupvalue debug.traceback + 'debug', 'debug.debug', 'debug.gethook', 'debug.getinfo', 'debug.getlocal', 'debug.getmetatable', + 'debug.getregistry', 'debug.getupvalue', 'debug.sethook', 'debug.setlocal', 'debug.setmetatable', + 'debug.setupvalue', 'debug.traceback', -- Debug added in 5.2. - debug.getuservalue debug.setuservalue debug.upvalueid debug.upvaluejoin -]]) -local deprecated_library = token('deprecated_library', word_match[[ + 'debug.getuservalue', 'debug.setuservalue', 'debug.upvalueid', 'debug.upvaluejoin' +}) +local deprecated_library = token('deprecated_library', word_match{ -- Module deprecated in 5.2. - package.loaders package.seeall + 'package.loaders', 'package.seeall', -- Table deprecated in 5.2. - table.maxn + 'table.maxn', -- Math deprecated in 5.2. - math.log10 + 'math.log10', -- Math deprecated in 5.3. - math.atan2 math.cosh math.frexp math.ldexp math.pow math.sinh math.tanh + 'math.atan2', 'math.cosh', 'math.frexp', 'math.ldexp', 'math.pow', 'math.sinh', 'math.tanh', -- Bit32 deprecated in 5.3. - bit32 bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.extract - bit32.lrotate bit32.lshift bit32.replace bit32.rrotate bit32.rshift bit32.xor + 'bit32', 'bit32.arshift', 'bit32.band', 'bit32.bnot', 'bit32.bor', 'bit32.btest', 'bit32.extract', + 'bit32.lrotate', 'bit32.lshift', 'bit32.replace', 'bit32.rrotate', 'bit32.rshift', 'bit32.xor', -- Debug deprecated in 5.2. - debug.getfenv debug.setfenv -]]) -lex:add_rule('library', library + deprecated_library) -lex:add_style('library', lexer.STYLE_TYPE) -lex:add_style('deprecated_library', lexer.STYLE_TYPE .. ',italics') + 'debug.getfenv', 'debug.setfenv' +}) +lex:add_rule('library', -B('.') * (library + deprecated_library)) +lex:add_style('library', lexer.styles.type) +lex:add_style('deprecated_library', lexer.styles.type .. {italics = true}) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[', - function(input, index, eq) - local _, e = input:find(']' .. eq .. ']', index, true) - return (e or #input) + 1 - end) - -- Strings. local sq_str = lexer.range("'") local dq_str = lexer.range('"') -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str) + - token('longstring', longstring)) -lex:add_style('longstring', lexer.STYLE_STRING) +local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[', function(input, index, eq) + local _, e = input:find(']' .. eq .. ']', index, true) + return (e or #input) + 1 +end) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str) + token('longstring', longstring)) +lex:add_style('longstring', lexer.styles.string) -- Comments. local line_comment = lexer.to_eol('--') @@ -134,9 +137,13 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.float + lua_integer)) -- Labels. lex:add_rule('label', token(lexer.LABEL, '::' * lexer.word * '::')) +-- Attributes. +lex:add_rule('attribute', token('attribute', '<' * lexer.space^0 * word_match('const close') * + lexer.space^0 * '>')) +lex:add_style('attribute', lexer.styles.class) + -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, '..' + - S('+-*/%^#=<>&|~;:,.{}[]()'))) +lex:add_rule('operator', token(lexer.OPERATOR, '..' + S('+-*/%^#=<>&|~;:,.{}[]()'))) -- Fold points. local function fold_longcomment(text, pos, line, s, symbol) @@ -153,7 +160,7 @@ lex:add_fold_point(lexer.KEYWORD, 'function', 'end') lex:add_fold_point(lexer.KEYWORD, 'repeat', 'until') lex:add_fold_point(lexer.COMMENT, '[', fold_longcomment) lex:add_fold_point(lexer.COMMENT, ']', fold_longcomment) -lex:add_fold_point(lexer.COMMENT, '--', lexer.fold_line_comments('--')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('--')) lex:add_fold_point('longstring', '[', ']') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') diff --git a/syntaxhighlight/textadept/makefile.lua b/syntaxhighlight/textadept/makefile.lua index 13bfdd0..dcd97ef 100644 --- a/syntaxhighlight/textadept/makefile.lua +++ b/syntaxhighlight/textadept/makefile.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Makefile LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('makefile', {lex_by_line = true}) @@ -13,63 +13,61 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, P('!')^-1 * word_match([[ +lex:add_rule('keyword', token(lexer.KEYWORD, P('!')^-1 * word_match({ -- GNU Make conditionals. - ifeq ifneq ifdef ifndef else endif + 'ifeq', 'ifneq', 'ifdef', 'ifndef', 'else', 'endif', -- Other conditionals. - if elseif elseifdef elseifndef + 'if', 'elseif', 'elseifdef', 'elseifndef', -- Directives and other keywords. - define endef export include override private undefine unexport vpath -]], true))) + 'define', 'endef', 'export', 'include', 'override', 'private', 'undefine', 'unexport', 'vpath' +}, true))) -- Targets. -local special_target = token(lexer.CONSTANT, word_match[[ - .PHONY .SUFFIXES .DEFAULT .PRECIOUS .INTERMEDIATE .SECONDARY .SECONDEXPANSION - .DELETE_ON_ERROR .IGNORE .LOW_RESOLUTION_TIME .SILENT .EXPORT_ALL_VARIABLES - .NOTPARALLEL .ONESHELL .POSIX -]]) +local special_target = token(lexer.CONSTANT, word_match{ + '.PHONY', '.SUFFIXES', '.DEFAULT', '.PRECIOUS', '.INTERMEDIATE', '.SECONDARY', '.SECONDEXPANSION', + '.DELETE_ON_ERROR', '.IGNORE', '.LOW_RESOLUTION_TIME', '.SILENT', '.EXPORT_ALL_VARIABLES', + '.NOTPARALLEL', '.ONESHELL', '.POSIX' +}) local normal_target = token('target', (lexer.any - lexer.space - S(':#='))^1) -lex:add_rule('target', lexer.starts_line((special_target + normal_target) * - ws^0 * #(':' * -P('=')))) -lex:add_style('target', lexer.STYLE_LABEL) +local target_list = normal_target * (ws * normal_target)^0 +lex:add_rule('target', lexer.starts_line((special_target + target_list) * ws^0 * #(':' * -P('=')))) +lex:add_style('target', lexer.styles.label) -- Variables. local word_char = lexer.any - lexer.space - S(':#=(){}') local assign = S(':+?')^-1 * '=' local expanded_var = '$' * ('(' * word_char^1 * ')' + '{' * word_char^1 * '}') local auto_var = '$' * S('@%. See License.txt. +-- Copyright 2015-2021 David B. Lamkins . See LICENSE. -- man/roff LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('man') @@ -12,16 +12,12 @@ local lex = lexer.new('man') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Markup. -lex:add_rule('rule1', token(lexer.STRING, '.' * - lexer.to_eol('B' * P('R')^-1 + 'I' * P('PR')^-1))) +lex:add_rule('rule1', token(lexer.STRING, '.' * lexer.to_eol('B' * P('R')^-1 + 'I' * P('PR')^-1))) lex:add_rule('rule2', token(lexer.NUMBER, lexer.to_eol('.' * S('ST') * 'H'))) -lex:add_rule('rule3', token(lexer.KEYWORD, P('.br') + '.DS' + '.RS' + '.RE' + - '.PD')) +lex:add_rule('rule3', token(lexer.KEYWORD, P('.br') + '.DS' + '.RS' + '.RE' + '.PD')) lex:add_rule('rule4', token(lexer.LABEL, '.' * (S('ST') * 'H' + '.TP'))) -lex:add_rule('rule5', token(lexer.VARIABLE, '.B' * P('R')^-1 + - '.I' * S('PR')^-1 + '.PP')) +lex:add_rule('rule5', token(lexer.VARIABLE, '.B' * P('R')^-1 + '.I' * S('PR')^-1 + '.PP')) lex:add_rule('rule6', token(lexer.TYPE, '\\f' * S('BIPR'))) -lex:add_rule('rule7', token(lexer.PREPROCESSOR, lexer.starts_line('.') * - lexer.alpha^1)) +lex:add_rule('rule7', token(lexer.PREPROCESSOR, lexer.starts_line('.') * lexer.alpha^1)) return lex diff --git a/syntaxhighlight/textadept/markdown.lua b/syntaxhighlight/textadept/markdown.lua index a715e56..cad449b 100644 --- a/syntaxhighlight/textadept/markdown.lua +++ b/syntaxhighlight/textadept/markdown.lua @@ -1,49 +1,52 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Markdown LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('markdown') -- Block elements. -local function h(n) - return token('h' .. n, lexer.to_eol(lexer.starts_line(string.rep('#', n)))) -end +local function h(n) return token('h' .. n, lexer.to_eol(lexer.starts_line(string.rep('#', n)))) end lex:add_rule('header', h(6) + h(5) + h(4) + h(3) + h(2) + h(1)) +local font_size = tonumber(lexer.property_expanded['style.default']:match('size:(%d+)')) or 10 local function add_header_style(n) - local font_size = lexer.property_int['fontsize'] > 0 and - lexer.property_int['fontsize'] or 10 - lex:add_style('h' .. n, 'fore:$(color.red),size:' .. (font_size + (6 - n))) + lex:add_style('h' .. n, {fore = lexer.colors.red, size = (font_size + (6 - n))}) end for i = 1, 6 do add_header_style(i) end -lex:add_rule('blockquote', token(lexer.STRING, - lpeg.Cmt(lexer.starts_line(S(' \t')^0 * '>'), function(input, index) +lex:add_rule('blockquote', + token(lexer.STRING, lpeg.Cmt(lexer.starts_line(S(' \t')^0 * '>'), function(input, index) local _, e = input:find('\n[ \t]*\r?\n', index) return (e or #input) + 1 end))) lex:add_rule('list', token('list', - lexer.starts_line(S(' \t')^0 * (S('*+-') + R('09')^1 * '.')) * S(' \t'))) -lex:add_style('list', lexer.STYLE_CONSTANT) - -local code_line = lexer.to_eol(lexer.starts_line(P(' ')^4 + '\t') * -P('<')) * - lexer.newline^-1 -local code_block = lexer.range(lexer.starts_line('```'), '```') -local code_inline = lexer.range('``') + lexer.range('`', false, false) + lexer.starts_line(S(' \t')^0 * (S('*+-') + lexer.digit^1 * '.')) * S(' \t'))) +lex:add_style('list', lexer.styles.constant) + +local hspace = S('\t\v\f\r ') +local blank_line = '\n' * hspace^0 * ('\n' + P(-1)) + +local code_line = lexer.to_eol(lexer.starts_line(P(' ')^4 + '\t') * -P('<')) * lexer.newline^-1 +local code_block = lexer.range(lexer.starts_line('```'), '\n```' * hspace^0 * ('\n' + P(-1))) +local code_inline = lpeg.Cmt(lpeg.C(P('`')^1), function(input, index, bt) + -- `foo`, ``foo``, ``foo`bar``, `foo``bar` are all allowed. + local _, e = input:find('[^`]' .. bt .. '%f[^`]', index) + return (e or #input) + 1 +end) lex:add_rule('block_code', token('code', code_line + code_block + code_inline)) -lex:add_style('code', lexer.STYLE_EMBEDDED .. ',eolfilled') +lex:add_style('code', lexer.styles.embedded .. {eolfilled = true}) -lex:add_rule('hr', token('hr', lpeg.Cmt( - lexer.starts_line(S(' \t')^0 * lpeg.C(S('*-_'))), function(input, index, c) +lex:add_rule('hr', + token('hr', lpeg.Cmt(lexer.starts_line(S(' \t')^0 * lpeg.C(S('*-_'))), function(input, index, c) local line = input:match('[^\r\n]*', index):gsub('[ \t]', '') if line:find('[^' .. c .. ']') or #line < 2 then return nil end return (select(2, input:find('\r?\n', index)) or #input) + 1 end))) -lex:add_style('hr', 'back:$(color.black),eolfilled') +lex:add_style('hr', {back = lexer.colors.black, eolfilled = true}) -- Whitespace. local ws = token(lexer.WHITESPACE, S(' \t')^1 + S('\v\r\n')^1) @@ -56,50 +59,47 @@ local ref_link_label = token('link_label', lexer.range('[', ']', true) * ':') local ref_link_url = token('link_url', (lexer.any - lexer.space)^1) local ref_link_title = token(lexer.STRING, lexer.range('"', true, false) + lexer.range("'", true, false) + lexer.range('(', ')', true)) -lex:add_rule('link_label', ref_link_label * ws * ref_link_url * - (ws * ref_link_title)^-1) -lex:add_style('link_label', lexer.STYLE_LABEL) -lex:add_style('link_url', 'underlined') +lex:add_rule('link_label', ref_link_label * ws * ref_link_url * (ws * ref_link_title)^-1) +lex:add_style('link_label', lexer.styles.label) +lex:add_style('link_url', {underlined = true}) local link_label = P('!')^-1 * lexer.range('[', ']', true) -local link_target = P('(') * (lexer.any - S(') \t'))^0 * - (S(' \t')^1 * lexer.range('"', false, false))^-1 * ')' +local link_target = + '(' * (lexer.any - S(') \t'))^0 * (S(' \t')^1 * lexer.range('"', false, false))^-1 * ')' local link_ref = S(' \t')^0 * lexer.range('[', ']', true) -local link_url = 'http' * P('s')^-1 * '://' * (lexer.any - lexer.space)^1 -lex:add_rule('link', token('link', link_label * (link_target + link_ref) + - link_url)) -lex:add_style('link', 'underlined') +local link_url = 'http' * P('s')^-1 * '://' * (lexer.any - lexer.space)^1 + + ('<' * lexer.alpha^2 * ':' * (lexer.any - lexer.space - '>')^1 * '>') +lex:add_rule('link', token('link', link_label * (link_target + link_ref) + link_url)) +lex:add_style('link', {underlined = true}) local punct_space = lexer.punct + lexer.space -- Handles flanking delimiters as described in --- https://github.github.com/gfm/#emphasis-and-strong-emphasis in the cases --- where simple delimited ranges are not sufficient. +-- https://github.github.com/gfm/#emphasis-and-strong-emphasis in the cases where simple +-- delimited ranges are not sufficient. local function flanked_range(s, not_inword) local fl_char = lexer.any - s - lexer.space - local left_fl = lpeg.B(punct_space - s) * s * #fl_char + - s * #(fl_char - lexer.punct) - local right_fl = lpeg.B(lexer.punct) * s * #(punct_space - s) + - lpeg.B(fl_char) * s - return left_fl * (lexer.any - (not_inword and s * #punct_space or s))^0 * - right_fl + local left_fl = lpeg.B(punct_space - s) * s * #fl_char + s * #(fl_char - lexer.punct) + local right_fl = lpeg.B(lexer.punct) * s * #(punct_space - s) + lpeg.B(fl_char) * s + return left_fl * (lexer.any - blank_line - (not_inword and s * #punct_space or s))^0 * right_fl end -lex:add_rule('strong', token('strong', flanked_range('**') + - (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('__', true) * - #(punct_space + -1))) -lex:add_style('strong', 'bold') +local asterisk_strong = flanked_range('**') +local underscore_strong = (lpeg.B(punct_space) + #lexer.starts_line('_')) * + flanked_range('__', true) * #(punct_space + -1) +lex:add_rule('strong', token('strong', asterisk_strong + underscore_strong)) +lex:add_style('strong', {bold = true}) -lex:add_rule('em', token('em', flanked_range('*') + - (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * - #(punct_space + -1))) -lex:add_style('em', 'italics') +local asterisk_em = flanked_range('*') +local underscore_em = (lpeg.B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * + #(punct_space + -1) +lex:add_rule('em', token('em', asterisk_em + underscore_em)) +lex:add_style('em', {italics = true}) -- Embedded HTML. local html = lexer.load('html') -local start_rule = lexer.starts_line(S(' \t')^0) * #P('<') * - html:get_rule('element') -local end_rule = token(lexer.DEFAULT, P('\n')) -- TODO: lexer.WHITESPACE errors +local start_rule = lexer.starts_line(P(' ')^-3) * #P('<') * html:get_rule('element') -- P(' ')^4 starts code_line +local end_rule = token(lexer.DEFAULT, blank_line) -- TODO: lexer.WHITESPACE errors lex:embed(html, start_rule, end_rule) return lex diff --git a/syntaxhighlight/textadept/matlab.lua b/syntaxhighlight/textadept/matlab.lua index 9e0ada8..3777c0c 100644 --- a/syntaxhighlight/textadept/matlab.lua +++ b/syntaxhighlight/textadept/matlab.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Martin Morawetz. See License.txt. +-- Copyright 2006-2021 Martin Morawetz. See LICENSE. -- Matlab LPeg lexer. -- Based off of lexer code by Mitchell. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('matlab') @@ -13,43 +13,42 @@ local lex = lexer.new('matlab') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - break case catch continue do else elseif end end_try_catch end_unwind_protect - endfor endif endswitch endwhile for function endfunction global if otherwise - persistent replot return static switch try until unwind_protect - unwind_protect_cleanup varargin varargout while -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'break', 'case', 'catch', 'continue', 'do', 'else', 'elseif', 'end', 'end_try_catch', + 'end_unwind_protect', 'endfor', 'endif', 'endswitch', 'endwhile', 'for', 'function', + 'endfunction', 'global', 'if', 'otherwise', 'persistent', 'replot', 'return', 'static', 'switch', + 'try', 'until', 'unwind_protect', 'unwind_protect_cleanup', 'varargin', 'varargout', 'while' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs any argvatan2 axes axis ceil cla clear clf columns cos delete diff disp - doc double drawnow exp figure find fix floor fprintf gca gcf get grid help - hist hold isempty isnull length load log log10 loglog max mean median min mod - ndims numel num2str ones pause plot printf quit rand randn rectangle rem - repmat reshape round rows save semilogx semilogy set sign sin size sizeof - size_equal sort sprintf squeeze sqrt std strcmp subplot sum tan tic title toc - uicontrol who xlabel ylabel zeros -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'any', 'argvatan2', 'axes', 'axis', 'ceil', 'cla', 'clear', 'clf', 'columns', 'cos', + 'delete', 'diff', 'disp', 'doc', 'double', 'drawnow', 'exp', 'figure', 'find', 'fix', 'floor', + 'fprintf', 'gca', 'gcf', 'get', 'grid', 'help', 'hist', 'hold', 'isempty', 'isnull', 'length', + 'load', 'log', 'log10', 'loglog', 'max', 'mean', 'median', 'min', 'mod', 'ndims', 'numel', + 'num2str', 'ones', 'pause', 'plot', 'printf', 'quit', 'rand', 'randn', 'rectangle', 'rem', + 'repmat', 'reshape', 'round', 'rows', 'save', 'semilogx', 'semilogy', 'set', 'sign', 'sin', + 'size', 'sizeof', 'size_equal', 'sort', 'sprintf', 'squeeze', 'sqrt', 'std', 'strcmp', 'subplot', + 'sum', 'tan', 'tic', 'title', 'toc', 'uicontrol', 'who', 'xlabel', 'ylabel', 'zeros' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - EDITOR I IMAGEPATH INFO_FILE J LOADPATH OCTAVE_VERSION PAGER PS1 PS2 PS4 PWD -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match( + 'EDITOR I IMAGEPATH INFO_FILE J LOADPATH OCTAVE_VERSION PAGER PS1 PS2 PS4 PWD'))) -- Variable. -lex:add_rule('variable', token(lexer.VARIABLE, word_match[[ - ans automatic_replot default_return_value do_fortran_indexing - define_all_return_values empty_list_elements_ok eps false gnuplot_binary - ignore_function_time_stamp implicit_str_to_num_ok Inf inf NaN nan - ok_to_lose_imaginary_part output_max_field_width output_precision - page_screen_output pi prefer_column_vectors prefer_zero_one_indexing - print_answer_id_name print_empty_dimensions realmax realmin - resize_on_range_error return_last_computed_value save_precision - silent_functions split_long_rows suppress_verbose_help_message - treat_neg_dim_as_zero true warn_assign_as_truth_value - warn_comma_in_global_decl warn_divide_by_zero warn_function_name_clash - whitespace_in_literal_matrix -]])) +lex:add_rule('variable', token(lexer.VARIABLE, word_match{ + 'ans', 'automatic_replot', 'default_return_value', 'do_fortran_indexing', + 'define_all_return_values', 'empty_list_elements_ok', 'eps', 'false', 'gnuplot_binary', + 'ignore_function_time_stamp', 'implicit_str_to_num_ok', 'Inf', 'inf', 'NaN', 'nan', + 'ok_to_lose_imaginary_part', 'output_max_field_width', 'output_precision', 'page_screen_output', + 'pi', 'prefer_column_vectors', 'prefer_zero_one_indexing', 'print_answer_id_name', + 'print_empty_dimensions', 'realmax', 'realmin', 'resize_on_range_error', + 'return_last_computed_value', 'save_precision', 'silent_functions', 'split_long_rows', + 'suppress_verbose_help_message', 'treat_neg_dim_as_zero', 'true', 'warn_assign_as_truth_value', + 'warn_comma_in_global_decl', 'warn_divide_by_zero', 'warn_function_name_clash', + 'whitespace_in_literal_matrix' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -61,7 +60,7 @@ local bq_str = lexer.range('`') lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str)) -- Comments. -local line_comment = lexer.to_eol(P('%') + '#') +local line_comment = lexer.to_eol(S('%#')) local block_comment = lexer.range('%{', '%}') lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) @@ -69,8 +68,7 @@ lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('!%^&*()[]{}-=+/\\|:;.,?<>~`´'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/\\|:;.,?<>~`´'))) -- Fold points. lex:add_fold_point(lexer.KEYWORD, 'if', 'end') @@ -80,7 +78,7 @@ lex:add_fold_point(lexer.KEYWORD, 'switch', 'end') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.COMMENT, '%{', '%}') -lex:add_fold_point(lexer.COMMENT, '%', lexer.fold_line_comments('%')) -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/mediawiki.lua b/syntaxhighlight/textadept/mediawiki.lua index cee802c..2564863 100644 --- a/syntaxhighlight/textadept/mediawiki.lua +++ b/syntaxhighlight/textadept/mediawiki.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- MediaWiki LPeg lexer. -- Contributed by Alexander Misel. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, B = lpeg.P, lpeg.R, lpeg.S, lpeg.B +local P, S, B = lpeg.P, lpeg.S, lpeg.B local lex = lexer.new('mediawiki') @@ -13,42 +13,36 @@ local lex = lexer.new('mediawiki') lex:add_rule('comment', token(lexer.COMMENT, lexer.range(''))) -- HTML-like tags -local tag_start = token('tag_start', '<' * P('/')^-1 * lexer.alnum^1 * - lexer.space^0) +local tag_start = token('tag_start', '<' * P('/')^-1 * lexer.alnum^1 * lexer.space^0) +local dq_str = '"' * ((lexer.any - S('>"\\')) + ('\\' * lexer.any))^0 * '"' local tag_attr = token('tag_attr', lexer.alpha^1 * lexer.space^0 * - ('=' * lexer.space^0 * - ('"' * ((lexer.any - S('>"\\')) + ('\\' * lexer.any))^0 * '"' + - (lexer.any - lexer.space - '>')^0)^-1)^0 * lexer.space^0) + ('=' * lexer.space^0 * (dq_str + (lexer.any - lexer.space - '>')^0)^-1)^0 * lexer.space^0) local tag_end = token('tag_end', P('/')^-1 * '>') lex:add_rule('tag', tag_start * tag_attr^0 * tag_end) -lex:add_style('tag_start', lexer.STYLE_KEYWORD) -lex:add_style('tag_attr', lexer.STYLE_TYPE) -lex:add_style('tag_end', lexer.STYLE_KEYWORD) +lex:add_style('tag_start', lexer.styles.keyword) +lex:add_style('tag_attr', lexer.styles.type) +lex:add_style('tag_end', lexer.styles.keyword) -- Link lex:add_rule('link', token(lexer.STRING, S('[]'))) -lex:add_rule('internal_link', B('[[') * - token('link_article', (lexer.any - '|' - ']]')^1)) -lex:add_style('link_article', lexer.STYLE_STRING .. ',underlined') +lex:add_rule('internal_link', B('[[') * token('link_article', (lexer.any - '|' - ']]')^1)) +lex:add_style('link_article', lexer.styles.string .. {underlined = true}) -- Templates and parser functions. lex:add_rule('template', token(lexer.OPERATOR, S('{}'))) -lex:add_rule('parser_func', B('{{') * - token('parser_func', P('#') * lexer.alpha^1 + lexer.upper^1 * ':')) -lex:add_rule('template_name', B('{{') * - token('template_name', (lexer.any - S('{}|'))^1)) -lex:add_style('parser_func', lexer.STYLE_FUNCTION) -lex:add_style('template_name', lexer.STYLE_OPERATOR .. ',underlined') +lex:add_rule('parser_func', + B('{{') * token('parser_func', '#' * lexer.alpha^1 + lexer.upper^1 * ':')) +lex:add_rule('template_name', B('{{') * token('template_name', (lexer.any - S('{}|'))^1)) +lex:add_style('parser_func', lexer.styles['function']) +lex:add_style('template_name', lexer.styles.operator .. {underlined = true}) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('-=|#~!'))) -- Behavior switches local start_pat = P(function(_, pos) return pos == 1 end) -lex:add_rule('behavior_switch', (B(lexer.space) + start_pat) * - token('behavior_switch', '__' * - (P('TOC') + 'FORCETOC' + 'NOTOC' + 'NOEDITSECTION' + 'NOCC' + 'NOINDEX') * - '__') * #lexer.space) -lex:add_style('behavior_switch', lexer.STYLE_KEYWORD) +lex:add_rule('behavior_switch', (B(lexer.space) + start_pat) * token('behavior_switch', word_match( + '__TOC__ __FORCETOC__ __NOTOC__ __NOEDITSECTION__ __NOCC__ __NOINDEX__')) * #lexer.space) +lex:add_style('behavior_switch', lexer.styles.keyword) return lex diff --git a/syntaxhighlight/textadept/meson.lua b/syntaxhighlight/textadept/meson.lua new file mode 100644 index 0000000..bc99760 --- /dev/null +++ b/syntaxhighlight/textadept/meson.lua @@ -0,0 +1,127 @@ +local lpeg = require('lpeg') +-- Copyright 2020-2021 Florian Fischer. See LICENSE. +-- Meson file LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('meson', {fold_by_indentation = true}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'and or not if elif else endif foreach break continue endforeach'))) + +-- Methods. +-- https://mesonbuild.com/Reference-manual.html#builtin-objects +-- https://mesonbuild.com/Reference-manual.html#returned-objects +local method_names = word_match{ + -- array -- + 'contains', 'get', 'length', + -- boolean -- + 'to_int', 'to_string', + -- dictionary -- + 'has_key', 'get', 'keys', + -- disabler -- + 'found', + -- integer -- + 'is_even', 'is_odd', + -- string -- + 'contains', 'endswith', 'format', 'join', 'split', 'startswith', 'substring', 'strip', 'to_int', + 'to_lower', 'to_upper', 'underscorify', 'version_compare', + -- meson object -- + 'add_dist_script', 'add_install_script', 'add_postconf_script', 'backend', 'build_root', + 'source_root', 'project_build_root', 'project_source_root', 'current_build_dir', + 'current_source_dir', 'get_compiler', 'get_cross_property', 'get_external_property', + 'can_run_host_binaries', 'has_exe_wrapper', 'install_dependency_manifest', 'is_cross_build', + 'is_subproject', 'is_unity', 'override_find_program', 'override_dependency', 'project_version', + 'project_license', 'project_name', 'version', + -- *_machine object -- + 'cpu_family', 'cpu', 'system', 'endian', + -- compiler object -- + 'alignment', 'cmd_array', 'compiles', 'compute_int', 'find_library', 'first_supported_argument', + 'first_supported_link_argument', 'get_define', 'get_id', 'get_argument_syntax', 'get_linker_id', + 'get_supported_arguments', 'get_supported_link_arguments', 'has_argument', 'has_link_argument', + 'has_function', 'check_header', 'has_header', 'has_header_symbol', 'has_member', 'has_members', + 'has_multi_arguments', 'has_multi_link_arguments', 'has_type', 'links', 'run', + 'symbols_have_underscore_prefix', 'sizeof', 'version', 'has_function_attribute', + 'get_supported_function_attributes', + -- build target object -- + 'extract_all_objects', 'extract_objects', 'full_path', 'private_dir_include', 'name', + -- configuration data object -- + 'get', 'get_unquoted', 'has', 'keys', 'merge_from', 'set', 'set10', 'set_quoted', + -- custom target object -- + 'full_path', 'to_list', + -- dependency object -- + 'found', 'name', 'get_pkgconfig_variable', 'get_configtool_variable', 'type_name', 'version', + 'include_type', 'as_system', 'as_link_whole', 'partial_dependency', 'found', + -- external program object -- + 'found', 'path', 'full_path', + -- environment object -- + 'append', 'prepend', 'set', + -- external library object -- + 'found', 'type_name', 'partial_dependency', 'enabled', 'disabled', 'auto', + -- generator object -- + 'process', + -- subproject object -- + 'found', 'get_variable', + -- run result object -- + 'compiled', 'returncode', 'stderr', 'stdout' +} +-- A method call must be followed by an opening parenthesis. +lex:add_rule('method', token('method', method_names * #(lexer.space^0 * '('))) +lex:add_style('method', lexer.styles['function']) + +-- Function. +-- https://mesonbuild.com/Reference-manual.html#functions +local func_names = word_match{ + 'add_global_arguments', 'add_global_link_arguments', 'add_languages', 'add_project_arguments', + 'add_project_link_arguments', 'add_test_setup', 'alias_targ', 'assert', 'benchmark', + 'both_libraries', 'build_target', 'configuration_data', 'configure_file', 'custom_target', + 'declare_dependency', 'dependency', 'disabler', 'error', 'environment', 'executable', + 'find_library', 'find_program', 'files', 'generator', 'get_option', 'get_variable', 'import', + 'include_directories', 'install_data', 'install_headers', 'install_man', 'install_subdir', + 'is_disabler', 'is_variable', 'jar', 'join_paths', 'library', 'message', 'warning', 'summary', + 'project', 'run_command', 'run_targ', 'set_variable', 'shared_library', 'shared_module', + 'static_library', 'subdir', 'subdir_done', 'subproject', 'test', 'vcs_tag' +} +-- A function call must be followed by an opening parenthesis. The matching of function calls +-- instead of just their names is needed to not falsely highlight function names which can also +-- be keyword arguments. For example 'include_directories' can be a function call itself or a +-- keyword argument of an 'executable' or 'library' function call. +lex:add_rule('function', token(lexer.FUNCTION, func_names * #(lexer.space^0 * '('))) + +-- Builtin objects. +-- https://mesonbuild.com/Reference-manual.html#builtin-objects +lex:add_rule('object', + token('object', word_match('meson build_machine host_machine target_machine'))) +lex:add_style('object', lexer.styles.type) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match('false true'))) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local str = lexer.range("'", true) +local multiline_str = lexer.range("'''") +lex:add_rule('string', token(lexer.STRING, multiline_str + str)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) + +-- Numbers. +local dec = R('19')^1 * R('09')^0 +local bin = '0b' * S('01')^1 +local oct = '0o' * R('07')^1 +local integer = S('+-')^-1 * (bin + lexer.hex_num + oct + dec) +lex:add_rule('number', token(lexer.NUMBER, integer)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('()[]{}-=+/%:.,?<>'))) + +return lex diff --git a/syntaxhighlight/textadept/moonscript.lua b/syntaxhighlight/textadept/moonscript.lua index 11fae40..df814ea 100644 --- a/syntaxhighlight/textadept/moonscript.lua +++ b/syntaxhighlight/textadept/moonscript.lua @@ -1,127 +1,129 @@ local lpeg = require('lpeg') --- Copyright 2016-2020 Alejandro Baez (https://keybase.io/baez). See License.txt. +-- Copyright 2016-2021 Alejandro Baez (https://keybase.io/baez). See LICENSE. -- Moonscript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, S, R = lpeg.P, lpeg.S, lpeg.R +local P, S = lpeg.P, lpeg.S local lex = lexer.new('moonscript', {fold_by_indentation = true}) -- Whitespace. lex:add_rule('whitspace', token(lexer.WHITESPACE, lexer.space^1)) +-- Table keys. +lex:add_rule('tbl_key', token('tbl_key', lexer.word * ':' + ':' * lexer.word)) +lex:add_style('tbl_key', lexer.STYLE_REGEX) + -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- Lua. - and break do else elseif false for if in local nil not or return then true - while + 'and', 'break', 'do', 'else', 'elseif', 'false', 'for', 'if', 'in', 'local', 'nil', 'not', 'or', + 'return', 'then', 'true', 'while', -- Moonscript. - continue class export extends from import super switch unless using when with -]])) + 'continue', 'class', 'export', 'extends', 'from', 'import', 'super', 'switch', 'unless', 'using', + 'when', 'with' +})) -- Error words. -lex:add_rule('error', token(lexer.ERROR, word_match[[function end]])) +lex:add_rule('error', token(lexer.ERROR, word_match('function end'))) -- Self reference. -lex:add_rule('self_ref', token('self_ref', '@' * lexer.word + 'self')) -lex:add_style('self_ref', lexer.STYLE_LABEL) +lex:add_rule('self_ref', token('self_ref', '@' * lexer.word^-1 + 'self')) +lex:add_style('self_ref', lexer.styles.label) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - assert collectgarbage dofile error getmetatable ipairs load loadfile next - pairs pcall print rawequal rawget rawset require select setmetatable tonumber - tostring type xpcall +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'assert', 'collectgarbage', 'dofile', 'error', 'getmetatable', 'ipairs', 'load', 'loadfile', + 'next', 'pairs', 'pcall', 'print', 'rawequal', 'rawget', 'rawset', 'require', 'select', + 'setmetatable', 'tonumber', 'tostring', 'type', 'xpcall', -- Added in 5.2. - rawlen -]])) + 'rawlen' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - _G _VERSION +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + '_G', '_VERSION', -- Added in 5.2. - _ENV -]])) + '_ENV' +})) -- Libraries. -lex:add_rule('library', token('library', word_match[[ +lex:add_rule('library', token('library', word_match{ -- Coroutine. - coroutine coroutine.create coroutine.resume coroutine.running coroutine.status - coroutine.wrap coroutine.yield + 'coroutine', 'coroutine.create', 'coroutine.resume', 'coroutine.running', 'coroutine.status', + 'coroutine.wrap', 'coroutine.yield', -- Coroutine added in 5.3. - coroutine.isyieldable + 'coroutine.isyieldable', -- Module. - package package.cpath package.loaded package.loadlib package.path - package.preload + 'package', 'package.cpath', 'package.loaded', 'package.loadlib', 'package.path', + 'package.preload', -- Module added in 5.2. - package.config package.searchers package.searchpath + 'package.config', 'package.searchers', 'package.searchpath', -- UTF-8 added in 5.3. - utf8 utf8.char utf8.charpattern utf8.codepoint utf8.codes utf8.len utf8.offset + 'utf8', 'utf8.char', 'utf8.charpattern', 'utf8.codepoint', 'utf8.codes', 'utf8.len', + 'utf8.offset', -- String. - string string.byte string.char string.dump string.find string.format - string.gmatch string.gsub string.len string.lower string.match string.rep - string.reverse string.sub string.upper + 'string', 'string.byte', 'string.char', 'string.dump', 'string.find', 'string.format', + 'string.gmatch', 'string.gsub', 'string.len', 'string.lower', 'string.match', 'string.rep', + 'string.reverse', 'string.sub', 'string.upper', -- String added in 5.3. - string.pack string.packsize string.unpack + 'string.pack', 'string.packsize', 'string.unpack', -- Table. - table table.concat table.insert table.remove table.sort + 'table', 'table.concat', 'table.insert', 'table.remove', 'table.sort', -- Table added in 5.2. - table.pack table.unpack + 'table.pack', 'table.unpack', -- Table added in 5.3. - table.move + 'table.move', -- Math. - math math.abs math.acos math.asin math.atan math.ceil math.cos math.deg - math.exp math.floor math.fmod math.huge math.log math.max math.min math.modf - math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan + 'math', 'math.abs', 'math.acos', 'math.asin', 'math.atan', 'math.ceil', 'math.cos', 'math.deg', + 'math.exp', 'math.floor', 'math.fmod', 'math.huge', 'math.log', 'math.max', 'math.min', + 'math.modf', 'math.pi', 'math.rad', 'math.random', 'math.randomseed', 'math.sin', 'math.sqrt', + 'math.tan', -- Math added in 5.3. - math.maxinteger math.mininteger math.tointeger math.type math.ult + 'math.maxinteger', 'math.mininteger', 'math.tointeger', 'math.type', 'math.ult', -- IO. - io io.close io.flush io.input io.lines io.open io.output io.popen io.read - io.stderr io.stdin io.stdout io.tmpfile io.type io.write + 'io', 'io.close', 'io.flush', 'io.input', 'io.lines', 'io.open', 'io.output', 'io.popen', + 'io.read', 'io.stderr', 'io.stdin', 'io.stdout', 'io.tmpfile', 'io.type', 'io.write', -- OS. - os os.clock os.date os.difftime os.execute os.exit os.getenv os.remove - os.rename os.setlocale os.time os.tmpname + 'os', 'os.clock', 'os.date', 'os.difftime', 'os.execute', 'os.exit', 'os.getenv', 'os.remove', + 'os.rename', 'os.setlocale', 'os.time', 'os.tmpname', -- Debug. - debug debug.debug debug.gethook debug.getinfo debug.getlocal - debug.getmetatable debug.getregistry debug.getupvalue debug.sethook - debug.setlocal debug.setmetatable debug.setupvalue debug.traceback + 'debug', 'debug.debug', 'debug.gethook', 'debug.getinfo', 'debug.getlocal', 'debug.getmetatable', + 'debug.getregistry', 'debug.getupvalue', 'debug.sethook', 'debug.setlocal', 'debug.setmetatable', + 'debug.setupvalue', 'debug.traceback', -- Debug added in 5.2. - debug.getuservalue debug.setuservalue debug.upvalueid debug.upvaluejoin + 'debug.getuservalue', 'debug.setuservalue', 'debug.upvalueid', 'debug.upvaluejoin', --- MoonScript 0.3.1 standard library. -- Printing functions. - p + 'p', -- Table functions. - run_with_scope defaultbl extend copy + 'run_with_scope', 'defaultbl', 'extend', 'copy', -- Class/object functions. - is_object bind_methods mixin mixin_object mixin_table + 'is_object', 'bind_methods', 'mixin', 'mixin_object', 'mixin_table', -- Misc functions. - fold + 'fold', -- Debug functions. - debug.upvalue -]])) -lex:add_style('library', lexer.STYLE_TYPE) + 'debug.upvalue' +})) +lex:add_style('library', lexer.styles.type) -- Identifiers. local identifier = token(lexer.IDENTIFIER, lexer.word) -local proper_ident = token('proper_ident', R('AZ') * lexer.word) -local tbl_key = token('tbl_key', lexer.word * ':' + ':' * lexer.word ) -lex:add_rule('identifier', tbl_key + proper_ident + identifier) -lex:add_style('proper_ident', lexer.STYLE_CLASS) -lex:add_style('tbl_key', lexer.STYLE_REGEX) - -local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[', - function(input, index, eq) - local _, e = input:find(']' .. eq .. ']', index, true) - return (e or #input) + 1 - end) +local proper_ident = token('proper_ident', lexer.upper * lexer.word) +lex:add_rule('identifier', proper_ident + identifier) +lex:add_style('proper_ident', lexer.styles.class) -- Strings. local sq_str = lexer.range("'", false, false) local dq_str = lexer.range('"', false, false) -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str) + - token('longstring', longstring)) -lex:add_style('longstring', lexer.STYLE_STRING) +local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[', function(input, index, eq) + local _, e = input:find(']' .. eq .. ']', index, true) + return (e or #input) + 1 +end) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str) + token('longstring', longstring)) +lex:add_style('longstring', lexer.styles.string) -- Comments. local line_comment = lexer.to_eol('--') @@ -133,11 +135,11 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Function definition. lex:add_rule('fndef', token('fndef', P('->') + '=>')) -lex:add_style('fndef', lexer.STYLE_PREPROCESSOR) +lex:add_style('fndef', lexer.styles.preprocessor) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-*!\\/%^#=<>;:,.'))) lex:add_rule('symbol', token('symbol', S('(){}[]'))) -lex:add_style('symbol', lexer.STYLE_EMBEDDED) +lex:add_style('symbol', lexer.styles.embedded) return lex diff --git a/syntaxhighlight/textadept/myrddin.lua b/syntaxhighlight/textadept/myrddin.lua index 70cf392..4467011 100644 --- a/syntaxhighlight/textadept/myrddin.lua +++ b/syntaxhighlight/textadept/myrddin.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2017-2020 Michael Forney. See License.txt +-- Copyright 2017-2021 Michael Forney. See LICENSE -- Myrddin LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('myrddin') @@ -12,16 +12,17 @@ local lex = lexer.new('myrddin') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break const continue elif else extern false for generic goto if impl in match - pkg pkglocal sizeof struct trait true type union use var while -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'const', 'continue', 'elif', 'else', 'extern', 'false', 'for', 'generic', 'goto', 'if', + 'impl', 'in', 'match', 'pkg', 'pkglocal', 'sizeof', 'struct', 'trait', 'true', 'type', 'union', + 'use', 'var', 'while' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - void bool char byte int uint int8 uint8 int16 uint16 int32 uint32 int64 uint64 - flt32 flt64 -]] + '@' * lexer.word)) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'void', 'bool', 'char', 'byte', 'int', 'uint', 'int8', 'uint8', 'int16', 'uint16', 'int32', + 'uint32', 'int64', 'uint64', 'flt32', 'flt64' +} + '@' * lexer.word)) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -38,16 +39,15 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Numbers. local digit = lexer.digit + '_' -local bdigit = R'01' + '_' +local bdigit = S('01') + '_' local xdigit = lexer.xdigit + '_' -local odigit = R'07' + '_' +local odigit = lpeg.R('07') + '_' local integer = '0x' * xdigit^1 + '0o' * odigit^1 + '0b' * bdigit^1 + digit^1 -local float = digit^1 * ( - ('.' * digit^1) * (S'eE' * S'+-'^-1 * digit^1)^-1 + - ('.' * digit^1)^-1 * S'eE' * S'+-'^-1 * digit^1) +local float = digit^1 * ((('.' * digit^1) * (S('eE') * S('+-')^-1 * digit^1)^-1) + + (('.' * digit^1)^-1 * S('eE') * S('+-')^-1 * digit^1)) lex:add_rule('number', token(lexer.NUMBER, float + integer)) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S'`#_+-/*%<>~!=^&|~:;,.()[]{}')) +lex:add_rule('operator', token(lexer.OPERATOR, S('`#_+-/*%<>~!=^&|~:;,.()[]{}'))) return lex diff --git a/syntaxhighlight/textadept/nemerle.lua b/syntaxhighlight/textadept/nemerle.lua index 236bea8..ab498ab 100644 --- a/syntaxhighlight/textadept/nemerle.lua +++ b/syntaxhighlight/textadept/nemerle.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Nemerle LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('nemerle') @@ -12,21 +12,22 @@ local lex = lexer.new('nemerle') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - _ abstract and array as base catch class def do else extends extern finally - foreach for fun if implements in interface internal lock macro match module - mutable namespace new out override params private protected public ref repeat - sealed static struct syntax this throw try type typeof unless until using - variant virtual when where while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + '_', 'abstract', 'and', 'array', 'as', 'base', 'catch', 'class', 'def', 'do', 'else', 'extends', + 'extern', 'finally', 'foreach', 'for', 'fun', 'if', 'implements', 'in', 'interface', 'internal', + 'lock', 'macro', 'match', 'module', 'mutable', 'namespace', 'new', 'out', 'override', 'params', + 'private', 'protected', 'public', 'ref', 'repeat', 'sealed', 'static', 'struct', 'syntax', 'this', + 'throw', 'try', 'type', 'typeof', 'unless', 'until', 'using', 'variant', 'virtual', 'when', + 'where', 'while', -- Values. - null true false -]])) + 'null', 'true', 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool byte char decimal double float int list long object sbyte short string - uint ulong ushort void -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'byte', 'char', 'decimal', 'double', 'float', 'int', 'list', 'long', 'object', 'sbyte', + 'short', 'string', 'uint', 'ulong', 'ushort', 'void' +})) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) @@ -45,12 +46,10 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Preprocessor. -local preproc_word = word_match[[ - define elif else endif endregion error if ifdef ifndef line pragma region - undef using warning -]] -lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * - S('\t ')^0 * preproc_word)) +lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') * S('\t ')^0 * word_match{ + 'define', 'elif', 'else', 'endif', 'endregion', 'error', 'if', 'ifdef', 'ifndef', 'line', + 'pragma', 'region', 'undef', 'using', 'warning' +})) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) @@ -62,6 +61,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif') lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/networkd.lua b/syntaxhighlight/textadept/networkd.lua new file mode 100644 index 0000000..7ad3625 --- /dev/null +++ b/syntaxhighlight/textadept/networkd.lua @@ -0,0 +1,102 @@ +local lpeg = require('lpeg') +-- Copyright 2016-2021 Christian Hesse. See LICENSE. +-- systemd networkd file LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('networkd', {lex_by_line = true}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Boolean values. + 'true', 'false', 'on', 'off', 'yes', 'no' +})) + +-- Options. +lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{ + -- Match section. + 'MACAddress', 'OriginalName', 'Path', 'Driver', 'Type', 'Host', 'Name', 'Virtualization', + 'KernelCommandLine', 'Architecture', + -- Link section. + 'Description', 'Alias', 'MACAddressPolicy', 'MACAddress', 'NamePolicy', 'Name', 'MTUBytes', + 'BitsPerSecond', 'Duplex', 'WakeOnLan', + -- Network section. + 'Description', 'DHCP', 'DHCPServer', 'LinkLocalAddressing', 'IPv4LLRoute', 'IPv6Token', 'LLMNR', + 'MulticastDNS', 'DNSSEC', 'DNSSECNegativeTrustAnchors', 'LLDP', 'BindCarrier', 'Address', + 'Gateway', 'DNS', 'Domains', 'NTP', 'IPForward', 'IPMasquerade', 'IPv6PrivacyExtensions', + 'IPv6AcceptRouterAdvertisements', 'IPv6DuplicateAddressDetection', 'IPv6HopLimit', 'Bridge', + 'Bond', 'VLAN', 'MACVLAN', 'VXLAN', 'Tunnel', + -- Address section. + 'Address', 'Peer', 'Broadcast', 'Label', + -- Route section. + 'Gateway', 'Destination', 'Source', 'Metric', 'Scope', 'PreferredSource', + -- DHCP section. + 'UseDNS', 'UseNTP', 'UseMTU', 'SendHostname', 'UseHostname', 'Hostname', 'UseDomains', + 'UseRoutes', 'UseTimezone', 'CriticalConnection', 'ClientIdentifier', 'VendorClassIdentifier', + 'RequestBroadcast', 'RouteMetric', + -- DHCPServer section. + 'PoolOffset', 'PoolSize', 'DefaultLeaseTimeSec', 'MaxLeaseTimeSec', 'EmitDNS', 'DNS', 'EmitNTP', + 'NTP', 'EmitTimezone', 'Timezone', + -- Bridge section. + 'UnicastFlood', 'HairPin', 'UseBPDU', 'FastLeave', 'AllowPortToBeRoot', 'Cost', + -- BridgeFDP section. + 'MACAddress', 'VLANId', + -- NetDev section. + 'Description', 'Name', 'Kind', 'MTUBytes', 'MACAddress', + -- Bridge (netdev) section. + 'HelloTimeSec', 'MaxAgeSec', 'ForwardDelaySec', + -- VLAN section. + 'Id', + -- MACVLAN MACVTAP and IPVLAN section. + 'Mode', + -- VXLAN section. + 'Id', 'Group', 'TOS', 'TTL', 'MacLearning', 'FDBAgeingSec', 'MaximumFDBEntries', 'ARPProxy', + 'L2MissNotification', 'L3MissNotification', 'RouteShortCircuit', 'UDPCheckSum', + 'UDP6ZeroChecksumTx', 'UDP6ZeroCheckSumRx', 'GroupPolicyExtension', 'DestinationPort', + 'PortRange', + -- Tunnel section. + 'Local', 'Remote', 'TOS', 'TTL', 'DiscoverPathMTU', 'IPv6FlowLabel', 'CopyDSCP', + 'EncapsulationLimit', 'Mode', + -- Peer section. + 'Name', 'MACAddress', + -- Tun and Tap section. + 'OneQueue', 'MultiQueue', 'PacketInfo', 'VNetHeader', 'User', 'Group', + -- Bond section. + 'Mode', 'TransmitHashPolicy', 'LACPTransmitRate', 'MIIMonitorSec', 'UpDelaySec', 'DownDelaySec', + 'LearnPacketIntervalSec', 'AdSelect', 'FailOverMACPolicy', 'ARPValidate', 'ARPIntervalSec', + 'ARPIPTargets', 'ARPAllTargets', 'PrimaryReselectPolicy', 'ResendIGMP', 'PacketsPerSlave', + 'GratuitousARP', 'AllSlavesActive', 'MinLinks' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0)) + +-- Strings. +local sq_str = lexer.range("'") +local dq_str = lexer.range('"') +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Sections. +lex:add_rule('section', token(lexer.LABEL, '[' * word_match{ + 'Address', 'Link', 'Match', 'Network', 'Route', 'DHCP', 'DHCPServer', 'Bridge', 'BridgeFDB', + 'NetDev', 'VLAN', 'MACVLAN', 'MACVTAP', 'IPVLAN', 'VXLAN', 'Tunnel', 'Peer', 'Tun', 'Tap', 'Bond' +} * ']')) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#'))))) + +-- Numbers. +local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 +local oct_num = '0' * S('01234567_')^1 +local integer = S('+-')^-1 * (lexer.hex_num + oct_num + dec) +lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, '=')) + +return lex diff --git a/syntaxhighlight/textadept/nim.lua b/syntaxhighlight/textadept/nim.lua index 7189cfa..00fb77d 100644 --- a/syntaxhighlight/textadept/nim.lua +++ b/syntaxhighlight/textadept/nim.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Nim LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('nim', {fold_by_indentation = true}) @@ -12,62 +12,64 @@ local lex = lexer.new('nim', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - addr and as asm atomic bind block break case cast const continue converter - discard distinct div do elif else end enum except export finally for from - generic if import in include interface is isnot iterator lambda let macro - method mixin mod nil not notin object of or out proc ptr raise ref return - shared shl static template try tuple type var when while with without xor - yield -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'addr', 'and', 'as', 'asm', 'atomic', 'bind', 'block', 'break', 'case', 'cast', 'const', + 'continue', 'converter', 'discard', 'distinct', 'div', 'do', 'elif', 'else', 'end', 'enum', + 'except', 'export', 'finally', 'for', 'from', 'generic', 'if', 'import', 'in', 'include', + 'interface', 'is', 'isnot', 'iterator', 'lambda', 'let', 'macro', 'method', 'mixin', 'mod', 'nil', + 'not', 'notin', 'object', 'of', 'or', 'out', 'proc', 'ptr', 'raise', 'ref', 'return', 'shared', + 'shl', 'static', 'template', 'try', 'tuple', 'type', 'var', 'when', 'while', 'with', 'without', + 'xor', 'yield' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ +lex:add_rule('function', token(lexer.FUNCTION, word_match({ -- Procs. - defined definedInScope new unsafeNew internalNew reset high low sizeof succ - pred inc dec newSeq len incl excl card ord chr ze ze64 toU8 toU16 toU32 abs - min max contains cmp setLen newString newStringOfCap add compileOption quit - shallowCopy del delete insert repr toFloat toBiggestFloat toInt toBiggestInt - addQuitProc substr zeroMem copyMem moveMem equalMem swap getRefcount clamp - isNil find contains pop each map GC_ref GC_unref echo debugEcho getTypeInfo - Open repopen Close EndOfFile readChar FlushFile readAll readFile writeFile - write readLine writeln getFileSize ReadBytes ReadChars readBuffer writeBytes - writeChars writeBuffer setFilePos getFilePos fileHandle cstringArrayToSeq - allocCStringArray deallocCStringArray atomicInc atomicDec compareAndSwap - setControlCHook writeStackTrace getStackTrace alloc alloc0 dealloc realloc - getFreeMem getTotalMem getOccupiedMem allocShared allocShared0 deallocShared - reallocShared IsOnStack GC_addCycleRoot GC_disable GC_enable GC_setStrategy - GC_enableMarkAndSweep GC_disableMarkAndSweep GC_fullCollect GC_getStatistics - nimDestroyRange getCurrentException getCurrentExceptionMsg onRaise likely - unlikely rawProc rawEnv finished slurp staticRead gorge staticExec rand - astToStr InstatiationInfo raiseAssert shallow compiles safeAdd locals + 'defined', 'definedInScope', 'new', 'unsafeNew', 'internalNew', 'reset', 'high', 'low', 'sizeof', + 'succ', 'pred', 'inc', 'dec', 'newSeq', 'len', 'incl', 'excl', 'card', 'ord', 'chr', 'ze', 'ze64', + 'toU8', 'toU16', 'toU32', 'abs', 'min', 'max', 'contains', 'cmp', 'setLen', 'newString', + 'newStringOfCap', 'add', 'compileOption', 'quit', 'shallowCopy', 'del', 'delete', 'insert', + 'repr', 'toFloat', 'toBiggestFloat', 'toInt', 'toBiggestInt', 'addQuitProc', 'substr', 'zeroMem', + 'copyMem', 'moveMem', 'equalMem', 'swap', 'getRefcount', 'clamp', 'isNil', 'find', 'contains', + 'pop', 'each', 'map', 'GC_ref', 'GC_unref', 'echo', 'debugEcho', 'getTypeInfo', 'Open', 'repopen', + 'Close', 'EndOfFile', 'readChar', 'FlushFile', 'readAll', 'readFile', 'writeFile', 'write', + 'readLine', 'writeln', 'getFileSize', 'ReadBytes', 'ReadChars', 'readBuffer', 'writeBytes', + 'writeChars', 'writeBuffer', 'setFilePos', 'getFilePos', 'fileHandle', 'cstringArrayToSeq', + 'allocCStringArray', 'deallocCStringArray', 'atomicInc', 'atomicDec', 'compareAndSwap', + 'setControlCHook', 'writeStackTrace', 'getStackTrace', 'alloc', 'alloc0', 'dealloc', 'realloc', + 'getFreeMem', 'getTotalMem', 'getOccupiedMem', 'allocShared', 'allocShared0', 'deallocShared', + 'reallocShared', 'IsOnStack', 'GC_addCycleRoot', 'GC_disable', 'GC_enable', 'GC_setStrategy', + 'GC_enableMarkAndSweep', 'GC_disableMarkAndSweep', 'GC_fullCollect', 'GC_getStatistics', + 'nimDestroyRange', 'getCurrentException', 'getCurrentExceptionMsg', 'onRaise', 'likely', + 'unlikely', 'rawProc', 'rawEnv', 'finished', 'slurp', 'staticRead', 'gorge', 'staticExec', 'rand', + 'astToStr', 'InstatiationInfo', 'raiseAssert', 'shallow', 'compiles', 'safeAdd', 'locals', -- Iterators. - countdown countup items pairs fields fieldPairs lines + 'countdown', 'countup', 'items', 'pairs', 'fields', 'fieldPairs', 'lines', -- Templates. - accumulateResult newException CurrentSourcePath assert doAssert onFailedAssert - eval + 'accumulateResult', 'newException', 'CurrentSourcePath', 'assert', 'doAssert', 'onFailedAssert', + 'eval', -- Threads. - running joinThread joinThreads createThread threadId myThreadId + 'running', 'joinThread', 'joinThreads', 'createThread', 'threadId', 'myThreadId', -- Channels. - send recv peek ready -]], true))) + 'send', 'recv', 'peek', 'ready' +}, true))) -- Types. -lex:add_rule('type', token(lexer.TYPE , word_match([[ - int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float float32 - float64 bool char string cstring pointer Ordinal auto any TSignedInt - TUnsignedInt TInteger TOrdinal TReal TNumber range array openarray varargs - seq set TSlice TThread TChannel +lex:add_rule('type', token(lexer.TYPE, word_match({ + 'int', 'int8', 'int16', 'int32', 'int64', 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'float', + 'float32', 'float64', 'bool', 'char', 'string', 'cstring', 'pointer', 'Ordinal', 'auto', 'any', + 'TSignedInt', 'TUnsignedInt', 'TInteger', 'TOrdinal', 'TReal', 'TNumber', 'range', 'array', + 'openarray', 'varargs', 'seq', 'set', 'TSlice', 'TThread', 'TChannel', -- Meta Types. - expr stmt typeDesc void -]], true))) + 'expr', 'stmt', 'typeDesc', 'void' +}, true))) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - on off isMainModule CompileDate CompileTime NimVersion NimMajor NimMinor - NimPatch cpuEndian hostOS hostCPU appType QuitSuccess QuitFailure inf neginf - nan -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + 'on', 'off', 'isMainModule', 'CompileDate', 'CompileTime', 'NimVersion', 'NimMajor', 'NimMinor', + 'NimPatch', 'cpuEndian', 'hostOS', 'hostCPU', 'appType', 'QuitSuccess', 'QuitFailure', 'inf', + 'neginf', 'nan' +})) -- Strings. local sq_str = lexer.range("'", true) @@ -80,22 +82,22 @@ lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str + raw_str)) lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) +local line_comment = lexer.to_eol('#', true) +local block_comment = lexer.range('#[', ']#') +lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) -- Numbers. local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 local hex = '0' * S('xX') * lexer.xdigit^1 * ('_' * lexer.xdigit^1)^0 local bin = '0' * S('bB') * S('01')^1 * ('_' * S('01')^1)^0 -local oct = '0o' * R('07')^1 +local oct = '0o' * lpeg.R('07')^1 local integer = S('+-')^-1 * (bin + hex + oct + dec) * ("'" * S('iIuUfF') * (P('8') + '16' + '32' + '64'))^-1 -local float = lexer.digit^1 * ('_' * lexer.digit^1)^0 * - ('.' * ('_' * lexer.digit)^0)^-1 * S('eE') * S('+-')^-1 * lexer.digit^1 * - ('_' * lexer.digit^1)^0 -lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) +local float = lexer.digit^1 * ('_' * lexer.digit^1)^0 * ('.' * ('_' * lexer.digit)^0)^-1 * S('eE') * + S('+-')^-1 * lexer.digit^1 * ('_' * lexer.digit^1)^0 +lex:add_rule('number', token(lexer.NUMBER, float + integer)) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('=+-*/<>@$~&%|!?^.:\\`()[]{},;'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('=+-*/<>@$~&%|!?^.:\\`()[]{},;'))) return lex diff --git a/syntaxhighlight/textadept/nsis.lua b/syntaxhighlight/textadept/nsis.lua index c22b14c..9299067 100644 --- a/syntaxhighlight/textadept/nsis.lua +++ b/syntaxhighlight/textadept/nsis.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke. See License.txt. +-- Copyright 2006-2021 Robert Gieseke. See LICENSE. -- NSIS LPeg lexer -- Based on NSIS 2.46 docs: http://nsis.sourceforge.net/Docs/. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('nsis') @@ -13,7 +13,7 @@ local lex = lexer.new('nsis') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments (4.1). -local line_comment = lexer.to_eol(P(';') + '#') +local line_comment = lexer.to_eol(S(';#')) local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) @@ -24,114 +24,115 @@ local bq_str = lexer.range('`') lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str)) -- Constants (4.2.3). -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - $PROGRAMFILES $PROGRAMFILES32 $PROGRAMFILES64 $COMMONFILES $COMMONFILES32 - $COMMONFILES64 $DESKTOP $EXEDIR $EXEFILE $EXEPATH ${NSISDIR} $WINDIR $SYSDIR - $TEMP $STARTMENU $SMPROGRAMS $SMSTARTUP $QUICKLAUNCH$DOCUMENTS $SENDTO $RECENT - $FAVORITES $MUSIC $PICTURES $VIDEOS $NETHOOD $FONTS $TEMPLATES $APPDATA - $LOCALAPPDATA $PRINTHOOD $INTERNET_CACHE $COOKIES $HISTORY $PROFILE - $ADMINTOOLS $RESOURCES $RESOURCES_LOCALIZED $CDBURN_AREA $HWNDPARENT - $PLUGINSDIR -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + '$PROGRAMFILES', '$PROGRAMFILES32', '$PROGRAMFILES64', '$COMMONFILES', '$COMMONFILES32', + '$COMMONFILES64', '$DESKTOP', '$EXEDIR', '$EXEFILE', '$EXEPATH', '${NSISDIR}', '$WINDIR', + '$SYSDIR', '$TEMP', '$STARTMENU', '$SMPROGRAMS', '$SMSTARTUP', '$QUICKLAUNCH$DOCUMENTS', + '$SENDTO', '$RECENT', '$FAVORITES', '$MUSIC', '$PICTURES', '$VIDEOS', '$NETHOOD', '$FONTS', + '$TEMPLATES', '$APPDATA', '$LOCALAPPDATA', '$PRINTHOOD', '$INTERNET_CACHE', '$COOKIES', + '$HISTORY', '$PROFILE', '$ADMINTOOLS', '$RESOURCES', '$RESOURCES_LOCALIZED', '$CDBURN_AREA', + '$HWNDPARENT', '$PLUGINSDIR' +})) -- TODO? Constants used in strings: $$ $\r $\n $\t -- Variables (4.2). -lex:add_rule('variable', token(lexer.VARIABLE, word_match[[ - $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $R0 $R1 $R2 $R3 $R4 $R5 $R6 $R7 $R8 $R9 - $INSTDIR $OUTDIR $CMDLINE $LANGUAGE Var /GLOBAL -]]) + '$' * lexer.word) +lex:add_rule('variable', token(lexer.VARIABLE, word_match{ + '$0', '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9', '$R0', '$R1', '$R2', '$R3', '$R4', + '$R5', '$R6', '$R7', '$R8', '$R9', '$INSTDIR', '$OUTDIR', '$CMDLINE', '$LANGUAGE', 'Var', + '/GLOBAL' +} + '$' * lexer.word)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- Pages (4.5). - Page UninstPage PageEx PageEnd PageExEnd + 'Page', 'UninstPage', 'PageEx', 'PageEnd', 'PageExEnd', -- Section commands (4.6). - AddSize Section SectionEnd SectionIn SectionGroup SectionGroupEnd + 'AddSize', 'Section', 'SectionEnd', 'SectionIn', 'SectionGroup', 'SectionGroupEnd', -- Functions (4.7). - Function FunctionEnd + 'Function', 'FunctionEnd', -- Callbacks (4.7.2). - .onGUIInit .onInit .onInstFailed .onInstSuccess .onGUIEnd .onMouseOverSection - .onRebootFailed .onSelChange .onUserAbort .onVerifyInstDir un.onGUIInit - un.onInit un.onUninstFailed un.onUninstSuccess un.onGUIEnd un.onRebootFailed - un.onSelChange un.onUserAbort + '.onGUIInit', '.onInit', '.onInstFailed', '.onInstSuccess', '.onGUIEnd', '.onMouseOverSection', + '.onRebootFailed', '.onSelChange', '.onUserAbort', '.onVerifyInstDir', 'un.onGUIInit', + 'un.onInit', 'un.onUninstFailed', 'un.onUninstSuccess', 'un.onGUIEnd', 'un.onRebootFailed', + 'un.onSelChange', 'un.onUserAbort', -- General Attributes (4.8.1). - AddBrandingImage AllowRootDirInstall AutoCloseWindow BGFont BGFont - BrandingText /TRIMLEFT /TRIMRIGHT /TRIMCENTER Caption ChangeUI CheckBitmap - CompletedText ComponentText CRCCheck DetailsButtonText DirText DirVar - DirVerify FileErrorText Icon InstallButtonText InstallColors InstallDir - InstallDirRegKey InstProgressFlags InstType LicenseBkColor LicenseData - LicenseForceSelection LicenseText MiscButtonText Name OutFile - RequestExecutionLevel SetFont ShowInstDetails ShowUninstDetails SilentInstall - SilentUnInstall SpaceTexts SubCaption UninstallButtonText UninstallCaption - UninstallIcon UninstallSubCaption UninstallText WindowIcon XPStyle admin auto - bottom checkbox false force height hide highest leave left nevershow none - normal off on radiobuttons right show silent silentlog top true user width + 'AddBrandingImage', 'AllowRootDirInstall', 'AutoCloseWindow', 'BGFont', 'BGFont', 'BrandingText', + '/TRIMLEFT', '/TRIMRIGHT', '/TRIMCENTER', 'Caption', 'ChangeUI', 'CheckBitmap', 'CompletedText', + 'ComponentText', 'CRCCheck', 'DetailsButtonText', 'DirText', 'DirVar', 'DirVerify', + 'FileErrorText', 'Icon', 'InstallButtonText', 'InstallColors', 'InstallDir', 'InstallDirRegKey', + 'InstProgressFlags', 'InstType', 'LicenseBkColor', 'LicenseData', 'LicenseForceSelection', + 'LicenseText', 'MiscButtonText', 'Name', 'OutFile', 'RequestExecutionLevel', 'SetFont', + 'ShowInstDetails', 'ShowUninstDetails', 'SilentInstall', 'SilentUnInstall', 'SpaceTexts', + 'SubCaption', 'UninstallButtonText', 'UninstallCaption', 'UninstallIcon', 'UninstallSubCaption', + 'UninstallText', 'WindowIcon', 'XPStyle', 'admin', 'auto', 'bottom', 'checkbox', 'false', 'force', + 'height', 'hide', 'highest', 'leave', 'left', 'nevershow', 'none', 'normal', 'off', 'on', + 'radiobuttons', 'right', 'show', 'silent', 'silentlog', 'top', 'true', 'user', 'width', -- Compiler Flags (4.8.2). - AllowSkipFiles FileBufSize SetCompress SetCompressor /SOLID /FINAL zlib bzip2 - lzma SetCompressorDictSize SetDatablockOptimize SetDateSave SetOverwrite - ifnewer ifdiff lastused try + 'AllowSkipFiles', 'FileBufSize', 'SetCompress', 'SetCompressor', '/SOLID', '/FINAL', 'zlib', + 'bzip2', 'lzma', 'SetCompressorDictSize', 'SetDatablockOptimize', 'SetDateSave', 'SetOverwrite', + 'ifnewer', 'ifdiff', 'lastused', 'try', -- Version Information (4.8.3). - VIAddVersionKey VIProductVersion /LANG ProductName Comments CompanyName - LegalCopyright FileDescription FileVersion ProductVersion InternalName - LegalTrademarks OriginalFilename PrivateBuild SpecialBuild + 'VIAddVersionKey', 'VIProductVersion', '/LANG', 'ProductName', 'Comments', 'CompanyName', + 'LegalCopyright', 'FileDescription', 'FileVersion', 'ProductVersion', 'InternalName', + 'LegalTrademarks', 'OriginalFilename', 'PrivateBuild', 'SpecialBuild', -- Basic Instructions (4.9.1). - Delete /REBOOTOK Exec ExecShell ExecShell File /nonfatal Rename ReserveFile - RMDir SetOutPath + 'Delete', '/REBOOTOK', 'Exec', 'ExecShell', 'ExecShell', 'File', '/nonfatal', 'Rename', + 'ReserveFile', 'RMDir', 'SetOutPath', -- Registry INI File Instructions (4.9.2). - DeleteINISec DeleteINIStr DeleteRegKey /ifempty DeleteRegValue EnumRegKey - EnumRegValue ExpandEnvStrings FlushINI ReadEnvStr ReadINIStr ReadRegDWORD - ReadRegStr WriteINIStr WriteRegBin WriteRegDWORD WriteRegStr WriteRegExpandStr - HKCR HKEY_CLASSES_ROOT HKLM HKEY_LOCAL_MACHINE HKCU HKEY_CURRENT_USER HKU - HKEY_USERS HKCC HKEY_CURRENT_CONFIG HKDD HKEY_DYN_DATA HKPD - HKEY_PERFORMANCE_DATA SHCTX SHELL_CONTEXT + 'DeleteINISec', 'DeleteINIStr', 'DeleteRegKey', '/ifempty', 'DeleteRegValue', 'EnumRegKey', + 'EnumRegValue', 'ExpandEnvStrings', 'FlushINI', 'ReadEnvStr', 'ReadINIStr', 'ReadRegDWORD', + 'ReadRegStr', 'WriteINIStr', 'WriteRegBin', 'WriteRegDWORD', 'WriteRegStr', 'WriteRegExpandStr', + 'HKCR', 'HKEY_CLASSES_ROOT', 'HKLM', 'HKEY_LOCAL_MACHINE', 'HKCU', 'HKEY_CURRENT_USER', 'HKU', + 'HKEY_USERS', 'HKCC', 'HKEY_CURRENT_CONFIG', 'HKDD', 'HKEY_DYN_DATA', 'HKPD', + 'HKEY_PERFORMANCE_DATA', 'SHCTX', 'SHELL_CONTEXT', -- General Purpose Instructions (4.9.3). - CallInstDLL CopyFiles /SILENT /FILESONLY CreateDirectory CreateShortCut - GetDLLVersion GetDLLVersionLocal GetFileTime GetFileTimeLocal GetFullPathName - /SHORT GetTempFileName SearchPath SetFileAttributes RegDLL UnRegDLL + 'CallInstDLL', 'CopyFiles', '/SILENT', '/FILESONLY', 'CreateDirectory', 'CreateShortCut', + 'GetDLLVersion', 'GetDLLVersionLocal', 'GetFileTime', 'GetFileTimeLocal', 'GetFullPathName', + '/SHORT', 'GetTempFileName', 'SearchPath', 'SetFileAttributes', 'RegDLL', 'UnRegDLL', -- Flow Control Instructions (4.9.4). - Abort Call ClearErrors GetCurrentAddress GetFunctionAddress GetLabelAddress - Goto IfAbort IfErrors IfFileExists IfRebootFlag IfSilent IntCmp IntCmpU - MessageBox MB_OK MB_OKCANCEL MB_ABORTRETRYIGNORE MB_RETRYCANCEL MB_YESNO - MB_YESNOCANCEL MB_ICONEXCLAMATION MB_ICONINFORMATION MB_ICONQUESTION - MB_ICONSTOP MB_USERICON MB_TOPMOST MB_SETFOREGROUND MB_RIGHT MB_RTLREADING - MB_DEFBUTTON1 MB_DEFBUTTON2 MB_DEFBUTTON3 MB_DEFBUTTON4 IDABORT IDCANCEL - IDIGNORE IDNO IDOK IDRETRY IDYES Return Quit SetErrors StrCmp StrCmpS + 'Abort', 'Call', 'ClearErrors', 'GetCurrentAddress', 'GetFunctionAddress', 'GetLabelAddress', + 'Goto', 'IfAbort', 'IfErrors', 'IfFileExists', 'IfRebootFlag', 'IfSilent', 'IntCmp', 'IntCmpU', + 'MessageBox', 'MB_OK', 'MB_OKCANCEL', 'MB_ABORTRETRYIGNORE', 'MB_RETRYCANCEL', 'MB_YESNO', + 'MB_YESNOCANCEL', 'MB_ICONEXCLAMATION', 'MB_ICONINFORMATION', 'MB_ICONQUESTION', 'MB_ICONSTOP', + 'MB_USERICON', 'MB_TOPMOST', 'MB_SETFOREGROUND', 'MB_RIGHT', 'MB_RTLREADING', 'MB_DEFBUTTON1', + 'MB_DEFBUTTON2', 'MB_DEFBUTTON3', 'MB_DEFBUTTON4', 'IDABORT', 'IDCANCEL', 'IDIGNORE', 'IDNO', + 'IDOK', 'IDRETRY', 'IDYES', 'Return', 'Quit', 'SetErrors', 'StrCmp', 'StrCmpS', -- File Instructions (4.9.5). - FileClose FileOpen FileRead FileReadByte FileSeek FileWrite FileWriteByte - FindClose FindFirst FindNext + 'FileClose', 'FileOpen', 'FileRead', 'FileReadByte', 'FileSeek', 'FileWrite', 'FileWriteByte', + 'FindClose', 'FindFirst', 'FindNext', -- Uninstaller Instructions (4.9.6). - WriteUninstaller + 'WriteUninstaller', -- Miscellaneous Instructions (4.9.7). - GetErrorLevel GetInstDirError InitPluginsDir Nop SetErrorLevel SetRegView - SetShellVarContext all current Sleep + 'GetErrorLevel', 'GetInstDirError', 'InitPluginsDir', 'Nop', 'SetErrorLevel', 'SetRegView', + 'SetShellVarContext', 'all', 'current', 'Sleep', -- String Manipulation Instructions (4.9.8). - StrCpy StrLen + 'StrCpy', 'StrLen', -- Stack Support (4.9.9). - Exch Pop Push + 'Exch', 'Pop', 'Push', -- Integer Support (4.9.10). - IntFmt IntOp + 'IntFmt', 'IntOp', -- Reboot Instructions (4.9.11). - Reboot SetRebootFlag + 'Reboot', 'SetRebootFlag', -- Install Logging Instructions (4.9.12). - LogSet LogText + 'LogSet', 'LogText', -- Section Management (4.9.13). - SectionSetFlags SectionGetFlags SectionGetFlags SectionSetText SectionGetText - SectionSetInstTypes SectionGetInstTypes SectionSetSize SectionGetSize - SetCurInstType GetCurInstType InstTypeSetText InstTypeGetText + 'SectionSetFlags', 'SectionGetFlags', 'SectionGetFlags', 'SectionSetText', 'SectionGetText', + 'SectionSetInstTypes', 'SectionGetInstTypes', 'SectionSetSize', 'SectionGetSize', + 'SetCurInstType', 'GetCurInstType', 'InstTypeSetText', 'InstTypeGetText', -- User Interface Instructions (4.9.14). - BringToFront CreateFont DetailPrint EnableWindow FindWindow GetDlgItem - HideWindow IsWindow LockWindow SendMessage SetAutoClose SetBrandingImage - SetDetailsView SetDetailsPrint listonlytextonly both SetCtlColors /BRANDING - SetSilent ShowWindow + 'BringToFront', 'CreateFont', 'DetailPrint', 'EnableWindow', 'FindWindow', 'GetDlgItem', + 'HideWindow', 'IsWindow', 'LockWindow', 'SendMessage', 'SetAutoClose', 'SetBrandingImage', + 'SetDetailsView', 'SetDetailsPrint', 'listonlytextonly', 'both', 'SetCtlColors', '/BRANDING', + 'SetSilent', 'ShowWindow', -- Multiple Languages Instructions (4.9.15). - LoadLanguageFile LangString LicenseLangString + 'LoadLanguageFile', 'LangString', 'LicenseLangString', -- Compile time commands (5). - !include !addincludedir !addplugindir !appendfile !cd !delfile !echo !error - !execute !packhdr !system !tempfile !warning !verbose {__FILE__} {__LINE__} - {__DATE__} {__TIME__} {__TIMESTAMP__} {NSIS_VERSION} !define !undef !ifdef - !ifndef !if !ifmacrodef !ifmacrondef !else !endif !insertmacro !macro - !macroend !searchparse !searchreplace -]])) + '!include', '!addincludedir', '!addplugindir', '!appendfile', '!cd', '!delfile', '!echo', + '!error', '!execute', '!packhdr', '!system', '!tempfile', '!warning', '!verbose', '{__FILE__}', + '{__LINE__}', '{__DATE__}', '{__TIME__}', '{__TIMESTAMP__}', '{NSIS_VERSION}', '!define', + '!undef', '!ifdef', '!ifndef', '!if', '!ifmacrodef', '!ifmacrondef', '!else', '!endif', + '!insertmacro', '!macro', '!macroend', '!searchparse', '!searchreplace' +})) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.integer)) diff --git a/syntaxhighlight/textadept/null.lua b/syntaxhighlight/textadept/null.lua index f04177c..046ce80 100644 --- a/syntaxhighlight/textadept/null.lua +++ b/syntaxhighlight/textadept/null.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Null LPeg lexer. return require('syntaxhighlight.textadept.lexer').new('null') diff --git a/syntaxhighlight/textadept/objective_c.lua b/syntaxhighlight/textadept/objective_c.lua index 906d483..d532caa 100644 --- a/syntaxhighlight/textadept/objective_c.lua +++ b/syntaxhighlight/textadept/objective_c.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Objective C LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('objective_c') @@ -12,25 +12,24 @@ local lex = lexer.new('objective_c') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- From C. - asm auto break case const continue default do else extern false for goto if - inline register return sizeof static switch true typedef void volatile while - restrict _Bool _Complex _Pragma _Imaginary + 'asm', 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'extern', 'false', + 'for', 'goto', 'if', 'inline', 'register', 'return', 'sizeof', 'static', 'switch', 'true', + 'typedef', 'void', 'volatile', 'while', 'restrict', '_Bool', '_Complex', '_Pragma', '_Imaginary', -- Objective C. - oneway in out inout bycopy byref self super + 'oneway', 'in', 'out', 'inout', 'bycopy', 'byref', 'self', 'super', -- Preprocessor directives. - @interface @implementation @protocol @end @private @protected @public @class - @selector @encode @defs @synchronized @try @throw @catch @finally + '@interface', '@implementation', '@protocol', '@end', '@private', '@protected', '@public', + '@class', '@selector', '@encode', '@defs', '@synchronized', '@try', '@throw', '@catch', + '@finally', -- Constants. - TRUE FALSE YES NO NULL nil Nil METHOD_NULL -]])) + 'TRUE', 'FALSE', 'YES', 'NO', 'NULL', 'nil', 'Nil', 'METHOD_NULL' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - apply_t id Class MetaClass Object Protocol retval_t SEL STR IMP BOOL - TypedStream -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'apply_t id Class MetaClass Object Protocol retval_t SEL STR IMP BOOL TypedStream'))) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) @@ -49,12 +48,11 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Preprocessor. -local preproc_word = word_match[[ - define elif else endif error if ifdef ifndef import include line pragma undef - warning -]] -lex:add_rule('preprocessor', #lexer.starts_line('#') * - token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * preproc_word)) +lex:add_rule('preprocessor', + #lexer.starts_line('#') * token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * word_match{ + 'define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'import', 'include', + 'line', 'pragma', 'undef', 'warning' + })) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) @@ -66,6 +64,6 @@ lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif') lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/pascal.lua b/syntaxhighlight/textadept/pascal.lua index 3ffa7d6..6cf977b 100644 --- a/syntaxhighlight/textadept/pascal.lua +++ b/syntaxhighlight/textadept/pascal.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Pascal LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('pascal') @@ -12,35 +12,38 @@ local lex = lexer.new('pascal') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - and array as at asm begin case class const constructor destructor - dispinterface div do downto else end except exports file final finalization - finally for function goto if implementation in inherited initialization inline - interface is label mod not object of on or out packed procedure program - property raise record repeat resourcestring set sealed shl shr static string - then threadvar to try type unit unsafe until uses var while with xor - absolute abstract assembler automated cdecl contains default deprecated dispid - dynamic export external far forward implements index library local message - name namespaces near nodefault overload override package pascal platform - private protected public published read readonly register reintroduce requires - resident safecall stdcall stored varargs virtual write writeln writeonly - false nil self true -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'and', 'array', 'as', 'at', 'asm', 'begin', 'case', 'class', 'const', 'constructor', 'destructor', + 'dispinterface', 'div', 'do', 'downto', 'else', 'end', 'except', 'exports', 'file', 'final', + 'finalization', 'finally', 'for', 'function', 'goto', 'if', 'implementation', 'in', 'inherited', + 'initialization', 'inline', 'interface', 'is', 'label', 'mod', 'not', 'object', 'of', 'on', 'or', + 'out', 'packed', 'procedure', 'program', 'property', 'raise', 'record', 'repeat', + 'resourcestring', 'set', 'sealed', 'shl', 'shr', 'static', 'string', 'then', 'threadvar', 'to', + 'try', 'type', 'unit', 'unsafe', 'until', 'uses', 'var', 'while', 'with', 'xor', 'absolute', + 'abstract', 'assembler', 'automated', 'cdecl', 'contains', 'default', 'deprecated', 'dispid', + 'dynamic', 'export', 'external', 'far', 'forward', 'implements', 'index', 'library', 'local', + 'message', 'name', 'namespaces', 'near', 'nodefault', 'overload', 'override', 'package', 'pascal', + 'platform', 'private', 'protected', 'public', 'published', 'read', 'readonly', 'register', + 'reintroduce', 'requires', 'resident', 'safecall', 'stdcall', 'stored', 'varargs', 'virtual', + 'write', 'writeln', 'writeonly', -- + 'false', 'nil', 'self', 'true' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ - chr ord succ pred abs round trunc sqr sqrt arctan cos sin exp ln odd eof eoln -]], true))) +lex:add_rule('function', token(lexer.FUNCTION, word_match({ + 'chr', 'ord', 'succ', 'pred', 'abs', 'round', 'trunc', 'sqr', 'sqrt', 'arctan', 'cos', 'sin', + 'exp', 'ln', 'odd', 'eof', 'eoln' +}, true))) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match([[ - shortint byte char smallint integer word longint cardinal boolean bytebool - wordbool longbool real single double extended comp currency pointer -]], true))) +lex:add_rule('type', token(lexer.TYPE, word_match({ + 'shortint', 'byte', 'char', 'smallint', 'integer', 'word', 'longint', 'cardinal', 'boolean', + 'bytebool', 'wordbool', 'longbool', 'real', 'single', 'double', 'extended', 'comp', 'currency', + 'pointer' +}, true))) -- Strings. -lex:add_rule('string', token(lexer.STRING, S('uUrR')^-1 * - lexer.range("'", true, false))) +lex:add_rule('string', token(lexer.STRING, S('uUrR')^-1 * lexer.range("'", true, false))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -49,8 +52,7 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) local line_comment = lexer.to_eol('//', true) local bblock_comment = lexer.range('{', '}') local pblock_comment = lexer.range('(*', '*)') -lex:add_rule('comment', token(lexer.COMMENT, line_comment + bblock_comment + - pblock_comment)) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + bblock_comment + pblock_comment)) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlDdFf')^-1)) diff --git a/syntaxhighlight/textadept/perl.lua b/syntaxhighlight/textadept/perl.lua index fa972aa..3a09b97 100644 --- a/syntaxhighlight/textadept/perl.lua +++ b/syntaxhighlight/textadept/perl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Perl LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('perl') @@ -12,45 +12,49 @@ local lex = lexer.new('perl') lex:add_rule('perl', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - STDIN STDOUT STDERR BEGIN END CHECK INIT - require use - break continue do each else elsif foreach for if last local my next our - package return sub unless until while __FILE__ __LINE__ __PACKAGE__ - and or not eq ne lt gt le ge -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'STDIN', 'STDOUT', 'STDERR', 'BEGIN', 'END', 'CHECK', 'INIT', -- + 'require', 'use', -- + 'break', 'continue', 'do', 'each', 'else', 'elsif', 'foreach', 'for', 'if', 'last', 'local', 'my', + 'next', 'our', 'package', 'return', 'sub', 'unless', 'until', 'while', '__FILE__', '__LINE__', + '__PACKAGE__', -- + 'and', 'or', 'not', 'eq', 'ne', 'lt', 'gt', 'le', 'ge' +})) -- Markers. -lex:add_rule('marker', token(lexer.COMMENT, word_match[[__DATA__ __END__]] * - lexer.any^0)) +lex:add_rule('marker', token(lexer.COMMENT, word_match('__DATA__ __END__') * lexer.any^0)) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs accept alarm atan2 bind binmode bless caller chdir chmod chomp chop chown - chr chroot closedir close connect cos crypt dbmclose dbmopen defined delete - die dump each endgrent endhostent endnetent endprotoent endpwent endservent - eof eval exec exists exit exp fcntl fileno flock fork format formline getc - getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin - getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid getpriority - getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid - getservbyname getservbyport getservent getsockname getsockopt glob gmtime goto - grep hex import index int ioctl join keys kill lcfirst lc length link listen - localtime log lstat map mkdir msgctl msgget msgrcv msgsnd new oct opendir open - ord pack pipe pop pos printf print prototype push quotemeta rand readdir read - readlink recv redo ref rename reset reverse rewinddir rindex rmdir scalar - seekdir seek select semctl semget semop send setgrent sethostent setnetent - setpgrp setpriority setprotoent setpwent setservent setsockopt shift shmctl - shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split - sprintf sqrt srand stat study substr symlink syscall sysread sysseek system - syswrite telldir tell tied tie time times truncate ucfirst uc umask undef - unlink unpack unshift untie utime values vec wait waitpid wantarray warn write -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'accept', 'alarm', 'atan2', 'bind', 'binmode', 'bless', 'caller', 'chdir', 'chmod', + 'chomp', 'chop', 'chown', 'chr', 'chroot', 'closedir', 'close', 'connect', 'cos', 'crypt', + 'dbmclose', 'dbmopen', 'defined', 'delete', 'die', 'dump', 'each', 'endgrent', 'endhostent', + 'endnetent', 'endprotoent', 'endpwent', 'endservent', 'eof', 'eval', 'exec', 'exists', 'exit', + 'exp', 'fcntl', 'fileno', 'flock', 'fork', 'format', 'formline', 'getc', 'getgrent', 'getgrgid', + 'getgrnam', 'gethostbyaddr', 'gethostbyname', 'gethostent', 'getlogin', 'getnetbyaddr', + 'getnetbyname', 'getnetent', 'getpeername', 'getpgrp', 'getppid', 'getpriority', 'getprotobyname', + 'getprotobynumber', 'getprotoent', 'getpwent', 'getpwnam', 'getpwuid', 'getservbyname', + 'getservbyport', 'getservent', 'getsockname', 'getsockopt', 'glob', 'gmtime', 'goto', 'grep', + 'hex', 'import', 'index', 'int', 'ioctl', 'join', 'keys', 'kill', 'lcfirst', 'lc', 'length', + 'link', 'listen', 'localtime', 'log', 'lstat', 'map', 'mkdir', 'msgctl', 'msgget', 'msgrcv', + 'msgsnd', 'new', 'oct', 'opendir', 'open', 'ord', 'pack', 'pipe', 'pop', 'pos', 'printf', 'print', + 'prototype', 'push', 'quotemeta', 'rand', 'readdir', 'read', 'readlink', 'recv', 'redo', 'ref', + 'rename', 'reset', 'reverse', 'rewinddir', 'rindex', 'rmdir', 'scalar', 'seekdir', 'seek', + 'select', 'semctl', 'semget', 'semop', 'send', 'setgrent', 'sethostent', 'setnetent', 'setpgrp', + 'setpriority', 'setprotoent', 'setpwent', 'setservent', 'setsockopt', 'shift', 'shmctl', 'shmget', + 'shmread', 'shmwrite', 'shutdown', 'sin', 'sleep', 'socket', 'socketpair', 'sort', 'splice', + 'split', 'sprintf', 'sqrt', 'srand', 'stat', 'study', 'substr', 'symlink', 'syscall', 'sysread', + 'sysseek', 'system', 'syswrite', 'telldir', 'tell', 'tied', 'tie', 'time', 'times', 'truncate', + 'ucfirst', 'uc', 'umask', 'undef', 'unlink', 'unpack', 'unshift', 'untie', 'utime', 'values', + 'vec', 'wait', 'waitpid', 'wantarray', 'warn', 'write' +})) +-- Strings. local delimiter_matches = {['('] = ')', ['['] = ']', ['{'] = '}', ['<'] = '>'} local literal_delimited = P(function(input, index) -- for single delimiter sets local delimiter = input:sub(index, index) if not delimiter:find('%w') then -- only non alpha-numerics - local match_pos, patt + local patt if delimiter_matches[delimiter] then -- Handle nested delimiter/matches in strings. local s, e = delimiter, delimiter_matches[delimiter] @@ -58,16 +62,16 @@ local literal_delimited = P(function(input, index) -- for single delimiter sets else patt = lexer.range(delimiter) end - match_pos = lpeg.match(patt, input, index) + local match_pos = lpeg.match(patt, input, index) return match_pos or #input + 1 end end) local literal_delimited2 = P(function(input, index) -- for 2 delimiter sets local delimiter = input:sub(index, index) - -- Only consider non-alpha-numerics and non-spaces as delimiters. The - -- non-spaces are used to ignore operators like "-s". + -- Only consider non-alpha-numerics and non-spaces as delimiters. The non-spaces are used to + -- ignore operators like "-s". if not delimiter:find('[%w ]') then - local match_pos, patt + local patt if delimiter_matches[delimiter] then -- Handle nested delimiter/matches in strings. local s, e = delimiter, delimiter_matches[delimiter] @@ -75,8 +79,8 @@ local literal_delimited2 = P(function(input, index) -- for 2 delimiter sets else patt = lexer.range(delimiter) end - first_match_pos = lpeg.match(patt, input, index) - final_match_pos = lpeg.match(patt, input, first_match_pos - 1) + local first_match_pos = lpeg.match(patt, input, index) + local final_match_pos = lpeg.match(patt, input, first_match_pos - 1) if not final_match_pos then -- using (), [], {}, or <> notation final_match_pos = lpeg.match(lexer.space^0 * patt, input, first_match_pos) end @@ -84,7 +88,6 @@ local literal_delimited2 = P(function(input, index) -- for 2 delimiter sets end end) --- Strings. local sq_str = lexer.range("'") local dq_str = lexer.range('"') local cmd_str = lexer.range('`') @@ -92,7 +95,7 @@ local heredoc = '<<' * P(function(input, index) local s, e, delimiter = input:find('([%a_][%w_]*)[\n\r\f;]+', index) if s == index and delimiter then local end_heredoc = '[\n\r\f]+' - local _, e = input:find(end_heredoc .. delimiter, e) + e = select(2, input:find(end_heredoc .. delimiter, e)) return e and e + 1 or #input + 1 end end) @@ -100,8 +103,8 @@ local lit_str = 'q' * P('q')^-1 * literal_delimited local lit_array = 'qw' * literal_delimited local lit_cmd = 'qx' * literal_delimited local lit_tr = (P('tr') + 'y') * literal_delimited2 * S('cds')^0 -local string = token(lexer.STRING, sq_str + dq_str + cmd_str + heredoc + - lit_str + lit_array + lit_cmd + lit_tr) +local string = token(lexer.STRING, + sq_str + dq_str + cmd_str + heredoc + lit_str + lit_array + lit_cmd + lit_tr) local regex_str = #P('/') * lexer.last_char_includes('-<>+*!~\\=%&|^?:;([{') * lexer.range('/', true) * S('imosx')^0 local lit_regex = 'qr' * literal_delimited * S('imosx')^0 @@ -115,26 +118,30 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Comments. local line_comment = lexer.to_eol('#', true) -local block_comment = lexer.range(lexer.starts_line('=' * lexer.alpha), - lexer.starts_line('=cut')) +local block_comment = lexer.range(lexer.starts_line('=' * lexer.alpha), lexer.starts_line('=cut')) lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Variables. +-- LuaFormatter off local special_var = '$' * ( - '^' * S('ADEFHILMOPSTWX')^-1 + S('\\"[]\'&`+*.,;=%~?@<>(|/!-') + - ':' * (lexer.any - ':') + P('$') * -lexer.word + lexer.digit^1) + '^' * S('ADEFHILMOPSTWX')^-1 + + S('\\"[]\'&`+*.,;=%~?@<>(|/!-') + + ':' * (lexer.any - ':') + + P('$') * -lexer.word + + lexer.digit^1) +-- LuaFormatter on local plain_var = ('$#' + S('$@%')) * P('$')^0 * lexer.word + '$#' lex:add_rule('variable', token(lexer.VARIABLE, special_var + plain_var)) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('-<>+*!~\\=/%&|^.?:;()[]{}'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('-<>+*!~\\=/%&|^.,?:;()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/php.lua b/syntaxhighlight/textadept/php.lua index 8467274..d20fddf 100644 --- a/syntaxhighlight/textadept/php.lua +++ b/syntaxhighlight/textadept/php.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- PHP LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('php') @@ -12,20 +12,46 @@ local lex = lexer.new('php') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and array as bool boolean break case cfunction class const continue declare - default die directory do double echo else elseif empty enddeclare endfor - endforeach endif endswitch endwhile eval exit extends false float for foreach - function global if include include_once int integer isset list new null object - old_function or parent print real require require_once resource return static - stdclass string switch true unset use var while xor - __class__ __file__ __function__ __line__ __sleep __wakeup -]])) - -local word = (lexer.alpha + '_' + R('\127\255')) * - (lexer.alnum + '_' + R('\127\255'))^0 +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Reserved words (http://php.net/manual/en/reserved.keywords.php) + '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', + 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', + 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', + 'exit', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', 'function', 'global', 'goto', 'if', + 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', + 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', + 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor', + 'yield', 'from', + -- Reserved classes (http://php.net/manual/en/reserved.classes.php) + 'Directory', 'stdClass', '__PHP_Incomplete_Class', 'Exception', 'ErrorException', + 'php_user_filter', 'Closure', 'Generator', 'ArithmeticError', 'AssertionError', + 'DivisionByZeroError', 'Error', 'Throwable', 'ParseError', 'TypeError', 'self', 'static', 'parent' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, + word_match('int float bool string true false null void iterable object'))) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + -- Compile-time (https://www.php.net/manual/en/reserved.keywords.php) + '__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', + '__TRAIT__', + -- Reserved (https://www.php.net/manual/en/reserved.constants.php) + 'PHP_VERSION', 'PHP_MAJOR_VERSION', 'PHP_MINOR_VERSION', 'PHP_RELEASE_VERSION', 'PHP_VERSION_ID', + 'PHP_EXTRA_VERSION', 'PHP_ZTS', 'PHP_DEBUG', 'PHP_MAXPATHLEN', 'PHP_OS', 'PHP_OS_FAMILY', + 'PHP_SAPI', 'PHP_EOL', 'PHP_INT_MAX', 'PHP_INT_MIN', 'PHP_INT_SIZE', 'PHP_FLOAT_DIG', + 'PHP_FLOAT_EPSILON', 'PHP_FLOAT_MIN', 'PHP_FLOAT_MAX', 'DEFAULT_INCLUDE_PATH', 'PEAR_INSTALL_DIR', + 'PEAR_EXTENSION_DIR', 'PHP_EXTENSION_DIR', 'PHP_PREFIX', 'PHP_BINDIR', 'PHP_BINARY', 'PHP_MANDIR', + 'PHP_LIBDIR', 'PHP_DATADIR', 'PHP_SYSCONFDIR', 'PHP_LOCALSTATEDIR', 'PHP_CONFIG_FILE_PATH', + 'PHP_CONFIG_FILE_SCAN_DIR', 'PHP_SHLIB_SUFFIX', 'PHP_FD_SETSIZE', 'E_ERROR', 'E_WARNING', + 'E_PARSE', 'E_NOTICE', 'E_CORE_ERROR', 'E_CORE_WARNING', 'E_COMPILE_ERROR', 'E_USER_ERROR', + 'E_USER_WARNING', 'E_USER_NOTICE', 'E_DEPRECATED', 'E_DEPRECATED', 'E_USER_DEPRECATED', 'E_ALL', + 'E_STRICT', '__COMPILER_HALT_OFFSET__' +})) -- Identifiers. +local word = (lexer.alpha + '_' + lpeg.R('\127\255')) * (lexer.alnum + '_' + lpeg.R('\127\255'))^0 lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) -- Variables. @@ -38,7 +64,7 @@ local bq_str = lexer.range('`') local heredoc = '<<<' * P(function(input, index) local _, e, delimiter = input:find('([%a_][%w_]*)[\n\r\f]+', index) if delimiter then - local _, e = input:find('[\n\r\f]+' .. delimiter, e) + e = select(2, input:find('[\n\r\f]+' .. delimiter, e)) return e and e + 1 end end) @@ -63,13 +89,13 @@ local html = lexer.load('html') local php_start_rule = token('php_tag', '') html:embed(lex, php_start_rule, php_end_rule) -lex:add_style('php_tag', lexer.STYLE_EMBEDDED) +lex:add_style('php_tag', lexer.styles.embedded) -- Fold points. lex:add_fold_point('php_tag', '') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.OPERATOR, '(', ')') diff --git a/syntaxhighlight/textadept/pico8.lua b/syntaxhighlight/textadept/pico8.lua index edcf632..312f271 100644 --- a/syntaxhighlight/textadept/pico8.lua +++ b/syntaxhighlight/textadept/pico8.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2016-2020 Alejandro Baez (https://keybase.io/baez). See License.txt. +-- Copyright 2016-2021 Alejandro Baez (https://keybase.io/baez). See LICENSE. -- PICO-8 lexer. -- http://www.lexaloffle.com/pico-8.php local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('pico8') @@ -13,9 +13,8 @@ local lex = lexer.new('pico8') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - __lua__ __gfx__ __gff__ __map__ __sfx__ __music__ -]])) +lex:add_rule('keyword', + token(lexer.KEYWORD, word_match('__lua__ __gfx__ __gff__ __map__ __sfx__ __music__'))) -- Identifiers lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -27,14 +26,13 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('//', true))) lex:add_rule('number', token(lexer.NUMBER, lexer.integer)) -- Operators -lex:add_rule('operator', token(lexer.OPERATOR, S('_'))) +lex:add_rule('operator', token(lexer.OPERATOR, '_')) -- Embed Lua into PICO-8. local lua = lexer.load('lua') - local lua_start_rule = token('pico8_tag', '__lua__') -local lua_end_rule = token('pico8_tag', '__gfx__' ) +local lua_end_rule = token('pico8_tag', '__gfx__') lex:embed(lua, lua_start_rule, lua_end_rule) -lex:add_style('pico8_tag', lexer.STYLE_EMBEDDED) +lex:add_style('pico8_tag', lexer.styles.embedded) return lex diff --git a/syntaxhighlight/textadept/pike.lua b/syntaxhighlight/textadept/pike.lua index 353f76d..fd1e4f7 100644 --- a/syntaxhighlight/textadept/pike.lua +++ b/syntaxhighlight/textadept/pike.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Pike LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('pike') @@ -12,19 +12,17 @@ local lex = lexer.new('pike') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break case catch continue default do else for foreach gauge if lambda return - sscanf switch while import inherit +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'case', 'catch', 'continue', 'default', 'do', 'else', 'for', 'foreach', 'gauge', 'if', + 'lambda', 'return', 'sscanf', 'switch', 'while', 'import', 'inherit', -- Type modifiers. - constant extern final inline local nomask optional private protected public - static variant -]])) + 'constant', 'extern', 'final', 'inline', 'local', 'nomask', 'optional', 'private', 'protected', + 'public', 'static', 'variant' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - array class float function int mapping mixed multiset object program string - void -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'array class float function int mapping mixed multiset object program string void'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -43,8 +41,7 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('lLdDfF')^-1)) -- Preprocessors. -lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, - lexer.to_eol(lexer.starts_line('#')))) +lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, lexer.to_eol(lexer.starts_line('#')))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('<>=!+-/*%&|^~@`.,:;()[]{}'))) @@ -52,6 +49,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('<>=!+-/*%&|^~@`.,:;()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/pkgbuild.lua b/syntaxhighlight/textadept/pkgbuild.lua index 3e64dca..4dab915 100644 --- a/syntaxhighlight/textadept/pkgbuild.lua +++ b/syntaxhighlight/textadept/pkgbuild.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 gwash. See License.txt. +-- Copyright 2006-2021 gwash. See LICENSE. -- Archlinux PKGBUILD LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('pkgbuild') @@ -19,10 +19,9 @@ local sq_str = lexer.range("'", false, false) local dq_str = lexer.range('"') local ex_str = lexer.range('`') local heredoc = '<<' * P(function(input, index) - local s, e, _, delimiter = input:find('(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', - index) + local s, e, _, delimiter = input:find('(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index) if s == index and delimiter then - local _, e = input:find('[\n\r\f]+' .. delimiter, e) + e = select(2, input:find('[\n\r\f]+' .. delimiter, e)) return e and e + 1 or #input + 1 end end) @@ -32,29 +31,29 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + ex_str + heredoc)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - patch cd make patch mkdir cp sed install rm if then elif else fi case in esac - while for do done continue local return git svn co clone gconf-merge-schema - msg echo ln +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'patch', 'cd', 'make', 'patch', 'mkdir', 'cp', 'sed', 'install', 'rm', 'if', 'then', 'elif', + 'else', 'fi', 'case', 'in', 'esac', 'while', 'for', 'do', 'done', 'continue', 'local', 'return', + 'git', 'svn', 'co', 'clone', 'gconf-merge-schema', 'msg', 'echo', 'ln', -- Operators. - -a -b -c -d -e -f -g -h -k -p -r -s -t -u -w -x -O -G -L -S -N -nt -ot -ef -o - -z -n -eq -ne -lt -le -gt -ge -Np -i -]])) + '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-k', '-p', '-r', '-s', '-t', '-u', '-w', '-x', + '-O', '-G', '-L', '-S', '-N', '-nt', '-ot', '-ef', '-o', '-z', '-n', '-eq', '-ne', '-lt', '-le', + '-gt', '-ge', '-Np', '-i' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - build check package pkgver prepare -]] * '()')) +lex:add_rule('function', + token(lexer.FUNCTION, word_match('build check package pkgver prepare') * '()')) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ -- We do *not* list pkgver srcdir and startdir here. -- These are defined by makepkg but user should not alter them. - arch backup changelog checkdepends conflicts depends epoch groups install - license makedepends md5sums noextract optdepends options pkgbase pkgdesc - pkgname pkgrel pkgver provides replaces sha1sums sha256sums sha384sums - sha512sums source url validpgpkeys -]])) + 'arch', 'backup', 'changelog', 'checkdepends', 'conflicts', 'depends', 'epoch', 'groups', + 'install', 'license', 'makedepends', 'md5sums', 'noextract', 'optdepends', 'options', 'pkgbase', + 'pkgdesc', 'pkgname', 'pkgrel', 'pkgver', 'provides', 'replaces', 'sha1sums', 'sha256sums', + 'sha384sums', 'sha512sums', 'source', 'url', 'validpgpkeys' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -65,7 +64,7 @@ local parens = lexer.range('(', ')', true) local brackets = lexer.range('[', ']', true) local braces = lexer.range('{', '}', true) local backticks = lexer.range('`', true, false) -local number = lexer.digit^1 +local number = lexer.dec_num lex:add_rule('variable', token(lexer.VARIABLE, '$' * (symbol + parens + brackets + braces + backticks + number + lexer.word))) @@ -75,6 +74,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*^~.,:;?()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/pony.lua b/syntaxhighlight/textadept/pony.lua new file mode 100644 index 0000000..ad3b49b --- /dev/null +++ b/syntaxhighlight/textadept/pony.lua @@ -0,0 +1,95 @@ +local lpeg = require('lpeg') +-- Copyright 2017-2021 Murray Calavera. See LICENSE. +-- Pony LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('pony') + +-- Whitespace. +local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', ws) + +-- Capabilities. +local capability = token(lexer.LABEL, word_match('box iso ref tag trn val')) +lex:add_rule('capability', capability) + +-- Annotations. +local annotation = token(lexer.PREPROCESSOR, lexer.range('\\', false, false)) +lex:add_rule('annotation', annotation) + +-- Functions. +-- Highlight functions with syntax sugar at declaration. +lex:add_rule('function', + token(lexer.KEYWORD, word_match('fun new be')) * ws^-1 * annotation^-1 * ws^-1 * capability^-1 * + ws^-1 * token(lexer.FUNCTION, word_match{ + 'create', 'dispose', '_final', 'apply', 'update', 'add', 'sub', 'mul', 'div', 'mod', + 'add_unsafe', 'sub_unsafe', 'mul_unsafe', 'div_unsafe', 'mod_unsafe', 'shl', 'shr', + 'shl_unsafe', 'shr_unsafe', 'op_and', 'op_or', 'op_xor', 'eq', 'ne', 'lt', 'le', 'ge', 'gt', + 'eq_unsafe', 'ne_unsafe', 'lt_unsafe', 'le_unsafe', 'ge_unsafe', 'gt_unsafe', 'neg', + 'neg_unsafe', 'op_not', -- + 'has_next', 'next', -- + '_serialise_space', '_serialise', '_deserialise' + })) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'actor', 'as', 'be', 'break', 'class', 'compile_error', 'compile_intrinsic', 'continue', + 'consume', 'do', 'else', 'elseif', 'embed', 'end', 'error', 'for', 'fun', 'if', 'ifdef', 'iftype', + 'in', 'interface', 'is', 'isnt', 'lambda', 'let', 'match', 'new', 'object', 'primitive', + 'recover', 'repeat', 'return', 'struct', 'then', 'this', 'trait', 'try', 'type', 'until', 'use', + 'var', 'where', 'while', 'with' +})) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match('true false'))) + +-- Operators. +local ops = { + ['+'] = true, ['-'] = true, ['*'] = true, ['/'] = true, ['%'] = true, ['+~'] = true, + ['-~'] = true, ['*~'] = true, ['/~'] = true, ['%~'] = true, ['<<'] = true, ['>>'] = true, + ['<<~'] = true, ['>>~'] = true, ['=='] = true, ['!='] = true, ['<'] = true, ['<='] = true, + ['>='] = true, ['>'] = true, ['==~'] = true, ['!=~'] = true, ['<~'] = true, ['<=~'] = true, + ['>=~'] = true, ['>~'] = true +} +lex:add_rule('operator', token(lexer.OPERATOR, word_match('and or xor not addressof digestof') + + lpeg.Cmt(S('+-*/%<>=!~')^1, function(input, index, op) return ops[op] and index or nil end))) + +-- Identifiers. +local id_suffix = (lexer.alnum + "'" + '_')^0 +lex:add_rule('type', token(lexer.TYPE, P('_')^-1 * lexer.upper * id_suffix)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, P('_')^-1 * lexer.lower * id_suffix)) +lex:add_rule('lookup', token(lexer.IDENTIFIER, '_' * lexer.digit^1)) + +-- Strings. +local sq_str = lexer.range("'") +local dq_str = lexer.range('"') +local tq_str = lexer.range('"""') +lex:add_rule('string', token(lexer.STRING, sq_str + tq_str + dq_str)) + +-- Numbers. +local function num(digit) return digit * (digit^0 * '_')^0 * digit^1 + digit end +local int = num(lexer.digit) +local frac = '.' * int +local exp = S('eE') * (P('-') + '+')^-1 * int +local hex = '0x' * num(lexer.xdigit) +local bin = '0b' * num(S('01')) +local float = int * frac^-1 * exp^-1 +lex:add_rule('number', token(lexer.NUMBER, hex + bin + float)) + +-- Comments. +local line_comment = lexer.to_eol('//') +local block_comment = lexer.range('/*', '*/', false, false, true) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Punctuation. +-- There is no suitable token name for this, change this if ever one is added. +lex:add_rule('punctuation', + token(lexer.OPERATOR, P('=>') + '.>' + '<:' + '->' + S('=.,:;()[]{}!?~^&|_@'))) + +-- Qualifiers. +lex:add_rule('qualifier', token(lexer.LABEL, '#' * word_match('read send share any alias'))) + +return lex diff --git a/syntaxhighlight/textadept/powershell.lua b/syntaxhighlight/textadept/powershell.lua index 4087c1d..d866239 100644 --- a/syntaxhighlight/textadept/powershell.lua +++ b/syntaxhighlight/textadept/powershell.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2015-2021 Mitchell. See LICENSE. -- PowerShell LPeg lexer. -- Contributed by Jeff Stone. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('powershell') @@ -16,37 +16,35 @@ lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - Begin Break Continue Do Else End Exit For ForEach ForEach-Object Get-Date - Get-Random If Param Pause Powershell Process Read-Host Return Switch While - Write-Host -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'Begin', 'Break', 'Continue', 'Do', 'Else', 'End', 'Exit', 'For', 'ForEach', 'ForEach-Object', + 'Get-Date', 'Get-Random', 'If', 'Param', 'Pause', 'Powershell', 'Process', 'Read-Host', 'Return', + 'Switch', 'While', 'Write-Host' +}, true))) -- Comparison Operators. -lex:add_rule('comparison', token(lexer.KEYWORD, '-' * word_match([[ - and as band bor contains eq ge gt is isnot le like lt match ne nomatch not - notcontains notlike or replace -]], true))) +lex:add_rule('comparison', token(lexer.KEYWORD, '-' * word_match({ + 'and', 'as', 'band', 'bor', 'contains', 'eq', 'ge', 'gt', 'is', 'isnot', 'le', 'like', 'lt', + 'match', 'ne', 'nomatch', 'not', 'notcontains', 'notlike', 'or', 'replace' +}, true))) -- Parameters. -lex:add_rule('parameter', token(lexer.KEYWORD, '-' * word_match([[ - Confirm Debug ErrorAction ErrorVariable OutBuffer OutVariable Verbose WhatIf -]], true))) +lex:add_rule('parameter', token(lexer.KEYWORD, '-' * + word_match('Confirm Debug ErrorAction ErrorVariable OutBuffer OutVariable Verbose WhatIf', true))) -- Properties. -lex:add_rule('property', token(lexer.KEYWORD, '.' * word_match([[ - day dayofweek dayofyear hour millisecond minute month second timeofday year -]], true))) +lex:add_rule('property', token(lexer.KEYWORD, '.' * + word_match('day dayofweek dayofyear hour millisecond minute month second timeofday year', true))) -- Types. -lex:add_rule('type', token(lexer.KEYWORD, '[' * word_match([[ - array boolean byte char datetime decimal double hashtable int long single - string xml -]], true) * ']')) +lex:add_rule('type', token(lexer.KEYWORD, '[' * word_match({ + 'array', 'boolean', 'byte', 'char', 'datetime', 'decimal', 'double', 'hashtable', 'int', 'long', + 'single', 'string', 'xml' +}, true) * ']')) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '$' * - (lexer.digit^1 + lexer.word + lexer.range('{', '}', true)))) +lex:add_rule('variable', token(lexer.VARIABLE, + '$' * (lexer.digit^1 + lexer.word + lexer.range('{', '}', true)))) -- Strings. lex:add_rule('string', token(lexer.STRING, lexer.range('"', true))) diff --git a/syntaxhighlight/textadept/prolog.lua b/syntaxhighlight/textadept/prolog.lua index a58aea2..1f5474b 100644 --- a/syntaxhighlight/textadept/prolog.lua +++ b/syntaxhighlight/textadept/prolog.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Lexer enhanced to conform to the realities of Prologs on the ground by -- Michael T. Richter. Copyright is explicitly assigned back to Mitchell. -- Prolog LPeg lexer. @@ -27,7 +27,7 @@ local lpeg = require('lpeg') local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, B, V, C = lpeg.P, lpeg.R, lpeg.S, lpeg.B, lpeg.V, lpeg.C +local P, S = lpeg.P, lpeg.S local lex = lexer.new('prolog') @@ -73,9 +73,9 @@ directives.swipl = directives.iso .. [[ ]] lex:add_rule('directive', token(lexer.WHITESPACE, lexer.starts_line(S(' \t'))^0) * - token(lexer.OPERATOR, P':-') * + token(lexer.OPERATOR, ':-') * token(lexer.WHITESPACE, S(' \t')^0) * - token(lexer.PREPROCESSOR, P(word_match(directives[dialect])))) + token(lexer.PREPROCESSOR, word_match(directives[dialect]))) -- Whitespace. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) @@ -281,7 +281,7 @@ one_plus_arity_keywords.swipl = [[ ]] lex:add_rule('keyword', token(lexer.KEYWORD, word_match(zero_arity_keywords[dialect]) + - (word_match(one_plus_arity_keywords[dialect]) * #(P'(')))) + word_match(one_plus_arity_keywords[dialect]) * #P('('))) -- BIFs. local bifs = {} @@ -304,12 +304,12 @@ bifs.swipl = [[ nan pi popcount powm random random_float rational rationalize rdiv rem round sign sin sinh sqrt tan tanh truncate xor ]] -lex:add_rule('bif', token(lexer.FUNCTION, word_match(bifs[dialect]) * #(P'('))) +lex:add_rule('bif', token(lexer.FUNCTION, word_match(bifs[dialect]) * #P('('))) -- Numbers. local decimal_group = S('+-')^-1 * (lexer.digit + '_')^1 local binary_number = '0b' * (S('01') + '_')^1 -local character_code = '0\'' * S('\\')^-1 * (lexer.print - lexer.space) +local character_code = '0\'' * S('\\')^-1 * lexer.graph local decimal_number = decimal_group * ('.' * decimal_group)^-1 * ('e' * decimal_group)^-1 local hexadecimal_number = '0x' * (lexer.xdigit + '_')^1 diff --git a/syntaxhighlight/textadept/props.lua b/syntaxhighlight/textadept/props.lua index e1b0165..c63a7c5 100644 --- a/syntaxhighlight/textadept/props.lua +++ b/syntaxhighlight/textadept/props.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Props LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('props', {lex_by_line = true}) @@ -12,9 +12,9 @@ local lex = lexer.new('props', {lex_by_line = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Colors. -lex:add_rule('color', token('color', '#' * lexer.xdigit * lexer.xdigit * - lexer.xdigit * lexer.xdigit * lexer.xdigit * lexer.xdigit)) -lex:add_style('color', lexer.STYLE_NUMBER) +local xdigit = lexer.xdigit +lex:add_rule('color', token('color', '#' * xdigit * xdigit * xdigit * xdigit * xdigit * xdigit)) +lex:add_style('color', lexer.styles.number) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) @@ -28,7 +28,6 @@ local dq_str = lexer.range('"') lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '$' * - lexer.range('(', ')', true))) +lex:add_rule('variable', token(lexer.VARIABLE, '$' * lexer.range('(', ')', true))) return lex diff --git a/syntaxhighlight/textadept/protobuf.lua b/syntaxhighlight/textadept/protobuf.lua index 56072d3..e849243 100644 --- a/syntaxhighlight/textadept/protobuf.lua +++ b/syntaxhighlight/textadept/protobuf.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2016-2020 David B. Lamkins . See License.txt. +-- Copyright 2016-2021 David B. Lamkins . See LICENSE. -- Protocol Buffer IDL LPeg lexer. -- local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('protobuf') @@ -13,16 +13,17 @@ local lex = lexer.new('protobuf') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - contained syntax import option package message group oneof optional required - repeated default extend extensions to max reserved service rpc returns -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'contained', 'syntax', 'import', 'option', 'package', 'message', 'group', 'oneof', 'optional', + 'required', 'repeated', 'default', 'extend', 'extensions', 'to', 'max', 'reserved', 'service', + 'rpc', 'returns' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - int32 int64 uint32 uint64 sint32 sint64 fixed32 fixed64 sfixed32 sfixed64 - float double bool string bytes enum true false -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32', 'fixed64', 'sfixed32', + 'sfixed64', 'float', 'double', 'bool', 'string', 'bytes', 'enum', 'true', 'false' +})) -- Strings. local sq_str = P('L')^-1 * lexer.range("'", true) diff --git a/syntaxhighlight/textadept/ps.lua b/syntaxhighlight/textadept/ps.lua index 6b369fe..7bb2ed1 100644 --- a/syntaxhighlight/textadept/ps.lua +++ b/syntaxhighlight/textadept/ps.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Postscript LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ps') @@ -12,17 +12,17 @@ local lex = lexer.new('ps') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - pop exch dup copy roll clear count mark cleartomark counttomark exec if ifelse - for repeat loop exit stop stopped countexecstack execstack quit start - true false NULL -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'pop', 'exch', 'dup', 'copy', 'roll', 'clear', 'count', 'mark', 'cleartomark', 'counttomark', + 'exec', 'if', 'ifelse', 'for', 'repeat', 'loop', 'exit', 'stop', 'stopped', 'countexecstack', + 'execstack', 'quit', 'start', 'true', 'false', 'NULL' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - add div idiv mod mul sub abs ned ceiling floor round truncate sqrt atan cos - sin exp ln log rand srand rrand -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'add', 'div', 'idiv', 'mod', 'mul', 'sub', 'abs', 'ned', 'ceiling', 'floor', 'round', 'truncate', + 'sqrt', 'atan', 'cos', 'sin', 'exp', 'ln', 'log', 'rand', 'srand', 'rrand' +})) -- Identifiers. local word = (lexer.alpha + '-') * (lexer.alnum + '-')^0 diff --git a/syntaxhighlight/textadept/pure.lua b/syntaxhighlight/textadept/pure.lua index b2ce647..52eac12 100644 --- a/syntaxhighlight/textadept/pure.lua +++ b/syntaxhighlight/textadept/pure.lua @@ -1,51 +1,49 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 David B. Lamkins . See License.txt. +-- Copyright 2015-2021 David B. Lamkins . See LICENSE. -- pure LPeg lexer, see http://purelang.bitbucket.org/ local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('pure') -- Whitespace. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'namespace', 'with', 'end', 'using', 'interface', 'extern', 'let', 'const', 'def', 'type', + 'public', 'private', 'nonfix', 'outfix', 'infix', 'infixl', 'infixr', 'prefix', 'postfix', 'if', + 'otherwise', 'when', 'case', 'of', 'then', 'else' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"', true))) + -- Comments. local line_comment = lexer.to_eol('//') local block_comment = lexer.range('/*', '*/') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) --- Pragmas. -local hashbang = lexer.starts_line('#!') * (lexer.nonnewline - '//')^0 -lex:add_rule('pragma', token(lexer.PREPROCESSOR, hashbang)) - --- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - namespace with end using interface extern let const def type public private - nonfix outfix infix infixl infixr prefix postfix if otherwise when case of - then else -]])) - -- Numbers. local bin = '0' * S('Bb') * S('01')^1 -local hex = '0' * S('Xx') * (R('09') + R('af') + R('AF'))^1 -local dec = R('09')^1 +local hex = lexer.hex_num +local dec = lexer.dec_num local int = (bin + hex + dec) * P('L')^-1 local rad = P('.') - '..' local exp = (S('Ee') * S('+-')^-1 * int)^-1 local flt = int * (rad * dec)^-1 * exp + int^-1 * rad * dec * exp lex:add_rule('number', token(lexer.NUMBER, flt + int)) --- Operators. -local punct = S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\'') -local dots = P('..') -lex:add_rule('operator', token(lexer.OPERATOR, dots + punct)) - --- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) +-- Pragmas. +local hashbang = lexer.starts_line('#!') * (lexer.nonnewline - '//')^0 +lex:add_rule('pragma', token(lexer.PREPROCESSOR, hashbang)) --- Strings. -lex:add_rule('string', token(lexer.STRING, lexer.range('"', true))) +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, '..' + S('+-/*%<>~!=^&|?~:;,.()[]{}@#$`\\\''))) return lex diff --git a/syntaxhighlight/textadept/python.lua b/syntaxhighlight/textadept/python.lua index c9a4ea4..489cf69 100644 --- a/syntaxhighlight/textadept/python.lua +++ b/syntaxhighlight/textadept/python.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Python LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('python', {fold_by_indentation = true}) @@ -12,63 +12,65 @@ local lex = lexer.new('python', {fold_by_indentation = true}) lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and as assert break class continue def del elif else except exec finally for - from global if import in is lambda nonlocal not or pass print raise return try - while with yield +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', + 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', + 'lambda', 'nonlocal', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', + 'yield', -- Descriptors/attr access. - __get__ __set__ __delete__ __slots__ + '__get__', '__set__', '__delete__', '__slots__', -- Class. - __new__ __init__ __del__ __repr__ __str__ __cmp__ __index__ __lt__ __le__ - __gt__ __ge__ __eq__ __ne__ __hash__ __nonzero__ __getattr__ __getattribute__ - __setattr__ __delattr__ __call__ + '__new__', '__init__', '__del__', '__repr__', '__str__', '__cmp__', '__index__', '__lt__', + '__le__', '__gt__', '__ge__', '__eq__', '__ne__', '__hash__', '__nonzero__', '__getattr__', + '__getattribute__', '__setattr__', '__delattr__', '__call__', -- Operator. - __add__ __sub__ __mul__ __div__ __floordiv__ __mod__ __divmod__ __pow__ - __and__ __xor__ __or__ __lshift__ __rshift__ __nonzero__ __neg__ __pos__ - __abs__ __invert__ __iadd__ __isub__ __imul__ __idiv__ __ifloordiv__ __imod__ - __ipow__ __iand__ __ixor__ __ior__ __ilshift__ __irshift__ + '__add__', '__sub__', '__mul__', '__div__', '__floordiv__', '__mod__', '__divmod__', '__pow__', + '__and__', '__xor__', '__or__', '__lshift__', '__rshift__', '__nonzero__', '__neg__', '__pos__', + '__abs__', '__invert__', '__iadd__', '__isub__', '__imul__', '__idiv__', '__ifloordiv__', + '__imod__', '__ipow__', '__iand__', '__ixor__', '__ior__', '__ilshift__', '__irshift__', -- Conversions. - __int__ __long__ __float__ __complex__ __oct__ __hex__ __coerce__ + '__int__', '__long__', '__float__', '__complex__', '__oct__', '__hex__', '__coerce__', -- Containers. - __len__ __getitem__ __missing__ __setitem__ __delitem__ __contains__ __iter__ - __getslice__ __setslice__ __delslice__ + '__len__', '__getitem__', '__missing__', '__setitem__', '__delitem__', '__contains__', '__iter__', + '__getslice__', '__setslice__', '__delslice__', -- Module and class attribs. - __doc__ __name__ __dict__ __file__ __path__ __module__ __bases__ __class__ - __self__ + '__doc__', '__name__', '__dict__', '__file__', '__path__', '__module__', '__bases__', '__class__', + '__self__', -- Stdlib/sys. - __builtin__ __future__ __main__ __import__ __stdin__ __stdout__ __stderr__ + '__builtin__', '__future__', '__main__', '__import__', '__stdin__', '__stdout__', '__stderr__', -- Other. - __debug__ __doc__ __import__ __name__ -]])) + '__debug__', '__doc__', '__import__', '__name__' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs all any apply basestring bool buffer callable chr classmethod cmp coerce - compile complex copyright credits delattr dict dir divmod enumerate eval - execfile exit file filter float frozenset getattr globals hasattr hash help - hex id input int intern isinstance issubclass iter len license list locals - long map max min object oct open ord pow property quit range raw_input reduce - reload repr reversed round set setattr slice sorted staticmethod str sum super - tuple type unichr unicode vars xrange zip -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'abs', 'all', 'any', 'apply', 'basestring', 'bool', 'buffer', 'callable', 'chr', 'classmethod', + 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', + 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'frozenset', 'getattr', + 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', + 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', + 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', + 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', + 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - ArithmeticError AssertionError AttributeError BaseException DeprecationWarning - EOFError Ellipsis EnvironmentError Exception False FloatingPointError - FutureWarning GeneratorExit IOError ImportError ImportWarning IndentationError - IndexError KeyError KeyboardInterrupt LookupError MemoryError NameError None - NotImplemented NotImplementedError OSError OverflowError - PendingDeprecationWarning ReferenceError RuntimeError RuntimeWarning - StandardError StopIteration SyntaxError SyntaxWarning SystemError SystemExit - TabError True TypeError UnboundLocalError UnicodeDecodeError - UnicodeEncodeError UnicodeError UnicodeTranslateError UnicodeWarning - UserWarning ValueError Warning ZeroDivisionError -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + 'ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'DeprecationWarning', + 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', + 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', + 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', + 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', + 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', + 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', + 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', + 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', + 'ZeroDivisionError' +})) -- Self. -lex:add_rule('self', token('self', P('self'))) -lex:add_style('self', lexer.STYLE_TYPE) +lex:add_rule('self', token('self', 'self')) +lex:add_style('self', lexer.styles.type) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -83,19 +85,18 @@ local tq_str = lexer.range("'''") + lexer.range('"""') -- TODO: raw_strs cannot end in single \. local raw_sq_str = P('u')^-1 * 'r' * lexer.range("'", false, false) local raw_dq_str = P('U')^-1 * 'R' * lexer.range('"', false, false) -lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str + - raw_sq_str + raw_dq_str)) +lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str + raw_sq_str + raw_dq_str)) -- Numbers. -local dec = lexer.digit^1 * S('Ll')^-1 +local dec = lexer.dec_num * S('Ll')^-1 local bin = '0b' * S('01')^1 * ('_' * S('01')^1)^0 -local oct = '0' * R('07')^1 * S('Ll')^-1 +local oct = lexer.oct_num * S('Ll')^-1 local integer = S('+-')^-1 * (bin + lexer.hex_num + oct + dec) lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) -- Decorators. lex:add_rule('decorator', token('decorator', lexer.to_eol('@'))) -lex:add_style('decorator', lexer.STYLE_PREPROCESSOR) +lex:add_style('decorator', lexer.styles.preprocessor) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~`'))) diff --git a/syntaxhighlight/textadept/rails.lua b/syntaxhighlight/textadept/rails.lua index f03f038..af52154 100644 --- a/syntaxhighlight/textadept/rails.lua +++ b/syntaxhighlight/textadept/rails.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Ruby on Rails LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rails', {inherit = lexer.load('ruby')}) @@ -12,44 +12,33 @@ local lex = lexer.new('rails', {inherit = lexer.load('ruby')}) lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Functions. - --- ActionPack. -lex:modify_rule('function', token(lexer.FUNCTION, word_match[[ - before_filter skip_before_filter skip_after_filter after_filter around_filter - filter filter_parameter_logging layout require_dependency render render_action - render_text render_file render_template render_nothing render_component - render_without_layout rescue_from url_for redirect_to redirect_to_path - redirect_to_url respond_to helper helper_method model service observer - serialize scaffold verify hide_action -]]) + - --- View helpers. -token(lexer.FUNCTION, word_match[[ - check_box content_for error_messages_for form_for fields_for file_field - hidden_field image_submit_tag label link_to password_field radio_button submit - text_field text_area -]]) + - --- ActiveRecord -token(lexer.FUNCTION, word_match[[ - after_create after_destroy after_save after_update after_validation - after_validation_on_create after_validation_on_update before_create - before_destroy before_save before_update before_validation - before_validation_on_create before_validation_on_update composed_of belongs_to - has_one has_many has_and_belongs_to_many validate validates validate_on_create - validates_numericality_of validate_on_update validates_acceptance_of - validates_associated validates_confirmation_of validates_each - validates_format_of validates_inclusion_of validates_exclusion_of - validates_length_of validates_presence_of validates_size_of - validates_uniqueness_of - attr_protected attr_accessible attr_readonly accepts_nested_attributes_for - default_scope scope -]]) + - --- ActiveSupport -token(lexer.FUNCTION, word_match[[ - alias_method_chain alias_attribute delegate cattr_accessor mattr_accessor - returning memoize -]]) + lex:get_rule('function')) +lex:modify_rule('function', token(lexer.FUNCTION, word_match{ + -- ActionPack. + 'before_filter', 'skip_before_filter', 'skip_after_filter', 'after_filter', 'around_filter', + 'filter', 'filter_parameter_logging', 'layout', 'require_dependency', 'render', 'render_action', + 'render_text', 'render_file', 'render_template', 'render_nothing', 'render_component', + 'render_without_layout', 'rescue_from', 'url_for', 'redirect_to', 'redirect_to_path', + 'redirect_to_url', 'respond_to', 'helper', 'helper_method', 'model', 'service', 'observer', + 'serialize', 'scaffold', 'verify', 'hide_action', + -- View helpers. + 'check_box', 'content_for', 'error_messages_for', 'form_for', 'fields_for', 'file_field', + 'hidden_field', 'image_submit_tag', 'label', 'link_to', 'password_field', 'radio_button', + 'submit', 'text_field', 'text_area', + -- ActiveRecord. + 'after_create', 'after_destroy', 'after_save', 'after_update', 'after_validation', + 'after_validation_on_create', 'after_validation_on_update', 'before_create', 'before_destroy', + 'before_save', 'before_update', 'before_validation', 'before_validation_on_create', + 'before_validation_on_update', 'composed_of', 'belongs_to', 'has_one', 'has_many', + 'has_and_belongs_to_many', 'validate', 'validates', 'validate_on_create', + 'validates_numericality_of', 'validate_on_update', 'validates_acceptance_of', + 'validates_associated', 'validates_confirmation_of', 'validates_each', 'validates_format_of', + 'validates_inclusion_of', 'validates_exclusion_of', 'validates_length_of', + 'validates_presence_of', 'validates_size_of', 'validates_uniqueness_of', -- + 'attr_protected', 'attr_accessible', 'attr_readonly', 'accepts_nested_attributes_for', + 'default_scope', 'scope', + -- ActiveSupport. + 'alias_method_chain', 'alias_attribute', 'delegate', 'cattr_accessor', 'mattr_accessor', + 'returning', 'memoize' +}) + lex:get_rule('function')) return lex diff --git a/syntaxhighlight/textadept/rc.lua b/syntaxhighlight/textadept/rc.lua index c48976e..08cb3d3 100644 --- a/syntaxhighlight/textadept/rc.lua +++ b/syntaxhighlight/textadept/rc.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2017-2020 Michael Forney. See License.txt. +-- Copyright 2017-2021 Michael Forney. See LICENSE. -- rc LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rc') @@ -12,10 +12,10 @@ local lex = lexer.new('rc') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - for in while if not switch fn builtin cd eval exec exit flag rfork shift - ulimit umask wait whatis . ~ -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'for', 'in', 'while', 'if', 'not', 'switch', 'case', 'fn', 'builtin', 'cd', 'eval', 'exec', + 'exit', 'flag', 'rfork', 'shift', 'ulimit', 'umask', 'wait', 'whatis', '.', '~' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -23,11 +23,10 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Strings. local str = lexer.range("'", false, false) local heredoc = '<<' * P(function(input, index) - local s, e, _, delimiter = input:find('[ \t]*(["\']?)([%w!"%%+,-./:?@_~]+)%1', - index) + local s, e, _, delimiter = input:find('[ \t]*(["\']?)([%w!"%%+,-./:?@_~]+)%1', index) if s == index and delimiter then delimiter = delimiter:gsub('[%%+-.?]', '%%%1') - local _, e = input:find('[\n\r]' .. delimiter .. '[\n\r]', e) + e = select(2, input:find('[\n\r]' .. delimiter .. '[\n\r]', e)) return e and e + 1 or #input + 1 end end) @@ -40,15 +39,14 @@ lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Variables. -lex:add_rule('variable', token(lexer.VARIABLE, '$' * S('"#')^-1 * - ('*' + lexer.digit^1 + lexer.word))) +lex:add_rule('variable', + token(lexer.VARIABLE, '$' * S('"#')^-1 * ('*' + lexer.digit^1 + lexer.word))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('@`=!<>*&^|;?()[]{}') + - '\\\n')) +lex:add_rule('operator', token(lexer.OPERATOR, S('@`=!<>*&^|;?()[]{}') + '\\\n')) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/reason.lua b/syntaxhighlight/textadept/reason.lua new file mode 100644 index 0000000..8365f6e --- /dev/null +++ b/syntaxhighlight/textadept/reason.lua @@ -0,0 +1,66 @@ +local lpeg = require('lpeg') +-- Copyright 2018-2021 Hugo O. Rivera. See LICENSE. +-- Reason (https://reasonml.github.io/) LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('reason') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'as', 'asr', 'begin', 'class', 'closed', 'constraint', 'do', 'done', 'downto', 'else', + 'end', 'exception', 'external', 'failwith', 'false', 'flush', 'for', 'fun', 'function', 'functor', + 'if', 'in', 'include', 'inherit', 'incr', 'land', 'let', 'load', 'los', 'lsl', 'lsr', 'lxor', + 'method', 'mod', 'module', 'mutable', 'new', 'not', 'of', 'open', 'option', 'or', 'parser', + 'private', 'ref', 'rec', 'raise', 'regexp', 'sig', 'struct', 'stdout', 'stdin', 'stderr', + 'switch', 'then', 'to', 'true', 'try', 'type', 'val', 'virtual', 'when', 'while', 'with' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match('int float bool char string unit'))) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'raise', 'invalid_arg', 'failwith', 'compare', 'min', 'max', 'succ', 'pred', 'mod', 'abs', + 'max_int', 'min_int', 'sqrt', 'exp', 'log', 'log10', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', + 'atan2', 'cosh', 'sinh', 'tanh', 'ceil', 'floor', 'abs_float', 'mod_float', 'frexp', 'ldexp', + 'modf', 'float', 'float_of_int', 'truncate', 'int_of_float', 'infinity', 'nan', 'max_float', + 'min_float', 'epsilon_float', 'classify_float', 'int_of_char', 'char_of_int', 'ignore', + 'string_of_bool', 'bool_of_string', 'string_of_int', 'int_of_string', 'string_of_float', + 'float_of_string', 'fst', 'snd', 'stdin', 'stdout', 'stderr', 'print_char', 'print_string', + 'print_int', 'print_float', 'print_endline', 'print_newline', 'prerr_char', 'prerr_string', + 'prerr_int', 'prerr_float', 'prerr_endline', 'prerr_newline', 'read_line', 'read_int', + 'read_float', 'open_out', 'open_out_bin', 'open_out_gen', 'flush', 'flush_all', 'output_char', + 'output_string', 'output', 'output_byte', 'output_binary_int', 'output_value', 'seek_out', + 'pos_out', 'out_channel_length', 'close_out', 'close_out_noerr', 'set_binary_mode_out', 'open_in', + 'open_in_bin', 'open_in_gen', 'input_char', 'input_line', 'input', 'really_input', 'input_byte', + 'input_binary_int', 'input_value', 'seek_in', 'pos_in', 'in_channel_length', 'close_in', + 'close_in_noerr', 'set_binary_mode_in', 'incr', 'decr', 'string_of_format', 'format_of_string', + 'exit', 'at_exit' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Comments. +local line_comment = lexer.to_eol('//') +local block_comment = lexer.range('/*', '*/', false, false, true) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/.,:;~!#%^&|?[](){}'))) + +return lex diff --git a/syntaxhighlight/textadept/rebol.lua b/syntaxhighlight/textadept/rebol.lua index ada445d..88dc824 100644 --- a/syntaxhighlight/textadept/rebol.lua +++ b/syntaxhighlight/textadept/rebol.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Rebol LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rebol') @@ -17,70 +17,74 @@ local block_comment = 'comment' * P(' ')^-1 * lexer.range('{', '}') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abs absolute add and~ at back change clear complement copy cp divide fifth - find first fourth head insert last make max maximum min minimum multiply - negate next or~ pick poke power random remainder remove second select skip - sort subtract tail third to trim xor~ - alias all any arccosine arcsine arctangent bind break browse call - caret-to-offset catch checksum close comment compose compress cosine debase - decompress dehex detab dh-compute-key dh-generate-key dh-make-key difference - disarm do dsa-generate-key dsa-make-key dsa-make-signature - dsa-verify-signature either else enbase entab exclude exit exp foreach form - free get get-modes halt hide if in intersect load log-10 log-2 log-e loop - lowercase maximum-of minimum-of mold not now offset-to-caret open parse prin - print protect q query quit read read-io recycle reduce repeat return reverse - rsa-encrypt rsa-generate-key rsa-make-key save secure set set-modes show sine - size-text square-root tangent textinfo throw to-hex to-local-file - to-rebol-file trace try union unique unprotect unset until update uppercase - use wait while write write-io - basic-syntax-header crlf font-fixed font-sans-serif font-serif list-words - outstr val value - about alert alter append array ask boot-prefs build-tag center-face change-dir - charset choose clean-path clear-fields confine confirm context cvs-date - cvs-version decode-cgi decode-url deflag-face delete demo desktop dirize - dispatch do-boot do-events do-face do-face-alt does dump-face dump-pane echo - editor emailer emit extract find-by-type find-key-face find-window flag-face - flash focus for forall forever forskip func function get-net-info get-style - has help hide-popup import-email inform input insert-event-func join launch - launch-thru layout license list-dir load-image load-prefs load-thru make-dir - make-face net-error open-events parse-email-addrs parse-header - parse-header-date parse-xml path-thru probe protect-system read-net read-thru - reboot reform rejoin remold remove-event-func rename repend replace request - request-color request-date request-download request-file request-list - request-pass request-text resend save-prefs save-user scroll-para send - set-font set-net set-para set-style set-user set-user-name show-popup source - split-path stylize switch throw-on-error to-binary to-bitset to-block to-char - to-date to-decimal to-email to-event to-file to-get-word to-hash to-idate - to-image to-integer to-issue to-list to-lit-path to-lit-word to-logic to-money - to-none to-pair to-paren to-path to-refinement to-set-path to-set-word - to-string to-tag to-time to-tuple to-url to-word unfocus uninstall unview - upgrade Usage vbug view view-install view-prefs what what-dir write-user - return at space pad across below origin guide tabs indent style styles size - sense backcolor do none - action? any-block? any-function? any-string? any-type? any-word? binary? - bitset? block? char? datatype? date? decimal? email? empty? equal? error? - even? event? file? function? get-word? greater-or-equal? greater? hash? head? - image? index? integer? issue? length? lesser-or-equal? lesser? library? list? - lit-path? lit-word? logic? money? native? negative? none? not-equal? number? - object? odd? op? pair? paren? path? port? positive? refinement? routine? same? - series? set-path? set-word? strict-equal? strict-not-equal? string? struct? - tag? tail? time? tuple? unset? url? word? zero? connected? crypt-strength? - exists-key? input? script? type? value? ? ?? dir? exists-thru? exists? - flag-face? found? in-window? info? inside? link-app? link? modified? offset? - outside? screen-offset? size? span? view? viewed? win-offset? within? - action! any-block! any-function! any-string! any-type! any-word! binary! - bitset! block! char! datatype! date! decimal! email! error! event! file! - function! get-word! hash! image! integer! issue! library! list! lit-path! - lit-word! logic! money! native! none! number! object! op! pair! paren! path! - port! refinement! routine! series! set-path! set-word! string! struct! symbol! - tag! time! tuple! unset! url! word! - true false self -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abs', 'absolute', 'add', 'and~', 'at', 'back', 'change', 'clear', 'complement', 'copy', 'cp', + 'divide', 'fifth', 'find', 'first', 'fourth', 'head', 'insert', 'last', 'make', 'max', 'maximum', + 'min', 'minimum', 'multiply', 'negate', 'next', 'or~', 'pick', 'poke', 'power', 'random', + 'remainder', 'remove', 'second', 'select', 'skip', 'sort', 'subtract', 'tail', 'third', 'to', + 'trim', 'xor~', -- + 'alias', 'all', 'any', 'arccosine', 'arcsine', 'arctangent', 'bind', 'break', 'browse', 'call', + 'caret-to-offset', 'catch', 'checksum', 'close', 'comment', 'compose', 'compress', 'cosine', + 'debase', 'decompress', 'dehex', 'detab', 'dh-compute-key', 'dh-generate-key', 'dh-make-key', + 'difference', 'disarm', 'do', 'dsa-generate-key', 'dsa-make-key', 'dsa-make-signature', + 'dsa-verify-signature', 'either', 'else', 'enbase', 'entab', 'exclude', 'exit', 'exp', 'foreach', + 'form', 'free', 'get', 'get-modes', 'halt', 'hide', 'if', 'in', 'intersect', 'load', 'log-10', + 'log-2', 'log-e', 'loop', 'lowercase', 'maximum-of', 'minimum-of', 'mold', 'not', 'now', + 'offset-to-caret', 'open', 'parse', 'prin', 'print', 'protect', 'q', 'query', 'quit', 'read', + 'read-io', 'recycle', 'reduce', 'repeat', 'return', 'reverse', 'rsa-encrypt', 'rsa-generate-key', + 'rsa-make-key', 'save', 'secure', 'set', 'set-modes', 'show', 'sine', 'size-text', 'square-root', + 'tangent', 'textinfo', 'throw', 'to-hex', 'to-local-file', 'to-rebol-file', 'trace', 'try', + 'union', 'unique', 'unprotect', 'unset', 'until', 'update', 'uppercase', 'use', 'wait', 'while', + 'write', 'write-io', -- + 'basic-syntax-header', 'crlf', 'font-fixed', 'font-sans-serif', 'font-serif', 'list-words', + 'outstr', 'val', 'value', -- + 'about', 'alert', 'alter', 'append', 'array', 'ask', 'boot-prefs', 'build-tag', 'center-face', + 'change-dir', 'charset', 'choose', 'clean-path', 'clear-fields', 'confine', 'confirm', 'context', + 'cvs-date', 'cvs-version', 'decode-cgi', 'decode-url', 'deflag-face', 'delete', 'demo', 'desktop', + 'dirize', 'dispatch', 'do-boot', 'do-events', 'do-face', 'do-face-alt', 'does', 'dump-face', + 'dump-pane', 'echo', 'editor', 'emailer', 'emit', 'extract', 'find-by-type', 'find-key-face', + 'find-window', 'flag-face', 'flash', 'focus', 'for', 'forall', 'forever', 'forskip', 'func', + 'function', 'get-net-info', 'get-style', 'has', 'help', 'hide-popup', 'import-email', 'inform', + 'input', 'insert-event-func', 'join', 'launch', 'launch-thru', 'layout', 'license', 'list-dir', + 'load-image', 'load-prefs', 'load-thru', 'make-dir', 'make-face', 'net-error', 'open-events', + 'parse-email-addrs', 'parse-header', 'parse-header-date', 'parse-xml', 'path-thru', 'probe', + 'protect-system', 'read-net', 'read-thru', 'reboot', 'reform', 'rejoin', 'remold', + 'remove-event-func', 'rename', 'repend', 'replace', 'request', 'request-color', 'request-date', + 'request-download', 'request-file', 'request-list', 'request-pass', 'request-text', 'resend', + 'save-prefs', 'save-user', 'scroll-para', 'send', 'set-font', 'set-net', 'set-para', 'set-style', + 'set-user', 'set-user-name', 'show-popup', 'source', 'split-path', 'stylize', 'switch', + 'throw-on-error', 'to-binary', 'to-bitset', 'to-block', 'to-char', 'to-date', 'to-decimal', + 'to-email', 'to-event', 'to-file', 'to-get-word', 'to-hash', 'to-idate', 'to-image', 'to-integer', + 'to-issue', 'to-list', 'to-lit-path', 'to-lit-word', 'to-logic', 'to-money', 'to-none', 'to-pair', + 'to-paren', 'to-path', 'to-refinement', 'to-set-path', 'to-set-word', 'to-string', 'to-tag', + 'to-time', 'to-tuple', 'to-url', 'to-word', 'unfocus', 'uninstall', 'unview', 'upgrade', 'Usage', + 'vbug', 'view', 'view-install', 'view-prefs', 'what', 'what-dir', 'write-user', 'return', 'at', + 'space', 'pad', 'across', 'below', 'origin', 'guide', 'tabs', 'indent', 'style', 'styles', 'size', + 'sense', 'backcolor', 'do', 'none', -- + 'action?', 'any-block?', 'any-function?', 'any-string?', 'any-type?', 'any-word?', 'binary?', + 'bitset?', 'block?', 'char?', 'datatype?', 'date?', 'decimal?', 'email?', 'empty?', 'equal?', + 'error?', 'even?', 'event?', 'file?', 'function?', 'get-word?', 'greater-or-equal?', 'greater?', + 'hash?', 'head?', 'image?', 'index?', 'integer?', 'issue?', 'length?', 'lesser-or-equal?', + 'lesser?', 'library?', 'list?', 'lit-path?', 'lit-word?', 'logic?', 'money?', 'native?', + 'negative?', 'none?', 'not-equal?', 'number?', 'object?', 'odd?', 'op?', 'pair?', 'paren?', + 'path?', 'port?', 'positive?', 'refinement?', 'routine?', 'same?', 'series?', 'set-path?', + 'set-word?', 'strict-equal?', 'strict-not-equal?', 'string?', 'struct?', 'tag?', 'tail?', 'time?', + 'tuple?', 'unset?', 'url?', 'word?', 'zero?', 'connected?', 'crypt-strength?', 'exists-key?', + 'input?', 'script?', 'type?', 'value?', '?', '??', 'dir?', 'exists-thru?', 'exists?', + 'flag-face?', 'found?', 'in-window?', 'info?', 'inside?', 'link-app?', 'link?', 'modified?', + 'offset?', 'outside?', 'screen-offset?', 'size?', 'span?', 'view?', 'viewed?', 'win-offset?', + 'within?', 'action!', 'any-block!', 'any-function!', 'any-string!', 'any-type!', 'any-word!', + 'binary!', 'bitset!', 'block!', 'char!', 'datatype!', 'date!', 'decimal!', 'email!', 'error!', + 'event!', 'file!', 'function!', 'get-word!', 'hash!', 'image!', 'integer!', 'issue!', 'library!', + 'list!', 'lit-path!', 'lit-word!', 'logic!', 'money!', 'native!', 'none!', 'number!', 'object!', + 'op!', 'pair!', 'paren!', 'path!', 'port!', 'refinement!', 'routine!', 'series!', 'set-path!', + 'set-word!', 'string!', 'struct!', 'symbol!', 'tag!', 'time!', 'tuple!', 'unset!', 'url!', + 'word!', -- + 'true', 'false', 'self' +})) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '-') * - (lexer.alnum + '-')^0)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '-') * (lexer.alnum + '-')^0)) -- Strings. local dq_str = lexer.range('"', true) @@ -93,7 +97,7 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+/*:()[]'))) -- Fold points. lex:add_fold_point(lexer.COMMENT, '{', '}') -lex:add_fold_point(lexer.COMMENT, ';', lexer.fold_line_comments(';')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines(';')) lex:add_fold_point(lexer.OPERATOR, '[', ']') return lex diff --git a/syntaxhighlight/textadept/rest.lua b/syntaxhighlight/textadept/rest.lua index 889e34c..0cde5a5 100644 --- a/syntaxhighlight/textadept/rest.lua +++ b/syntaxhighlight/textadept/rest.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- reStructuredText LPeg lexer. local l = require('syntaxhighlight.textadept.lexer') local token, word_match, starts_line = l.token, l.word_match, l.starts_line -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local M = {_NAME = 'rest'} @@ -29,7 +29,7 @@ local overline = lpeg.Cmt(starts_line(adornment), function(input, index, adm, c) return #input + 1 end) local underline = lpeg.Cmt(starts_line(adornment), function(_, index, adm, c) - local pos = adm:match('^%' .. c .. '+()%s*$') + local pos = adm:match('^%' .. c .. '+%s*()$') return pos and index - #adm + pos - 1 or nil end) -- Token needs to be a predefined one in order for folder to work. @@ -144,8 +144,8 @@ local substitution = #prefix * token('substitution', local line_comment = l.to_eol(prefix) local bprefix = any_indent * '..' local block_comment = bprefix * l.newline * indented_block -local comment = #bprefix * token(l.COMMENT, - starts_line(line_comment + block_comment)) +local comment = #bprefix * token(l.COMMENT, starts_line(line_comment + + block_comment)) -- Inline markup. local em = token('em', l.range('*')) diff --git a/syntaxhighlight/textadept/rexx.lua b/syntaxhighlight/textadept/rexx.lua index 7ba409c..39963b5 100644 --- a/syntaxhighlight/textadept/rexx.lua +++ b/syntaxhighlight/textadept/rexx.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Rexx LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rexx') @@ -12,41 +12,42 @@ local lex = lexer.new('rexx') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - address arg by call class do drop else end exit expose forever forward guard - if interpret iterate leave method nop numeric otherwise parse procedure pull - push queue raise reply requires return routine result rc say select self sigl - signal super then to trace use when while until -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'address', 'arg', 'by', 'call', 'class', 'do', 'drop', 'else', 'end', 'exit', 'expose', 'forever', + 'forward', 'guard', 'if', 'interpret', 'iterate', 'leave', 'method', 'nop', 'numeric', + 'otherwise', 'parse', 'procedure', 'pull', 'push', 'queue', 'raise', 'reply', 'requires', + 'return', 'routine', 'result', 'rc', 'say', 'select', 'self', 'sigl', 'signal', 'super', 'then', + 'to', 'trace', 'use', 'when', 'while', 'until' +}, true))) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match([[ - abbrev abs address arg beep bitand bitor bitxor b2x center changestr charin - charout chars compare consition copies countstr c2d c2x datatype date delstr - delword digits directory d2c d2x errortext filespec form format fuzz insert - lastpos left length linein lineout lines max min overlay pos queued random - reverse right sign sourceline space stream strip substr subword symbol time - trace translate trunc value var verify word wordindex wordlength wordpos words - xrange x2b x2c x2d - rxfuncadd rxfuncdrop rxfuncquery rxmessagebox rxwinexec - sysaddrexxmacro sysbootdrive sysclearrexxmacrospace syscloseeventsem - sysclosemutexsem syscls syscreateeventsem syscreatemutexsem syscurpos - syscurstate sysdriveinfo sysdrivemap sysdropfuncs sysdroprexxmacro - sysdumpvariables sysfiledelete sysfilesearch sysfilesystemtype sysfiletree - sysfromunicode systounicode sysgeterrortext sysgetfiledatetime sysgetkey - sysini sysloadfuncs sysloadrexxmacrospace sysmkdir sysopeneventsem - sysopenmutexsem sysposteventsem syspulseeventsem sysqueryprocess - sysqueryrexxmacro sysreleasemutexsem sysreorderrexxmacro sysrequestmutexsem - sysreseteventsem sysrmdir syssaverexxmacrospace syssearchpath - syssetfiledatetime syssetpriority syssleep sysstemcopy sysstemdelete - syssteminsert sysstemsort sysswitchsession syssystemdirectory systempfilename - systextscreenread systextscreensize sysutilversion sysversion sysvolumelabel - syswaiteventsem syswaitnamedpipe syswindecryptfile syswinencryptfile syswinver -]], true))) +lex:add_rule('function', token(lexer.FUNCTION, word_match({ + 'abbrev', 'abs', 'address', 'arg', 'beep', 'bitand', 'bitor', 'bitxor', 'b2x', 'center', + 'changestr', 'charin', 'charout', 'chars', 'compare', 'consition', 'copies', 'countstr', 'c2d', + 'c2x', 'datatype', 'date', 'delstr', 'delword', 'digits', 'directory', 'd2c', 'd2x', 'errortext', + 'filespec', 'form', 'format', 'fuzz', 'insert', 'lastpos', 'left', 'length', 'linein', 'lineout', + 'lines', 'max', 'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign', + 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol', 'time', 'trace', + 'translate', 'trunc', 'value', 'var', 'verify', 'word', 'wordindex', 'wordlength', 'wordpos', + 'words', 'xrange', 'x2b', 'x2c', 'x2d', -- + 'rxfuncadd', 'rxfuncdrop', 'rxfuncquery', 'rxmessagebox', 'rxwinexec', 'sysaddrexxmacro', + 'sysbootdrive', 'sysclearrexxmacrospace', 'syscloseeventsem', 'sysclosemutexsem', 'syscls', + 'syscreateeventsem', 'syscreatemutexsem', 'syscurpos', 'syscurstate', 'sysdriveinfo', + 'sysdrivemap', 'sysdropfuncs', 'sysdroprexxmacro', 'sysdumpvariables', 'sysfiledelete', + 'sysfilesearch', 'sysfilesystemtype', 'sysfiletree', 'sysfromunicode', 'systounicode', + 'sysgeterrortext', 'sysgetfiledatetime', 'sysgetkey', 'sysini', 'sysloadfuncs', + 'sysloadrexxmacrospace', 'sysmkdir', 'sysopeneventsem', 'sysopenmutexsem', 'sysposteventsem', + 'syspulseeventsem', 'sysqueryprocess', 'sysqueryrexxmacro', 'sysreleasemutexsem', + 'sysreorderrexxmacro', 'sysrequestmutexsem', 'sysreseteventsem', 'sysrmdir', + 'syssaverexxmacrospace', 'syssearchpath', 'syssetfiledatetime', 'syssetpriority', 'syssleep', + 'sysstemcopy', 'sysstemdelete', 'syssteminsert', 'sysstemsort', 'sysswitchsession', + 'syssystemdirectory', 'systempfilename', 'systextscreenread', 'systextscreensize', + 'sysutilversion', 'sysversion', 'sysvolumelabel', 'syswaiteventsem', 'syswaitnamedpipe', + 'syswindecryptfile', 'syswinencryptfile', 'syswinver' +}, true))) -- Identifiers. -local word = lexer.alpha * (lexer.alnum + S('@#$\\.!?_'))^0 -lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('@#$\\.!?_'))^0)) -- Strings. local sq_str = lexer.range("'", true, false) @@ -62,8 +63,7 @@ lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Preprocessor. -lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, - lexer.to_eol(lexer.starts_line('#')))) +lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, lexer.to_eol(lexer.starts_line('#')))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/\\*%&|^~.,:;(){}'))) @@ -72,7 +72,7 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/\\*%&|^~.,:;(){}'))) lex:add_fold_point(lexer.KEYWORD, 'do', 'end') lex:add_fold_point(lexer.KEYWORD, 'select', 'return') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '--', lexer.fold_line_comments('--')) ---lex:add_fold_point(lexer.OPERATOR, ':', ?) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('--')) +-- lex:add_fold_point(lexer.OPERATOR, ':', ?) return lex diff --git a/syntaxhighlight/textadept/rhtml.lua b/syntaxhighlight/textadept/rhtml.lua index 94f1649..6fa88b3 100644 --- a/syntaxhighlight/textadept/rhtml.lua +++ b/syntaxhighlight/textadept/rhtml.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- RHTML LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rhtml', {inherit = lexer.load('html')}) @@ -13,7 +13,7 @@ local ruby = lexer.load('rails') local ruby_start_rule = token('rhtml_tag', '<%' * P('=')^-1) local ruby_end_rule = token('rhtml_tag', '%>') lex:embed(ruby, ruby_start_rule, ruby_end_rule) -lex:add_style('rhtml_tag', lexer.STYLE_EMBEDDED) +lex:add_style('rhtml_tag', lexer.styles.embedded) -- Fold points. lex:add_fold_point('rhtml_tag', '<%', '%>') diff --git a/syntaxhighlight/textadept/routeros.lua b/syntaxhighlight/textadept/routeros.lua new file mode 100644 index 0000000..58906fb --- /dev/null +++ b/syntaxhighlight/textadept/routeros.lua @@ -0,0 +1,60 @@ +local lpeg = require('lpeg') +-- Copyright 2020-2021 Christian Hesse. See LICENSE. +-- Mikrotik RouterOS script LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('routeros') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Control. + ':delay', ':do', 'on-error', 'while', ':error', ':foreach', 'in', 'do', ':for', 'from', 'to', + 'step', ':if', 'do', 'else', ':return', ':while', 'do', + -- Menu specific commands. + 'add', 'disable', 'edit', 'enable', 'export', 'find', 'get', 'info', 'monitor', 'print', 'append', + 'as-value', 'brief', 'count-only', 'detail', 'file', 'follow', 'follow-only', 'from', 'interval', + 'terse', 'value-list', 'where', 'without-paging', 'remove', 'set', + -- Output & string handling. + ':beep', ':blink', ':environment', ':execute', ':find', ':len', ':log', 'alert', 'critical', + 'debug', 'emergency', 'error', 'info', 'notice', 'warning', ':parse', ':pick', ':put', + ':terminal', ':time', ':typeof', + -- Variable declaration. + ':global', ':local', ':set', + -- Variable casting. + ':toarray', ':tobool', ':toid', ':toip', ':toip6', ':tonum', ':tostr', ':totime', + -- Boolean values and logical operators. + 'false', 'no', 'true', 'yes', 'and', 'in', 'or', + -- Networking. + ':ping', ':resolve' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) + +-- Variables. +lex:add_rule('variable', token(lexer.VARIABLE, '$' * + (S('!#?*@$') + lexer.digit^1 + lexer.word + lexer.range('{', '}', true, false, true)))) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('=!%<>+-/*&|~.,;()[]{}'))) + +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) + +return lex diff --git a/syntaxhighlight/textadept/rstats.lua b/syntaxhighlight/textadept/rstats.lua index 1d7a03a..9a1f70a 100644 --- a/syntaxhighlight/textadept/rstats.lua +++ b/syntaxhighlight/textadept/rstats.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- R LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('rstats') @@ -12,16 +12,16 @@ local lex = lexer.new('rstats') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - break else for if in next repeat return switch try while - Inf NA NaN NULL FALSE TRUE -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', -- + 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - array character complex data.frame double factor function integer list logical - matrix numeric vector -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'array', 'character', 'complex', 'data.frame', 'double', 'factor', 'function', 'integer', 'list', + 'logical', 'matrix', 'numeric', 'vector' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/ruby.lua b/syntaxhighlight/textadept/ruby.lua index 4e6e00d..dee97fc 100644 --- a/syntaxhighlight/textadept/ruby.lua +++ b/syntaxhighlight/textadept/ruby.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Ruby LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('ruby') @@ -12,33 +12,34 @@ local lex = lexer.new('ruby') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - BEGIN END alias and begin break case class def defined? do else elsif end - ensure false for if in module next nil not or redo rescue retry return self - super then true undef unless until when while yield __FILE__ __LINE__ -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'BEGIN', 'END', 'alias', 'and', 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', + 'else', 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next', 'nil', 'not', + 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super', 'then', 'true', 'undef', 'unless', + 'until', 'when', 'while', 'yield', '__FILE__', '__LINE__' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - at_exit autoload binding caller catch chop chop! chomp chomp! eval exec exit - exit! fail fork format gets global_variables gsub gsub! iterator? lambda load - local_variables loop open p print printf proc putc puts raise rand readline - readlines require select sleep split sprintf srand sub sub! syscall system - test trace_var trap untrace_var -]]) * -S('.:|')) - -local word_char = lexer.alnum + S('_!?') +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'at_exit', 'autoload', 'binding', 'caller', 'catch', 'chop', 'chop!', 'chomp', 'chomp!', 'eval', + 'exec', 'exit', 'exit!', 'extend', 'fail', 'fork', 'format', 'gets', 'global_variables', 'gsub', + 'gsub!', 'include', 'iterator?', 'lambda', 'load', 'local_variables', 'loop', 'module_function', + 'open', 'p', 'print', 'printf', 'proc', 'putc', 'puts', 'raise', 'rand', 'readline', 'readlines', + 'require', 'require_relative', 'select', 'sleep', 'split', 'sprintf', 'srand', 'sub', 'sub!', + 'syscall', 'system', 'test', 'trace_var', 'trap', 'untrace_var' +}) * -S('.:|')) -- Identifiers. +local word_char = lexer.alnum + S('_!?') local word = (lexer.alpha + '_') * word_char^0 lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) -- Comments. local line_comment = lexer.to_eol('#', true) -local block_comment = lexer.range(lexer.starts_line('=begin'), - lexer.starts_line('=end')) +local block_comment = lexer.range(lexer.starts_line('=begin'), lexer.starts_line('=end')) lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment)) +-- Strings. local delimiter_matches = {['('] = ')', ['['] = ']', ['{'] = '}'} local literal_delimited = P(function(input, index) local delimiter = input:sub(index, index) @@ -56,7 +57,6 @@ local literal_delimited = P(function(input, index) end end) --- Strings. local cmd_str = lexer.range('`') local lit_cmd = '%x' * literal_delimited local lit_array = '%w' * literal_delimited @@ -64,19 +64,18 @@ local sq_str = lexer.range("'") local dq_str = lexer.range('"') local lit_str = '%' * S('qQ')^-1 * literal_delimited local heredoc = '<<' * P(function(input, index) - local s, e, indented, _, delimiter = input:find( - '(%-?)(["`]?)([%a_][%w_]*)%2[\n\r\f;]+', index) + local s, e, indented, _, delimiter = input:find('([%-~]?)(["`]?)([%a_][%w_]*)%2[\n\r\f;]+', index) if s == index and delimiter then local end_heredoc = (#indented > 0 and '[\n\r\f]+ *' or '[\n\r\f]+') - local _, e = input:find(end_heredoc .. delimiter, e) + e = select(2, input:find(end_heredoc .. delimiter, e)) return e and e + 1 or #input + 1 end end) -local string = token(lexer.STRING, (sq_str + dq_str + lit_str + heredoc + - cmd_str + lit_cmd + lit_array) * S('f')^-1) +local string = token(lexer.STRING, (sq_str + dq_str + lit_str + heredoc + cmd_str + lit_cmd + + lit_array) * S('f')^-1) -- TODO: regex_str fails with `obj.method /patt/` syntax. -local regex_str = #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * - lexer.range('/', true) * S('iomx')^0 +local regex_str = + #P('/') * lexer.last_char_includes('!%^&*([{-=+|:;,?<>~') * lexer.range('/', true) * S('iomx')^0 local lit_regex = '%r' * literal_delimited * S('iomx')^0 local regex = token(lexer.REGEX, regex_str + lit_regex) lex:add_rule('string', string + regex) @@ -87,30 +86,28 @@ local bin = '0b' * S('01')^1 * ('_' * S('01')^1)^0 local integer = S('+-')^-1 * (bin + lexer.hex_num + lexer.oct_num + dec) -- TODO: meta, control, etc. for numeric_literal. local numeric_literal = '?' * (lexer.any - lexer.space) * -word_char -lex:add_rule('number', token(lexer.NUMBER, lexer.float * S('ri')^-1 + integer + - numeric_literal)) +lex:add_rule('number', token(lexer.NUMBER, lexer.float * S('ri')^-1 + integer + numeric_literal)) -- Variables. -local global_var = '$' * (word + S('!@L+`\'=~/\\,.;<>_*"$?:') + lexer.digit + - '-' * S('0FadiIKlpvw')) +local global_var = '$' * + (word + S('!@L+`\'=~/\\,.;<>_*"$?:') + lexer.digit + '-' * S('0FadiIKlpvw')) local class_var = '@@' * word local inst_var = '@' * word -lex:add_rule('variable', token(lexer.VARIABLE, global_var + class_var + - inst_var)) +lex:add_rule('variable', token(lexer.VARIABLE, global_var + class_var + inst_var)) -- Symbols. lex:add_rule('symbol', token('symbol', ':' * P(function(input, index) if input:sub(index - 2, index - 2) ~= ':' then return index end end) * (word_char^1 + sq_str + dq_str))) -lex:add_style('symbol', lexer.STYLE_CONSTANT) +lex:add_style('symbol', lexer.styles.constant) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~'))) -- Fold points. local function disambiguate(text, pos, line, s) - return line:sub(1, s - 1):match('^%s*$') and - not text:sub(1, pos - 1):match('\\[ \t]*\r?\n$') and 1 or 0 + return line:sub(1, s - 1):match('^%s*$') and not text:sub(1, pos - 1):match('\\[ \t]*\r?\n$') and + 1 or 0 end lex:add_fold_point(lexer.KEYWORD, 'begin', 'end') lex:add_fold_point(lexer.KEYWORD, 'class', 'end') @@ -127,6 +124,6 @@ lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '[', ']') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '=begin', '=end') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/rust.lua b/syntaxhighlight/textadept/rust.lua index adc1419..effb4db 100644 --- a/syntaxhighlight/textadept/rust.lua +++ b/syntaxhighlight/textadept/rust.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Alejandro Baez (https://keybase.io/baez). See License.txt. +-- Copyright 2015-2021 Alejandro Baez (https://keybase.io/baez). See LICENSE. -- Rust LPeg lexer. local lexer = require("lexer") local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local C, Cmt = lpeg.C, lpeg.Cmt local lex = lexer.new('rust') @@ -14,60 +14,50 @@ lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -- https://github.com/rust-lang/rust/blob/stable/src/libsyntax_pos/symbol.rs -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - Self abstract as async auto await become box break catch const continue crate - default do dyn else enum extern false final fn for if impl in let loop macro - match mod move mut override priv pub ref return self static struct super - trait true try type typeof union unsafe unsized use virtual where while yield -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'Self', 'abstract', 'as', 'async', 'auto', 'await', 'become', 'box', 'break', 'catch', 'const', + 'continue', 'crate', 'default', 'do', 'dyn', 'else', 'enum', 'extern', 'false', 'final', 'fn', + 'for', 'if', 'impl', 'in', 'let', 'loop', 'macro', 'match', 'mod', 'move', 'mut', 'override', + 'priv', 'pub', 'ref', 'return', 'self', 'static', 'struct', 'super', 'trait', 'true', 'try', + 'type', 'typeof', 'union', 'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield' +})) -- Macro names. lex:add_rule('macro', token(lexer.FUNCTION, lexer.word * S("!"))) -- Library types -lex:add_rule('library', token(lexer.LABEL, lexer.upper * - (lexer.lower + lexer.dec_num)^1)) +lex:add_rule('library', token(lexer.LABEL, lexer.upper * (lexer.lower + lexer.dec_num)^1)) -- Numbers. local identifier = P('r#')^-1 * lexer.word local digit = lexer.digit local decimal_literal = digit * (digit + '_')^0 -local function integer_suffix(digit) - return P('_')^0 * digit * (digit + '_')^0 -end -local function opt_cap(patt) - return C(patt^-1) -end -local float = decimal_literal * (Cmt( - opt_cap('.' * decimal_literal) * opt_cap(S('eE') * S('+-')^-1 * - integer_suffix(digit)) * opt_cap(P('f32') + 'f64'), - function (input, index, decimals, exponent, type) +local function integer_suffix(digit) return P('_')^0 * digit * (digit + '_')^0 end +local function opt_cap(patt) return C(patt^-1) end +local float = decimal_literal * + (Cmt(opt_cap('.' * decimal_literal) * opt_cap(S('eE') * S('+-')^-1 * integer_suffix(digit)) * + opt_cap(P('f32') + 'f64'), function(input, index, decimals, exponent, type) return decimals ~= "" or exponent ~= "" or type ~= "" end) + '.' * -(S('._') + identifier)) -local function prefixed_integer(prefix, digit) - return P(prefix) * integer_suffix(digit) -end -local integer = ( - prefixed_integer('0b', S('01')) + - prefixed_integer('0o', R('07')) + - prefixed_integer('0x', lexer.xdigit) + - decimal_literal -) * (S('iu') * (P('8') + '16' + '32' + '64' + '128' + 'size'))^-1 +local function prefixed_integer(prefix, digit) return P(prefix) * integer_suffix(digit) end +local bin = prefixed_integer('0b', S('01')) +local oct = prefixed_integer('0o', lpeg.R('07')) +local hex = prefixed_integer('0x', lexer.xdigit) +local integer = (bin + oct + hex + decimal_literal) * + (S('iu') * (P('8') + '16' + '32' + '64' + '128' + 'size'))^-1 lex:add_rule('number', token(lexer.NUMBER, float + integer)) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - () bool isize usize char str u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 f32 f64 -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + '() bool isize usize char str u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 f32 f64'))) -- Strings. local sq_str = P('b')^-1 * lexer.range("'", true) local dq_str = P('b')^-1 * lexer.range('"') -local raw_str = Cmt(P('b')^-1 * P('r') * C(P('#')^0) * '"', - function(input, index, hashes) - local _, e = input:find('"' .. hashes, index, true) - return (e or #input) + 1 - end) +local raw_str = Cmt(P('b')^-1 * P('r') * C(P('#')^0) * '"', function(input, index, hashes) + local _, e = input:find('"' .. hashes, index, true) + return (e or #input) + 1 +end) lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + raw_str)) -- Identifiers. @@ -79,16 +69,14 @@ local block_comment = lexer.range('/*', '*/', false, false, true) lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Attributes. -lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * - lexer.range('[', ']', true))) +lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * lexer.range('[', ']', true))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, - S('+-/*%<>!=`^~@&|?#~:;,.()[]{}'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=`^~@&|?#~:;,.()[]{}'))) -- Fold points. lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '{', '}') diff --git a/syntaxhighlight/textadept/sass.lua b/syntaxhighlight/textadept/sass.lua index 0e7d0c7..af0872e 100644 --- a/syntaxhighlight/textadept/sass.lua +++ b/syntaxhighlight/textadept/sass.lua @@ -1,5 +1,5 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Robert Gieseke. See License.txt. +-- Copyright 2006-2021 Robert Gieseke. See LICENSE. -- Sass CSS preprocessor LPeg lexer. -- http://sass-lang.com @@ -16,10 +16,10 @@ lex:add_rule('line_comment', token(lexer.COMMENT, lexer.to_eol('//'))) lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.alnum + S('_-'))^1)) -- Mixins. -lex:add_rule('mixin', token('mixin', P('@') * lexer.word)) -lex:add_style('mixin', lexer.STYLE_FUNCTION) +lex:add_rule('mixin', token('mixin', '@' * lexer.word)) +lex:add_style('mixin', lexer.styles['function']) -- Fold points. -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/scala.lua b/syntaxhighlight/textadept/scala.lua index c9d4577..272debf 100644 --- a/syntaxhighlight/textadept/scala.lua +++ b/syntaxhighlight/textadept/scala.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 JMS. See License.txt. +-- Copyright 2006-2021 JMS. See LICENSE. -- Scala LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('scala') @@ -13,22 +13,22 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Classes. -lex:add_rule('class', token(lexer.KEYWORD, P('class')) * ws^1 * - token(lexer.CLASS, lexer.word)) +lex:add_rule('class', token(lexer.KEYWORD, 'class') * ws^1 * token(lexer.CLASS, lexer.word)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - abstract case catch class def do else extends false final finally for forSome - if implicit import lazy match new null object override package private - protected return sealed super this throw trait try true type val var while - with yield -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstract', 'case', 'catch', 'class', 'def', 'do', 'else', 'extends', 'false', 'final', 'finally', + 'for', 'forSome', 'if', 'implicit', 'import', 'lazy', 'match', 'new', 'null', 'object', + 'override', 'package', 'private', 'protected', 'return', 'sealed', 'super', 'this', 'throw', + 'trait', 'try', 'true', 'type', 'val', 'var', 'while', 'with', 'yield' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - Array Boolean Buffer Byte Char Collection Double Float Int Iterator LinkedList - List Long Map None Option Set Short SortedMap SortedSet String TreeMap TreeSet -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'Array', 'Boolean', 'Buffer', 'Byte', 'Char', 'Collection', 'Double', 'Float', 'Int', 'Iterator', + 'LinkedList', 'List', 'Long', 'Map', 'None', 'Option', 'Set', 'Short', 'SortedMap', 'SortedSet', + 'String', 'TreeMap', 'TreeSet' +})) -- Functions. lex:add_rule('function', token(lexer.FUNCTION, lexer.word) * #P('(')) @@ -56,6 +56,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/scheme.lua b/syntaxhighlight/textadept/scheme.lua index 5905fbd..88d3b2d 100644 --- a/syntaxhighlight/textadept/scheme.lua +++ b/syntaxhighlight/textadept/scheme.lua @@ -1,10 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Scheme LPeg lexer. +-- Contributions by Murray Calavera. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('scheme') @@ -12,70 +13,163 @@ local lex = lexer.new('scheme') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - and begin case cond cond-expand define define-macro delay do else fluid-let if - lambda let let* letrec or quasiquote quote set! -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'and', 'or', 'not', 'else', + -- + 'library', 'define-library', 'export', 'include-library-declarations', 'cond-expand', 'import', + 'rename', 'only', 'except', 'prefix', 'include', 'include-ci', + -- + 'begin', 'case', 'case-lambda', 'cond', 'define', 'define-record-type', 'define-syntax', + 'define-values', 'delay', 'delay-force', 'do', 'if', 'guard', 'lambda', 'let', 'let*', + 'let*-values', 'let-syntax', 'let-values', 'letrec', 'letrec*', 'letrec-syntax', 'parameterize', + 'quasiquote', 'quote', 'set!', 'unless', 'unquote', 'unquote-splicing', 'when', + -- + 'define-macro', 'fluid-let' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - abs acos angle append apply asin assoc assq assv atan car cdr caar cadr cdar - cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr - call-with-current-continuation call-with-input-file call-with-output-file - call-with-values call/cc catch ceiling char->integer char-downcase char-upcase - close-input-port close-output-port cons cos current-input-port - current-output-port delete-file display dynamic-wind eval exit exact->inexact - exp expt file-or-directory-modify-seconds floor force for-each gcd gensym - get-output-string getenv imag-part integer->char lcm length list list->string - list->vector list-ref list-tail load log magnitude make-polar make-rectangular - make-string make-vector map max member memq memv min modulo newline nil not - number->string open-input-file open-input-string open-output-file - open-output-string peek-char quotient read read-char read-line real-part - remainder reverse reverse! round set-car! set-cdr! sin sqrt string - string->list string->number string->symbol string-append string-copy - string-fill! string-length string-ref string-set! substring symbol->string - system tan truncate values vector vector->list vector-fill! vector-length - vector-ref vector-set! with-input-from-file with-output-to-file write - write-char - boolean? char-alphabetic? char-ci<=? char-ci=? char-ci>? - char-lower-case? char-numeric? char-ready? char-upper-case? char-whitespace? - char<=? char=? char>? char? complex? eof-object? eq? equal? - eqv? even? exact? file-exists? inexact? input-port? integer? list? negative? - null? number? odd? output-port? pair? port? positive? procedure? rational? - real? string-ci<=? string-ci=? string-ci>? string<=? - string=? string>? string? symbol? vector? zero? - #t #f -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + '*', '+', '-', '/', '<', '<=', '=', '=>', '>', '>=', 'abs', 'append', 'apply', 'assoc', 'assq', + 'assv', 'binary-port?', 'boolean=?', 'boolean?', 'bytevector', 'bytevector-append', + 'bytevector-copy', 'bytevector-copy!', 'bytevector-length', 'bytevector-u8-ref', + 'bytevector-u8-set!', 'bytevector?', 'caar', 'cadr', 'call-with-current-continuation', + 'call-with-port', 'call-with-values', 'call/cc', 'car', 'cdar', 'cddr', 'cdr', 'ceiling', + 'char->integer', 'char-ready?', 'char<=?', 'char=?', 'char>?', 'char?', + 'close-input-port', 'close-output-port', 'close-port', 'complex?', 'cons', 'current-error-port', + 'current-input-port', 'current-output-port', 'denominator', 'dynamic-wind', 'eof-object', + 'eof-object?', 'eq?', 'equal?', 'eqv?', 'error', 'error-object-irritants', 'error-object-message', + 'error-object?', 'even?', 'exact', 'exact-integer-sqrt', 'exact-integer?', 'exact?', 'expt', + 'features', 'file-error?', 'floor', 'floor-quotient', 'floor-remainder', 'floor/', + 'flush-output-port', 'for-each', 'gcd', 'get-output-bytevector', 'get-output-string', 'inexact', + 'inexact?', 'input-port-open?', 'input-port?', 'integer->char', 'integer?', 'lcm', 'length', + 'list', 'list->string', 'list->vector', 'list-copy', 'list-ref', 'list-set!', 'list-tail', + 'list?', 'make-bytevector', 'make-list', 'make-parameter', 'make-string', 'make-vector', 'map', + 'max', 'member', 'memq', 'memv', 'min', 'modulo', 'negative?', 'newline', 'null?', + 'number->string', 'number?', 'numerator', 'odd?', 'open-input-bytevector', 'open-input-string', + 'open-output-bytevector', 'open-output-string', 'output-port-open?', 'output-port?', 'pair?', + 'peek-char', 'peek-u8', 'port?', 'positive?', 'procedure?', 'quotient', 'raise', + 'raise-continuable', 'rational?', 'rationalize', 'read-bytevector', 'read-bytevector!', + 'read-char', 'read-error?', 'read-line', 'read-string', 'read-u8', 'real?', 'remainder', + 'reverse', 'round', 'set-car!', 'set-cdr!', 'square', 'string', 'string->list', 'string->number', + 'string->symbol', 'string->utf8', 'string->vector', 'string-append', 'string-copy', + 'string-copy!', 'string-fill!', 'string-for-each', 'string-length', 'string-map', 'string-ref', + 'string-set!', 'string<=?', 'string=?', 'string>?', 'string?', + 'substring', 'symbol->string', 'symbol=?', 'symbol?', 'syntax-error', 'syntax-rules', + 'textual-port?', 'truncate', 'truncate-quotient', 'truncate-remainder', 'truncate/', 'u8-ready?', + 'utf8->string', 'values', 'vector', 'vector->list', 'vector->string', 'vector-append', + 'vector-copy', 'vector-copy!', 'vector-fill!', 'vector-for-each', 'vector-length', 'vector-map', + 'vector-ref', 'vector-set!', 'vector?', 'with-exception-handler', 'write-bytevector', + 'write-char', 'write-string', 'write-u8', 'zero?', + -- + 'char-alphabetic?', 'char-ci<=?', 'char-ci=?', 'char-ci>?', + 'char-downcase', 'char-foldcase', 'char-lower-case?', 'char-numeric?', 'char-upcase', + 'char-upper-case?', 'char-whitespace?', 'digit-value', 'string-ci<=?', 'string-ci=?', 'string-ci>?', 'string-downcase', 'string-foldcase', + 'string-upcase', + -- + 'angle', 'imag-part', 'magnitude', 'make-polar', 'make-rectangular', 'real-part', + -- + 'caaaar', 'caaadr', 'caaar', 'caadar', 'caaddr', 'caadr', 'cadaar', 'cadadr', 'cadar', 'caddar', + 'cadddr', 'caddr', 'cdaaar', 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cddaar', 'cddadr', + 'cddar', 'cdddar', 'cddddr', 'cdddr', + -- + 'environment', 'eval', + -- + 'call-with-input-file', 'call-with-output-file', 'delete-file', 'file-exists?', + 'open-binary-input-file', 'open-binary-output-file', 'open-input-file', 'open-output-file', + 'with-input-from-file', 'with-output-to-file', + -- + 'acos', 'asin', 'atan', 'cos', 'exp', 'finite?', 'infinite?', 'log', 'nan?', 'sin', 'sqrt', 'tan', + -- + 'force', 'make-promise', 'promise?', + -- + 'load', + -- + 'command-line', 'emergency-exit', 'exit', 'get-environment-variable', 'get-environment-variables', + -- + 'read', + -- + 'interaction-environment', + -- + 'current-jiffy', 'current-second', 'jiffies-per-second', + -- + 'display', 'write', 'write-shared', 'write-simple', + -- + 'syntax-case', 'er-macro-transformer', 'sc-macro-transformer', 'rsc-macro-transformer' +})) -local word = (lexer.alpha + S('-!?')) * (lexer.alnum + S('-!?'))^0 - --- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, word)) +-- Identifiers and symbols. +local explicit_sign = S('+-') +local initial = lexer.alpha + S('!$%&*/:<=>?@^_~') +local subsequent = initial + lexer.digit + explicit_sign + '.' +local sign_subsequent = initial + explicit_sign +local dot_subsequent = sign_subsequent + '.' +-- LuaFormatter off +local peculiar_identifier = + explicit_sign * '.' * dot_subsequent * subsequent^0 + + explicit_sign * sign_subsequent * subsequent^0 + + '.' * dot_subsequent * subsequent^0 + + explicit_sign +-- LuaFormatter on +local ident = lexer.range('|') + initial * subsequent^0 + peculiar_identifier +lex:add_rule('identifier', token(lexer.IDENTIFIER, ident)) +lex:add_rule('symbol', token(lexer.CLASS, "'" * ident)) -- Strings. -local literal = (P("'") + '#' * S('\\bdox')) * lexer.word +local character = '#\\' * + (word_match('alarm backspace delete escape newline null return space tab') + 'x' * lexer.xdigit^1 + + lexer.any) local dq_str = lexer.range('"') -lex:add_rule('string', token(lexer.STRING, literal + dq_str)) +lex:add_rule('string', token(lexer.STRING, character + dq_str)) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match('#t #f #true #false'))) + +-- Directives. +lex:add_rule('directive', token(lexer.PREPROCESSOR, P('#!fold-case') + '#!no-fold-case')) -- Comments. local line_comment = lexer.to_eol(';') -local block_comment = lexer.range('#|', '|#') -lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) +local block_comment = lexer.range('#|', '|#', false, false, true) +local datum_comment = '#;' * lexer.space^0 * lexer.range('(', ')', false, true, true) * + (lexer.any - lexer.space)^0 +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment + datum_comment)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * - (S('./') * lexer.digit^1)^-1)) +local radixes = {[2] = P('#b'), [8] = P('#o'), [10] = P('#d')^-1, [16] = P('#x')} +local digits = {[2] = S('01'), [8] = lpeg.R('07'), [10] = lexer.digit, [16] = lexer.xdigit} +local function num(r) + local exactness = (P('#i') + '#e')^-1 + local radix, digit = radixes[r], digits[r] + local prefix = radix * exactness + exactness * radix + local suffix = ('e' * S('+-')^-1 * lexer.digit^1)^-1 + local infnan = S('+-') * word_match[[inf nan]] * '.0' + -- LuaFormatter off + local decimal = lexer.digit^1 * suffix + + '.' * lexer.digit^1 * suffix + + lexer.digit^1 * '.' * lexer.digit^0 * suffix + local ureal = digit^1 * '/' * digit^1 + + (r == 10 and decimal or P(false)) + + digit^1 + local real = S('+-')^-1 * ureal + infnan + local i = P('i') + local complex = real * '@' * real + + real * S('+-') * ureal^-1 * i + + real * infnan * i + + infnan * i + + real + + S('+-') * ureal^-1 * i + -- LuaFormatter on + return prefix * complex +end +lex:add_rule('number', token(lexer.NUMBER, num(2) + num(8) + num(10) + num(16))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('<>=*/+-`@%:()'))) - --- Entity. -lex:add_rule('entity', token('entity', '&' * word)) -lex:add_style('entity', lexer.STYLE_VARIABLE) +lex:add_rule('operator', token(lexer.OPERATOR, P('#u8') + ',@' + S(".`'#(),"))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.COMMENT, '#|', '|#') -lex:add_fold_point(lexer.COMMENT, ';', lexer.fold_line_comments(';')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines(';')) return lex diff --git a/syntaxhighlight/textadept/smalltalk.lua b/syntaxhighlight/textadept/smalltalk.lua index fb5cb9d..26dfad2 100644 --- a/syntaxhighlight/textadept/smalltalk.lua +++ b/syntaxhighlight/textadept/smalltalk.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Smalltalk LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('smalltalk') @@ -12,14 +12,12 @@ local lex = lexer.new('smalltalk') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - true false nil self super isNil not Smalltalk Transcript -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match( + 'true false nil self super isNil not Smalltalk Transcript'))) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - Date Time Boolean True False Character String Array Symbol Integer Object -]])) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'Date Time Boolean True False Character String Array Symbol Integer Object'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/sml.lua b/syntaxhighlight/textadept/sml.lua index a22ffc9..e5ad3ba 100644 --- a/syntaxhighlight/textadept/sml.lua +++ b/syntaxhighlight/textadept/sml.lua @@ -1,106 +1,92 @@ local lpeg = require('lpeg') --- Copyright 2017-2020 Murray Calavera. See License.txt. +-- Copyright 2017-2021 Murray Calavera. See LICENSE. -- Standard ML LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') -local token = lexer.token +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S -function mlword(words) - return lexer.word_match(words, "'") -end +local lex = lexer.new('sml') +-- Whitespace. local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', ws) --- single line comments are valid in successor ml -local line_comment = lexer.to_eol('(*)') -local block_comment = lexer.range('(*', '*)', false, false, true) -local comment = token(lexer.COMMENT, line_comment + block_comment) +-- Structures. +local id = (lexer.alnum + "'" + '_')^0 +local aid = lexer.alpha * id +local longid = (aid * '.')^0 * aid +local struct_dec = token(lexer.KEYWORD, 'structure') * ws * token(lexer.CLASS, aid) * ws * + token(lexer.OPERATOR, '=') * ws +lex:add_rule('struct_new', struct_dec * token(lexer.KEYWORD, 'struct')) +lex:add_rule('struct_alias', struct_dec * token(lexer.CLASS, longid)) +lex:add_rule('structure', token(lexer.CLASS, aid * '.')) + +-- Open. +lex:add_rule('open', token(lexer.KEYWORD, word_match('open structure functor')) * ws * + token(lexer.CLASS, longid)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'abstype', 'and', 'andalso', 'as', 'case', 'do', 'datatype', 'else', 'end', 'exception', 'fn', + 'fun', 'handle', 'if', 'in', 'infix', 'infixr', 'let', 'local', 'nonfix', 'of', 'op', 'orelse', + 'raise', 'rec', 'then', 'type', 'val', 'with', 'withtype', 'while', -- + 'eqtype', 'functor', 'include', 'sharing', 'sig', 'signature', 'struct', 'structure' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'int', 'real', 'word', 'bool', 'char', 'string', 'unit', 'array', 'exn', 'list', 'option', + 'order', 'ref', 'substring', 'vector' +})) + +-- Functions. +-- `real`, `vector` and `substring` are a problem. +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'app', 'before', 'ceil', 'chr', 'concat', 'exnMessage', 'exnName', 'explode', 'floor', 'foldl', + 'foldr', 'getOpt', 'hd', 'ignore', 'implode', 'isSome', 'length', 'map', 'not', 'null', 'ord', + 'print', 'real', 'rev', 'round', 'size', 'str', 'substring', 'tl', 'trunc', 'valOf', 'vector', + 'o', 'abs', 'mod', 'div' +})) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match('true false nil') + lexer.upper * id)) + +-- Indentifiers (non-symbolic). +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.lower * id)) -local string = token(lexer.STRING, lpeg.P('#')^-1 * lexer.range('"', true)) +-- Strings. +lex:add_rule('string', token(lexer.STRING, P('#')^-1 * lexer.range('"', true))) -local function num(digit) - return digit * (digit^0 * lpeg.P('_'))^0 * digit^1 + digit -end +-- Comments. +local line_comment = lexer.to_eol('(*)') +local block_comment = lexer.range('(*', '*)', false, false, true) +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) +-- Numbers. +local function num(digit) return digit * (digit^0 * '_')^0 * digit^1 + digit end local int = num(lexer.digit) -local frac = lpeg.P('.') * int +local frac = '.' * int local minus = lpeg.P('~')^-1 local exp = lpeg.S('eE') * minus * int local real = int * frac^-1 * exp + int * frac * exp^-1 local hex = num(lexer.xdigit) local bin = num(lpeg.S('01')) - -local number = token(lexer.NUMBER, lpeg.P('0w') * int + - (lpeg.P('0wx') + lpeg.P('0xw')) * hex + - (lpeg.P('0wb') + lpeg.P('0bw')) * bin + minus * lpeg.P('0x') * hex + - minus * lpeg.P('0b') * bin + minus * real + minus * int) - -local keyword = token(lexer.KEYWORD, mlword{ - 'abstype', 'and', 'andalso', 'as', 'case', 'do', 'datatype', 'else', 'end', - 'exception', 'fn', 'fun', 'handle', 'if', 'in', 'infix', 'infixr', 'let', - 'local', 'nonfix', 'of', 'op', 'orelse', 'raise', 'rec', 'then', - 'type', 'val', 'with', 'withtype', 'while', - - 'eqtype', 'functor', 'include', 'sharing', 'sig', 'signature', - 'struct', 'structure' -}) - --- includes valid symbols for identifiers -local operator = token(lexer.OPERATOR, - lpeg.S('!*/+-^:@=<>()[]{},;._|#%&$?~`\\')) - -local type = token(lexer.TYPE, mlword{ - 'int', 'real', 'word', 'bool', 'char', 'string', 'unit', - 'array', 'exn', 'list', 'option', 'order', 'ref', 'substring', 'vector' -}) - --- `real`, `vector` and `substring` are a problem -local func = token(lexer.FUNCTION, mlword{ - 'app', 'before', 'ceil', 'chr', 'concat', 'exnMessage', 'exnName', - 'explode', 'floor', 'foldl', 'foldr', 'getOpt', 'hd', 'ignore', - 'implode', 'isSome', 'length', 'map', 'not', 'null', 'ord', 'print', - 'real', 'rev', 'round', 'size', 'str', 'substring', 'tl', 'trunc', - 'valOf', 'vector', - 'o', 'abs', 'mod', 'div' -}) - --- non-symbolic identifiers only -local id = (lexer.alnum + "'" + '_')^0 -local aid = lexer.alpha * id -local longid = (aid * lpeg.P('.'))^0 * aid -local identifier = token(lexer.IDENTIFIER, lexer.lower * id) -local typevar = token(lexer.VARIABLE, "'" * id) -local c = mlword{'true', 'false', 'nil'} -local const = token(lexer.CONSTANT, lexer.upper * id + c) -local structure = token(lexer.CLASS, aid * lpeg.P('.')) - -local open = token(lexer.KEYWORD, mlword{'open', 'structure', 'functor'}) * ws * - token(lexer.CLASS, longid) - -local struct_dec = token(lexer.KEYWORD, lpeg.P('structure')) * ws * - token(lexer.CLASS, aid) * ws * token(lexer.OPERATOR, lpeg.P('=')) * ws - -local struct_new = struct_dec * token(lexer.KEYWORD, lpeg.P('struct')) -local struct_alias = struct_dec * token(lexer.CLASS, longid) - -local M = {_NAME = 'sml'} - -M._rules = { - {'whitespace', ws}, - {'comment', comment}, - {'number', number}, - {'struct_new', struct_new}, - {'struct_alias', struct_alias}, - {'structure', structure}, - {'open', open}, - {'type', type}, - {'keyword', keyword}, - {'function', func}, - {'string', string}, - {'operator', operator}, - {'typevar', typevar}, - {'constant', const}, - {'identifier', identifier}, -} - -return M +-- LuaFormatter off +lex:add_rule('number', token(lexer.NUMBER, + '0w' * int + + (P('0wx') + '0xw') * hex + + (P('0wb') + '0bw') * bin + + minus * '0x' * hex + + minus * '0b' * bin + + minus * real + + minus * int)) +-- LuaFormatter on + +-- Type variables. +lex:add_rule('typevar', token(lexer.VARIABLE, "'" * id)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('!*/+-^:@=<>()[]{},;._|#%&$?~`\\'))) + +return lex diff --git a/syntaxhighlight/textadept/snobol4.lua b/syntaxhighlight/textadept/snobol4.lua index faf67af..4e0bd81 100644 --- a/syntaxhighlight/textadept/snobol4.lua +++ b/syntaxhighlight/textadept/snobol4.lua @@ -1,66 +1,70 @@ local lpeg = require('lpeg') --- Copyright 2013-2020 Michael T. Richter. See License.txt. +-- Copyright 2013-2021 Michael T. Richter. See LICENSE. -- SNOBOL4 lexer. -- This lexer works with classic SNOBOL4 as well as the CSNOBOL4 extensions. -local lexer = require 'lexer' +local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local B, P, R, S, V = lpeg.B, lpeg.P, lpeg.R, lpeg.S, lpeg.V +local B, P, S = lpeg.B, lpeg.P, lpeg.S -local M = { _NAME = 'snobol4' } +local lex = lexer.new('snobol4') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'ABORT', 'ARRAY', 'CONTINUE', 'DEFINE', 'END', 'FRETURN', 'INPUT', 'NRETURN', 'OUTPUT', 'PUNCH', + 'RETURN', 'SCONTINUE', 'TABLE' +}, true) + '&' * lexer.word)) -- Helper patterns. -local dotted_id = lexer.word * (P'.' * lexer.word)^0 +local dotted_id = lexer.word * ('.' * lexer.word)^0 + +-- Labels. +lex:add_rule('label', token(lexer.LABEL, lexer.starts_line(dotted_id))) + +-- Targets. +local branch = B(lexer.space * ':(') * dotted_id * #P(')') +local sbranch = B(lexer.space * ':' * S('SsFf') * '(') * dotted_id * #P(')') +local sbranchx = B(')' * S('SsFf') * '(') * dotted_id * #P(')') +lex:add_rule('target', token(lexer.LABEL, branch + sbranch + sbranchx)) + +-- Patterns. +lex:add_rule('pattern', lexer.token(lexer.CLASS, word_match({ + -- Keep distinct. + 'ABORT', 'ANY', 'ARB', 'ARBNO', 'BAL', 'BREAK', 'BREAKX', 'FAIL', 'FENCE', 'LEN', 'NOTANY', 'POS', + 'REM', 'RPOS', 'RTAB', 'SPAN', 'SUCCEED', 'TAB' +}, true) * #P('('))) + +-- Token definitions. +lex:add_rule('built-in', token(lexer.FUNCTION, word_match({ + 'APPLY', 'ARRAY', 'CHAR', 'CONVERT', 'COPY', 'DATA', 'DATE', 'DIFFER', 'DUPL', 'EQ', 'EVAL', + 'FILE_ABSPATH', 'FILE_ISDIR', 'FREEZE', 'FUNCTION', 'GE', 'GT', 'HOST', 'IDENT', 'INTEGER', + 'IO_FINDUNIT', 'ITEM', 'LABEL', 'LOAD', 'LPAD', 'LE', 'LGT', 'LT', 'NE', 'OPSYN', 'ORD', + 'PROTOTYPE', 'REMDR', 'REPLACE', 'REVERSE', 'RPAD', 'RSORT', 'SERV_LISTEN', 'SET', 'SETEXIT', + 'SIZE', 'SORT', 'SQRT', 'SSET', 'SUBSTR', 'TABLE', 'THAW', 'TIME', 'TRACE', 'TRIM', 'UNLOAD', + 'VALUE', 'VDIFFER' +}, true) * #P('('))) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.DEFAULT, dotted_id)) +-- Strings. local dq_str = lexer.range('"', true, false) local sq_str = lexer.range("'", true, false) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -local branch = B(lexer.space * P':(') * dotted_id * #P')' -local sbranch = B(lexer.space * P':' * S'SF' * '(') * dotted_id * #P')' -local sbranchx = B(P')' * S'SF' * P'(') * dotted_id * #P')' +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S('*#|;!'))))) --- Token definitions. -local bif = token(lexer.FUNCTION, word_match({ - 'APPLY', 'ARRAY', 'CHAR', 'CONVERT', 'COPY', 'DATA', 'DATE', 'DIFFER', 'DUPL', - 'EQ', 'EVAL', 'FILE_ABSPATH', 'FILE_ISDIR', 'FREEZE', 'FUNCTION', 'GE', 'GT', - 'HOST', 'IDENT', 'INTEGER', 'IO_FINDUNIT', 'ITEM', 'LABEL', 'LOAD', 'LPAD', - 'LE', 'LGT', 'LT', 'NE', 'OPSYN', 'ORD', 'PROTOTYPE', 'REMDR', 'REPLACE', - 'REVERSE', 'RPAD', 'RSORT', 'SERV_LISTEN', 'SET', 'SETEXIT', 'SIZE', 'SORT', - 'SQRT', 'SSET', 'SUBSTR', 'TABLE', 'THAW', 'TIME', 'TRACE', 'TRIM', 'UNLOAD', - 'VALUE', 'VDIFFER', -}, '', true) * #lexer.range('(', ')', false, false, true)) -local comment = token(lexer.COMMENT, lexer.starts_line(S'*#|;!' * - lexer.nonnewline^0)) -local control = token(lexer.PREPROCESSOR, lexer.starts_line(P'-' * lexer.word)) -local identifier = token(lexer.DEFAULT, dotted_id) -local keyword = token(lexer.KEYWORD, word_match({ - 'ABORT', 'ARRAY', 'CONTINUE', 'DEFINE', 'END', 'FRETURN', 'INPUT', 'NRETURN', - 'OUTPUT', 'PUNCH', 'RETURN', 'SCONTINUE', 'TABLE', -}, '', true) + P'&' * lexer.word) -local label = token(lexer.LABEL, lexer.starts_line(dotted_id)) -local number = token(lexer.NUMBER, lexer.float + lexer.integer) -local operator = token(lexer.OPERATOR, S'¬?$.!%*/#+-@⊥&^~\\=') -local pattern = lexer.token(lexer.CLASS, word_match({ -- keep distinct - 'ABORT', 'ANY', 'ARB', 'ARBNO', 'BAL', 'BREAK', 'BREAKX', 'FAIL', 'FENCE', - 'LEN', 'NOTANY', 'POS', 'REM', 'RPOS', 'RTAB', 'SPAN', 'SUCCEED', 'TAB', -}, '', true) * #lexer.range('(', ')', false, false, true)) -local str = token(lexer.STRING, sq_str + dq_str) -local target = token(lexer.LABEL, branch + sbranch + sbranchx) -local ws = token(lexer.WHITESPACE, lexer.space^1) - -M._rules = { - { 'comment', comment }, - { 'control', control }, - { 'string', str }, - { 'number', number }, - { 'keyword', keyword }, - { 'label', label }, - { 'target', target }, - { 'pattern', pattern }, - { 'built-in', bif }, - { 'operator', operator }, - { 'identifier', identifier }, - { 'whitespace', ws }, -} - -return M +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Control. +lex:add_rule('control', token(lexer.PREPROCESSOR, lexer.starts_line('-' * lexer.word))) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S'¬?$.!%*/#+-@⊥&^~\\=')) + +return lex diff --git a/syntaxhighlight/textadept/spin.lua b/syntaxhighlight/textadept/spin.lua new file mode 100644 index 0000000..f87af3f --- /dev/null +++ b/syntaxhighlight/textadept/spin.lua @@ -0,0 +1,69 @@ +local lpeg = require('lpeg') +-- Copyright 2017-2021 David B. Lamkins . See LICENSE. +-- Spin LPeg lexer, see https://www.parallax.com/microcontrollers/propeller. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('spin') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + '_clkfreq', '_clkmode', '_free', '_stack', '_xinfreq', 'abort', 'abs', 'absneg', 'add', 'addabs', + 'adds', 'addsx', 'addx', 'and', 'andn', 'byte', 'bytefill', 'bytemove', 'call', 'case', 'chipver', + 'clkfreq', 'clkmode', 'clkset', 'cmp', 'cmps', 'cmpsub', 'cmpsx', 'cmpx', 'cnt', 'cogid', + 'coginit', 'cognew', 'cogstop', 'con', 'constant', 'ctra', 'ctrb', 'dat', 'dira', 'dirb', 'djnz', + 'else', 'elseif', 'elseifnot', 'enc', 'false', 'file', 'fit', 'float', 'from', 'frqa', 'frqb', + 'hubop', 'if', 'ifnot', 'if_a', 'if_ae', 'if_always', 'if_b', 'if_be', 'if_c', 'if_c_and_nz', + 'if_c_and_z', 'if_c_eq_z', 'if_c_ne_z', 'if_c_or_nz', 'if_c_or_z', 'if_e', 'if_nc', + 'if_nc_and_nz', 'if_nc_and_z', 'if_nc_or_nz', 'if_nc_or_z', 'if_ne', 'if_never', 'if_nz', + 'if_nz_and_c', 'if_nz_and_nc', 'if_nz_or_c', 'if_nz_or_nc', 'if_z', 'if_z_and_c', 'if_z_and_nc', + 'if_z_eq_c', 'if_z_ne_c', 'if_z_or_c', 'if_z_or_nc', 'ina', 'inb', 'jmp', 'jmpret', 'lockclr', + 'locknew', 'lockret', 'lockset', 'long', 'longfill', 'longmove', 'lookdown', 'lookdownz', + 'lookup', 'lookupz', 'max', 'maxs', 'min', 'mins', 'mov', 'movd', 'movi', 'movs', 'mul', 'muls', + 'muxc', 'muxnc', 'muxnz', 'muxz', 'neg', 'negc', 'negnc', 'negnz', 'negx', 'negz', 'next', 'nop', + 'not', 'nr', 'obj', 'ones', 'or', 'org', 'other', 'outa', 'outb', 'par', 'phsa', 'phsb', 'pi', + 'pll1x', 'pll2x', 'pll4x', 'pll8x', 'pll16x', 'posx', 'pri', 'pub', 'quit', 'rcfast', 'rcl', + 'rcr', 'rcslow', 'rdbyte', 'rdlong', 'rdword', 'reboot', 'repeat', 'res', 'result', 'ret', + 'return', 'rev', 'rol', 'ror', 'round', 'sar', 'shl', 'shr', 'spr', 'step', 'strcomp', 'string', + 'strsize', 'sub', 'subabs', 'subs', 'subsx', 'subx', 'sumc', 'sumnc', 'sumnz', 'sumz', 'test', + 'testn', 'tjnz', 'tjz', 'to', 'true', 'trunc', 'until', 'var', 'vcfg', 'vscl', 'waitcnt', + 'waitpeq', 'waitpne', 'waitvid', 'wc', 'while', 'word', 'wordfill', 'wordmove', 'wr', 'wrbyte', + 'wrlong', 'wz', 'xinput', 'xor', 'xtal1', 'xtal2', 'xtal3' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.range('"', true))) + +-- Comments. +local line_comment = lexer.to_eol(P("''") + "'") +local block_comment = lexer.range('{', '}') +local block_doc_comment = lexer.range('{{', '}}') +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_doc_comment + block_comment)) + +-- Numbers. +local bin = '%' * S('01_')^1 +local ter = '%%' * (R('03') + '_')^1 +local hex = '$' * (lexer.xdigit + '_')^1 +local dec = (lexer.digit + '_')^1 +local int = bin + ter + dec + hex +local rad = P('.') - '..' +local exp = (S('Ee') * S('+-')^-1 * int)^-1 +local flt = dec * (rad * dec)^-1 * exp + dec^-1 * rad * dec * exp +lex:add_rule('number', token(lexer.NUMBER, flt + int)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, + P('--') + '++' + '^^' + '||' + '~~' + '|<' + '>|' + '@@' + ':=' + '+=' + '-=' + '*=' + '/=' + '**' + + '**=' + '//' + '//=' + '#>' + '#>=' + '<#' + '<#=' + '~>' + '~>=' + '<<' + '<<=' + '>>' + '>>=' + + '<-' + '<-=' + '->' + '->=' + '><' + '><=' + '&=' + '|=' + 'and=' + 'or=' + '==' + '===' + '<>' + + '<>=' + '<=' + '>=' + '=<' + '=<=' + '=>' + '=>=' + '..' + S('+-/*<>~!&=^|?:.()[]@#\\'))) + +return lex diff --git a/syntaxhighlight/textadept/sql.lua b/syntaxhighlight/textadept/sql.lua index 8cec2fe..d5515fb 100644 --- a/syntaxhighlight/textadept/sql.lua +++ b/syntaxhighlight/textadept/sql.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- SQL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('sql') @@ -12,31 +12,33 @@ local lex = lexer.new('sql') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ - add all alter analyze and as asc asensitive before between bigint binary blob - both by call cascade case change char character check collate column condition - connection constraint continue convert create cross current_date current_time - current_timestamp current_user cursor database databases day_hour - day_microsecond day_minute day_second dec decimal declare default delayed - delete desc describe deterministic distinct distinctrow div double drop dual - each else elseif enclosed escaped exists exit explain false fetch float for - force foreign from fulltext goto grant group having high_priority - hour_microsecond hour_minute hour_second if ignore in index infile inner inout - insensitive insert int integer interval into is iterate join key keys kill - leading leave left like limit lines load localtime localtimestamp lock long - longblob longtext loop low_priority match mediumblob mediumint mediumtext - middleint minute_microsecond minute_second mod modifies natural not - no_write_to_binlog null numeric on optimize option optionally or order out - outer outfile precision primary procedure purge read reads real references - regexp rename repeat replace require restrict return revoke right rlike schema - schemas second_microsecond select sensitive separator set show smallint soname - spatial specific sql sqlexception sqlstate sqlwarning sql_big_result - sql_calc_found_rows sql_small_result ssl starting straight_join table - terminated text then tinyblob tinyint tinytext to trailing trigger true undo - union unique unlock unsigned update usage use using utc_date utc_time - utc_timestamp values varbinary varchar varcharacter varying when where while - with write xor year_month zerofill -]], true))) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ + 'add', 'all', 'alter', 'analyze', 'and', 'as', 'asc', 'asensitive', 'before', 'between', 'bigint', + 'binary', 'blob', 'both', 'by', 'call', 'cascade', 'case', 'change', 'char', 'character', 'check', + 'collate', 'column', 'condition', 'connection', 'constraint', 'continue', 'convert', 'create', + 'cross', 'current_date', 'current_time', 'current_timestamp', 'current_user', 'cursor', + 'database', 'databases', 'day_hour', 'day_microsecond', 'day_minute', 'day_second', 'dec', + 'decimal', 'declare', 'default', 'delayed', 'delete', 'desc', 'describe', 'deterministic', + 'distinct', 'distinctrow', 'div', 'double', 'drop', 'dual', 'each', 'else', 'elseif', 'enclosed', + 'escaped', 'exists', 'exit', 'explain', 'false', 'fetch', 'float', 'for', 'force', 'foreign', + 'from', 'fulltext', 'goto', 'grant', 'group', 'having', 'high_priority', 'hour_microsecond', + 'hour_minute', 'hour_second', 'if', 'ignore', 'in', 'index', 'infile', 'inner', 'inout', + 'insensitive', 'insert', 'int', 'integer', 'interval', 'into', 'is', 'iterate', 'join', 'key', + 'keys', 'kill', 'leading', 'leave', 'left', 'like', 'limit', 'lines', 'load', 'localtime', + 'localtimestamp', 'lock', 'long', 'longblob', 'longtext', 'loop', 'low_priority', 'match', + 'mediumblob', 'mediumint', 'mediumtext', 'middleint', 'minute_microsecond', 'minute_second', + 'mod', 'modifies', 'natural', 'not', 'no_write_to_binlog', 'null', 'numeric', 'on', 'optimize', + 'option', 'optionally', 'or', 'order', 'out', 'outer', 'outfile', 'precision', 'primary', + 'procedure', 'purge', 'read', 'reads', 'real', 'references', 'regexp', 'rename', 'repeat', + 'replace', 'require', 'restrict', 'return', 'revoke', 'right', 'rlike', 'schema', 'schemas', + 'second_microsecond', 'select', 'sensitive', 'separator', 'set', 'show', 'smallint', 'soname', + 'spatial', 'specific', 'sql', 'sqlexception', 'sqlstate', 'sqlwarning', 'sql_big_result', + 'sql_calc_found_rows', 'sql_small_result', 'ssl', 'starting', 'straight_join', 'table', + 'terminated', 'text', 'then', 'tinyblob', 'tinyint', 'tinytext', 'to', 'trailing', 'trigger', + 'true', 'undo', 'union', 'unique', 'unlock', 'unsigned', 'update', 'usage', 'use', 'using', + 'utc_date', 'utc_time', 'utc_timestamp', 'values', 'varbinary', 'varchar', 'varcharacter', + 'varying', 'when', 'where', 'while', 'with', 'write', 'xor', 'year_month', 'zerofill' +}, true))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) diff --git a/syntaxhighlight/textadept/systemd.lua b/syntaxhighlight/textadept/systemd.lua new file mode 100644 index 0000000..584b415 --- /dev/null +++ b/syntaxhighlight/textadept/systemd.lua @@ -0,0 +1,134 @@ +local lpeg = require('lpeg') +-- Copyright 2016-2021 Christian Hesse. See LICENSE. +-- systemd unit file LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('systemd', {lex_by_line = true}) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Boolean values. + 'true', 'false', 'on', 'off', 'yes', 'no', + -- Service types. + 'forking', 'simple', 'oneshot', 'dbus', 'notify', 'idle', + -- Special system units. + 'basic.target', 'ctrl-alt-del.target', 'cryptsetup.target', 'dbus.service', 'dbus.socket', + 'default.target', 'display-manager.service', 'emergency.target', 'exit.target', 'final.target', + 'getty.target', 'graphical.target', 'hibernate.target', 'hybrid-sleep.target', 'halt.target', + 'initrd-fs.target', 'kbrequest.target', 'kexec.target', 'local-fs.target', 'multi-user.target', + 'network-online.target', 'paths.target', 'poweroff.target', 'reboot.target', 'remote-fs.target', + 'rescue.target', 'initrd-root-fs.target', 'runlevel2.target', 'runlevel3.target', + 'runlevel4.target', 'runlevel5.target', 'shutdown.target', 'sigpwr.target', 'sleep.target', + 'slices.target', 'sockets.target', 'suspend.target', 'swap.target', 'sysinit.target', + 'syslog.socket', 'system-update.target', 'timers.target', 'umount.target', + -- Special system units for devices. + 'bluetooth.target', 'printer.target', 'smartcard.target', 'sound.target', + -- Special passive system units. + 'cryptsetup-pre.target', 'local-fs-pre.target', 'network.target', 'network-pre.target', + 'nss-lookup.target', 'nss-user-lookup.target', 'remote-fs-pre.target', 'rpcbind.target', + 'time-sync.target', + -- Specail slice units. + '-.slice', 'system.slice', 'user.slice', 'machine.slice', + -- Environment variables. + 'PATH', 'LANG', 'USER', 'LOGNAME', 'HOME', 'SHELL', 'XDG_RUNTIME_DIR', 'XDG_SESSION_ID', + 'XDG_SEAT', 'XDG_VTNR', 'MAINPID', 'MANAGERPID', 'LISTEN_FDS', 'LISTEN_PID', 'LISTEN_FDNAMES', + 'NOTIFY_SOCKET', 'WATCHDOG_PID', 'WATCHDOG_USEC', 'TERM' +})) + +-- Options. +lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{ + -- Unit section. + 'Description', 'Documentation', 'Requires', 'Requisite', 'Wants', 'BindsTo', 'PartOf', + 'Conflicts', 'Before', 'After', 'OnFailure', 'PropagatesReloadTo', 'ReloadPropagatedFrom', + 'JoinsNamespaceOf', 'RequiresMountsFor', 'OnFailureJobMode', 'IgnoreOnIsolate', + 'StopWhenUnneeded', 'RefuseManualStart', 'RefuseManualStop', 'AllowIsolate', + 'DefaultDependencies', 'JobTimeoutSec', 'JobTimeoutAction', 'JobTimeoutRebootArgument', + 'StartLimitInterval', 'StartLimitBurst', 'StartLimitAction', 'RebootArgument', + 'ConditionArchitecture', 'ConditionVirtualization', 'ConditionHost', 'ConditionKernelCommandLine', + 'ConditionSecurity', 'ConditionCapability', 'ConditionACPower', 'ConditionNeedsUpdate', + 'ConditionFirstBoot', 'ConditionPathExists', 'ConditionPathExistsGlob', + 'ConditionPathIsDirectory', 'ConditionPathIsSymbolicLink', 'ConditionPathIsMountPoint', + 'ConditionPathIsReadWrite', 'ConditionDirectoryNotEmpty', 'ConditionFileNotEmpty', + 'ConditionFileIsExecutable', 'AssertArchitecture', 'AssertVirtualization', 'AssertHost', + 'AssertKernelCommandLine', 'AssertSecurity', 'AssertCapability', 'AssertACPower', + 'AssertNeedsUpdate', 'AssertFirstBoot', 'AssertPathExists', 'AssertPathExistsGlob', + 'AssertPathIsDirectory', 'AssertPathIsSymbolicLink', 'AssertPathIsMountPoint', + 'AssertPathIsReadWrite', 'AssertDirectoryNotEmpty', 'AssertFileNotEmpty', + 'AssertFileIsExecutable', 'SourcePath', + -- Install section. + 'Alias', 'WantedBy', 'RequiredBy', 'Also', 'DefaultInstance', + -- Service section. + 'Type', 'RemainAfterExit', 'GuessMainPID', 'PIDFile', 'BusName', 'BusPolicy', 'ExecStart', + 'ExecStartPre', 'ExecStartPost', 'ExecReload', 'ExecStop', 'ExecStopPost', 'RestartSec', + 'TimeoutStartSec', 'TimeoutStopSec', 'TimeoutSec', 'RuntimeMaxSec', 'WatchdogSec', 'Restart', + 'SuccessExitStatus', 'RestartPreventExitStatus', 'RestartForceExitStatus', 'PermissionsStartOnly', + 'RootDirectoryStartOnly', 'NonBlocking', 'NotifyAccess', 'Sockets', 'FailureAction', + 'FileDescriptorStoreMax', 'USBFunctionDescriptors', 'USBFunctionStrings', + -- Socket section. + 'ListenStream', 'ListenDatagram', 'ListenSequentialPacket', 'ListenFIFO', 'ListenSpecial', + 'ListenNetlink', 'ListenMessageQueue', 'ListenUSBFunction', 'SocketProtocol', 'BindIPv6Only', + 'Backlog', 'BindToDevice', 'SocketUser', 'SocketGroup', 'SocketMode', 'DirectoryMode', 'Accept', + 'Writable', 'MaxConnections', 'KeepAlive', 'KeepAliveTimeSec', 'KeepAliveIntervalSec', + 'KeepAliveProbes', 'NoDelay', 'Priority', 'DeferAcceptSec', 'ReceiveBuffer', 'SendBuffer', + 'IPTOS', 'IPTTL', 'Mark', 'ReusePort', 'SmackLabel', 'SmackLabelIPIn', 'SmackLabelIPOut', + 'SELinuxContextFromNet', 'PipeSize', 'MessageQueueMaxMessages', 'MessageQueueMessageSize', + 'FreeBind', 'Transparent', 'Broadcast', 'PassCredentials', 'PassSecurity', 'TCPCongestion', + 'ExecStartPre', 'ExecStartPost', 'ExecStopPre', 'ExecStopPost', 'TimeoutSec', 'Service', + 'RemoveOnStop', 'Symlinks', 'FileDescriptorName', + -- Mount section. + 'What', 'Where', 'Type', 'Options', 'SloppyOptions', 'DirectoryMode', 'TimeoutSec', + -- Path section. + 'PathExists', 'PathExistsGlob', 'PathChanged', 'PathModified', 'DirectoryNotEmpty', 'Unit', + 'MakeDirectory', 'DirectoryMode', + -- Timer section. + 'OnActiveSec', 'OnBootSec', 'OnStartupSec', 'OnUnitActiveSec', 'OnUnitInactiveSec', 'OnCalendar', + 'AccuracySec', 'RandomizedDelaySec', 'Unit', 'Persistent', 'WakeSystem', 'RemainAfterElapse', + -- Exec section. + 'WorkingDirectory', 'RootDirectory', 'User', 'Group', 'SupplementaryGroups', 'Nice', + 'OOMScoreAdjust', 'IOSchedulingClass', 'IOSchedulingPriority', 'CPUSchedulingPolicy', + 'CPUSchedulingPriority', 'CPUSchedulingResetOnFork', 'CPUAffinity', 'UMask', 'Environment', + 'EnvironmentFile', 'PassEnvironment', 'StandardInput', 'StandardOutput', 'StandardError', + 'TTYPath', 'TTYReset', 'TTYVHangup', 'TTYVTDisallocate', 'SyslogIdentifier', 'SyslogFacility', + 'SyslogLevel', 'SyslogLevelPrefix', 'TimerSlackNSec', 'LimitCPU', 'LimitFSIZE', 'LimitDATA', + 'LimitSTACK', 'LimitCORE', 'LimitRSS', 'LimitNOFILE', 'LimitAS', 'LimitNPROC', 'LimitMEMLOCK', + 'LimitLOCKS', 'LimitSIGPENDING', 'LimitMSGQUEUE', 'LimitNICE', 'LimitRTPRIO', 'LimitRTTIME', + 'PAMName', 'CapabilityBoundingSet', 'AmbientCapabilities', 'SecureBits', 'Capabilities', + 'ReadWriteDirectories', 'ReadOnlyDirectories', 'InaccessibleDirectories', 'PrivateTmp', + 'PrivateDevices', 'PrivateNetwork', 'ProtectSystem', 'ProtectHome', 'MountFlags', + 'UtmpIdentifier', 'UtmpMode', 'SELinuxContext', 'AppArmorProfile', 'SmackProcessLabel', + 'IgnoreSIGPIPE', 'NoNewPrivileges', 'SystemCallFilter', 'SystemCallErrorNumber', + 'SystemCallArchitectures', 'RestrictAddressFamilies', 'Personality', 'RuntimeDirectory', + 'RuntimeDirectoryMode' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0)) + +-- Strings. +local sq_str = lexer.range("'") +local dq_str = lexer.range('"') +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Sections. +lex:add_rule('section', token(lexer.LABEL, '[' * + word_match('Automount BusName Install Mount Path Service Service Socket Timer Unit') * ']')) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#'))))) + +-- Numbers. +local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 +local oct_num = '0' * S('01234567_')^1 +local integer = S('+-')^-1 * (lexer.hex_num + oct_num + dec) +lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, '=')) + +return lex diff --git a/syntaxhighlight/textadept/taskpaper.lua b/syntaxhighlight/textadept/taskpaper.lua index 7da9594..83cfc5f 100644 --- a/syntaxhighlight/textadept/taskpaper.lua +++ b/syntaxhighlight/textadept/taskpaper.lua @@ -1,59 +1,40 @@ local lpeg = require('lpeg') --- Copyright (c) 2016-2020 Larry Hynes. See License.txt. +-- Copyright (c) 2016-2021 Larry Hynes. See LICENSE. -- Taskpaper LPeg lexer local lexer = require('syntaxhighlight.textadept.lexer') local token = lexer.token -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S -local M = {_NAME = 'taskpaper'} +local lex = lexer.new('taskpaper', {lex_by_line = true}) local delimiter = P(' ') + P('\t') --- Whitespace -local ws = token(lexer.WHITESPACE, lexer.space^1) - --- Tags -local day_tag = token('day_tag', (P('@today') + P('@tomorrow'))) - -local overdue_tag = token('overdue_tag', P('@overdue')) - -local plain_tag = token('plain_tag', P('@') * lexer.word) - -local extended_tag = token('extended_tag', P('@') * lexer.word * P('(') * - (lexer.word + R('09') + P('-'))^1 * P(')')) - --- Projects -local project = token('project', lexer.range(lexer.starts_line(lexer.alnum), - ':', false, false, true) * lexer.newline) - --- Notes -local note = token('note', delimiter^1 * lexer.alnum * lexer.nonnewline^0) - --- Tasks -local task = token('task', delimiter^1 * P('-') + lexer.newline) - -M._rules = { - {'note', note}, - {'task', task}, - {'project', project}, - {'extended_tag', extended_tag}, - {'day_tag', day_tag}, - {'overdue_tag', overdue_tag}, - {'plain_tag', plain_tag}, - {'whitespace', ws}, -} - -M._tokenstyles = { - note = lexer.STYLE_CONSTANT, - task = lexer.STYLE_FUNCTION, - project = lexer.STYLE_TAG, - extended_tag = lexer.STYLE_COMMENT, - day_tag = lexer.STYLE_CLASS, - overdue_tag = lexer.STYLE_PREPROCESSOR, - plain_tag = lexer.STYLE_COMMENT, -} - -M._LEXBYLINE = true - -return M +-- Notes. +lex:add_rule('note', token('note', delimiter^1 * lexer.to_eol(lexer.alnum))) +lex:add_style('note', lexer.styles.constant) + +-- Tasks. +lex:add_rule('task', token('task', delimiter^1 * '-' + lexer.newline)) +lex:add_style('task', lexer.styles['function']) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Projects. +lex:add_rule('project', + token('project', lexer.range(lexer.starts_line(lexer.alnum), ':') * lexer.newline)) +lex:add_style('project', lexer.styles.label) + +-- Tags. +lex:add_rule('extended_tag', token('extended_tag', '@' * lexer.word * '(' * + (lexer.word + lexer.digit + '-')^1 * ')')) +lex:add_style('extended_tag', lexer.styles.comment) +lex:add_rule('day_tag', token('day_tag', (P('@today') + '@tomorrow'))) +lex:add_style('day_tag', lexer.styles.class) +lex:add_rule('overdue_tag', token('overdue_tag', '@overdue')) +lex:add_style('overdue_tag', lexer.styles.preprocessor) +lex:add_rule('plain_tag', token('plain_tag', '@' * lexer.word)) +lex:add_style('plain_tag', lexer.styles.comment) + +return lex diff --git a/syntaxhighlight/textadept/tcl.lua b/syntaxhighlight/textadept/tcl.lua index 260f199..c608b36 100644 --- a/syntaxhighlight/textadept/tcl.lua +++ b/syntaxhighlight/textadept/tcl.lua @@ -1,12 +1,12 @@ local lpeg = require('lpeg') --- Copyright 2014-2020 Joshua Krämer. See License.txt. +-- Copyright 2014-2021 Joshua Krämer. See LICENSE. -- Tcl LPeg lexer. -- This lexer follows the TCL dodekalogue (http://wiki.tcl.tk/10259). -- It is based on the previous lexer by Mitchell. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('tcl') @@ -14,18 +14,17 @@ local lex = lexer.new('tcl') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comment. -lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#' * - P(function(input, index) - local i = index - 2 - while i > 0 and input:find('^[ \t]', i) do i = i - 1 end - if i < 1 or input:find('^[\r\n;]', i) then return index end - end)))) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#' * P(function(input, index) + local i = index - 2 + while i > 0 and input:find('^[ \t]', i) do i = i - 1 end + if i < 1 or input:find('^[\r\n;]', i) then return index end +end)))) -- Separator (semicolon). -lex:add_rule('separator', token(lexer.CLASS, P(';'))) +lex:add_rule('separator', token(lexer.CLASS, ';')) -- Argument expander. -lex:add_rule('expander', token(lexer.LABEL, P('{*}'))) +lex:add_rule('expander', token(lexer.LABEL, '{*}')) -- Delimiters. lex:add_rule('braces', token(lexer.KEYWORD, S('{}'))) @@ -33,8 +32,7 @@ lex:add_rule('quotes', token(lexer.FUNCTION, '"')) lex:add_rule('brackets', token(lexer.VARIABLE, S('[]'))) -- Variable substitution. -lex:add_rule('variable', token(lexer.STRING, '$' * - (lexer.alnum + '_' + P(':')^2)^0)) +lex:add_rule('variable', token(lexer.STRING, '$' * (lexer.alnum + '_' + P(':')^2)^0)) -- Backslash substitution. local oct = lexer.digit * lexer.digit^-2 @@ -44,6 +42,6 @@ lex:add_rule('backslash', token(lexer.TYPE, '\\' * (oct + hex + unicode + 1))) -- Fold points. lex:add_fold_point(lexer.KEYWORD, '{', '}') -lex:add_fold_point(lexer.COMMENT, '#', lexer.fold_line_comments('#')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) return lex diff --git a/syntaxhighlight/textadept/tex.lua b/syntaxhighlight/textadept/tex.lua index 97b01fa..45ff4fd 100644 --- a/syntaxhighlight/textadept/tex.lua +++ b/syntaxhighlight/textadept/tex.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Plain TeX LPeg lexer. -- Modified by Robert Gieseke. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('tex') @@ -16,19 +16,17 @@ lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) -- TeX environments. -lex:add_rule('environment', token('environment', '\\' * (P('begin') + 'end') * - lexer.word)) -lex:add_style('environment', lexer.STYLE_KEYWORD) +lex:add_rule('environment', token('environment', '\\' * (P('begin') + 'end') * lexer.word)) +lex:add_style('environment', lexer.styles.keyword) -- Commands. -lex:add_rule('command', token(lexer.KEYWORD, '\\' * (lexer.alpha^1 + - S('#$&~_^%{}')))) +lex:add_rule('command', token(lexer.KEYWORD, '\\' * (lexer.alpha^1 + S('#$&~_^%{}')))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('$&#{}[]'))) -- Fold points. -lex:add_fold_point(lexer.COMMENT, '%', lexer.fold_line_comments('%')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('%')) lex:add_fold_point('environment', '\\begin', '\\end') lex:add_fold_point(lexer.OPERATOR, '{', '}') diff --git a/syntaxhighlight/textadept/texinfo.lua b/syntaxhighlight/textadept/texinfo.lua index 9a97440..0ba29b9 100644 --- a/syntaxhighlight/textadept/texinfo.lua +++ b/syntaxhighlight/textadept/texinfo.lua @@ -1,16 +1,15 @@ local lpeg = require('lpeg') --- Copyright 2014-2020 stef@ailleurs.land. See License.txt. +-- Copyright 2014-2021 stef@ailleurs.land. See LICENSE. -- Plain Texinfo version 5.2 LPeg lexer -- Freely inspired from Mitchell work and valuable help from him too ! --- Directives are processed (more or less) in the Reference Card Texinfo order --- Reference Card page for each directive group is in comment for reference +-- Directives are processed (more or less) in the Reference Card Texinfo order Reference Card +-- page for each directive group is in comment for reference --[[ Note: Improving Fold Points use with Texinfo -At the very beginning of your Texinfo file, it could be wised to insert theses -alias : +At the very beginning of your Texinfo file, it could be wised to insert theses alias : @alias startchapter = comment @alias endchapter = comment @@ -22,13 +21,13 @@ Then use this to begin each chapter : @startchapter ------------------------------------------------------------------ With the use of Scintilla's `SCI_FOLDALL(SC_FOLDACTION_TOGGLE)` or Textadept's -`buffer:fold_all(buffer.FOLDACTION_TOGGLE)`, you have then a nice chapter -folding, useful with large documents. +`buffer:fold_all(buffer.FOLDACTION_TOGGLE)`, you have then a nice chapter folding, useful with +large documents. ]] local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('texinfo') @@ -36,158 +35,145 @@ local lex = lexer.new('texinfo') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Directives. -local directives_base = word_match([[ - end +local directives_base = word_match({ + 'end', -- Custom keywords for chapter folding - startchapter endchapter + 'startchapter', 'endchapter', -- List and tables (page 2, column 2) - itemize enumerate + 'itemize', 'enumerate', -- Beginning a Texinfo document (page 1, column 1) - titlepage copying + 'titlepage', 'copying', -- Block environments (page 2, column 1) - cartouche + 'cartouche', -- Block environments > Displays using fixed-width fonts (page 2, column 2) - example smallexample + 'example', 'smallexample', -- List and tables (page 2, column 2) - multitable + 'multitable', -- Floating Displays (page 2, column 3) - float listoffloats caption shortcaption image + 'float', 'listoffloats', 'caption', 'shortcaption', 'image', -- Floating Displays > Footnotes (page 2, column 3) - footnote footnotestyle + 'footnote', 'footnotestyle', -- Conditionally (in)visible text > Output formats (page 3, column 3) - ifdocbook ifhtml ifinfo ifplaintext iftex ifxml ifnotdocbook ifnothtml - ifnotplaintext ifnottex ifnotxml ifnotinfo inlinefmt inlinefmtifelse + 'ifdocbook', 'ifhtml', 'ifinfo', 'ifplaintext', 'iftex', 'ifxml', 'ifnotdocbook', 'ifnothtml', + 'ifnotplaintext', 'ifnottex', 'ifnotxml', 'ifnotinfo', 'inlinefmt', 'inlinefmtifelse', -- Conditionally (in)visible text > Raw formatter text (page 4, column 1) - docbook html tex xml inlineraw + 'docbook', 'html', 'tex', 'xml', 'inlineraw', -- Conditionally (in)visible text > Documents variables (page 4, column 1) - set clear value ifset ifclear inlineifset inlineifclear + 'set', 'clear', 'value', 'ifset', 'ifclear', 'inlineifset', 'inlineifclear', -- Conditionally (in)visible text > Testing for commands (page 4, column 1) - ifcommanddefined ifcommandnotdefined end + 'ifcommanddefined', 'ifcommandnotdefined', 'end', -- Defining new Texinfo commands (page 4, column 1) - alias macro unmacro definfounclose + 'alias', 'macro', 'unmacro', 'definfounclose', -- File inclusion (page 4, column 1) - include verbatiminclude + 'include', 'verbatiminclude', -- Formatting and headers footers for TeX (page 4, column 1) - allowcodebreaks finalout fonttextsize + 'allowcodebreaks', 'finalout', 'fonttextsize', -- Formatting and headers footers for TeX > paper size (page 4, column 2) - smallbook afourpaper afivepaper afourlatex afourwide pagesizes - -- Formatting and headers footers for TeX > Page headers and footers (page 4, - -- column 2) + 'smallbook', 'afourpaper', 'afivepaper', 'afourlatex', 'afourwide', 'pagesizes', + -- Formatting and headers footers for TeX > Page headers and footers (page 4, column 2) -- not implemented -- Document preferences (page 4, column 2) -- not implemented -- Ending a Texinfo document (page 4, column 2) - bye -]], true) -lex:add_rule('directive', token('directives', ('@end' * lexer.space^1 + '@') * - directives_base)) -lex:add_style('directives', lexer.STYLE_FUNCTION) + 'bye' +}, true) +lex:add_rule('directive', token('directives', ('@end' * lexer.space^1 + '@') * directives_base)) +lex:add_style('directives', lexer.styles['function']) -- Chapters. -local chapters_base = word_match([[ +local chapters_base = word_match({ -- Chapter structuring (page 1, column 2) - lowersections raisesections part + 'lowersections', 'raisesections', 'part', -- Chapter structuring > Numbered, included in contents (page 1, column 2) - chapter centerchap - -- Chapter structuring > Context-dependent, included in contents (page 1, - -- column 2) - section subsection subsubsection + 'chapter', 'centerchap', + -- Chapter structuring > Context-dependent, included in contents (page 1, column 2) + 'section', 'subsection', 'subsubsection', -- Chapter structuring > Unumbered, included in contents (page 1, column 2) - unnumbered unnumberedsec unnumberedsubsec unnumberedsubsection - unnumberedsubsubsec unnumberedsubsubsection - -- Chapter structuring > Letter and numbered, included in contents (page 1, - -- column 2) - appendix appendixsec appendixsection appendixsubsec appendixsubsection - appendixsubsubsec appendixsubsubsection - -- Chapter structuring > Unumbered, not included in contents, no new page - -- (page 1, column 3) - chapheading majorheading heading subheading subsubheading -]], true) -lex:add_rule('chapter', token('chapters', ('@end' * lexer.space^1 + '@') * - chapters_base)) -lex:add_style('chapters', lexer.STYLE_CLASS) + 'unnumbered', 'unnumberedsec', 'unnumberedsubsec', 'unnumberedsubsection', 'unnumberedsubsubsec', + 'unnumberedsubsubsection', + -- Chapter structuring > Letter and numbered, included in contents (page 1, column 2) + 'appendix', 'appendixsec', 'appendixsection', 'appendixsubsec', 'appendixsubsection', + 'appendixsubsubsec', 'appendixsubsubsection', + -- Chapter structuring > Unumbered, not included in contents, no new page (page 1, column 3) + 'chapheading', 'majorheading', 'heading', 'subheading', 'subsubheading' +}, true) +lex:add_rule('chapter', token('chapters', ('@end' * lexer.space^1 + '@') * chapters_base)) +lex:add_style('chapters', lexer.styles.class) -- Common keywords. -local keyword_base = word_match([[ - end +local keyword_base = word_match({ + 'end', -- Beginning a Texinfo document (page 1, column 1) - setfilename settitle insertcopying + 'setfilename', 'settitle', 'insertcopying', -- Beginning a Texinfo document > Internationlization (page 1, column 1) - documentencoding documentlanguage frenchspacing - -- Beginning a Texinfo document > Info directory specification and HTML - -- document description (page 1, column 1) - dircategory direntry documentdescription + 'documentencoding', 'documentlanguage', 'frenchspacing', + -- Beginning a Texinfo document > Info directory specification and HTML document description + -- (page 1, column 1) + 'dircategory', 'direntry', 'documentdescription', -- Beginning a Texinfo document > Titre pages (page 1, column 1) - shorttitlepage center titlefont title subtitle author + 'shorttitlepage', 'center', 'titlefont', 'title', 'subtitle', 'author', -- Beginning a Texinfo document > Tables of contents (page 1, column 2) - shortcontents summarycontents contents setcontentsaftertitlepage - setshortcontentsaftertitlepage + 'shortcontents', 'summarycontents', 'contents', 'setcontentsaftertitlepage', + 'setshortcontentsaftertitlepage', -- Nodes (page 1, column 2) - node top anchor novalidate + 'node', 'top', 'anchor', 'novalidate', -- Menus (page 1, column 2) - menu detailmenu + 'menu', 'detailmenu', -- Cross references > Within the Info system (page 1, column 3) - xref pxref ref inforef xrefautomaticsectiontitle + 'xref', 'pxref', 'ref', 'inforef', 'xrefautomaticsectiontitle', -- Cross references > Outside of info (page 1, column 3) - url cite + 'url', 'cite', -- Marking text > Markup for regular text (page 1, column 3) - var dfn acronym abbr + 'var', 'dfn', 'acronym', 'abbr', -- Marking text > Markup for litteral text (page 1, column 3) - code file command env option kbd key email indicateurl samp verb + 'code', 'file', 'command', 'env', 'option', 'kbd', 'key', 'email', 'indicateurl', 'samp', 'verb', -- Marking text > GUI sequences (page 2, column 1) - clicksequence click clickstyle arrow + 'clicksequence', 'click', 'clickstyle', 'arrow', -- Marking text > Math (page 2, column 1) - math minus geq leq + 'math', 'minus', 'geq', 'leq', -- Marking text > Explicit font selection (page 2, column 1) - sc r i slanted b sansserif t + 'sc', 'r', 'i', 'slanted', 'b', 'sansserif', 't', -- Block environments (page 2, column 1) - noindent indent exdent - -- Block environments > Normally filled displays using regular text fonts - -- (page 2, column 1) - quotation smallquotation indentedblock smallindentedblock raggedright - -- Block environments > Line-for-line displays using regular test fonts (page - -- 2, column 2) - format smallformat display smalldisplay flushleft flushright + 'noindent', 'indent', 'exdent', + -- Block environments > Normally filled displays using regular text fonts (page 2, column 1) + 'quotation', 'smallquotation', 'indentedblock', 'smallindentedblock', 'raggedright', + -- Block environments > Line-for-line displays using regular test fonts (page 2, column 2) + 'format', 'smallformat', 'display', 'smalldisplay', 'flushleft', 'flushright', -- Block environments > Displays using fixed-width fonts (page 2, column 2) - lisp smalllisp verbatim + 'lisp', 'smalllisp', 'verbatim', -- List and tables (page 2, column 2) - table ftable vtable tab item itemx headitem headitemfont asis + 'table', 'ftable', 'vtable', 'tab', 'item', 'itemx', 'headitem', 'headitemfont', 'asis', -- Indices (page 2, column 3) - cindex findex vindex kindex pindex tindex defcodeindex syncodeindex synindex - printindex - -- Insertions within a paragraph > Characters special to Texinfo (page 2, - -- column 3) - @ { } backslashcar comma hashcar : . ? ! dmn + 'cindex', 'findex', 'vindex', 'kindex', 'pindex', 'tindex', 'defcodeindex', 'syncodeindex', + 'synindex', 'printindex', + -- Insertions within a paragraph > Characters special to Texinfo (page 2, column 3) + '@', '{', '}', 'backslashcar', 'comma', 'hashcar', ':', '.', '?', '!', 'dmn', -- Insertions within a paragraph > Accents (page 3, column 1) -- not implemented -- Insertions within a paragraph > Non-English characters (page 3, column 1) -- not implemented - -- Insertions within a paragraph > Other text characters an logos (page 3, - -- column 1) - bullet dots enddots euro pounds textdegree copyright registeredsymbol TeX - LaTeX today guillemetleft guillementright guillemotleft guillemotright + -- Insertions within a paragraph > Other text characters an logos (page 3, column 1) + 'bullet', 'dots', 'enddots', 'euro', 'pounds', 'textdegree', 'copyright', 'registeredsymbol', + 'TeX', 'LaTeX', 'today', 'guillemetleft', 'guillementright', 'guillemotleft', 'guillemotright', -- Insertions within a paragraph > Glyphs for code examples (page 3, column 2) - equiv error expansion point print result + 'equiv', 'error', 'expansion', 'point', 'print', 'result', -- Making and preventing breaks (page 3, column 2) - * / - hyphenation tie w refill + '*', '/', '-', 'hyphenation', 'tie', 'w', 'refill', -- Vertical space (page 3, column 2) - sp page need group vskip + 'sp', 'page', 'need', 'group', 'vskip' -- Definition commands (page 3, column 2) -- not implemented -]], true) -lex:add_rule('keyword', token(lexer.KEYWORD, ('@end' * lexer.space^1 + '@') * - keyword_base)) - -local nested_braces = lexer.range('{', '}', false, false, true) +}, true) +lex:add_rule('keyword', token(lexer.KEYWORD, ('@end' * lexer.space^1 + '@') * keyword_base)) -- Italics +local nested_braces = lexer.range('{', '}', false, false, true) lex:add_rule('emph', token('emph', '@emph' * nested_braces)) - -lex:add_style('emph', lexer.STYLE_STRING .. ',italics') +lex:add_style('emph', lexer.styles.string .. {italics = true}) -- Bold lex:add_rule('strong', token('strong', '@strong' * nested_braces)) -lex:add_style('strong', lexer.STYLE_STRING .. ',bold') +lex:add_style('strong', lexer.styles.string .. {bold = true}) -- Identifiers lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -200,7 +186,7 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Comments. local line_comment = lexer.to_eol('@c', true) ---local line_comment_long = lexer.to_eol('@comment', true) +-- local line_comment_long = lexer.to_eol('@comment', true) local block_comment = lexer.range('@ignore', '@end ignore') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) diff --git a/syntaxhighlight/textadept/text.lua b/syntaxhighlight/textadept/text.lua index 1a9912a..b4f51d6 100644 --- a/syntaxhighlight/textadept/text.lua +++ b/syntaxhighlight/textadept/text.lua @@ -1,5 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Text LPeg lexer. -return require('syntaxhighlight.textadept.lexer').new('text') +local lexer = require('syntaxhighlight.textadept.lexer') + +local lex = lexer.new('text') + +lex:add_rule('whitespace', lexer.token(lexer.WHITESPACE, lexer.space^1)) + +return lex diff --git a/syntaxhighlight/textadept/toml.lua b/syntaxhighlight/textadept/toml.lua index 12a492e..aa15ec3 100644 --- a/syntaxhighlight/textadept/toml.lua +++ b/syntaxhighlight/textadept/toml.lua @@ -1,22 +1,18 @@ local lpeg = require('lpeg') --- Copyright 2015-2020 Alejandro Baez (https://keybase.io/baez). See License.txt. +-- Copyright 2015-2021 Alejandro Baez (https://keybase.io/baez). See LICENSE. -- TOML LPeg lexer. local lexer = require("lexer") local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('toml', {fold_by_indentation = true}) -- Whitespace -lex:add_rule('indent', #lexer.starts_line(S(' \t')) * - (token(lexer.WHITESPACE, ' ') + token('indent_error', '\t'))^1) -lex:add_rule('whitespace', token(lexer.WHITESPACE, S(' \t')^1 + - lexer.newline^1)) -lex:add_style('indent_error', 'back:%(color.red)') +lex:add_rule('whitespace', token(lexer.WHITESPACE, S(' \t')^1 + lexer.newline^1)) -- kewwords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[true false]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match('true false'))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -30,7 +26,7 @@ lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) -- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('#=+-,.{}[]()'))) +lex:add_rule('operator', token(lexer.OPERATOR, S('=+-,.{}[]()'))) -- Datetime. local year = lexer.digit * lexer.digit * lexer.digit * lexer.digit @@ -45,7 +41,7 @@ local time = hours * ':' * minutes * ':' * seconds * fraction^-1 local T = S(' \t')^1 + S('tT') local zone = 'Z' + S(' \t')^0 * S('-+') * hours * (':' * minutes)^-1 lex:add_rule('datetime', token('timestamp', date * (T * time * zone^-1))) -lex:add_style('timestamp', lexer.STYLE_NUMBER) +lex:add_style('timestamp', lexer.styles.number) -- Numbers. lex:add_rule('number', token(lexer.NUMBER, lexer.number)) diff --git a/syntaxhighlight/textadept/txt2tags.lua b/syntaxhighlight/textadept/txt2tags.lua index 51e6083..dec364d 100644 --- a/syntaxhighlight/textadept/txt2tags.lua +++ b/syntaxhighlight/textadept/txt2tags.lua @@ -1,4 +1,5 @@ local lpeg = require('lpeg') +-- Copyright 2019-2021 Julien L. See LICENSE. -- txt2tags LPeg lexer. -- (developed and tested with Txt2tags Markup Rules -- [https://txt2tags.org/doc/english/rules.t2t]) @@ -6,7 +7,7 @@ local lpeg = require('lpeg') local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local nonspace = lexer.any - lexer.space local lex = lexer.new('txt2tags') @@ -15,14 +16,12 @@ local lex = lexer.new('txt2tags') local ws = token(lexer.WHITESPACE, (lexer.space - lexer.newline)^1) -- Titles -local alphanumeric = R('AZ') + R('az') + R('09') + P('_') + P('-') -local header_label = token('header_label_start', '[') * - token('header_label', alphanumeric^1) * token('header_label_end', ']') +local alphanumeric = lexer.alnum + S('_-') +local header_label = token('header_label_start', '[') * token('header_label', alphanumeric^1) * + token('header_label_end', ']') local function h(level) - local equal = string.rep('=', level) * (lexer.nonnewline - '=')^1 * - string.rep('=', level) - local plus = string.rep('+', level) * (lexer.nonnewline - '+')^1 * - string.rep('+', level) + local equal = string.rep('=', level) * (lexer.nonnewline - '=')^1 * string.rep('=', level) + local plus = string.rep('+', level) * (lexer.nonnewline - '+')^1 * string.rep('+', level) return token('h' .. level, equal + plus) * header_label^-1 end local header = h(5) + h(4) + h(3) + h(2) + h(1) @@ -34,9 +33,9 @@ local comment = token(lexer.COMMENT, block_comment + line_comment) -- Inline. local function span(name, delimiter) - return token(name, (delimiter * nonspace * delimiter * S(delimiter)^0) + ( - delimiter * nonspace * (lexer.nonnewline - nonspace * delimiter)^0 * - nonspace * delimiter * S(delimiter)^0)) + return token(name, (delimiter * nonspace * delimiter * S(delimiter)^0) + + (delimiter * nonspace * (lexer.nonnewline - nonspace * delimiter)^0 * nonspace * delimiter * + S(delimiter)^0)) end local bold = span('bold', '**') local italic = span('italic', '//') @@ -48,36 +47,34 @@ local tagged = span('tagged', "''") local inline = bold + italic + underline + strike + mono + raw + tagged -- Link. -local email = token('email', (nonspace - '@')^1 * '@' * (nonspace - '.')^1 * - ('.' * (nonspace - '.' - '?')^1)^1 * ('?' * nonspace^1)^-1) -local host = token('host', (P('www') + P('WWW') + P('ftp') + P('FTP')) * - (nonspace - '.')^0 * '.' * (nonspace - '.')^1 * '.' * - (nonspace - ',' - '.')^1) -local url = token('url', (nonspace - '://')^1 * '://' * - (nonspace - ',' - '.')^1 * - ('.' * (nonspace - ',' - '.' - '/' - '?' - '#')^1)^1 * - ('/' * (nonspace - '.' - '/' - '?' - '#')^0 * - ('.' * (nonspace - ',' - '.' - '?' - '#')^1)^0)^0 * - ('?' * (nonspace - '#')^1)^-1 * ('#' * nonspace^0)^-1) +local email = token('email', + (nonspace - '@')^1 * '@' * (nonspace - '.')^1 * ('.' * (nonspace - S('.?'))^1)^1 * + ('?' * nonspace^1)^-1) +local host = token('host', + word_match('www ftp', true) * (nonspace - '.')^0 * '.' * (nonspace - '.')^1 * '.' * + (nonspace - S(',.'))^1) +local url = token('url', + (nonspace - '://')^1 * '://' * (nonspace - ',' - '.')^1 * ('.' * (nonspace - S(',./?#'))^1)^1 * + ('/' * (nonspace - S('./?#'))^0 * ('.' * (nonspace - S(',.?#'))^1)^0)^0 * + ('?' * (nonspace - '#')^1)^-1 * ('#' * nonspace^0)^-1) local label_with_address = token('label_start', '[') * lexer.space^0 * token('address_label', ((nonspace - ']')^1 * lexer.space^1)^1) * token('address', (nonspace - ']')^1) * token('label_end', ']') local link = label_with_address + url + host + email -- Line. -local line = token('line', (P('-') + P('=') + P('_'))^20) +local line = token('line', S('-=_')^20) -- Image. -local image_only = token('image_start', '[') * - token('image', (nonspace - ']')^1) * token('image_end', ']') +local image_only = token('image_start', '[') * token('image', (nonspace - ']')^1) * + token('image_end', ']') local image_link = token('image_link_start', '[') * image_only * - token('image_link_sep', lexer.space^1) * - token('image_link', (nonspace - ']')^1) * token('image_link_end', ']') + token('image_link_sep', lexer.space^1) * token('image_link', (nonspace - ']')^1) * + token('image_link_end', ']') local image = image_link + image_only -- Macro. -local macro = token('macro', '%%' * (nonspace - '(')^1 * - lexer.range('(', ')', true)^-1) +local macro = token('macro', '%%' * (nonspace - '(')^1 * lexer.range('(', ')', true)^-1) -- Verbatim. local verbatim_line = lexer.to_eol(lexer.starts_line('```') * S(' \t')) @@ -96,16 +93,15 @@ local tagged_area = token('tagged_area', tagged_block + tagged_line) -- Table. local table_sep = token('table_sep', '|') -local cell_content = inline + link + image + macro + - token('cell_content', lexer.nonnewline - ' |') -local header_cell_content = token('header_cell_content', lexer.nonnewline - - ' |') +local cell_content = inline + link + image + macro + token('cell_content', lexer.nonnewline - ' |') +local header_cell_content = token('header_cell_content', lexer.nonnewline - ' |') local field_sep = ' ' * table_sep^1 * ' ' local table_row_end = P(' ')^0 * table_sep^0 local table_row = lexer.starts_line(P(' ')^0 * table_sep) * cell_content^0 * (field_sep * cell_content^0)^0 * table_row_end -local table_row_header = lexer.starts_line(P(' ')^0 * table_sep * table_sep) * - header_cell_content^0 * (field_sep * header_cell_content^0)^0 * table_row_end +local table_row_header = + lexer.starts_line(P(' ')^0 * table_sep * table_sep) * header_cell_content^0 * + (field_sep * header_cell_content^0)^0 * table_row_end local table = table_row_header + table_row lex:add_rule('table', table) @@ -121,36 +117,31 @@ lex:add_rule('verbatim_area', verbatim_area) lex:add_rule('raw_area', raw_area) lex:add_rule('tagged_area', tagged_area) -local font_size = lexer.property_int['fontsize'] > 0 and - lexer.property_int['fontsize'] or 10 -local hstyle = 'fore:$(color.red)' - -lex:add_style('line', 'bold') -lex:add_style('h5', hstyle .. ',size:' .. (font_size + 1)) -lex:add_style('h4', hstyle .. ',size:' .. (font_size + 2)) -lex:add_style('h3', hstyle .. ',size:' .. (font_size + 3)) -lex:add_style('h2', hstyle .. ',size:' .. (font_size + 4)) -lex:add_style('h1', hstyle .. ',size:' .. (font_size + 5)) -lex:add_style('header_label', lexer.STYLE_LABEL) -lex:add_style('email', 'underlined') -lex:add_style('host', 'underlined') -lex:add_style('url', 'underlined') -lex:add_style('address_label', lexer.STYLE_LABEL) -lex:add_style('address', 'underlined') -lex:add_style('image', 'fore:$(color.green)') -lex:add_style('image_link', 'underlined') -lex:add_style('macro', lexer.STYLE_PREPROCESSOR) -lex:add_style('bold', 'bold') -lex:add_style('italic', 'italics') -lex:add_style('underline', 'underlined') -lex:add_style('strike', 'italics') -- a strike style is not available -lex:add_style('mono', 'font:mono') -lex:add_style('raw', 'back:$(color.grey)') -lex:add_style('tagged', lexer.STYLE_EMBEDDED) -lex:add_style('verbatim_area', 'font:mono') -- in consistency with mono -lex:add_style('raw_area', 'back:$(color.grey)') -- in consistency with raw -lex:add_style('tagged_area', lexer.STYLE_EMBEDDED) -- in consistency with tagged -lex:add_style('table_sep', 'fore:$(color.green)') -lex:add_style('header_cell_content', 'fore:$(color.green)') +lex:add_style('line', {bold = true}) +local font_size = tonumber(lexer.property_expanded['style.default']:match('size:(%d+)')) or 10 +for n = 5, 1, -1 do + lex:add_style('h' .. n, {fore = lexer.colors.red, size = font_size + (6 - n)}) +end +lex:add_style('header_label', lexer.styles.label) +lex:add_style('email', {underlined = true}) +lex:add_style('host', {underlined = true}) +lex:add_style('url', {underlined = true}) +lex:add_style('address_label', lexer.styles.label) +lex:add_style('address', {underlined = true}) +lex:add_style('image', {fore = lexer.colors.green}) +lex:add_style('image_link', {underlined = true}) +lex:add_style('macro', lexer.styles.preprocessor) +lex:add_style('bold', {bold = true}) +lex:add_style('italic', {italics = true}) +lex:add_style('underline', {underlined = true}) +lex:add_style('strike', {italics = true}) -- a strike style is not available +lex:add_style('mono', {font = 'mono'}) +lex:add_style('raw', {back = lexer.colors.grey}) +lex:add_style('tagged', lexer.styles.embedded) +lex:add_style('verbatim_area', {font = 'mono'}) -- in consistency with mono +lex:add_style('raw_area', {back = lexer.colors.grey}) -- in consistency with raw +lex:add_style('tagged_area', lexer.styles.embedded) -- in consistency with tagged +lex:add_style('table_sep', {fore = lexer.colors.green}) +lex:add_style('header_cell_content', {fore = lexer.colors.green}) return lex diff --git a/syntaxhighlight/textadept/typescript.lua b/syntaxhighlight/textadept/typescript.lua new file mode 100644 index 0000000..d104f53 --- /dev/null +++ b/syntaxhighlight/textadept/typescript.lua @@ -0,0 +1,24 @@ +local lpeg = require('lpeg') +-- Copyright 2021 Mitchell. See LICENSE. +-- TypeScript LPeg lexer. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('typescript', {inherit = lexer.load('javascript')}) + +-- Whitespace +lex:modify_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +local keyword = token(lexer.KEYWORD, word_match( + 'abstract as constructor declare is module namespace require type')) +lex:modify_rule('keyword', keyword + lex:get_rule('keyword')) + +-- Types. +local type = token(lexer.TYPE, + word_match('boolean number bigint string unknown any void never symbol object')) +lex:modify_rule('type', type + lex:get_rule('type')) + +return lex diff --git a/syntaxhighlight/textadept/vala.lua b/syntaxhighlight/textadept/vala.lua index dc1ecb7..d3b1f86 100644 --- a/syntaxhighlight/textadept/vala.lua +++ b/syntaxhighlight/textadept/vala.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Vala LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('vala') @@ -12,24 +12,26 @@ local lex = lexer.new('vala') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - class delegate enum errordomain interface namespace signal struct using +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'class', 'delegate', 'enum', 'errordomain', 'interface', 'namespace', 'signal', 'struct', 'using', -- Modifiers. - abstract const dynamic extern inline out override private protected public ref - static virtual volatile weak + 'abstract', 'const', 'dynamic', 'extern', 'inline', 'out', 'override', 'private', 'protected', + 'public', 'ref', 'static', 'virtual', 'volatile', 'weak', -- Other. - as base break case catch construct continue default delete do else ensures - finally for foreach get if in is lock new requires return set sizeof switch - this throw throws try typeof value var void while + 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue', 'default', 'delete', 'do', + 'else', 'ensures', 'finally', 'for', 'foreach', 'get', 'if', 'in', 'is', 'lock', 'new', + 'requires', 'return', 'set', 'sizeof', 'switch', 'this', 'throw', 'throws', 'try', 'typeof', + 'value', 'var', 'void', 'while', -- Etc. - null true false -]])) + 'null', 'true', 'false' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bool char double float int int8 int16 int32 int64 long short size_t ssize_t - string uchar uint uint8 uint16 uint32 uint64 ulong unichar ushort -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16', 'int32', 'int64', 'long', 'short', + 'size_t', 'ssize_t', 'string', 'uchar', 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'ulong', + 'unichar', 'ushort' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -55,6 +57,6 @@ lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}'))) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/vb.lua b/syntaxhighlight/textadept/vb.lua index 58da5b6..7d47f6d 100644 --- a/syntaxhighlight/textadept/vb.lua +++ b/syntaxhighlight/textadept/vb.lua @@ -1,40 +1,38 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- VisualBasic LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S -local lex = lexer.new('vb') +local lex = lexer.new('vb', {case_insensitive_fold_points = true}) -- Whitespace. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match([[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match({ -- Control. - If Then Else ElseIf While Wend For To Each In Step Case Select Return Continue - Do Until Loop Next With Exit + 'If', 'Then', 'Else', 'ElseIf', 'While', 'Wend', 'For', 'To', 'Each', 'In', 'Step', 'Case', + 'Select', 'Return', 'Continue', 'Do', 'Until', 'Loop', 'Next', 'With', 'Exit', -- Operators. - Mod And Not Or Xor Is + 'Mod', 'And', 'Not', 'Or', 'Xor', 'Is', -- Storage types. - Call Class Const Dim ReDim Preserve Function Sub Property End Set Let Get New - Randomize Option Explicit On Error Execute + 'Call', 'Class', 'Const', 'Dim', 'ReDim', 'Preserve', 'Function', 'Sub', 'Property', 'End', 'Set', + 'Let', 'Get', 'New', 'Randomize', 'Option', 'Explicit', 'On', 'Error', 'Execute', 'Module', -- Storage modifiers. - Private Public Default + 'Private', 'Public', 'Default', -- Constants. - Empty False Nothing Null True -]], true))) + 'Empty', 'False', 'Nothing', 'Null', 'True' +}, true))) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match([[ - Boolean Byte Char Date Decimal Double Long Object Short Single String -]], true))) +lex:add_rule('type', token(lexer.TYPE, word_match( + 'Boolean Byte Char Date Decimal Double Long Object Short Single String', true))) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, - lexer.to_eol("'" + word_match([[rem]], true)))) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol("'" + word_match('rem', true)))) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -48,4 +46,19 @@ lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlUuFf')^-2)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('=><+-*^&:.,_()'))) +-- Fold points. +lex:add_fold_point(lexer.KEYWORD, 'If', 'End If') +lex:add_fold_point(lexer.KEYWORD, 'Select', 'End Select') +lex:add_fold_point(lexer.KEYWORD, 'For', 'Next') +lex:add_fold_point(lexer.KEYWORD, 'While', 'End While') +lex:add_fold_point(lexer.KEYWORD, 'While', 'Wend') +lex:add_fold_point(lexer.KEYWORD, 'Do', 'Loop') +lex:add_fold_point(lexer.KEYWORD, 'With', 'End With') +lex:add_fold_point(lexer.KEYWORD, 'Sub', 'End Sub') +lex:add_fold_point(lexer.KEYWORD, 'Function', 'End Function') +lex:add_fold_point(lexer.KEYWORD, 'Property', 'End Property') +lex:add_fold_point(lexer.KEYWORD, 'Module', 'End Module') +lex:add_fold_point(lexer.KEYWORD, 'Class', 'End Class') +lex:add_fold_point(lexer.KEYWORD, 'Try', 'End Try') + return lex diff --git a/syntaxhighlight/textadept/vcard.lua b/syntaxhighlight/textadept/vcard.lua index 1d3bc4d..dcc7ee1 100644 --- a/syntaxhighlight/textadept/vcard.lua +++ b/syntaxhighlight/textadept/vcard.lua @@ -1,97 +1,72 @@ local lpeg = require('lpeg') --- Copyright (c) 2015-2020 Piotr Orzechowski [drzewo.org]. See License.txt. +-- Copyright (c) 2015-2021 Piotr Orzechowski [drzewo.org]. See LICENSE. -- vCard 2.1, 3.0 and 4.0 LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S -local M = {_NAME = 'vcard'} +local lex = lexer.new('vcard') -- Whitespace. -local ws = token(lexer.WHITESPACE, lexer.space^1) +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Begin vCard, end vCard. +lex:add_rule('begin_sequence', token(lexer.KEYWORD, 'BEGIN') * token(lexer.OPERATOR, ':') * + token(lexer.COMMENT, 'VCARD')) +lex:add_rule('end_sequence', token(lexer.KEYWORD, 'END') * token(lexer.OPERATOR, ':') * + token(lexer.COMMENT, 'VCARD')) + +-- vCard version (in v3.0 and v4.0 must appear immediately after BEGIN:VCARD). +lex:add_rule('version_sequence', token(lexer.KEYWORD, 'VERSION') * token(lexer.OPERATOR, ':') * + token(lexer.CONSTANT, lexer.digit^1 * ('.' * lexer.digit^1)^-1)) -- Required properties. local required_property = token(lexer.KEYWORD, word_match({ - 'BEGIN', 'END', 'FN', 'N' --[[ Not required in v4.0. ]], 'VERSION' -}, nil, true)) * #P(':') + 'BEGIN', 'END', 'FN', 'VERSION', -- + 'N' -- Not required in v4.0. +}, true)) * #P(':') +lex:add_rule('required_property', required_property) -- Supported properties. local supported_property = token(lexer.TYPE, word_match({ - 'ADR', 'AGENT' --[[ Not supported in v4.0. ]], - 'ANNIVERSARY' --[[ Supported in v4.0 only. ]], 'BDAY', - 'CALADRURI' --[[ Supported in v4.0 only. ]], - 'CALURI' --[[ Supported in v4.0 only. ]], 'CATEGORIES', - 'CLASS' --[[ Supported in v3.0 only. ]], - 'CLIENTPIDMAP' --[[ Supported in v4.0 only. ]], 'EMAIL', 'END', - 'FBURL' --[[ Supported in v4.0 only. ]], - 'GENDER' --[[ Supported in v4.0 only. ]], 'GEO', - 'IMPP' --[[ Not supported in v2.1. ]], 'KEY', - 'KIND' --[[ Supported in v4.0 only. ]], - 'LABEL' --[[ Not supported in v4.0. ]], - 'LANG' --[[ Supported in v4.0 only. ]], 'LOGO', - 'MAILER' --[[ Not supported in v4.0. ]], - 'MEMBER' --[[ Supported in v4.0 only. ]], - 'NAME' --[[ Supported in v3.0 only. ]], - 'NICKNAME' --[[ Not supported in v2.1. ]], 'NOTE', 'ORG', 'PHOTO', - 'PRODID' --[[ Not supported in v2.1. ]], - 'PROFILE' --[[ Not supported in v4.0. ]], - 'RELATED' --[[ Supported in v4.0 only. ]], 'REV', 'ROLE', - 'SORT-STRING' --[[ Not supported in v4.0. ]], 'SOUND', 'SOURCE', 'TEL', - 'TITLE', 'TZ', 'UID', 'URL', 'XML' --[[ Supported in v4.0 only. ]] -}, nil, true)) * #S(':;') + 'ADR', 'BDAY', 'CATEGORIES', 'EMAIL', 'END', 'GEO', 'KEY', 'LOGO', 'NOTE', 'ORG', 'PHOTO', 'REV', + 'ROLE', 'SOUND', 'SOURCE', 'TEL', 'TITLE', 'TZ', 'UID', 'URL', + -- Supported in v4.0 only. + 'ANNIVERSARY', 'CALADRURI', 'CALURI', 'CLIENTPIDMAP', 'FBURL', 'GENDER', 'KIND', 'LANG', 'MEMBER', + 'RELATED', 'XML', + -- Not supported in v4.0. + 'AGENT', 'LABEL', 'MAILER', 'PROFILE', 'SORT-STRING', + -- Supported in v3.0 only. + 'CLASS', 'NAME', + -- Not supported in v2.1. + 'IMPP', 'NICKNAME', 'PRODID' +}, true)) * #S(':;') +lex:add_rule('supported_property', supported_property) -local identifier = lexer.alpha^1 * lexer.digit^0 * (P('-') * lexer.alnum^1)^0 +-- Group and property. +local identifier = lexer.alpha^1 * lexer.digit^0 * ('-' * lexer.alnum^1)^0 +local property = required_property + supported_property + + lexer.token(lexer.TYPE, S('xX') * '-' * identifier) * #S(':;') +lex:add_rule('group_sequence', token(lexer.CONSTANT, lexer.starts_line(identifier)) * + token(lexer.OPERATOR, '.') * property) -- Extension. -local extension = token(lexer.TYPE, lexer.starts_line(S('xX') * P('-') * - identifier * #S(':;'))) +lex:add_rule('extension', + token(lexer.TYPE, lexer.starts_line(S('xX') * '-' * identifier * #S(':;')))) -- Parameter. -local parameter = token(lexer.IDENTIFIER, - lexer.starts_line(identifier * #S(':='))) + token(lexer.STRING, identifier) * - #S(':=') +local parameter = (token(lexer.IDENTIFIER, lexer.starts_line(identifier)) + + token(lexer.STRING, identifier)) * #S(':=') +lex:add_rule('parameter', parameter) -- Operators. -local operator = token(lexer.OPERATOR, S('.:;=')) - --- Group and property. -local group_sequence = token(lexer.CONSTANT, lexer.starts_line(identifier)) * - token(lexer.OPERATOR, P('.')) * (required_property + supported_property + - lexer.token(lexer.TYPE, S('xX') * P('-') * identifier) * #S(':;')) --- Begin vCard, end vCard. -local begin_sequence = token(lexer.KEYWORD, P('BEGIN')) * - token(lexer.OPERATOR, P(':')) * token(lexer.COMMENT, P('VCARD')) -local end_sequence = token(lexer.KEYWORD, P('END')) * - token(lexer.OPERATOR, P(':')) * token(lexer.COMMENT, P('VCARD')) - --- vCard version (in v3.0 and v4.0 must appear immediately after BEGIN:VCARD). -local version_sequence = token(lexer.KEYWORD, P('VERSION')) * - token(lexer.OPERATOR, P(':')) * - token(lexer.CONSTANT, lexer.digit^1 * (P('.') * lexer.digit^1)^-1) +lex:add_rule('operator', token(lexer.OPERATOR, S('.:;='))) -- Data. -local data = token(lexer.IDENTIFIER, lexer.any) - --- Rules. -M._rules = { - {'whitespace', ws}, - {'begin_sequence', begin_sequence}, - {'end_sequence', end_sequence}, - {'version_sequence', version_sequence}, - {'group_sequence', group_sequence}, - {'required_property', required_property}, - {'supported_property', supported_property}, - {'extension', extension}, - {'parameter', parameter}, - {'operator', operator}, - {'data', data}, -} +lex:add_rule('data', token(lexer.IDENTIFIER, lexer.any)) --- Folding. -M._foldsymbols = { - _patterns = {'BEGIN', 'END'}, - [lexer.KEYWORD] = {['BEGIN'] = 1, ['END'] = -1} -} +-- Fold points. +lex:add_fold_point(lexer.KEYWORD, 'BEGIN', 'END') -return M +return lex diff --git a/syntaxhighlight/textadept/verilog.lua b/syntaxhighlight/textadept/verilog.lua index 3726912..3a0f736 100644 --- a/syntaxhighlight/textadept/verilog.lua +++ b/syntaxhighlight/textadept/verilog.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- Verilog LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('verilog') @@ -12,36 +12,39 @@ local lex = lexer.new('verilog') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - always assign begin case casex casez default deassign disable else end endcase - endfunction endgenerate endmodule endprimitive endspecify endtable endtask for - force forever fork function generate if initial join macromodule module - negedge posedge primitive repeat release specify table task wait while +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'always', 'assign', 'begin', 'case', 'casex', 'casez', 'default', 'deassign', 'disable', 'else', + 'end', 'endcase', 'endfunction', 'endgenerate', 'endmodule', 'endprimitive', 'endspecify', + 'endtable', 'endtask', 'for', 'force', 'forever', 'fork', 'function', 'generate', 'if', 'initial', + 'join', 'macromodule', 'module', 'negedge', 'posedge', 'primitive', 'repeat', 'release', + 'specify', 'table', 'task', 'wait', 'while', -- Compiler directives. - `include `define `undef `ifdef `ifndef `else `endif `timescale `resetall - `signed `unsigned `celldefine `endcelldefine `default_nettype - `unconnected_drive `nounconnected_drive `protect `endprotect `protected - `endprotected `remove_gatename `noremove_gatename `remove_netname - `noremove_netname `expand_vectornets `noexpand_vectornets - `autoexpand_vectornets + '`include', '`define', '`undef', '`ifdef', '`ifndef', '`else', '`endif', '`timescale', + '`resetall', '`signed', '`unsigned', '`celldefine', '`endcelldefine', '`default_nettype', + '`unconnected_drive', '`nounconnected_drive', '`protect', '`endprotect', '`protected', + '`endprotected', '`remove_gatename', '`noremove_gatename', '`remove_netname', '`noremove_netname', + '`expand_vectornets', '`noexpand_vectornets', '`autoexpand_vectornets', -- Signal strengths. - strong0 strong1 pull0 pull1 weak0 weak1 highz0 highz1 small medium large -]])) + 'strong0', 'strong1', 'pull0', 'pull1', 'weak0', 'weak1', 'highz0', 'highz1', 'small', 'medium', + 'large' +})) -- Function. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - $stop $finish $time $stime $realtime $settrace $cleartrace $showscopes - $showvars $monitoron $monitoroff $random $printtimescale $timeformat $display +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + '$stop', '$finish', '$time', '$stime', '$realtime', '$settrace', '$cleartrace', '$showscopes', + '$showvars', '$monitoron', '$monitoroff', '$random', '$printtimescale', '$timeformat', '$display', -- Built-in primitives. - and nand or nor xor xnor buf bufif0 bufif1 not notif0 notif1 nmos pmos cmos - rnmos rpmos rcmos tran tranif0 tranif1 rtran rtranif0 rtranif1 pullup pulldown -]])) + 'and', 'nand', 'or', 'nor', 'xor', 'xnor', 'buf', 'bufif0', 'bufif1', 'not', 'notif0', 'notif1', + 'nmos', 'pmos', 'cmos', 'rnmos', 'rpmos', 'rcmos', 'tran', 'tranif0', 'tranif1', 'rtran', + 'rtranif0', 'rtranif1', 'pullup', 'pulldown' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - integer reg time realtime defparam parameter event wire wand wor tri triand - trior tri0 tri1 trireg vectored scalared input output inout supply0 supply1 -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'integer', 'reg', 'time', 'realtime', 'defparam', 'parameter', 'event', 'wire', 'wand', 'wor', + 'tri', 'triand', 'trior', 'tri0', 'tri1', 'trireg', 'vectored', 'scalared', 'input', 'output', + 'inout', 'supply0', 'supply1' +})) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) @@ -81,6 +84,6 @@ lex:add_fold_point(lexer.KEYWORD, 'begin', 'end') lex:add_fold_point(lexer.OPERATOR, '(', ')') lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) return lex diff --git a/syntaxhighlight/textadept/vhdl.lua b/syntaxhighlight/textadept/vhdl.lua index 2d0f931..6588a65 100644 --- a/syntaxhighlight/textadept/vhdl.lua +++ b/syntaxhighlight/textadept/vhdl.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- VHDL LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('vhdl') @@ -12,46 +12,47 @@ local lex = lexer.new('vhdl') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ - access after alias all architecture array assert attribute begin block body - buffer bus case component configuration constant disconnect downto else elsif - end entity exit file for function generate generic group guarded if impure in - inertial inout is label library linkage literal loop map new next null of on - open others out package port postponed procedure process pure range record - register reject report return select severity signal shared subtype then to - transport type unaffected units until use variable wait when while with - note warning error failure - and nand or nor xor xnor rol ror sla sll sra srl mod rem - abs not false true -]])) +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'access', 'after', 'alias', 'all', 'architecture', 'array', 'assert', 'attribute', 'begin', + 'block', 'body', 'buffer', 'bus', 'case', 'component', 'configuration', 'constant', 'disconnect', + 'downto', 'else', 'elsif', 'end', 'entity', 'exit', 'file', 'for', 'function', 'generate', + 'generic', 'group', 'guarded', 'if', 'impure', 'in', 'inertial', 'inout', 'is', 'label', + 'library', 'linkage', 'literal', 'loop', 'map', 'new', 'next', 'null', 'of', 'on', 'open', + 'others', 'out', 'package', 'port', 'postponed', 'procedure', 'process', 'pure', 'range', + 'record', 'register', 'reject', 'report', 'return', 'select', 'severity', 'signal', 'shared', + 'subtype', 'then', 'to', 'transport', 'type', 'unaffected', 'units', 'until', 'use', 'variable', + 'wait', 'when', 'while', 'with', -- + 'note', 'warning', 'error', 'failure', -- + 'and', 'nand', 'or', 'nor', 'xor', 'xnor', 'rol', 'ror', 'sla', 'sll', 'sra', 'srl', 'mod', 'rem', -- + 'abs', 'not', 'false', 'true' +})) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, word_match[[ - rising_edge shift_left shift_right rotate_left rotate_right resize std_match - to_integer to_unsigned to_signed unsigned signed to_bit to_bitvector - to_stdulogic to_stdlogicvector to_stdulogicvector -]])) +lex:add_rule('function', token(lexer.FUNCTION, word_match{ + 'rising_edge', 'shift_left', 'shift_right', 'rotate_left', 'rotate_right', 'resize', 'std_match', + 'to_integer', 'to_unsigned', 'to_signed', 'unsigned', 'signed', 'to_bit', 'to_bitvector', + 'to_stdulogic', 'to_stdlogicvector', 'to_stdulogicvector' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - bit bit_vector character boolean integer real time string severity_level - positive natural signed unsigned line text std_logic std_logic_vector - std_ulogic std_ulogic_vector qsim_state qsim_state_vector qsim_12state - qsim_12state_vector qsim_strength mux_bit mux_vectory reg_bit reg_vector - wor_bit wor_vector -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'bit', 'bit_vector', 'character', 'boolean', 'integer', 'real', 'time', 'string', + 'severity_level', 'positive', 'natural', 'signed', 'unsigned', 'line', 'text', 'std_logic', + 'std_logic_vector', 'std_ulogic', 'std_ulogic_vector', 'qsim_state', 'qsim_state_vector', + 'qsim_12state', 'qsim_12state_vector', 'qsim_strength', 'mux_bit', 'mux_vectory', 'reg_bit', + 'reg_vector', 'wor_bit', 'wor_vector' +})) -- Constants. -lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ - EVENT BASE LEFT RIGHT LOW HIGH ASCENDING IMAGE VALUE POS VAL SUCC VAL POS PRED - VAL POS LEFTOF RIGHTOF LEFT RIGHT LOW HIGH RANGE REVERSE LENGTH ASCENDING - DELAYED STABLE QUIET TRANSACTION EVENT ACTIVE LAST LAST LAST DRIVING DRIVING - SIMPLE INSTANCE PATH -]])) +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + 'EVENT', 'BASE', 'LEFT', 'RIGHT', 'LOW', 'HIGH', 'ASCENDING', 'IMAGE', 'VALUE', 'POS', 'VAL', + 'SUCC', 'VAL', 'POS', 'PRED', 'VAL', 'POS', 'LEFTOF', 'RIGHTOF', 'LEFT', 'RIGHT', 'LOW', 'HIGH', + 'RANGE', 'REVERSE', 'LENGTH', 'ASCENDING', 'DELAYED', 'STABLE', 'QUIET', 'TRANSACTION', 'EVENT', + 'ACTIVE', 'LAST', 'LAST', 'LAST', 'DRIVING', 'DRIVING', 'SIMPLE', 'INSTANCE', 'PATH' +})) -- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + "'") * - (lexer.alnum + S("_'"))^1)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + "'") * (lexer.alnum + S("_'"))^1)) -- Strings. local sq_str = lexer.range("'", true, false) diff --git a/syntaxhighlight/textadept/wsf.lua b/syntaxhighlight/textadept/wsf.lua index e511c30..9cb8945 100644 --- a/syntaxhighlight/textadept/wsf.lua +++ b/syntaxhighlight/textadept/wsf.lua @@ -1,11 +1,11 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- WSF LPeg lexer (based on XML). -- Contributed by Jeff Stone. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('wsf') @@ -16,14 +16,13 @@ lex:add_rule('whitespace', ws) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, lexer.range(''))) -local alpha = R('az', 'AZ', '\127\255') +-- Elements. +local alpha = lpeg.R('az', 'AZ', '\127\255') local word_char = lexer.alnum + S('_-:.?') local identifier = (alpha + S('_-:.?')) * word_char^0 - --- Elements. local element = token('element', '<' * P('/')^-1 * identifier) lex:add_rule('element', element) -lex:add_style('element', lexer.STYLE_KEYWORD) +lex:add_style('element', lexer.styles.keyword) -- Closing tags. local tag_close = token('element', P('/')^-1 * '>') @@ -32,8 +31,9 @@ lex:add_rule('tag_close', tag_close) -- Attributes. local attribute = token('attribute', identifier) * #(lexer.space^0 * '=') lex:add_rule('attribute', attribute) -lex:add_style('attribute', lexer.STYLE_TYPE) +lex:add_style('attribute', lexer.styles.type) +-- Equals. local in_tag = P(function(input, index) local before = input:sub(1, index - 1) local s, e = before:find('<[^>]-$'), before:find('>[^<]-$') @@ -42,31 +42,25 @@ local in_tag = P(function(input, index) return input:find('^[^<]->', index) and index or nil end) --- Equals. local equals = token(lexer.OPERATOR, '=') * in_tag lex:add_rule('equals', equals) -- Strings. local sq_str = lexer.range("'", false, false) local dq_str = lexer.range('"', false, false) -local string = #S('\'"') * lexer.last_char_includes('=') * - token(lexer.STRING, sq_str + dq_str) +local string = #S('\'"') * lexer.last_char_includes('=') * token(lexer.STRING, sq_str + dq_str) lex:add_rule('string', string) -- Numbers. -lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * - token(lexer.NUMBER, lexer.digit^1 * P('%')^-1) * in_tag) +local number = token(lexer.NUMBER, lexer.dec_num * P('%')^-1) +lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * number * in_tag) -- Entities. -lex:add_rule('entity', token('entity', '&' * word_match[[ - lt gt amp apos quot -]] * ';')) -lex:add_style('entity', lexer.STYLE_OPERATOR) +lex:add_rule('entity', token('entity', '&' * word_match('lt gt amp apos quot') * ';')) +lex:add_style('entity', lexer.styles.operator) -- Fold points. -local function disambiguate_lt(text, pos, line, s) - return not line:find('^', -1) lex:add_fold_point(lexer.COMMENT, '') @@ -74,26 +68,22 @@ lex:add_fold_point(lexer.COMMENT, '') -- Finally, add JavaScript and VBScript as embedded languages -- Tags that start embedded languages. -local embed_start_tag = element * - (ws^1 * attribute * ws^0 * equals * ws^0 * string)^0 * ws^0 * tag_close +local embed_start_tag = element * (ws^1 * attribute * ws^0 * equals * ws^0 * string)^0 * ws^0 * + tag_close local embed_end_tag = element * tag_close -- Embedded JavaScript. local js = lexer.load('javascript') local js_start_rule = #(P('')) * embed_start_tag -- lex:embed(js, js_start_rule, js_end_rule) -- Embedded VBScript. -local vbs = lexer.load('vbscript') +local vbs = lexer.load('vb', 'vbscript') local vbs_start_rule = #(P('')) * embed_start_tag -- lex:embed(vbs, vbs_start_rule, vbs_end_rule) diff --git a/syntaxhighlight/textadept/xml.lua b/syntaxhighlight/textadept/xml.lua index 5f3ada2..7aa93d7 100644 --- a/syntaxhighlight/textadept/xml.lua +++ b/syntaxhighlight/textadept/xml.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- XML LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V +local P, S = lpeg.P, lpeg.S local lex = lexer.new('xml') @@ -15,38 +15,35 @@ lex:add_rule('whitespace', ws) -- Comments and CDATA. lex:add_rule('comment', token(lexer.COMMENT, lexer.range(''))) lex:add_rule('cdata', token('cdata', lexer.range(''))) -lex:add_style('cdata', lexer.STYLE_COMMENT) +lex:add_style('cdata', lexer.styles.comment) -local alpha = R('az', 'AZ', '\127\255') +-- Doctypes and other markup tags. +local alpha = lpeg.R('az', 'AZ', '\127\255') local word_char = lexer.alnum + S('_-:.??') local identifier = (alpha + S('_-:.?')) * word_char^0 - --- Doctypes and other markup tags. -lex:add_rule('doctype', token('doctype', P(''))^0 * - token('doctype', '>')) -lex:add_style('doctype', lexer.STYLE_COMMENT) +local doctype = token('doctype', ''))^0 * token('doctype', '>') +lex:add_rule('doctype', doctype) +lex:add_style('doctype', lexer.styles.comment) -- Processing instructions. -lex:add_rule('proc_insn', token('proc_insn', P(''))^0 * - P('?>')^-1)) -lex:add_style('proc_insn', lexer.STYLE_COMMENT) +lex:add_rule('proc_insn', token('proc_insn', ''))^0 * P('?>')^-1)) +lex:add_style('proc_insn', lexer.styles.comment) -- Elements. local namespace = token(lexer.OPERATOR, ':') * token('namespace', identifier) -lex:add_rule('element', token('element', '<' * P('/')^-1 * identifier) * - namespace^-1) -lex:add_style('element', lexer.STYLE_KEYWORD) -lex:add_style('namespace', lexer.STYLE_CLASS) +lex:add_rule('element', token('element', '<' * P('/')^-1 * identifier) * namespace^-1) +lex:add_style('element', lexer.styles.keyword) +lex:add_style('namespace', lexer.styles.class) -- Closing tags. lex:add_rule('close_tag', token('element', P('/')^-1 * '>')) -- Attributes. -lex:add_rule('attribute', token('attribute', identifier) * namespace^-1 * - #(lexer.space^0 * '=')) -lex:add_style('attribute', lexer.STYLE_TYPE) +lex:add_rule('attribute', token('attribute', identifier) * namespace^-1 * #(lexer.space^0 * '=')) +lex:add_style('attribute', lexer.styles.type) +-- Equals. -- TODO: performance is terrible on large files. local in_tag = P(function(input, index) local before = input:sub(1, index - 1) @@ -56,29 +53,24 @@ local in_tag = P(function(input, index) return input:find('^[^<]->', index) and index or nil end) --- Equals. ---lex:add_rule('equal', token(lexer.OPERATOR, '=')) -- * in_tag +-- lex:add_rule('equal', token(lexer.OPERATOR, '=')) -- * in_tag -- Strings. local sq_str = lexer.range("'", false, false) local dq_str = lexer.range('"', false, false) -lex:add_rule('string', #S('\'"') * lexer.last_char_includes('=') * - token(lexer.STRING, sq_str + dq_str)) +lex:add_rule('string', + #S('\'"') * lexer.last_char_includes('=') * token(lexer.STRING, sq_str + dq_str)) -- Numbers. -lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * - token(lexer.NUMBER, lexer.digit^1 * P('%')^-1))--*in_tag) +local number = token(lexer.NUMBER, lexer.dec_num * P('%')^-1) +lex:add_rule('number', #lexer.digit * lexer.last_char_includes('=') * number) -- *in_tag) -- Entities. -lex:add_rule('entity', token('entity', '&' * word_match[[ - lt gt amp apos quot -]] * ';')) -lex:add_style('entity', lexer.STYLE_OPERATOR) +lex:add_rule('entity', token('entity', '&' * word_match('lt gt amp apos quot') * ';')) +lex:add_style('entity', lexer.styles.operator) -- Fold Points. -local function disambiguate_lt(text, pos, line, s) - return not line:find('^', -1) lex:add_fold_point(lexer.COMMENT, '') diff --git a/syntaxhighlight/textadept/xs.lua b/syntaxhighlight/textadept/xs.lua new file mode 100644 index 0000000..f85a786 --- /dev/null +++ b/syntaxhighlight/textadept/xs.lua @@ -0,0 +1,60 @@ +local lpeg = require('lpeg') +-- Copyright 2017-2021 David B. Lamkins. See LICENSE. +-- xs LPeg lexer. +-- Adapted from rc lexer by Michael Forney. + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('xs') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'access', 'alias', 'catch', 'cd', 'dirs', 'echo', 'else', 'escape', 'eval', 'exec', 'exit', + 'false', 'fn-', 'fn', 'for', 'forever', 'fork', 'history', 'if', 'jobs', 'let', 'limit', 'local', + 'map', 'omap', 'popd', 'printf', 'pushd', 'read', 'result', 'set-', 'switch', 'throw', 'time', + 'true', 'umask', 'until', 'unwind-protect', 'var', 'vars', 'wait', 'whats', 'while', ':lt', ':le', + ':gt', ':ge', ':eq', ':ne', '~', '~~', '...', '.' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local str = lexer.range("'", false, true) +local herestr = '<<<' * str +local heredoc = '<<' * P(function(input, index) + local s, e, _, delimiter = input:find('[ \t]*(["\']?)([%w!"%%+,-./:?@_~]+)%1', index) + if s == index and delimiter then + delimiter = delimiter:gsub('[%%+-.?]', '%%%1') + e = select(2, input:find('[\n\r]' .. delimiter .. '[\n\r]', e)) + return e and e + 1 or #input + 1 + end +end) +lex:add_rule('string', token(lexer.STRING, str + herestr + heredoc)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) + +-- Numbers. +-- lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, '$&' * lexer.word)) + +-- Variables. +lex:add_rule('variable', + token(lexer.VARIABLE, '$' * S('"#')^-1 * ('*' + lexer.digit^1 + lexer.word))) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('@`=!<>*&^|;?()[]{}') + '\\\n')) + +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('#')) + +return lex diff --git a/syntaxhighlight/textadept/xtend.lua b/syntaxhighlight/textadept/xtend.lua index 8e33225..5602e0c 100644 --- a/syntaxhighlight/textadept/xtend.lua +++ b/syntaxhighlight/textadept/xtend.lua @@ -1,10 +1,10 @@ local lpeg = require('lpeg') --- Copyright (c) 2014-2020 Piotr Orzechowski [drzewo.org]. See License.txt. +-- Copyright (c) 2014-2021 Piotr Orzechowski [drzewo.org]. See LICENSE. -- Xtend LPeg lexer. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S = lpeg.P, lpeg.S local lex = lexer.new('xtend') @@ -13,27 +13,27 @@ local ws = token(lexer.WHITESPACE, lexer.space^1) lex:add_rule('whitespace', ws) -- Classes. -lex:add_rule('class', token(lexer.KEYWORD, P('class')) * ws^1 * - token(lexer.CLASS, lexer.word)) +lex:add_rule('class', token(lexer.KEYWORD, 'class') * ws^1 * token(lexer.CLASS, lexer.word)) -- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ -- General. - abstract annotation as case catch class create def default dispatch do else - enum extends extension final finally for if implements import interface - instanceof it new override package private protected public return self static - super switch synchronized this throw throws try typeof val var while + 'abstract', 'annotation', 'as', 'case', 'catch', 'class', 'create', 'def', 'default', 'dispatch', + 'do', 'else', 'enum', 'extends', 'extension', 'final', 'finally', 'for', 'if', 'implements', + 'import', 'interface', 'instanceof', 'it', 'new', 'override', 'package', 'private', 'protected', + 'public', 'return', 'self', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', + 'throws', 'try', 'typeof', 'val', 'var', 'while', -- Templates. - -- AFTER BEFORE ENDFOR ENDIF FOR IF SEPARATOR + 'AFTER', 'BEFORE', 'ENDFOR', 'ENDIF', 'FOR', 'IF', 'SEPARATOR', -- Literals. - true false null -]])) + 'true', 'false', 'null' +})) -- Types. -lex:add_rule('type', token(lexer.TYPE, word_match[[ - boolean byte char double float int long short void - Boolean Byte Character Double Float Integer Long Short String -]])) +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'boolean', 'byte', 'char', 'double', 'float', 'int', 'long', 'short', 'void', 'Boolean', 'Byte', + 'Character', 'Double', 'Float', 'Integer', 'Long', 'Short', 'String' +})) -- Functions. lex:add_rule('function', token(lexer.FUNCTION, lexer.word) * #P('(')) @@ -43,7 +43,7 @@ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Templates. lex:add_rule('template', token('template', lexer.range("'''"))) -lex:add_style('template', lexer.STYLE_EMBEDDED) +lex:add_style('template', lexer.styles.embedded) -- Strings. local sq_str = lexer.range("'", true) @@ -74,7 +74,7 @@ lex:add_rule('number', token(lexer.NUMBER, float + hex + dec)) -- Annotations. lex:add_rule('annotation', token('annotation', '@' * lexer.word)) -lex:add_style('annotation', lexer.STYLE_PREPROCESSOR) +lex:add_style('annotation', lexer.styles.preprocessor) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}#'))) @@ -85,7 +85,7 @@ lex:add_rule('error', token(lexer.ERROR, lexer.any)) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '//', lexer.fold_line_comments('//')) -lex:add_fold_point(lexer.KEYWORD, 'import', lexer.fold_line_comments('import')) +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +lex:add_fold_point(lexer.KEYWORD, lexer.fold_consecutive_lines('import')) return lex diff --git a/syntaxhighlight/textadept/yaml.lua b/syntaxhighlight/textadept/yaml.lua index f4aeabb..5b12262 100644 --- a/syntaxhighlight/textadept/yaml.lua +++ b/syntaxhighlight/textadept/yaml.lua @@ -1,31 +1,35 @@ local lpeg = require('lpeg') --- Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. +-- Copyright 2006-2021 Mitchell. See LICENSE. -- YAML LPeg lexer. -- It does not keep track of indentation perfectly. local lexer = require('syntaxhighlight.textadept.lexer') local token, word_match = lexer.token, lexer.word_match -local P, R, S = lpeg.P, lpeg.R, lpeg.S +local P, S, B = lpeg.P, lpeg.S, lpeg.B -local M = {_NAME = 'yaml'} +local lex = lexer.new('yaml', {fold_by_indentation = true}) -- Whitespace. local indent = #lexer.starts_line(S(' \t')) * (token(lexer.WHITESPACE, ' ') + token('indent_error', '\t'))^1 -local ws = token(lexer.WHITESPACE, S(' \t')^1 + lexer.newline^1) +lex:add_rule('indent', indent) +lex:add_style('indent_error', {back = lexer.colors.red}) +lex:add_rule('whitespace', token(lexer.WHITESPACE, S(' \t')^1 + lexer.newline^1)) --- Comments. -local comment = token(lexer.COMMENT, lexer.to_eol('#')) +-- Keys. +local word = (lexer.alpha + '-' * -lexer.space) * (lexer.alnum + '-')^0 +lex:add_rule('key', token(lexer.KEYWORD, word * (S(' \t_')^1 * word^-1)^0) * #(':' * lexer.space)) + +-- Constants. +lex:add_rule('constant', B(lexer.space) * token(lexer.CONSTANT, word_match('null true false', true))) -- Strings. local sq_str = lexer.range("'") local dq_str = lexer.range('"') -local string = token(lexer.STRING, sq_str + dq_str) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) --- Numbers. -local integer = lexer.dec_num + lexer.hex_num + '0' * S('oO') * R('07')^1 -local special_num = '.' * word_match({'inf', 'nan'}, nil, true) -local number = token(lexer.NUMBER, special_num + lexer.float + integer) +-- Comments. +lex:add_rule('comment', B(lexer.space) * token(lexer.COMMENT, lexer.to_eol('#'))) -- Timestamps. local year = lexer.digit * lexer.digit * lexer.digit * lexer.digit @@ -39,84 +43,43 @@ local fraction = '.' * lexer.digit^0 local time = hours * ':' * minutes * ':' * seconds * fraction^-1 local T = S(' \t')^1 + S('tT') local zone = 'Z' + S(' \t')^0 * S('-+') * hours * (':' * minutes)^-1 -local ts = token('timestamp', date * (T * time * zone^-1)) +lex:add_rule('timestamp', token('timestamp', date * (T * time * zone^-1)^-1)) +lex:add_style('timestamp', lexer.styles.number) --- Constants. -local constant = token(lexer.CONSTANT, word_match({ - 'null', 'true', 'false' -}, nil, true)) +-- Numbers. +local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 +local hex = '0' * S('xX') * ('_' * lexer.xdigit^1)^1 +local bin = '0' * S('bB') * S('01')^1 * ('_' * S('01')^1)^0 +local integer = S('+-')^-1 * (hex + bin + dec) +local float = S('+-')^-1 * + ((dec^-1 * '.' * dec + dec * '.' * dec^-1 * -P('.')) * (S('eE') * S('+-')^-1 * dec)^-1 + + (dec * S('eE') * S('+-')^-1 * dec)) +local special_num = S('+-')^-1 * '.' * word_match('inf nan', true) +lex:add_rule('number', B(lexer.space) * token(lexer.NUMBER, special_num + float + integer)) -- Types. -local type = token(lexer.TYPE, '!!' * word_match({ +lex:add_rule('type', token(lexer.TYPE, '!!' * word_match({ -- Collection types. 'map', 'omap', 'pairs', 'set', 'seq', -- Scalar types. - 'binary', 'bool', 'float', 'int', 'merge', 'null', 'str', 'timestamp', - 'value', 'yaml' -}, nil, true) + '!' * lexer.range('<', '>', true)) + 'binary', 'bool', 'float', 'int', 'merge', 'null', 'str', 'timestamp', 'value', 'yaml' +}, true) + '!' * lexer.range('<', '>', true))) -- Document boundaries. -local doc_bounds = token('document', lexer.starts_line(P('---') + '...')) +lex:add_rule('doc_bounds', token('document', lexer.starts_line(P('---') + '...'))) +lex:add_style('document', lexer.styles.constant) -- Directives -local directive = token('directive', lexer.starts_line('%') * - lexer.nonnewline^1) - -local word = (lexer.alpha + '-' * -lexer.space) * (lexer.alnum + '-')^0 - --- Keys and literals. -local colon = S(' \t')^0 * ':' * (lexer.space + -1) -local key = token(lexer.KEYWORD, #word * (lexer.nonnewline - colon)^1 * #colon * - P(function(input, index) - local line = input:sub(1, index - 1):match('[^\r\n]+$') - return not line:find('[%w-]+:') and index - end)) -local value = #word * (lexer.nonnewline - lexer.space^0 * S(',]}'))^1 -local block = S('|>') * S('+-')^-1 * (lexer.newline + -1) * - function(input, index) - local rest = input:sub(index) - local level = #rest:match('^( *)') - for pos, indent, line in rest:gmatch('() *()([^\r\n]+)') do - if indent - pos < level and line ~= ' ' or level == 0 and pos > 1 then - return index + pos - 1 - end - end - return #input + 1 - end -local literal = token('literal', value + block) +lex:add_rule('directive', token('directive', lexer.starts_line(lexer.to_eol('%')))) +lex:add_style('directive', lexer.styles.preprocessor) -- Indicators. -local anchor = token(lexer.LABEL, '&' * word) +local anchor = B(lexer.space) * token(lexer.LABEL, '&' * word) local alias = token(lexer.VARIABLE, '*' * word) local tag = token('tag', '!' * word * P('!')^-1) local reserved = token(lexer.ERROR, S('@`') * word) -local indicator_chars = token(lexer.OPERATOR, S('-?:,[]{}!')) - -M._rules = { - {'indent', indent}, - {'whitespace', ws}, - {'comment', comment}, - {'doc_bounds', doc_bounds}, - {'key', key}, - {'string', string}, - {'literal', literal}, - {'timestamp', ts}, - {'number', number}, - {'constant', constant}, - {'type', type}, - {'indicator', tag + indicator_chars + alias + anchor + reserved}, - {'directive', directive}, -} - -M._tokenstyles = { - indent_error = 'back:%(color.red)', - document = lexer.STYLE_CONSTANT, - literal = lexer.STYLE_DEFAULT, - timestamp = lexer.STYLE_NUMBER, - tag = lexer.STYLE_CLASS, - directive = lexer.STYLE_PREPROCESSOR, -} - -M._FOLDBYINDENTATION = true +local indicator_chars = token(lexer.OPERATOR, S('-?:,>|[]{}!')) +lex:add_rule('indicator', tag + indicator_chars + alias + anchor + reserved) +lex:add_style('tag', lexer.styles.class) -return M +return lex diff --git a/syntaxhighlight/textadept/zig.lua b/syntaxhighlight/textadept/zig.lua new file mode 100644 index 0000000..8c195cc --- /dev/null +++ b/syntaxhighlight/textadept/zig.lua @@ -0,0 +1,94 @@ +local lpeg = require('lpeg') +-- Copyright 2020-2021 Karchnu karchnu@karchnu.fr. See LICENSE. +-- Zig LPeg lexer. +-- (Based on the C++ LPeg lexer from Mitchell.) + +local lexer = require('syntaxhighlight.textadept.lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('zig') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + -- Keywords. + 'inline', 'pub', 'fn', 'comptime', 'const', 'extern', 'return', 'var', 'usingnamespace', + -- Defering code blocks. + 'defer', 'errdefer', + -- Functions and structures related keywords. + 'align', 'allowzero', 'noalias', 'noinline', 'callconv', 'packed', 'linksection', 'unreachable', + 'test', 'asm', 'volatile', + -- Parallelism and concurrency related keywords. + 'async', 'await', 'noasync', 'suspend', 'nosuspend', 'resume', 'threadlocalanyframe', + -- Control flow: conditions and loops. + 'if', 'else', 'orelse', 'or', 'and', 'while', 'for', 'switch', 'continue', 'break', 'catch', + 'try', + -- Not keyword but overly used variable name with always the same semantic. + 'self' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'enum', 'struct', 'union', -- + 'i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'i128', 'u128', -- + 'isize', 'usize', -- + 'c_short', 'c_ushort', 'c_int', 'c_uint', -- + 'c_long', 'c_ulong', 'c_longlong', 'c_ulonglong', 'c_longdouble', -- + 'c_void', -- + 'f16', 'f32', 'f64', 'f128', -- + 'bool', 'void', 'noreturn', 'type', 'anytype', 'error', 'anyerror', -- + 'comptime_int', 'comptime_float' +})) + +-- Constants. +lex:add_rule('constant', token(lexer.CONSTANT, word_match{ + -- Special values. + 'false', 'true', 'null', 'undefined' +})) + +-- Built-in functions. +lex:add_rule('function', token(lexer.FUNCTION, '@' * word_match{ + 'addWithOverflow', 'alignCast', 'alignOf', 'as', 'asyncCall', 'atomicLoad', 'atomicRmw', + 'atomicStore', 'bitCast', 'bitOffsetOf', 'boolToInt', 'bitSizeOf', 'breakpoint', 'mulAdd', + 'byteSwap', 'bitReverse', 'byteOffsetOf', 'call', 'cDefine', 'cImport', 'cInclude', 'clz', + 'cmpxchgStrong', 'cmpxchgWeak', 'compileError', 'compileLog', 'ctz', 'cUndef', 'divExact', + 'divFloor', 'divTrunc', 'embedFile', 'enumToInt', 'errorName', 'errorReturnTrace', 'errorToInt', + 'errSetCast', 'export', 'fence', 'field', 'fieldParentPtr', 'floatCast', 'floatToInt', 'frame', + 'Frame', 'frameAddress', 'frameSize', 'hasDecl', 'hasField', 'import', 'intCast', 'intToEnum', + 'intToError', 'intToFloat', 'intToPtr', 'memcpy', 'memset', 'wasmMemorySize', 'wasmMemoryGrow', + 'mod', 'mulWithOverflow', 'panic', 'popCount', 'ptrCast', 'ptrToInt', 'rem', 'returnAddress', + 'setAlignStack', 'setCold', 'setEvalBranchQuota', 'setFloatMode', 'setRuntimeSafety', 'shlExact', + 'shlWithOverflow', 'shrExact', 'shuffle', 'sizeOf', 'splat', 'reduce', 'src', 'sqrt', 'sin', + 'cos', 'exp', 'exp2', 'log', 'log2', 'log10', 'fabs', 'floor', 'ceil', 'trunc', 'round', + 'subWithOverflow', 'tagName', 'TagType', 'This', 'truncate', 'Type', 'typeInfo', 'typeName', + 'TypeOf', 'unionInit' +})) + +-- Strings. +local sq_str = P('L')^-1 * lexer.range("'", true) +local dq_str = P('L')^-1 * lexer.range('"', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +lex:add_rule('doc_comment', token('doc_comment', lexer.to_eol('///', true))) +lex:add_style('doc_comment', lexer.styles.comment) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('//', true))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;,.()[]{}'))) + +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, lexer.fold_consecutive_lines('//')) +lex:add_fold_point(lexer.PREPROCESSOR, lexer.fold_consecutive_lines('///')) + +return lex