Add bin and edit workflow
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s

This commit is contained in:
2026-09-16 13:11:16 -06:00
parent c8ac4fcae5
commit 4cee170d66
17576 changed files with 895740 additions and 2 deletions
@@ -0,0 +1,240 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# ABAP elements taken from http://help.sap.com/abapdocu_750/en/index.htm?file=abapdo.htm
module Rouge
module Lexers
class ABAP < RegexLexer
title "ABAP"
desc "SAP - Advanced Business Application Programming"
tag 'abap'
filenames '*.abap'
mimetypes 'text/x-abap'
def self.keywords
@keywords = Set.new %w(
*-INPUT ?TO ABAP-SOURCE ABBREVIATED ABS ABSTRACT ACCEPT ACCEPTING
ACCORDING ACCP ACTIVATION ACTUAL ADD ADD-CORRESPONDING ADJACENT
AFTER ALIAS ALIASES ALIGN ALL ALLOCATE ALPHA ANALYSIS ANALYZER AND
ANY APPEND APPENDAGE APPENDING APPLICATION ARCHIVE AREA ARITHMETIC
AS ASCENDING ASPECT ASSERT ASSIGN ASSIGNED ASSIGNING ASSOCIATION
ASYNCHRONOUS AT ATTRIBUTES AUTHORITY AUTHORITY-CHECK AVG BACK
BACKGROUND BACKUP BACKWARD BADI BASE BEFORE BEGIN BETWEEN BIG BINARY
BINTOHEX BIT BIT-AND BIT-NOT BIT-OR BIT-XOR BLACK BLANK BLANKS BLOB
BLOCK BLOCKS BLUE BOUND BOUNDARIES BOUNDS BOXED BREAK-POINT BT
BUFFER BY BYPASSING BYTE BYTE-CA BYTE-CN BYTE-CO BYTE-CS BYTE-NA
BYTE-NS BYTE-ORDER CA CALL CALLING CASE CAST CASTING CATCH CEIL
CENTER CENTERED CHAIN CHAIN-INPUT CHAIN-REQUEST CHANGE CHANGING
CHANNELS CHAR CHAR-TO-HEX CHARACTER CHECK CHECKBOX CIRCULAR CLASS
CLASS-CODING CLASS-DATA CLASS-EVENTS CLASS-METHODS CLASS-POOL
CLEANUP CLEAR CLIENT CLNT CLOB CLOCK CLOSE CN CO COALESCE CODE
CODING COLLECT COLOR COLUMN COLUMNS COL_BACKGROUND COL_GROUP
COL_HEADING COL_KEY COL_NEGATIVE COL_NORMAL COL_POSITIVE COL_TOTAL
COMMENT COMMENTS COMMIT COMMON COMMUNICATION COMPARING COMPONENT
COMPONENTS COMPRESSION COMPUTE CONCAT CONCATENATE CONCAT_WITH_SPACE
COND CONDENSE CONDITION CONNECT CONNECTION CONSTANTS CONTEXT
CONTEXTS CONTINUE CONTROL CONTROLS CONV CONVERSION CONVERT COPIES
COPY CORRESPONDING COUNT COUNTRY COVER CP CPI CREATE CREATING
CRITICAL CS CUKY CURR CURRENCY CURRENCY_CONVERSION CURRENT CURSOR
CURSOR-SELECTION CUSTOMER CUSTOMER-FUNCTION CX_DYNAMIC_CHECK
CX_NO_CHECK CX_ROOT CX_SQL_EXCEPTION CX_STATIC_CHECK DANGEROUS DATA
DATABASE DATAINFO DATASET DATE DATS DATS_ADD_DAYS DATS_ADD_MONTHS
DATS_DAYS_BETWEEN DATS_IS_VALID DAYLIGHT DD/MM/YY DD/MM/YYYY DDMMYY
DEALLOCATE DEC DECIMALS DECIMAL_SHIFT DECLARATIONS DEEP DEFAULT
DEFERRED DEFINE DEFINING DEFINITION DELETE DELETING DEMAND
DEPARTMENT DESCENDING DESCRIBE DESTINATION DETAIL DF16_DEC DF16_RAW
DF16_SCL DF34_DEC DF34_RAW DF34_SCL DIALOG DIRECTORY DISCONNECT
DISPLAY DISPLAY-MODE DISTANCE DISTINCT DIV DIVIDE
DIVIDE-CORRESPONDING DIVISION DO DUMMY DUPLICATE DUPLICATES DURATION
DURING DYNAMIC DYNPRO E EDIT EDITOR-CALL ELSE ELSEIF EMPTY ENABLED
ENABLING ENCODING END END-ENHANCEMENT-SECTION END-LINES
END-OF-DEFINITION END-OF-FILE END-OF-PAGE END-OF-SELECTION
END-TEST-INJECTION END-TEST-SEAM ENDAT ENDCASE ENDCATCH ENDCHAIN
ENDCLASS ENDDO ENDENHANCEMENT ENDEXEC ENDFORM ENDFUNCTION ENDIAN
ENDIF ENDING ENDINTERFACE ENDLOOP ENDMETHOD ENDMODULE ENDON
ENDPROVIDE ENDSELECT ENDTRY ENDWHILE ENDWITH ENGINEERING ENHANCEMENT
ENHANCEMENT-POINT ENHANCEMENT-SECTION ENHANCEMENTS ENTRIES ENTRY
ENVIRONMENT EQ EQUIV ERRORMESSAGE ERRORS ESCAPE ESCAPING EVENT
EVENTS EXACT EXCEPT EXCEPTION EXCEPTION-TABLE EXCEPTIONS EXCLUDE
EXCLUDING EXEC EXECUTE EXISTS EXIT EXIT-COMMAND EXPAND EXPANDING
EXPIRATION EXPLICIT EXPONENT EXPORT EXPORTING EXTEND EXTENDED
EXTENSION EXTRACT FAIL FETCH FIELD FIELD-GROUPS FIELD-SYMBOL
FIELD-SYMBOLS FIELDS FILE FILTER FILTER-TABLE FILTERS FINAL FIND
FIRST FIRST-LINE FIXED-POINT FKEQ FKGE FLOOR FLTP FLUSH FONT FOR
FORM FORMAT FORWARD FOUND FRAME FRAMES FREE FRIENDS FROM FUNCTION
FUNCTION-POOL FUNCTIONALITY FURTHER GAPS GE GENERATE GET
GET_PRINT_PARAMETERS GIVING GKEQ GKGE GLOBAL GRANT GREEN GROUP
GROUPS GT HANDLE HANDLER HARMLESS HASHED HAVING HDB HEAD-LINES
HEADER HEADERS HEADING HELP-ID HELP-REQUEST HEXTOBIN HIDE HIGH HINT
HOLD HOTSPOT I ICON ID IDENTIFICATION IDENTIFIER IDS IF
IF_ABAP_CLOSE_RESOURCE IF_ABAP_CODEPAGE IF_ABAP_DB_BLOB_HANDLE
IF_ABAP_DB_CLOB_HANDLE IF_ABAP_DB_LOB_HANDLE IF_ABAP_DB_READER
IF_ABAP_DB_WRITER IF_ABAP_READER IF_ABAP_WRITER IF_MESSAGE
IF_OS_CA_INSTANCE IF_OS_CA_PERSISTENCY IF_OS_FACTORY IF_OS_QUERY
IF_OS_QUERY_MANAGER IF_OS_QUERY_OPTIONS IF_OS_STATE
IF_OS_TRANSACTION IF_OS_TRANSACTION_MANAGER IF_SERIALIZABLE_OBJECT
IF_SHM_BUILD_INSTANCE IF_SYSTEM_UUID IF_T100_DYN_MSG IF_T100_MESSAGE
IGNORE IGNORING IMMEDIATELY IMPLEMENTATION IMPLEMENTATIONS
IMPLEMENTED IMPLICIT IMPORT IMPORTING IN INACTIVE INCL INCLUDE
INCLUDES INCLUDING INCREMENT INDEX INDEX-LINE INFOTYPES INHERITING
INIT INITIAL INITIALIZATION INNER INOUT INPUT INSERT INSTANCE
INSTANCES INSTR INT1 INT2 INT4 INT8 INTENSIFIED INTERFACE
INTERFACE-POOL INTERFACES INTERNAL INTERVALS INTO INVERSE
INVERTED-DATE IS ISO ITNO JOB JOIN KEEP KEEPING KERNEL KEY KEYS
KEYWORDS KIND LANG LANGUAGE LAST LATE LAYOUT LCHR LDB_PROCESS LE
LEADING LEAVE LEFT LEFT-JUSTIFIED LEFTPLUS LEFTSPACE LEGACY LENGTH
LET LEVEL LEVELS LIKE LINE LINE-COUNT LINE-SELECTION LINE-SIZE
LINEFEED LINES LIST LIST-PROCESSING LISTBOX LITTLE LLANG LOAD
LOAD-OF-PROGRAM LOB LOCAL LOCALE LOCATOR LOG-POINT LOGFILE LOGICAL
LONG LOOP LOW LOWER LPAD LPI LRAW LT LTRIM M MAIL MAIN MAJOR-ID
MAPPING MARGIN MARK MASK MATCH MATCHCODE MAX MAXIMUM MEDIUM MEMBERS
MEMORY MESH MESSAGE MESSAGE-ID MESSAGES MESSAGING METHOD METHODS MIN
MINIMUM MINOR-ID MM/DD/YY MM/DD/YYYY MMDDYY MOD MODE MODIF MODIFIER
MODIFY MODULE MOVE MOVE-CORRESPONDING MULTIPLY
MULTIPLY-CORRESPONDING NA NAME NAMETAB NATIVE NB NE NESTED NESTING
NEW NEW-LINE NEW-PAGE NEW-SECTION NEXT NO NO-DISPLAY NO-EXTENSION
NO-GAP NO-GAPS NO-GROUPING NO-HEADING NO-SCROLLING NO-SIGN NO-TITLE
NO-TOPOFPAGE NO-ZERO NODE NODES NON-UNICODE NON-UNIQUE NOT NP NS
NULL NUMBER NUMC O OBJECT OBJECTS OBLIGATORY OCCURRENCE OCCURRENCES
OCCURS OF OFF OFFSET ON ONLY OPEN OPTION OPTIONAL OPTIONS OR ORDER
OTHER OTHERS OUT OUTER OUTPUT OUTPUT-LENGTH OVERFLOW OVERLAY PACK
PACKAGE PAD PADDING PAGE PAGES PARAMETER PARAMETER-TABLE PARAMETERS
PART PARTIALLY PATTERN PERCENTAGE PERFORM PERFORMING PERSON PF
PF-STATUS PINK PLACES POOL POSITION POS_HIGH POS_LOW PRAGMAS PREC
PRECOMPILED PREFERRED PRESERVING PRIMARY PRINT PRINT-CONTROL
PRIORITY PRIVATE PROCEDURE PROCESS PROGRAM PROPERTY PROTECTED
PROVIDE PUBLIC PUSH PUSHBUTTON PUT QUAN QUEUE-ONLY QUICKINFO
RADIOBUTTON RAISE RAISING RANGE RANGES RAW RAWSTRING READ READ-ONLY
READER RECEIVE RECEIVED RECEIVER RECEIVING RED REDEFINITION REDUCE
REDUCED REF REFERENCE REFRESH REGEX REJECT REMOTE RENAMING REPLACE
REPLACEMENT REPLACING REPORT REQUEST REQUESTED RESERVE RESET
RESOLUTION RESPECTING RESPONSIBLE RESULT RESULTS RESUMABLE RESUME
RETRY RETURN RETURNCODE RETURNING RETURNS RIGHT RIGHT-JUSTIFIED
RIGHTPLUS RIGHTSPACE RISK RMC_COMMUNICATION_FAILURE
RMC_INVALID_STATUS RMC_SYSTEM_FAILURE ROLE ROLLBACK ROUND ROWS RPAD
RTRIM RUN SAP SAP-SPOOL SAVING SCALE_PRESERVING
SCALE_PRESERVING_SCIENTIFIC SCAN SCIENTIFIC
SCIENTIFIC_WITH_LEADING_ZERO SCREEN SCROLL SCROLL-BOUNDARY SCROLLING
SEARCH SECONDARY SECONDS SECTION SELECT SELECT-OPTIONS SELECTION
SELECTION-SCREEN SELECTION-SET SELECTION-SETS SELECTION-TABLE
SELECTIONS SEND SEPARATE SEPARATED SET SHARED SHIFT SHORT
SHORTDUMP-ID SIGN SIGN_AS_POSTFIX SIMPLE SINGLE SIZE SKIP SKIPPING
SMART SOME SORT SORTABLE SORTED SOURCE SPACE SPECIFIED SPLIT SPOOL
SPOTS SQL SQLSCRIPT SSTRING STABLE STAMP STANDARD START-OF-SELECTION
STARTING STATE STATEMENT STATEMENTS STATIC STATICS STATUSINFO
STEP-LOOP STOP STRING STRUCTURE STRUCTURES STYLE SUBKEY SUBMATCHES
SUBMIT SUBROUTINE SUBSCREEN SUBSTRING SUBTRACT
SUBTRACT-CORRESPONDING SUFFIX SUM SUMMARY SUMMING SUPPLIED SUPPLY
SUPPRESS SWITCH SWITCHSTATES SYMBOL SYNCPOINTS SYNTAX SYNTAX-CHECK
SYNTAX-TRACE SYST SYSTEM-CALL SYSTEM-EXCEPTIONS SYSTEM-EXIT TAB
TABBED TABLE TABLES TABLEVIEW TABSTRIP TARGET TASK TASKS TEST
TEST-INJECTION TEST-SEAM TESTING TEXT TEXTPOOL THEN THROW TIME TIMES
TIMESTAMP TIMEZONE TIMS TIMS_IS_VALID TITLE TITLE-LINES TITLEBAR TO
TOKENIZATION TOKENS TOP-LINES TOP-OF-PAGE TRACE-FILE TRACE-TABLE
TRAILING TRANSACTION TRANSFER TRANSFORMATION TRANSLATE TRANSPORTING
TRMAC TRUNCATE TRUNCATION TRY TSTMP_ADD_SECONDS
TSTMP_CURRENT_UTCTIMESTAMP TSTMP_IS_VALID TSTMP_SECONDS_BETWEEN TYPE
TYPE-POOL TYPE-POOLS TYPES ULINE UNASSIGN UNDER UNICODE UNION UNIQUE
UNIT UNIT_CONVERSION UNIX UNPACK UNTIL UNWIND UP UPDATE UPPER USER
USER-COMMAND USING UTF-8 VALID VALUE VALUE-REQUEST VALUES VARC VARY
VARYING VERIFICATION-MESSAGE VERSION VIA VIEW VISIBLE WAIT WARNING
WHEN WHENEVER WHERE WHILE WIDTH WINDOW WINDOWS WITH WITH-HEADING
WITH-TITLE WITHOUT WORD WORK WRITE WRITER XML XSD YELLOW YES YYMMDD
Z ZERO ZONE
)
end
def self.builtins
@keywords = Set.new %w(
acos apply asin assign atan attribute bit-set boolc boolx call
call-method cast ceil cfunc charlen char_off class_constructor clear
cluster cmax cmin cnt communication_failure concat_lines_of cond
cond-var condense constructor contains contains_any_not_of
contains_any_of copy cos cosh count count_any_not_of count_any_of
create cursor data dbmaxlen dbtab deserialize destructor distance
empty error_message escape exp extensible find find_any_not_of
find_any_of find_end floor frac from_mixed group hashed header idx
include index insert ipow itab key lax lines line_exists line_index
log log10 loop loop_key match matches me mesh_path namespace nmax
nmin node numeric numofchar object parameter primary_key read ref
repeat replace rescale resource_failure reverse root round segment
sender serialize shift_left shift_right sign simple sin sinh skip
sorted space sqrt standard strlen substring substring_after
substring_before substring_from substring_to sum switch switch-var
system_failure table table_line tan tanh template text to_lower
to_mixed to_upper transform translate trunc type value variable write
xsdbool xsequence xstrlen
)
end
def self.types
@types = Set.new %w(
b c d decfloat16 decfloat34 f i int8 n p s t x
clike csequence decfloat string xstring
)
end
def self.new_keywords
@types = Set.new %w(
DATA FIELD-SYMBOL
)
end
state :root do
rule %r/\s+/m, Text
rule %r/".*/, Comment::Single
rule %r(^\*.*), Comment::Multiline
rule %r/\d+/, Num::Integer
rule %r/('|`)/, Str::Single, :single_string
rule %r/[\[\]\(\)\{\}\.,:\|]/, Punctuation
# builtins / new ABAP 7.40 keywords (@DATA(), ...)
rule %r/(->|=>)?([A-Za-z][A-Za-z0-9_\-]*)(\()/ do |m|
if m[1] != ''
token Operator, m[1]
end
if (self.class.new_keywords.include? m[2].upcase) && m[1].nil?
token Keyword, m[2]
elsif (self.class.builtins.include? m[2].downcase) && m[1].nil?
token Name::Builtin, m[2]
else
token Name, m[2]
end
token Punctuation, m[3]
end
# keywords, types and normal text
rule %r/\w\w*/ do |m|
if self.class.keywords.include? m[0].upcase
token Keyword
elsif self.class.types.include? m[0].downcase
token Keyword::Type
else
token Name
end
end
# operators
rule %r((->|->>|=>)), Operator
rule %r([-\*\+%/~=&\?<>!#\@\^]+), Operator
end
state :operators do
rule %r((->|->>|=>)), Operator
rule %r([-\*\+%/~=&\?<>!#\@\^]+), Operator
end
state :single_string do
rule %r/\\./, Str::Escape
rule %r/(''|``)/, Str::Escape
rule %r/['`]/, Str::Single, :pop!
rule %r/[^\\'`]+/, Str::Single
end
end
end
end
@@ -0,0 +1,196 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Actionscript < RegexLexer
title "ActionScript"
desc "ActionScript"
tag 'actionscript'
aliases 'as', 'as3'
filenames '*.as'
mimetypes 'application/x-actionscript'
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
end
state :expr_start do
mixin :comments_and_whitespace
rule %r(/) do
token Str::Regex
goto :regex
end
rule %r/[{]/, Punctuation, :object
rule %r//, Text, :pop!
end
state :regex do
rule %r(/) do
token Str::Regex
goto :regex_end
end
rule %r([^/]\n), Error, :pop!
rule %r/\n/, Error, :pop!
rule %r/\[\^/, Str::Escape, :regex_group
rule %r/\[/, Str::Escape, :regex_group
rule %r/\\./, Str::Escape
rule %r{[(][?][:=<!]}, Str::Escape
rule %r/[{][\d,]+[}]/, Str::Escape
rule %r/[()?]/, Str::Escape
rule %r/./, Str::Regex
end
state :regex_end do
rule %r/[gim]+/, Str::Regex, :pop!
rule(//) { pop! }
end
state :regex_group do
# specially highlight / in a group to indicate that it doesn't
# close the regex
rule %r(/), Str::Escape
rule %r([^/]\n) do
token Error
pop! 2
end
rule %r/\]/, Str::Escape, :pop!
rule %r/\\./, Str::Escape
rule %r/./, Str::Regex
end
state :bad_regex do
rule %r/[^\n]+/, Error, :pop!
end
def self.keywords
@keywords ||= Set.new %w(
for in while do break return continue switch case default
if else throw try catch finally new delete typeof is
this with
)
end
def self.declarations
@declarations ||= Set.new %w(var with function)
end
def self.reserved
@reserved ||= Set.new %w(
dynamic final internal native public protected private class const
override static package interface extends implements namespace
set get import include super flash_proxy object_proxy trace
)
end
def self.constants
@constants ||= Set.new %w(true false null NaN Infinity undefined)
end
def self.builtins
@builtins ||= %w(
void Function Math Class
Object RegExp decodeURI
decodeURIComponent encodeURI encodeURIComponent
eval isFinite isNaN parseFloat parseInt this
)
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
state :root do
rule %r/\A\s*#!.*?\n/m, Comment::Preproc, :statement
rule %r/\n/, Text, :statement
rule %r((?<=\n)(?=\s|/|<!--)), Text, :expr_start
mixin :comments_and_whitespace
rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >>>? | ===
| !== )x,
Operator, :expr_start
rule %r([:-<>+*%&|\^/!=]=?), Operator, :expr_start
rule %r/[(\[,]/, Punctuation, :expr_start
rule %r/;/, Punctuation, :statement
rule %r/[)\].]/, Punctuation
rule %r/[?]/ do
token Punctuation
push :ternary
push :expr_start
end
rule %r/[{}]/, Punctuation, :statement
rule id do |m|
if self.class.keywords.include? m[0]
token Keyword
push :expr_start
elsif self.class.declarations.include? m[0]
token Keyword::Declaration
push :expr_start
elsif self.class.reserved.include? m[0]
token Keyword::Reserved
elsif self.class.constants.include? m[0]
token Keyword::Constant
elsif self.class.builtins.include? m[0]
token Name::Builtin
else
token Name::Other
end
end
rule %r/\-?[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
rule %r/0x[0-9a-fA-F]+/, Num::Hex
rule %r/\-?[0-9]+/, Num::Integer
rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
end
# braced parts that aren't object literals
state :statement do
rule %r/(#{id})(\s*)(:)/ do
groups Name::Label, Text, Punctuation
end
rule %r/[{}]/, Punctuation
mixin :expr_start
end
# object literals
state :object do
mixin :comments_and_whitespace
rule %r/[}]/ do
token Punctuation
goto :statement
end
rule %r/(#{id})(\s*)(:)/ do
groups Name::Attribute, Text, Punctuation
push :expr_start
end
rule %r/:/, Punctuation
mixin :root
end
# ternary expressions, where <id>: is not a label!
state :ternary do
rule %r/:/ do
token Punctuation
goto :expr_start
end
mixin :root
end
end
end
end
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Ada < RegexLexer
tag 'ada'
filenames '*.ada', '*.ads', '*.adb', '*.adc', '*.gpr'
mimetypes 'text/x-ada'
title 'Ada'
desc 'The Ada 2012 programming language'
# Ada identifiers are Unicode with underscores only allowed as separators.
ID = /\b[[:alpha:]](?:\p{Pc}?[[:alnum:]])*\b/
# Numerals can also contain underscores.
NUM = /\d(_?\d)*/
XNUM = /\h(_?\h)*/
EXP = /(E[-+]?#{NUM})?/i
# Return a hash mapping lower-case identifiers to token classes.
def self.idents
@idents ||= Hash.new(Name).tap do |h|
%w(
abort abstract accept access aliased all array at begin body
case constant declare delay delta digits do else elsif end
exception exit for generic goto if in interface is limited
loop new null of others out overriding parallel pragma private
protected raise range record renames requeue return reverse
select separate some synchronized tagged task terminate then
until use when while with
).each {|w| h[w] = Keyword}
%w(abs and mod not or rem xor).each {|w| h[w] = Operator::Word}
%w(
entry function package procedure subtype type
).each {|w| h[w] = Keyword::Declaration}
%w(
boolean character constraint_error duration float integer
natural positive long_float long_integer long_long_float
long_long_integer program_error short_float short_integer
short_short_integer storage_error string tasking_error
wide_character wide_string wide_wide_character
wide_wide_string
).each {|w| h[w] = Name::Builtin}
end
end
state :whitespace do
rule %r{\s+}m, Text
rule %r{--.*$}, Comment::Single
end
state :dquote_string do
rule %r{[^"\n]+}, Literal::String::Double
rule %r{""}, Literal::String::Escape
rule %r{"}, Literal::String::Double, :pop!
rule %r{\n}, Error, :pop!
end
state :attr do
mixin :whitespace
rule ID, Name::Attribute, :pop!
rule %r{}, Text, :pop!
end
# Handle a dotted name immediately following a declaration keyword.
state :decl_name do
mixin :whitespace
rule %r{body\b}i, Keyword::Declaration # package body Foo.Bar is...
rule %r{(#{ID})(\.)} do
groups Name::Namespace, Punctuation
end
# function "<=" (Left, Right: Type) is ...
rule %r{#{ID}|"(and|or|xor|/?=|<=?|>=?|\+|–|&\|/|mod|rem|\*?\*|abs|not)"},
Name::Function, :pop!
rule %r{}, Text, :pop!
end
# Handle a sequence of library unit names: with Ada.Foo, Ada.Bar;
#
# There's a chance we entered this state mistakenly since 'with'
# has multiple other uses in Ada (none of which are likely to
# appear at the beginning of a line). Try to bail as soon as
# possible if we see something suspicious like keywords.
#
# See ada_spec.rb for some examples.
state :libunit_name do
mixin :whitespace
rule ID do |m|
t = self.class.idents[m[0].downcase]
if t <= Name
# Convert all kinds of Name to namespaces in this context.
token Name::Namespace
else
# Yikes, we're not supposed to get a keyword in a library unit name!
# We probably entered this state by mistake, so try to fix it.
token t
if t == Keyword::Declaration
goto :decl_name
else
pop!
end
end
end
rule %r{[.,]}, Punctuation
rule %r{}, Text, :pop!
end
state :root do
mixin :whitespace
# String literals.
rule %r{'.'}, Literal::String::Char
rule %r{"[^"\n]*}, Literal::String::Double, :dquote_string
# Real literals.
rule %r{#{NUM}\.#{NUM}#{EXP}}, Literal::Number::Float
rule %r{#{NUM}##{XNUM}\.#{XNUM}##{EXP}}, Literal::Number::Float
# Integer literals.
rule %r{2#[01](_?[01])*##{EXP}}, Literal::Number::Bin
rule %r{8#[0-7](_?[0-7])*##{EXP}}, Literal::Number::Oct
rule %r{16##{XNUM}*##{EXP}}, Literal::Number::Hex
rule %r{#{NUM}##{XNUM}##{EXP}}, Literal::Number::Integer
rule %r{#{NUM}#\w+#}, Error
rule %r{#{NUM}#{EXP}}, Literal::Number::Integer
# Special constructs.
rule %r{'}, Punctuation, :attr
rule %r{<<#{ID}>>}, Name::Label
# Context clauses are tricky because the 'with' keyword is used
# for many purposes. Detect at beginning of the line only.
rule %r{^(?:(limited)(\s+))?(?:(private)(\s+))?(with)\b}i do
groups Keyword::Namespace, Text, Keyword::Namespace, Text, Keyword::Namespace
push :libunit_name
end
# Operators and punctuation characters.
rule %r{[+*/&<=>|]|-|=>|\.\.|\*\*|[:></]=|<<|>>|<>|@}, Operator
rule %r{[.,:;()\[\]]}, Punctuation
rule ID do |m|
t = self.class.idents[m[0].downcase]
token t
if t == Keyword::Declaration
push :decl_name
end
end
# Flag word-like things that don't match the ID pattern.
rule %r{\b(\p{Pc}|[[:alpha:]])\p{Word}*}, Error
end
end
end
end
@@ -0,0 +1,83 @@
# frozen_string_literal: true
require 'yaml'
module Rouge
module Lexers
class Apache < RegexLexer
title "Apache"
desc 'configuration files for Apache web server'
tag 'apache'
mimetypes 'text/x-httpd-conf', 'text/x-apache-conf'
filenames '.htaccess', 'httpd.conf'
# self-modifying method that loads the keywords file
def self.directives
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
directives
end
def self.sections
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
sections
end
def self.values
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
values
end
def name_for_token(token, tktype)
if self.class.sections.include? token
tktype
elsif self.class.directives.include? token
tktype
elsif self.class.values.include? token
tktype
else
Text
end
end
state :whitespace do
rule %r/\#.*/, Comment
rule %r/\s+/m, Text
end
state :root do
mixin :whitespace
rule %r/(<\/?)(\w+)/ do |m|
groups Punctuation, name_for_token(m[2].downcase, Name::Label)
push :section
end
rule %r/\w+/ do |m|
token name_for_token(m[0].downcase, Name::Class)
push :directive
end
end
state :section do
# Match section arguments
rule %r/([^>]+)?(>(?:\r\n?|\n)?)/ do
groups Literal::String::Regex, Punctuation
pop!
end
mixin :whitespace
end
state :directive do
# Match value literals and other directive arguments
rule %r/\r\n?|\n/, Text, :pop!
mixin :whitespace
rule %r/\S+/ do |m|
token name_for_token(m[0].downcase, Literal::String::Symbol)
end
end
end
end
end
File diff suppressed because one or more lines are too long
@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Apex < RegexLexer
title "Apex"
desc "The Apex programming language (provided by salesforce)"
tag 'apex'
filenames '*.cls'
mimetypes 'text/x-apex'
def self.keywords
@keywords ||= Set.new %w(
assert break case catch continue default do else finally for if goto
instanceof new return switch this throw try while insert update
delete
)
end
def self.declarations
@declarations ||= Set.new %w(
abstract const enum extends final implements native private protected
public static super synchronized throws transient volatile with
sharing without inherited virtual global testmethod
)
end
def self.soql
@soql ||= Set.new %w(
SELECT FROM WHERE UPDATE LIKE TYPEOF END USING SCOPE WITH DATA
CATEGORY GROUP BY ROLLUP CUBE HAVING ORDER BY ASC DESC NULLS FIRST
LAST LIMIT OFFSET FOR VIEW REFERENCE UPDATE TRACKING VIEWSTAT OR AND
)
end
def self.types
@types ||= Set.new %w(
String boolean byte char double float int long short var void
)
end
def self.constants
@constants ||= Set.new %w(true false null)
end
id = /[a-z_][a-z0-9_]*/i
state :root do
rule %r/\s+/m, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
rule %r/(?:class|interface)\b/, Keyword::Declaration, :class
rule %r/import\b/, Keyword::Namespace, :import
rule %r/([@$.]?)(#{id})([:(]?)/io do |m|
lowercased = m[0].downcase
uppercased = m[0].upcase
if self.class.keywords.include? lowercased
token Keyword
elsif self.class.soql.include? uppercased
token Keyword
elsif self.class.declarations.include? lowercased
token Keyword::Declaration
elsif self.class.types.include? lowercased
token Keyword::Type
elsif self.class.constants.include? lowercased
token Keyword::Constant
elsif lowercased == 'package'
token Keyword::Namespace
elsif m[1] == "@"
token Name::Decorator
elsif m[3] == ":"
groups Operator, Name::Label, Punctuation
elsif m[3] == "("
groups Operator, Name::Function, Punctuation
elsif m[1] == "."
groups Operator, Name::Property, Punctuation
else
token Name
end
end
rule %r/"/, Str::Double, :dq
rule %r/'/, Str::Single, :sq
digit = /[0-9]_+[0-9]|[0-9]/
rule %r/#{digit}+\.#{digit}+([eE]#{digit}+)?[fd]?/, Num::Float
rule %r/0b(?:[01]_+[01]|[01])+/i, Num::Bin
rule %r/0x(?:\h_+\h|\h)+/i, Num::Hex
rule %r/0(?:[0-7]_+[0-7]|[0-7])+/, Num::Oct
rule %r/#{digit}+L?/, Num::Integer
rule %r/[-+\/*~^!%&<>|=.?]/, Operator
rule %r/[\[\](){},:;]/, Punctuation;
end
state :class do
rule %r/\s+/m, Text
rule id, Name::Class, :pop!
end
state :import do
rule %r/\s+/m, Text
rule %r/[a-z0-9_.]+\*?/i, Name::Namespace, :pop!
end
state :escape do
rule %r/\\[btnfr\\"']/, Str::Escape
end
state :dq do
mixin :escape
rule %r/[^\\"]+/, Str::Double
rule %r/"/, Str::Double, :pop!
end
state :sq do
mixin :escape
rule %r/[^\\']+/, Str::Double
rule %r/'/, Str::Double, :pop!
end
end
end
end
@@ -0,0 +1,49 @@
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'markdown.rb'
class APIBlueprint < Markdown
title 'API Blueprint'
desc 'Markdown based API description language.'
tag 'apiblueprint'
aliases 'apiblueprint', 'apib'
filenames '*.apib'
mimetypes 'text/vnd.apiblueprint'
prepend :root do
# Metadata
rule(/(\S+)(:\s*)(.*)$/) do
groups Name::Variable, Punctuation, Literal::String
end
# Resource Group
rule(/^(#+)(\s*Group\s+)(.*)$/) do
groups Punctuation, Keyword, Generic::Heading
end
# Resource \ Action
rule(/^(#+)(.*)(\[.*\])$/) do
groups Punctuation, Generic::Heading, Literal::String
end
# Relation
rule(/^([\+\-\*])(\s*Relation:)(\s*.*)$/) do
groups Punctuation, Keyword, Literal::String
end
# MSON
rule(/^(\s+[\+\-\*]\s*)(Attributes|Parameters)(.*)$/) do
groups Punctuation, Keyword, Literal::String
end
# Request/Response
rule(/^([\+\-\*]\s*)(Request|Response)(\s+\d\d\d)?(.*)$/) do
groups Punctuation, Keyword, Literal::Number, Literal::String
end
end
end
end
end
@@ -0,0 +1,370 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class AppleScript < RegexLexer
title "AppleScript"
desc "The AppleScript scripting language by Apple Inc. (https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html)"
tag 'applescript'
aliases 'applescript'
filenames '*.applescript', '*.scpt'
mimetypes 'application/x-applescript'
def self.literals
@literals ||= ['AppleScript', 'current application', 'false', 'linefeed',
'missing value', 'pi','quote', 'result', 'return', 'space',
'tab', 'text item delimiters', 'true', 'version']
end
def self.classes
@classes ||= ['alias ', 'application ', 'boolean ', 'class ', 'constant ',
'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
'real ', 'record ', 'reference ', 'RGB color ', 'script ',
'text ', 'unit types', '(?:Unicode )?text', 'string']
end
def self.builtins
@builtins ||= ['attachment', 'attribute run', 'character', 'day', 'month',
'paragraph', 'word', 'year']
end
def self.handler_params
@handler_params ||= ['about', 'above', 'against', 'apart from', 'around',
'aside from', 'at', 'below', 'beneath', 'beside',
'between', 'for', 'given', 'instead of', 'on', 'onto',
'out of', 'over', 'since']
end
def self.commands
@commands ||= ['ASCII (character|number)', 'activate', 'beep', 'choose URL',
'choose application', 'choose color', 'choose file( name)?',
'choose folder', 'choose from list',
'choose remote application', 'clipboard info',
'close( access)?', 'copy', 'count', 'current date', 'delay',
'delete', 'display (alert|dialog)', 'do shell script',
'duplicate', 'exists', 'get eof', 'get volume settings',
'info for', 'launch', 'list (disks|folder)', 'load script',
'log', 'make', 'mount volume', 'new', 'offset',
'open( (for access|location))?', 'path to', 'print', 'quit',
'random number', 'read', 'round', 'run( script)?',
'say', 'scripting components',
'set (eof|the clipboard to|volume)', 'store script',
'summarize', 'system attribute', 'system info',
'the clipboard', 'time to GMT', 'write', 'quoted form']
end
def self.references
@references ||= ['(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
'before', 'behind', 'every', 'front', 'index', 'last',
'middle', 'some', 'that', 'through', 'thru', 'where', 'whose']
end
def self.operators
@operators ||= ["and", "or", "is equal", "equals", "(is )?equal to", "is not",
"isn't", "isn't equal( to)?", "is not equal( to)?",
"doesn't equal", "does not equal", "(is )?greater than",
"comes after", "is not less than or equal( to)?",
"isn't less than or equal( to)?", "(is )?less than",
"comes before", "is not greater than or equal( to)?",
"isn't greater than or equal( to)?",
"(is )?greater than or equal( to)?", "is not less than",
"isn't less than", "does not come before",
"doesn't come before", "(is )?less than or equal( to)?",
"is not greater than", "isn't greater than",
"does not come after", "doesn't come after", "starts? with",
"begins? with", "ends? with", "contains?", "does not contain",
"doesn't contain", "is in", "is contained by", "is not in",
"is not contained by", "isn't contained by", "div", "mod",
"not", "(a )?(ref( to)?|reference to)", "is", "does"]
end
def self.controls
@controls ||= ['considering', 'else', 'error', 'exit', 'from', 'if',
'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
'try', 'until', 'using terms from', 'while', 'whith',
'with timeout( of)?', 'with transaction', 'by', 'continue',
'end', 'its?', 'me', 'my', 'return', 'of' , 'as']
end
def self.declarations
@declarations ||= ['global', 'local', 'prop(erty)?', 'set', 'get']
end
def self.reserved
@reserved ||= ['but', 'put', 'returning', 'the']
end
def self.studio_classes
@studio_classes ||= ['action cell', 'alert reply', 'application', 'box',
'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
'clip view', 'color well', 'color-panel',
'combo box( item)?', 'control',
'data( (cell|column|item|row|source))?', 'default entry',
'dialog reply', 'document', 'drag info', 'drawer',
'event', 'font(-panel)?', 'formatter',
'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
'movie( view)?', 'open-panel', 'outline view', 'panel',
'pasteboard', 'plugin', 'popup button',
'progress indicator', 'responder', 'save-panel',
'scroll view', 'secure text field( cell)?', 'slider',
'sound', 'split view', 'stepper', 'tab view( item)?',
'table( (column|header cell|header view|view))',
'text( (field( cell)?|view))?', 'toolbar( item)?',
'user-defaults', 'view', 'window']
end
def self.studio_events
@studio_events ||= ['accept outline drop', 'accept table drop', 'action',
'activated', 'alert ended', 'awake from nib', 'became key',
'became main', 'begin editing', 'bounds changed',
'cell value', 'cell value changed', 'change cell value',
'change item value', 'changed', 'child of item',
'choose menu item', 'clicked', 'clicked toolbar item',
'closed', 'column clicked', 'column moved',
'column resized', 'conclude drop', 'data representation',
'deminiaturized', 'dialog ended', 'document nib name',
'double clicked', 'drag( (entered|exited|updated))?',
'drop', 'end editing', 'exposed', 'idle', 'item expandable',
'item value', 'item value changed', 'items changed',
'keyboard down', 'keyboard up', 'launched',
'load data representation', 'miniaturized', 'mouse down',
'mouse dragged', 'mouse entered', 'mouse exited',
'mouse moved', 'mouse up', 'moved',
'number of browser rows', 'number of items',
'number of rows', 'open untitled', 'opened', 'panel ended',
'parameters updated', 'plugin loaded', 'prepare drop',
'prepare outline drag', 'prepare outline drop',
'prepare table drag', 'prepare table drop',
'read from file', 'resigned active', 'resigned key',
'resigned main', 'resized( sub views)?',
'right mouse down', 'right mouse dragged',
'right mouse up', 'rows changed', 'scroll wheel',
'selected tab view item', 'selection changed',
'selection changing', 'should begin editing',
'should close', 'should collapse item',
'should end editing', 'should expand item',
'should open( untitled)?',
'should quit( after last window closed)?',
'should select column', 'should select item',
'should select row', 'should select tab view item',
'should selection change', 'should zoom', 'shown',
'update menu item', 'update parameters',
'update toolbar item', 'was hidden', 'was miniaturized',
'will become active', 'will close', 'will dismiss',
'will display browser cell', 'will display cell',
'will display item cell', 'will display outline cell',
'will finish launching', 'will hide', 'will miniaturize',
'will move', 'will open', 'will pop up', 'will quit',
'will resign active', 'will resize( sub views)?',
'will select tab view item', 'will show', 'will zoom',
'write to file', 'zoomed']
end
def self.studio_commands
@studio_commands ||= ['animate', 'append', 'call method', 'center',
'close drawer', 'close panel', 'display',
'display alert', 'display dialog', 'display panel', 'go',
'hide', 'highlight', 'increment', 'item for',
'load image', 'load movie', 'load nib', 'load panel',
'load sound', 'localized string', 'lock focus', 'log',
'open drawer', 'path for', 'pause', 'perform action',
'play', 'register', 'resume', 'scroll', 'select( all)?',
'show', 'size to fit', 'start', 'step back',
'step forward', 'stop', 'synchronize', 'unlock focus',
'update']
end
def self.studio_properties
@studio_properties ||= ['accepts arrow key', 'action method', 'active',
'alignment', 'allowed identifiers',
'allows branch selection', 'allows column reordering',
'allows column resizing', 'allows column selection',
'allows customization', 'allows editing text attributes',
'allows empty selection', 'allows mixed state',
'allows multiple selection', 'allows reordering',
'allows undo', 'alpha( value)?', 'alternate image',
'alternate increment value', 'alternate title',
'animation delay', 'associated file name',
'associated object', 'auto completes', 'auto display',
'auto enables items', 'auto repeat', 'auto resizes( outline column)?',
'auto save expanded items', 'auto save name',
'auto save table columns', 'auto saves configuration',
'auto scroll', 'auto sizes all columns to fit',
'auto sizes cells', 'background color', 'bezel state',
'bezel style', 'bezeled', 'border rect', 'border type',
'bordered', 'bounds( rotation)?', 'box type',
'button returned', 'button type',
'can choose directories', 'can choose files', 'can draw', 'can hide',
'cell( (background color|size|type))?', 'characters',
'class', 'click count', 'clicked( data)? column',
'clicked data item', 'clicked( data)? row',
'closeable', 'collating', 'color( (mode|panel))',
'command key down', 'configuration',
'content(s| (size|view( margins)?))?', 'context',
'continuous', 'control key down', 'control size',
'control tint', 'control view',
'controller visible', 'coordinate system',
'copies( on scroll)?', 'corner view', 'current cell',
'current column', 'current( field)? editor',
'current( menu)? item', 'current row',
'current tab view item', 'data source',
'default identifiers', 'delta (x|y|z)',
'destination window', 'directory', 'display mode',
'displayed cell', 'document( (edited|rect|view))?',
'double value', 'dragged column', 'dragged distance',
'dragged items', 'draws( cell)? background',
'draws grid', 'dynamically scrolls', 'echos bullets',
'edge', 'editable', 'edited( data)? column',
'edited data item', 'edited( data)? row', 'enabled',
'enclosing scroll view', 'ending page',
'error handling', 'event number', 'event type',
'excluded from windows menu', 'executable path',
'expanded', 'fax number', 'field editor', 'file kind',
'file name', 'file type', 'first responder',
'first visible column', 'flipped', 'floating',
'font( panel)?', 'formatter', 'frameworks path',
'frontmost', 'gave up', 'grid color', 'has data items',
'has horizontal ruler', 'has horizontal scroller',
'has parent data item', 'has resize indicator',
'has shadow', 'has sub menu', 'has vertical ruler',
'has vertical scroller', 'header cell', 'header view',
'hidden', 'hides when deactivated', 'highlights by',
'horizontal line scroll', 'horizontal page scroll',
'horizontal ruler view', 'horizontally resizable',
'icon image', 'id', 'identifier',
'ignores multiple clicks',
'image( (alignment|dims when disabled|frame style|scaling))?',
'imports graphics', 'increment value',
'indentation per level', 'indeterminate', 'index',
'integer value', 'intercell spacing', 'item height',
'key( (code|equivalent( modifier)?|window))?',
'knob thickness', 'label', 'last( visible)? column',
'leading offset', 'leaf', 'level', 'line scroll',
'loaded', 'localized sort', 'location', 'loop mode',
'main( (bunde|menu|window))?', 'marker follows cell',
'matrix mode', 'maximum( content)? size',
'maximum visible columns',
'menu( form representation)?', 'miniaturizable',
'miniaturized', 'minimized image', 'minimized title',
'minimum column width', 'minimum( content)? size',
'modal', 'modified', 'mouse down state',
'movie( (controller|file|rect))?', 'muted', 'name',
'needs display', 'next state', 'next text',
'number of tick marks', 'only tick mark values',
'opaque', 'open panel', 'option key down',
'outline table column', 'page scroll', 'pages across',
'pages down', 'palette label', 'pane splitter',
'parent data item', 'parent window', 'pasteboard',
'path( (names|separator))?', 'playing',
'plays every frame', 'plays selection only', 'position',
'preferred edge', 'preferred type', 'pressure',
'previous text', 'prompt', 'properties',
'prototype cell', 'pulls down', 'rate',
'released when closed', 'repeated',
'requested print time', 'required file type',
'resizable', 'resized column', 'resource path',
'returns records', 'reuses columns', 'rich text',
'roll over', 'row height', 'rulers visible',
'save panel', 'scripts path', 'scrollable',
'selectable( identifiers)?', 'selected cell',
'selected( data)? columns?', 'selected data items?',
'selected( data)? rows?', 'selected item identifier',
'selection by rect', 'send action on arrow key',
'sends action when done editing', 'separates columns',
'separator item', 'sequence number', 'services menu',
'shared frameworks path', 'shared support path',
'sheet', 'shift key down', 'shows alpha',
'shows state by', 'size( mode)?',
'smart insert delete enabled', 'sort case sensitivity',
'sort column', 'sort order', 'sort type',
'sorted( data rows)?', 'sound', 'source( mask)?',
'spell checking enabled', 'starting page', 'state',
'string value', 'sub menu', 'super menu', 'super view',
'tab key traverses cells', 'tab state', 'tab type',
'tab view', 'table view', 'tag', 'target( printer)?',
'text color', 'text container insert',
'text container origin', 'text returned',
'tick mark position', 'time stamp',
'title(d| (cell|font|height|position|rect))?',
'tool tip', 'toolbar', 'trailing offset', 'transparent',
'treat packages as directories', 'truncated labels',
'types', 'unmodified characters', 'update views',
'use sort indicator', 'user defaults',
'uses data source', 'uses ruler', 'uses threaded animation',
'uses title from previous column', 'value wraps', 'version',
'vertical( (line scroll|page scroll|ruler view))?', 'vertically resizable', 'view',
'visible( document rect)?', 'volume', 'width', 'window',
'windows menu', 'wraps', 'zoomable', 'zoomed']
end
operators = %r(\b(#{self.operators.to_a.join('|')})\b)
classes = %r(\b(as )(#{self.classes.to_a.join('|')})\b)
literals = %r(\b(#{self.literals.to_a.join('|')})\b)
commands = %r(\b(#{self.commands.to_a.join('|')})\b)
controls = %r(\b(#{self.controls.to_a.join('|')})\b)
declarations = %r(\b(#{self.declarations.to_a.join('|')})\b)
reserved = %r(\b(#{self.reserved.to_a.join('|')})\b)
builtins = %r(\b(#{self.builtins.to_a.join('|')})s?\b)
handler_params = %r(\b(#{self.handler_params.to_a.join('|')})\b)
references = %r(\b(#{self.references.to_a.join('|')})\b)
studio_properties = %r(\b(#{self.studio_properties.to_a.join('|')})\b)
studio_classes = %r(\b(#{self.studio_classes.to_a.join('|')})s?\b)
studio_commands = %r(\b(#{self.studio_commands.to_a.join('|')})\b)
identifiers = %r(\b([a-zA-Z]\w*)\b)
state :root do
rule %r/\s+/, Text::Whitespace
rule %r/¬\n/, Literal::String::Escape
rule %r/'s\s+/, Text
rule %r/(--|#).*?$/, Comment::Single
rule %r/\(\*/, Comment::Multiline
rule %r/[\(\){}!,.:]/, Punctuation
rule %r/(«)([^»]+)(»)/ do |match|
token Text, match[1]
token Name::Builtin, match[2]
token Text, match[3]
end
rule %r/\b((?:considering|ignoring)\s*)(application responses|case|diacriticals|hyphens|numeric strings|punctuation|white space)/ do |match|
token Keyword, match[1]
token Name::Builtin, match[2]
end
rule %r/(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|\/|÷|\^)/, Operator
rule operators, Operator::Word
rule %r/^(\s*(?:on|end)\s+)'r'(%s)/ do |match|
token Keyword, match[1]
token Name::Function, match[2]
end
rule %r/^(\s*)(in|on|script|to)(\s+)/ do |match|
token Text, match[1]
token Keyword, match[2]
token Text, match[3]
end
rule classes do |match|
token Keyword, match[1]
token Name::Class, match[2]
end
rule literals, Name::Builtin
rule commands, Name::Builtin
rule controls, Keyword
rule declarations, Keyword
rule reserved, Name::Builtin
rule builtins, Name::Builtin
rule handler_params, Name::Builtin
rule studio_properties, Name::Attribute
rule studio_classes, Name::Builtin
rule studio_commands, Name::Builtin
rule references, Name::Builtin
rule %r/"(\\\\|\\"|[^"])*"/, Literal::String::Double
rule identifiers, Name::Variable
rule %r/[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?/, Literal::Number::Float
rule %r/[-+]?\d+/, Literal::Number::Integer
end
end
end
end
@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class ArmAsm < RegexLexer
title "ArmAsm"
desc "Arm assembly syntax"
tag 'armasm'
filenames '*.s'
def self.preproc_keyword
@preproc_keyword ||= %w(
define elif else endif error if ifdef ifndef include line pragma undef warning
)
end
def self.file_directive
@file_directive ||= %w(
BIN GET INCBIN INCLUDE LNK
)
end
def self.general_directive
@general_directive ||= %w(
ALIAS ALIGN AOF AOUT AREA ARM ASSERT ATTR CN CODE16 CODE32 COMMON CP
DATA DCB DCD DCDO DCDU DCFD DCFDU DCFH DCFHU DCFS DCFSU DCI DCI.N DCI.W
DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT
EXPORTAS EXTERN FIELD FILL FN FRAME FUNCTION GBLA GBLL GBLS GLOBAL IF
IMPORT INFO KEEP LCLA LCLL LCLS LEADR LEAF LTORG MACRO MAP MEND MEXIT
NOFP OPT ORG PRESERVE8 PROC QN RELOC REQUIRE REQUIRE8 RLIST RN ROUT
SETA SETL SETS SN SPACE STRONG SUBT THUMB THUMBX TTL WEND WHILE
\[ \] [|!#*=%&^]
)
end
def self.shift_or_condition
@shift_or_condition ||= %w(
ASR LSL LSR ROR RRX AL CC CS EQ GE GT HI HS LE LO LS LT MI NE PL VC VS
asr lsl lsr ror rrx al cc cs eq ge gt hi hs le lo ls lt mi ne pl vc vs
)
end
def self.builtin
@builtin ||= %w(
ARCHITECTURE AREANAME ARMASM_VERSION CODESIZE COMMANDLINE CONFIG CPU
ENDIAN FALSE FPIC FPU INPUTFILE INTER LINENUM LINENUMUP LINENUMUPPER
OBJASM_VERSION OPT PC PCSTOREOFFSET REENTRANT ROPI RWPI TRUE VAR
)
end
def self.operator
@operator ||= %w(
AND BASE CC CC_ENCODING CHR DEF EOR FATTR FEXEC FLOAD FSIZE INDEX LAND
LEFT LEN LEOR LNOT LOR LOWERCASE MOD NOT OR RCONST REVERSE_CC RIGHT ROL
ROR SHL SHR STR TARGET_ARCH_[0-9A-Z_]+ TARGET_FEATURE_[0-9A-Z_]+
TARGET_FPU_[A-Z_] TARGET_PROFILE_[ARM] UAL UPPERCASE
)
end
state :root do
rule %r/\n/, Text
rule %r/^([ \t]*)(#[ \t]*(?:(?:#{ArmAsm.preproc_keyword.join('|')})(?:[ \t].*)?)?)(\n)/ do
groups Text, Comment::Preproc, Text
end
rule %r/[ \t]+/, Text, :command
rule %r/;.*/, Comment
rule %r/\$[a-z_]\w*\.?/i, Name::Namespace # variable substitution or macro argument
rule %r/\w+|\|[^|\n]+\|/, Name::Label
end
state :command do
rule %r/\n/, Text, :pop!
rule %r/[ \t]+/ do |m|
token Text
goto :args
end
rule %r/;.*/, Comment, :pop!
rule %r/(?:#{ArmAsm.file_directive.join('|')})\b/ do |m|
token Keyword
goto :filespec
end
rule %r/(?:#{ArmAsm.general_directive.join('|')})(?=[; \t\n])/, Keyword
rule %r/(?:[A-Z][\dA-Z]*|[a-z][\da-z]*)(?:\.[NWnw])?(?:\.[DFIPSUdfipsu]?(?:8|16|32|64)?){,3}\b/, Name::Builtin # rather than attempt to list all opcodes, rely on all-uppercase or all-lowercase rule
rule %r/[a-z_]\w*|\|[^|\n]+\|/i, Name::Function # probably a macro name
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
end
state :args do
rule %r/\n/, Text, :pop!
rule %r/[ \t]+/, Text
rule %r/;.*/, Comment, :pop!
rule %r/(?:#{ArmAsm.shift_or_condition.join('|')})\b/, Name::Builtin
rule %r/[a-z_]\w*|\|[^|\n]+\|/i, Name::Variable # various types of symbol
rule %r/%[bf]?[at]?\d+(?:[a-z_]\w*)?/i, Name::Label
rule %r/(?:&|0x)\h+(?!p)/i, Literal::Number::Hex
rule %r/(?:&|0x)[.\h]+(?:p[-+]?\d+)?/i, Literal::Number::Float
rule %r/0f_\h{8}|0d_\h{16}/i, Literal::Number::Float
rule %r/(?:2_[01]+|3_[0-2]+|4_[0-3]+|5_[0-4]+|6_[0-5]+|7_[0-6]+|8_[0-7]+|9_[0-8]+|\d+)(?!e)/i, Literal::Number::Integer
rule %r/(?:2_[.01]+|3_[.0-2]+|4_[.0-3]+|5_[.0-4]+|6_[.0-5]+|7_[.0-6]+|8_[.0-7]+|9_[.0-8]+|[.\d]+)(?:e[-+]?\d+)?/i, Literal::Number::Float
rule %r/[@:](?=[ \t]*(?:8|16|32|64|128|256)[^\d])/, Operator
rule %r/[.@]|\{(?:#{ArmAsm.builtin.join('|')})\}/, Name::Constant
rule %r/[-!#%&()*+,\/<=>?^{|}]|\[|\]|!=|&&|\/=|<<|<=|<>|==|><|>=|>>|\|\||:(?:#{ArmAsm.operator.join('|')}):/, Operator
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
rule %r/'/ do |m|
token Literal::String::Char
goto :singlequoted
end
rule %r/"/ do |m|
token Literal::String::Double
goto :doublequoted
end
end
state :singlequoted do
rule %r/\n/, Text, :pop!
rule %r/\$\$/, Literal::String::Char
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
rule %r/'/ do |m|
token Literal::String::Char
goto :args
end
rule %r/[^$'\n]+/, Literal::String::Char
end
state :doublequoted do
rule %r/\n/, Text, :pop!
rule %r/\$\$/, Literal::String::Double
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
rule %r/"/ do |m|
token Literal::String::Double
goto :args
end
rule %r/[^$"\n]+/, Literal::String::Double
end
state :filespec do
rule %r/\n/, Text, :pop!
rule %r/\$\$/, Literal::String::Other
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
rule %r/[^$\n]+/, Literal::String::Other
end
end
end
end
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Augeas < RegexLexer
title "Augeas"
desc "The Augeas programming language (augeas.net)"
tag 'augeas'
aliases 'aug'
filenames '*.aug'
mimetypes 'text/x-augeas'
def self.reserved
@reserved ||= Set.new %w(
_ let del store value counter seq key label autoload incl excl
transform test get put in after set clear insa insb print_string
print_regexp print_endline print_tree lens_ctype lens_atype
lens_ktype lens_vtype lens_format_atype regexp_match
)
end
state :basic do
rule %r/\s+/m, Text
rule %r/\(\*/, Comment::Multiline, :comment
end
state :comment do
rule %r/\*\)/, Comment::Multiline, :pop!
rule %r/\(\*/, Comment::Multiline, :comment
rule %r/[^*)]+/, Comment::Multiline
rule %r/[*)]/, Comment::Multiline
end
state :root do
mixin :basic
rule %r/(:)(\w\w*)/ do
groups Punctuation, Keyword::Type
end
rule %r/\w[\w']*/ do |m|
name = m[0]
if name == "module"
token Keyword::Reserved
push :module
elsif self.class.reserved.include? name
token Keyword::Reserved
elsif name =~ /\A[A-Z]/
token Keyword::Namespace
else
token Name
end
end
rule %r/"/, Str, :string
rule %r/\//, Str, :regexp
rule %r([-*+.=?\|]+), Operator
rule %r/[\[\](){}:;]/, Punctuation
end
state :module do
rule %r/\s+/, Text
rule %r/[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
end
state :regexp do
rule %r/\//, Str::Regex, :pop!
rule %r/[^\\\/]+/, Str::Regex
rule %r/\\[\\\/]/, Str::Regex
rule %r/\\/, Str::Regex
end
state :string do
rule %r/"/, Str, :pop!
rule %r/\\/, Str::Escape, :escape
rule %r/[^\\"]+/, Str
end
state :escape do
rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
rule %r/o[0-7]+/i, Str::Escape, :pop!
rule %r/x[\da-f]+/i, Str::Escape, :pop!
rule %r/\d+/, Str::Escape, :pop!
rule %r/\s+/, Str::Escape, :pop!
rule %r/./, Str, :pop!
end
end
end
end
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Awk < RegexLexer
title "Awk"
desc "pattern-directed scanning and processing language"
tag 'awk'
filenames '*.awk'
mimetypes 'application/x-awk'
def self.detect?(text)
return true if text.shebang?('awk')
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
def self.keywords
@keywords ||= Set.new %w(
if else while for do break continue return next nextfile delete
exit print printf getline
)
end
def self.declarations
@declarations ||= Set.new %w(function)
end
def self.reserved
@reserved ||= Set.new %w(BEGIN END)
end
def self.constants
@constants ||= Set.new %w(
CONVFMT FS NF NR FNR FILENAME RS OFS ORS OFMT SUBSEP ARGC ARGV
ENVIRON
)
end
def self.builtins
@builtins ||= %w(
exp log sqrt sin cos atan2 length rand srand int substr index match
split sub gsub sprintf system tolower toupper
)
end
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(#.*?$), Comment::Single
end
state :expr_start do
mixin :comments_and_whitespace
rule %r(/) do
token Str::Regex
goto :regex
end
rule %r//, Text, :pop!
end
state :regex do
rule %r(/) do
token Str::Regex
goto :regex_end
end
rule %r([^/]\n), Error, :pop!
rule %r/\n/, Error, :pop!
rule %r/\[\^/, Str::Escape, :regex_group
rule %r/\[/, Str::Escape, :regex_group
rule %r/\\./, Str::Escape
rule %r{[(][?][:=<!]}, Str::Escape
rule %r/[{][\d,]+[}]/, Str::Escape
rule %r/[()?]/, Str::Escape
rule %r/./, Str::Regex
end
state :regex_end do
rule(//) { pop! }
end
state :regex_group do
# specially highlight / in a group to indicate that it doesn't
# close the regex
rule %r(/), Str::Escape
rule %r([^/]\n) do
token Error
pop! 2
end
rule %r/\]/, Str::Escape, :pop!
rule %r/\\./, Str::Escape
rule %r/./, Str::Regex
end
state :bad_regex do
rule %r/[^\n]+/, Error, :pop!
end
state :root do
mixin :comments_and_whitespace
rule %r((?<=\n)(?=\s|/)), Text, :expr_start
rule %r([-<>+*/%\^!=]=?|in\b|\+\+|--|\|), Operator, :expr_start
rule %r(&&|\|\||~!?), Operator, :expr_start
rule %r/[(\[,]/, Punctuation, :expr_start
rule %r/;/, Punctuation, :statement
rule %r/[)\].]/, Punctuation
rule %r/[?]/ do
token Punctuation
push :ternary
push :expr_start
end
rule %r/[{}]/, Punctuation, :statement
rule id do |m|
if self.class.keywords.include? m[0]
token Keyword
push :expr_start
elsif self.class.declarations.include? m[0]
token Keyword::Declaration
push :expr_start
elsif self.class.reserved.include? m[0]
token Keyword::Reserved
elsif self.class.constants.include? m[0]
token Keyword::Constant
elsif self.class.builtins.include? m[0]
token Name::Builtin
elsif m[0] =~ /^\$/
token Name::Variable
else
token Name::Other
end
end
rule %r/[0-9]+\.[0-9]+/, Num::Float
rule %r/[0-9]+/, Num::Integer
rule %r/"(\\[\\"]|[^"])*"/, Str::Double
rule %r/:/, Punctuation
end
state :statement do
rule %r/[{}]/, Punctuation
mixin :expr_start
end
state :ternary do
rule %r/:/ do
token Punctuation
goto :expr_start
end
mixin :root
end
end
end
end
@@ -0,0 +1,165 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Batchfile < RegexLexer
title "Batchfile"
desc "Windows Batch File"
tag 'batchfile'
aliases 'bat', 'batch', 'dosbatch', 'winbatch'
filenames '*.bat', '*.cmd'
mimetypes 'application/bat', 'application/x-bat', 'application/x-msdos-program'
def self.keywords
@keywords ||= %w(
if else for in do goto call exit
)
end
def self.operator_words
@operator_words ||= %w(
exist defined errorlevel cmdextversion not equ neq lss leq gtr geq
)
end
def self.devices
@devices ||= %w(
con prn aux nul com1 com2 com3 com4 com5 com6 com7 com8 com9 lpt1 lpt2
lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9
)
end
def self.builtin_commands
@builtin_commands ||= %w(
assoc attrib break bcdedit cacls cd chcp chdir chkdsk chkntfs choice
cls cmd color comp compact convert copy date del dir diskpart doskey
dpath driverquery echo endlocal erase fc find findstr format fsutil
ftype gpresult graftabl help icacls label md mkdir mklink mode more
move openfiles path pause popd print prompt pushd rd recover ren
rename replace rmdir robocopy setlocal sc schtasks shift shutdown sort
start subst systeminfo takeown tasklist taskkill time timeout title
tree type ver verify vol xcopy waitfor wmic
)
end
def self.other_commands
@other_commands ||= %w(
addusers admodcmd ansicon arp at bcdboot bitsadmin browstat certreq
certutil change cidiag cipher cleanmgr clip cmdkey compress convertcp
coreinfo csccmd csvde cscript curl debug defrag delprof deltree devcon
diamond dirquota diruse diskshadow diskuse dism dnscmd dsacls dsadd
dsget dsquery dsmod dsmove dsrm dsmgmt dsregcmd edlin eventcreate
expand extract fdisk fltmc forfiles freedisk ftp getmac gpupdate
hostname ifmember inuse ipconfig kill lgpo lodctr logman logoff
logtime makecab mapisend mbsacli mem mountvol moveuser msg mshta
msiexec msinfo32 mstsc nbtstat net net1 netdom netsh netstat nlsinfo
nltest now nslookup ntbackup ntdsutil ntoskrnl ntrights nvspbind
pathping perms ping portqry powercfg pngout pnputil printbrm prncnfg
prnmngr procdump psexec psfile psgetsid psinfo pskill pslist
psloggedon psloglist pspasswd psping psservice psshutdown pssuspend
qbasic qgrep qprocess query quser qwinsta rasdial reg reg1 regdump
regedt32 regsvr32 regini reset restore rundll32 rmtshare route rpcping
run runas scandisk setspn setx sfc share shellrunas shortcut sigcheck
sleep slmgr strings subinacl sysmon telnet tftp tlist touch tracerpt
tracert tscon tsdiscon tskill tttracer typeperf tzutil undelete
unformat verifier vmconnect vssadmin w32tm wbadmin wecutil wevtutil
wget where whoami windiff winrm winrs wpeutil wpr wusa wuauclt wscript
)
end
def self.attributes
@attributes ||= %w(
on off disable enableextensions enabledelayedexpansion
)
end
state :basic do
# Comments
rule %r/@?\brem\b.*$/i, Comment
# Empty Labels
rule %r/^::.*$/, Comment
# Labels
rule %r/:[a-z]+/i, Name::Label
rule %r/([a-z]\w*)(\.exe|com|bat|cmd|msi)?/i do |m|
if self.class.devices.include? m[1]
groups Keyword::Reserved, Error
elsif self.class.keywords.include? m[1]
groups Keyword, Error
elsif self.class.operator_words.include? m[1]
groups Operator::Word, Error
elsif self.class.builtin_commands.include? m[1]
token Name::Builtin
elsif self.class.other_commands.include? m[1]
token Name::Builtin
elsif self.class.attributes.include? m[1]
groups Name::Attribute, Error
elsif "set".casecmp m[1]
groups Keyword::Declaration, Error
else
token Text
end
end
rule %r/((?:[\/\+]|--?)[a-z]+)\s*/i, Name::Attribute
mixin :expansions
rule %r/[<>&|(){}\[\]\-+=;,~?*]/, Operator
end
state :escape do
rule %r/\^./m, Str::Escape
end
state :expansions do
# Normal and Delayed expansion
rule %r/[%!]+([a-z_$@#]+)[%!]+/i, Name::Variable
# For Variables
rule %r/(\%+~?[a-z]+\d?)/i, Name::Variable::Magic
end
state :double_quotes do
mixin :escape
rule %r/["]/, Str::Double, :pop!
mixin :expansions
rule %r/[^\^"%!]+/, Str::Double
end
state :single_quotes do
mixin :escape
rule %r/[']/, Str::Single, :pop!
mixin :expansions
rule %r/[^\^'%!]+/, Str::Single
end
state :backtick do
mixin :escape
rule %r/[`]/, Str::Backtick, :pop!
mixin :expansions
rule %r/[^\^`%!]+/, Str::Backtick
end
state :data do
rule %r/\s+/, Text
rule %r/0x[0-9a-f]+/i, Literal::Number::Hex
rule %r/[0-9]/, Literal::Number
rule %r/["]/, Str::Double, :double_quotes
rule %r/[']/, Str::Single, :single_quotes
rule %r/[`]/, Str::Backtick, :backtick
rule %r/[^\s&|()\[\]{}\^=;!%+\-,"'`~?*]+/, Text
mixin :escape
end
state :root do
mixin :basic
mixin :data
end
end
end
end
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class BBCBASIC < RegexLexer
title "BBCBASIC"
desc "BBC BASIC syntax"
tag 'bbcbasic'
filenames '*,fd1'
def self.punctuation
@punctuation ||= %w(
[,;'~] SPC TAB
)
end
def self.function
@function ||= %w(
ABS ACS ADVAL ASC ASN ATN BEATS BEAT BGET# CHR\$ COS COUNT DEG DIM
EOF# ERL ERR EVAL EXP EXT# FN GET\$# GET\$ GET HIMEM INKEY\$ INKEY
INSTR INT LEFT\$ LEN LN LOG LOMEM MID\$ OPENIN OPENOUT OPENUP PAGE
POINT POS PTR# RAD REPORT\$ RIGHT\$ RND SGN SIN SQR STR\$ STRING\$ SUM
SUMLEN TAN TEMPO TIME\$ TIME TOP USR VAL VPOS
)
end
def self.statement
@statement ||= %w(
BEATS BPUT# CALL CASE CHAIN CLEAR CLG CLOSE# CLS COLOR COLOUR DATA
ELSE ENDCASE ENDIF ENDPROC ENDWHILE END ENVELOPE FOR GCOL GOSUB GOTO
IF INSTALL LET LIBRARY MODE NEXT OFF OF ON ORIGIN OSCI OTHERWISE
OVERLAY PLOT PRINT# PRINT PROC QUIT READ REPEAT REPORT RETURN SOUND
STEP STEREO STOP SWAP SYS THEN TINT TO VDU VOICES VOICE UNTIL WAIT
WHEN WHILE WIDTH
)
end
def self.operator
@operator ||= %w(
<< <= <> < >= >>> >> > [-!$()*+/=?^|] AND DIV EOR MOD NOT OR
)
end
def self.constant
@constant ||= %w(
FALSE TRUE
)
end
state :expression do
rule %r/#{BBCBASIC.function.join('|')}/o, Name::Builtin # function or pseudo-variable
rule %r/#{BBCBASIC.operator.join('|')}/o, Operator
rule %r/#{BBCBASIC.constant.join('|')}/o, Name::Constant
rule %r/"[^"]*"/o, Literal::String
rule %r/[a-z_`][\w`]*[$%]?/io, Name::Variable
rule %r/@%/o, Name::Variable
rule %r/[\d.]+/o, Literal::Number
rule %r/%[01]+/o, Literal::Number::Bin
rule %r/&[\h]+/o, Literal::Number::Hex
end
state :root do
rule %r/(:+)( *)(\*)(.*)/ do
groups Punctuation, Text, Keyword, Text # CLI command
end
rule %r/(\n+ *)(\*)(.*)/ do
groups Text, Keyword, Text # CLI command
end
rule %r/(ELSE|OTHERWISE|REPEAT|THEN)( *)(\*)(.*)/ do
groups Keyword, Text, Keyword, Text # CLI command
end
rule %r/[ \n]+/o, Text
rule %r/:+/o, Punctuation
rule %r/[\[]/o, Keyword, :assembly1
rule %r/REM *>.*/o, Comment::Special
rule %r/REM.*/o, Comment
rule %r/(?:#{BBCBASIC.statement.join('|')}|CIRCLE(?: *FILL)?|DEF *(?:FN|PROC)|DRAW(?: *BY)?|DIM(?!\()|ELLIPSE(?: *FILL)?|ERROR(?: *EXT)?|FILL(?: *BY)?|INPUT(?:#| *LINE)?|LINE(?: *INPUT)?|LOCAL(?: *DATA| *ERROR)?|MOUSE(?: *COLOUR| *OFF| *ON| *RECTANGLE| *STEP| *TO)?|MOVE(?: *BY)?|ON(?! *ERROR)|ON *ERROR *(?:LOCAL|OFF)?|POINT(?: *BY)?(?!\()|RECTANGE(?: *FILL)?|RESTORE(?: *DATA| *ERROR)?|TRACE(?: *CLOSE| *ENDPROC| *OFF| *STEP(?: *FN| *ON| *PROC)?| *TO)?)/o, Keyword
mixin :expression
rule %r/#{BBCBASIC.punctuation.join('|')}/o, Punctuation
end
# Assembly statements are parsed as
# {label} {directive|opcode |']' {expressions}} {comment}
# Technically, you don't need whitespace between opcodes and arguments,
# but this is rare in uncrunched source and trying to enumerate all
# possible opcodes here is impractical so we colour it as though
# the whitespace is required. Opcodes and directives can only easily be
# distinguished from the symbols that make up expressions by looking at
# their position within the statement. Similarly, ']' is treated as a
# keyword at the start of a statement or as punctuation elsewhere. This
# requires a two-state state machine.
state :assembly1 do
rule %r/ +/o, Text
rule %r/]/o, Keyword, :pop!
rule %r/[:\n]/o, Punctuation
rule %r/\.[a-z_`][\w`]*%? */io, Name::Label
rule %r/(?:REM|;)[^:\n]*/o, Comment
rule %r/[^ :\n]+/o, Keyword, :assembly2
end
state :assembly2 do
rule %r/ +/o, Text
rule %r/[:\n]/o, Punctuation, :pop!
rule %r/(?:REM|;)[^:\n]*/o, Comment, :pop!
mixin :expression
rule %r/[!#,@\[\]^{}]/, Punctuation
end
end
end
end
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# Regular expressions based on https://github.com/SaswatPadhi/prismjs-bibtex
# and https://github.com/alecthomas/chroma/blob/master/lexers/b/bibtex.go
module Rouge
module Lexers
class BibTeX < RegexLexer
title 'BibTeX'
desc "BibTeX"
tag 'bibtex'
aliases 'bib'
filenames '*.bib'
valid_punctuation = Regexp.quote("@!$&.\\:;<>?[]^`|~*/+-")
valid_name = /[a-z_#{valid_punctuation}][\w#{valid_punctuation}]*/io
state :root do
mixin :whitespace
rule %r/@(#{valid_name})/o do |m|
match = m[1].downcase
if match == "comment"
token Comment
elsif match == "preamble"
token Name::Class
push :closing_brace
push :value
push :opening_brace
elsif match == "string"
token Name::Class
push :closing_brace
push :field
push :opening_brace
else
token Name::Class
push :closing_brace
push :command_body
push :opening_brace
end
end
rule %r/.+/, Comment
end
state :opening_brace do
mixin :whitespace
rule %r/[{(]/, Punctuation, :pop!
end
state :closing_brace do
mixin :whitespace
rule %r/[})]/, Punctuation, :pop!
end
state :command_body do
mixin :whitespace
rule %r/[^\s\,\}]+/ do
token Name::Label
pop!
push :fields
end
end
state :fields do
mixin :whitespace
rule %r/,/, Punctuation, :field
rule(//) { pop! }
end
state :field do
mixin :whitespace
rule valid_name do
token Name::Attribute
push :value
push :equal_sign
end
rule(//) { pop! }
end
state :equal_sign do
mixin :whitespace
rule %r/=/, Punctuation, :pop!
end
state :value do
mixin :whitespace
rule valid_name, Name::Variable
rule %r/"/, Literal::String, :quoted_string
rule %r/\{/, Literal::String, :braced_string
rule %r/\d+/, Literal::Number
rule %r/#/, Punctuation
rule(//) { pop! }
end
state :quoted_string do
rule %r/\{/, Literal::String, :braced_string
rule %r/"/, Literal::String, :pop!
rule %r/[^\{\"]+/, Literal::String
end
state :braced_string do
rule %r/\{/, Literal::String, :braced_string
rule %r/\}/, Literal::String, :pop!
rule %r/[^\{\}]+/, Literal::String
end
state :whitespace do
rule %r/\s+/, Text
end
end
end
end
@@ -0,0 +1,111 @@
module Rouge
module Lexers
class Bicep < Rouge::RegexLexer
tag 'bicep'
filenames '*.bicep'
title "Bicep"
desc 'Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources.'
def self.keywords
@keywords ||= Set.new %w(
as assert existing extends extension false for from func if import in metadata module
none null output param provider resource targetScope test true type using var void with
)
end
def self.datatypes
@datatypes ||= Set.new %w(array bool int object string)
end
def self.functions
@functions ||= Set.new %w(
array base64 base64ToJson base64ToString bool cidrHost cidrSubnet concat contains dataUri
dataUriToString dateTimeAdd dateTimeFromEpoch dateTimeToEpoch deployer deployment empty endsWith
environment extensionResourceId fail filter first flatten format getSecret groupBy guid indexOf int
intersection items join json last lastIndexOf length list* listAccountSas listKeys listSecrets loadFileAsBase64
loadJsonContent loadTextContent loadYamlContent managementGroup managementGroupResourceId map mapValue max min
newGuid objectKeys padLeft parseCidr pickZones range readEnvironmentVariable reduce reference replace resourceGroup
resourceId shallowMerge skip sort split startsWith string subscription subscriptionResourceId substring take tenant
tenantResourceId toLogicalZone toLower toObject toPhysicalZone toUpper trim union uniqueString uri uriComponent
uriComponentToString utcNow
)
end
operators = %w(+ - * / % < <= > >= == != =~ !~ && || ! ?? ... .?)
punctuations = %w(( ) { } [ ] , : ; = .)
state :root do
mixin :comments
# Match strings
rule %r/'/, Str::Single, :string
# Match numbers
rule %r/\b\d+\b/, Num
# Rules for sets of reserved keywords
rule %r/\b\w+\b/ do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.datatypes.include? m[0]
token Keyword::Type
elsif self.class.functions.include? m[0]
token Name::Function
else
token Name
end
end
# Match operators
rule %r/#{operators.map { |o| Regexp.escape(o) }.join('|')}/, Operator
# Enter a state when encountering an opening curly bracket
rule %r/{/, Punctuation::Indicator, :block
# Match punctuation
rule %r/#{punctuations.map { |p| Regexp.escape(p) }.join('|')}/, Punctuation
# Match identifiers
rule %r/[a-zA-Z_]\w*/, Name
# Match decorators
rule %r/@[a-zA-Z_]\w*/, Name::Decorator
# Ignore whitespace
rule %r/\s+/, Text
end
state :comments do
rule %r(//[^\n\r]+), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
end
state :string do
rule %r/[^'$}]+/, Str::Single
rule %r/\$(?!\{)/, Str::Single
rule %r/\$[\{]/, Str::Interpol, :interp
rule %r/\'/, Str::Single, :pop!
rule %r/\$+/, Str::Single
end
state :interp do
rule %r/\}/, Str::Interpol, :pop!
mixin :root
end
# State for matching code blocks between curly brackets
state :block do
# Match property names
rule %r/\b([a-zA-Z_]\w*)\b(?=\s*:)/, Name::Property
# Match closing curly brackets
rule %r/}/, Punctuation::Indicator, :pop!
# Include the root state for nested tokens
mixin :root
end
end
end
end
@@ -0,0 +1,43 @@
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'xml.rb'
class BIML < XML
title "BIML"
desc "BIML, Business Intelligence Markup Language"
tag 'biml'
filenames '*.biml'
def self.detect?(text)
return true if text =~ /<\s*Biml\b/
end
prepend :root do
rule %r(<#\@\s*)m, Name::Tag, :directive_tag
rule %r(<#[=]?\s*)m, Name::Tag, :directive_as_csharp
end
prepend :attr do
#TODO: how to deal with embedded <# tags inside a attribute string
#rule %r("<#[=]?\s*)m, Name::Tag, :directive_as_csharp
end
state :directive_as_csharp do
rule %r/\s*#>\s*/m, Name::Tag, :pop!
rule %r(.*?(?=\s*#>\s*))m do
delegate CSharp
end
end
state :directive_tag do
rule %r/\s+/m, Text
rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr
rule %r/\w+\s*/m, Name::Attribute
rule %r(/?\s*#>), Name::Tag, :pop!
end
end
end
end
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class BPF < RegexLexer
title "BPF"
desc "BPF bytecode syntax"
tag 'bpf'
TYPE_KEYWORDS = %w(
u8 u16 u32 u64 s8 s16 s32 s64 ll
).join('|')
MISC_KEYWORDS = %w(
be16 be32 be64 le16 le32 le64 bswap16 bswap32 bswap64 exit lock map
).join('|')
state :root do
# Line numbers and hexadecimal output from bpftool/objdump
rule %r/(\d+)(:)(\s+)(\(\h{2}\))/i do
groups Generic::Lineno, Punctuation, Text::Whitespace, Generic
end
rule %r/(\d+)(:)(\s+)((?:\h{2} ){8})/i do
groups Generic::Lineno, Punctuation, Text::Whitespace, Generic
end
rule %r/(\d+)(:)(\s+)/i do
groups Generic::Lineno, Punctuation, Text::Whitespace
end
# Calls to helpers
rule %r/(call)(\s+)(\d+)/i do
groups Keyword, Text::Whitespace, Literal::Number::Integer
end
rule %r/(call)(\s+)(\w+)(?:(#)(\d+))?/i do
groups Keyword, Text::Whitespace, Name::Builtin, Punctuation, Literal::Number::Integer
end
# Unconditional jumps
rule %r/(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
end
# Conditional jumps
rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
end
rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)([rw]\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
end
# Dereferences
rule %r/(\*)(\s*)(\()(#{TYPE_KEYWORDS})(\s*)(\*)(\))/i do
groups Operator, Text::Whitespace, Punctuation, Keyword::Type, Text::Whitespace, Operator, Punctuation
push :address
end
# Operators
rule %r/[+-\/\*&|><^s]{0,3}=/i, Operator
# Registers
rule %r/([+-]?)([rw]\d+)/i do
groups Punctuation, Name
end
# Comments
rule %r/\/\//, Comment::Single, :linecomment
rule %r/\/\*/, Comment::Multiline, :multilinescomment
rule %r/#{MISC_KEYWORDS}/i, Keyword
# Literals and global objects (maps) refered by name
rule %r/([-]?0x\h+|[-]?\d+)(\s*)(ll)?/i do
groups Literal::Number, Text::Whitespace, Keyword::Type
end
rule %r/(\w+)(\s*)(ll)/i do
groups Name, Text::Whitespace, Keyword::Type
end
# Labels
rule %r/(\w+)(\s*)(:)/i do
groups Name::Label, Text::Whitespace, Punctuation
end
rule %r{.}m, Text
end
state :address do
# Address is offset from register
rule %r/(\()([rw]\d+)(\s*)([+-])(\s*)(\d+)(\))/i do
groups Punctuation, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number::Integer, Punctuation
pop!
end
# Address is array subscript
rule %r/(\w+)(\[)(\d+)(\])/i do
groups Name, Punctuation, Literal::Number::Integer, Punctuation
pop!
end
rule %r/(\w+)(\[)([rw]\d+)(\])/i do
groups Name, Punctuation, Name, Punctuation
pop!
end
end
state :linecomment do
rule %r/\n/, Comment::Single, :pop!
rule %r/.+/, Comment::Single
end
state :multilinescomment do
rule %r/\*\//, Comment::Multiline, :pop!
rule %r/([^\*\/]+)/, Comment::Multiline
rule %r/([\*\/])/, Comment::Multiline
end
end
end
end
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Brainfuck < RegexLexer
tag 'brainfuck'
filenames '*.b', '*.bf'
mimetypes 'text/x-brainfuck'
title "Brainfuck"
aliases "bf"
desc "The Brainfuck programming language"
start { push :bol }
state :bol do
rule %r/\s+/m, Text
rule %r/\[/, Comment::Multiline, :comment_multi
rule(//) { pop! }
end
state :root do
rule %r/\]/, Error
rule %r/\[/, Punctuation, :loop
mixin :comment_single
mixin :commands
end
state :comment_multi do
rule %r/\[/, Comment::Multiline, :comment_multi
rule %r/\]/, Comment::Multiline, :pop!
rule %r/[^\[\]]+?/m, Comment::Multiline
end
state :comment_single do
rule %r/[^><+\-.,\[\]]+/, Comment::Single
end
state :loop do
rule %r/\[/, Punctuation, :loop
rule %r/\]/, Punctuation, :pop!
mixin :comment_single
mixin :commands
end
state :commands do
rule %r/[><]+/, Name::Builtin
rule %r/[+\-.,]+/, Name::Function
end
end
end
end
@@ -0,0 +1,147 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Brightscript < RegexLexer
title "BrightScript"
desc "BrightScript Programming Language (https://developer.roku.com/en-ca/docs/references/brightscript/language/brightscript-language-reference.md)"
tag 'brightscript'
aliases 'bs', 'brs'
filenames '*.brs'
# https://developer.roku.com/en-ca/docs/references/brightscript/language/global-utility-functions.md
# https://developer.roku.com/en-ca/docs/references/brightscript/language/global-string-functions.md
# https://developer.roku.com/en-ca/docs/references/brightscript/language/global-math-functions.md
def self.name_builtin
@name_builtin ||= Set.new %w(
ABS ASC ATN CDBL CHR CINT CONTROL COPYFILE COS CREATEDIRECTORY CSNG
DELETEDIRECTORY DELETEFILE EXP FINDMEMBERFUNCTION FINDNODE FIX
FORMATDRIVEFORMATJSON GETINTERFACE INSTR INT LCASE LEFT LEN LISTDIR
LOG MATCHFILES MID MOVEFILE OBSERVEFIELD PARSEJSON PARSEXML
READASCIIFILE REBOOTSYSTEM RIGHT RND RUNGARBAGECOLLECTOR SGN SIN
SLEEP SQR STR STRI STRING STRINGI STRTOI SUBSTITUTE TANTEXTTOP TEXT
TRUCASE UPTIME VALVISIBLE VISIBLE WAIT
)
end
# https://developer.roku.com/en-ca/docs/references/brightscript/language/reserved-words.md
def self.keyword_reserved
@keyword_reserved ||= Set.new %w(
BOX CREATEOBJECT DIM EACH ELSE ELSEIF END ENDFUNCTION ENDIF ENDSUB
ENDWHILE EVAL EXIT EXITWHILE FALSE FOR FUNCTION GETGLOBALAA
GETLASTRUNCOMPILEERROR GETLASTRUNRUNTIMEERROR GOTO IF IN INVALID LET
LINE_NUM M NEXT OBJFUN POS PRINT REM RETURN RUN STEP STOP SUB TAB TO
TRUE TYPE WHILE
)
end
# These keywords are present in BrightScript, but not supported in standard .brs files
def self.keyword_reserved_unsupported
@keyword_reserved_unsupported ||= Set.new %w(
CLASS CONST IMPORT LIBRARY NAMESPACE PRIVATE PROTECTED PUBLIC
)
end
# https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md
def self.keyword_type
@keyword_type ||= Set.new %w(
BOOLEAN DIM DOUBLE DYNAMIC FLOAT FUNCTION INTEGER INTERFACE INVALID
LONGINTEGER OBJECT STRING VOID
)
end
# https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#operators
def self.operator_word
@operator_word ||= Set.new %w(
AND AS MOD NOT OR THEN
)
end
# Scene graph components configured as builtins. See BrightScript component documentation e.g.
# https://developer.roku.com/en-ca/docs/references/brightscript/components/roappinfo.md
def self.builtins
@builtins ||= Set.new %w(
roAppendFile roAppInfo roAppManager roArray roAssociativeArray
roAudioGuide roAudioMetadata roAudioPlayer roAudioPlayerEvent
roAudioResourceroBitmap roBoolean roBoolean roBrightPackage roBrSub
roButton roByteArray roCaptionRenderer roCaptionRendererEvent
roCecInterface roCECStatusEvent roChannelStore roChannelStoreEvent
roClockWidget roCodeRegistrationScreen
roCodeRegistrationScreenEventroCompositor roControlDown roControlPort
roControlPort roControlUp roCreateFile roDatagramReceiver
roDatagramSender roDataGramSocket roDateTime roDeviceInfo
roDeviceInfoEvent roDoubleroEVPCipher roEVPDigest roFileSystem
roFileSystemEvent roFloat roFont roFontMetrics roFontRegistry
roFunction roGlobal roGpio roGridScreen roGridScreenEvent
roHdmiHotPlugEventroHdmiStatus roHdmiStatusEvent roHMAC roHttpAgent
roImageCanvas roImageCanvasEvent roImageMetadata roImagePlayer
roImageWidgetroInput roInputEvent roInt roInt roInvalid roInvalid
roIRRemote roKeyboard roKeyboardPress roKeyboardScreen
roKeyboardScreenEventroList roListScreen roListScreenEvent
roLocalization roLongInteger roMessageDialog roMessageDialogEvent
roMessagePort roMicrophone roMicrophoneEvent roNetworkConfiguration
roOneLineDialog roOneLineDialogEventroParagraphScreen
roParagraphScreenEvent roPath roPinEntryDialog roPinEntryDialogEvent
roPinentryScreen roPosterScreen roPosterScreenEventroProgramGuide
roQuadravoxButton roReadFile roRectangleroRegexroRegion roRegistry
roRegistrySection roResourceManager roRSA roRssArticle roRssParser
roScreen roSearchHistory roSearchScreen roSearchScreenEvent
roSerialPort roSGNode roSGNodeEvent roSGScreenroSGScreenEvent
roSlideShowroSlideShowEvent roSNS5 roSocketAddress roSocketEvent
roSpringboardScreen roSpringboardScreenEventroSprite roStorageInfo
roStreamSocket roStringroSystemLogroSystemLogEvent roSystemTime
roTextFieldroTextScreen roTextScreenEvent roTextToSpeech
roTextToSpeechEvent roTextureManager roTextureRequest
roTextureRequestEventroTextWidget roTimer roTimespan roTouchScreen
roTunerroTunerEvent roUniversalControlEvent roUrlEvent roUrlTransfer
roVideoEvent roVideoInput roVideoMode roVideoPlayer roVideoPlayerEvent
roVideoScreen roVideoScreenEventroWriteFile roXMLElement roXMLList
)
end
id = /[$a-z_][a-z0-9_]*/io
state :root do
rule %r/\s+/m, Text::Whitespace
# https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#comments
rule %r/\'.*/, Comment::Single
rule %r/REM.*/i, Comment::Single
# https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#operators
rule %r([~!%^&*+=\|?:<>/-]), Operator
rule %r/\d*\.\d+(e-?\d+)?/i, Num::Float
rule %r/\d+[lu]*/i, Num::Integer
rule %r/".*?"/, Str::Double
rule %r/#{id}(?=\s*[(])/, Name::Function
rule %r/[()\[\],.;{}]/, Punctuation
rule id do |m|
caseSensitiveChunk = m[0]
caseInsensitiveChunk = m[0].upcase
if self.class.builtins.include?(caseSensitiveChunk)
token Keyword::Reserved
elsif self.class.keyword_reserved.include?(caseInsensitiveChunk)
token Keyword::Reserved
elsif self.class.keyword_reserved_unsupported.include?(caseInsensitiveChunk)
token Keyword::Reserved
elsif self.class.keyword_type.include?(caseInsensitiveChunk)
token Keyword::Type
elsif self.class.name_builtin.include?(caseInsensitiveChunk)
token Name::Builtin
elsif self.class.operator_word.include?(caseInsensitiveChunk)
token Operator::Word
else
token Name
end
end
end
end
end
end
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Bsl < RegexLexer
title "1C (BSL)"
desc "The 1C:Enterprise programming language"
tag 'bsl'
filenames '*.bsl', '*.os'
KEYWORDS = /(?<=[^\wа-яё]|^)(?:
КонецПроцедуры | EndProcedure | КонецФункции | EndFunction
| Прервать | Break | Продолжить | Continue
| Возврат | Return | Если | If
| Иначе | Else | ИначеЕсли | ElsIf
| Тогда | Then | КонецЕсли | EndIf
| Попытка | Try | Исключение | Except
| КонецПопытки | EndTry | Raise | ВызватьИсключение
| Пока | While | Для | For
| Каждого | Each | Из | In
| По | To | Цикл | Do
| КонецЦикла | EndDo | НЕ | NOT
| И | AND | ИЛИ | OR
| Новый | New | Процедура | Procedure
| Функция | Function | Перем | Var
| Экспорт | Export | Знач | Val
)(?=[^\wа-яё]|$)/ix
BUILTINS = /(?<=[^\wа-яё]|^)(?:
СтрДлина|StrLen|СокрЛ|TrimL|СокрП|TrimR|СокрЛП|TrimAll|Лев|Left|Прав|Right|Сред|Mid|СтрНайти|StrFind|ВРег|Upper|НРег|Lower|ТРег|Title|Символ|Char|КодСимвола|CharCode|ПустаяСтрока|IsBlankString|СтрЗаменить|StrReplace|СтрЧислоСтрок|StrLineCount|СтрПолучитьСтроку|StrGetLine|СтрЧислоВхождений|StrOccurrenceCount|СтрСравнить|StrCompare|СтрНачинаетсяС|StrStartWith|СтрЗаканчиваетсяНа|StrEndsWith|СтрРазделить|StrSplit|СтрСоединить|StrConcat
| Цел|Int|Окр|Round|ACos|ACos|ASin|ASin|ATan|ATan|Cos|Cos|Exp|Exp|Log|Log|Log10|Log10|Pow|Pow|Sin|Sin|Sqrt|Sqrt|Tan|Tan
| Год|Year|Месяц|Month|День|Day|Час|Hour|Минута|Minute|Секунда|Second|НачалоГода|BegOfYear|НачалоДня|BegOfDay|НачалоКвартала|BegOfQuarter|НачалоМесяца|BegOfMonth|НачалоМинуты|BegOfMinute|НачалоНедели|BegOfWeek|НачалоЧаса|BegOfHour|КонецГода|EndOfYear|КонецДня|EndOfDay|КонецКвартала|EndOfQuarter|КонецМесяца|EndOfMonth|КонецМинуты|EndOfMinute|КонецНедели|EndOfWeek|КонецЧаса|EndOfHour|НеделяГода|WeekOfYear|ДеньГода|DayOfYear|ДеньНедели|WeekDay|ТекущаяДата|CurrentDate|ДобавитьМесяц|AddMonth
| Тип|Type|ТипЗнч|TypeOf
| Булево|Boolean|Число|Number|Строка|String|Дата|Date
| ПоказатьВопрос|ShowQueryBox|Вопрос|DoQueryBox|ПоказатьПредупреждение|ShowMessageBox|Предупреждение|DoMessageBox|Сообщить|Message|ОчиститьСообщения|ClearMessages|ОповеститьОбИзменении|NotifyChanged|Состояние|Status|Сигнал|Beep|ПоказатьЗначение|ShowValue|ОткрытьЗначение|OpenValue|Оповестить|Notify|ОбработкаПрерыванияПользователя|UserInterruptProcessing|ОткрытьСодержаниеСправки|OpenHelpContent|ОткрытьИндексСправки|OpenHelpIndex|ОткрытьСправку|OpenHelp|ПоказатьИнформациюОбОшибке|ShowErrorInfo|КраткоеПредставлениеОшибки|BriefErrorDescription|ПодробноеПредставлениеОшибки|DetailErrorDescription|ПолучитьФорму|GetForm|ЗакрытьСправку|CloseHelp|ПоказатьОповещениеПользователя|ShowUserNotification|ОткрытьФорму|OpenForm|ОткрытьФормуМодально|OpenFormModal|АктивноеОкно|ActiveWindow|ВыполнитьОбработкуОповещения|ExecuteNotifyProcessing
| ПоказатьВводЗначения|ShowInputValue|ВвестиЗначение|InputValue|ПоказатьВводЧисла|ShowInputNumber|ВвестиЧисло|InputNumber|ПоказатьВводСтроки|ShowInputString|ВвестиСтроку|InputString|ПоказатьВводДаты|ShowInputDate|ВвестиДату|InputDate
| Формат|Format|ЧислоПрописью|NumberInWords|НСтр|NStr|ПредставлениеПериода|PeriodPresentation|СтрШаблон|StrTemplate
| ПолучитьОбщийМакет|GetCommonTemplate|ПолучитьОбщуюФорму|GetCommonForm|ПредопределенноеЗначение|PredefinedValue|ПолучитьПолноеИмяПредопределенногоЗначения|GetPredefinedValueFullName
| ПолучитьЗаголовокСистемы|GetCaption|ПолучитьСкоростьКлиентскогоСоединения|GetClientConnectionSpeed|ПодключитьОбработчикОжидания|AttachIdleHandler|УстановитьЗаголовокСистемы|SetCaption|ОтключитьОбработчикОжидания|DetachIdleHandler|ИмяКомпьютера|ComputerName|ЗавершитьРаботуСистемы|Exit|ИмяПользователя|UserName|ПрекратитьРаботуСистемы|Terminate|ПолноеИмяПользователя|UserFullName|ЗаблокироватьРаботуПользователя|LockApplication|КаталогПрограммы|BinDir|КаталогВременныхФайлов|TempFilesDir|ПравоДоступа|AccessRight|РольДоступна|IsInRole|ТекущийЯзык|CurrentLanguage|ТекущийКодЛокализации|CurrentLocaleCode|СтрокаСоединенияИнформационнойБазы|InfoBaseConnectionString|ПодключитьОбработчикОповещения|AttachNotificationHandler|ОтключитьОбработчикОповещения|DetachNotificationHandler|ПолучитьСообщенияПользователю|GetUserMessages|ПараметрыДоступа|AccessParameters|ПредставлениеПриложения|ApplicationPresentation|ТекущийЯзыкСистемы|CurrentSystemLanguage|ЗапуститьСистему|RunSystem|ТекущийРежимЗапуска|CurrentRunMode|УстановитьЧасовойПоясСеанса|SetSessionTimeZone|ЧасовойПоясСеанса|SessionTimeZone|ТекущаяДатаСеанса|CurrentSessionDate|УстановитьКраткийЗаголовокПриложения|SetShortApplicationCaption|ПолучитьКраткийЗаголовокПриложения|GetShortApplicationCaption|ПредставлениеПрава|RightPresentation|ВыполнитьПроверкуПравДоступа|VerifyAccessRights|РабочийКаталогДанныхПользователя|UserDataWorkDir|КаталогДокументов|DocumentsDir|ПолучитьИнформациюЭкрановКлиента|GetClientDisplaysInformation|ТекущийВариантОсновногоШрифтаКлиентскогоПриложения|ClientApplicationBaseFontCurrentVariant|ТекущийВариантИнтерфейсаКлиентскогоПриложения|ClientApplicationInterfaceCurrentVariant|УстановитьЗаголовокКлиентскогоПриложения|SetClientApplicationCaption|ПолучитьЗаголовокКлиентскогоПриложения|GetClientApplicationCaption|НачатьПолучениеКаталогаВременныхФайлов|BeginGettingTempFilesDir|НачатьПолучениеКаталогаДокументов|BeginGettingDocumentsDir|НачатьПолучениеРабочегоКаталогаДанныхПользователя|BeginGettingUserDataWorkDir|ПодключитьОбработчикЗапросаНастроекКлиентаЛицензирования|AttachLicensingClientParametersRequestHandler|ОтключитьОбработчикЗапросаНастроекКлиентаЛицензирования|DetachLicensingClientParametersRequestHandler
| ЗначениеВСтрокуВнутр|ValueToStringInternal|ЗначениеИзСтрокиВнутр|ValueFromStringInternal|ЗначениеВФайл|ValueToFile|ЗначениеИзФайла|ValueFromFile
| КомандаСистемы|System|ЗапуститьПриложение|RunApp|ПолучитьCOMОбъект|GetCOMObject|ПользователиОС|OSUsers|НачатьЗапускПриложения|BeginRunningApplication
| ПодключитьВнешнююКомпоненту|AttachAddIn|НачатьУстановкуВнешнейКомпоненты|BeginInstallAddIn|УстановитьВнешнююКомпоненту|InstallAddIn|НачатьПодключениеВнешнейКомпоненты|BeginAttachingAddIn
| КопироватьФайл|FileCopy|ПереместитьФайл|MoveFile|УдалитьФайлы|DeleteFiles|НайтиФайлы|FindFiles|СоздатьКаталог|CreateDirectory|ПолучитьИмяВременногоФайла|GetTempFileName|РазделитьФайл|SplitFile|ОбъединитьФайлы|MergeFiles|ПолучитьФайл|GetFile|НачатьПомещениеФайла|BeginPutFile|ПоместитьФайл|PutFile|ЭтоАдресВременногоХранилища|IsTempStorageURL|УдалитьИзВременногоХранилища|DeleteFromTempStorage|ПолучитьИзВременногоХранилища|GetFromTempStorage|ПоместитьВоВременноеХранилище|PutToTempStorage|ПодключитьРасширениеРаботыСФайлами|AttachFileSystemExtension|НачатьУстановкуРасширенияРаботыСФайлами|BeginInstallFileSystemExtension|УстановитьРасширениеРаботыСФайлами|InstallFileSystemExtension|ПолучитьФайлы|GetFiles|ПоместитьФайлы|PutFiles|ЗапроситьРазрешениеПользователя|RequestUserPermission|ПолучитьМаскуВсеФайлы|GetAllFilesMask|ПолучитьМаскуВсеФайлыКлиента|GetClientAllFilesMask|ПолучитьМаскуВсеФайлыСервера|GetServerAllFilesMask|ПолучитьРазделительПути|GetPathSeparator|ПолучитьРазделительПутиКлиента|GetClientPathSeparator|ПолучитьРазделительПутиСервера|GetServerPathSeparator|НачатьПодключениеРасширенияРаботыСФайлами|BeginAttachingFileSystemExtension|НачатьЗапросРазрешенияПользователя|BeginRequestingUserPermission|НачатьПоискФайлов|BeginFindingFiles|НачатьСозданиеКаталога|BeginCreatingDirectory|НачатьКопированиеФайла|BeginCopyingFile|НачатьПеремещениеФайла|BeginMovingFile|НачатьУдалениеФайлов|BeginDeletingFiles|НачатьПолучениеФайлов|BeginGettingFiles|НачатьПомещениеФайлов|BeginPuttingFiles
| НачатьТранзакцию|BeginTransaction|ЗафиксироватьТранзакцию|CommitTransaction|ОтменитьТранзакцию|RollbackTransaction|УстановитьМонопольныйРежим|SetExclusiveMode|МонопольныйРежим|ExclusiveMode|ПолучитьОперативнуюОтметкуВремени|GetRealTimeTimestamp|ПолучитьСоединенияИнформационнойБазы|GetInfoBaseConnections|НомерСоединенияИнформационнойБазы|InfoBaseConnectionNumber|КонфигурацияИзменена|ConfigurationChanged|КонфигурацияБазыДанныхИзмененаДинамически|DataBaseConfigurationChangedDynamically|УстановитьВремяОжиданияБлокировкиДанных|SetLockWaitTime|ОбновитьНумерациюОбъектов|RefreshObjectsNumbering|ПолучитьВремяОжиданияБлокировкиДанных|GetLockWaitTime|КодЛокализацииИнформационнойБазы|InfoBaseLocaleCode|УстановитьМинимальнуюДлинуПаролейПользователей|SetUserPasswordMinLength|ПолучитьМинимальнуюДлинуПаролейПользователей|GetUserPasswordMinLength|ИнициализироватьПредопределенныеДанные|InitializePredefinedData|УдалитьДанныеИнформационнойБазы|EraseInfoBaseData|УстановитьПроверкуСложностиПаролейПользователей|SetUserPasswordStrengthCheck|ПолучитьПроверкуСложностиПаролейПользователей|GetUserPasswordStrengthCheck|ПолучитьСтруктуруХраненияБазыДанных|GetDBStorageStructureInfo|УстановитьПривилегированныйРежим|SetPrivilegedMode|ПривилегированныйРежим|PrivilegedMode|ТранзакцияАктивна|TransactionActive|НеобходимостьЗавершенияСоединения|ConnectionStopRequest|НомерСеансаИнформационнойБазы|InfoBaseSessionNumber|ПолучитьСеансыИнформационнойБазы|GetInfoBaseSessions|ЗаблокироватьДанныеДляРедактирования|LockDataForEdit|УстановитьСоединениеСВнешнимИсточникомДанных|ConnectExternalDataSource|РазблокироватьДанныеДляРедактирования|UnlockDataForEdit|РазорватьСоединениеСВнешнимИсточникомДанных|DisconnectExternalDataSource|ПолучитьБлокировкуСеансов|GetSessionsLock|УстановитьБлокировкуСеансов|SetSessionsLock|ОбновитьПовторноИспользуемыеЗначения|RefreshReusableValues|УстановитьБезопасныйРежим|SetSafeMode|БезопасныйРежим|SafeMode|ПолучитьДанныеВыбора|GetChoiceData|УстановитьЧасовойПоясИнформационнойБазы|SetInfoBaseTimeZone|ПолучитьЧасовойПоясИнформационнойБазы|GetInfoBaseTimeZone|ПолучитьОбновлениеКонфигурацииБазыДанных|GetDataBaseConfigurationUpdate|УстановитьБезопасныйРежимРазделенияДанных|SetDataSeparationSafeMode|БезопасныйРежимРазделенияДанных|DataSeparationSafeMode|УстановитьВремяЗасыпанияПассивногоСеанса|SetPassiveSessionHibernateTime|ПолучитьВремяЗасыпанияПассивногоСеанса|GetPassiveSessionHibernateTime|УстановитьВремяЗавершенияСпящегоСеанса|SetHibernateSessionTerminateTime|ПолучитьВремяЗавершенияСпящегоСеанса|GetHibernateSessionTerminateTime|ПолучитьТекущийСеансИнформационнойБазы|GetCurrentInfoBaseSession|ПолучитьИдентификаторКонфигурации|GetConfigurationID|УстановитьНастройкиКлиентаЛицензирования|SetLicensingClientParameters|ПолучитьИмяКлиентаЛицензирования|GetLicensingClientName|ПолучитьДополнительныйПараметрКлиентаЛицензирования|GetLicensingClientAdditionalParameter
| НайтиПомеченныеНаУдаление|FindMarkedForDeletion|НайтиПоСсылкам|FindByRef|УдалитьОбъекты|DeleteObjects|УстановитьОбновлениеПредопределенныхДанныхИнформационнойБазы|SetInfoBasePredefinedDataUpdate|ПолучитьОбновлениеПредопределенныхДанныхИнформационнойБазы|GetInfoBasePredefinedData
| XMLСтрока|XMLString|XMLЗначение|XMLValue|XMLТип|XMLType|XMLТипЗнч|XMLTypeOf|ИзXMLТипа|FromXMLType|ВозможностьЧтенияXML|CanReadXML|ПолучитьXMLТип|GetXMLType|ПрочитатьXML|ReadXML|ЗаписатьXML|WriteXML|НайтиНедопустимыеСимволыXML|FindDisallowedXMLCharacters|ИмпортМоделиXDTO|ImportXDTOModel|СоздатьФабрикуXDTO|CreateXDTOFactory
| ЗаписатьJSON|WriteJSON|ПрочитатьJSON|ReadJSON|ПрочитатьДатуJSON|ReadJSONDate|ЗаписатьДатуJSON|WriteJSONDate
| ЗаписьЖурналаРегистрации|WriteLogEvent|ПолучитьИспользованиеЖурналаРегистрации|GetEventLogUsing|УстановитьИспользованиеЖурналаРегистрации|SetEventLogUsing|ПредставлениеСобытияЖурналаРегистрации|EventLogEventPresentation|ВыгрузитьЖурналРегистрации|UnloadEventLog|ПолучитьЗначенияОтбораЖурналаРегистрации|GetEventLogFilterValues|УстановитьИспользованиеСобытияЖурналаРегистрации|SetEventLogEventUse|ПолучитьИспользованиеСобытияЖурналаРегистрации|GetEventLogEventUse|СкопироватьЖурналРегистрации|CopyEventLog|ОчиститьЖурналРегистрации|ClearEventLog
| ЗначениеВДанныеФормы|ValueToFormData|ДанныеФормыВЗначение|FormDataToValue|КопироватьДанныеФормы|CopyFormData|УстановитьСоответствиеОбъектаИФормы|SetObjectAndFormConformity|ПолучитьСоответствиеОбъектаИФормы|GetObjectAndFormConformity
| ПолучитьФункциональнуюОпцию|GetFunctionalOption|ПолучитьФункциональнуюОпциюИнтерфейса|GetInterfaceFunctionalOption|УстановитьПараметрыФункциональныхОпцийИнтерфейса|SetInterfaceFunctionalOptionParameters|ПолучитьПараметрыФункциональныхОпцийИнтерфейса|GetInterfaceFunctionalOptionParameters|ОбновитьИнтерфейс|RefreshInterface
| УстановитьРасширениеРаботыСКриптографией|InstallCryptoExtension|НачатьУстановкуРасширенияРаботыСКриптографией|BeginInstallCryptoExtension|ПодключитьРасширениеРаботыСКриптографией|AttachCryptoExtension|НачатьПодключениеРасширенияРаботыСКриптографией|BeginAttachingCryptoExtension
| УстановитьСоставСтандартногоИнтерфейсаOData|SetStandardODataInterfaceContent|ПолучитьСоставСтандартногоИнтерфейсаOData|GetStandardODataInterfaceContent
| Мин|Min|Макс|Max|ОписаниеОшибки|ErrorDescription|Вычислить|Eval|ИнформацияОбОшибке|ErrorInfo|Base64Значение|Base64Value|Base64Строка|Base64String|ЗаполнитьЗначенияСвойств|FillPropertyValues|ЗначениеЗаполнено|ValueIsFilled|ПолучитьПредставленияНавигационныхСсылок|GetURLsPresentations|НайтиОкноПоНавигационнойСсылке|FindWindowByURL|ПолучитьОкна|GetWindows|ПерейтиПоНавигационнойСсылке|GotoURL|ПолучитьНавигационнуюСсылку|GetURL|ПолучитьДопустимыеКодыЛокализации|GetAvailableLocaleCodes|ПолучитьНавигационнуюСсылкуИнформационнойБазы|GetInfoBaseURL|ПредставлениеКодаЛокализации|LocaleCodePresentation|ПолучитьДопустимыеЧасовыеПояса|GetAvailableTimeZones|ПредставлениеЧасовогоПояса|TimeZonePresentation|ТекущаяУниверсальнаяДата|CurrentUniversalDate|ТекущаяУниверсальнаяДатаВМиллисекундах|CurrentUniversalDateInMilliseconds|МестноеВремя|ToLocalTime|УниверсальноеВремя|ToUniversalTime|ЧасовойПояс|TimeZone|СмещениеЛетнегоВремени|DaylightTimeOffset|СмещениеСтандартногоВремени|StandardTimeOffset|КодироватьСтроку|EncodeString|РаскодироватьСтроку|DecodeString|Найти|Find
| ПередНачаломРаботыСистемы|BeforeStart|ПриНачалеРаботыСистемы|OnStart|ПередЗавершениемРаботыСистемы|BeforeExit|ПриЗавершенииРаботыСистемы|OnExit|ОбработкаВнешнегоСобытия|ExternEventProcessing|УстановкаПараметровСеанса|SessionParametersSetting|ПриИзмененииПараметровЭкрана|OnChangeDisplaySettings
| WSСсылки|WSReferences|БиблиотекаКартинок|PictureLib|БиблиотекаМакетовОформленияКомпоновкиДанных|DataCompositionAppearanceTemplateLib|БиблиотекаСтилей|StyleLib|БизнесПроцессы|BusinessProcesses|ВнешниеИсточникиДанных|ExternalDataSources|ВнешниеОбработки|ExternalDataProcessors|ВнешниеОтчеты|ExternalReports|Документы|Documents|ДоставляемыеУведомления|DeliverableNotifications|ЖурналыДокументов|DocumentJournals|Задачи|Tasks|ИспользованиеРабочейДаты|WorkingDateUse|ИсторияРаботыПользователя|UserWorkHistory|Константы|Constants|КритерииОтбора|FilterCriteria|Метаданные|Metadata|Обработки|DataProcessors|ОтправкаДоставляемыхУведомлений|DeliverableNotificationSend|Отчеты|Reports|ПараметрыСеанса|SessionParameters|Перечисления|Enums|ПланыВидовРасчета|ChartsOfCalculationTypes|ПланыВидовХарактеристик|ChartsOfCharacteristicTypes|ПланыОбмена|ExchangePlans|ПланыСчетов|ChartsOfAccounts|ПолнотекстовыйПоиск|FullTextSearch|ПользователиИнформационнойБазы|InfoBaseUsers|Последовательности|Sequences|РасширенияКонфигурации|ConfigurationExtensions|РегистрыБухгалтерии|AccountingRegisters|РегистрыНакопления|AccumulationRegisters|РегистрыРасчета|CalculationRegisters|РегистрыСведений|InformationRegisters|РегламентныеЗадания|ScheduledJobs|СериализаторXDTO|XDTOSerializer|Справочники|Catalogs|СредстваГеопозиционирования|LocationTools|СредстваКриптографии|CryptoToolsManager|СредстваМультимедиа|MultimediaTools|СредстваПочты|MailTools|СредстваТелефонии|TelephonyTools|ФабрикаXDTO|XDTOFactory|ФоновыеЗадания|BackgroundJobs|ХранилищаНастроек
| ГлавныйИнтерфейс|MainInterface|ГлавныйСтиль|MainStyle|ПараметрЗапуска|LaunchParameter|РабочаяДата|WorkingDate|SettingsStorages|ХранилищеВариантовОтчетов|ReportsVariantsStorage|ХранилищеНастроекДанныхФорм|FormDataSettingsStorage|ХранилищеОбщихНастроек|CommonSettingsStorage|ХранилищеПользовательскихНастроекДинамическихСписков|DynamicListsUserSettingsStorage|ХранилищеПользовательскихНастроекОтчетов|ReportsUserSettingsStorage|ХранилищеСистемныхНастроек|SystemSettingsStorage
| Если|If|ИначеЕсли|ElsIf|Иначе|Else|КонецЕсли|EndIf|Тогда|Then
| Неопределено|Undefined|Истина|True|Ложь|False|NULL
)\s*(?=\()/ix
state :root do
rule %r/\n/, Text
rule %r/[^\S\n]+/, Text
rule %r(//.*$), Comment::Single
rule %r/[\[\]:(),;]/, Punctuation
rule %r/(?<=[^\wа-яё]|^)\&.*$/, Keyword::Declaration
rule %r/[-+\/*%=<>.?&]/, Operator
rule %r/(?<=[^\wа-яё]|^)\#.*$/, Keyword::Declaration
rule KEYWORDS, Keyword
rule BUILTINS, Name::Builtin
rule %r/[\wа-яё][\wа-яё]*/i, Name::Variable
#literals
rule %r/\b((\h{8}-(\h{4}-){3}\h{12})|\d+\.?\d*)\b/, Literal::Number
rule %r/\'.*\'/, Literal::Date
rule %r/".*?("|$)/, Literal::String::Single
rule %r/(?<=[^\wа-яё]|^)\|((?!\"\").)*?(\"|$)/, Literal::String
end
end
end
end
+200
View File
@@ -0,0 +1,200 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class C < RegexLexer
tag 'c'
filenames '*.c', '*.h', '*.idc'
mimetypes 'text/x-chdr', 'text/x-csrc'
title "C"
desc "The C programming language"
# optional comment or whitespace
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
def self.keywords
@keywords ||= Set.new %w(
auto break case const continue default do else enum extern
for goto if register restricted return sizeof static struct
switch typedef union volatile virtual while
_Alignas _Alignof _Atomic _Generic _Imaginary
_Noreturn _Static_assert _Thread_local
)
end
def self.keywords_type
@keywords_type ||= Set.new %w(
int long float short double char unsigned signed void
jmp_buf FILE DIR div_t ldiv_t mbstate_t sig_atomic_t fpos_t
clock_t time_t va_list size_t ssize_t off_t wchar_t ptrdiff_t
wctrans_t wint_t wctype_t
_Bool _Complex int8_t int16_t int32_t int64_t
uint8_t uint16_t uint32_t uint64_t int_least8_t
int_least16_t int_least32_t int_least64_t
uint_least8_t uint_least16_t uint_least32_t
uint_least64_t int_fast8_t int_fast16_t int_fast32_t
int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t
uint_fast64_t intptr_t uintptr_t intmax_t
uintmax_t
char16_t char32_t
)
end
def self.reserved
@reserved ||= Set.new %w(
__asm __int8 __based __except __int16 __stdcall __cdecl
__fastcall __int32 __declspec __finally __int61 __try __leave
inline _inline __inline naked _naked __naked restrict _restrict
__restrict thread _thread __thread typename _typename __typename
)
end
def self.builtins
@builtins ||= []
end
start { push :bol }
state :expr_bol do
mixin :inline_whitespace
rule %r/#if\s0/, Comment, :if_0
rule %r/#/, Comment::Preproc, :macro
rule(//) { pop! }
end
# :expr_bol is the same as :bol but without labels, since
# labels can only appear at the beginning of a statement.
state :bol do
rule %r/#{id}:(?!:)/, Name::Label
mixin :expr_bol
end
state :inline_whitespace do
rule %r/[ \t\r]+/, Text
rule %r/\\\n/, Text # line continuation
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
end
state :whitespace do
rule %r/\n+/m, Text, :bol
rule %r(//(\\.|.)*?$), Comment::Single, :bol
mixin :inline_whitespace
end
state :expr_whitespace do
rule %r/\n+/m, Text, :expr_bol
mixin :whitespace
end
state :statements do
mixin :whitespace
rule %r/(u8|u|U|L)?"/, Str, :string
rule %r((u8|u|U|L)?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
rule %r((\d+[.]\d*|[.]?\d+)e[+-]?\d+[lu]*)i, Num::Float
rule %r(\d+e[+-]?\d+[lu]*)i, Num::Float
rule %r/0x[0-9a-f]+[lu]*/i, Num::Hex
rule %r/0[0-7]+[lu]*/i, Num::Oct
rule %r/\d+[lu]*/i, Num::Integer
rule %r(\*/), Error
rule %r([~!%^&*+=\|?:<>/-]), Operator
rule %r/[()\[\],.;]/, Punctuation
rule %r/\bcase\b/, Keyword, :case
rule %r/(?:true|false|NULL)\b/, Name::Builtin
rule id do |m|
name = m[0]
if self.class.keywords.include? name
token Keyword
elsif self.class.keywords_type.include? name
token Keyword::Type
elsif self.class.reserved.include? name
token Keyword::Reserved
elsif self.class.builtins.include? name
token Name::Builtin
else
token Name
end
end
end
state :case do
rule %r/:/, Punctuation, :pop!
mixin :statements
end
state :root do
mixin :expr_whitespace
rule %r(
([\w*\s]+?[\s*]) # return arguments
(#{id}) # function name
(\s*\([^;]*?\)) # signature
(#{ws}?)({|;) # open brace or semicolon
)mx do |m|
# TODO: do this better.
recurse m[1]
token Name::Function, m[2]
recurse m[3]
recurse m[4]
token Punctuation, m[5]
if m[5] == ?{
push :function
end
end
rule %r/\{/, Punctuation, :function
mixin :statements
end
state :function do
mixin :whitespace
mixin :statements
rule %r/;/, Punctuation
rule %r/{/, Punctuation, :function
rule %r/}/, Punctuation, :pop!
end
state :string do
rule %r/"/, Str, :pop!
rule %r/\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
rule %r/[^\\"\n]+/, Str
rule %r/\\\n/, Str
rule %r/\\/, Str # stray backslash
end
state :macro do
mixin :include
rule %r([^/\n\\]+), Comment::Preproc
rule %r/\\./m, Comment::Preproc
mixin :inline_whitespace
rule %r(/), Comment::Preproc
# NB: pop! goes back to :bol
rule %r/\n/, Comment::Preproc, :pop!
end
state :include do
rule %r/(include)(\s*)(<[^>]+>)([^\n]*)/ do
groups Comment::Preproc, Text, Comment::PreprocFile, Comment::Single
end
rule %r/(include)(\s*)("[^"]+")([^\n]*)/ do
groups Comment::Preproc, Text, Comment::PreprocFile, Comment::Single
end
end
state :if_0 do
# NB: no \b here, to cover #ifdef and #ifndef
rule %r/^\s*#if/, Comment, :if_0
rule %r/^\s*#\s*el(?:se|if)/, Comment, :pop!
rule %r/^\s*#\s*endif\b.*?(?<!\\)\n/m, Comment, :pop!
rule %r/.*?\n/, Comment
end
end
end
end
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Ceylon < RegexLexer
tag 'ceylon'
filenames '*.ceylon'
mimetypes 'text/x-ceylon'
title "Ceylon"
desc 'Say more, more clearly.'
state :whitespace do
rule %r([^\S\n]+), Text
rule %r(//.*?\n), Comment::Single
rule %r(/\*), Comment::Multiline
end
state :root do
mixin :whitespace
rule %r((shared|abstract|formal|default|actual|variable|deprecated|small|
late|literal|doc|by|see|throws|optional|license|tagged|final|native|
annotation|sealed)\b), Name::Decorator
rule %r((break|case|catch|continue|else|finally|for|in|
if|return|switch|this|throw|try|while|is|exists|dynamic|
nonempty|then|outer|assert|let)\b), Keyword
rule %r((abstracts|extends|satisfies|super|given|of|out|assign)\b), Keyword::Declaration
rule %r((function|value|void|new)\b), Keyword::Type
rule %r((assembly|module|package)(\s+)) do
groups Keyword::Namespace, Text
push :import
end
rule %r((true|false|null)\b), Keyword::Constant
rule %r((class|interface|object|alias)(\s+)) do
groups Keyword::Declaration, Text
push :class
end
rule %r((import)(\s+)) do
groups Keyword::Namespace, Text
push :import
end
rule %r("(\\\\|\\"|[^"])*"), Literal::String
rule %r('\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'), Literal::String::Char
rule %r("[^`]*``[^`]*``[^`]*"), Literal::String::Interpol
rule %r((\.)([a-z_]\w*)) do
groups Operator, Name::Attribute
end
rule %r([a-zA-Z_]\w*:), Name::Label
rule %r((\\I[a-z]|[A-Z])\w*), Name::Decorator
rule %r([a-zA-Z_]\w*), Name
rule %r([~^*!%&\[\](){}<>|+=:;,./?`-]), Operator
rule %r(\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?), Literal::Number::Float
rule %r(\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?),
Literal::Number::Float
rule %r([0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?), Literal::Number::Float
rule %r([0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?),
Literal::Number::Float
rule %r(#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+), Literal::Number::Hex
rule %r(#[0-9a-fA-F]+), Literal::Number::Hex
rule %r(\$([01]{4})(_[01]{4})+), Literal::Number::Bin
rule %r(\$[01]+), Literal::Number::Bin
rule %r(\d{1,3}(_\d{3})+[kMGTP]?), Literal::Number::Integer
rule %r([0-9]+[kMGTP]?), Literal::Number::Integer
rule %r(\n), Text
end
state :class do
mixin :whitespace
rule %r([A-Za-z_]\w*), Name::Class, :pop!
end
state :import do
rule %r([a-z][\w.]*), Name::Namespace, :pop!
rule %r("(\\\\|\\"|[^"])*"), Literal::String, :pop!
end
state :comment do
rule %r([^*/]), Comment.Multiline
rule %r(/\*), Comment::Multiline, :push!
rule %r(\*/), Comment::Multiline, :pop!
rule %r([*/]), Comment::Multiline
end
end
end
end
@@ -0,0 +1,154 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Cfscript < RegexLexer
title "CFScript"
desc 'CFScript, the CFML scripting language'
tag 'cfscript'
aliases 'cfc'
filenames '*.cfc'
def self.keywords
@keywords ||= %w(
if else var xml default break switch do try catch throw in continue for return while required
)
end
def self.declarations
@declarations ||= %w(
component property function remote public package private
)
end
def self.types
@types ||= %w(
any array binary boolean component date guid numeric query string struct uuid void xml
)
end
constants = %w(application session client cookie super this variables arguments cgi)
operators = %w(\+\+ -- && \|\| <= >= < > == != mod eq lt gt lte gte not is and or xor eqv imp equal contains \? )
dotted_id = /[$a-zA-Z_][a-zA-Z0-9_.]*/
state :root do
mixin :comments_and_whitespace
rule %r/(?:#{operators.join('|')}|does not contain|greater than(?: or equal to)?|less than(?: or equal to)?)\b/i, Operator, :expr_start
rule %r([-<>+*%&|\^/!=]=?), Operator, :expr_start
rule %r/[(\[,]/, Punctuation, :expr_start
rule %r/;/, Punctuation, :statement
rule %r/[)\].]/, Punctuation
rule %r/[?]/ do
token Punctuation
push :ternary
push :expr_start
end
rule %r/[{}]/, Punctuation, :statement
rule %r/(?:#{constants.join('|')})\b/, Name::Constant
rule %r/(?:true|false|null)\b/, Keyword::Constant
rule %r/import\b/, Keyword::Namespace, :import
rule %r/(#{dotted_id})(\s*)(:)(\s*)/ do
groups Name, Text, Punctuation, Text
push :expr_start
end
rule %r/([A-Za-z_$][\w.]*)(\s*)(\()/ do |m|
if self.class.keywords.include? m[1]
token Keyword, m[1]
token Text, m[2]
token Punctuation, m[3]
else
token Name::Function, m[1]
token Text, m[2]
token Punctuation, m[3]
end
end
rule dotted_id do |m|
if self.class.declarations.include? m[0]
token Keyword::Declaration
push :expr_start
elsif self.class.keywords.include? m[0]
token Keyword
push :expr_start
elsif self.class.types.include? m[0]
token Keyword::Type
push :expr_start
else
token Name::Other
end
end
rule %r/[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
rule %r/0x[0-9a-fA-F]+/, Num::Hex
rule %r/[0-9]+/, Num::Integer
rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
end
# same as java, broken out
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
end
state :expr_start do
mixin :comments_and_whitespace
rule %r/[{]/, Punctuation, :object
rule %r//, Text, :pop!
end
state :statement do
rule %r/[{}]/, Punctuation
mixin :expr_start
end
# object literals
state :object do
mixin :comments_and_whitespace
rule %r/[}]/ do
token Punctuation
push :expr_start
end
rule %r/(#{dotted_id})(\s*)(:)/ do
groups Name::Other, Text, Punctuation
push :expr_start
end
rule %r/:/, Punctuation
mixin :root
end
# ternary expressions, where <dotted_id>: is not a label!
state :ternary do
rule %r/:/ do
token Punctuation
goto :expr_start
end
mixin :root
end
state :import do
rule %r/\s+/m, Text
rule %r/[a-z0-9_.]+\*?/i, Name::Namespace, :pop!
end
end
end
end
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# Based on/regexes mostly from Brandon Bennett's pygments-routerlexers:
# https://github.com/nemith/pygments-routerlexers
module Rouge
module Lexers
class CiscoIos < RegexLexer
title 'Cisco IOS'
desc 'Cisco IOS configuration lexer'
tag 'cisco_ios'
filenames '*.cfg'
mimetypes 'text/x-cisco-conf'
state :root do
rule %r/^!.*/, Comment::Single
rule %r/^(version\s+)(.*)$/ do
groups Keyword, Num::Float
end
rule %r/(desc*r*i*p*t*i*o*n*)(.*?)$/ do
groups Keyword, Comment::Single
end
rule %r/^(inte*r*f*a*c*e*|controller|router \S+|voice translation-\S+|voice-port|line)(.*)$/ do
groups Keyword::Type, Name::Function
end
rule %r/(password|secret)(\s+[57]\s+)(\S+)/ do
groups Keyword, Num, String::Double
end
rule %r/(permit|deny)/, Operator::Word
rule %r/^(banner\s+)(motd\s+|login\s+)([#$%])/ do
groups Keyword, Name::Function, Str::Delimiter
push :cisco_ios_text
end
rule %r/^(dial-peer\s+\S+\s+)(\S+)(.*?)$/ do
groups Keyword, Name::Attribute, Keyword
end
rule %r/^(vlan\s+)(\d+)$/ do
groups Keyword, Name::Attribute
end
# IPv4 Address/Prefix
rule %r/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/\d{1,2})?/, Num
# NSAP
rule %r/49\.\d{4}\.\d{4}\.\d{4}\.\d{4}\.\d{2}/, Num
# MAC Address
rule %r/[a-f0-9]{4}\.[a-f0-9]{4}\.[a-f0-9]{4}/, Num::Hex
rule %r/^(\s*no\s+)(\S+)/ do
groups Keyword::Constant, Keyword
end
rule %r/^[^\n\r]\s*\S+/, Keyword
# Obfuscated Passwords
rule %r/\*+/, Name::Entity
rule %r/(?<= )\d+(?= )/, Num
# Newline catcher, avoid errors on empty lines
rule %r/\n+/m, Text
# This one goes last, a text catch-all
rule %r/./, Text
end
state :cisco_ios_text do
rule %r/[^#$%]/, Text
rule %r/[#$%]/, Str::Delimiter, :pop!
end
end
end
end
@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Clean < RegexLexer
title "Clean"
desc "The Clean programming language (clean.cs.ru.nl)"
tag 'clean'
filenames '*.dcl', '*.icl'
def self.keywords
@keywords ||= Set.new %w(
if otherwise
let in
with where
case of
infix infixl infixr
class instance
generic derive
special
implementation definition system module
from import qualified as
dynamic
code inline foreign export ccall stdcall
)
end
# These are literal patterns common to the ABC intermediate language and
# Clean. Clean has more extensive literal patterns (see :basic below).
state :common_literals do
rule %r/'(?:[^'\\]|\\(?:x[0-9a-fA-F]+|\d+|.))'/, Str::Char
rule %r/[+~-]?\d+\.\d+(?:E[+-]?\d+)?\b/, Num::Float
rule %r/[+~-]?\d+E[+-]?\d+\b/, Num::Float
rule %r/[+~-]?\d+/, Num::Integer
rule %r/"/, Str::Double, :string
end
state :basic do
rule %r/\s+/m, Text::Whitespace
rule %r/\/\/\*.*/, Comment::Doc
rule %r/\/\/.*/, Comment::Single
rule %r/\/\*\*/, Comment::Doc, :comment_doc
rule %r/\/\*/, Comment::Multiline, :comment
rule %r/[+~-]?0[0-7]+/, Num::Oct
rule %r/[+~-]?0x[0-9a-fA-F]+/, Num::Hex
mixin :common_literals
rule %r/(\[)(\s*)(')(?=.*?'\])/ do
groups Punctuation, Text::Whitespace, Str::Single, Punctuation
push :charlist
end
end
# nested commenting
state :comment_doc do
rule %r/\*\//, Comment::Doc, :pop!
rule %r/\/\/.*/, Comment::Doc # Singleline comments in multiline comments are skipped
rule %r/\/\*/, Comment::Doc, :comment
rule %r/[^*\/]+/, Comment::Doc
rule %r/[*\/]/, Comment::Doc
end
# This is the same as the above, but with Multiline instead of Doc
state :comment do
rule %r/\*\//, Comment::Multiline, :pop!
rule %r/\/\/.*/, Comment::Multiline # Singleline comments in multiline comments are skipped
rule %r/\/\*/, Comment::Multiline, :comment
rule %r/[^*\/]+/, Comment::Multiline
rule %r/[*\/]/, Comment::Multiline
end
state :root do
mixin :basic
rule %r/code(\s+inline)?\s*{/, Comment::Preproc, :abc
rule %r/_*[a-z][\w`]*/ do |m|
if self.class.keywords.include?(m[0])
token Keyword
else
token Name
end
end
rule %r/_*[A-Z][\w`]*/ do |m|
if m[0]=='True' || m[0]=='False'
token Keyword::Constant
else
token Keyword::Type
end
end
rule %r/[^\w\s`]/, Punctuation
rule %r/_\b/, Punctuation
end
state :escapes do
rule %r/\\x[0-9a-fA-F]{1,2}/i, Str::Escape
rule %r/\\d\d{0,3}/i, Str::Escape
rule %r/\\0[0-7]{0,3}/, Str::Escape
rule %r/\\[0-7]{1,3}/, Str::Escape
rule %r/\\[nrfbtv\\"']/, Str::Escape
end
state :string do
rule %r/"/, Str::Double, :pop!
mixin :escapes
rule %r/[^\\"]+/, Str::Double
end
state :charlist do
rule %r/(')(\])/ do
groups Str::Single, Punctuation
pop!
end
mixin :escapes
rule %r/[^\\']/, Str::Single
end
state :abc_basic do
rule %r/\s+/, Text::Whitespace
rule %r/\|.*/, Comment::Single
mixin :common_literals
end
# The ABC intermediate language can be included, similar to C's inline
# assembly. For some information about ABC, see:
# https://en.wikipedia.org/wiki/Clean_(programming_language)#The_ABC-Machine
state :abc do
mixin :abc_basic
rule %r/}/, Comment::Preproc, :pop!
rule %r/\.\w*/, Keyword, :abc_rest_of_line
rule %r/[\w]+/, Name::Builtin, :abc_rest_of_line
end
state :abc_rest_of_line do
rule %r/\n/, Text::Whitespace, :pop!
rule %r/}/ do
token Comment::Preproc
pop!
pop!
end
mixin :abc_basic
rule %r/\S+/, Name
end
end
end
end
@@ -0,0 +1,113 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Clojure < RegexLexer
title "Clojure"
desc "The Clojure programming language (clojure.org)"
tag 'clojure'
aliases 'clj', 'cljs'
filenames '*.clj', '*.cljs', '*.cljc', 'build.boot', '*.edn'
mimetypes 'text/x-clojure', 'application/x-clojure'
def self.keywords
@keywords ||= Set.new %w(
fn def defn defmacro defmethod defmulti defn- defstruct if
cond let for
)
end
def self.builtins
@builtins ||= Set.new %w(
. .. * + - -> / < <= = == > >= accessor agent agent-errors
aget alength all-ns alter and append-child apply array-map
aset aset-boolean aset-byte aset-char aset-double aset-float
aset-int aset-long aset-short assert assoc await await-for bean
binding bit-and bit-not bit-or bit-shift-left bit-shift-right
bit-xor boolean branch? butlast byte cast char children
class clear-agent-errors comment commute comp comparator
complement concat conj cons constantly construct-proxy
contains? count create-ns create-struct cycle dec deref
difference disj dissoc distinct doall doc dorun doseq dosync
dotimes doto double down drop drop-while edit end? ensure eval
every? false? ffirst file-seq filter find find-doc find-ns
find-var first float flush fnseq frest gensym get-proxy-class
get hash-map hash-set identical? identity if-let import in-ns
inc index insert-child insert-left insert-right inspect-table
inspect-tree instance? int interleave intersection into
into-array iterate join key keys keyword keyword? last lazy-cat
lazy-cons left lefts line-seq list* list load load-file locking
long loop macroexpand macroexpand-1 make-array make-node map
map-invert map? mapcat max max-key memfn merge merge-with meta
min min-key name namespace neg? new newline next nil? node not
not-any? not-every? not= ns-imports ns-interns ns-map ns-name
ns-publics ns-refers ns-resolve ns-unmap nth nthrest or parse
partial path peek pop pos? pr pr-str print print-str println
println-str prn prn-str project proxy proxy-mappings quot
rand rand-int range re-find re-groups re-matcher re-matches
re-pattern re-seq read read-line reduce ref ref-set refer rem
remove remove-method remove-ns rename rename-keys repeat replace
replicate resolve rest resultset-seq reverse rfirst right
rights root rrest rseq second select select-keys send send-off
seq seq-zip seq? set short slurp some sort sort-by sorted-map
sorted-map-by sorted-set special-symbol? split-at split-with
str string? struct struct-map subs subvec symbol symbol?
sync take take-nth take-while test time to-array to-array-2d
tree-seq true? union up update-proxy val vals var-get var-set
var? vector vector-zip vector? when when-first when-let
when-not with-local-vars with-meta with-open with-out-str
xml-seq xml-zip zero? zipmap zipper'
)
end
identifier = %r([\w!$%*+,<=>?/.-]+)
keyword = %r([\w!\#$%*+,<=>?/.-]+)
def name_token(name)
return Keyword if self.class.keywords.include?(name)
return Name::Builtin if self.class.builtins.include?(name)
nil
end
state :root do
rule %r/;.*?$/, Comment::Single
rule %r/\s+/m, Text::Whitespace
rule %r/-?\d+\.\d+/, Num::Float
rule %r/-?\d+/, Num::Integer
rule %r/0x-?[0-9a-fA-F]+/, Num::Hex
rule %r/"(\\.|[^"])*"/, Str
rule %r/'#{keyword}/, Str::Symbol
rule %r/::?#{keyword}/, Name::Constant
rule %r/\\(.|[a-z]+)/i, Str::Char
rule %r/~@|[`\'#^~&@]/, Operator
rule %r/(\()(\s*)(#{identifier})/m do |m|
token Punctuation, m[1]
token Text::Whitespace, m[2]
token(name_token(m[3]) || Name::Function, m[3])
end
rule identifier do |m|
token name_token(m[0]) || Name
end
# vectors
rule %r/[\[\]]/, Punctuation
# maps
rule %r/[{}]/, Punctuation
# parentheses
rule %r/[()]/, Punctuation
end
end
end
end
@@ -0,0 +1,218 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CMake < RegexLexer
title 'CMake'
desc 'The cross-platform, open-source build system'
tag 'cmake'
filenames 'CMakeLists.txt', '*.cmake'
mimetypes 'text/x-cmake'
SPACE = '[ \t]'
BRACKET_OPEN = '\[=*\['
STATES_MAP = {
:root => Text,
:bracket_string => Str::Double,
:quoted_argument => Str::Double,
:bracket_comment => Comment::Multiline,
:variable_reference => Name::Variable,
}
BUILTIN_COMMANDS = Set.new %w[
add_compile_definitions
add_compile_options
add_custom_command
add_custom_target
add_definitions
add_dependencies
add_executable
add_library
add_link_options
add_subdirectory
add_test
aux_source_directory
break
build_command
build_name
cmake_host_system_information
cmake_language
cmake_minimum_required
cmake_parse_arguments
cmake_policy
configure_file
create_test_sourcelist
define_property
else
elseif
enable_language
enable_testing
endforeach
endfunction
endif
endmacro
endwhile
exec_program
execute_process
export
export_library_dependencies
file
find_file
find_library
find_package
find_path
find_program
fltk_wrap_ui
foreach
function
get_cmake_property
get_directory_property
get_filename_component
get_property
get_source_file_property
get_target_property
get_test_property
if
include
include_directories
include_external_msproject
include_guard
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
return
separate_arguments
set
set_directory_properties
set_property
set_source_files_properties
set_target_properties
set_tests_properties
site_name
source_group
string
subdir_depends
subdirs
target_compile_definitions
target_compile_features
target_compile_options
target_include_directories
target_link_directories
target_link_libraries
target_link_options
target_precompile_headers
target_sources
try_compile
try_run
unset
use_mangled_mesa
utility_source
variable_requires
variable_watch
while
write_file
]
state :default do
rule %r/\r\n?|\n/ do
token STATES_MAP[state.name.to_sym]
end
rule %r/./ do
token STATES_MAP[state.name.to_sym]
end
end
state :variable_interpolation do
rule %r/\$\{/ do
token Str::Interpol
push :variable_reference
end
end
state :bracket_close do
rule %r/\]=*\]/ do |m|
token STATES_MAP[state.name.to_sym]
goto :root if m[0].length == @bracket_len
end
end
state :root do
mixin :variable_interpolation
rule %r/#{SPACE}/, Text
rule %r/[()]/, Punctuation
rule %r/##{BRACKET_OPEN}/ do |m|
token Comment::Multiline
@bracket_len = m[0].length - 1 # decount '#'
goto :bracket_comment
end
rule %r/#{BRACKET_OPEN}/ do |m|
token Str::Double
@bracket_len = m[0].length
goto :bracket_string
end
rule %r/\\"/, Text
rule %r/"/, Str::Double, :quoted_argument
rule %r/([A-Za-z_][A-Za-z0-9_]*)(#{SPACE}*)(\()/ do |m|
groups BUILTIN_COMMANDS.include?(m[1]) ? Name::Builtin : Name::Function, Text, Punctuation
end
rule %r/#.*/, Comment::Single
mixin :default
end
state :bracket_string do
mixin :bracket_close
mixin :variable_interpolation
mixin :default
end
state :bracket_comment do
mixin :bracket_close
mixin :default
end
state :variable_reference do
mixin :variable_interpolation
rule %r/}/, Str::Interpol, :pop!
mixin :default
end
state :quoted_argument do
mixin :variable_interpolation
rule %r/"/, Str::Double, :root
rule %r/\\[()#" \\$@^trn;]/, Str::Escape
mixin :default
end
end
end
end
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CMHG < RegexLexer
title "CMHG"
desc "RISC OS C module header generator source file"
tag 'cmhg'
filenames '*.cmhg'
def self.preproc_keyword
@preproc_keyword ||= %w(
define elif else endif error if ifdef ifndef include line pragma undef warning
)
end
state :root do
rule %r/;[^\n]*/, Comment
rule %r/^([ \t]*)(#[ \t]*(?:(?:#{CMHG.preproc_keyword.join('|')})(?:[ \t].*)?)?)(?=\n)/ do
groups Text, Comment::Preproc
end
rule %r/[-a-z]+:/, Keyword::Declaration
rule %r/[a-z_]\w+/i, Name::Entity
rule %r/"[^"]*"/, Literal::String
rule %r/(?:&|0x)\h+/, Literal::Number::Hex
rule %r/\d+/, Literal::Number
rule %r/[,\/()]/, Punctuation
rule %r/[ \t]+/, Text
rule %r/\n+/, Text
end
end
end
end
@@ -0,0 +1,137 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class COBOL < RegexLexer
title 'COBOL'
desc 'COBOL (Common Business-Oriented Language) programming language'
tag 'cobol'
filenames '*.cob', '*.cbl', '*.cpy', '*.cpb'
mimetypes 'text/x-cobol'
identifier = /\p{Alpha}[\p{Alnum}-]*/
def self.divisions
@divisions ||= %w(
IDENTIFICATION ENVIRONMENT DATA PROCEDURE DIVISION
)
end
def self.sections
@sections ||= %w(
CONFIGURATION INPUT-OUTPUT FILE WORKING-STORAGE LOCAL-STORAGE LINKAGE SECTION
)
end
# List of COBOL keywords
# sourced from https://www.ibm.com/docs/en/cobol-zos/6.4?topic=appendixes-reserved-words
def self.keywords
@keywords ||= Set.new(%w(
ACCEPT ACCESS ACTIVE-CLASS ADD ADDRESS ADVANCING AFTER ALIGNED ALL ALLOCATE ALPHABET ALPHABETIC ALPHABETIC-LOWER
ALPHABETIC-UPPER ALPHANUMERIC ALPHANUMERIC-EDITED ALSO ALTER ALTERNATE AND ANYCASE ANY APPLY ARE AREA AREAS
ASCENDING ASSIGN AT AUTHOR B-AND B-NOT B-OR B-XOR BASED BASIS BEFORE BEGINNING BINARY BINARY-CHAR BINARY-DOUBLE
BINARY-LONG BINARY-SHORT BIT BLANK BLOCK BOOLEAN BOTTOM BY BYTE-LENGTH CALL CANCEL CBL CD CF CH CHARACTER
CHARACTERS CLASS CLASS-ID CLOCK-UNITS CLOSE COBOL CODE CODE-SET COL COLLATING COLS COLUMN COLUMNS COM-REG COMMA
COMMON COMMUNICATION COMP-1 COMP-2 COMP-3 COMP-4 COMP-5 COMP COMPUTATIONAL-1 COMPUTATIONAL-2
COMPUTATIONAL-3 COMPUTATIONAL-4 COMPUTATIONAL-5 COMPUTATIONAL COMPUTE CONDITION CONSTANT CONTAINS CONTENT
CONTINUE CONTROL CONTROLS CONVERTING COPY CORR CORRESPONDING COUNT CRT CURRENCY CURSOR DATA-POINTER DATE
DATE-COMPILED DATE-WRITTEN DAY DAY-OF-WEEK DBCS DE DEBUG-CONTENTS DEBUG-ITEM DEBUG-LINE DEBUG-NAME DEBUG-SUB-1
DEBUG-SUB-2 DEBUG-SUB-3 DEBUGGING DECIMAL-POINT DECLARATIVES DEFAULT DELETE DELIMITED DELIMITER DEPENDING
DESCENDING DESTINATION DETAIL DISABLE DISPLAY-1 DISPLAY DIVIDE DOWN DUPLICATES DYNAMIC EC EGCS EGI
EJECT ELSE EMI ENABLE END-ACCEPT END-ADD END-CALL END-COMPUTE END-DELETE END-DISPLAY END-DIVIDE END-EVALUATE
END-EXEC END-IF END-INVOKE END-JSON END-MULTIPLY END-OF-PAGE END-PERFORM END-READ END-RECEIVE END-RETURN
END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT END-UNSTRING END-WRITE END-XML ENDING END ENTER ENTRY
EO EOP EQUAL ERROR ESI EVALUATE EVERY EXCEPTION EXCEPTION-OBJECT EXEC EXECUTE EXIT EXTEND EXTERNAL
FACTORY FALSE FD FILE-CONTROL FILLER FINAL FIRST FLOAT-EXTENDED FLOAT-LONG FLOAT-SHORT FOOTING FOR FORMAT
FREE FROM FUNCTION FUNCTION-ID FUNCTION-POINTER GENERATE GET GIVING GLOBAL GO GOBACK GREATER GROUP GROUP-USAGE
HEADING HIGH-VALUE HIGH-VALUES I-O-CONTROL I-O ID IF IN INDEX INDEXED INDICATE INHERITS INITIAL
INITIALIZE INITIATE INPUT INSERT INSPECT INSTALLATION INTERFACE INTERFACE-ID INTO INVALID INVOKE
IS JAVA JNIENVPTR JSON JSON-CODE JSON-STATUS JUST JUSTIFIED KANJI KEY LABEL LAST LEADING LEFT LENGTH LESS LIMIT
LIMITS LINAGE-COUNTER LINAGE LINE-COUNTER LINES LINE LOCALE LOCK LOW-VALUE LOW-VALUES
MEMORY MERGE MESSAGE METHOD METHOD-ID MINUS MODE MODULES MORE-LABELS MOVE MULTIPLE MULTIPLY NATIONAL
NATIONAL-EDITED NATIVE NEGATIVE NESTED NEXT NO NOT NULL NULLS NUMBER NUMERIC NUMERIC-EDITED OBJECT
OBJECT-COMPUTER OBJECT-REFERENCE OCCURS OF OFF OMITTED ON OPEN OPTIONAL OPTIONS OR ORDER ORGANIZATION
OTHER OUTPUT OVERFLOW OVERRIDE PACKED-DECIMAL PADDING PAGE PAGE-COUNTER PASSWORD PERFORM PF PH PIC PICTURE
PLUS POINTER- POINTER-31 POINTER-32 POINTER-64 POINTER POSITION POSITIVE PRESENT PRINTING
PROCEDURE-POINTER PROCEDURES PROCEED PROCESSING PROGRAM-ID PROGRAM-POINTER PROGRAM PROPERTY PROTOTYPE
PURGE QUEUE QUOTE QUOTES RAISE RAISING RANDOM RD READ READY RECEIVE RECORD RECORDING RECORDS RECURSIVE REDEFINES
REEL REFERENCE REFERENCES RELATIVE RELEASE RELOAD REMAINDER REMOVAL RENAMES REPLACE REPLACING REPORT REPORTING
REPORTS REPOSITORY RERUN RESERVE RESET RESUME RETRY RETURN RETURN-CODE RETURNING REVERSED REWIND REWRITE RF RH
RIGHT ROUNDED RUN SAME SCREEN SD SEARCH SECTION SECURITY SEGMENT SEGMENT-LIMIT SELECT SELF SEND SENTENCE
SEPARATE SEQUENCE SEQUENTIAL SERVICE SET SHARING SHIFT-IN SHIFT-OUT SIGN SIZE SKIP1 SKIP2 SKIP3
SORT-CONTROL SORT-CORE-SIZE SORT-FILE-SIZE SORT-MERGE SORT-MESSAGE SORT-MODE-SIZE SORT-RETURN SORT
SOURCE-COMPUTER SOURCES SOURCE SPACE SPACES SPECIAL-NAMES SQL SQLIMS STANDARD-1 STANDARD-2 STANDARD START STATUS STOP
STRING SUB-QUEUE-1 SUB-QUEUE-2 SUB-QUEUE-3 SUBTRACT SUM SUPER SUPPRESS SYMBOLIC SYNC SYNCHRONIZED SYSTEM-DEFAULT
TABLE TALLY TALLYING TAPE TERMINAL TERMINATE TEST TEXT THAN THEN THROUGH THRU TIME TIMES TITLE TO TOP TRACE
TRAILING TRUE TYPE TYPEDEF UNIT UNIVERSAL UNLOCK UNSTRING UNTIL UP UPON USAGE USE USER-DEFAULT USING UTF-8
VAL-STATUS VALID VALIDATE VALIDATE-STATUS VALUE VALUES VARYING VOLATILE WHEN WHEN-COMPILED WITH WORDS
WRITE WRITE-ONLY XML-CODE XML-EVENT XML-INFORMATION XML-NAMESPACE XML-NAMESPACE-PREFIX
XML-NNAMESPACE XML-NNAMESPACE-PREFIX XML-NTEXT XML-SCHEMA XML-TEXT XML ZERO ZEROES ZEROS
))
end
state :root do
# First detect the comments
rule %r/^( \*).*|^(^Debug \*).*/, Comment::Special
# Strings
rule %r/"/, Str::Double, :string_double
rule %r/'/, Str::Single, :string_single
# Keywords and divisions
rule %r/(?<![\w-])#{identifier}(?![\w-])/i do |m|
if self.class.divisions.include?(m[0].upcase)
token Keyword::Declaration
elsif self.class.sections.include?(m[0].upcase)
token Keyword::Namespace
elsif self.class.keywords.include?(m[0].upcase)
token Keyword
else
token Name
end
end
# Numbers
rule %r/[-+]?\b\d+(\.\d+)?\b/, Num
# Punctuation
rule %r/[.,;:()]/, Punctuation
# Comments
rule %r/\*>.*/, Comment::Single
# Operators
rule %r/[+\-*\/><=]/, Operator
# Whitespace remaining
rule %r/\s/, Text::Whitespace
# Anything else remaining
rule %r/.+/, Text
end
# TODO double check string escaping in COBOL
# TODO Fix that a string opened by " can't be closed by '
# TODO Fix that strings can't be multi-line
# Handle strings where " opens a string and must be closed by "
state :string_double do
# Ensure strings can't span multiple lines
rule %r/[^"\\\n]+/, Str
rule %r/\\./, Str::Escape
rule %r/"/, Str::Double, :pop!
rule %r/\n/, Error # Flag an error if a string goes to the next line
end
# Handle strings where ' opens a string and must be closed by '
state :string_single do
# Ensure strings can't span multiple lines
rule %r/[^'\\\n]+/, Str
rule %r/\\./, Str::Escape
rule %r/'/, Str::Single, :pop!
rule %r/\n/, Error # Flag an error if a string goes to the next line
end
end
end
end
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Codeowners < RegexLexer
title 'CODEOWNERS'
desc 'Code Owners syntax (https://docs.gitlab.com/ee/user/project/codeowners/reference.html)'
tag 'codeowners'
filenames 'CODEOWNERS'
state :root do
rule %r/[ \t\r\n]+/, Text::Whitespace
rule %r/^\s*#.*$/, Comment::Single
rule %r(
(\^?\[(?!\d+\])[^\]]+\])
(\[\d+\])?
)x do
groups Name::Namespace, Literal::Number
end
rule %r/\S*@\S+/, Name::Function
rule %r/[\p{Word}\.\/\-\*]+/, Name
rule %r/.*\\[\#\s]/, Name
end
end
end
end
@@ -0,0 +1,215 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Coffeescript < RegexLexer
tag 'coffeescript'
aliases 'coffee', 'coffee-script'
filenames '*.coffee', 'Cakefile'
mimetypes 'text/coffeescript'
title "CoffeeScript"
desc 'The Coffeescript programming language (coffeescript.org)'
def self.detect?(text)
return true if text.shebang? 'coffee'
end
def self.keywords
@keywords ||= Set.new %w(
for by while until loop break continue return
switch when then if else do yield throw try catch finally await
new delete typeof instanceof super extends this class
import export debugger
)
end
def self.reserved
@reserved ||= Set.new %w(
case function var void with const let enum
native implements interface package private protected public static
)
end
def self.constants
@constants ||= Set.new %w(
true false yes no on off null NaN Infinity undefined
)
end
def self.builtins
@builtins ||= Set.new %w(
Array Boolean Date Error Function Math netscape Number Object
Packages RegExp String sun decodeURI decodeURIComponent
encodeURI encodeURIComponent eval isFinite isNaN parseFloat
parseInt document window
)
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
state :comments do
rule %r/###[^#].*?###/m, Comment::Multiline
rule %r/#.*$/, Comment::Single
end
state :whitespace do
rule %r/\s+/m, Text
end
state :regex_comment do
rule %r/^#(?!\{).*$/, Comment::Single
rule %r/(\s+)(#(?!\{).*)$/ do
groups Text, Comment::Single
end
end
state :multiline_regex_begin do
rule %r(///) do
token Str::Regex
goto :multiline_regex
end
end
state :multiline_regex_end do
rule %r(///([gimy]+\b|\B)), Str::Regex, :pop!
end
state :multiline_regex do
mixin :multiline_regex_end
mixin :regex_comment
mixin :has_interpolation
mixin :comments
mixin :whitespace
mixin :code_escape
rule %r/\\\D/, Str::Escape
rule %r/\\\d+/, Name::Variable
rule %r/./m, Str::Regex
end
state :slash_starts_regex do
mixin :comments
mixin :whitespace
mixin :multiline_regex_begin
rule %r(
/(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
([gimy]+\b|\B)
)x, Str::Regex, :pop!
rule(//) { pop! }
end
state :root do
rule(%r(^(?=\s|/|<!--))) { push :slash_starts_regex }
mixin :comments
mixin :whitespace
rule %r(
[+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\bin\b|\bof\b|
[?]|:|=|[|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
)x, Operator, :slash_starts_regex
rule %r/[-=]>/, Name::Function
rule %r/(@)([ \t]*)(#{id})/ do
groups Name::Variable::Instance, Text, Name::Attribute
push :slash_starts_regex
end
rule %r/([.])([ \t]*)(#{id})/ do
groups Punctuation, Text, Name::Attribute
push :slash_starts_regex
end
rule %r/#{id}(?=\s*:)/, Name::Attribute, :slash_starts_regex
rule %r/#{id}/ do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.constants.include? m[0]
token Name::Constant
elsif self.class.builtins.include? m[0]
token Name::Builtin
else
token Name::Other
end
push :slash_starts_regex
end
rule %r/[{(\[;,]/, Punctuation, :slash_starts_regex
rule %r/[})\].]/, Punctuation
rule %r/\d+[.]\d+([eE]\d+)?[fd]?/, Num::Float
rule %r/0x[0-9a-fA-F]+/, Num::Hex
rule %r/\d+/, Num::Integer
rule %r/"""/, Str, :tdqs
rule %r/'''/, Str, :tsqs
rule %r/"/, Str, :dqs
rule %r/'/, Str, :sqs
end
state :code_escape do
rule %r(\\(
c[A-Z]|
x[0-9a-fA-F]{2}|
u[0-9a-fA-F]{4}|
u\{[0-9a-fA-F]{4}\}
))x, Str::Escape
end
state :strings do
# all coffeescript strings are multi-line
rule %r/[^#\\'"]+/m, Str
mixin :code_escape
rule %r/\\./, Str::Escape
rule %r/#/, Str
end
state :double_strings do
rule %r/'/, Str
mixin :has_interpolation
mixin :strings
end
state :single_strings do
rule %r/"/, Str
mixin :strings
end
state :interpolation do
rule %r/}/, Str::Interpol, :pop!
mixin :root
end
state :has_interpolation do
rule %r/[#][{]/, Str::Interpol, :interpolation
end
state :dqs do
rule %r/"/, Str, :pop!
mixin :double_strings
end
state :tdqs do
rule %r/"""/, Str, :pop!
rule %r/"/, Str
mixin :double_strings
end
state :sqs do
rule %r/'/, Str, :pop!
mixin :single_strings
end
state :tsqs do
rule %r/'''/, Str, :pop!
rule %r/'/, Str
mixin :single_strings
end
end
end
end
@@ -0,0 +1,346 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CommonLisp < RegexLexer
title "Common Lisp"
desc "The Common Lisp variant of Lisp (common-lisp.net)"
tag 'common_lisp'
aliases 'cl', 'common-lisp', 'elisp', 'emacs-lisp', 'lisp'
filenames '*.cl', '*.lisp', '*.asd', '*.el' # used for Elisp too
mimetypes 'text/x-common-lisp'
# 638 functions
BUILTIN_FUNCTIONS = Set.new %w(
< <= = > >= - / /= * + 1- 1+ abort abs acons acos acosh add-method
adjoin adjustable-array-p adjust-array allocate-instance
alpha-char-p alphanumericp append apply apropos apropos-list
aref arithmetic-error-operands arithmetic-error-operation
array-dimension array-dimensions array-displacement
array-element-type array-has-fill-pointer-p array-in-bounds-p
arrayp array-rank array-row-major-index array-total-size
ash asin asinh assoc assoc-if assoc-if-not atan atanh atom
bit bit-and bit-andc1 bit-andc2 bit-eqv bit-ior bit-nand
bit-nor bit-not bit-orc1 bit-orc2 bit-vector-p bit-xor boole
both-case-p boundp break broadcast-stream-streams butlast
byte byte-position byte-size caaaar caaadr caaar caadar
caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
cadr call-next-method car cdaaar cdaadr cdaar cdadar cdaddr
cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr
ceiling cell-error-name cerror change-class char char< char<=
char= char> char>= char/= character characterp char-code
char-downcase char-equal char-greaterp char-int char-lessp
char-name char-not-equal char-not-greaterp char-not-lessp
char-upcase cis class-name class-of clear-input clear-output
close clrhash code-char coerce compile compiled-function-p
compile-file compile-file-pathname compiler-macro-function
complement complex complexp compute-applicable-methods
compute-restarts concatenate concatenated-stream-streams conjugate
cons consp constantly constantp continue copy-alist copy-list
copy-pprint-dispatch copy-readtable copy-seq copy-structure
copy-symbol copy-tree cos cosh count count-if count-if-not
decode-float decode-universal-time delete delete-duplicates
delete-file delete-if delete-if-not delete-package denominator
deposit-field describe describe-object digit-char digit-char-p
directory directory-namestring disassemble documentation dpb
dribble echo-stream-input-stream echo-stream-output-stream
ed eighth elt encode-universal-time endp enough-namestring
ensure-directories-exist ensure-generic-function eq
eql equal equalp error eval evenp every exp export expt
fboundp fceiling fdefinition ffloor fifth file-author
file-error-pathname file-length file-namestring file-position
file-string-length file-write-date fill fill-pointer find
find-all-symbols find-class find-if find-if-not find-method
find-package find-restart find-symbol finish-output first
float float-digits floatp float-precision float-radix
float-sign floor fmakunbound force-output format fourth
fresh-line fround ftruncate funcall function-keywords
function-lambda-expression functionp gcd gensym gentemp get
get-decoded-time get-dispatch-macro-character getf gethash
get-internal-real-time get-internal-run-time get-macro-character
get-output-stream-string get-properties get-setf-expansion
get-universal-time graphic-char-p hash-table-count hash-table-p
hash-table-rehash-size hash-table-rehash-threshold
hash-table-size hash-table-test host-namestring identity
imagpart import initialize-instance input-stream-p inspect
integer-decode-float integer-length integerp interactive-stream-p
intern intersection invalid-method-error invoke-debugger
invoke-restart invoke-restart-interactively isqrt keywordp
last lcm ldb ldb-test ldiff length lisp-implementation-type
lisp-implementation-version list list* list-all-packages listen
list-length listp load load-logical-pathname-translations
log logand logandc1 logandc2 logbitp logcount logeqv
logical-pathname logical-pathname-translations logior
lognand lognor lognot logorc1 logorc2 logtest logxor
long-site-name lower-case-p machine-instance machine-type
machine-version macroexpand macroexpand-1 macro-function
make-array make-broadcast-stream make-concatenated-stream
make-condition make-dispatch-macro-character make-echo-stream
make-hash-table make-instance make-instances-obsolete make-list
make-load-form make-load-form-saving-slots make-package
make-pathname make-random-state make-sequence make-string
make-string-input-stream make-string-output-stream make-symbol
make-synonym-stream make-two-way-stream makunbound map mapc
mapcan mapcar mapcon maphash map-into mapl maplist mask-field
max member member-if member-if-not merge merge-pathnames
method-combination-error method-qualifiers min minusp mismatch mod
muffle-warning name-char namestring nbutlast nconc next-method-p
nintersection ninth no-applicable-method no-next-method not notany
notevery nreconc nreverse nset-difference nset-exclusive-or
nstring-capitalize nstring-downcase nstring-upcase nsublis
nsubst nsubst-if nsubst-if-not nsubstitute nsubstitute-if
nsubstitute-if-not nth nthcdr null numberp numerator nunion
oddp open open-stream-p output-stream-p package-error-package
package-name package-nicknames packagep package-shadowing-symbols
package-used-by-list package-use-list pairlis parse-integer
parse-namestring pathname pathname-device pathname-directory
pathname-host pathname-match-p pathname-name pathnamep
pathname-type pathname-version peek-char phase plusp
position position-if position-if-not pprint pprint-dispatch
pprint-fill pprint-indent pprint-linear pprint-newline pprint-tab
pprint-tabular prin1 prin1-to-string princ princ-to-string print
print-object probe-file proclaim provide random random-state-p
rassoc rassoc-if rassoc-if-not rational rationalize rationalp
read read-byte read-char read-char-no-hang read-delimited-list
read-from-string read-line read-preserving-whitespace
read-sequence readtable-case readtablep realp realpart
reduce reinitialize-instance rem remhash remove
remove-duplicates remove-if remove-if-not remove-method
remprop rename-file rename-package replace require rest
restart-name revappend reverse room round row-major-aref
rplaca rplacd sbit scale-float schar search second set
set-difference set-dispatch-macro-character set-exclusive-or
set-macro-character set-pprint-dispatch set-syntax-from-char
seventh shadow shadowing-import shared-initialize
short-site-name signal signum simple-bit-vector-p
simple-condition-format-arguments simple-condition-format-control
simple-string-p simple-vector-p sin sinh sixth sleep slot-boundp
slot-exists-p slot-makunbound slot-missing slot-unbound slot-value
software-type software-version some sort special-operator-p
sqrt stable-sort standard-char-p store-value stream-element-type
stream-error-stream stream-external-format streamp string string<
string<= string= string> string>= string/= string-capitalize
string-downcase string-equal string-greaterp string-left-trim
string-lessp string-not-equal string-not-greaterp string-not-lessp
stringp string-right-trim string-trim string-upcase sublis subseq
subsetp subst subst-if subst-if-not substitute substitute-if
substitute-if-not subtypepsvref sxhash symbol-function
symbol-name symbolp symbol-package symbol-plist symbol-value
synonym-stream-symbol syntax: tailp tan tanh tenth terpri third
translate-logical-pathname translate-pathname tree-equal truename
truncate two-way-stream-input-stream two-way-stream-output-stream
type-error-datum type-error-expected-type type-of
typep unbound-slot-instance unexport unintern union
unread-char unuse-package update-instance-for-different-class
update-instance-for-redefined-class upgraded-array-element-type
upgraded-complex-part-type upper-case-p use-package
user-homedir-pathname use-value values values-list vector vectorp
vector-pop vector-push vector-push-extend warn wild-pathname-p
write write-byte write-char write-line write-sequence write-string
write-to-string yes-or-no-p y-or-n-p zerop
).freeze
SPECIAL_FORMS = Set.new %w(
block catch declare eval-when flet function go if labels lambda
let let* load-time-value locally macrolet multiple-value-call
multiple-value-prog1 progn progv quote return-from setq
symbol-macrolet tagbody the throw unwind-protect
)
MACROS = Set.new %w(
and assert call-method case ccase check-type cond ctypecase decf
declaim 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 defsystem deftype defun defvar
destructuring-bind do do* do-all-symbols do-external-symbols
dolist do-symbols dotimes ecase etypecase formatter
handler-bind handler-case ignore-errors incf in-package
lambda loop loop-finish make-method multiple-value-bind
multiple-value-list multiple-value-setq nth-value or pop
pprint-exit-if-list-exhausted pprint-logical-block pprint-pop
print-unreadable-object prog prog* prog1 prog2 psetf psetq
push pushnew remf restart-bind restart-case return rotatef
setf shiftf step time trace typecase unless untrace 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
)
LAMBDA_LIST_KEYWORDS = Set.new %w(
&allow-other-keys &aux &body &environment &key &optional &rest
&whole
)
DECLARATIONS = Set.new %w(
dynamic-extent ignore optimize ftype inline special ignorable
notinline type
)
BUILTIN_TYPES = Set.new %w(
atom boolean base-char base-string bignum bit compiled-function
extended-char fixnum keyword nil signed-byte short-float
single-float double-float long-float simple-array
simple-base-string simple-bit-vector simple-string simple-vector
standard-char unsigned-byte
arithmetic-error cell-error condition control-error
division-by-zero end-of-file error file-error
floating-point-inexact floating-point-overflow
floating-point-underflow floating-point-invalid-operation
parse-error package-error print-not-readable program-error
reader-error serious-condition simple-condition simple-error
simple-type-error simple-warning stream-error storage-condition
style-warning type-error unbound-variable unbound-slot
undefined-function warning
)
BUILTIN_CLASSES = Set.new %w(
array broadcast-stream bit-vector built-in-class character
class complex concatenated-stream cons echo-stream file-stream
float function generic-function hash-table integer list
logical-pathname method-combination method null number package
pathname ratio rational readtable real random-state restart
sequence standard-class standard-generic-function standard-method
standard-object string-stream stream string structure-class
structure-object symbol synonym-stream t two-way-stream vector
)
nonmacro = /\\.|[a-zA-Z0-9!$%&*+-\/<=>?@\[\]^_{}~]/
constituent = /#{nonmacro}|[#.:]/
terminated = /(?=[ "'()\n,;`])/ # whitespace or terminating macro chars
symbol = /(\|[^\|]+\||#{nonmacro}#{constituent}*)/
state :root do
rule %r/\s+/m, Text
rule %r/;.*$/, Comment::Single
rule %r/#\|/, Comment::Multiline, :multiline_comment
# encoding comment
rule %r/#\d*Y.*$/, Comment::Special
rule %r/"(\\.|[^"\\])*"/, Str
rule %r/[:']#{symbol}/, Str::Symbol
rule %r/['`]/, Operator
# numbers
rule %r/[-+]?\d+\.?#{terminated}/, Num::Integer
rule %r([-+]?\d+/\d+#{terminated}), Num::Integer
rule %r(
[-+]?
(\d*\.\d+([defls][-+]?\d+)?
|\d+(\.\d*)?[defls][-+]?\d+)
#{terminated}
)x, Num::Float
# sharpsign strings and characters
rule %r/#\\.#{terminated}/, Str::Char
rule %r/#\\#{symbol}/, Str::Char
rule %r/#\(/, Operator, :root
# bitstring
rule %r/#\d*\*[01]*/, Other
# uninterned symbol
rule %r/#:#{symbol}/, Str::Symbol
# read-time and load-time evaluation
rule %r/#[.,]/, Operator
# function shorthand
rule %r/#'/, Name::Function
# binary rational
rule %r/#b[+-]?[01]+(\/[01]+)?/i, Num
# octal rational
rule %r/#o[+-]?[0-7]+(\/[0-7]+)?/i, Num::Oct
# hex rational
rule %r/#x[+-]?[0-9a-f]+(\/[0-9a-f]+)?/i, Num
# complex
rule %r/(#c)(\()/i do
groups Num, Punctuation
push :root
end
# arrays and structures
rule %r/(#(?:\d+a|s))(\()/i do
groups Str::Other, Punctuation
push :root
end
# path
rule %r/#p?"(\\.|[^"])*"/i, Str::Symbol
# reference
rule %r/#\d+[=#]/, Operator
# read-time comment
rule %r/#+nil#{terminated}\s*\(/, Comment, :commented_form
# read-time conditional
rule %r/#[+-]/, Operator
# special operators that should have been parsed already
rule %r/(,@|,|\.)/, Operator
# special constants
rule %r/(t|nil)#{terminated}/, Name::Constant
# functions and variables
# note that these get filtered through in stream_tokens
rule %r/\*#{symbol}\*/, Name::Variable::Global
rule symbol do |m|
sym = m[0]
if BUILTIN_FUNCTIONS.include? sym
token Name::Builtin
elsif SPECIAL_FORMS.include? sym
token Keyword
elsif MACROS.include? sym
token Name::Builtin
elsif LAMBDA_LIST_KEYWORDS.include? sym
token Keyword
elsif DECLARATIONS.include? sym
token Keyword
elsif BUILTIN_TYPES.include? sym
token Keyword::Type
elsif BUILTIN_CLASSES.include? sym
token Name::Class
else
token Name::Variable
end
end
rule %r/\(/, Punctuation, :root
rule %r/\)/, Punctuation do
if stack.size == 1
token Error
else
token Punctuation
pop!
end
end
end
state :multiline_comment do
rule %r/#\|/, Comment::Multiline, :multiline_comment
rule %r/\|#/, Comment::Multiline, :pop!
rule %r/[^\|#]+/, Comment::Multiline
rule %r/[\|#]/, Comment::Multiline
end
state :commented_form do
rule %r/\(/, Comment, :commented_form
rule %r/\)/, Comment, :pop!
rule %r/[^()]+/, Comment
end
end
end
end
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Conf < RegexLexer
tag 'conf'
aliases 'config', 'configuration'
title "Config File"
desc 'A generic lexer for configuration files'
filenames '*.conf', '*.config'
# short and sweet
state :root do
rule %r/#.*?\n/, Comment
rule %r/".*?"/, Str::Double
rule %r/'.*?'/, Str::Single
rule %r/[a-z]\w*/i, Name
rule %r/\d+/, Num
rule %r/[^\w#"']+/, Text
end
end
end
end
@@ -0,0 +1,190 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
# The {ConsoleLexer} class is intended to lex content that represents the
# text that would display in a console/terminal. As distinct from the
# {Shell} lexer, {ConsoleLexer} will try to parse out the prompt from each
# line before passing the remainder of the line to the language lexer for
# the shell (by default, the {Shell} lexer).
#
# The {ConsoleLexer} class accepts five options:
# 1. **lang**: the shell language to lex (default: `shell`);
# 2. **output**: the output language (default: `plaintext?token=Generic.Output`);
# 3. **prompt**: comma-separated list of strings that indicate the end of a
# prompt (default: `$,#,>,;`);
# 4. **comments**: whether to enable comments.
# 5. **error**: comma-separated list of strings that indicate the start of an
# error message
#
# The comments option, if enabled, will lex lines that begin with a `#` as a
# comment. Please note that this option will only work if the prompt is
# either not manually specified or, if manually specified, does not include
# the `#` character.
#
# Most Markdown lexers that recognise GitHub-Flavored Markdown syntax, will
# pass the language string to Rouge as written in the original document.
# This allows an end user to pass options to {ConsoleLexer} by passing them
# as CGI-style parameters as in the example below.
#
# @example
# <pre>Here's some regular text.
#
# ```console?comments=true
# # This is a comment
# $ cp foo bar
# ```
#
# Some more regular text.</pre>
class ConsoleLexer < Lexer
tag 'console'
aliases 'terminal', 'shell_session', 'shell-session'
filenames '*.cap'
desc 'A generic lexer for shell sessions. Accepts ?lang and ?output lexer options, a ?prompt option, ?comments to enable # comments, and ?error to handle error messages.'
option :lang, 'the shell language to lex (default: shell)'
option :output, 'the output language (default: plaintext?token=Generic.Output)'
option :prompt, 'comma-separated list of strings that indicate the end of a prompt. (default: $,#,>,;)'
option :comments, 'enable hash-comments at the start of a line - otherwise interpreted as a prompt. (default: false, implied by ?prompt not containing `#`)'
option :error, 'comma-separated list of strings that indicate the start of an error message'
def initialize(*)
super
@prompt = list_option(:prompt) { nil }
@lang = lexer_option(:lang) { 'shell' }
@output = lexer_option(:output) { PlainText.new(token: Generic::Output) }
@comments = bool_option(:comments) { :guess }
@error = list_option(:error) { nil }
end
# whether to allow comments. if manually specifying a prompt that isn't
# simply "#", we flag this to on
def allow_comments?
case @comments
when :guess
@prompt && !@prompt.empty? && !end_chars.include?('#')
else
@comments
end
end
def comment_regex
/\A\s*?#/
end
def end_chars
@end_chars ||= if @prompt.any?
@prompt.reject { |c| c.empty? }
elsif allow_comments?
%w($ > ;)
else
%w($ # > ;)
end
end
def error_regex
@error_regex ||= if @error.any?
/^(?:#{@error.map(&Regexp.method(:escape)).join('|')})/
end
end
def lang_lexer
@lang_lexer ||= case @lang
when Lexer
@lang
when nil
Shell.new(options)
when Class
@lang.new(options)
when String
Lexer.find(@lang).new(options)
end
end
def line_regex
/(.*?)(\n|$)/
end
def output_lexer
@output_lexer ||= case @output
when nil
PlainText.new(token: Generic::Output)
when Lexer
@output
when Class
@output.new(options)
when String
Lexer.find(@output).new(options)
end
end
def process_line(input, &output)
input.scan(line_regex)
# As a nicety, support the use of elisions in input text. A user can
# write a line with only `<...>` or one or more `.` characters and
# Rouge will treat it as a comment.
if input[0] =~ /\A\s*(?:<[.]+>|[.]+)\s*\z/
puts "console: matched snip #{input[0].inspect}" if @debug
output_lexer.reset!
lang_lexer.reset!
yield Comment, input[0]
elsif prompt_regex =~ input[0]
puts "console: matched prompt #{input[0].inspect}" if @debug
output_lexer.reset!
yield Generic::Prompt, $&
# make sure to take care of initial whitespace
# before we pass to the lang lexer so it can determine where
# the "real" beginning of the line is
$' =~ /\A\s*/
yield Text::Whitespace, $& unless $&.empty?
lang_lexer.continue_lex($', &output)
elsif comment_regex =~ input[0].strip
puts "console: matched comment #{input[0].inspect}" if @debug
output_lexer.reset!
lang_lexer.reset!
yield Comment, input[0]
elsif error_regex =~ input[0]
puts "console: matched error #{input[0].inspect}" if @debug
output_lexer.reset!
lang_lexer.reset!
yield Generic::Error, input[0]
else
puts "console: matched output #{input[0].inspect}" if @debug
lang_lexer.reset!
output_lexer.continue_lex(input[0], &output)
end
end
def prompt_prefix_regex
if allow_comments?
/[^<#]*?/m
else
/.*?/m
end
end
def prompt_regex
@prompt_regex ||= begin
/^#{prompt_prefix_regex}(?:#{end_chars.map(&Regexp.method(:escape)).join('|')})/
end
end
def stream_tokens(input, &output)
input = StringScanner.new(input)
lang_lexer.reset!
output_lexer.reset!
process_line(input, &output) while !input.eos?
end
end
end
end
@@ -0,0 +1,255 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Coq < RegexLexer
title "Coq"
desc 'Coq (coq.inria.fr)'
tag 'coq'
mimetypes 'text/x-coq'
def self.gallina
@gallina ||= Set.new %w(
as fun if in let match then else return end Type Set Prop
forall
)
end
def self.coq
@coq ||= Set.new %w(
Definition Theorem Lemma Remark Example Fixpoint CoFixpoint
Record Inductive CoInductive Corollary Goal Proof
Ltac Require Import Export Module Section End Variable
Context Polymorphic Monomorphic Universe Universes
Variables Class Instance Global Local Include
Printing Notation Infix Arguments Hint Rewrite Immediate
Qed Defined Opaque Transparent Existing
Compute Eval Print SearchAbout Search About Check Admitted
)
end
def self.ltac
@ltac ||= Set.new %w(
apply eapply auto eauto rewrite setoid_rewrite
with in as at destruct split inversion injection
intro intros unfold fold cbv cbn lazy subst
clear symmetry transitivity etransitivity erewrite
edestruct constructor econstructor eexists exists
f_equal refine instantiate revert simpl
specialize generalize dependent red induction
beta iota zeta delta exfalso autorewrite setoid_rewrite
compute vm_compute native_compute
)
end
def self.tacticals
@tacticals ||= Set.new %w(
repeat first try
)
end
def self.terminators
@terminators ||= Set.new %w(
omega solve congruence reflexivity exact
assumption eassumption
)
end
def self.classify(x)
if self.coq.include? x
return Keyword
elsif self.gallina.include? x
return Keyword::Reserved
elsif self.ltac.include? x
return Keyword::Pseudo
elsif self.terminators.include? x
return Name::Exception
elsif self.tacticals.include? x
return Keyword::Pseudo
else
return Name::Constant
end
end
# https://github.com/coq/coq/blob/110921a449fcb830ec2a1cd07e3acc32319feae6/clib/unicode.ml#L67
# https://coq.inria.fr/refman/language/core/basic.html#grammar-token-ident
id_first = /\p{L}/
id_first_underscore = /(?:\p{L}|_)/
id_subsequent = /(?:\p{L}|\p{N}|_|')/ # a few missing? some mathematical ' primes and subscripts
id = /(?:#{id_first}#{id_subsequent}*)|(?:#{id_first_underscore}#{id_subsequent}+)/i
dot_id = /\.(#{id})/i
dot_space = /\.(\s+)/
state :root do
mixin :begin_proof
mixin :sentence
end
state :sentence do
mixin :comment_whitespace
mixin :module_setopts
# After parsing the id, end up in sentence_postid
rule id do |m|
@name = m[0]
@id_dotted = false
push :sentence_postid
push :continue_id
end
end
state :begin_proof do
rule %r/(Proof)(\s*)(\.)(\s+)/i do
groups Keyword, Text::Whitespace, Punctuation::Indicator, Text::Whitespace
push :proof_mode
end
end
state :proof_mode do
mixin :comment_whitespace
mixin :module_setopts
mixin :begin_proof
rule %r/(Qed|Defined|Save|Admitted)(\s*)(\.)(\s+)/i do
groups Keyword, Text::Whitespace, Punctuation::Indicator, Text::Whitespace
pop!
end
# the whole point of parsing Proof/Qed, normally some of these will be operators
rule %r/(?:\-+|\++|\*+)/, Punctuation
rule %r/[{}]/, Punctuation
# toplevel_selector
rule %r/(!|all|par)(:)/ do
groups Keyword::Pseudo, Punctuation
end
# numbered goals 1: {} 1,2: {}
rule %r/\d+/, Num::Integer, :numeric_labels
# [named_goal]: { ... }
rule %r/(\[)(\s*)(#{id})(\s*)(\])(\s*)(:)/ do
groups Punctuation, Text::Whitespace, Name::Constant, Text::Whitespace, Punctuation, Text::Whitespace, Punctuation
end
# After parsing the id, end up in sentence_postid
rule id do |m|
@name = m[0]
@id_dotted = false
push :sentence_postid
push :continue_id
end
end
state :numeric_labels do
mixin :whitespace
rule %r/(,)(\s*)(\d+)/ do
groups Punctuation, Text::Whitespace, Num::Integer
end
rule %r(:), Punctuation, :pop!
end
state :whitespace do
rule %r/\s+/m, Text::Whitespace
end
state :comment_whitespace do
rule %r/[(][*](?![)])/, Comment, :comment
mixin :whitespace
end
state :module_setopts do
rule %r/(Module)(\s+)(Type)(\s+)/ do
groups Keyword, Text::Whitespace, Keyword, Text::Whitespace
end
rule %r(
(Set|Unset)(\s+)
(Universe|Printing|Implicit|Strict)(\s+)
(Polymorphism|All|Notations|Arguments|Universes|Implicit)?(\s*)(\.)
)x do
groups Keyword, Text::Whitespace, Keyword, Text::Whitespace, Keyword, Text::Whitespace, Punctuation::Indicator
end
end
state :sentence_postid do
mixin :comment_whitespace
mixin :module_setopts
# up here to beat the id rule for lambda
rule %r(:=|=>|;|:>|:|::|_), Punctuation
rule %r(->|/\\|\\/|;|:>|[⇒→↔⇔≔≡∀∃∧∨¬⊤⊥⊢⊨∈λ]), Operator
rule id do |m|
@name = m[0]
@id_dotted = false
push :continue_id
end
# must be followed by whitespace, so that we don't match notations like sym.(a + b)
rule %r/\.(?=\s)/, Punctuation::Indicator, :pop! # :sentence_postid
rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
rule %r/-?\d[\d_]*/, Num::Integer
rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
rule %r/'/, Keyword
rule %r/"/, Str::Double, :string
rule %r/[~?]#{id}/, Name::Variable
rule %r(`{|[{}\[\]()?|;,.]), Punctuation
rule %r([!@^|~#.%/]+), Operator
# any other combo of S (symbol), P (punctuation) and some extras just to be sure
rule %r((?:\p{S}|\p{Pc}|[./\:\<=>\-+*])+), Operator
rule %r/./, Error
end
state :comment do
rule %r/[^(*)]+/, Comment
rule(/[(][*]/) { token Comment; push }
rule %r/[*][)]/, Comment, :pop!
rule %r/[(*)]/, Comment
end
state :string do
rule %r/[^"]+/, Str::Double
rule %r/""/, Str::Double
rule %r/"/, Str::Double, :pop!
end
state :continue_id do
# the stream starts with an id (stored in @name) and continues here
rule dot_id do |m|
token Name::Namespace, @name
token Punctuation, '.'
@id_dotted = true
@name = m[1]
end
rule dot_space do |m|
if @id_dotted
token Name::Constant, @name
else
token self.class.classify(@name), @name
end
token Punctuation::Indicator, '.'
token Text::Whitespace, m[1]
@name = false
@id_dotted = false
pop! # :continue_id
pop! # :sentence_postid
end
rule %r// do
if @id_dotted
token Name::Constant, @name
else
token self.class.classify(@name), @name
end
@name = false
@id_dotted = false
# we finished parsing an id, drop back into the sentence_postid that was pushed first.
pop! # :continue_id
end
end
end
end
end
@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'c.rb'
class Cpp < C
title "C++"
desc "The C++ programming language"
tag 'cpp'
aliases 'c++'
# the many varied filenames of c++ source files...
filenames '*.cpp', '*.hpp',
'*.c++', '*.h++',
'*.cc', '*.hh',
'*.cxx', '*.hxx',
'*.pde', '*.ino',
'*.tpp', '*.h'
mimetypes 'text/x-c++hdr', 'text/x-c++src'
def self.keywords
@keywords ||= super + Set.new(%w(
asm auto catch char8_t concept
consteval constexpr constinit const_cast co_await co_return co_yield
delete dynamic_cast explicit export friend
mutable namespace new operator private protected public
reinterpret_cast requires restrict size_of static_cast this throw throws
typeid typename using virtual final override import module
alignas alignof decltype noexcept static_assert
thread_local try
))
end
def self.keywords_type
@keywords_type ||= super + Set.new(%w(
bool
))
end
def self.reserved
@reserved ||= super + Set.new(%w(
__virtual_inheritance __uuidof __super __single_inheritance
__multiple_inheritance __interface __event
))
end
id = /[a-zA-Z_][a-zA-Z0-9_]*/
prepend :root do
# Offload C++ extensions, http://offload.codeplay.com/
rule %r/(?:__offload|__blockingoffload|__outer)\b/, Keyword::Pseudo
end
# digits with optional inner quotes
# see www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf
dq = /\d('?\d)*/
prepend :statements do
rule %r/(class|struct)\b/, Keyword, :classname
rule %r/template\b/, Keyword, :template
rule %r/#{dq}(\.#{dq})?(?:y|d|h|(?:min)|s|(?:ms)|(?:us)|(?:ns)|i|(?:if)|(?:il))\b/, Num::Other
rule %r((#{dq}[.]#{dq}?|[.]#{dq})([ep][+-]?#{dq})?[luf]*)i, Num::Float
rule %r(#{dq}[ep][+-]?#{dq}[luf]*)i, Num::Float
rule %r/0x\h('?\h)*([ep][+-]?#{dq})?[lu]*/i, Num::Hex
rule %r/0x\h('?\h)*[.]\h+([ep][+-]?#{dq})[luf]*/i, Num::Hex
rule %r/0b[01]+('[01]+)*/, Num::Bin
rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
rule %r/#{dq}[lu]*/i, Num::Integer
rule %r/\bnullptr\b/, Name::Builtin
rule %r/(?:u8|u|U|L)?R"([a-zA-Z0-9_{}\[\]#<>%:;.?*\+\-\/\^&|~!=,"']{,16})\(.*?\)\1"/m, Str
rule %r/(::|<=>)/, Operator
rule %r/[{]/, Punctuation
rule %r/}/ do
token Punctuation
pop! if in_state?(:function) # pop :function
end
end
state :classname do
rule id, Name::Class, :pop!
# template specification
mixin :whitespace
rule %r/[.]{3}/, Operator
rule %r/,/, Punctuation, :pop!
rule(//) { pop! }
end
state :template do
rule %r/[>;]/, Punctuation, :pop!
rule %r/typename\b/, Keyword, :classname
mixin :statements
end
state :case do
rule %r/:(?!:)/, Punctuation, :pop!
mixin :statements
end
end
end
end
@@ -0,0 +1,435 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Crystal < RegexLexer
title "Crystal"
desc "Crystal The Programming Language (crystal-lang.org)"
tag 'crystal'
aliases 'cr'
filenames '*.cr'
mimetypes 'text/x-crystal', 'application/x-crystal'
def self.detect?(text)
return true if text.shebang? 'crystal'
end
state :symbols do
# symbols
rule %r(
: # initial :
@{0,2} # optional ivar, for :@foo and :@@foo
[\p{Ll}_]\p{Word}*[!?]? # the symbol
)xi, Str::Symbol
# special symbols
rule %r(:(?:===|=?~|\[\][=?]?|\*\*=?|\/\/=?|[=^*/+-]=?|&[&*+-]?=?|\|\|?=?|![=~]?|%=?|<=>|<<?=?|>>?=?|\.\.\.?)), Str::Symbol
rule %r/:'(\\\\|\\'|[^'])*'/, Str::Symbol
rule %r/:"/, Str::Symbol, :simple_sym
end
state :sigil_strings do
# %-sigiled strings
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
rule %r/%([rqswQWxiI])?([^\p{Word}\s}])/ do |m|
open = Regexp.escape(m[2])
close = Regexp.escape(delimiter_map[m[2]] || m[2])
interp = /[rQWxI]/ === m[1]
toktype = Str::Other
puts " open: #{open.inspect}" if @debug
puts " close: #{close.inspect}" if @debug
# regexes
if m[1] == 'r'
toktype = Str::Regex
push :regex_flags
end
token toktype
push do
rule %r/\\[##{open}#{close}\\]/, Str::Escape
# nesting rules only with asymmetric delimiters
if open != close
rule %r/#{open}/ do
token toktype
push
end
end
rule %r/#{close}/, toktype, :pop!
if interp
mixin :string_intp_escaped
rule %r/#/, toktype
else
rule %r/[\\#]/, toktype
end
rule %r/[^##{open}#{close}\\]+/m, toktype
end
end
end
state :strings do
mixin :symbols
rule %r/\b[\p{Ll}_]\p{Word}*?[?!]?:\s+/, Str::Symbol, :expr_start
rule %r/"/, Str::Double, :simple_string
rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
rule %r/(')(\\u[a-fA-F0-9]{4}|\\u\{[a-fA-F0-9]{1,6}\}|\\[abefnrtv])?(\\\\|\\'|[^'])*(')/ do
groups Str::Single, Str::Escape, Str::Single, Str::Single
end
end
state :regex_flags do
rule %r/[mixounse]*/, Str::Regex, :pop!
end
# double-quoted string and symbol
[[:string, Str::Double, '"'],
[:sym, Str::Symbol, '"'],
[:backtick, Str::Backtick, '`']].each do |name, tok, fin|
state :"simple_#{name}" do
mixin :string_intp_escaped
rule %r/[^\\#{fin}#]+/m, tok
rule %r/[\\#]/, tok
rule %r/#{fin}/, tok, :pop!
end
end
keywords = %w(
BEGIN END alias begin break case defined\? do else elsif end
ensure for if ifdef in next redo rescue raise retry return super then
undef unless until when while yield lib fun type of as
)
keywords_pseudo = %w(
initialize new loop include extend raise attr_reader attr_writer
attr_accessor alias_method attr catch throw private module_function
public protected true false nil __FILE__ __LINE__
getter getter? getter! property property? property! struct record
)
builtins_g = %w(
abort ancestors at_exit
caller catch chomp chop clone constants
display dup eval exec exit extend fail fork format freeze
getc gets global_variables gsub hash id included_modules
inspect instance_eval instance_method instance_methods
lambda loop method method_missing
methods module_eval name object_id open p print printf
proc putc puts raise rand
readline readlines require scan select self send
sleep split sprintf srand sub syscall system
test throw to_a to_s trap warn
)
builtins_q = %w(
eql equal include is_a iterator kind_of nil
)
builtins_b = %w(chomp chop exit gsub sub)
start do
push :expr_start
@heredoc_queue = []
end
state :whitespace do
mixin :inline_whitespace
rule %r/\n\s*/m, Text, :expr_start
rule %r/#.*$/, Comment::Single
rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
end
state :inline_whitespace do
rule %r/[ \t\r]+/, Text
end
state :root do
mixin :whitespace
rule %r/__END__/, Comment::Preproc, :end_part
rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
rule %r/\d+\.\d+(e[\+\-]?\d+)?(_f32)?/i, Num::Float
rule %r/\d+(e[\+\-]?\d+)/i, Num::Float
rule %r/\d+_f32/i, Num::Float
rule %r/[\d]+(?:_\d+)*(_[iu]\d+)?/, Num::Integer
rule %r/@\[([^\]]+)\]/, Name::Decorator
# names
rule %r/@@[\p{Ll}_]\p{Word}*/i, Name::Variable::Class
rule %r/@[\p{Ll}_]\p{Word}*/i, Name::Variable::Instance
rule %r/\$\p{Word}+/, Name::Variable::Global
rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
rule %r/::/, Operator
mixin :strings
rule %r/(?:#{keywords.join('|')})\b/, Keyword, :expr_start
rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
rule %r(
(module)
(\s+)
([\p{L}_][\p{L}0-9_]*(::[\p{L}_][\p{L}0-9_]*)*)
)x do
groups Keyword, Text, Name::Namespace
end
rule %r/(def|macro\b)(\s*)/ do
groups Keyword, Text
push :funcname
end
rule %r/(class\b)(\s*)/ do
groups Keyword, Text
push :classname
end
rule %r/(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
rule %r/(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
rule %r/(?<!\.)(?:#{builtins_g.join('|')})\b/,
Name::Builtin, :method_call
mixin :has_heredocs
# `..` and `...` for ranges must have higher priority than `.`
# Otherwise, they will be parsed as :method_call
rule %r/\.{2,3}/, Operator, :expr_start
rule %r/[\p{Lu}][\p{L}0-9_]*/, Name::Constant, :method_call
rule %r/(\.|::)(\s*)([\p{Ll}_]\p{Word}*[!?]?|[*%&^`~+-\/\[<>=])/ do
groups Punctuation, Text, Name::Function
push :method_call
end
rule %r/[\p{L}_]\p{Word}*[?!]/, Name, :expr_start
rule %r/[\p{L}_]\p{Word}*/, Name, :method_call
rule %r/\*\*|\/\/|>=|<=|<=>|<<?|>>?|=~|={3}|!~|&&?|\|\||\./,
Operator, :expr_start
rule %r/{%|%}/, Punctuation
rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
rule %r<[\])}]>, Punctuation
end
state :has_heredocs do
rule %r/(?<!\p{Word})(<<[-~]?)(["`']?)([\p{L}_]\p{Word}*)(\2)/ do |m|
token Operator, m[1]
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
push :heredoc_queue unless state? :heredoc_queue
end
rule %r/(<<[-~]?)(["'])(\2)/ do |m|
token Operator, m[1]
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
push :heredoc_queue unless state? :heredoc_queue
end
end
state :heredoc_queue do
rule %r/(?=\n)/ do
goto :resolve_heredocs
end
mixin :root
end
state :resolve_heredocs do
mixin :string_intp_escaped
rule %r/\n/, Str::Heredoc, :test_heredoc
rule %r/[#\\\n]/, Str::Heredoc
rule %r/[^#\\\n]+/, Str::Heredoc
end
state :test_heredoc do
rule %r/[^#\\\n]*$/ do |m|
tolerant, heredoc_name = @heredoc_queue.first
check = tolerant ? m[0].strip : m[0].rstrip
# check if we found the end of the heredoc
puts " end heredoc check #{check.inspect} = #{heredoc_name.inspect}" if @debug
if check == heredoc_name
@heredoc_queue.shift
# if there's no more, we're done looking.
pop! if @heredoc_queue.empty?
token Name::Constant
else
token Str::Heredoc
end
pop!
end
rule(//) { pop! }
end
state :funcname do
rule %r/\s+/, Text
rule %r/\(/, Punctuation, :defexpr
rule %r(
(?:([\p{L}_]\p{Word}*)(\.))?
(
[\p{L}_]\p{Word}*[!?]? |
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
<<? | >>? | <=>? | >= | ===?
)
)x do |m|
puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
groups Name::Class, Operator, Name::Function
pop!
end
rule(//) { pop! }
end
state :classname do
rule %r/\s+/, Text
rule %r/\(/ do
token Punctuation
push :defexpr
push :expr_start
end
# class << expr
rule %r/<</ do
token Operator
goto :expr_start
end
rule %r/[\p{Lu}_]\p{Word}*/, Name::Class, :pop!
rule(//) { pop! }
end
state :ternary do
rule(/:(?!:)/) { token Punctuation; goto :expr_start }
mixin :root
end
state :defexpr do
rule %r/(\))(\.|::)?/ do
groups Punctuation, Operator
pop!
end
rule %r/\(/ do
token Punctuation
push :defexpr
push :expr_start
end
mixin :root
end
state :in_interp do
rule %r/}/, Str::Interpol, :pop!
mixin :root
end
state :string_intp do
rule %r/[#][{]/, Str::Interpol, :in_interp
rule %r/#(@@?|\$)[\p{Ll}_]\p{Word}*/i, Str::Interpol
end
state :string_intp_escaped do
mixin :string_intp
rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
Str::Escape
rule %r/\\u([a-fA-F0-9]{4}|\{[^}]+\})/, Str::Escape
rule %r/\\./, Str::Escape
end
state :method_call do
rule %r(/) do
token Operator
goto :expr_start
end
rule(/(?=\n)/) { pop! }
rule(//) { goto :method_call_spaced }
end
state :method_call_spaced do
mixin :whitespace
rule %r([%/]=) do
token Operator
goto :expr_start
end
rule %r((/)(?=\S|\s*/)) do
token Str::Regex
goto :slash_regex
end
mixin :sigil_strings
rule(%r((?=\s*/))) { pop! }
rule(/\s+/) { token Text; goto :expr_start }
rule(//) { pop! }
end
state :expr_start do
mixin :inline_whitespace
rule %r(/) do
token Str::Regex
goto :slash_regex
end
# char operator. ?x evaulates to "x", unless there's a digit
# beforehand like x>=0?n[x]:""
rule %r(
[?](\\[MC]-)* # modifiers
(\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
(?!\p{Word})
)x, Str::Char, :pop!
# special case for using a single space. Ruby demands that
# these be in a single line, otherwise it would make no sense.
rule %r/(\s*)(%[rqswQWxiI]? \S* )/ do
groups Text, Str::Other
pop!
end
mixin :sigil_strings
rule(//) { pop! }
end
state :slash_regex do
mixin :string_intp
rule %r(\\\\), Str::Regex
rule %r(\\/), Str::Regex
rule %r([\\#]), Str::Regex
rule %r([^\\/#]+)m, Str::Regex
rule %r(/) do
token Str::Regex
goto :regex_flags
end
end
state :end_part do
# eat up the rest of the stream as Comment::Preproc
rule %r/.+/m, Comment::Preproc, :pop!
end
end
end
end
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CSharp < RegexLexer
tag 'csharp'
aliases 'c#', 'cs'
filenames '*.cs'
mimetypes 'text/x-csharp'
title "C#"
desc 'a multi-paradigm language targeting .NET'
id = /@?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}][\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*/
# Reserved Identifiers
# Contextual Keywords
# LINQ Query Expressions
def self.keywords
@keywords ||= %w(
abstract add alias and as ascending async await base
break by case catch checked const continue default delegate
descending do else enum equals event explicit extern false
finally fixed for foreach from get global goto group
if implicit in init interface internal into is join
let lock nameof new notnull null on operator orderby
out override params partial private protected public readonly
ref remove return sealed set sizeof stackalloc static
switch this throw true try typeof unchecked unsafe
unmanaged value virtual void volatile when where while
with yield
)
end
def self.keywords_type
@keywords_type ||= %w(
bool byte char decimal double dynamic float int long nint nuint
object sbyte short string uint ulong ushort var
)
end
def self.cpp_keywords
@cpp_keywords ||= %w(
if endif else elif define undef line error warning region
endregion pragma nullable
)
end
state :whitespace do
rule %r/\s+/m, Text
rule %r(//.*?$), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline
end
state :nest do
rule %r/{/, Punctuation, :nest
rule %r/}/, Punctuation, :pop!
mixin :root
end
state :splice_string do
rule %r/\\./, Str
rule %r/{/, Punctuation, :nest
rule %r/"|\n/, Str, :pop!
rule %r/./, Str
end
state :splice_literal do
rule %r/""/, Str
rule %r/{/, Punctuation, :nest
rule %r/"/, Str, :pop!
rule %r/./, Str
end
state :root do
mixin :whitespace
rule %r/[$]\s*"/, Str, :splice_string
rule %r/[$]@\s*"/, Str, :splice_literal
rule %r/(<\[)\s*(#{id}:)?/, Keyword
rule %r/\]>/, Keyword
rule %r/[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, Punctuation
rule %r/@"(""|[^"])*"/m, Str
rule %r/"(\\.|.)*?["\n]/, Str
rule %r/'(\\.|.)'/, Str::Char
rule %r/0b[_01]+[lu]?/i, Num
rule %r/0x[_0-9a-f]+[lu]?/i, Num
rule %r(
[0-9](?:[_0-9]*[0-9])?
([.][0-9](?:[_0-9]*[0-9])?)? # decimal
(e[+-]?[0-9](?:[_0-9]*[0-9])?)? # exponent
[fldum]? # type
)ix, Num
rule %r/\b(?:class|record|struct|interface)\b/, Keyword, :class
rule %r/\b(?:namespace|using)\b/, Keyword, :namespace
rule %r/^#[ \t]*(#{CSharp.cpp_keywords.join('|')})\b.*?\n/, Comment::Preproc
rule %r/\b(#{CSharp.keywords.join('|')})\b/, Keyword
rule %r/\b(#{CSharp.keywords_type.join('|')})\b/, Keyword::Type
rule %r/#{id}(?=\s*[(])/, Name::Function
rule id, Name
end
state :class do
mixin :whitespace
rule id, Name::Class, :pop!
end
state :namespace do
mixin :whitespace
rule %r/(?=[(])/, Text, :pop!
rule %r/(#{id}|[.])+/, Name::Namespace, :pop!
end
end
end
end
@@ -0,0 +1,318 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CSS < RegexLexer
title "CSS"
desc "Cascading Style Sheets, used to style web pages"
tag 'css'
filenames '*.css'
mimetypes 'text/css'
# Documentation: https://www.w3.org/TR/CSS21/syndata.html#characters
identifier = /[\p{L}_-][\p{Word}\p{Cf}-]*/
number = /-?(?:[0-9]+(\.[0-9]+)?|\.[0-9]+)/
def self.properties
@properties ||= Set.new %w(
additive-symbols align-content align-items align-self
alignment-adjust alignment-baseline all anchor-point animation
animation-composition animation-delay animation-direction
animation-duration animation-fill-mode animation-iteration-count
animation-name animation-play-state animation-timing-function
appearance aspect-ratio azimuth backface-visibility background
background-attachment background-blend-mode
background-clip background-color background-image
background-origin background-position
background-repeat background-size baseline-shift
binding bleed bookmark-label bookmark-level bookmark-state
bookmark-target border border-bottom border-bottom-color
border-bottom-left-radius border-bottom-right-radius
border-bottom-style border-bottom-width border-collapse
border-color border-image border-image-outset border-image-repeat
border-image-slice border-image-source border-image-width
border-left border-left-color border-left-style border-left-width
border-radius border-right border-right-color border-right-style
border-right-width border-spacing border-style border-top
border-top-color border-top-left-radius border-top-right-radius
border-top-style border-top-width border-width bottom box-align
box-decoration-break box-direction box-flex box-flex-group
box-lines box-ordinal-group box-orient box-pack box-shadow
box-sizing break-after break-before break-inside caption-side
clear clip clip-path clip-rule color color-profile column-count
column-fill column-gap column-rule column-rule-color
column-rule-style column-rule-width column-span column-width
columns content container container-name container-type
counter-increment counter-reset counter-set crop cue
cue-after cue-before cursor direction display dominant-baseline
drop-initial-after-adjust drop-initial-after-align
drop-initial-before-adjust drop-initial-before-align
drop-initial-size drop-initial-value elevation empty-cells fallback
filter fit fit-position flex flex-basis flex-direction flex-flow
flex-grow flex-shrink flex-wrap float float-offset font
font-display font-family font-feature-settings font-kerning
font-language-override font-size font-size-adjust font-stretch
font-style font-synthesis font-variant font-variant-alternates
font-variant-caps font-variant-east-asian font-variant-ligatures
font-variant-numeric font-variant-position font-weight gap
grid-area grid-auto-columns grid-auto-flow grid-auto-rows
grid-column grid-column-end grid-column-start grid-row
grid-row-end grid-row-start grid-template grid-template-areas
grid-template-columns grid-template-rows hanging-punctuation
height hyphenate-after hyphenate-before hyphenate-character
hyphenate-lines hyphenate-resource hyphens icon image-orientation
image-rendering image-resolution ime-mode inherits initial-value
inline-box-align inset isolation justify-content justify-items
justify-self left letter-spacing line-break line-height
line-stacking line-stacking-ruby line-stacking-shift
line-stacking-strategy list-style list-style-image
list-style-position list-style-type margin margin-bottom
margin-left margin-right margin-top mark mark-after mark-before
marker-offset marks marquee-direction marquee-loop
marquee-play-count marquee-speed marquee-style
mask mask-clip mask-composite mask-image mask-mode
mask-origin mask-position mask-repeat mask-size mask-type
max-height max-width min-height min-width mix-blend-mode
move-to nav-down nav-index nav-left nav-right nav-up negative
object-fit object-position offset offset-anchor offset-distance
offset-path offset-position offset-rotate opacity order orphans
outline outline-color outline-offset outline-style outline-width
overflow overflow-style overflow-wrap overflow-x overflow-y pad
padding padding-bottom padding-left padding-right padding-top page
page-break-after page-break-before page-break-inside page-policy
pause pause-after pause-before perspective perspective-origin
phonemes pitch pitch-range place-content place-items place-self
play-during pointer-events position prefix presentation-level
punctuation-trim quotes range rendering-intent resize rest
rest-after rest-before richness right rotate rotation rotation-point
row-gap ruby-align ruby-overhang ruby-position ruby-span scale
scroll-behavior scroll-margin scroll-margin-block
scroll-margin-block-end scroll-margin-block-start
scroll-margin-bottom scroll-margin-inline scroll-margin-inline-end
scroll-margin-inline-start scroll-margin-left scroll-margin-right
scroll-margin-top scroll-padding-top scroll-padding-right
scroll-padding-bottom scroll-padding-left scroll-padding
scroll-padding-block-end scroll-padding-block-start
scroll-padding-block scroll-padding-inline-end
scroll-padding-inline-start scroll-padding-inline
scroll-snap-type scroll-snap-align scroll-snap-stop
shape-outside shape-margin shape-image-threshold shape-rendering
size speak speak-as speak-header speak-numeral speak-punctuation
speech-rate src stress string-set suffix symbols syntax system
tab-size table-layout target target-name target-new target-position
text-align text-align-last text-combine-horizontal
text-decoration text-decoration-color text-decoration-line
text-decoration-skip text-decoration-style text-emphasis
text-emphasis-color text-emphasis-position text-emphasis-style
text-height text-indent text-justify text-orientation
text-outline text-overflow text-rendering text-shadow
text-space-collapse text-transform text-underline-position
text-wrap top transform transform-origin transform-style
transition transition-delay transition-duration
transition-property transition-timing-function translate
unicode-bidi vertical-align visibility voice-balance
voice-duration voice-family voice-pitch voice-pitch-range
voice-range voice-rate voice-stress voice-volume volume
white-space widows width word-break word-spacing word-wrap
writing-mode z-index
)
end
def self.builtins
@builtins ||= Set.new %w(
above absolute accumulate add additive all alpha alphabetic
alternate alternate-reverse always armenian aural auto auto-fill
auto-fit avoid backwards balance baseline behind below bidi-override
blink block bold bolder border-box both bottom bottom break-spaces
capitalize center center-left center-right circle cjk-ideographic
close-quote closest-corner closest-side collapse
color color-burn color-dodge column column-reverse
condensed contain content content-box continuous cover crop cross
crosshair cursive cyclic darken dashed decimal decimal-leading-zero
default difference digits disc dotted double e-resize
ease ease-in ease-in-out ease-out embed end exclude exclusion
expanded extends extra-condensed extra-expanded fantasy
farthest-corner farthest-side far-left far-right
fast faster fill fixed flat flex flex-end flex-start
forwards georgian grid groove hard-light hebrew help hidden
hide high higher hiragana hiragana-iroha horizontal hue icon
infinite inherit inline inline-block inline-flex inline-grid
inline-size inline-table inset inside intersect isolate italic
justify katakana katakana-iroha landscape large larger left
left-side leftwards level lighten lighter line-through linear
list-item loud low lower lower-alpha lower-greek lower-roman
lowercase ltr luminance luminosity mandatory match-source medium
message-box middle mix monospace multiply n-resize narrower
ne-resize no-close-quote no-open-quote no-repeat none normal
nowrap numeric nw-resize oblique once open-quote outset outside
overlay overline paused pointer portrait pre preserve-3d pre-line
pre-wrap proximity px relative repeat-x repeat-y replace reverse
ridge right right-side rightwards row row-reverse rtl running
s-resize sans-serif saturation scale-down screen scroll
se-resize semi-condensed semi-expanded separate serif show
sides silent size slow slower small-caps small-caption smaller
smooth soft soft-light solid space-around space-between
space-evenly span spell-out square start static status-bar sticky
stretch sub subtract super sw-resize swap symbolic table
table-caption table-cell table-column table-column-group
table-footer-group table-header-group table-row table-row-group
text text-bottom text-top thick thin top transparent
ultra-condensed ultra-expanded underline upper-alpha upper-latin
upper-roman uppercase vertical visible w-resize wait wider wrap
wrap-reverse x x-fast x-high x-large x-loud x-low x-small x-soft
xx-large xx-small yes y z
)
end
def self.colors
@colors ||= Set.new %w(
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 darkkhaki
darkmagenta darkolivegreen darkorange darkorchid darkred
darksalmon darkseagreen darkslateblue darkslategray darkturquoise
darkviolet deeppink deepskyblue dimgray dodgerblue firebrick
floralwhite forestgreen fuchsia gainsboro ghostwhite gold
goldenrod gray green greenyellow honeydew hotpink indianred
indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon
lightblue lightcoral lightcyan lightgoldenrodyellow lightgreen
lightgrey lightpink lightsalmon lightseagreen lightskyblue
lightslategray 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 red rosybrown royalblue saddlebrown salmon sandybrown
seagreen seashell sienna silver skyblue slateblue slategray snow
springgreen steelblue tan teal thistle tomato
turquoise violet wheat white whitesmoke yellow yellowgreen
)
end
def self.functions
@functions ||= Set.new %w(
abs acos annotation asin atan atan2 attr blur brightness calc
character-variant circle clamp color color-mix conic-gradient
contrast cos counter counters cubic-bezier drop-shadow ellipse
env exp fit-content format grayscale hsl hsla hue-rotate hwb hypot
image-set inset invert lab lch linear linear-gradient log matrix
matrix3d max min minmax mod oklab oklch opacity ornaments path
perspective polygon pow radial-gradient ray rect rem repeat
repeating-conic-gradient repeating-linear-gradient
repeating-radial-gradient rgb rgba rotate rotate3d rotatex
rotatey rotatez round saturate scale scale3d scalex scaley scalez
sepia sign sin skewx skewy sqrt steps styleset
stylistic swash tan translate translate3d translatex translatey
translatez url var xywh
)
end
# source: http://www.w3.org/TR/CSS21/syndata.html#vendor-keyword-history
def self.vendor_prefixes
@vendor_prefixes ||= Set.new %w(
-ah- -atsc- -hp- -khtml- -moz- -ms- -o- -rim- -ro- -tc- -wap-
-webkit- -xv- mso- prince-
)
end
state :root do
mixin :basics
rule %r/{/, Punctuation, :stanza
rule %r/:[:]?#{identifier}/, Name::Decorator
rule %r/\.#{identifier}/, Name::Class
rule %r/##{identifier}/, Name::Function
rule %r/@#{identifier}/, Keyword, :at_rule
rule identifier, Name::Tag
rule %r([~^*!%&\[\]()<>|+=@:;,./?-]), Operator
rule %r/"(\\\\|\\"|[^"])*"/, Str::Single
rule %r/'(\\\\|\\'|[^'])*'/, Str::Double
rule %r/[0-9]{1,3}\%/, Num
end
state :value do
mixin :basics
rule %r/#[0-9a-f]{3,8}/i, Name::Other # colors
rule %r/#{number}(?:%|(?:px|pt|pc|in|cm|mm|Q|em|rem|ex|ch|vw|vh|vmin|vmax|fr|dpi|dpcm|dppx|deg|grad|rad|turn|s|ms|Hz|kHz)\b)?/, Num
rule %r/[\[\]():.,]/, Punctuation
rule %r/"(\\\\|\\"|[^"])*"/, Str::Single
rule %r/'(\\\\|\\'|[^'])*'/, Str::Double
rule %r/(true|false)/i, Name::Constant
rule %r/\-\-#{identifier}/, Literal
rule %r([*+/-]), Operator
rule(identifier) do |m|
if self.class.colors.include? m[0].downcase
token Name::Other
elsif self.class.builtins.include? m[0].downcase
token Name::Builtin
elsif self.class.functions.include? m[0].downcase
token Name::Function
else
token Name
end
end
end
state :at_rule do
rule %r/(?:<=|>=|~=|\|=|\^=|\$=|\*=|<|>|=)/, Operator
rule %r/{(?=\s*#{identifier}\s*:)/m, Punctuation, :at_stanza
rule %r/{/, Punctuation, :at_body
rule %r/;/, Punctuation, :pop!
mixin :value
end
state :at_body do
mixin :at_content
mixin :root
end
state :at_stanza do
mixin :at_content
mixin :stanza
end
state :at_content do
rule %r/}/ do
token Punctuation
pop! 2
end
end
state :basics do
rule %r/\s+/m, Text
rule %r(/\*(?:.*?)\*/)m, Comment
end
state :stanza do
mixin :basics
rule %r/}/, Punctuation, :pop!
rule %r/(#{identifier})(\s*)(:)/m do |m|
name_tok = if self.class.properties.include? m[1]
Name::Label
elsif self.class.vendor_prefixes.any? { |p| m[1].start_with?(p) }
Name::Label
else
Name::Property
end
groups name_tok, Text, Punctuation
push :stanza_value
end
end
state :stanza_value do
rule %r/;/, Punctuation, :pop!
rule(/(?=})/) { pop! }
rule %r/!\s*important\b/, Comment::Preproc
rule %r/^@.*?$/, Comment::Preproc
mixin :value
end
end
end
end
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class CSVS < RegexLexer
tag 'csvs'
title "csvs"
desc 'The CSV Schema Language (digital-preservation.github.io)'
filenames '*.csvs'
state :root do
rule %r/\s+/m, Text
rule %r(//[\S\t ]*), Comment::Single
rule %r(/\*[^*]*\*/)m, Comment::Multiline
rule %r/(version)( )(\d+\.\d+)/ do
groups Keyword, Text::Whitespace, Num::Float
end
rule %r/T?\d{2}:\d{2}:\d{2}(\.\d{5})?(Z|(?:[-+]\d{2}:\d{2}))?/, Literal::Date
rule %r/\d{4}-\d{2}-\d{2}/, Literal::Date
rule %r/\d{2}\/\d{2}\/\d{4}/, Literal::Date
rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
rule %r/\d+/, Num::Integer
rule %r/@\w+/, Keyword::Pseudo
rule %r/[-.\w]+:/, Name::Variable
rule %r/^"[^"]+"/, Name::Variable
rule %r/\$([-.\w]+|("[^"]+"))\/?/, Name::Variable
rule %r/[A-Z]+/i, Keyword
rule %r/"[^"]*"/, Str::Double
rule %r/'[^\r\n\f']'/, Str::Char
rule %r/[,()*]/, Punctuation
end
end
end
end
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
load_lexer 'cpp.rb'
class CUDA < Cpp
title "CUDA"
desc "Compute Unified Device Architecture, used for programming with NVIDIA GPU"
tag 'cuda'
filenames '*.cu', '*.cuh'
def self.keywords
@keywords ||= super + Set.new(%w(
__global__ __device__ __host__ __noinline__ __forceinline__
__constant__ __shared__ __managed__ __restrict__
))
end
def self.keywords_type
@keywords_type ||= super + Set.new(%w(
char1 char2 char3 char4 uchar1 uchar2 uchar3 uchar4
short1 short2 short3 short4 ushort1 ushort2 ushort3 ushort4
int1 int2 int3 int4 uint1 uint2 uint3 uint4
long1 long2 long3 long4 ulong1 ulong2 ulong3 ulong4
longlong1 longlong2 longlong3 longlong4
ulonglong1 ulonglong2 ulonglong3 ulonglong4
float1 float2 float3 float4 double1 double2 double3 double4
dim3
))
end
end
end
end
@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Cypher < RegexLexer
tag 'cypher'
aliases 'cypher'
filenames '*.cypher'
mimetypes 'application/x-cypher-query'
title "Cypher"
desc 'The Cypher query language (neo4j.com/docs/cypher-manual)'
def self.functions
@functions ||= Set.new %w(
ABS ACOS ALLSHORTESTPATHS ASIN ATAN ATAN2 AVG CEIL COALESCE COLLECT
COS COT COUNT DATE DEGREES E ENDNODE EXP EXTRACT FILTER FLOOR
HAVERSIN HEAD ID KEYS LABELS LAST LEFT LENGTH LOG LOG10 LOWER LTRIM
MAX MIN NODE NODES PERCENTILECONT PERCENTILEDISC PI RADIANS RAND
RANGE REDUCE REL RELATIONSHIP RELATIONSHIPS REPLACE REVERSE RIGHT
ROUND RTRIM SHORTESTPATH SIGN SIN SIZE SPLIT SQRT STARTNODE STDEV
STDEVP STR SUBSTRING SUM TAIL TAN TIMESTAMP TOFLOAT TOINT TOINTEGER
TOSTRING TRIM TYPE UPPER
)
end
def self.predicates
@predicates ||= Set.new %w(
ALL AND ANY CONTAINS EXISTS HAS IN NONE NOT OR SINGLE XOR
)
end
def self.keywords
@keywords ||= Set.new %w(
AS ASC ASCENDING ASSERT BY CASE COMMIT CONSTRAINT CREATE CSV CYPHER
DELETE DESC DESCENDING DETACH DISTINCT DROP ELSE END ENDS EXPLAIN
FALSE FIELDTERMINATOR FOREACH FROM HEADERS IN INDEX IS JOIN LIMIT
LOAD MATCH MERGE NULL ON OPTIONAL ORDER PERIODIC PROFILE REMOVE
RETURN SCAN SET SKIP START STARTS THEN TRUE UNION UNIQUE UNWIND USING
WHEN WHERE WITH CALL YIELD
)
end
state :root do
rule %r/[\s]+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*), Comment::Multiline, :multiline_comments
rule %r([*+\-<>=&|~%^]), Operator
rule %r/[{}),;\[\]]/, Str::Symbol
# literal number
rule %r/(\w+)(:)(\s*)(-?[._\d]+)/ do
groups Name::Label, Str::Delimiter, Text::Whitespace, Num
end
# function-like
# - "name("
# - "name ("
# - "name ("
rule %r/(\w+)(\s*)(\()/ do |m|
name = m[1].upcase
if self.class.functions.include? name
groups Name::Function, Text::Whitespace, Str::Symbol
elsif self.class.keywords.include? name
groups Keyword, Text::Whitespace, Str::Symbol
else
groups Name, Text::Whitespace, Str::Symbol
end
end
rule %r/:\w+/, Name::Class
# number range
rule %r/(-?\d+)(\.\.)(-?\d+)/ do
groups Num, Operator, Num
end
# numbers
rule %r/(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i, Num::Float
rule %r/\d+e[+-]?\d+/i, Num::Float
rule %r/0[0-7]+/, Num::Oct
rule %r/0x[a-f0-9]+/i, Num::Hex
rule %r/\d+/, Num::Integer
rule %r([.\w]+:), Name::Property
# remaining "("
rule %r/\(/, Str::Symbol
rule %r/[.\w$]+/ do |m|
match = m[0].upcase
if self.class.predicates.include? match
token Operator::Word
elsif self.class.keywords.include? match
token Keyword
else
token Name
end
end
rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
rule %r/`(\\\\|\\`|[^`])*`/, Str::Backtick
end
state :multiline_comments do
rule %r(/[*]), Comment::Multiline, :multiline_comments
rule %r([*]/), Comment::Multiline, :pop!
rule %r([^/*]+), Comment::Multiline
rule %r([/*]), Comment::Multiline
end
end
end
end
@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'python.rb'
class Cython < Python
title "Cython"
desc "Cython and Pyrex source code (cython.org)"
tag 'cython'
aliases 'pyx', 'pyrex'
filenames '*.pyx', '*.pxd', '*.pxi'
mimetypes 'text/x-cython', 'application/x-cython'
def initialize(opts = {})
super opts
@indentation = nil
end
def self.keywords
@keywords ||= super + %w(
by except? fused gil nogil
)
end
def self.c_keywords
@ckeywords ||= %w(
public readonly extern api inline enum union
)
end
identifier = /[a-z_]\w*/i
dotted_identifier = /[a-z_.][\w.]*/i
prepend :root do
rule %r/cp?def|ctypedef/ do
token Keyword
push :c_definitions
push :c_start
end
rule %r/(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(cimport)/ do
groups Keyword::Namespace,
Text,
Name::Namespace,
Text,
Keyword::Namespace
end
rule %r/(cimport)(\s+)(#{dotted_identifier})/ do
groups Keyword::Namespace, Text, Name::Namespace
end
rule %r/(struct)((?:\\\s|\s)+)/ do
groups Keyword, Text
push :classname
end
mixin :func_call_fix
rule %r/[(,]/, Punctuation, :c_start
end
prepend :classname do
rule %r/(?:\\\s|\s)+/, Text
end
prepend :funcname do
rule %r/(?:\\\s|\s)+/, Text
end
# This is a fix for the way that function calls are lexed in the Python
# lexer. This should be moved to the Python lexer once confirmed that it
# does not cause any regressions.
state :func_call_fix do
rule %r/#{identifier}(?=\()/ do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.exceptions.include? m[0]
token Name::Builtin
elsif self.class.builtins.include? m[0]
token Name::Builtin
elsif self.class.builtins_pseudo.include? m[0]
token Name::Builtin::Pseudo
else
token Name::Function
end
end
end
# The Cython lexer adds three states to those already in the Python lexer.
# Calls to `cdef`, `cpdef` and `ctypedef` move the lexer into the :c_start
# state. The primary purpose of this state is to highlight datatypes. Once
# this has been done, the lexer moves to the :c_definitions state where
# the majority of text in a definition is lexed. Finally, newlines cause
# the lexer to move to :c_indent. This state is used to check whether we
# have moved out of a C block.
state :c_start do
rule %r/[^\S\n]+/, Text
rule %r/cp?def|ctypedef/, Keyword
rule %r/(?:un)?signed/, Keyword::Type
# This rule matches identifiers that could be type declarations. The
# lookahead matches (1) pointers, (2) arrays and (3) variable names.
rule %r/#{identifier}(?=(?:\*+)|(?:[ \t]*\[)|(?:[ \t]+\w))/ do |m|
if self.class.keywords.include? m[0]
token Keyword
pop!
elsif %w(def).include? m[0]
token Keyword
goto :funcname
elsif %w(struct class).include? m[0]
token Keyword::Reserved
goto :classname
elsif self.class.c_keywords.include? m[0]
token Keyword::Reserved
else
token Keyword::Type
pop!
end
end
rule(//) { pop! }
end
state :c_definitions do
rule %r/\n/, Text, :c_indent
mixin :root
end
state :c_indent do
rule %r/[ \t]+/ do |m|
token Text
goto :c_start
if @indentation.nil?
@indentation = m[0]
elsif @indentation.length > m[0].length
@indentation = nil
pop! 2 # Pop :c_start and :c_definitions
end
end
rule(//) { @indentation = nil; reset_stack }
end
end
end
end
+177
View File
@@ -0,0 +1,177 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class D < RegexLexer
tag 'd'
aliases 'dlang'
filenames '*.d', '*.di'
mimetypes 'application/x-dsrc', 'text/x-dsrc'
title "D"
desc 'The D programming language(dlang.org)'
keywords = %w(
abstract alias align asm assert auto body
break case cast catch class const continue
debug default delegate delete deprecated do else
enum export extern finally final foreach_reverse
foreach for function goto if immutable import
interface invariant inout in is lazy mixin
module new nothrow out override package pragma
private protected public pure ref return scope
shared static struct super switch synchronized
template this throw try typedef typeid typeof
union unittest version volatile while with
__gshared __traits __vector __parameters
)
keywords_type = %w(
bool byte cdouble cent cfloat char creal
dchar double float idouble ifloat int ireal
long real short ubyte ucent uint ulong
ushort void wchar
)
keywords_pseudo = %w(
__FILE__ __FILE_FULL_PATH__ __MODULE__ __LINE__ __FUNCTION__
__PRETTY_FUNCTION__ __DATE__ __EOF__ __TIME__ __TIMESTAMP__
__VENDOR__ __VERSION__
)
state :whitespace do
rule %r/\n/m, Text
rule %r/\s+/m, Text
end
state :root do
mixin :whitespace
# Comments
rule %r(//.*), Comment::Single
rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), Comment::Multiline
rule %r(/\+), Comment::Multiline, :nested_comment
# Keywords
rule %r/(#{keywords.join('|')})\b/, Keyword
rule %r/(#{keywords_type.join('|')})\b/, Keyword::Type
rule %r/(false|true|null)\b/, Keyword::Constant
rule %r/(#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo
rule %r/macro\b/, Keyword::Reserved
rule %r/(string|wstring|dstring|size_t|ptrdiff_t)\b/, Name::Builtin
# Literals
# HexFloat
rule %r/0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)[pP][+\-]?[0-9_]+[fFL]?[i]?/, Num::Float
# DecimalFloat
rule %r/[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?/, Num::Float
rule %r/\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?/, Num::Float
# IntegerLiteral
# Binary
rule %r/0[Bb][01_]+/, Num::Bin
# Octal
# TODO: 0[0-7] isn't supported use octal![0-7] instead
rule %r/0[0-7_]+/, Num::Oct
# Hexadecimal
rule %r/0[xX][0-9a-fA-F_]+/, Num::Hex
# Decimal
rule %r/(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?/, Num::Integer
# CharacterLiteral
rule %r/'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'/, Str::Char
# StringLiteral
# WysiwygString
rule %r/r"[^"]*"[cwd]?/, Str
# Alternate WysiwygString
rule %r/`[^`]*`[cwd]?/, Str
# DoubleQuotedString
rule %r/"(\\\\|\\"|[^"])*"[cwd]?/, Str
# EscapeSequence
rule %r/\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)/, Str
# HexString
rule %r/x"[0-9a-fA-F_\s]*"[cwd]?/, Str
# DelimitedString
rule %r/q"\[/, Str, :delimited_bracket
rule %r/q"\(/, Str, :delimited_parenthesis
rule %r/q"</, Str, :delimited_angle
rule %r/q"\{/, Str, :delimited_curly
rule %r/q"([a-zA-Z_]\w*)\n.*?\n\1"/, Str
rule %r/q"(.).*?\1"/, Str
# TokenString
rule %r/q\{/, Str, :token_string
# Attributes
rule %r/@([a-zA-Z_]\w*)?/, Name::Decorator
# Tokens
rule %r`(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>=|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]`, Punctuation
# Identifier
rule %r/[a-zA-Z_]\w*/, Name
# Line
rule %r/#line\s.*\n/, Comment::Special
end
state :nested_comment do
rule %r([^+/]+), Comment::Multiline
rule %r(/\+), Comment::Multiline, :push
rule %r(\+/), Comment::Multiline, :pop!
rule %r([+/]), Comment::Multiline
end
state :token_string do
rule %r/\{/, Punctuation, :token_string_nest
rule %r/\}/, Str, :pop!
mixin :root
end
state :token_string_nest do
rule %r/\{/, Punctuation, :push
rule %r/\}/, Punctuation, :pop!
mixin :root
end
state :delimited_bracket do
rule %r/[^\[\]]+/, Str
rule %r/\[/, Str, :delimited_inside_bracket
rule %r/\]"/, Str, :pop!
end
state :delimited_inside_bracket do
rule %r/[^\[\]]+/, Str
rule %r/\[/, Str, :push
rule %r/\]/, Str, :pop!
end
state :delimited_parenthesis do
rule %r/[^()]+/, Str
rule %r/\(/, Str, :delimited_inside_parenthesis
rule %r/\)"/, Str, :pop!
end
state :delimited_inside_parenthesis do
rule %r/[^()]+/, Str
rule %r/\(/, Str, :push
rule %r/\)/, Str, :pop!
end
state :delimited_angle do
rule %r/[^<>]+/, Str
rule %r/</, Str, :delimited_inside_angle
rule %r/>"/, Str, :pop!
end
state :delimited_inside_angle do
rule %r/[^<>]+/, Str
rule %r/</, Str, :push
rule %r/>/, Str, :pop!
end
state :delimited_curly do
rule %r/[^{}]+/, Str
rule %r/\{/, Str, :delimited_inside_curly
rule %r/\}"/, Str, :pop!
end
state :delimited_inside_curly do
rule %r/[^{}]+/, Str
rule %r/\{/, Str, :push
rule %r/\}/, Str, :pop!
end
end
end
end
@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Dafny < RegexLexer
title "Dafny"
desc "The Dafny programming language (github.com/dafny-lang/dafny)"
tag "dafny"
filenames "*.dfy"
mimetypes "text/x-dafny"
keywords = %w(
abstract allocated assert assume
break by
calc case class codatatype const constructor
datatype decreases downto
else ensures exists expect export extends
false for forall fresh function
ghost greatest
if import include invariant iterator
label least lemma
match method modifies modify module
nameonly new newtype null
old opened
predicate print provides
reads refines requires return returns reveal reveals
static
then this to trait true twostate type
unchanged
var
while witness
yield yields
)
literals = %w{ true false null }
textOperators = %w{ as is in }
types = %w(bool char int real string nat
array array? object object? ORDINAL
seq set iset map imap multiset )
idstart = /[0-9a-zA-Z?]/
idchar = /[0-9a-zA-Z_'?]/
id = /#{idstart}#{idchar}*/
arrayType = /array(?:1[0-9]+|[2-9][0-9]*)\??(?!#{idchar})/
bvType = /bv(?:0|[1-9][0-9]*)(?!#{idchar})/
digit = /\d/
digits = /#{digit}+(?:_#{digit}+)*/
bin_digits = /[01]+(?:_[01]+)*/
hex_digit = /(?:[0-9a-fA-F])/
hex_digits = /#{hex_digit}+(?:_#{hex_digit}+)*/
cchar = /(?:[^\\'\n\r]|\\["'ntr\\0])/
schar = /(?:[^\\"\n\r]|\\["'ntr\\0])/
uchar = /(?:\\u#{hex_digit}{4})/
## IMPORTANT: Rules are ordered, which allows later rules to be
## simpler than they would otherwise be
state :root do
rule %r(/\*), Comment::Multiline, :comment
rule %r(//.*?$), Comment::Single
rule %r(\*/), Error # should not have closing comment in :root
# is an improperly nested comment
rule %r/'#{cchar}'/, Str::Char # standard or escape char
rule %r/'#{uchar}'/, Str::Char # unicode char
rule %r/'[^'\n\r]*'/, Error # bad any other enclosed char
rule %r/'[^'\n\r]*$/, Error # bad unclosed char
rule %r/"(?:#{schar}|#{uchar})*"/, Str::Double # valid string
rule %r/".*"/, Error # anything else that is closed
rule %r/".*$/, Error # bad unclosed string
rule %r/@"([^"]|"")*"/, Str::Other # valid verbatim string
rule %r/@".*/m, Error # anything else , multiline unclosed
rule %r/#{digits}\.#{digits}(?!#{idchar})/, Num::Float
rule %r/0b#{bin_digits}(?!#{idchar})/, Num::Bin
rule %r/0b#{idchar}*/, Error
rule %r/0x#{hex_digits}(?!#{idchar})/, Num::Hex
rule %r/0x#{idchar}*/, Error
rule %r/#{digits}(?!#{idchar})/, Num::Integer
rule %r/_(?!#{idchar})/, Name
rule %r/_[0-9_]+[_]?(?!#{idchar})/, Error
rule %r/[0-9_]+_(?!#{idchar})/, Error
rule %r/[0-9]#{idchar}+/, Error
rule %r/#{arrayType}/, Keyword::Type
rule %r/#{bvType}/, Keyword::Type
rule id do |m|
if types.include?(m[0])
token Keyword::Type
elsif literals.include?(m[0])
token Keyword::Constant
elsif textOperators.include?(m[0])
token Operator::Word
elsif keywords.include?(m[0])
token Keyword::Reserved
else
token Name
end
end
rule %r/\.\./, Operator
rule %r/[*!%&<>\|^+=:.\/-]/, Operator
rule %r/[\[\](){},;`]/, Punctuation
rule %r/[^\S\n]+/, Text
rule %r/\n/, Text
rule %r/./, Error # Catchall
end
state :comment do
rule %r(\*/), Comment::Multiline, :pop!
rule %r(/\*), Comment::Multiline, :comment
rule %r([^*/]+), Comment::Multiline
rule %r(.), Comment::Multiline
end
end
end
end
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Dart < RegexLexer
title "Dart"
desc "The Dart programming language (dart.dev)"
tag 'dart'
filenames '*.dart'
mimetypes 'text/x-dart'
keywords = %w(
as assert await break case catch continue default do else finally for if
in is new rethrow return super switch this throw try while when with yield
)
declarations = %w(
abstract base async dynamic const covariant external extends factory final get implements
interface late native on operator required sealed set static sync typedef var
)
types = %w(bool Comparable double Dynamic enum Function int List Map Never Null num Object Pattern Record Set String Symbol Type Uri void)
imports = %w(import deferred export library part\s*of part source)
id = /[a-zA-Z_]\w*/
state :root do
rule %r(^
(\s*(?:[a-zA-Z_][a-zA-Z\d_.\[\]]*\s+)+?) # return arguments
([a-zA-Z_]\w*) # method name
(\s*)(\() # signature start
)mx do |m|
# TODO: do this better, this shouldn't need a delegation
delegate Dart, m[1]
token Name::Function, m[2]
token Text, m[3]
token Punctuation, m[4]
end
rule %r/\s+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
rule %r/"/, Str, :dqs
rule %r/'/, Str, :sqs
rule %r/r"[^"]*"/, Str::Other
rule %r/r'[^']*'/, Str::Other
rule %r/##{id}*/i, Str::Symbol
rule %r/@#{id}/, Name::Decorator
rule %r/(?:#{keywords.join('|')})\b/, Keyword
rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
rule %r/(?:#{types.join('|')})\b/, Keyword::Type
rule %r/(?:true|false|null)\b/, Keyword::Constant
rule %r/(?:class|mixin)\b/, Keyword::Declaration, :class
rule %r/(?:#{imports.join('|')})\b/, Keyword::Namespace, :import
rule %r/(\.)(#{id})/ do
groups Operator, Name::Attribute
end
rule %r/#{id}:/, Name::Label
rule %r/\$?#{id}/, Name
rule %r/[~^*!%&\|+=:\/?-]/, Operator
rule %r/[\[\](){}<>\.,;]/, Punctuation
rule %r/\d*\.\d+([eE]\-?\d+)?/, Num::Float
rule %r/0x[\da-fA-F]+/, Num::Hex
rule %r/\d+L?/, Num::Integer
rule %r/\n/, Text
end
state :class do
rule %r/\s+/m, Text
rule id, Name::Class, :pop!
end
state :dqs do
rule %r/"/, Str, :pop!
rule %r/[^\\\$"]+/, Str
mixin :string
end
state :sqs do
rule %r/'/, Str, :pop!
rule %r/[^\\\$']+/, Str
mixin :string
end
state :import do
rule %r/;/, Operator, :pop!
rule %r/(?:show|hide)\b/, Keyword::Declaration
mixin :root
end
state :string do
mixin :interpolation
rule %r/\\[nrt\"\'\\]/, Str::Escape
end
state :interpolation do
rule %r/\$#{id}/, Str::Interpol
rule %r/\$\{[^\}]+\}/, Str::Interpol
end
end
end
end
@@ -0,0 +1,138 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Datastudio < RegexLexer
tag 'datastudio'
filenames '*.job'
mimetypes 'text/x-datastudio'
title "Datastudio"
desc 'Datastudio scripting language'
id = /@?[_a-z]\w*/i
def self.sql_keywords
@sql_keywords ||= %w(
ABORT ABS ABSOLUTE ACCESS ADA ADD ADMIN AFTER AGGREGATE ALIAS
ALL ALLOCATE ALTER ANALYSE ANALYZE AND ANY ARE AS ASC ASENSITIVE
ASSERTION ASSIGNMENT ASYMMETRIC AT ATOMIC AUTHORIZATION
AVG BACKWARD BEFORE BEGIN BETWEEN BITVAR BIT_LENGTH BOTH
BREADTH BY C CACHE CALL CALLED CARDINALITY CASCADE CASCADED
CASE CAST CATALOG CATALOG_NAME CHAIN CHARACTERISTICS
CHARACTER_LENGTH CHARACTER_SET_CATALOG CHARACTER_SET_NAME
CHARACTER_SET_SCHEMA CHAR_LENGTH CHECK CHECKED CHECKPOINT
CLASS CLASS_ORIGIN CLOB CLOSE CLUSTER COALSECE COBOL COLLATE
COLLATION COLLATION_CATALOG COLLATION_NAME COLLATION_SCHEMA
COLUMN COLUMN_NAME COMMAND_FUNCTION COMMAND_FUNCTION_CODE
COMMENT COMMIT COMMITTED COMPLETION CONDITION_NUMBER
CONNECT CONNECTION CONNECTION_NAME CONSTRAINT CONSTRAINTS
CONSTRAINT_CATALOG CONSTRAINT_NAME CONSTRAINT_SCHEMA
CONSTRUCTOR CONTAINS CONTINUE CONVERSION CONVERT COPY
CORRESPONTING COUNT CREATE CREATEDB CREATEUSER CROSS CUBE
CURRENT CURRENT_DATE CURRENT_PATH CURRENT_ROLE CURRENT_TIME
CURRENT_TIMESTAMP CURRENT_USER CURSOR CURSOR_NAME CYCLE DATA
DATABASE DATETIME_INTERVAL_CODE DATETIME_INTERVAL_PRECISION
DAY DEALLOCATE DECLARE DEFAULT DEFAULTS DEFERRABLE DEFERRED
DEFINED DEFINER DELETE DELIMITER DELIMITERS DEREF DESC DESCRIBE
DESCRIPTOR DESTROY DESTRUCTOR DETERMINISTIC DIAGNOSTICS
DICTIONARY DISCONNECT DISPATCH DISTINCT DO DOMAIN DROP
DYNAMIC DYNAMIC_FUNCTION DYNAMIC_FUNCTION_CODE EACH ELSE
ENCODING ENCRYPTED END END-EXEC EQUALS ESCAPE EVERY EXCEPT
ESCEPTION EXCLUDING EXCLUSIVE EXEC EXECUTE EXISTING EXISTS
EXPLAIN EXTERNAL EXTRACT FALSE FETCH FINAL FIRST FOR FORCE
FOREIGN FORTRAN FORWARD FOUND FREE FREEZE FROM FULL FUNCTION
G GENERAL GENERATED GET GLOBAL GO GOTO GRANT GRANTED GROUP
GROUPING HANDLER HAVING HIERARCHY HOLD HOST IDENTITY IGNORE
ILIKE IMMEDIATE IMMUTABLE IMPLEMENTATION IMPLICIT IN INCLUDING
INCREMENT INDEX INDITCATOR INFIX INHERITS INITIALIZE INITIALLY
INNER INOUT INPUT INSENSITIVE INSERT INSTANTIABLE INSTEAD
INTERSECT INTO INVOKER IS ISNULL ISOLATION ITERATE JOIN KEY
KEY_MEMBER KEY_TYPE LANCOMPILER LANGUAGE LARGE LAST LATERAL
LEADING LEFT LENGTH LESS LEVEL LIKE LIMIT LISTEN LOAD LOCAL
LOCALTIME LOCALTIMESTAMP LOCATION LOCATOR LOCK LOWER MAP MATCH
MAX MAXVALUE MESSAGE_LENGTH MESSAGE_OCTET_LENGTH MESSAGE_TEXT
METHOD MIN MINUTE MINVALUE MOD MODE MODIFIES MODIFY MONTH
MORE MOVE MUMPS NAMES NATURAL NCLOB NEW NEXT
NO NOCREATEDB NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL
NULL NULLABLE NULLIF OBJECT OCTET_LENGTH OF OFF OFFSET OIDS
OLD ON ONLY OPEN OPERATION OPERATOR OPTION OPTIONS OR ORDER
ORDINALITY OUT OUTER OUTPUT OVERLAPS OVERLAY OVERRIDING
OWNER PAD PARAMETER PARAMETERS PARAMETER_MODE PARAMATER_NAME
PARAMATER_ORDINAL_POSITION PARAMETER_SPECIFIC_CATALOG
PARAMETER_SPECIFIC_NAME PARAMATER_SPECIFIC_SCHEMA PARTIAL PASCAL
PENDANT PLACING PLI POSITION POSTFIX PREFIX PREORDER
PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
PUBLIC READ READS RECHECK RECURSIVE REF REFERENCES REFERENCING
REINDEX RELATIVE RENAME REPEATABLE REPLACE RESET RESTART
RESTRICT RESULT RETURN RETURNED_LENGTH RETURNED_OCTET_LENGTH
RETURNED_SQLSTATE RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
ROUTINE ROUTINE_CATALOG ROUTINE_NAME ROUTINE_SCHEMA ROW ROWS
ROW_COUNT RULE SAVE_POINT SCALE SCHEMA SCHEMA_NAME SCOPE SCROLL
SEARCH SECOND SECURITY SELECT SELF SENSITIVE SERIALIZABLE
SERVER_NAME SESSION SESSION_USER SET SETOF SETS SHARE SHOW
SIMILAR SIMPLE SIZE SOME SOURCE SPACE SPECIFIC SPECIFICTYPE
SPECIFIC_NAME SQL SQLCODE SQLERROR SQLEXCEPTION SQLSTATE
SQLWARNINIG STABLE START STATE STATEMENT STATIC STATISTICS
STDIN STDOUT STORAGE STRICT STRUCTURE STYPE SUBCLASS_ORIGIN
SUBLIST SUBSTRING SUM SYMMETRIC SYSID SYSTEM SYSTEM_USER
TABLE TABLE_NAME TEMP TEMPLATE TEMPORARY TERMINATE THAN THEN
TIMEZONE_HOUR TIMEZONE_MINUTE TO TOAST TRAILING
TRANSATION TRANSACTIONS_COMMITTED TRANSACTIONS_ROLLED_BACK
TRANSATION_ACTIVE TRANSFORM TRANSFORMS TRANSLATE TRANSLATION
TREAT TRIGGER TRIGGER_CATALOG TRIGGER_NAME TRIGGER_SCHEMA TRIM
TRUE TRUNCATE TRUSTED TYPE UNCOMMITTED UNDER UNENCRYPTED UNION
UNIQUE UNKNOWN UNLISTEN UNNAMED UNNEST UNTIL UPDATE UPPER
USAGE USER USER_DEFINED_TYPE_CATALOG USER_DEFINED_TYPE_NAME
USER_DEFINED_TYPE_SCHEMA USING VACUUM VALID VALIDATOR VALUES
VARIABLE VERBOSE VERSION VIEW VOLATILE WHEN WHENEVER WHERE
WITH WITHOUT WORK WRITE ZONE
)
end
state :whitespace do
rule %r/\s+/m, Text
rule %r(//.*?$), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline
end
state :string do
rule %r/%(\\.|.)+?%/, Str::Escape
rule %r/\\"/, Str::Double
rule %r/"/, Str::Double, :pop!
rule %r/./m, Str::Double
end
state :string_s do
rule %r/%(\\.|.)+?%/, Str::Escape
rule %r/\\'/, Str::Single
rule %r/'/, Str::Single, :pop!
rule %r/./m, Str::Single
end
state :root do
mixin :whitespace
rule %r/^:#{id}/, Name::Label
rule %r/@#{id}(\.#{id})?/m, Name::Entity
rule %r/%(\\.|.)+?%/, Name::Variable
rule %r/[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, Punctuation
rule %r/"/, Str::Double, :string
rule %r/'/, Str::Single, :string_s
rule %r/\d(\.\d*)?/i, Num
rule %r/#{id}(?=\s*[(])/, Name::Function
rule id do |m|
name = m[0].upcase
if self.class.sql_keywords.include? name
token Keyword
else
token Name
end
end
end
end
end
end
@@ -0,0 +1,47 @@
# frozen_string_literal: true
module Rouge
module Lexers
class Diff < RegexLexer
title 'diff'
desc 'Lexes unified diffs or patches'
tag 'diff'
aliases 'patch', 'udiff'
filenames '*.diff', '*.patch'
mimetypes 'text/x-diff', 'text/x-patch'
def self.detect?(text)
return true if text.start_with?('Index: ')
return true if text =~ %r(\Adiff[^\n]*?\ba/[^\n]*\bb/)
return true if text =~ /---.*?\n[+][+][+]/ || text =~ /[+][+][+].*?\n---/
end
state :root do
rule(/^ .*$\n?/, Text)
rule(/^---$\n?/, Punctuation)
rule %r(
(^\++.*$\n?) |
(^>+[ \t]+.*$\n?) |
(^>+$\n?)
)x, Generic::Inserted
rule %r(
(^-+.*$\n?) |
(^<+[ \t]+.*$\n?) |
(^<+$\n?)
)x, Generic::Deleted
rule(/^!.*$\n?/, Generic::Strong)
rule(/^([Ii]ndex|diff).*$\n?/, Generic::Heading)
rule(/^(@@[^@]*@@)([^\n]*\n)/) do
groups Punctuation, Text
end
rule(/^\w.*$\n?/, Punctuation)
rule(/^=.*$\n?/, Generic::Heading)
rule(/.+$\n?/, Text)
end
end
end
end
@@ -0,0 +1,70 @@
# frozen_string_literal: true
require 'set'
module Rouge
module Lexers
load_lexer 'yaml.rb'
class Digdag < YAML
title 'digdag'
desc 'A simple, open source, multi-cloud workflow engine (https://www.digdag.io/)'
tag 'digdag'
filenames '*.dig'
mimetypes 'application/x-digdag'
# http://docs.digdag.io/operators.html
# as of digdag v0.9.10
KEYWORD_PATTERN = Regexp.union(%w(
call
require
loop
for_each
if
fail
echo
td
td_run
td_ddl
td_load
td_for_each
td_wait
td_wait_table
td_partial_delete
td_table_export
pg
mail
http
s3_wait
redshift
redshift_load
redshift_unload
emr
gcs_wait
bq
bq_ddl
bq_extract
bq_load
sh
py
rb
embulk
).map { |name| "#{name}>"} + %w(
_do
_parallel
))
prepend :block_nodes do
rule %r/(#{KEYWORD_PATTERN})(:)(?=\s|$)/ do |m|
groups Keyword::Reserved, Punctuation::Indicator
set_indent m[0], :implicit => true
end
end
end
end
end
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Docker < RegexLexer
title "Docker"
desc "Dockerfile syntax"
tag 'docker'
aliases 'dockerfile', 'Dockerfile', 'containerfile', 'Containerfile'
filenames 'Dockerfile', 'Dockerfile.*', '*.Dockerfile', '*.docker', 'Containerfile', 'Containerfile.*', '*.Containerfile'
mimetypes 'text/x-dockerfile-config'
KEYWORDS = %w(
FROM MAINTAINER CMD LABEL EXPOSE ENV ADD COPY ENTRYPOINT VOLUME USER WORKDIR ARG STOPSIGNAL HEALTHCHECK SHELL
).join('|')
start { @shell = Shell.new(@options) }
state :root do
rule %r/\s+/, Text
rule %r/^(FROM)(\s+)(.*)(\s+)(AS)(\s+)(.*)/io do
groups Keyword, Text::Whitespace, Str, Text::Whitespace, Keyword, Text::Whitespace, Str
end
rule %r/^(ONBUILD)(\s+)(#{KEYWORDS})(.*)/io do
groups Keyword, Text::Whitespace, Keyword, Str
end
rule %r/^(#{KEYWORDS})\b(.*)/io do
groups Keyword, Str
end
rule %r/#.*?$/, Comment
rule %r/^(ONBUILD\s+)?RUN(\s+)/i do
token Keyword
push :run
@shell.reset!
end
rule %r/\w+/, Text
rule %r/[^\w]+/, Text
rule %r/./, Text
end
state :run do
rule %r/\n/, Text, :pop!
rule %r/\\./m, Str::Escape
rule(/(\\.|[^\n\\])+/) { delegate @shell }
end
end
end
end
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Dot < RegexLexer
title "DOT"
desc "graph description language"
tag 'dot'
aliases 'graphviz'
filenames '*.dot'
mimetypes 'text/vnd.graphviz'
start do
@html = HTML.new(options)
end
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(#.*), Comment::Single
rule %r(//.*?$), Comment::Single
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
end
state :html do
rule %r/[^<>]+/ do
delegate @html
end
rule %r/<.+?>/m do
delegate @html
end
rule %r/>/, Punctuation, :pop!
end
state :ID do
rule %r/([a-zA-Z][a-zA-Z_0-9]*)(\s*)(=)/ do |m|
token Name, m[1]
token Text, m[2]
token Punctuation, m[3]
end
rule %r/[a-zA-Z][a-zA-Z_0-9]*/, Name::Variable
rule %r/([0-9]+)?\.[0-9]+/, Num::Float
rule %r/[0-9]+/, Num::Integer
rule %r/"(\\"|[^"])*"/, Str::Double
rule %r/</ do
token Punctuation
@html.reset!
push :html
end
end
state :a_list do
mixin :comments_and_whitespace
mixin :ID
rule %r/[=;,]/, Punctuation
rule %r/\]/, Operator, :pop!
end
state :root do
mixin :comments_and_whitespace
rule %r/\b(strict|graph|digraph|subgraph|node|edge)\b/i, Keyword
rule %r/[{};:=]/, Punctuation
rule %r/-[->]/, Operator
rule %r/\[/, Operator, :a_list
mixin :ID
end
end
end
end
@@ -0,0 +1,175 @@
# -*- codding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class ECL < RegexLexer
tag 'ecl'
filenames '*.ecl'
mimetypes 'application/x-ecl'
title "ECL"
desc "Enterprise Control Language (hpccsystems.com)"
id = /(#?)\b([a-z_][\w]*?)(\d*)\b/i
def self.class_first
@class_first ||= Set.new %w(
file date str math metaphone metaphone3 uni audit blas system
)
end
def self.class_second
@class_second ||= Set.new %w(
debug email job log thorlib util workunit
)
end
def self.functions
@functions ||= Set.new %w(
abs acos aggregate allnodes apply ascii asin asstring atan _token ave
case catch choose choosen choosesets clustersize combine correlation
cos cosh count covariance cron dataset dedup define denormalize
dictionary distribute distributed distribution ebcdic enth error
evaluate event eventextra eventname exists exp failcode failmessage
fetch fromunicode fromxml getenv getisvalid global graph group hash
hashcrc having httpcall httpheader if iff index intformat isvalid
iterate join keyunicode length library limit ln local log loop map
matched matchlength matchposition matchtext matchunicode max merge
mergejoin min nofold nolocal nonempty normalize parse pipe power
preload process project pull random range rank ranked realformat
recordof regexfind regexreplace regroup rejected rollup round roundup
row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt
stepped stored sum table tan tanh thisnode topn tounicode toxml
transfer transform trim truncate typeof ungroup unicodeorder variance
which workunit xmldecode xmlencode xmltext xmlunicode apply assert
build buildindex evaluate fail keydiff keypatch loadxml nothor notify
output parallel sequential soapcall wait
)
end
def self.keywords
@keywords ||= Set.new %w(
and or in not all any as from atmost before best between case const
counter csv descend encrypt end endmacro enum except exclusive expire
export extend fail few first flat full function functionmacro group
heading hole ifblock import joined keep keyed last left limit load
local locale lookup many maxcount maxlength _token module interface
named nocase noroot noscan nosort of only opt outer overwrite packed
partition penalty physicallength pipe quote record repeat return
right rows scan self separator service shared skew skip sql store
terminator thor threshold token transform trim type unicodeorder
unsorted validate virtual whole wild within xml xpath after cluster
compressed compression default encoding escape fileposition forward
grouped inner internal linkcounted literal lzw mofn multiple
namespace wnotrim noxpath onfail prefetch retry rowset scope smart
soapaction stable timelimit timeout unordered unstable update use
width
)
end
def self.template
@template ||= Set.new %w(
append apply break constant debug declare demangle else elseif end
endregion error expand export exportxml for forall getdatatype if
ifdefined inmodule isdefined isvalid line link loop mangle onwarning
option region set stored text trace uniquename warning webservice
workunit loadxml
)
end
def self.type
@type ||= Set.new %w(
ascii big_endian boolean data decimal ebcdic grouped integer
linkcounted pattern qstring real record rule set of streamed string
token udecimal unicode utf8 unsigned varstring varunicode
)
end
def self.typed
@typed ||= Set.new %w(
data string qstring varstring varunicode unicode utf8
)
end
state :single_quote do
rule %r([xDQUV]?'([^'\\]*(?:\\.[^'\\]*)*)'), Str::Single
rule %r/\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)/, Text
end
state :inline_whitespace do
rule %r/[ \t\r]+/, Text
rule %r/\\\n/, Text # line continuation
rule %r(/[*].*?[*]/)m, Comment::Multiline
end
state :whitespace do
rule %r/\n+/m, Text
rule %r(//.*), Comment::Single
mixin :inline_whitespace
end
state :root do
mixin :whitespace
mixin :single_quote
rule %r(\b(?i:(and|not|or|in))\b), Operator::Word
rule %r(:=|>|<|<>|/|\\|\+|-|=), Operator
rule %r([\[\]{}();,\&\.\%]), Punctuation
rule %r(\b(?i:(beginc\+\+.*?endc\+\+)))m, Str::Single
rule %r(\b(?i:(embed.*?endembed)))m, Str::Single
rule %r(\b(\w+)\.(\w+)\.(\w+)) do |m|
if m[1] == "std" &&
self.class.class_first.include?(m[2]) &&
self.class.class_second.include?(m[3])
token Name::Class
else
token Name::Variable
end
end
rule %r(\b(?i:(u)?decimal)(\d+(_\d+)?)\b), Keyword::Type
rule %r/\d+\.\d+(e[\+\-]?\d+)?/i, Num::Float
rule %r/x[0-9a-f]+/i, Num::Hex
rule %r/0x[0-9a-f]+/i, Num::Hex
rule %r/0[0-9a-f]+x/i, Num::Hex
rule %r(0[bB][01]+), Num::Bin
rule %r([01]+[bB]), Num::Bin
rule %r(\d+), Num::Integer
rule id do |m|
name_only = m[2].downcase
name = name_only + m[3]
number = (m[3] == "") ? nil : m[3].to_i
if m[1] == "#"
if self.class.template.include? name
token Keyword::Type
else
token Error
end
elsif self.class.typed.include?(name_only) && number != nil
token Keyword::Type
elsif self.class.type.include? name
token Keyword::Type
elsif self.class.keywords.include? name
token Keyword
elsif self.class.functions.include? name
token Name::Function
elsif ["integer", "unsigned"].include?(name_only) && (1..8).cover?(number)
token Keyword::Type
elsif name_only == "real" && [4, 8].include?(number)
token Keyword::Type
elsif ["true", "false"].include? name
token Keyword::Constant
else
token Name::Other
end
end
end
end
end
end
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class EEX < TemplateLexer
title "EEX"
desc "Embedded Elixir"
tag 'eex'
aliases 'leex', 'heex'
filenames '*.eex', '*.leex', '*.heex'
def initialize(opts={})
@elixir_lexer = Elixir.new(opts)
super(opts)
end
start do
parent.reset!
@elixir_lexer.reset!
end
open = /<%%|<%=|<%#|<%/
close = /%%>|%>/
state :root do
rule %r/<%#/, Comment, :comment
rule open, Comment::Preproc, :elixir
rule %r/.+?(?=#{open})|.+/mo do
delegate parent
end
end
state :comment do
rule close, Comment, :pop!
rule %r/.+?(?=#{close})|.+/mo, Comment
end
state :elixir do
rule close, Comment::Preproc, :pop!
rule %r/.+?(?=#{close})|.+/mo do
delegate @elixir_lexer
end
end
end
end
end
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Eiffel < RegexLexer
title "Eiffel"
desc "Eiffel programming language"
tag 'eiffel'
filenames '*.e'
mimetypes 'text/x-eiffel'
LanguageKeywords = %w(
across agent alias all and attached as assign attribute check
class convert create debug deferred detachable do else elseif end
ensure expanded export external feature from frozen if implies inherit
inspect invariant like local loop not note obsolete old once or
Precursor redefine rename require rescue retry select separate
some then undefine until variant Void when xor
)
BooleanConstants = %w(True False)
LanguageVariables = %w(Current Result)
SimpleString = /(?:[^"%\b\f\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)+?/
state :root do
rule %r/"\[/, Str::Other, :aligned_verbatim_string
rule %r/"\{/, Str::Other, :non_aligned_verbatim_string
rule %r/"(?:[^%\b\f\n\r\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)*?"/, Str::Double
rule %r/--.*/, Comment::Single
rule %r/'(?:[^%\b\f\n\r\t\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)'/, Str::Char
rule %r/(?:#{LanguageKeywords.join('|')})\b/, Keyword
rule %r/(?:#{LanguageVariables.join('|')})\b/, Keyword::Variable
rule %r/(?:#{BooleanConstants.join('|')})\b/, Keyword::Constant
rule %r/\b0[xX][\da-fA-F](?:_*[\da-fA-F])*b/, Num::Hex
rule %r/\b0[cC][0-7](?:_*[0-7])*\b/, Num::Oct
rule %r/\b0[bB][01](?:_*[01])*\b/, Num::Bin
rule %r/\d(?:_*\d)*/, Num::Integer
rule %r/(?:\d(?:_*\d)*)?\.(?:(?:\d(?:_*\d)*)?[eE][+-]?)?\d(?:_*\d)*|\d(?:_*\d)*\.?/, Num::Float
rule %r/:=|<<|>>|\(\||\|\)|->|\.|[{}\[\];(),:?]/, Punctuation::Indicator
rule %r/\\\\|\|\.\.\||\.\.|\/[~\/]?|[><\/]=?|[-+*^=~≤≥−∀∃¦⟳⟲]/, Operator
rule %r/[A-Z][\dA-Z_]*/, Name::Class
rule %r/[A-Za-z][\dA-Za-z_]*/, Name
rule %r/\s+/, Text
end
state :aligned_verbatim_string do
rule %r/]"/, Str::Other, :pop!
rule SimpleString, Str::Other
end
state :non_aligned_verbatim_string do
rule %r/}"/, Str::Other, :pop!
rule SimpleString, Str::Other
end
end
end
end
@@ -0,0 +1,153 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
# Direct port of pygments Lexer.
# See: https://bitbucket.org/birkenfeld/pygments-main/src/7304e4759ae65343d89a51359ca538912519cc31/pygments/lexers/functional.py?at=default#cl-2362
class Elixir < RegexLexer
title "Elixir"
desc "Elixir language (elixir-lang.org)"
tag 'elixir'
aliases 'elixir', 'exs'
filenames '*.ex', '*.exs'
def self.detect?(text)
return true if text.shebang?('elixir')
end
mimetypes 'text/x-elixir', 'application/x-elixir'
state :root do
rule %r/\s+/m, Text
rule %r/#.*$/, Comment::Single
rule %r{\b(case|cond|end|bc|lc|if|unless|try|loop|receive|fn|defmodule|
defp?|defprotocol|defimpl|defrecord|defmacrop?|defdelegate|
defexception|defguardp?|defstruct|exit|raise|throw|after|rescue|catch|else)\b(?![?!])|
(?<!\.)\b(do|\-\>)\b}x, Keyword
rule %r/\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])/, Keyword::Namespace
rule %r/(?<!\.)\b(and|not|or|when|xor|in)\b/, Operator::Word
rule %r{%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|
<=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[\s])\?|
(?<=[\s])!+|&(&&?|(?!\d))|\|\||\^|\*|\+|\-|/|
\||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.|~~~}x, Operator
rule %r{(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|
<=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|
\*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)}, Str::Symbol
rule %r/:"/, Str::Symbol, :interpoling_symbol
rule %r/\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/, Name::Constant
rule %r/\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/, Name::Builtin::Pseudo
rule %r/[a-zA-Z_!]\w*[!\?]?/, Name
rule %r{::|[%(){};,/\|:\\\[\]]}, Punctuation
rule %r/@[a-zA-Z_]\w*|&\d/, Name::Variable
rule %r{\b\d(_?\d)*(\.(?![^\d\s])(_?\d)+)([eE][-+]?\d(_?\d)*)?\b}, Num::Float
rule %r{\b0x[0-9A-Fa-f](_?[0-9A-Fa-f])*\b}, Num::Hex
rule %r{\b0o[0-7](_?[0-7])*\b}, Num::Oct
rule %r{\b0b[01](_?[01])*\b}, Num::Bin
rule %r{\b\d(_?\d)*\b}, Num::Integer
mixin :strings
mixin :sigil_strings
end
state :strings do
rule %r/(%[A-Ba-z])?"""(?:.|\n)*?"""/, Str::Doc
rule %r/'''(?:.|\n)*?'''/, Str::Doc
rule %r/"/, Str::Double, :dqs
rule %r/'/, Str::Single, :sqs
rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])}, Str::Other
end
state :dqs do
mixin :escapes
mixin :interpoling
rule %r/[^#"\\]+/, Str::Double
rule %r/"/, Str::Double, :pop!
rule %r/[#\\]/, Str::Double
end
state :sqs do
mixin :escapes
mixin :interpoling
rule %r/[^#'\\]+/, Str::Single
rule %r/'/, Str::Single, :pop!
rule %r/[#\\]/, Str::Single
end
state :interpoling do
rule %r/#\{/, Str::Interpol, :interpoling_string
end
state :interpoling_string do
rule %r/\}/, Str::Interpol, :pop!
mixin :root
end
state :escapes do
rule %r/\\x\h{2}/, Str::Escape
rule %r/\\u\{?\d+\}?/, Str::Escape
rule %r/\\[\\abdefnrstv0"']/, Str::Escape
end
state :interpoling_symbol do
rule %r/"/, Str::Symbol, :pop!
mixin :interpoling
rule %r/[^#"]+/, Str::Symbol
end
state :sigil_strings do
# ~-sigiled strings
# ~(abc), ~[abc], ~<abc>, ~|abc|, ~r/abc/, etc
# Cribbed and adjusted from Ruby lexer
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
# Match a-z for custom sigils too
sigil_opens = Regexp.union(delimiter_map.keys + %w(| / ' "))
rule %r/~([A-Za-z])?(#{sigil_opens})/ do |m|
open = Regexp.escape(m[2])
close = Regexp.escape(delimiter_map[m[2]] || m[2])
interp = /[SRCW]/ === m[1]
toktype = Str::Other
puts " open: #{open.inspect}" if @debug
puts " close: #{close.inspect}" if @debug
# regexes
if 'Rr'.include? m[1]
toktype = Str::Regex
push :regex_flags
end
if 'Ww'.include? m[1]
push :list_flags
end
token toktype
push do
rule %r/#{close}/, toktype, :pop!
if interp
mixin :interpoling
rule %r/#/, toktype
else
rule %r/[\\#]/, toktype
end
uniq_chars = [open, close].uniq.join
rule %r/[^##{uniq_chars}\\]+/m, toktype
end
end
end
state :regex_flags do
rule %r/[fgimrsux]*/, Str::Regex, :pop!
end
state :list_flags do
rule %r/[csa]?/, Str::Other, :pop!
end
end
end
end
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Elm < RegexLexer
title "Elm"
desc "The Elm programming language (http://elm-lang.org/)"
tag 'elm'
filenames '*.elm'
mimetypes 'text/x-elm'
# Keywords are logically grouped by lines
keywords = %w(
module exposing port
import as
type alias
if then else
case of
let in
)
state :root do
# Whitespaces
rule %r/\s+/m, Text
# Single line comments
rule %r/--.*/, Comment::Single
# Multiline comments
rule %r/{-/, Comment::Multiline, :multiline_comment
# Keywords
rule %r/\b(#{keywords.join('|')})\b/, Keyword
# Variable or a function
rule %r/[a-z]\w*/, Name
# Underscore is a name for a variable, when it won't be used later
rule %r/_/, Name
# Type
rule %r/[A-Z]\w*/, Keyword::Type
# Two symbol operators: -> :: // .. && || ++ |> <| << >> == /= <= >=
rule %r/(->|::|\/\/|\.\.|&&|\|\||\+\+|\|>|<\||>>|<<|==|\/=|<=|>=)/, Operator
# One symbol operators: + - / * % = < > ^ | !
rule %r/[+-\/*%=<>^\|!]/, Operator
# Lambda operator
rule %r/\\/, Operator
# Not standard Elm operators, but these symbols can be used for custom inflix operators. We need to highlight them as operators as well.
rule %r/[@\#$&~?]/, Operator
# Single, double quotes, and triple double quotes
rule %r/"""/, Str, :multiline_string
rule %r/'(\\.|.)'/, Str::Char
rule %r/"/, Str, :double_quote
# Numbers
rule %r/0x[\da-f]+/i, Num::Hex
rule %r/\d+e[+-]?\d+/i, Num::Float
rule %r/\d+\.\d+(e[+-]?\d+)?/i, Num::Float
rule %r/\d+/, Num::Integer
# Punctuation: [ ] ( ) , ; ` { } :
rule %r/[\[\](),;`{}:]/, Punctuation
end
# Multiline and nested commenting
state :multiline_comment do
rule %r/-}/, Comment::Multiline, :pop!
rule %r/{-/, Comment::Multiline, :multiline_comment
rule %r/[^-{}]+/, Comment::Multiline
rule %r/[-{}]/, Comment::Multiline
end
# Double quotes
state :double_quote do
rule %r/[^\\"]+/, Str::Double
rule %r/\\"/, Str::Escape
rule %r/"/, Str::Double, :pop!
end
# Multiple line string with triple double quotes, e.g. """ multi """
state :multiline_string do
rule %r/\\"/, Str::Escape
rule %r/"""/, Str, :pop!
rule %r/[^"]+/, Str
rule %r/"/, Str
end
end
end
end
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Email < RegexLexer
tag 'email'
aliases 'eml', 'e-mail'
filenames '*.eml'
mimetypes 'message/rfc822'
title "Email"
desc "An email message"
start do
push :fields
end
state :fields do
rule %r/[:]/, Operator, :field_body
rule %r/[^\n\r:]+/, Name::Tag
rule %r/[\n\r]/, Name::Tag
end
state :field_body do
rule(/(\r?\n){2}/) { token Text; pop!(2) }
rule %r/\r?\n(?![ \v\t\f])/, Text, :pop!
rule %r/[^\n\r]+/, Name::Attribute
rule %r/[\n\r]/, Name::Attribute
end
state :root do
rule %r/\n/, Text
rule %r/^>.*/, Comment
rule %r/.+/, Text
end
end
end
end
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class EPP < TemplateLexer
title "EPP"
desc "Embedded Puppet template files"
tag 'epp'
filenames '*.epp'
def initialize(opts={})
super(opts)
@parent = lexer_option(:parent) { PlainText.new(opts) }
@puppet_lexer = Puppet.new(opts)
end
start do
parent.reset!
@puppet_lexer.reset!
end
open = /<%%|<%=|<%#|(<%-|<%)(\s*\|)?/
close = /%%>|(\|\s*)?(-%>|%>)/
state :root do
rule %r/<%#/, Comment, :comment
rule open, Comment::Preproc, :puppet
rule %r/.+?(?=#{open})|.+/m do
delegate parent
end
end
state :comment do
rule close, Comment, :pop!
rule %r/.+?(?=#{close})|.+/m, Comment
end
state :puppet do
rule close, Comment::Preproc, :pop!
rule %r/.+?(?=#{close})|.+/m do
delegate @puppet_lexer
end
end
end
end
end
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class ERB < TemplateLexer
title "ERB"
desc "Embedded ruby template files"
tag 'erb'
aliases 'eruby', 'rhtml'
filenames '*.erb', '*.erubis', '*.rhtml', '*.eruby'
def initialize(opts={})
@ruby_lexer = Ruby.new(opts)
super(opts)
end
start do
parent.reset!
@ruby_lexer.reset!
end
open = /<%%|<%=|<%#|<%-|<%/
close = /%%>|-%>|%>/
state :root do
rule %r/<%#/, Comment, :comment
rule open, Comment::Preproc, :ruby
rule %r/.+?(?=#{open})|.+/m do
delegate parent
end
end
state :comment do
rule close, Comment, :pop!
rule %r/.+?(?=#{close})|.+/m, Comment
end
state :ruby do
rule close, Comment::Preproc, :pop!
rule %r/.+?(?=#{close})|.+/m do
delegate @ruby_lexer
end
end
end
end
end
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Erlang < RegexLexer
title "Erlang"
desc "The Erlang programming language (erlang.org)"
tag 'erlang'
aliases 'erl'
filenames '*.erl', '*.hrl'
mimetypes 'text/x-erlang', 'application/x-erlang'
keywords = %w(
after begin case catch cond end fun if
let of query receive try when
)
builtins = %w(
abs append_element apply atom_to_list binary_to_list
bitstring_to_list binary_to_term bit_size bump_reductions
byte_size cancel_timer check_process_code delete_module
demonitor disconnect_node display element erase exit
float float_to_list fun_info fun_to_list
function_exported garbage_collect get get_keys
group_leader hash hd integer_to_list iolist_to_binary
iolist_size is_atom is_binary is_bitstring is_boolean
is_builtin is_float is_function is_integer is_list
is_number is_pid is_port is_process_alive is_record
is_reference is_tuple length link list_to_atom
list_to_binary list_to_bitstring list_to_existing_atom
list_to_float list_to_integer list_to_pid list_to_tuple
load_module localtime_to_universaltime make_tuple md5
md5_final md5_update memory module_loaded monitor
monitor_node node nodes open_port phash phash2
pid_to_list port_close port_command port_connect
port_control port_call port_info port_to_list
process_display process_flag process_info purge_module
put read_timer ref_to_list register resume_process
round send send_after send_nosuspend set_cookie
setelement size spawn spawn_link spawn_monitor
spawn_opt split_binary start_timer statistics
suspend_process system_flag system_info system_monitor
system_profile term_to_binary tl trace trace_delivered
trace_info trace_pattern trunc tuple_size tuple_to_list
universaltime_to_localtime unlink unregister whereis
)
operators = %r{(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)}
word_operators = %w(
and andalso band bnot bor bsl bsr bxor
div not or orelse rem xor
)
atom_re = %r{(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')}
variable_re = %r{(?:[A-Z_][a-zA-Z0-9_]*)}
escape_re = %r{(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))}
macro_re = %r{(?:#{variable_re}|#{atom_re})}
base_re = %r{(?:[2-9]|[12][0-9]|3[0-6])}
state :root do
rule(/\s+/, Text)
rule(/%.*\n/, Comment)
rule(%r{(#{keywords.join('|')})\b}, Keyword)
rule(%r{(#{builtins.join('|')})\b}, Name::Builtin)
rule(%r{(#{word_operators.join('|')})\b}, Operator::Word)
rule(/^-/, Punctuation, :directive)
rule(operators, Operator)
rule(/"/, Str, :string)
rule(/<</, Name::Label)
rule(/>>/, Name::Label)
rule %r{(#{atom_re})(:)} do
groups Name::Namespace, Punctuation
end
rule %r{(?:^|(?<=:))(#{atom_re})(\s*)(\()} do
groups Name::Function, Text, Punctuation
end
rule(%r{[+-]?#{base_re}#[0-9a-zA-Z]+}, Num::Integer)
rule(/[+-]?\d+/, Num::Integer)
rule(/[+-]?\d+.\d+/, Num::Float)
rule(%r{[\]\[:_@\".{}()|;,]}, Punctuation)
rule(variable_re, Name::Variable)
rule(atom_re, Name)
rule(%r{\?#{macro_re}}, Name::Constant)
rule(%r{\$(?:#{escape_re}|\\[ %]|[^\\])}, Str::Char)
rule(%r{##{atom_re}(:?\.#{atom_re})?}, Name::Label)
end
state :string do
rule(escape_re, Str::Escape)
rule(/"/, Str, :pop!)
rule(%r{~[0-9.*]*[~#+bBcdefginpPswWxX]}, Str::Interpol)
rule(%r{[^"\\~]+}, Str)
rule(/~/, Str)
end
state :directive do
rule %r{(define)(\s*)(\()(#{macro_re})} do
groups Name::Entity, Text, Punctuation, Name::Constant
pop!
end
rule %r{(record)(\s*)(\()(#{macro_re})} do
groups Name::Entity, Text, Punctuation, Name::Label
pop!
end
rule(atom_re, Name::Entity, :pop!)
end
end
end
end
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Escape < Lexer
tag 'escape'
aliases 'esc'
desc 'A generic lexer for including escaped content - see Formatter.enable_escape!'
option :start, 'the beginning of the escaped section, default "<!"'
option :end, 'the end of the escaped section, e.g. "!>"'
option :lang, 'the language to lex in unescaped sections'
attr_reader :start
attr_reader :end
attr_reader :lang
def initialize(*)
super
@start = string_option(:start) { '<!' }
@end = string_option(:end) { '!>' }
@lang = lexer_option(:lang) { PlainText.new }
end
def to_start_regex
@to_start_regex ||= /(.*?)(#{Regexp.escape(@start)})/m
end
def to_end_regex
@to_end_regex ||= /(.*?)(#{Regexp.escape(@end)})/m
end
def stream_tokens(str, &b)
stream = StringScanner.new(str)
loop do
if stream.scan(to_start_regex)
puts "pre-escape: #{stream[1].inspect}" if @debug
@lang.continue_lex(stream[1], &b)
else
# no more start delimiters, scan til the end
@lang.continue_lex(stream.rest, &b)
return
end
if stream.scan(to_end_regex)
yield Token::Tokens::Escape, stream[1]
else
yield Token::Tokens::Escape, stream.rest
return
end
end
end
end
end
end
@@ -0,0 +1,303 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Factor < RegexLexer
title "Factor"
desc "Factor, the practical stack language (factorcode.org)"
tag 'factor'
filenames '*.factor'
mimetypes 'text/x-factor'
def self.detect?(text)
return true if text.shebang? 'factor'
end
def self.builtins
@builtins ||= {}.tap do |builtins|
builtins[:kernel] = Set.new %w(
or 2bi 2tri while wrapper nip 4dip wrapper? bi*
callstack>array both? hashcode die dupd callstack
callstack? 3dup tri@ pick curry build ?execute 3bi prepose
>boolean if clone eq? tri* ? = swapd 2over 2keep 3keep clear
2dup when not tuple? dup 2bi* 2tri* call tri-curry object bi@
do unless* if* loop bi-curry* drop when* assert= retainstack
assert? -rot execute 2bi@ 2tri@ boa with either? 3drop bi
curry? datastack until 3dip over 3curry tri-curry* tri-curry@
swap and 2nip throw bi-curry (clone) hashcode* compose 2dip if
3tri unless compose? tuple keep 2curry equal? assert tri 2drop
most <wrapper> boolean? identity-hashcode identity-tuple?
null new dip bi-curry@ rot xor identity-tuple boolean
)
builtins[:assocs] = Set.new %w(
?at assoc? assoc-clone-like assoc= delete-at* assoc-partition
extract-keys new-assoc value? assoc-size map>assoc push-at
assoc-like key? assoc-intersect assoc-refine update
assoc-union assoc-combine at* assoc-empty? at+ set-at
assoc-all? assoc-subset? assoc-hashcode change-at assoc-each
assoc-diff zip values value-at rename-at inc-at enum? at cache
assoc>map <enum> assoc assoc-map enum value-at* assoc-map-as
>alist assoc-filter-as clear-assoc assoc-stack maybe-set-at
substitute assoc-filter 2cache delete-at assoc-find keys
assoc-any? unzip
)
builtins[:combinators] = Set.new %w(
case execute-effect no-cond no-case? 3cleave>quot 2cleave
cond>quot wrong-values? no-cond? cleave>quot no-case case>quot
3cleave wrong-values to-fixed-point alist>quot case-find
cond cleave call-effect 2cleave>quot recursive-hashcode
linear-case-quot spread spread>quot
)
builtins[:math] = Set.new %w(
number= if-zero next-power-of-2 each-integer ?1+
fp-special? imaginary-part unless-zero float>bits number?
fp-infinity? bignum? fp-snan? denominator fp-bitwise= *
+ power-of-2? - u>= / >= bitand log2-expects-positive <
log2 > integer? number bits>double 2/ zero? (find-integer)
bits>float float? shift ratio? even? ratio fp-sign bitnot
>fixnum complex? /i /f byte-array>bignum when-zero sgn >bignum
next-float u< u> mod recip rational find-last-integer >float
(all-integers?) 2^ times integer fixnum? neg fixnum sq bignum
(each-integer) bit? fp-qnan? find-integer complex <fp-nan>
real double>bits bitor rem fp-nan-payload all-integers?
real-part log2-expects-positive? prev-float align unordered?
float fp-nan? abs bitxor u<= odd? <= /mod rational? >integer
real? numerator
)
builtins[:sequences] = Set.new %w(
member-eq? append assert-sequence= find-last-from
trim-head-slice clone-like 3sequence assert-sequence? map-as
last-index-from reversed index-from cut* pad-tail
remove-eq! concat-as but-last snip trim-tail nths
nth 2selector sequence slice? <slice> partition
remove-nth tail-slice empty? tail* if-empty
find-from virtual-sequence? member? set-length
drop-prefix unclip unclip-last-slice iota map-sum
bounds-error? sequence-hashcode-step selector-for
accumulate-as map start midpoint@ (accumulate) rest-slice
prepend fourth sift accumulate! new-sequence follow map! like
first4 1sequence reverse slice unless-empty padding virtual@
repetition? set-last index 4sequence max-length set-second
immutable-sequence first2 first3 replicate-as reduce-index
unclip-slice supremum suffix! insert-nth trim-tail-slice
tail 3append short count suffix concat flip filter sum
immutable? reverse! 2sequence map-integers delete-all start*
indices snip-slice check-slice sequence? head map-find
filter! append-as reduce sequence= halves collapse-slice
interleave 2map filter-as binary-reduce slice-error? product
bounds-check? bounds-check harvest immutable virtual-exemplar
find produce remove pad-head last replicate set-fourth
remove-eq shorten reversed? map-find-last 3map-as
2unclip-slice shorter? 3map find-last head-slice pop* 2map-as
tail-slice* but-last-slice 2map-reduce iota? collector-for
accumulate each selector append! new-resizable cut-slice
each-index head-slice* 2reverse-each sequence-hashcode
pop set-nth ?nth <flat-slice> second join when-empty
collector immutable-sequence? <reversed> all? 3append-as
virtual-sequence subseq? remove-nth! push-either new-like
length last-index push-if 2all? lengthen assert-sequence
copy map-reduce move third first 3each tail? set-first prefix
bounds-error any? <repetition> trim-slice exchange surround
2reduce cut change-nth min-length set-third produce-as
push-all head? delete-slice rest sum-lengths 2each head*
infimum remove! glue slice-error subseq trim replace-slice
push repetition map-index trim-head unclip-last mismatch
)
builtins[:namespaces] = Set.new %w(
global +@ change set-namestack change-global init-namespaces
on off set-global namespace set with-scope bind with-variable
inc dec counter initialize namestack get get-global make-assoc
)
builtins[:arrays] = Set.new %w(
<array> 2array 3array pair >array 1array 4array pair?
array resize-array array?
)
builtins[:io] = Set.new %w(
+character+ bad-seek-type? readln each-morsel
stream-seek read print with-output-stream contents
write1 stream-write1 stream-copy stream-element-type
with-input-stream stream-print stream-read stream-contents
stream-tell tell-output bl seek-output bad-seek-type nl
stream-nl write flush stream-lines +byte+ stream-flush
read1 seek-absolute? stream-read1 lines stream-readln
stream-read-until each-line seek-end with-output-stream*
seek-absolute with-streams seek-input seek-relative?
input-stream stream-write read-partial seek-end?
seek-relative error-stream read-until with-input-stream*
with-streams* tell-input each-block output-stream
stream-read-partial each-stream-block each-stream-line
)
builtins[:strings] = Set.new %w(
resize-string >string <string> 1string string string?
)
builtins[:vectors] = Set.new %w(
with-return restarts return-continuation with-datastack
recover rethrow-restarts <restart> ifcc set-catchstack
>continuation< cleanup ignore-errors restart?
compute-restarts attempt-all-error error-thread
continue <continuation> attempt-all-error? condition?
<condition> throw-restarts error catchstack continue-with
thread-error-hook continuation rethrow callcc1
error-continuation callcc0 attempt-all condition
continuation? restart return
)
builtins[:continuations] = Set.new %w(
with-return restarts return-continuation with-datastack
recover rethrow-restarts <restart> ifcc set-catchstack
>continuation< cleanup ignore-errors restart?
compute-restarts attempt-all-error error-thread
continue <continuation> attempt-all-error? condition?
<condition> throw-restarts error catchstack continue-with
thread-error-hook continuation rethrow callcc1
error-continuation callcc0 attempt-all condition
continuation? restart return
)
end
end
state :root do
rule %r/\s+/m, Text
rule %r/(:|::|MACRO:|MEMO:|GENERIC:|HELP:)(\s+)(\S+)/m do
groups Keyword, Text, Name::Function
end
rule %r/(M:|HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)/m do
groups Keyword, Text, Name::Class, Text, Name::Function
end
rule %r/\((?=\s)/, Name::Function, :stack_effect
rule %r/;(?=\s)/, Keyword
rule %r/(USING:)((?:\s|\\\s)+)/m do
groups Keyword::Namespace, Text
push :import
end
rule %r/(IN:|USE:|UNUSE:|QUALIFIED:|QUALIFIED-WITH:)(\s+)(\S+)/m do
groups Keyword::Namespace, Text, Name::Namespace
end
rule %r/(FROM:|EXCLUDE:)(\s+)(\S+)(\s+)(=>)/m do
groups Keyword::Namespace, Text, Name::Namespace, Text, Punctuation
end
rule %r/(?:ALIAS|DEFER|FORGET|POSTPONE):/, Keyword::Namespace
rule %r/(TUPLE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
groups(
Keyword, Text,
Name::Class, Text,
Punctuation, Text,
Name::Class
)
push :slots
end
rule %r/(TUPLE:)(\s+)(\S+)/m do
groups Keyword, Text, Name::Class
push :slots
end
rule %r/(UNION:|INTERSECTION:)(\s+)(\S+)/m do
groups Keyword, Text, Name::Class
end
rule %r/(PREDICATE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
groups(
Keyword, Text,
Name::Class, Text,
Punctuation, Text,
Name::Class
)
end
rule %r/(C:)(\s+)(\S+)(\s+)(\S+)/m do
groups(
Keyword, Text,
Name::Function, Text,
Name::Class
)
end
rule %r(
(INSTANCE|SLOT|MIXIN|SINGLETONS?|CONSTANT|SYMBOLS?|ERROR|SYNTAX
|ALIEN|TYPEDEF|FUNCTION|STRUCT):
)x, Keyword
rule %r/(?:<PRIVATE|PRIVATE>)/, Keyword::Namespace
rule %r/(MAIN:)(\s+)(\S+)/ do
groups Keyword::Namespace, Text, Name::Function
end
# strings
rule %r/"(?:\\\\|\\"|[^"])*"/, Str
rule %r/\S+"\s+(?:\\\\|\\"|[^"])*"/, Str
rule %r/(CHAR:)(\s+)(\\[\\abfnrstv]*|\S)(?=\s)/, Str::Char
# comments
rule %r/!\s+.*$/, Comment
rule %r/#!\s+.*$/, Comment
# booleans
rule %r/[tf](?=\s)/, Name::Constant
# numbers
rule %r/-?\d+\.\d+(?=\s)/, Num::Float
rule %r/-?\d+(?=\s)/, Num::Integer
rule %r/HEX:\s+[a-fA-F\d]+(?=\s)/m, Num::Hex
rule %r/BIN:\s+[01]+(?=\s)/, Num::Bin
rule %r/OCT:\s+[0-7]+(?=\s)/, Num::Oct
rule %r([-+/*=<>^](?=\s)), Operator
rule %r/(?:deprecated|final|foldable|flushable|inline|recursive)(?=\s)/,
Keyword
rule %r/\S+/ do |m|
name = m[0]
if self.class.builtins.values.any? { |b| b.include? name }
token Name::Builtin
else
token Name
end
end
end
state :stack_effect do
rule %r/\s+/, Text
rule %r/\(/, Name::Function, :stack_effect
rule %r/\)/, Name::Function, :pop!
rule %r/--/, Name::Function
rule %r/\S+/, Name::Variable
end
state :slots do
rule %r/\s+/, Text
rule %r/;(?=\s)/, Keyword, :pop!
rule %r/\S+/, Name::Variable
end
state :import do
rule %r/;(?=\s)/, Keyword, :pop!
rule %r/\s+/, Text
rule %r/\S+/, Name::Namespace
end
end
end
end
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Fluent < RegexLexer
title 'Fluent'
desc 'Fluent localization files'
tag 'fluent'
aliases 'ftl'
filenames '*.ftl'
state :root do
rule %r{( *)(\=)( *)} do
groups Text::Whitespace, Punctuation, Text::Whitespace
push :template
end
rule %r{(?:\s*\n)+}m, Text::Whitespace
rule %r{\#{1,3}(?: .*)?$}, Comment::Single
rule %r{[a-zA-Z][a-zA-Z0-9_-]*}, Name::Constant
rule %r{\-[a-zA-Z][a-zA-Z0-9_-]*}, Name::Entity
rule %r{\s*\.[a-zA-Z][a-zA-Z0-9_-]*}, Name::Attribute
rule %r{\s+(?=[^\s\.])}, Text::Whitespace, :template
end
state :template do
rule %r{\n}m, Text::Whitespace, :pop!
rule %r{[^\{\n\}\*]+}, Text
rule %r{\{}, Punctuation, :placeable
rule %r{(?=\})}, Punctuation, :pop!
end
state :placeable do
rule %r{\s+}m, Text::Whitespace
rule %r{\{}, Punctuation, :placeable
rule %r{\}}, Punctuation, :pop!
rule %r{\$[a-zA-Z][a-zA-Z0-9_-]*}, Name::Variable
rule %r{\-[a-zA-Z][a-zA-Z0-9_-]*}, Name::Entity
rule %r{\.[a-zA-Z][a-zA-Z0-9_-]*}, Name::Attribute
rule %r{[A-Z]+}, Name::Builtin
rule %r{[a-zA-Z][a-zA-Z0-9_-]*}, Name::Constant
rule %r{[\(\),\:]}, Punctuation
rule %r{->}, Punctuation
rule %r{\*}, Punctuation::Indicator
rule %r{\-?\d+\.\d+?}, Literal::Number::Float
rule %r{\-?\d+}, Literal::Number::Integer
rule %r{"}, Str::Double, :string
rule %r{(\[)(\-?\d+\.\d+)(\])} do
groups Punctuation, Literal::Number::Float, Punctuation
push :template
end
rule %r{(\[)(\-?\d+)(\])} do
groups Punctuation, Literal::Number::Integer, Punctuation
push :template
end
rule %r{(\[)([a-zA-Z][a-zA-Z0-9_-]+)(\])} do
groups Punctuation, Str::Symbol, Punctuation
push :template
end
end
state :string do
rule %r{\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{6}}, Str::Escape
rule %r{\\.}, Str::Escape
rule %r{[^\"\\]}, Str::Double
rule %r{"}, Str::Double, :pop!
end
end
end
end
@@ -0,0 +1,178 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# vim: set ts=2 sw=2 et:
# TODO: Implement format list support.
module Rouge
module Lexers
class Fortran < RegexLexer
title "Fortran"
desc "Fortran 2008 (free-form)"
tag 'fortran'
filenames '*.f', '*.f90', '*.f95', '*.f03', '*.f08',
'*.F', '*.F90', '*.F95', '*.F03', '*.F08'
mimetypes 'text/x-fortran'
name = /[A-Z][_A-Z0-9]*/i
kind_param = /(\d+|#{name})/
exponent = /[ED][+-]?\d+/i
def self.keywords
# Special rules for two-word keywords are defined further down.
# Note: Fortran allows to omit whitespace between certain keywords.
@keywords ||= Set.new %w(
abstract allocatable allocate assign assignment associate asynchronous
backspace bind block blockdata call case class close codimension
common concurrent contains contiguous continue critical cycle data
deallocate deferred dimension do elemental else elseif elsewhere end
endassociate endblock endblockdata enddo endenum endfile endforall
endfunction endif endinterface endmodule endprogram endselect
endsubmodule endsubroutine endtype endwhere endwhile entry enum
enumerator equivalence exit extends external final flush forall format
function generic goto if implicit import in include inout inquire
intent interface intrinsic is lock module namelist non_overridable
none nopass nullify only open operator optional out parameter pass
pause pointer print private procedure program protected public pure
read recursive result return rewind save select selectcase sequence
stop submodule subroutine target then type unlock use value volatile
wait where while write
)
end
def self.types
# A special rule for the two-word version "double precision" is
# defined further down.
@types ||= Set.new %w(
character complex doubleprecision integer logical real
)
end
def self.intrinsics
@intrinsics ||= Set.new %w(
abs achar acos acosh adjustl adjustr aimag aint all allocated anint
any asin asinh associated atan atan2 atanh atomic_define atomic_ref
bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn bge bgt
bit_size ble blt btest c_associated c_f_pointer c_f_procpointer
c_funloc c_loc c_sizeof ceiling char cmplx command_argument_count
compiler_options compiler_version conjg cos cosh count cpu_time cshift
date_and_time dble digits dim dot_product dprod dshiftl dshiftr
eoshift epsilon erf erfc_scaled erfc execute_command_line exp exponent
extends_type_of findloc floor fraction gamma get_command_argument
get_command get_environment_variable huge hypot iachar iall iand iany
ibclr ibits ibset ichar ieee_class ieee_copy_sign ieee_get_flag
ieee_get_halting_mode ieee_get_rounding_mode ieee_get_status
ieee_get_underflow_mode ieee_is_finite ieee_is_nan ieee_is_normal
ieee_logb ieee_next_after ieee_rem ieee_rint ieee_scalb
ieee_selected_real_kind ieee_set_flag ieee_set_halting_mode
ieee_set_rounding_mode ieee_set_status ieee_set_underflow_mode
ieee_support_datatype ieee_support_denormal ieee_support_divide
ieee_support_flag ieee_support_halting ieee_support_inf
ieee_support_io ieee_support_nan ieee_support_rounding
ieee_support_sqrt ieee_support_standard ieee_support_underflow_control
ieee_unordered ieee_value ieor image_index index int ior iparity
is_contiguous is_iostat_end is_iostat_eor ishft ishftc kind lbound
lcobound leadz len_trim len lge lgt lle llt log_gamma log log10
logical maskl maskr matmul max maxexponent maxloc maxval merge_bits
merge min minexponent minloc minval mod modulo move_alloc mvbits
nearest new_line nint norm2 not null num_images pack parity popcnt
poppar present product radix random_number random_seed range real
repeat reshape rrspacing same_type_as scale scan selected_char_kind
selected_int_kind selected_real_kind set_exponent shape shifta shiftl
shiftr sign sin sinh size spacing spread sqrt storage_size sum
system_clock tan tanh this_image tiny trailz transfer transpose trim
ubound ucobound unpack verify
)
end
state :root do
rule %r/[\s]+/, Text::Whitespace
rule %r/!.*$/, Comment::Single
rule %r/^#.*$/, Comment::Preproc
rule %r/::|[()\/;,:&\[\]]/, Punctuation
# TODO: This does not take into account line continuation.
rule %r/^(\s*)([0-9]+)\b/m do |m|
token Text::Whitespace, m[1]
token Name::Label, m[2]
end
# Format statements are quite a strange beast.
# Better process them in their own state.
rule %r/\b(FORMAT)(\s*)(\()/mi do |m|
token Keyword, m[1]
token Text::Whitespace, m[2]
token Punctuation, m[3]
push :format_spec
end
rule %r(
[+-]? # sign
(
(\d+[.]\d*|[.]\d+)(#{exponent})?
| \d+#{exponent} # exponent is mandatory
)
(_#{kind_param})? # kind parameter
)xi, Num::Float
rule %r/[+-]?\d+(_#{kind_param})?/i, Num::Integer
rule %r/B'[01]+'|B"[01]+"/i, Num::Bin
rule %r/O'[0-7]+'|O"[0-7]+"/i, Num::Oct
rule %r/Z'[0-9A-F]+'|Z"[0-9A-F]+"/i, Num::Hex
rule %r/(#{kind_param}_)?'/, Str::Single, :string_single
rule %r/(#{kind_param}_)?"/, Str::Double, :string_double
rule %r/[.](TRUE|FALSE)[.](_#{kind_param})?/i, Keyword::Constant
rule %r{\*\*|//|==|/=|<=|>=|=>|[-+*/<>=%]}, Operator
rule %r/\.(?:EQ|NE|LT|LE|GT|GE|NOT|AND|OR|EQV|NEQV|[A-Z]+)\./i, Operator::Word
# Special rules for two-word keywords and types.
# Note: "doubleprecision" is covered by the normal keyword rule.
rule %r/double\s+precision\b/i, Keyword::Type
rule %r/go\s+to\b/i, Keyword
rule %r/sync\s+(all|images|memory)\b/i, Keyword
rule %r/error\s+stop\b/i, Keyword
rule %r/#{name}/m do |m|
match = m[0].downcase
if self.class.keywords.include? match
token Keyword
elsif self.class.types.include? match
token Keyword::Type
elsif self.class.intrinsics.include? match
token Name::Builtin
else
token Name
end
end
end
state :string_single do
rule %r/[^']+/, Str::Single
rule %r/''/, Str::Escape
rule %r/'/, Str::Single, :pop!
end
state :string_double do
rule %r/[^"]+/, Str::Double
rule %r/""/, Str::Escape
rule %r/"/, Str::Double, :pop!
end
state :format_spec do
rule %r/'/, Str::Single, :string_single
rule %r/"/, Str::Double, :string_double
rule %r/\(/, Punctuation, :format_spec
rule %r/\)/, Punctuation, :pop!
rule %r/,/, Punctuation
rule %r/[\s]+/, Text::Whitespace
# Edit descriptors could be seen as a kind of "format literal".
rule %r/[^\s'"(),]+/, Literal
end
end
end
end
@@ -0,0 +1,240 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'cpp.rb'
class FreeFEM < Cpp
title "FreeFEM"
desc "The FreeFEM programming language (freefem.org)"
tag 'freefem'
aliases 'ff'
filenames '*.edp', '*.idp'
mimetypes 'text/x-ffhdr', 'text/x-ffsrc'
# Override C/C++ ones (for example, `do` does not exists)
def self.keywords
@keywords ||= Set.new(%w(
break catch continue else for if return try while
))
end
# Override C/C++ ones (for example, `double` does not exists)
def self.keywords_type
@keywords_type ||= Set.new(%w(
bool border complex dmatrix fespace func gslspline ifstream int macro
matrix mesh mesh3 mpiComm mpiGroup mpiRequest NewMacro EndMacro
ofstream Pmmap problem Psemaphore real solve string varf
))
end
# Override C/C++ ones (totally different)
def self.reserved
@reserved ||= Set.new(%w(
BDM1 BDM1Ortho Edge03d Edge13d Edge23d FEQF HCT P0 P03d P0Edge P1
P13d P1b P1b3d P1bl P1bl3d P1dc P1Edge P1nc P2 P23d P2b P2BR P2dc
P2Edge P2h P2Morley P2pnc P3 P3dc P3Edge P4 P4dc P4Edge P5Edge RT0
RT03d RT0Ortho RT1 RT1Ortho RT2 RT2Ortho
qf1pE qf1pElump qf1pT qf1pTlump qfV1 qfV1lump qf2pE qf2pT qf2pT4P1
qfV2 qf3pE qf4pE qf5pE qf5pT qfV5 qf7pT qf9pT qfnbpE
ARGV append area be binary BoundaryEdge bordermeasure CG Cholesky cin
cout Crout default diag edgeOrientation endl FILE fixed GMRES good
hTriangle im imax imin InternalEdge l1 l2 label lenEdge length LINE
linfty LU m max measure min mpiAnySource mpiBAND mpiBXOR mpiCommWorld
mpiLAND mpiLOR mpiLXOR mpiMAX mpiMIN mpiPROD mpirank mpisize mpiSUM
mpiUndefined n N nbe ndof ndofK noshowbase noshowpos notaregion nt
nTonEdge nuEdge nuTriangle nv P pi precision quantile re region
scientific searchMethod setw showbase showpos sparsesolver sum tellp
true UMFPACK unused whoinElement verbosity version volume x y z
))
end
def self.builtins
@builtins ||= Set.new(%w(
abs acos acosh adaptmesh adj AffineCG AffineGMRES arg asin asinh
assert atan atan2 atanh atof atoi BFGS broadcast buildlayers
buildmesh ceil chi complexEigenValue copysign change checkmovemesh
clock cmaes conj convect cos cosh cube d dd dfft diffnp diffpos
dimKrylov dist dumptable dx dxx dxy dxz dy dyx dyy dyz dz dzx dzy dzz
EigenValue emptymesh erf erfc exec exit exp fdim ffind find floor
flush fmax fmin fmod freeyams getARGV getline gmshload gmshload3
gslcdfugaussianP gslcdfugaussianQ gslcdfugaussianPinv
gslcdfugaussianQinv gslcdfgaussianP gslcdfgaussianQ
gslcdfgaussianPinv gslcdfgaussianQinv gslcdfgammaP gslcdfgammaQ
gslcdfgammaPinv gslcdfgammaQinv gslcdfcauchyP gslcdfcauchyQ
gslcdfcauchyPinv gslcdfcauchyQinv gslcdflaplaceP gslcdflaplaceQ
gslcdflaplacePinv gslcdflaplaceQinv gslcdfrayleighP gslcdfrayleighQ
gslcdfrayleighPinv gslcdfrayleighQinv gslcdfchisqP gslcdfchisqQ
gslcdfchisqPinv gslcdfchisqQinv gslcdfexponentialP gslcdfexponentialQ
gslcdfexponentialPinv gslcdfexponentialQinv gslcdfexppowP
gslcdfexppowQ gslcdftdistP gslcdftdistQ gslcdftdistPinv
gslcdftdistQinv gslcdffdistP gslcdffdistQ gslcdffdistPinv
gslcdffdistQinv gslcdfbetaP gslcdfbetaQ gslcdfbetaPinv gslcdfbetaQinv
gslcdfflatP gslcdfflatQ gslcdfflatPinv gslcdfflatQinv
gslcdflognormalP gslcdflognormalQ gslcdflognormalPinv
gslcdflognormalQinv gslcdfgumbel1P gslcdfgumbel1Q gslcdfgumbel1Pinv
gslcdfgumbel1Qinv gslcdfgumbel2P gslcdfgumbel2Q gslcdfgumbel2Pinv
gslcdfgumbel2Qinv gslcdfweibullP gslcdfweibullQ gslcdfweibullPinv
gslcdfweibullQinv gslcdfparetoP gslcdfparetoQ gslcdfparetoPinv
gslcdfparetoQinv gslcdflogisticP gslcdflogisticQ gslcdflogisticPinv
gslcdflogisticQinv gslcdfbinomialP gslcdfbinomialQ gslcdfpoissonP
gslcdfpoissonQ gslcdfgeometricP gslcdfgeometricQ
gslcdfnegativebinomialP gslcdfnegativebinomialQ gslcdfpascalP
gslcdfpascalQ gslinterpakima gslinterpakimaperiodic
gslinterpcsplineperiodic gslinterpcspline gslinterpsteffen
gslinterplinear gslinterppolynomial gslranbernoullipdf gslranbeta
gslranbetapdf gslranbinomialpdf gslranexponential
gslranexponentialpdf gslranexppow gslranexppowpdf gslrancauchy
gslrancauchypdf gslranchisq gslranchisqpdf gslranerlang
gslranerlangpdf gslranfdist gslranfdistpdf gslranflat gslranflatpdf
gslrangamma gslrangammaint gslrangammapdf gslrangammamt
gslrangammaknuth gslrangaussian gslrangaussianratiomethod
gslrangaussianziggurat gslrangaussianpdf gslranugaussian
gslranugaussianratiomethod gslranugaussianpdf gslrangaussiantail
gslrangaussiantailpdf gslranugaussiantail gslranugaussiantailpdf
gslranlandau gslranlandaupdf gslrangeometricpdf gslrangumbel1
gslrangumbel1pdf gslrangumbel2 gslrangumbel2pdf gslranlogistic
gslranlogisticpdf gslranlognormal gslranlognormalpdf
gslranlogarithmicpdf gslrannegativebinomialpdf gslranpascalpdf
gslranpareto gslranparetopdf gslranpoissonpdf gslranrayleigh
gslranrayleighpdf gslranrayleightail gslranrayleightailpdf
gslrantdist gslrantdistpdf gslranlaplace gslranlaplacepdf gslranlevy
gslranweibull gslranweibullpdf gslsfairyAi gslsfairyBi
gslsfairyAiscaled gslsfairyBiscaled gslsfairyAideriv gslsfairyBideriv
gslsfairyAiderivscaled gslsfairyBiderivscaled gslsfairyzeroAi
gslsfairyzeroBi gslsfairyzeroAideriv gslsfairyzeroBideriv
gslsfbesselJ0 gslsfbesselJ1 gslsfbesselJn gslsfbesselY0 gslsfbesselY1
gslsfbesselYn gslsfbesselI0 gslsfbesselI1 gslsfbesselIn
gslsfbesselI0scaled gslsfbesselI1scaled gslsfbesselInscaled
gslsfbesselK0 gslsfbesselK1 gslsfbesselKn gslsfbesselK0scaled
gslsfbesselK1scaled gslsfbesselKnscaled gslsfbesselj0 gslsfbesselj1
gslsfbesselj2 gslsfbesseljl gslsfbessely0 gslsfbessely1 gslsfbessely2
gslsfbesselyl gslsfbesseli0scaled gslsfbesseli1scaled
gslsfbesseli2scaled gslsfbesselilscaled gslsfbesselk0scaled
gslsfbesselk1scaled gslsfbesselk2scaled gslsfbesselklscaled
gslsfbesselJnu gslsfbesselYnu gslsfbesselInuscaled gslsfbesselInu
gslsfbesselKnuscaled gslsfbesselKnu gslsfbessellnKnu
gslsfbesselzeroJ0 gslsfbesselzeroJ1 gslsfbesselzeroJnu gslsfclausen
gslsfhydrogenicR1 gslsfdawson gslsfdebye1 gslsfdebye2 gslsfdebye3
gslsfdebye4 gslsfdebye5 gslsfdebye6 gslsfdilog gslsfmultiply
gslsfellintKcomp gslsfellintEcomp gslsfellintPcomp gslsfellintDcomp
gslsfellintF gslsfellintE gslsfellintRC gslsferfc gslsflogerfc
gslsferf gslsferfZ gslsferfQ gslsfhazard gslsfexp gslsfexpmult
gslsfexpm1 gslsfexprel gslsfexprel2 gslsfexpreln gslsfexpintE1
gslsfexpintE2 gslsfexpintEn gslsfexpintE1scaled gslsfexpintE2scaled
gslsfexpintEnscaled gslsfexpintEi gslsfexpintEiscaled gslsfShi
gslsfChi gslsfexpint3 gslsfSi gslsfCi gslsfatanint gslsffermidiracm1
gslsffermidirac0 gslsffermidirac1 gslsffermidirac2 gslsffermidiracint
gslsffermidiracmhalf gslsffermidirachalf gslsffermidirac3half
gslsffermidiracinc0 gslsflngamma gslsfgamma gslsfgammastar
gslsfgammainv gslsftaylorcoeff gslsffact gslsfdoublefact gslsflnfact
gslsflndoublefact gslsflnchoose gslsfchoose gslsflnpoch gslsfpoch
gslsfpochrel gslsfgammaincQ gslsfgammaincP gslsfgammainc gslsflnbeta
gslsfbeta gslsfbetainc gslsfgegenpoly1 gslsfgegenpoly2
gslsfgegenpoly3 gslsfgegenpolyn gslsfhyperg0F1 gslsfhyperg1F1int
gslsfhyperg1F1 gslsfhypergUint gslsfhypergU gslsfhyperg2F0
gslsflaguerre1 gslsflaguerre2 gslsflaguerre3 gslsflaguerren
gslsflambertW0 gslsflambertWm1 gslsflegendrePl gslsflegendreP1
gslsflegendreP2 gslsflegendreP3 gslsflegendreQ0 gslsflegendreQ1
gslsflegendreQl gslsflegendrePlm gslsflegendresphPlm
gslsflegendrearraysize gslsfconicalPhalf gslsfconicalPmhalf
gslsfconicalP0 gslsfconicalP1 gslsfconicalPsphreg gslsfconicalPcylreg
gslsflegendreH3d0 gslsflegendreH3d1 gslsflegendreH3d gslsflog
gslsflogabs gslsflog1plusx gslsflog1plusxmx gslsfpowint gslsfpsiint
gslsfpsi gslsfpsi1piy gslsfpsi1int gslsfpsi1 gslsfpsin
gslsfsynchrotron1 gslsfsynchrotron2 gslsftransport2 gslsftransport3
gslsftransport4 gslsftransport5 gslsfsin gslsfcos gslsfhypot
gslsfsinc gslsflnsinh gslsflncosh gslsfanglerestrictsymm
gslsfanglerestrictpos gslsfzetaint gslsfzeta gslsfzetam1
gslsfzetam1int gslsfhzeta gslsfetaint gslsfeta imag int1d int2d int3d
intalledges intallfaces interpolate invdiff invdiffnp invdiffpos
Isend isInf isNaN isoline Irecv j0 j1 jn jump lgamma LinearCG
LinearGMRES log log10 lrint lround max mean medit min mmg3d movemesh
movemesh23 mpiAlltoall mpiAlltoallv mpiAllgather mpiAllgatherv
mpiAllReduce mpiBarrier mpiGather mpiGatherv mpiRank mpiReduce
mpiScatter mpiScatterv mpiSize mpiWait mpiWaitAny mpiWtick mpiWtime
mshmet NLCG on plot polar Post pow processor processorblock
projection randinit randint31 randint32 random randreal1 randreal2
randreal3 randres53 Read readmesh readmesh3 Recv rfind rint round
savemesh savesol savevtk seekg Sent set sign signbit sin sinh sort
splitComm splitmesh sqrt square srandom srandomdev Stringification
swap system tan tanh tellg tetg tetgconvexhull tetgreconstruction
tetgtransfo tgamma triangulate trunc Wait Write y0 y1 yn
))
end
def self.attributes
@builtinsParameters ||= Set.new(%w(
A A1 abserror absolute aniso aspectratio B B1 bb beginend bin
boundary bw close cmm coef composante cutoff datafilename dataname
dim distmax displacement doptions dparams eps err errg facemerge
facetcl factorize file fill fixedborder flabel flags floatmesh
floatsol fregion gradation grey hmax hmin holelist hsv init inquire
inside IsMetric iso ivalue keepbackvertices label labeldown labelmid
labelup levelset loptions lparams maxit maxsubdiv meditff mem memory
metric mode nbarrow nbiso nbiter nbjacoby nboffacetcl nbofholes
nbofregions nbregul nbsmooth nbvx ncv nev nomeshgeneration
normalization omega op optimize option options order orientation
periodic power precon prev ps ptmerge qfe qforder qft qfV ratio
rawvector reffacelow reffacemid reffaceup refnum reftet reftri region
regionlist renumv rescaling ridgeangle save sigma sizeofvolume
smoothing solver sparams split splitin2 splitpbedge stop strategy
swap switch sym t tgv thetamax tol tolpivot tolpivotsym transfo U2Vc
value varrow vector veps viso wait width withsurfacemesh WindowIndex
which zbound
))
end
id = /[a-z_]\w*/i
state :expr_bol do
mixin :inline_whitespace
rule %r/include/, Comment::Preproc, :macro
rule %r/load/, Comment::Preproc, :macro
rule %r/ENDIFMACRO/, Comment::Preproc, :macro
rule %r/IFMACRO/, Comment::Preproc, :macro
rule(//) { pop! }
end
state :statements do
mixin :whitespace
rule %r/(u8|u|U|L)?"/, Str, :string
rule %r((u8|u|U|L)?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
rule %r((\d+[.]\d*|[.]?\d+)e[+-]?\d+[lu]*)i, Num::Float
rule %r(\d+e[+-]?\d+[lu]*)i, Num::Float
rule %r/0x[0-9a-f]+[lu]*/i, Num::Hex
rule %r/0[0-7]+[lu]*/i, Num::Oct
rule %r/\d+[lu]*/i, Num::Integer
rule %r(\*/), Error
rule %r([~!%^&*+=\|?:<>/-]), Operator
rule %r/'/, Operator
rule %r/[()\[\],.;]/, Punctuation
rule %r/\bcase\b/, Keyword, :case
rule %r/(?:true|false|NaN)\b/, Name::Builtin
rule id do |m|
name = m[0]
if self.class.keywords.include? name
token Keyword
elsif self.class.keywords_type.include? name
token Keyword::Type
elsif self.class.reserved.include? name
token Keyword::Reserved
elsif self.class.builtins.include? name
token Name::Builtin
elsif self.class.attributes.include? name
token Name::Attribute
else
token Name
end
end
end
end
end
end
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class FSharp < RegexLexer
title "FSharp"
desc 'F# (fsharp.net)'
tag 'fsharp'
filenames '*.fs', '*.fsi', '*.fsx'
mimetypes 'application/fsharp-script', 'text/x-fsharp', 'text/x-fsi'
def self.keywords
@keywords ||= Set.new %w(
abstract and as assert base begin class default delegate do
done downcast downto elif else end exception extern false
finally for fun function global if in inherit inline interface
internal lazy let let! match member module mutable namespace
new not null of open or override private public rec return
return! select static struct then to true try type upcast
use use! val void when while with yield yield! sig atomic
break checked component const constraint constructor
continue eager event external fixed functor include method
mixin object parallel process protected pure sealed tailcall
trait virtual volatile
)
end
def self.keyopts
@keyopts ||= Set.new %w(
!= # & && ( ) * \+ , - -. -> . .. : :: := :> ; ;; < <- =
> >] >} ? ?? [ [< [> [| ] _ ` { {< | |] } ~ |> <| <>
)
end
def self.word_operators
@word_operators ||= Set.new %w(and asr land lor lsl lxor mod or)
end
def self.primitives
@primitives ||= Set.new %w(unit int float bool string char list array)
end
operator = %r([\[\];,{}_()!$%&*+./:<=>?@^|~#-]+)
id = /([a-z][\w']*)|(``[^`\n\r\t]+``)/i
upper_id = /[A-Z][\w']*/
state :root do
rule %r/\s+/m, Text
rule %r/false|true|[(][)]|\[\]/, Name::Builtin::Pseudo
rule %r/#{upper_id}(?=\s*[.])/, Name::Namespace, :dotted
rule upper_id, Name::Class
rule %r/[(][*](?![)])/, Comment, :comment
rule %r(//.*?$), Comment::Single
rule id do |m|
match = m[0]
if self.class.keywords.include? match
token Keyword
elsif self.class.word_operators.include? match
token Operator::Word
elsif self.class.primitives.include? match
token Keyword::Type
else
token Name
end
end
rule operator do |m|
match = m[0]
if self.class.keyopts.include? match
token Punctuation
else
token Operator
end
end
rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
rule %r/0x\h[\h_]*/i, Num::Hex
rule %r/0o[0-7][0-7_]*/i, Num::Oct
rule %r/0b[01][01_]*/i, Num::Bin
rule %r/\d[\d_]*/, Num::Integer
rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
rule %r/'[.]'/, Str::Char
rule %r/'/, Keyword
rule %r/"/, Str::Double, :string
rule %r/[~?]#{id}/, Name::Variable
end
state :comment do
rule %r/[^(*)]+/, Comment
rule(/[(][*]/) { token Comment; push }
rule %r/[*][)]/, Comment, :pop!
rule %r/[(*)]/, Comment
end
state :string do
rule %r/[^\\"]+/, Str::Double
mixin :escape_sequence
rule %r/\\\n/, Str::Double
rule %r/"/, Str::Double, :pop!
end
state :escape_sequence do
rule %r/\\[\\"'ntbr]/, Str::Escape
rule %r/\\\d{3}/, Str::Escape
rule %r/\\x\h{2}/, Str::Escape
end
state :dotted do
rule %r/\s+/m, Text
rule %r/[.]/, Punctuation
rule %r/#{upper_id}(?=\s*[.])/, Name::Namespace
rule upper_id, Name::Class, :pop!
rule id, Name, :pop!
rule %r/\[/, Punctuation, :pop!
end
end
end
end
@@ -0,0 +1,171 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class GDScript < RegexLexer
title "GDScript"
desc "The Godot Engine programming language (https://godotengine.org/)"
tag 'gdscript'
aliases 'gd', 'gdscript'
filenames '*.gd'
mimetypes 'text/x-gdscript', 'application/x-gdscript'
def self.keywords
@keywords ||= %w(
and in not or as breakpoint class class_name extends is func setget
signal tool const enum export onready static var break continue
if elif else for pass return match while remote master puppet
remotesync mastersync puppetsync
).join('|')
end
# Reserved for future implementation
def self.keywords_reserved
@keywords_reserved ||= %w(
do switch case
).join('|')
end
def self.builtins
@builtins ||= %w(
Color8 ColorN abs acos asin assert atan atan2 bytes2var ceil char
clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst
ease exp floor fmod fposmod funcref hash inst2dict instance_from_id
is_inf is_nan lerp linear2db load log max min nearest_po2 pow
preload print print_stack printerr printraw prints printt rad2deg
rand_range rand_seed randf randi randomize range round seed sign
sin sinh sqrt stepify str str2var tan tan tanh type_exist typeof
var2bytes var2str weakref yield
).join('|')
end
def self.builtins_type
@builtins_type ||= %w(
bool int float String Vector2 Rect2 Transform2D Vector3 AABB
Plane Quat Basis Transform Color RID Object NodePath Dictionary
Array PoolByteArray PoolIntArray PoolRealArray PoolStringArray
PoolVector2Array PoolVector3Array PoolColorArray null
).join('|')
end
state :root do
rule %r/\n/, Text
rule %r/[^\S\n]+/, Text
rule %r/#.*/, Comment::Single
rule %r/[\[\]{}:(),;]/, Punctuation
rule %r/\\\n/, Text
rule %r/(in|and|or|not)\b/, Operator::Word
rule %r/!=|==|<<|>>|&&|\+=|-=|\*=|\/=|%=|&=|\|=|\|\||[-~+\/*%=<>&^.!|$]/, Operator
rule %r/(func)((?:\s|\\)+)/ do
groups Keyword, Text
push :funcname
end
rule %r/(class)((?:\s|\\)+)/ do
groups Keyword, Text
push :classname
end
mixin :keywords
mixin :builtins
rule %r/"""/, Str::Double, :escape_tdqs
rule %r/'''/, Str::Double, :escape_tsqs
rule %r/"/, Str::Double, :escape_dqs
rule %r/'/, Str::Double, :escape_sqs
mixin :name
mixin :numbers
end
state :keywords do
rule %r/\b(#{GDScript.keywords})\b/, Keyword
rule %r/\b(#{GDScript.keywords_reserved})\b/, Keyword::Reserved
end
state :builtins do
rule %r/\b(#{GDScript.builtins})\b/, Name::Builtin
rule %r/\b((self|false|true)|(PI|TAU|NAN|INF))\b/, Name::Builtin::Pseudo
rule %r/\b(#{GDScript.builtins_type})\b/, Keyword::Type
end
state :numbers do
rule %r/(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?/, Num::Float
rule %r/\d+[eE][+-]?[0-9]+j?/, Num::Float
rule %r/0[xX][a-fA-F0-9]+/, Num::Hex
rule %r/\d+j?/, Num::Integer
end
state :name do
rule %r/[a-zA-Z_]\w*/, Name
end
state :funcname do
rule %r/[a-zA-Z_]\w*/, Name::Function, :pop!
end
state :classname do
rule %r/[a-zA-Z_]\w*/, Name::Class, :pop!
end
state :string_escape do
rule %r/\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})/, Str::Escape
end
state :strings_single do
rule %r/%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]/, Str::Interpol
rule %r/[^\\'%\n]+/, Str::Single
rule %r/["\\]/, Str::Single
rule %r/%/, Str::Single
end
state :strings_double do
rule %r/%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]/, Str::Interpol
rule %r/[^\\"%\n]+/, Str::Double
rule %r/['\\]/, Str::Double
rule %r/%/, Str::Double
end
state :dqs do
rule %r/"/, Str::Double, :pop!
rule %r/\\\\|\\"|\\\n/, Str::Escape
mixin :strings_double
end
state :escape_dqs do
mixin :string_escape
mixin :dqs
end
state :sqs do
rule %r/'/, Str::Single, :pop!
rule %r/\\\\|\\'|\\\n/, Str::Escape
mixin :strings_single
end
state :escape_sqs do
mixin :string_escape
mixin :sqs
end
state :tdqs do
rule %r/"""/, Str::Double, :pop!
mixin :strings_double
rule %r/\n/, Str::Double
end
state :escape_tdqs do
mixin :string_escape
mixin :tdqs
end
state :tsqs do
rule %r/'''/, Str::Single, :pop!
mixin :strings_single
rule %r/\n/, Str::Single
end
state :escape_tsqs do
mixin :string_escape
mixin :tsqs
end
end
end
end
@@ -0,0 +1,340 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# C minus minus (Cmm) is a pun on the name C++. It's an intermediate language
# of the Glasgow Haskell Compiler (GHC) that is very similar to C, but with
# many features missing and some special constructs.
#
# Cmm is a dialect of C--. The goal of this lexer is to use what GHC produces
# and parses (Cmm); C-- itself is not supported.
#
# https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/cmm-syntax
#
module Rouge
module Lexers
class GHCCmm < RegexLexer
title "GHC Cmm (C--)"
desc "GHC Cmm is the intermediate representation of the GHC Haskell compiler"
tag 'ghc-cmm'
filenames '*.cmm', '*.dump-cmm', '*.dump-cmm-*'
aliases 'cmm'
ws = %r(\s|//.*?\n|/[*](?:[^*]|(?:[*][^/]))*[*]+/)mx
# Make sure that this is not a preprocessor macro, e.g. `#if` or `#define`.
id = %r((?!\#[a-zA-Z])[\w#\$%']+)
complex_id = %r(
(?:[\w#$%']|\(\)|\(,\)|\[\]|[0-9])*
(?:[\w#$%']+)
)mx
state :root do
rule %r/\s+/m, Text
# sections markers
rule %r/^=====.*=====$/, Generic::Heading
# timestamps
rule %r/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC$/, Comment::Single
mixin :detect_section
mixin :preprocessor_macros
mixin :info_tbls
mixin :comments
mixin :literals
mixin :keywords
mixin :types
mixin :infos
mixin :names
mixin :operators
# escaped newline
rule %r/\\\n/, Text
# rest is Text
rule %r/./, Text
end
state :detect_section do
rule %r/(section)(\s+)/ do |m|
token Keyword, m[1]
token Text, m[2]
push :section
end
end
state :section do
rule %r/"(data|cstring|text|rodata|relrodata|bss)"/, Name::Builtin
rule %r/{/, Punctuation, :pop!
mixin :names
mixin :operators
mixin :keywords
rule %r/\s+/, Text
end
state :preprocessor_macros do
rule %r/#(include|endif|else|if)/, Comment::Preproc
rule %r{
(\#define)
(#{ws}*)
(#{id})
}mx do |m|
token Comment::Preproc, m[1]
recurse m[2]
token Name::Label, m[3]
end
end
state :info_tbls do
rule %r/({ )(info_tbls)(:)/ do |m|
token Punctuation, m[1]
token Name::Entity, m[2]
token Punctuation, m[3]
push :info_tbls_body
end
end
state :info_tbls_body do
rule %r/}/, Punctuation, :pop!
rule %r/{/, Punctuation, :info_tbls_body
rule %r/(?=label:)/ do
push :label
end
rule %r{(\()(#{complex_id})(,)}mx do |m|
token Punctuation, m[1]
token Name::Label, m[2]
token Punctuation, m[3]
end
mixin :literals
mixin :infos
mixin :keywords
mixin :operators
rule %r/#{id}/, Text
rule %r/\s+/, Text
end
state :label do
mixin :infos
mixin :names
mixin :keywords
mixin :operators
rule %r/[^\S\n]+/, Text # Tab, space, etc. but not newline!
rule %r/\n/, Text, :pop!
end
state :comments do
rule %r/\/{2}.*/, Comment::Single
rule %r/\(likely.*?\)/, Comment
rule %r/\/\*.*?\*\//m, Comment::Multiline
end
state :literals do
rule %r/-?[0-9]+\.[0-9]+/, Literal::Number::Float
rule %r/-?[0-9]+/, Literal::Number::Integer
rule %r/"/, Literal::String::Delimiter, :literal_string
end
state :literal_string do
# quotes
rule %r/\\./, Literal::String::Escape
rule %r/%./, Literal::String::Symbol
rule %r/"/, Literal::String::Delimiter, :pop!
rule %r/./, Literal::String
end
state :operators do
rule %r/\.\./, Operator
rule %r/[+\-*\/<>=!&|~]/, Operator
rule %r/[\[\].{}:;,()]/, Punctuation
end
state :keywords do
rule %r/(const)(\s+)/ do |m|
token Keyword::Constant, m[1]
token Text, m[2]
end
rule %r/"/, Literal::String::Double
rule %r/(switch)([^{]*)({)/ do |m|
token Keyword, m[1]
recurse m[2]
token Punctuation, m[3]
end
rule %r/(arg|result)(#{ws}+)(hints)(:)/ do |m|
token Name::Property, m[1]
recurse m[2]
token Name::Property, m[3]
token Punctuation, m[4]
end
rule %r/(returns)(#{ws}*)(to)/ do |m|
token Keyword, m[1]
recurse m[2]
token Keyword, m[3]
end
rule %r/(never)(#{ws}*)(returns)/ do |m|
token Keyword, m[1]
recurse m[2]
token Keyword, m[3]
end
rule %r{(return)(#{ws}*)(\()} do |m|
token Keyword, m[1]
recurse m[2]
token Punctuation, m[3]
end
rule %r{(if|else|goto|call|offset|import|jump|ccall|foreign|prim|case|unwind|export|reserve|push)(#{ws})} do |m|
token Keyword, m[1]
recurse m[2]
end
rule %r{(default)(#{ws}*)(:)} do |m|
token Keyword, m[1]
recurse m[2]
token Punctuation, m[3]
end
end
state :types do
# Memory access: `type[42]`
# Note: Only a token for type is produced.
rule %r/(#{id})(?=\[[^\]])/ do |m|
token Keyword::Type, m[1]
end
# Array type: `type[]`
rule %r/(#{id}\[\])/ do |m|
token Keyword::Type, m[1]
end
# Capture macro substitutions before lexing typed declarations
# I.e. there is no type in `PREPROCESSOR_MACRO_VARIABLE someFun()`
rule %r{
(^#{id})
(#{ws}+)
(#{id})
(#{ws}*)
(\()
}mx do |m|
token Name::Label, m[1]
recurse m[2]
token Name::Function, m[3]
recurse m[4]
token Punctuation, m[5]
end
# Type in variable or parameter declaration:
# `type /* optional whitespace */ var_name /* optional whitespace */;`
# `type /* optional whitespace */ var_name /* optional whitespace */, var_name2`
# `(type /* optional whitespace */ var_name /* optional whitespace */)`
# Note: Only the token for type is produced here.
rule %r{
(^#{id})
(#{ws}+)
(#{id})
}mx do |m|
token Keyword::Type, m[1]
recurse m[2]
token Name::Label, m[3]
end
end
state :infos do
rule %r/(args|res|upd|label|rep|srt|arity|fun_type|arg_space|updfr_space)(:)/ do |m|
token Name::Property, m[1]
token Punctuation, m[2]
end
rule %r/(stack_info)(:)/ do |m|
token Name::Entity, m[1]
token Punctuation, m[2]
end
end
state :names do
rule %r/(::)(#{ws}*)([A-Z]\w+)/ do |m|
token Operator, m[1]
recurse m[2]
token Keyword::Type, m[3]
end
rule %r/<(#{id})>/, Name::Builtin
rule %r/(Sp|SpLim|Hp|HpLim|HpAlloc|BaseReg|CurrentNursery|CurrentTSO|R\d{1,2}|gcptr)(?!#{id})/, Name::Variable::Global
rule %r/([A-Z]#{id})(\.)/ do |m|
token Name::Namespace, m[1]
token Punctuation, m[2]
push :namespace_name
end
# Inline function calls:
# ```
# arg1 `lt` arg2
# ```
rule %r/(`)(#{id})(`)/ do |m|
token Punctuation, m[1]
token Name::Function, m[2]
token Punctuation, m[3]
end
# Function: `name /* optional whitespace */ (`
# Function (arguments via explicit stack handling): `name /* optional whitespace */ {`
rule %r{(?=
#{complex_id}
#{ws}*
[\{\(]
)}mx do
push :function
end
rule %r/CLOSURE/, Keyword::Type
rule %r/#{complex_id}/, Name::Label
end
state :namespace_name do
rule %r/([A-Z]#{id})(\.)/ do |m|
token Name::Namespace, m[1]
token Punctuation, m[2]
end
rule %r{(#{complex_id})(#{ws}*)([\{\(])}mx do |m|
token Name::Function, m[1]
recurse m[2]
token Punctuation, m[3]
pop!
end
rule %r/#{complex_id}/, Name::Label, :pop!
rule %r/(?=.)/m do
pop!
end
end
state :function do
rule %r/INFO_TABLE_FUN|INFO_TABLE_CONSTR|INFO_TABLE_SELECTOR|INFO_TABLE_RET|INFO_TABLE/, Name::Builtin
rule %r/%#{id}/, Name::Builtin
rule %r/#{complex_id}/, Name::Function
rule %r/\s+/, Text
rule %r/[({]/, Punctuation, :pop!
mixin :comments
end
end
end
end
@@ -0,0 +1,152 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# See http://www.cs.cmu.edu/afs/andrew/course/15/411/ghc/share/doc/ghc/ext-core/core.pdf for a description of the syntax
# of the language and https://www.aosabook.org/en/ghc.html for a high level overview.
module Rouge
module Lexers
class GHCCore < RegexLexer
title "GHC Core"
desc "Intermediate representation of the GHC Haskell compiler."
tag 'ghc-core'
filenames '*.dump-simpl', '*.dump-cse', '*.dump-ds', '*.dump-spec'
state :root do
# sections
rule %r/^=====.*=====$/, Generic::Heading
# timestamps
rule %r/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC$/, Comment::Single
rule %r/^Result size of .+\n.+{[^}]*}/, Comment::Multiline
rule %r/--.*$/, Comment::Single
rule %r/\[/, Comment::Special, :annotation
mixin :recursive_binding
mixin :ghc_rule
mixin :function
# rest is Text
# TODO: this is really inefficient
rule %r/\s/m, Text
rule %r/./, Text
end
state :expression do
rule %r/[\n]+/, Text
rule %r/(?=^\S)/ do
pop!
end
rule %r/\s+/, Text, :expression_line
end
state :expression_line do
rule %r/ /, Text
mixin :common
rule %r/\n/, Text, :pop!
end
state :annotation do
rule %r/\]/, Comment::Special, :pop!
rule %r/\[/, Comment::Special, :annotation
rule %r/[^\[\]]+/, Comment::Special
end
state :common do
# array, e.g. '[]' or '[Char]'
rule %r/\[[^=]*\]/, Keyword::Type
rule %r/\[/, Comment::Special, :annotation
mixin :literal
mixin :constants
mixin :punctuation
mixin :operator
mixin :name
end
state :literal do
rule %r/\d+\.\d+\#{0,2}/, Literal::Number::Float
rule %r/\d+\#{0,2}/, Literal::Number::Integer
rule %r/".*"#/, Literal::String
rule %r/'.'#/, Literal::String::Char
end
state :constants do
rule %r/__DEFAULT/, Name::Constant
end
state :name do
rule %r/^([A-Z]\w*)(\.)/ do |m|
token Name::Namespace, m[0]
token Punctuation, m[1]
end
rule %r/[A-Z][^\s.,(){}]*/, Keyword::Type
# packages, e.g. 'ghc-prim-0.5.3:'
rule %r/(^[a-z].*?\d+\.\d+\.\d+)(:)(?=\S)/ do |m|
token Name::Namespace, m[1]
token Punctuation, m[2]
end
rule %r/\S*\(,\)\S*/, Name::Variable # '(,)' is a name, not punctuation
rule %r/\S[^\s.,(){}]*/, Name::Variable
end
state :punctuation do
rule %r/[.,(){};]/, Punctuation
end
state :operator do
rule %r/=>/, Operator
rule %r/->/, Operator
rule %r/::/, Operator
rule %r/=/, Operator
rule %r/forall/, Keyword
rule %r/case/, Keyword
rule %r/of/, Keyword
rule %r/letrec/, Keyword
rule %r/let/, Keyword
rule %r/join/, Keyword
rule %r/@/, Operator
rule %r/\\/, Operator
end
state :recursive_binding do
rule %r/(Rec)(\s*)({)/ do |m|
token Keyword, m[1]
token Text, m[2]
token Punctuation, m[3]
end
rule %r/^(end)(\s*)(Rec)(\s*)(})/ do |m|
token Keyword, m[1]
token Text, m[2]
token Keyword, m[3]
token Text, m[4]
token Punctuation, m[5]
end
end
state :ghc_rule do
rule %r/^(".*?")/m do |m|
token Name::Label, m[0]
push :expression
end
end
state :function do
rule %r/^(\S+)(?=.*?(=|::))/m do |m|
token Name::Function, m[0]
push :expression
end
end
end
end
end
@@ -0,0 +1,140 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Gherkin < RegexLexer
tag 'gherkin'
aliases 'cucumber', 'behat'
title "Gherkin"
desc 'A business-readable spec DSL (github.com/cucumber/cucumber/wiki/Gherkin)'
filenames '*.feature'
mimetypes 'text/x-gherkin'
def self.detect?(text)
return true if text.shebang? 'cucumber'
end
# self-modifying method that loads the keywords file
def self.keywords
Kernel::load File.join(Lexers::BASE_DIR, 'gherkin/keywords.rb')
keywords
end
def self.step_regex
# in Gherkin's config, keywords that end in < don't
# need word boundaries at the ends - all others do.
@step_regex ||= Regexp.new(
keywords[:step].map do |w|
if w.end_with? '<'
Regexp.escape(w.chop)
elsif w.end_with?(' ')
Regexp.escape(w)
else
"#{Regexp.escape(w)}\\b"
end
end.join('|')
)
end
rest_of_line = /.*?(?=[#\n])/
state :basic do
rule %r(#.*$), Comment
rule %r/[ \r\t]+/, Text
end
state :root do
mixin :basic
rule %r(\n), Text
rule %r(""".*?""")m, Str
rule %r(@[^\s@]+), Name::Tag
mixin :has_table
mixin :has_examples
end
state :has_scenarios do
rule %r((.*?)(:)) do |m|
reset_stack
keyword = m[1]
keyword_tok = if self.class.keywords[:element].include? keyword
push :description; Keyword::Namespace
elsif self.class.keywords[:feature].include? keyword
push :feature_description; Keyword::Declaration
elsif self.class.keywords[:examples].include? keyword
push :example_description; Name::Namespace
else
Error
end
groups keyword_tok, Punctuation
end
end
state :has_examples do
mixin :has_scenarios
rule Gherkin.step_regex, Name::Function do
token Name::Function
reset_stack; push :step
end
end
state :has_table do
rule(/(?=[|])/) { push :table_header }
end
state :table_header do
rule %r/[^|\s]+/, Name::Variable
rule %r/\n/ do
token Text
goto :table
end
mixin :table
end
state :table do
mixin :basic
rule %r/\n/, Text, :table_bol
rule %r/[|]/, Punctuation
rule %r/[^|\s]+/, Name
end
state :table_bol do
rule(/(?=\s*[^\s|])/) { reset_stack }
rule(//) { pop! }
end
state :description do
mixin :basic
mixin :has_examples
rule %r/\n/, Text
rule rest_of_line, Text
end
state :feature_description do
mixin :basic
mixin :has_scenarios
rule %r/\n/, Text
rule rest_of_line, Text
end
state :example_description do
mixin :basic
mixin :has_table
rule %r/\n/, Text
rule rest_of_line, Text
end
state :step do
mixin :basic
rule %r/<.*?>/, Name::Variable
rule %r/".*?"/, Str
rule %r/\S[^\s<]*/, Text
rule rest_of_line, Text, :pop!
end
end
end
end
File diff suppressed because one or more lines are too long
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'javascript.rb'
class Gjs < Javascript
title "Template Tag (gjs)"
desc "Ember.js, JavaScript with <template> tags"
tag "gjs"
filenames "*.gjs"
mimetypes "text/x-gjs", "application/x-gjs"
def initialize(*)
super
@handlebars = Handlebars.new(options)
end
prepend :root do
rule %r/(<)(template)(>)/ do
groups Name::Tag, Keyword, Name::Tag
push :template
end
end
state :template do
rule %r((</)(template)(>)) do
groups Name::Tag, Keyword, Name::Tag
pop!
end
rule %r/.+?(?=<\/template>)/m do
delegate @handlebars
end
end
end
end
end
@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'c.rb'
# This file defines the GLSL language lexer to the Rouge
# syntax highlighter.
#
# Author: Sri Harsha Chilakapati
class Glsl < C
tag 'glsl'
filenames '*.glsl', '*.frag', '*.vert', '*.geom', '*.vs', '*.gs', '*.shader'
mimetypes 'x-shader/x-vertex', 'x-shader/x-fragment', 'x-shader/x-geometry'
title "GLSL"
desc "The GLSL shader language"
def self.keywords
@keywords ||= Set.new %w(
attribute const uniform varying
layout
centroid flat smooth noperspective
patch sample
break continue do for while switch case default
if else
subroutine
in out inout
invariant
discard return struct precision
)
end
def self.keywords_type
@keywords_type ||= Set.new %w(
float double int void bool true false
lowp mediump highp
mat2 mat3 mat4 dmat2 dmat3 dmat4
mat2x2 mat2x3 mat2x4 dmat2x2 dmat2x3 dmat2x4
mat3x2 mat3x3 mat3x4 dmat3x2 dmat3x3 dmat3x4
mat4x2 mat4x3 mat4x4 dmat4x2 dmat4x3 dmat4x4
vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 dvec2 dvec3 dvec4
uint uvec2 uvec3 uvec4
sampler1D sampler2D sampler3D samplerCube
sampler1DShadow sampler2DShadow samplerCubeShadow
sampler1DArray sampler2DArray
sampler1DArrayShadow sampler2DArrayShadow
isampler1D isampler2D isampler3D isamplerCube
isampler1DArray isampler2DArray
usampler1D usampler2D usampler3D usamplerCube
usampler1DArray usampler2DArray
sampler2DRect sampler2DRectShadow isampler2DRect usampler2DRect
samplerBuffer isamplerBuffer usamplerBuffer
sampler2DMS isampler2DMS usampler2DMS
sampler2DMSArray isampler2DMSArray usampler2DMSArray
samplerCubeArray samplerCubeArrayShadow isamplerCubeArray usamplerCubeArray
)
end
def self.reserved
@reserved ||= Set.new %w(
common partition active
asm
class union enum typedef template this packed
goto
inline noinline volatile public static extern external interface
long short half fixed unsigned superp
input output
hvec2 hvec3 hvec4 fvec2 fvec3 fvec4
sampler3DRect
filter
image1D image2D image3D imageCube
iimage1D iimage2D iimage3D iimageCube
uimage1D uimage2D uimage3D uimageCube
image1DArray image2DArray
iimage1DArray iimage2DArray uimage1DArray uimage2DArray
image1DShadow image2DShadow
image1DArrayShadow image2DArrayShadow
imageBuffer iimageBuffer uimageBuffer
sizeof cast
namespace using
row_major
)
end
def self.builtins
@builtins ||= Set.new %w(
gl_VertexID gl_InstanceID gl_PerVertex gl_Position gl_PointSize gl_ClipDistance
gl_PrimitiveIDIn gl_InvocationID gl_PrimitiveID gl_Layer gl_ViewportIndex
gl_MaxPatchVertices gl_PatchVerticesIn gl_TessLevelOuter gl_TessLevelInner
gl_TessCoord gl_FragCoord gl_FrontFacing gl_PointCoord gl_SampleID gl_SamplePosition
gl_FragColor gl_FragData gl_MaxDrawBuffers 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_VertexID
gl_MultiTexCord0 gl_MultiTexCord1 gl_MultiTexCord2 gl_MultiTexCord3
gl_MultiTexCord4 gl_MultiTexCord5 gl_MultiTexCord6 gl_MultiTexCord7
gl_FogCoord 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_MaxClipDistances
gl_MaxGeometryTextureImageUnits 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_MaxTessGenLevel gl_MaxViewports
gl_MaxVertexUniformVectors gl_MaxFragmentUniformVectors gl_MaxVaryingVectors
gl_MaxTextureUnits gl_MaxTextureCoords gl_MaxClipPlanes gl_DepthRange
gl_DepthRangeParameters gl_ModelViewMatrix gl_ProjectionMatrix
gl_ModelViewProjectionMatrix gl_TextureMatrix gl_NormalMatrix
gl_ModelViewMatrixInverse gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse
gl_TextureMatrixInverse gl_ModelViewMatrixTranspose
gl_ModelViewProjectionMatrixTranspose gl_TextureMatrixTranspose
gl_ModelViewMatrixInverseTranspose gl_ProjectionMatrixInverseTranspose
gl_ModelViewProjectionMatrixInverseTranspose
gl_TextureMatrixInverseTranspose gl_NormalScale gl_ClipPlane gl_PointParameters
gl_Point gl_MaterialParameters gl_FrontMaterial gl_BackMaterial
gl_LightSourceParameters gl_LightSource gl_MaxLights gl_LightModelParameters
gl_LightModel gl_LightModelProducts gl_FrontLightModelProduct
gl_BackLightModelProduct gl_LightProducts gl_FrontLightProduct
gl_BackLightProduct gl_TextureEnvColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR
gl_EyePlaneQ gl_ObjectPlaneS gl_ObjectPlaneT gl_ObjectPlaneR gl_ObjectPlaneQ
gl_FogParameters gl_Fog
)
end
end
end
end
+177
View File
@@ -0,0 +1,177 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Go < RegexLexer
title "Go"
desc 'The Go programming language (http://golang.org)'
tag 'go'
aliases 'go', 'golang'
filenames '*.go'
mimetypes 'text/x-go', 'application/x-go'
# Characters
WHITE_SPACE = /\s+/
NEWLINE = /\n/
UNICODE_CHAR = /[^\n]/
UNICODE_LETTER = /[[:alpha:]]/
UNICODE_DIGIT = /[[:digit:]]/
# Letters and digits
LETTER = /#{UNICODE_LETTER}|_/
DECIMAL_DIGIT = /[0-9]/
BINARY_DIGIT = /[01]/
OCTAL_DIGIT = /[0-7]/
HEX_DIGIT = /[0-9A-Fa-f]/
# Comments
LINE_COMMENT = /\/\/(?:(?!#{NEWLINE}).)*/
GENERAL_COMMENT = /\/\*(?:(?!\*\/).)*\*\//m
COMMENT = /#{LINE_COMMENT}|#{GENERAL_COMMENT}/
# Keywords
KEYWORD = /\b(?:
break | default | func
| interface | select | case
| defer | go | map
| struct | chan | else
| goto | package | switch
| const | fallthrough | if
| range | type | continue
| for | import | return
| var
)\b/x
# Identifiers
IDENTIFIER = / (?!#{KEYWORD})
#{LETTER}(?:#{LETTER}|#{UNICODE_DIGIT})* /x
# Operators and delimiters
OPERATOR = / \+= | \+\+ | \+ | &\^= | &\^
| &= | && | & | == | =
| \!= | \! | -= | -- | -
| \|= | \|\| | \| | <= | <-
| <<= | << | < | \*= | \*
| \^= | \^ | >>= | >> | >=
| > | \/ | \/= | := | %
| %= | \.\.\. | \. | :
/x
SEPARATOR = / \( | \) | \[ | \] | \{
| \} | , | ;
/x
# Integer literals
DECIMAL_LIT = /#{DECIMAL_DIGIT}(?:_?#{DECIMAL_DIGIT})*/
BINARY_LIT = /0[bB]_*#{BINARY_DIGIT}(?:_?#{BINARY_DIGIT})*/
OCTAL_LIT = /0[oO]?_*#{OCTAL_DIGIT}(?:_?#{OCTAL_DIGIT})*/
HEX_LIT = /0[xX]_*#{HEX_DIGIT}(?:_?#{HEX_DIGIT})*/
INT_LIT = /#{BINARY_LIT}|#{HEX_LIT}|#{OCTAL_LIT}|#{DECIMAL_LIT}/
# Floating-point literals
DECIMALS = /#{DECIMAL_DIGIT}(?:_?#{DECIMAL_DIGIT})*/
EXPONENT = /[eE][+\-]?#{DECIMALS}/
FLOAT_LIT = / #{DECIMALS} \. #{DECIMALS}? #{EXPONENT}?
| #{DECIMALS} #{EXPONENT}
| \. #{DECIMALS} #{EXPONENT}?
/x
# Imaginary literals
IMAGINARY_LIT = /(?:#{DECIMALS}|#{FLOAT_LIT})i/
# Rune literals
ESCAPED_CHAR = /\\[abfnrtv\\'"]/
LITTLE_U_VALUE = /\\u#{HEX_DIGIT}{4}/
BIG_U_VALUE = /\\U#{HEX_DIGIT}{8}/
UNICODE_VALUE = / #{UNICODE_CHAR} | #{LITTLE_U_VALUE}
| #{BIG_U_VALUE} | #{ESCAPED_CHAR}
/x
OCTAL_BYTE_VALUE = /\\#{OCTAL_DIGIT}{3}/
HEX_BYTE_VALUE = /\\x#{HEX_DIGIT}{2}/
BYTE_VALUE = /#{OCTAL_BYTE_VALUE}|#{HEX_BYTE_VALUE}/
CHAR_LIT = /'(?:#{UNICODE_VALUE}|#{BYTE_VALUE})'/
ESCAPE_SEQUENCE = / #{ESCAPED_CHAR}
| #{LITTLE_U_VALUE}
| #{BIG_U_VALUE}
| #{HEX_BYTE_VALUE}
/x
# String literals
RAW_STRING_LIT = /`(?:#{UNICODE_CHAR}|#{NEWLINE})*`/
INTERPRETED_STRING_LIT = / "(?: (?!")
(?: #{UNICODE_VALUE} | #{BYTE_VALUE} )
)*" /x
STRING_LIT = /#{RAW_STRING_LIT}|#{INTERPRETED_STRING_LIT}/
# Predeclared identifiers
PREDECLARED_TYPES = /\b(?:
bool | byte | complex64
| complex128 | error | float32
| float64 | int8 | int16
| int32 | int64 | int
| rune | string | uint8
| uint16 | uint32 | uint64
| uintptr | uint
)\b/x
PREDECLARED_CONSTANTS = /\b(?:true|false|iota|nil)\b/
PREDECLARED_FUNCTIONS = /\b(?:
append | cap | close | complex
| copy | delete | imag | len
| make | new | panic | print
| println | real | recover
)\b/x
state :simple_tokens do
rule(COMMENT, Comment)
rule(KEYWORD, Keyword)
rule(PREDECLARED_TYPES, Keyword::Type)
rule(PREDECLARED_FUNCTIONS, Name::Builtin)
rule(PREDECLARED_CONSTANTS, Name::Constant)
rule(IMAGINARY_LIT, Num)
rule(FLOAT_LIT, Num)
rule(INT_LIT, Num)
rule(CHAR_LIT, Str::Char)
rule(OPERATOR, Operator)
rule(SEPARATOR, Punctuation)
rule(IDENTIFIER, Name)
rule(WHITE_SPACE, Text)
end
state :root do
mixin :simple_tokens
rule(/`/, Str, :raw_string)
rule(/"/, Str, :interpreted_string)
end
state :interpreted_string do
rule(ESCAPE_SEQUENCE, Str::Escape)
rule(/\\./, Error)
rule(/"/, Str, :pop!)
rule(/[^"\\]+/, Str)
end
state :raw_string do
rule(/`/, Str, :pop!)
rule(/[^`]+/m, Str)
end
end
end
end
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'groovy.rb'
class Gradle < Groovy
title "Gradle"
desc "A powerful build system for the JVM"
tag 'gradle'
filenames '*.gradle'
mimetypes 'text/x-gradle'
def self.keywords
@keywords ||= super + Set.new(%w(
allprojects artifacts buildscript configuration dependencies
repositories sourceSets subprojects publishing
))
end
def self.types
@types ||= super + Set.new(%w(
Project Task Gradle Settings Script JavaToolChain SourceSet
SourceSetOutput IncrementalTaskInputs Configuration
ResolutionStrategy ArtifactResolutionQuery ComponentSelection
ComponentSelectionRules ConventionProperty ExtensionAware
ExtraPropertiesExtension PublishingExtension IvyPublication
IvyArtifact IvyArtifactSet IvyModuleDescriptorSpec
MavenPublication MavenArtifact MavenArtifactSet MavenPom
PluginDependenciesSpec PluginDependencySpec ResourceHandler
TextResourceFactory
))
end
end
end
end
@@ -0,0 +1,261 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class GraphQL < RegexLexer
desc 'GraphQL'
tag 'graphql'
filenames '*.graphql', '*.gql'
mimetypes 'application/graphql'
name = /[_A-Za-z][_0-9A-Za-z]*/
state :root do
rule %r/\b(?:query|mutation|subscription)\b/, Keyword, :query_definition
rule %r/\{/ do
token Punctuation
push :query_definition
push :selection_set
end
rule %r/\bfragment\b/, Keyword, :fragment_definition
rule %r/\bscalar\b/, Keyword, :value
rule %r/\b(?:type|interface|enum)\b/, Keyword, :type_definition
rule %r/\b(?:input|schema)\b/, Keyword, :type_definition
rule %r/\bunion\b/, Keyword, :union_definition
rule %r/\bextend\b/, Keyword
mixin :basic
# Markdown descriptions
rule %r/(""")(\n)(.*?)(\n)(""")/m do |m|
token Str::Double, m[1]
token Text::Whitespace, m[2]
delegate Markdown, m[3]
token Text::Whitespace, m[4]
token Str::Double, m[5]
end
end
state :basic do
rule %r/\s+/m, Text::Whitespace
rule %r/#.*$/, Comment
rule %r/[!,]/, Punctuation
end
state :has_directives do
rule %r/(@#{name})(\s*)(\()/ do
groups Keyword, Text::Whitespace, Punctuation
push :arguments
end
rule %r/@#{name}\b/, Keyword
end
state :fragment_definition do
rule %r/\bon\b/, Keyword
mixin :query_definition
end
state :query_definition do
mixin :has_directives
rule %r/\b#{name}\b/, Name
rule %r/\(/, Punctuation, :variable_definitions
rule %r/\{/, Punctuation, :selection_set
mixin :basic
end
state :type_definition do
rule %r/\bimplements\b/, Keyword
rule %r/\b#{name}\b/, Name
rule %r/\(/, Punctuation, :variable_definitions
rule %r/\{/, Punctuation, :type_definition_set
mixin :basic
end
state :union_definition do
rule %r/\b#{name}\b/, Name
rule %r/\=/, Punctuation, :union_definition_variant
mixin :basic
end
state :union_definition_variant do
rule %r/\b#{name}\b/ do
token Name
pop!
push :union_definition_pipe
end
mixin :basic
end
state :union_definition_pipe do
rule %r/\|/ do
token Punctuation
pop!
push :union_definition_variant
end
rule %r/(?!\||\s+|#[^\n]*)/ do
pop! 2
end
mixin :basic
end
state :type_definition_set do
rule %r/\}/ do
token Punctuation
pop! 2
end
rule %r/\b(#{name})(\s*)(\()/ do
groups Name, Text::Whitespace, Punctuation
push :variable_definitions
end
rule %r/\b#{name}\b/, Name
rule %r/:/, Punctuation, :type_names
mixin :basic
end
state :arguments do
rule %r/\)/ do
token Punctuation
pop!
end
rule %r/\b#{name}\b/, Name
rule %r/:/, Punctuation, :value
mixin :basic
end
state :variable_definitions do
rule %r/\)/ do
token Punctuation
pop!
end
rule %r/\$#{name}\b/, Name::Variable
rule %r/\b#{name}\b/, Name
rule %r/:/, Punctuation, :type_names
rule %r/\=/, Punctuation, :value
mixin :basic
end
state :type_names do
rule %r/\b(?:Int|Float|String|Boolean|ID)\b/, Name::Builtin, :pop!
rule %r/\b#{name}\b/, Name, :pop!
rule %r/\[/, Punctuation, :type_name_list
mixin :basic
end
state :type_name_list do
rule %r/\b(?:Int|Float|String|Boolean|ID)\b/, Name::Builtin
rule %r/\b#{name}\b/, Name
rule %r/\]/ do
token Punctuation
pop! 2
end
mixin :basic
end
state :selection_set do
mixin :has_directives
rule %r/\}/ do
token Punctuation
pop!
pop! if state?(:query_definition) || state?(:fragment_definition)
end
rule %r/\b(#{name})(\s*)(\()/ do
groups Name, Text::Whitespace, Punctuation
push :arguments
end
rule %r/\b(#{name})(\s*)(:)/ do
groups Name, Text::Whitespace, Punctuation
end
rule %r/\b#{name}\b/, Name
rule %r/(\.\.\.)(\s+)(on)\b/ do
groups Punctuation, Text::Whitespace, Keyword
end
rule %r/\.\.\./, Punctuation
rule %r/\{/, Punctuation, :selection_set
mixin :basic
end
state :list do
rule %r/\]/ do
token Punctuation
pop!
pop! if state?(:value)
end
mixin :value
end
state :object do
rule %r/\}/ do
token Punctuation
pop!
pop! if state?(:value)
end
rule %r/\b(#{name})(\s*)(:)/ do
groups Name, Text::Whitespace, Punctuation
push :value
end
mixin :basic
end
state :value do
pop_unless_list = ->(t) {
->(m) {
token t
pop! unless state?(:list)
}
}
# Multiline strings
rule %r/""".*?"""/m, Str::Double
rule %r/\$#{name}\b/, &pop_unless_list[Name::Variable]
rule %r/\b(?:true|false|null)\b/, &pop_unless_list[Keyword::Constant]
rule %r/[+-]?[0-9]+\.[0-9]+(?:[eE][+-]?[0-9]+)?/, &pop_unless_list[Num::Float]
rule %r/[+-]?[1-9][0-9]*(?:[eE][+-]?[0-9]+)?/, &pop_unless_list[Num::Integer]
rule %r/"(\\[\\"]|[^"])*"/, &pop_unless_list[Str::Double]
rule %r/\b#{name}\b/, &pop_unless_list[Name]
rule %r/\{/, Punctuation, :object
rule %r/\[/, Punctuation, :list
mixin :basic
end
end
end
end
@@ -0,0 +1,113 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Groovy < RegexLexer
title "Groovy"
desc 'The Groovy programming language (http://www.groovy-lang.org/)'
tag 'groovy'
aliases 'nextflow', 'nf'
filenames '*.groovy', 'Jenkinsfile', '*.Jenkinsfile', '*.nf'
mimetypes 'text/x-groovy'
def self.detect?(text)
return true if text.shebang?(/groovy/)
return true if text.shebang?(/nextflow/)
end
def self.keywords
@keywords ||= Set.new %w(
assert break case catch continue default do else finally for
if goto instanceof new return switch this throw try while in as
)
end
def self.declarations
@declarations ||= Set.new %w(
abstract const extends final implements native private
protected public static strictfp super synchronized throws
transient volatile
)
end
def self.types
@types ||= Set.new %w(
def var boolean byte char double float int long short void
)
end
def self.constants
@constants ||= Set.new %w(true false null)
end
state :root do
rule %r(^
(\s*(?:\w[\w.\[\]]*\s+)+?) # return arguments
(\w\w*) # method name
(\s*) (\() # signature start
)x do |m|
delegate self.clone, m[1]
token Name::Function, m[2]
token Text, m[3]
token Operator, m[4]
end
# whitespace
rule %r/[^\S\n]+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline
rule %r/@\w[\w.]*/, Name::Decorator
rule %r/(class|interface|trait|enum|record)\b/, Keyword::Declaration, :class
rule %r/package\b/, Keyword::Namespace, :import
rule %r/import\b/, Keyword::Namespace, :import
# TODO: highlight backslash escapes
rule %r/""".*?"""/m, Str::Double
rule %r/'''.*?'''/m, Str::Single
rule %r/"(\\.|\\\n|.)*?"/, Str::Double
rule %r/'(\\.|\\\n|.)*?'/, Str::Single
rule %r(\$/(\$.|.)*?/\$)m, Str
rule %r(/(\\.|\\\n|.)*?/), Str
rule %r/'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'/, Str::Char
rule %r/(\.)([a-zA-Z_][a-zA-Z0-9_]*)/ do
groups Operator, Name::Attribute
end
rule %r/[a-zA-Z_][a-zA-Z0-9_]*:/, Name::Label
rule %r/[a-zA-Z_\$][a-zA-Z0-9_]*/ do |m|
if self.class.keywords.include? m[0]
token Keyword
elsif self.class.declarations.include? m[0]
token Keyword::Declaration
elsif self.class.types.include? m[0]
token Keyword::Type
elsif self.class.constants.include? m[0]
token Keyword::Constant
else
token Name
end
end
rule %r([~^*!%&\[\](){}<>\|+=:;,./?-]), Operator
# numbers
rule %r/\d+\.\d+([eE]\d+)?[fd]?/, Num::Float
rule %r/0x[0-9a-f]+/, Num::Hex
rule %r/[0-9]+L?/, Num::Integer
rule %r/\n/, Text
end
state :class do
rule %r/\s+/, Text
rule %r/\w\w*/, Name::Class, :pop!
end
state :import do
rule %r/\s+/, Text
rule %r/[\w.]+[*]?/, Name::Namespace, :pop!
end
end
end
end
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'typescript.rb'
class Gts < Typescript
title "Template Tag (gts)"
desc "Ember.js, TypeScript with <template> tags"
tag "gts"
filenames "*.gts"
mimetypes "text/x-gts", "application/x-gts"
def initialize(*)
super
@handlebars = Handlebars.new(options)
end
prepend :root do
rule %r/(<)(template)(>)/ do
groups Name::Tag, Keyword, Name::Tag
push :template
end
end
state :template do
rule %r((</)(template)(>)) do
groups Name::Tag, Keyword, Name::Tag
pop!
end
rule %r/.+?(?=<\/template>)/m do
delegate @handlebars
end
end
end
end
end
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'php.rb'
class Hack < PHP
title 'Hack'
desc 'The Hack programming language (hacklang.org)'
tag 'hack'
aliases 'hack', 'hh'
filenames '*.php', '*.hh'
def self.detect?(text)
return true if /<\?hh/ =~ text
return true if text.shebang?('hhvm')
return true if /async function [a-zA-Z]/ =~ text
return true if /\): Awaitable</ =~ text
return false
end
def self.keywords
@hh_keywords ||= super.merge Set.new %w(
type newtype enum
as super
async await Awaitable
vec dict keyset
void int string bool float double
arraykey num Stringish
)
end
prepend :root do
rule %r/<\?hh(\s*\/\/\s*(strict|decl|partial))?$/, Comment::Preproc, :php
end
prepend :php do
rule %r((/\*\s*)(HH_(?:IGNORE_ERROR|FIXME)\[\d+\])([^*]*)(\*/)) do
groups Comment::Preproc, Comment::Preproc, Comment::Multiline, Comment::Preproc
end
rule %r(// UNSAFE(?:_EXPR|_BLOCK)?), Comment::Preproc
rule %r(/\*\s*UNSAFE_EXPR\s*\*/), Comment::Preproc
end
end
end
end
@@ -0,0 +1,226 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
# A lexer for the Haml templating system for Ruby.
# @see http://haml.info
class Haml < RegexLexer
include Indentation
title "Haml"
desc "The Haml templating system for Ruby (haml.info)"
tag 'haml'
aliases 'HAML'
filenames '*.haml'
mimetypes 'text/x-haml'
option 'filters[filter_name]', 'Mapping of lexers to use for haml :filters'
attr_reader :filters
# @option opts :filters
# A hash of filter name to lexer of how various filters should be
# highlighted. By default, :javascript, :css, :ruby, and :erb
# are supported.
def initialize(opts={})
super
default_filters = {
'javascript' => Javascript.new(options),
'css' => CSS.new(options),
'ruby' => ruby,
'erb' => ERB.new(options),
'markdown' => Markdown.new(options),
'sass' => Sass.new(options),
# TODO
# 'textile' => Textile.new(options),
# 'maruku' => Maruku.new(options),
}
@filters = hash_option(:filters, default_filters) do |v|
as_lexer(v) || PlainText.new(@options)
end
end
def ruby
@ruby ||= Ruby.new(@options)
end
def html
@html ||= HTML.new(@options)
end
def ruby!(state)
ruby.reset!
push state
end
start { ruby.reset!; html.reset! }
identifier = /[\w:-]+/
ruby_var = /[a-z]\w*/
# Haml can include " |\n" anywhere,
# which is ignored and used to wrap long lines.
# To accomodate this, use this custom faux dot instead.
dot = /[ ]\|\n(?=.*[ ]\|)|./
state :root do
rule %r/\s*\n/, Text
rule(/\s*/) { |m| token Text; indentation(m[0]) }
end
state :content do
mixin :css
rule(/%#{identifier}/) { token Name::Tag; goto :tag }
rule %r/!!!#{dot}*\n/, Name::Namespace, :pop!
rule %r(
(/) (\[#{dot}*?\]) (#{dot}*\n)
)x do
groups Comment, Comment::Special, Comment
pop!
end
rule %r(/#{dot}*\n) do
token Comment
pop!
starts_block :html_comment_block
end
rule %r/-##{dot}*\n/ do
token Comment
pop!
starts_block :haml_comment_block
end
rule %r/-/ do
token Punctuation
reset_stack
ruby! :ruby_line
end
# filters
rule %r/:(#{dot}*)\n/ do |m|
token Name::Decorator
pop!
starts_block :filter_block
filter_name = m[1].strip
@filter_lexer = self.filters[filter_name]
@filter_lexer.reset! unless @filter_lexer.nil?
puts " haml: filter #{filter_name.inspect} #{@filter_lexer.inspect}" if @debug
end
mixin :eval_or_plain
end
state :css do
rule(/\.#{identifier}/) { token Name::Class; goto :tag }
rule(/##{identifier}/) { token Name::Function; goto :tag }
end
state :tag do
mixin :css
rule(/[{]/) { token Punctuation; ruby! :ruby_tag }
rule(/\[#{dot}*?\]/) { delegate ruby }
rule %r/\(/, Punctuation, :html_attributes
rule %r/\s*\n/, Text, :pop!
# whitespace chompers
rule %r/[<>]{1,2}(?=[ \t=])/, Punctuation
mixin :eval_or_plain
end
state :plain do
rule(/([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/) { delegate html }
mixin :interpolation
rule(/\n/) { token Text; reset_stack }
end
state :eval_or_plain do
rule %r/[&!]?==/, Punctuation, :plain
rule %r/[&!]?[=!]/ do
token Punctuation
reset_stack
ruby! :ruby_line
end
rule(//) { push :plain }
end
state :ruby_line do
rule %r/\n/, Text, :pop!
rule(/,[ \t]*\n/) { delegate ruby }
rule %r/[ ]\|[ \t]*\n/, Str::Escape
rule(/.*?(?=(,$| \|)?[ \t]*$)/) { delegate ruby }
end
state :ruby_tag do
mixin :ruby_inner
end
state :html_attributes do
rule %r/\s+/, Text
rule %r/#{identifier}\s*=/, Name::Attribute, :html_attribute_value
rule identifier, Name::Attribute
rule %r/\)/, Text, :pop!
end
state :html_attribute_value do
rule %r/\s+/, Text
rule ruby_var, Name::Variable, :pop!
rule %r/@#{ruby_var}/, Name::Variable::Instance, :pop!
rule %r/\$#{ruby_var}/, Name::Variable::Global, :pop!
rule %r/'(\\\\|\\'|[^'\n])*'/, Str, :pop!
rule %r/"(\\\\|\\"|[^"\n])*"/, Str, :pop!
end
state :html_comment_block do
rule %r/#{dot}+/, Comment
mixin :indented_block
end
state :haml_comment_block do
rule %r/#{dot}+/, Comment::Preproc
mixin :indented_block
end
state :filter_block do
rule %r/([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
if @filter_lexer
delegate @filter_lexer
else
token Name::Decorator
end
end
mixin :interpolation
mixin :indented_block
end
state :interpolation do
rule %r/#[{]/, Str::Interpol, :ruby
end
state :ruby do
rule %r/[}]/, Str::Interpol, :pop!
mixin :ruby_inner
end
state :ruby_inner do
rule(/[{]/) { delegate ruby; push :ruby_inner }
rule(/[}]/) { delegate ruby; pop! }
rule(/[^{}]+/) { delegate ruby }
end
state :indented_block do
rule(/\n/) { token Text; reset_stack }
end
end
end
end
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Handlebars < TemplateLexer
title "Handlebars"
desc 'the Handlebars and Mustache templating languages'
tag 'handlebars'
aliases 'hbs', 'mustache'
filenames '*.handlebars', '*.hbs', '*.mustache'
mimetypes 'text/x-handlebars', 'text/x-mustache'
id = %r([\w$-]+)
state :root do
# escaped slashes
rule(/\\{+/) { delegate parent }
# block comments
rule %r/{{!--/, Comment, :comment
rule %r/{{!.*?}}/, Comment
rule %r/{{{?/ do
token Keyword
push :stache
push :open_sym
end
rule(/(.+?)(?=\\|{{)/m) do
delegate parent
# if parent state is attr, then we have an html attribute without quotes
# pop the parent state to return to the tag state
if parent.state?('attr')
parent.pop!
end
end
# if we get here, there's no more mustache tags, so we eat
# the rest of the doc
rule(/.+/m) { delegate parent }
end
state :comment do
rule(/{{/) { token Comment; push }
rule(/}}/) { token Comment; pop! }
rule(/[^{}]+/m) { token Comment }
rule(/[{}]/) { token Comment }
end
state :stache do
rule %r/}}}?/, Keyword, :pop!
rule %r/\|/, Punctuation
rule %r/~/, Keyword
rule %r/\s+/m, Text
rule %r/[=]/, Operator
rule %r/[\[\]]/, Punctuation
rule %r/[\(\)]/, Punctuation
rule %r/[.](?=[}\s])/, Name::Variable
rule %r/[.][.]/, Name::Variable
rule %r([/.]), Punctuation
rule %r/"(\\.|.)*?"/, Str::Double
rule %r/'(\\.|.)*?'/, Str::Single
rule %r/\d+(?=}\s)/, Num
rule %r/(true|false)(?=[}\s])/, Keyword::Constant
rule %r/else(?=[}\s])/, Keyword
rule %r/this(?=[}\s])/, Name::Builtin::Pseudo
rule %r/@#{id}/, Name::Attribute
rule id, Name::Variable
end
state :open_sym do
rule %r([#/]) do
token Keyword
goto :block_name
end
rule %r/[>^&~]/, Keyword
rule(//) { pop! }
end
state :block_name do
rule %r/if(?=[}\s])/, Keyword
rule id, Name::Namespace, :pop!
rule(//) { pop! }
end
end
end
end
@@ -0,0 +1,207 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Haskell < RegexLexer
title "Haskell"
desc "The Haskell programming language (haskell.org)"
tag 'haskell'
aliases 'hs'
filenames '*.hs', '*.hs-boot'
mimetypes 'text/x-haskell'
def self.detect?(text)
return true if text.shebang?('runhaskell')
end
reserved = %w(
_ case class data default deriving do else if in infix infixl infixr
instance let newtype of then type where
)
ascii = %w(
NUL SOH [SE]TX EOT ENQ ACK BEL BS HT LF VT FF CR S[OI] DLE
DC[1-4] NAK SYN ETB CAN EM SUB ESC [FGRU]S SP DEL
)
state :basic do
rule %r/\s+/m, Text
rule %r/{-#/, Comment::Preproc, :comment_preproc
rule %r/{-/, Comment::Multiline, :comment
rule %r/^--\s+\|.*?$/, Comment::Doc
# this is complicated in order to support custom symbols
# like -->
rule %r/--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
end
# nested commenting
state :comment do
rule %r/-}/, Comment::Multiline, :pop!
rule %r/{-/, Comment::Multiline, :comment
rule %r/[^-{}]+/, Comment::Multiline
rule %r/[-{}]/, Comment::Multiline
end
state :comment_preproc do
rule %r/-}/, Comment::Preproc, :pop!
rule %r/{-/, Comment::Preproc, :comment
rule %r/[^-{}]+/, Comment::Preproc
rule %r/[-{}]/, Comment::Preproc
end
state :root do
mixin :basic
rule %r/'(?=(?:.|\\\S+)')/, Str::Char, :character
rule %r/"/, Str, :string
rule %r/\d+e[+-]?\d+/i, Num::Float
rule %r/\d+\.\d+(e[+-]?\d+)?/i, Num::Float
rule %r/0o[0-7]+/i, Num::Oct
rule %r/0x[\da-f]+/i, Num::Hex
rule %r/\d+/, Num::Integer
rule %r/[\w']+/ do |m|
match = m[0]
if match == "import"
token Keyword::Reserved
push :import
elsif match == "module"
token Keyword::Reserved
push :module
elsif reserved.include?(match)
token Keyword::Reserved
elsif match =~ /\A'?[A-Z]/
token Keyword::Type
else
token Name
end
end
# lambda operator
rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
# special operators
rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Operator
# constructor/type operators
rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), Operator
# other operators
rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), Operator
rule %r/\[\s*\]/, Keyword::Type
rule %r/\(\s*\)/, Name::Builtin
# Quasiquotations
rule %r/(\[)([_a-z][\w']*)(\|)/ do |m|
token Operator, m[1]
token Name, m[2]
token Operator, m[3]
push :quasiquotation
end
rule %r/[\[\](),;`{}]/, Punctuation
end
state :import do
rule %r/\s+/, Text
rule %r/"/, Str, :string
rule %r/\bqualified\b/, Keyword
# import X as Y
rule %r/([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
groups(
Name::Namespace, # X
Text, Keyword, # as
Text, Name # Y
)
pop!
end
# import X hiding (functions)
rule %r/([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
groups(
Name::Namespace, # X
Text, Keyword, # hiding
Text, Punctuation # (
)
goto :funclist
end
# import X (functions)
rule %r/([A-Z][\w.]*)(\s+)(\()/ do
groups(
Name::Namespace, # X
Text,
Punctuation # (
)
goto :funclist
end
rule %r/[\w.]+/, Name::Namespace, :pop!
end
state :module do
rule %r/\s+/, Text
# module Foo (functions)
rule %r/([A-Z][\w.]*)(\s+)(\()/ do
groups Name::Namespace, Text, Punctuation
push :funclist
end
rule %r/\bwhere\b/, Keyword::Reserved, :pop!
rule %r/[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
end
state :funclist do
mixin :basic
rule %r/[A-Z]\w*/, Keyword::Type
rule %r/(_[\w\']+|[a-z][\w\']*)/, Name::Function
rule %r/,/, Punctuation
rule %r/[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
rule %r/\(/, Punctuation, :funclist
rule %r/\)/, Punctuation, :pop!
end
state :character do
rule %r/\\/ do
token Str::Escape
goto :character_end
push :escape
end
rule %r/./ do
token Str::Char
goto :character_end
end
end
state :character_end do
rule %r/'/, Str::Char, :pop!
rule %r/./, Error, :pop!
end
state :quasiquotation do
rule %r/\|\]/, Operator, :pop!
rule %r/[^\|]+/m, Text
rule %r/\|/, Text
end
state :string do
rule %r/"/, Str, :pop!
rule %r/\\/, Str::Escape, :escape
rule %r/[^\\"]+/, Str
end
state :escape do
rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
rule %r/#{ascii.join('|')}/, Str::Escape, :pop!
rule %r/o[0-7]+/i, Str::Escape, :pop!
rule %r/x[\da-f]+/i, Str::Escape, :pop!
rule %r/\d+/, Str::Escape, :pop!
rule %r/\s+\\/, Str::Escape, :pop!
end
end
end
end
@@ -0,0 +1,265 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class Haxe < RegexLexer
title "Haxe"
desc "Haxe Cross-platform Toolkit (http://haxe.org)"
tag 'haxe'
aliases 'hx', 'haxe'
filenames '*.hx'
mimetypes 'text/haxe', 'text/x-haxe', 'text/x-hx'
def self.detect?(text)
return true if text.shebang? "haxe"
end
def self.keywords
@keywords ||= Set.new %w(
as break case cast catch class continue default do else enum false for
function if import in interface macro new null override package private
public return switch this throw true try untyped while
)
end
def self.imports
@imports ||= Set.new %w(
package import using
)
end
def self.declarations
@declarations ||= Set.new %w(
abstract dynamic extern extends from implements inline static to
typedef var
)
end
def self.reserved
@reserved ||= Set.new %w(
super trace inline build autoBuild enum
)
end
def self.constants
@constants ||= Set.new %w(true false null)
end
def self.builtins
@builtins ||= %w(
Void Dynamic Math Class Any Float Int UInt String StringTools Sys
EReg isNaN parseFloat parseInt this Array Map Date DateTools Bool
Lambda Reflect Std File FileSystem
)
end
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
dotted_id = /[$a-zA-Z_][a-zA-Z0-9_.]*/
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(//.*?$), Comment::Single
rule %r(/\*.*?\*/)m, Comment::Multiline
end
state :expr_start do
mixin :comments_and_whitespace
rule %r/#(?:if|elseif|else|end).*/, Comment::Preproc
rule %r(~) do
token Str::Regex
goto :regex
end
rule %r/[{]/, Punctuation, :object
rule %r//, Text, :pop!
end
state :namespace do
mixin :comments_and_whitespace
rule %r/
(#{dotted_id})
(\s+)(in|as)(\s+)
(#{id})
/x do
groups(Name::Namespace, Text::Whitespace, Keyword, Text::Whitespace, Name)
end
rule %r/#{dotted_id}/, Name::Namespace
rule(//) { pop! }
end
state :regex do
rule %r(/) do
token Str::Regex
goto :regex_end
end
rule %r([^/]\n), Error, :pop!
rule %r/\n/, Error, :pop!
rule %r/\[\^/, Str::Escape, :regex_group
rule %r/\[/, Str::Escape, :regex_group
rule %r/\\./, Str::Escape
rule %r{[(][?][:=<!]}, Str::Escape
rule %r/[{][\d,]+[}]/, Str::Escape
rule %r/[()?]/, Str::Escape
rule %r/./, Str::Regex
end
state :regex_end do
rule %r/[gim]+/, Str::Regex, :pop!
rule(//) { pop! }
end
state :regex_group do
# specially highlight / in a group to indicate that it doesn't
# close the regex
rule %r/\//, Str::Escape
rule %r([^/]\n) do
token Error
pop! 2
end
rule %r/\]/, Str::Escape, :pop!
rule %r/\\./, Str::Escape
rule %r/./, Str::Regex
end
state :bad_regex do
rule %r/[^\n]+/, Error, :pop!
end
state :root do
rule %r/\n/, Text, :statement
rule %r(\{), Punctuation, :expr_start
mixin :comments_and_whitespace
rule %r/@/, Name::Decorator, :metadata
rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >> | ==
| != )x,
Operator, :expr_start
rule %r([-:<>+*%&|\^/!=]=?), Operator, :expr_start
rule %r/[(\[,]/, Punctuation, :expr_start
rule %r/;/, Punctuation, :statement
rule %r/[)\]}.]/, Punctuation
rule %r/[?]/ do
token Punctuation
push :ternary
push :expr_start
end
rule id do |m|
match = m[0]
if self.class.imports.include?(match)
token Keyword::Namespace
push :namespace
elsif self.class.keywords.include?(match)
token Keyword
push :expr_start
elsif self.class.declarations.include?(match)
token Keyword::Declaration
push :expr_start
elsif self.class.reserved.include?(match)
token Keyword::Reserved
elsif self.class.constants.include?(match)
token Keyword::Constant
elsif self.class.builtins.include?(match)
token Name::Builtin
else
token Name::Other
end
end
rule %r/\-?\d+\.\d+(?:[eE]\d+)?[fd]?/, Num::Float
rule %r/0x\h+/, Num::Hex
rule %r/\-?[0-9]+/, Num::Integer
rule %r/"/, Str::Double, :str_double
rule %r/'/, Str::Single, :str_single
end
# braced parts that aren't object literals
state :statement do
rule %r/(#{id})(\s*)(:)/ do
groups Name::Label, Text, Punctuation
end
mixin :expr_start
end
# object literals
state :object do
mixin :comments_and_whitespace
rule %r/[}]/ do
token Punctuation
goto :statement
end
rule %r/(#{id})(\s*)(:)/ do
groups Name::Attribute, Text, Punctuation
push :expr_start
end
rule %r/:/, Punctuation
mixin :root
end
state :metadata do
rule %r/(#{id})(\()?/ do |m|
groups Name::Decorator, Punctuation
pop! unless m[2]
end
rule %r/:#{id}(?:\.#{id})*/, Name::Decorator, :pop!
rule %r/\)/, Name::Decorator, :pop!
mixin :root
end
# ternary expressions, where <id>: is not a label!
state :ternary do
rule %r/:/ do
token Punctuation
goto :expr_start
end
mixin :root
end
state :str_double do
mixin :str_escape
rule %r/"/, Str::Double, :pop!
rule %r/[^\\"]+/, Str::Double
end
state :str_single do
mixin :str_escape
rule %r/'/, Str::Single, :pop!
rule %r/\$\$/, Str::Single
rule %r/\$#{id}/, Str::Interpol
rule %r/\$\{/, Str::Interpol, :str_interpol
rule %r/[^\\$']+/, Str::Single
end
state :str_escape do
rule %r/\\[\\tnr'"]/, Str::Escape
rule %r/\\[0-7]{3}/, Str::Escape
rule %r/\\x\h{2}/, Str::Escape
rule %r/\\u\h{4}/, Str::Escape
rule %r/\\u\{\h{1,6}\}/, Str::Escape
end
state :str_interpol do
rule %r/\}/, Str::Interpol, :pop!
mixin :root
end
end
end
end
@@ -0,0 +1,166 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Hcl < RegexLexer
tag 'hcl'
filenames '*.hcl', '*.nomad'
title 'Hashicorp Configuration Language'
desc 'Hashicorp Configuration Language, used by Terraform and other Hashicorp tools'
state :multiline_comment do
rule %r([*]/), Comment::Multiline, :pop!
rule %r([^*/]+), Comment::Multiline
rule %r([*/]), Comment::Multiline
end
state :comments_and_whitespace do
rule %r/\s+/, Text
rule %r(//.*?$), Comment::Single
rule %r(#.*?$), Comment::Single
rule %r(/[*]), Comment::Multiline, :multiline_comment
end
state :primitives do
rule %r/[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?([kKmMgG]b?)?/, Num::Float
rule %r/[0-9]+([kKmMgG]b?)?/, Num::Integer
rule %r/[-+*\/!%&<>|=:?]/, Operator
rule %r/"/, Str::Double, :dq
rule %r/'/, Str::Single, :sq
rule %r/(<<-?)(\s*)(\'?)(\\?)(\w+)(\3)/ do |m|
groups Operator, Text, Str::Heredoc, Str::Heredoc, Name::Constant, Str::Heredoc
@heredocstr = Regexp.escape(m[5])
push :heredoc
end
end
def self.keywords
@keywords ||= Set.new %w()
end
def self.declarations
@declarations ||= Set.new %w()
end
def self.reserved
@reserved ||= Set.new %w()
end
def self.constants
@constants ||= Set.new %w(true false null)
end
def self.builtins
@builtins ||= %w()
end
id = /[$a-z_\-][a-z0-9_\-]*/io
state :root do
mixin :comments_and_whitespace
mixin :primitives
rule %r/\{/ do
token Punctuation
push :hash
end
rule %r/\[/ do
token Punctuation
push :array
end
rule id do |m|
if self.class.keywords.include? m[0]
token Keyword
push :composite
elsif self.class.declarations.include? m[0]
token Keyword::Declaration
push :composite
elsif self.class.reserved.include? m[0]
token Keyword::Reserved
elsif self.class.constants.include? m[0]
token Keyword::Constant
elsif self.class.builtins.include? m[0]
token Name::Builtin
else
token Name::Other
push :composite
end
end
end
state :composite do
mixin :comments_and_whitespace
rule %r/[{]/ do
token Punctuation
pop!
push :hash
end
rule %r/[\[]/ do
token Punctuation
pop!
push :array
end
mixin :root
rule %r//, Text, :pop!
end
state :hash do
mixin :comments_and_whitespace
rule %r/[.,()\\\/*]/, Punctuation
rule %r/\=/, Punctuation
rule %r/\}/, Punctuation, :pop!
mixin :root
end
state :array do
mixin :comments_and_whitespace
rule %r/[.,()\\\/*]/, Punctuation
rule %r/\]/, Punctuation, :pop!
mixin :root
end
state :dq do
rule %r/[^\\"]+/, Str::Double
rule %r/\\"/, Str::Escape
rule %r/"/, Str::Double, :pop!
end
state :sq do
rule %r/[^\\']+/, Str::Single
rule %r/\\'/, Str::Escape
rule %r/'/, Str::Single, :pop!
end
state :heredoc do
rule %r/\n/, Str::Heredoc, :heredoc_nl
rule %r/[^$\n]+/, Str::Heredoc
rule %r/[$]/, Str::Heredoc
end
state :heredoc_nl do
rule %r/\s*(\w+)\s*\n/ do |m|
if m[1] == @heredocstr
token Name::Constant
pop! 2
else
token Str::Heredoc
end
end
rule(//) { pop! }
end
end
end
end
@@ -0,0 +1,166 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'c.rb'
class HLSL < C
title "HLSL"
desc "HLSL, the High Level Shading Language for DirectX (docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl)"
tag 'hlsl'
filenames '*.hlsl', '*.hlsli'
mimetypes 'text/x-hlsl'
def self.keywords
@keywords ||= Set.new %w(
asm asm_fragment break case cbuffer centroid class column_major
compile compile_fragment const continue default discard do else export
extern for fxgroup globallycoherent groupshared if in inline inout
interface line lineadj linear namespace nointerpolation noperspective
NULL out packoffset pass pixelfragment point precise return register
row_major sample sampler shared stateblock stateblock_state static
struct switch tbuffer technique technique10 technique11 texture
typedef triangle uniform vertexfragment volatile while
)
end
def self.keywords_type
@keywords_type ||= Set.new %w(
dword matrix snorm string unorm unsigned void vector BlendState Buffer
ByteAddressBuffer ComputeShader DepthStencilState DepthStencilView
DomainShader GeometryShader HullShader InputPatch LineStream
OutputPatch PixelShader PointStream RasterizerState RenderTargetView
RasterizerOrderedBuffer RasterizerOrderedByteAddressBuffer
RasterizerOrderedStructuredBuffer RasterizerOrderedTexture1D
RasterizerOrderedTexture1DArray RasterizerOrderedTexture2D
RasterizerOrderedTexture2DArray RasterizerOrderedTexture3D RWBuffer
RWByteAddressBuffer RWStructuredBuffer RWTexture1D RWTexture1DArray
RWTexture2D RWTexture2DArray RWTexture3D SamplerState
SamplerComparisonState StructuredBuffer Texture1D Texture1DArray
Texture2D Texture2DArray Texture2DMS Texture2DMSArray Texture3D
TextureCube TextureCubeArray TriangleStream VertexShader
bool1 bool2 bool3 bool4 BOOL1 BOOL2 BOOL3 BOOL4
int1 int2 int3 int4
half1 half2 half3 half4
float1 float2 float3 float4
double1 double2 double3 double4
bool1x1 bool1x2 bool1x3 bool1x4 bool2x1 bool2x2 bool2x3 bool2x4
bool3x1 bool3x2 bool3x3 bool3x4 bool4x1 bool4x2 bool4x3 bool4x4
BOOL1x1 BOOL1x2 BOOL1x3 BOOL1x4 BOOL2x1 BOOL2x2 BOOL2x3 BOOL2x4
BOOL3x1 BOOL3x2 BOOL3x3 BOOL3x4 BOOL4x1 BOOL4x2 BOOL4x3 BOOL4x4
half1x1 half1x2 half1x3 half1x4 half2x1 half2x2 half2x3 half2x4
half3x1 half3x2 half3x3 half3x4 half4x1 half4x2 half4x3 half4x4
int1x1 int1x2 int1x3 int1x4 int2x1 int2x2 int2x3 int2x4
int3x1 int3x2 int3x3 int3x4 int4x1 int4x2 int4x3 int4x4
float1x1 float1x2 float1x3 float1x4 float2x1 float2x2 float2x3 float2x4
float3x1 float3x2 float3x3 float3x4 float4x1 float4x2 float4x3 float4x4
double1x1 double1x2 double1x3 double1x4 double2x1 double2x2 double2x3 double2x4
double3x1 double3x2 double3x3 double3x4 double4x1 double4x2 double4x3 double4x4
)
end
def self.reserved
@reserved ||= Set.new %w(
auto catch char const_cast delete dynamic_cast enum explicit friend
goto long mutable new operator private protected public
reinterpret_cast short signed sizeof static_cast template this throw
try typename union unsigned using virtual
)
end
def self.builtins
@builtins ||= Set.new %w(
abort abs acos all AllMemoryBarrier AllMemoryBarrierWithGroupSync any
AppendStructuredBuffer asdouble asfloat asin asint asuint asuint atan
atan2 ceil CheckAccessFullyMapped clamp clip CompileShader
ConsumeStructuredBuffer cos cosh countbits cross D3DCOLORtoUBYTE4 ddx
ddx_coarse ddx_fine ddy ddy_coarse ddy_fine degrees determinant
DeviceMemoryBarrier DeviceMemoryBarrierWithGroupSync distance dot dst
errorf EvaluateAttributeAtCentroid EvaluateAttributeAtSample
EvaluateAttributeSnapped exp exp2 f16tof32 f32tof16 faceforward
firstbithigh firstbitlow floor fma fmod frac frexp fwidth
GetRenderTargetSampleCount GetRenderTargetSamplePosition
GlobalOrderedCountIncrement GroupMemoryBarrier
GroupMemoryBarrierWithGroupSync InterlockedAdd InterlockedAnd
InterlockedCompareExchange InterlockedCompareStore InterlockedExchange
InterlockedMax InterlockedMin InterlockedOr InterlockedXor isfinite
isinf isnan ldexp length lerp lit log log10 log2 mad max min modf
msad4 mul noise normalize pow printf Process2DQuadTessFactorsAvg
Process2DQuadTessFactorsMax Process2DQuadTessFactorsMin
ProcessIsolineTessFactors ProcessQuadTessFactorsAvg
ProcessQuadTessFactorsMax ProcessQuadTessFactorsMin
ProcessTriTessFactorsAvg ProcessTriTessFactorsMax
ProcessTriTessFactorsMin QuadReadLaneAt QuadSwapX QuadSwapY radians
rcp reflect refract reversebits round rsqrt saturate sign sin sincos
sinh smoothstep sqrt step tan tanh tex1D tex1D tex1Dbias tex1Dgrad
tex1Dlod tex1Dproj tex2D tex2D tex2Dbias tex2Dgrad tex2Dlod tex2Dproj
tex3D tex3D tex3Dbias tex3Dgrad tex3Dlod tex3Dproj texCUBE texCUBE
texCUBEbias texCUBEgrad texCUBElod texCUBEproj transpose trunc
WaveAllBitAnd WaveAllMax WaveAllMin WaveAllBitOr WaveAllBitXor
WaveAllEqual WaveAllProduct WaveAllSum WaveAllTrue WaveAnyTrue
WaveBallot WaveGetLaneCount WaveGetLaneIndex WaveGetOrderedIndex
WaveIsHelperLane WaveOnce WavePrefixProduct WavePrefixSum
WaveReadFirstLane WaveReadLaneAt
SV_CLIPDISTANCE SV_CLIPDISTANCE0 SV_CLIPDISTANCE1 SV_CULLDISTANCE
SV_CULLDISTANCE0 SV_CULLDISTANCE1 SV_COVERAGE SV_DEPTH
SV_DEPTHGREATEREQUAL SV_DEPTHLESSEQUAL SV_DISPATCHTHREADID
SV_DOMAINLOCATION SV_GROUPID SV_GROUPINDEX SV_GROUPTHREADID
SV_GSINSTANCEID SV_INNERCOVERAGE SV_INSIDETESSFACTOR SV_INSTANCEID
SV_ISFRONTFACE SV_OUTPUTCONTROLPOINTID SV_POSITION SV_PRIMITIVEID
SV_RENDERTARGETARRAYINDEX SV_SAMPLEINDEX SV_STENCILREF SV_TESSFACTOR
SV_VERTEXID SV_VIEWPORTARRAYINDEX
allow_uav_condition branch call domain earlydepthstencil fastopt
flatten forcecase instance loop maxtessfactor numthreads
outputcontrolpoints outputtopology partitioning patchconstantfunc
unroll
BINORMAL BINORMAL0 BINORMAL1 BINORMAL2 BINORMAL3 BINORMAL4
BLENDINDICES0 BLENDINDICES1 BLENDINDICES2 BLENDINDICES3 BLENDINDICES4
BLENDWEIGHT0 BLENDWEIGHT1 BLENDWEIGHT2 BLENDWEIGHT3 BLENDWEIGHT4 COLOR
COLOR0 COLOR1 COLOR2 COLOR3 COLOR4 NORMAL NORMAL0 NORMAL1 NORMAL2
NORMAL3 NORMAL4 POSITION POSITION0 POSITION1 POSITION2 POSITION3
POSITION4 POSITIONT PSIZE0 PSIZE1 PSIZE2 PSIZE3 PSIZE4 TANGENT
TANGENT0 TANGENT1 TANGENT2 TANGENT3 TANGENT4 TESSFACTOR0 TESSFACTOR1
TESSFACTOR2 TESSFACTOR3 TESSFACTOR4 TEXCOORD0 TEXCOORD1 TEXCOORD2
TEXCOORD3 TEXCOORD4
FOG PSIZE
VFACE VPOS
DEPTH0 DEPTH1 DEPTH2 DEPTH3 DEPTH4
)
end
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
id = /[a-zA-Z_][a-zA-Z0-9_]*/
state :root do
mixin :expr_whitespace
rule %r(
([\w*\s]+?[\s*]) # return arguments
(#{id}) # function name
(\s*\([^;]*?\)(?:\s*:\s+#{id})?) # signature
(#{ws}?)({|;) # open brace or semicolon
)mx do |m|
# This is copied from the C lexer
recurse m[1]
token Name::Function, m[2]
recurse m[3]
recurse m[4]
token Punctuation, m[5]
if m[5] == ?{
push :function
end
end
rule %r/\{/, Punctuation, :function
mixin :statements
end
end
end
end
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'json.rb'
class HOCON < JSON
title 'HOCON'
desc "Human-Optimized Config Object Notation (https://github.com/lightbend/config)"
tag 'hocon'
filenames '*.hocon'
state :comments do
# Comments
rule %r(//.*?$), Comment::Single
rule %r(#.*?$), Comment::Single
end
prepend :root do
mixin :comments
end
prepend :object do
# Keywords
rule %r/\b(?:include|url|file|classpath)\b/, Keyword
end
state :name do
rule %r/("(?:\"|[^"\n])*?")(\s*)([:=]|(?={))/ do
groups Name::Label, Text::Whitespace, Punctuation
end
rule %r/([-\w.]+)(\s*)([:=]|(?={))/ do
groups Name::Label, Text::Whitespace, Punctuation
end
end
state :value do
mixin :comments
rule %r/\n/, Text::Whitespace
rule %r/\s+/, Text::Whitespace
mixin :constants
# Interpolation
rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
# Strings
rule %r/"""/, Literal::String::Double, :multiline_string
rule %r/"/, Str::Double, :string
rule %r/\[/, Punctuation, :array
rule %r/{/, Punctuation, :object
# Symbols (only those not handled by JSON)
rule %r/[()=]/, Punctuation
# Values
rule %r/[^$"{}\[\]:=,\+#`^?!@*&]+?/, Literal
end
state :interpolation do
rule %r/[\w\-\.]+?/, Name::Variable
rule %r/}/, Literal::String::Interpol, :pop!
end
prepend :string do
rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
rule %r/[^\\"\${]+/, Literal::String::Double
end
state :multiline_string do
rule %r/"[^"]{1,2}/, Literal::String::Double
mixin :string
rule %r/"""/, Literal::String::Double, :pop!
end
prepend :constants do
# Numbers (handle the case where we have multiple periods, ie. IP addresses)
rule %r/\d+\.(\d+\.?){3,}/, Literal
end
end
end
end
@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
load_lexer 'sql.rb'
class HQL < SQL
title "HQL"
desc "Hive Query Language SQL dialect"
tag 'hql'
filenames '*.hql'
def self.keywords
# sources:
# https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
# https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
@keywords ||= Set.new(%w(
ADD ADMIN AFTER ANALYZE ARCHIVE ASC BEFORE BUCKET BUCKETS CASCADE
CHANGE CLUSTER CLUSTERED CLUSTERSTATUS COLLECTION COLUMNS COMMENT
COMPACT COMPACTIONS COMPUTE CONCATENATE CONTINUE DATA DATABASES
DATETIME DAY DBPROPERTIES DEFERRED DEFINED DELIMITED DEPENDENCY DESC
DIRECTORIES DIRECTORY DISABLE DISTRIBUTE ELEM_TYPE ENABLE ESCAPED
EXCLUSIVE EXPLAIN EXPORT FIELDS FILE FILEFORMAT FIRST FORMAT FORMATTED
FUNCTIONS HOLD_DDLTIME HOUR IDXPROPERTIES IGNORE INDEX INDEXES INPATH
INPUTDRIVER INPUTFORMAT ITEMS JAR KEYS KEY_TYPE LIMIT LINES LOAD
LOCATION LOCK LOCKS LOGICAL LONG MAPJOIN MATERIALIZED METADATA MINUS
MINUTE MONTH MSCK NOSCAN NO_DROP OFFLINE OPTION OUTPUTDRIVER
OUTPUTFORMAT OVERWRITE OWNER PARTITIONED PARTITIONS PLUS PRETTY
PRINCIPALS PROTECTION PURGE READ READONLY REBUILD RECORDREADER
RECORDWRITER REGEXP RELOAD RENAME REPAIR REPLACE REPLICATION RESTRICT
REWRITE RLIKE ROLE ROLES SCHEMA SCHEMAS SECOND SEMI SERDE
SERDEPROPERTIES SERVER SETS SHARED SHOW SHOW_DATABASE SKEWED SORT
SORTED SSL STATISTICS STORED STREAMTABLE STRING STRUCT TABLES
TBLPROPERTIES TEMPORARY TERMINATED TINYINT TOUCH TRANSACTIONS UNARCHIVE
UNDO UNIONTYPE UNLOCK UNSET UNSIGNED URI USE UTC UTCTIMESTAMP
VALUE_TYPE VIEW WHILE YEAR IF
ALL ALTER AND ARRAY AS AUTHORIZATION BETWEEN BIGINT BINARY BOOLEAN
BOTH BY CASE CAST CHAR COLUMN CONF CREATE CROSS CUBE CURRENT
CURRENT_DATE CURRENT_TIMESTAMP CURSOR DATABASE DATE DECIMAL DELETE
DESCRIBE DISTINCT DOUBLE DROP ELSE END EXCHANGE EXISTS EXTENDED
EXTERNAL FALSE FETCH FLOAT FOLLOWING FOR FROM FULL FUNCTION GRANT
GROUP GROUPING HAVING IF IMPORT IN INNER INSERT INT INTERSECT
INTERVAL INTO IS JOIN LATERAL LEFT LESS LIKE LOCAL MACRO MAP MORE
NONE NOT NULL OF ON OR ORDER OUT OUTER OVER PARTIALSCAN PARTITION
PERCENT PRECEDING PRESERVE PROCEDURE RANGE READS REDUCE REVOKE RIGHT
ROLLUP ROW ROWS SELECT SET SMALLINT TABLE TABLESAMPLE THEN TIMESTAMP
TO TRANSFORM TRIGGER TRUE TRUNCATE UNBOUNDED UNION UNIQUEJOIN UPDATE
USER USING UTC_TMESTAMP VALUES VARCHAR WHEN WHERE WINDOW WITH
AUTOCOMMIT ISOLATION LEVEL OFFSET SNAPSHOT TRANSACTION WORK WRITE
COMMIT ONLY REGEXP RLIKE ROLLBACK START
ABORT KEY LAST NORELY NOVALIDATE NULLS RELY VALIDATE
CACHE CONSTRAINT FOREIGN PRIMARY REFERENCES
DETAIL DOW EXPRESSION OPERATOR QUARTER SUMMARY VECTORIZATION WEEK YEARS MONTHS WEEKS DAYS HOURS MINUTES SECONDS
DAYOFWEEK EXTRACT FLOOR INTEGER PRECISION VIEWS
TIMESTAMPTZ ZONE
TIME NUMERIC
NAMED_STRUCT CREATE_UNION
ROUND BROUND FLOOR CEIL CEILING RAND EXP LN LOG10 LOG2 LOG POW POWER SQRT BIN
HEX UNHEX CONV ABS PMOD SIN ASIN COS ACOS TAN ATAN DEGREES RADIANS POSITIVE
NEGATIVE SIGN E PI FACTORIAL CBRT SHIFTLEFT SHIFTRIGHT SHIFTRIGHTUNSIGNED
GREATEST LEAST WIDTH_BUCKET SIZE SIZE MAP_KEYS MAP_VALUES ARRAY_CONTAINS
SORT_ARRAY BINARY CAST FROM_UNIXTIME UNIX_TIMESTAMP UNIX_TIMESTAMP
UNIX_TIMESTAMP TO_DATE YEAR QUARTER MONTH DAY DAYOFMONTH HOUR MINUTE SECOND
WEEKOFYEAR EXTRACT DATEDIFF DATE_ADD DATE_SUB FROM_UTC_TIMESTAMP
TO_UTC_TIMESTAMP CURRENT_DATE CURRENT_TIMESTAMP ADD_MONTHS LAST_DAY NEXT_DAY
TRUNC MONTHS_BETWEEN DATE_FORMAT IF ISNULL ISNOTNULL NVL COALESCE CASE WHEN
then else end NULLIF ASSERT_TRUE ASCII BASE64 CHARACTER_LENGTH CHR CONCAT
CONTEXT_NGRAMS CONCAT_WS CONCAT_WS DECODE ELT ENCODE FIELD FIND_IN_SET
FORMAT_NUMBER GET_JSON_OBJECT IN_FILE INSTR LENGTH LOCATE LOWER LCASE LPAD LTRIM
NGRAMS OCTET_LENGTH PARSE_URL PRINTF REGEXP_EXTRACT REGEXP_REPLACE REPEAT
REPLACE REVERSE RPAD RTRIM SENTENCES SPACE SPLIT STR_TO_MAP SUBSTR SUBSTRING
SUBSTRING_INDEX TRANSLATE TRIM UNBASE64 UPPER UCASE INITCAP LEVENSHTEIN SOUNDEX
MASK MASK_FIRST_N MASK_LAST_N MASK_SHOW_FIRST_N MASK_SHOW_LAST_N MASK_HASH
JAVA_METHOD REFLECT HASH CURRENT_USER LOGGED_IN_USER CURRENT_DATABASE MD5 SHA1
SHA CRC32 SHA2 AES_ENCRYPT AES_DECRYPT VERSION COUNT SUM AVG MIN MAX VARIANCE
VAR_POP VAR_SAMP STDDEV_POP STDDEV_SAMP COVAR_POP COVAR_SAMP CORR PERCENTILE
PERCENTILE_APPROX PERCENTILE_APPROX REGR_AVGX REGR_AVGY REGR_COUNT
REGR_INTERCEPT REGR_R2 REGR_SLOPE REGR_SXX REGR_SXY REGR_SYY HISTOGRAM_NUMERIC
COLLECT_SET COLLECT_LIST NTILE EXPLODE EXPLODE POSEXPLODE INLINE STACK
JSON_TUPLE PARSE_URL_TUPLE
XPATH XPATH_SHORT XPATH_INT XPATH_LONG XPATH_FLOAT XPATH_DOUBLE
XPATH_NUMBER XPATH_STRING GET_JSON_OBJECT JSON_TUPLE
PARSE_URL_TUPLE
))
end
def self.keywords_type
# source: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
@keywords_type ||= Set.new(%w(
TINYINT SMALLINT INT INTEGER BIGINT FLOAT DOUBLE PRECISION DECIMAL NUMERIC
TIMESTAMP DATE INTERVAL
STRING VARCHAR CHAR
BOOLEAN BINARY
ARRAY MAP STRUCT UNIONTYPE
))
end
prepend :root do
# a double-quoted string is a string literal in Hive QL.
rule %r/"/, Str::Double, :double_string
# interpolation of variables through ${...}
rule %r/\$\{/, Name::Variable, :hive_variable
end
prepend :single_string do
rule %r/\$\{/, Name::Variable, :hive_variable
rule %r/[^\\'\$]+/, Str::Single
end
prepend :double_string do
rule %r/\$\{/, Name::Variable, :hive_variable
# double-quoted strings are string literals so need to change token
rule %r/"/, Str::Double, :pop!
rule %r/[^\\"\$]+/, Str::Double
end
state :hive_variable do
rule %r/\}/, Name::Variable, :pop!
rule %r/[^\}]+/, Name::Variable
end
end
end
end
@@ -0,0 +1,141 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class HTML < RegexLexer
title "HTML"
desc "HTML, the markup language of the web"
tag 'html'
filenames '*.htm', '*.html', '*.xhtml', '*.cshtml', '*.razor'
mimetypes 'text/html', 'application/xhtml+xml'
def self.detect?(text)
return true if text.doctype?(/\bhtml\b/i)
return false if text =~ /\A<\?xml\b/
return true if text =~ /<\s*html\b/
end
start do
@javascript = Javascript.new(options)
@css = CSS.new(options)
end
state :root do
rule %r/[^<&]+/m, Text
rule %r/&\S*?;/, Name::Entity
rule %r/<!DOCTYPE .*?>/im, Comment::Preproc
rule %r/<!\[CDATA\[.*?\]\]>/m, Comment::Preproc
rule %r/<!--/, Comment, :comment
rule %r/<\?.*?\?>/m, Comment::Preproc # php? really?
rule %r/<\s*script\s*/m do
token Name::Tag
@javascript.reset!
push :script_content
push :tag
end
rule %r/<\s*style\s*/m do
token Name::Tag
@css.reset!
@lang = @css
push :style_content
push :tag
end
rule %r(</), Name::Tag, :tag_end
rule %r/</, Name::Tag, :tag_start
rule %r(<\s*[\p{L}:_-][\p{Word}\p{Cf}:.·-]*), Name::Tag, :tag # opening tags
rule %r(<\s*/\s*[\p{L}:_-][\p{Word}\p{Cf}:.·-]*\s*>), Name::Tag # closing tags
end
state :tag_end do
mixin :tag_end_end
rule %r/[\p{L}:_-][\p{Word}\p{Cf}:.·-]*/ do
token Name::Tag
goto :tag_end_end
end
end
state :tag_end_end do
rule %r/\s+/, Text
rule %r/>/, Name::Tag, :pop!
end
state :tag_start do
rule %r/\s+/, Text
rule %r/[\p{L}:_-][\p{Word}\p{Cf}:.·-]*/ do
token Name::Tag
goto :tag
end
rule(//) { goto :tag }
end
state :comment do
rule %r/[^-]+/, Comment
rule %r/-->/, Comment, :pop!
rule %r/-/, Comment
end
state :tag do
rule %r/\s+/m, Text
rule %r/[\p{L}:_\[\]()*.-][\p{Word}\p{Cf}:.·\[\]()*-]*\s*=\s*/m, Name::Attribute, :attr
rule %r/[\p{L}:_*#-][\p{Word}\p{Cf}:.·*#-]*/, Name::Attribute
rule %r(/?\s*>)m, Name::Tag, :pop!
end
state :attr do
# TODO: are backslash escapes valid here?
rule %r/"/ do
token Str
goto :dq
end
rule %r/'/ do
token Str
goto :sq
end
rule %r/[^\s>]+/, Str, :pop!
end
state :dq do
rule %r/"/, Str, :pop!
rule %r/[^"]+/, Str
end
state :sq do
rule %r/'/, Str, :pop!
rule %r/[^']+/, Str
end
state :script_content do
rule %r([^<]+) do
delegate @javascript
end
rule %r(<\s*/\s*script\s*>)m, Name::Tag, :pop!
rule %r(<) do
delegate @javascript
end
end
state :style_content do
rule %r/[^<]+/ do
delegate @lang
end
rule %r(<\s*/\s*style\s*>)m, Name::Tag, :pop!
rule %r/</ do
delegate @lang
end
end
end
end
end
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class HTTP < RegexLexer
tag 'http'
title "HTTP"
desc 'http requests and responses'
option :content, "the language for the content (default: auto-detect)"
def self.http_methods
@http_methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH QUERY)
end
def content_lexer
@content_lexer ||= (lexer_option(:content) || guess_content_lexer)
end
def guess_content_lexer
return Lexers::PlainText unless @content_type
Lexer.guess_by_mimetype(@content_type)
rescue Lexer::AmbiguousGuess
Lexers::PlainText
end
start { @content_type = 'text/plain' }
state :root do
# request
rule %r(
(#{HTTP.http_methods.join('|')})([ ]+) # method
([^ ]+)([ ]+) # path
(HTTPS?)(/)(\d(?:\.\d)?)(\r?\n|$) # http version
)ox do
groups(
Name::Function, Text,
Name::Namespace, Text,
Keyword, Operator, Num, Text
)
push :headers
end
# response
rule %r(
(HTTPS?)(/)(\d(?:\.\d)?)([ ]+) # http version
(\d{3})([ ]+)? # status
([^\r\n]*)?(\r?\n|$) # status message
)x do
groups(
Keyword, Operator, Num, Text,
Num, Text,
Name::Exception, Text
)
push :headers
end
end
state :headers do
rule %r/([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|$)/ do |m|
key = m[1]
value = m[5]
if key.strip.casecmp('content-type').zero?
@content_type = value.split(';')[0].downcase
end
groups Name::Attribute, Text, Punctuation, Text, Str, Text
end
rule %r/([^\r\n]+)(\r?\n|$)/ do
groups Str, Text
end
rule %r/\r?\n/, Text, :content
end
state :content do
rule %r/.+/m do
delegate(content_lexer)
end
end
end
end
end
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class HyLang < RegexLexer
title "HyLang"
desc "The HyLang programming language (hylang.org)"
tag 'hylang'
aliases 'hy'
filenames '*.hy'
mimetypes 'text/x-hy', 'application/x-hy'
def self.keywords
@keywords ||= Set.new %w(
False None True and as assert break class continue def
del elif else except finally for from global if import
in is lambda nonlocal not or pass raise return try
)
end
def self.builtins
@builtins ||= Set.new %w(
!= % %= & &= * ** **= *= *map
+ += , - -= -> ->> . / //
//= /= < << <<= <= = > >= >>
>>= @ @= ^ ^= accumulate apply as-> assoc butlast
calling-module-name car cdr chain coll? combinations comp complement compress cond
cons cons? constantly count cut cycle dec defclass defmacro defmacro!
defmacro/g! defmain defn defreader dict-comp disassemble dispatch-reader-macro distinct do doto
drop drop-last drop-while empty? eval eval-and-compile eval-when-compile even? every? filter
first flatten float? fn for* fraction genexpr gensym get group-by
identity if* if-not if-python2 inc input instance? integer integer-char? integer?
interleave interpose islice iterable? iterate iterator? juxt keyword keyword? last
let lif lif-not list* list-comp macro-error macroexpand macroexpand-1 map merge-with
multicombinations name neg? none? not-in not? nth numeric? odd? partition
permutations pos? product quasiquote quote range read read-str reduce remove
repeat repeatedly require rest second set-comp setv some string string?
symbol? take take-nth take-while tee unless unquote unquote-splicing when with*
with-decorator with-gensyms xor yield-from zero? zip zip-longest | |= ~
)
end
identifier = %r([\w!$%*+,<=>?/.-]+)
keyword = %r([\w!\#$%*+,<=>?/.-]+)
def name_token(name)
return Keyword if self.class.keywords.include?(name)
return Name::Builtin if self.class.builtins.include?(name)
nil
end
state :root do
rule %r/;.*?$/, Comment::Single
rule %r/\s+/m, Text::Whitespace
rule %r/-?\d+\.\d+/, Num::Float
rule %r/-?\d+/, Num::Integer
rule %r/0x-?[0-9a-fA-F]+/, Num::Hex
rule %r/"(\\.|[^"])*"/, Str
rule %r/'#{keyword}/, Str::Symbol
rule %r/::?#{keyword}/, Name::Constant
rule %r/\\(.|[a-z]+)/i, Str::Char
rule %r/~@|[`\'#^~&@]/, Operator
rule %r/(\()(\s*)(#{identifier})/m do |m|
token Punctuation, m[1]
token Text::Whitespace, m[2]
token(name_token(m[3]) || Name::Function, m[3])
end
rule identifier do |m|
token name_token(m[0]) || Name
end
# vectors
rule %r/[\[\]]/, Punctuation
# maps
rule %r/[{}]/, Punctuation
# parentheses
rule %r/[()]/, Punctuation
end
end
end
end
@@ -0,0 +1,312 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# vim: set ts=2 sw=2 et:
module Rouge
module Lexers
class IDLang < RegexLexer
title "IDL"
desc "Interactive Data Language"
tag 'idlang'
filenames '*.idl'
name = /[_A-Z]\w*/i
kind_param = /(\d+|#{name})/
exponent = /[dDeE][+-]\d+/
def self.exec_unit
@exec_unit ||= Set.new %w(
PRO FUNCTION
)
end
def self.keywords
@keywords ||= Set.new %w(
STRUCT INHERITS
RETURN CONTINUE BEGIN END BREAK GOTO
)
end
def self.standalone_statements
# Must not have a comma afterwards
@standalone_statements ||= Set.new %w(
COMMON FORWARD_FUNCTION
)
end
def self.decorators
# Must not have a comma afterwards
@decorators ||= Set.new %w(
COMPILE_OPT
)
end
def self.operators
@operators ||= Set.new %w(
AND= EQ= GE= GT= LE= LT= MOD= NE= OR= XOR= NOT=
)
end
def self.conditionals
@conditionals ||= Set.new %w(
OF DO ENDIF ENDELSE ENDFOR ENDFOREACH ENDWHILE ENDREP ENDCASE ENDSWITCH
IF THEN ELSE FOR FOREACH WHILE REPEAT UNTIL CASE SWITCH
AND EQ GE GT LE LT MOD NE OR XOR NOT
)
end
def self.routines
@routines ||= Set.new %w(
A_CORRELATE ABS ACOS ADAPT_HIST_EQUAL ALOG ALOG10
AMOEBA ANNOTATE ARG_PRESENT ARRAY_EQUAL
ARRAY_INDICES ARROW ASCII_TEMPLATE ASIN ASSOC ATAN
AXIS BAR_PLOT BESELI BESELJ BESELK BESELY BETA
BILINEAR BIN_DATE BINARY_TEMPLATE BINDGEN BINOMIAL
BLAS_AXPY BLK_CON BOX_CURSOR BREAK BREAKPOINT
BROYDEN BYTARR BYTE BYTEORDER BYTSCL C_CORRELATE
CALDAT CALENDAR CALL_EXTERNAL CALL_FUNCTION
CALL_METHOD CALL_PROCEDURE CATCH CD CEIL CHEBYSHEV
CHECK_MATH CHISQR_CVF CHISQR_PDF CHOLDC CHOLSOL
CINDGEN CIR_3PNT CLOSE CLUST_WTS CLUSTER
COLOR_CONVERT COLOR_QUAN COLORMAP_APPLICABLE COMFIT
COMPLEX COMPLEXARR COMPLEXROUND
COMPUTE_MESH_NORMALS COND CONGRID CONJ
CONSTRAINED_MIN CONTOUR CONVERT_COORD CONVOL
COORD2TO3 CORRELATE COS COSH CRAMER CREATE_STRUCT
CREATE_VIEW CROSSP CRVLENGTH CT_LUMINANCE CTI_TEST
CURSOR CURVEFIT CV_COORD CVTTOBM CW_ANIMATE
CW_ANIMATE_GETP CW_ANIMATE_LOAD CW_ANIMATE_RUN
CW_ARCBALL CW_BGROUP CW_CLR_INDEX CW_COLORSEL
CW_DEFROI CW_FIELD CW_FILESEL CW_FORM CW_FSLIDER
CW_LIGHT_EDITOR CW_LIGHT_EDITOR_GET
CW_LIGHT_EDITOR_SET CW_ORIENT CW_PALETTE_EDITOR
CW_PALETTE_EDITOR_GET CW_PALETTE_EDITOR_SET
CW_PDMENU CW_RGBSLIDER CW_TMPL CW_ZOOM DBLARR
DCINDGEN DCOMPLEX DCOMPLEXARR DEFINE_KEY DEFROI
DEFSYSV DELETE_SYMBOL DELLOG DELVAR DERIV DERIVSIG
DETERM DEVICE DFPMIN DIALOG_MESSAGE
DIALOG_PICKFILE DIALOG_PRINTERSETUP
DIALOG_PRINTJOB DIALOG_READ_IMAGE
DIALOG_WRITE_IMAGE DICTIONARY DIGITAL_FILTER DILATE DINDGEN
DISSOLVE DIST DLM_LOAD DLM_REGISTER
DO_APPLE_SCRIPT DOC_LIBRARY DOUBLE DRAW_ROI EFONT
EIGENQL EIGENVEC ELMHES EMPTY ENABLE_SYSRTN EOF
ERASE ERODE ERRORF ERRPLOT EXECUTE EXIT EXP EXPAND
EXPAND_PATH EXPINT EXTRAC EXTRACT_SLICE F_CVF
F_PDF FACTORIAL FFT FILE_CHMOD FILE_DELETE
FILE_EXPAND_PATH FILE_MKDIR FILE_TEST FILE_WHICH
FILE_SEARCH PATH_SEP FILE_DIRNAME FILE_BASENAME
FILE_INFO FILE_MOVE FILE_COPY FILE_LINK FILE_POLL_INPUT
FILEPATH FINDFILE FINDGEN FINITE FIX FLICK FLOAT
FLOOR FLOW3 FLTARR FLUSH FORMAT_AXIS_VALUES
FORWARD_FUNCTION FREE_LUN FSTAT FULSTR FUNCT
FV_TEST FX_ROOT FZ_ROOTS GAMMA GAMMA_CT
GAUSS_CVF GAUSS_PDF GAUSS2DFIT GAUSSFIT GAUSSINT
GET_DRIVE_LIST GET_KBRD GET_LUN GET_SCREEN_SIZE
GET_SYMBOL GETENV GOTO GREG2JUL GRID_TPS GRID3 GS_ITER
H_EQ_CT H_EQ_INT HANNING HASH HEAP_GC HELP HILBERT
HIST_2D HIST_EQUAL HISTOGRAM HLS HOUGH HQR HSV
IBETA IDENTITY IDL_CONTAINER IDLANROI
IDLANROIGROUP IDLFFDICOM IDLFFDXF IDLFFLANGUAGECAT
IDLFFSHAPE IDLGRAXIS IDLGRBUFFER IDLGRCLIPBOARD
IDLGRCOLORBAR IDLGRCONTOUR IDLGRFONT IDLGRIMAGE
IDLGRLEGEND IDLGRLIGHT IDLGRMODEL IDLGRMPEG
IDLGRPALETTE IDLGRPATTERN IDLGRPLOT IDLGRPOLYGON
IDLGRPOLYLINE IDLGRPRINTER IDLGRROI IDLGRROIGROUP
IDLGRSCENE IDLGRSURFACE IDLGRSYMBOL
IDLGRTESSELLATOR IDLGRTEXT IDLGRVIEW
IDLGRVIEWGROUP IDLGRVOLUME IDLGRVRML IDLGRWINDOW
IGAMMA IMAGE_CONT IMAGE_STATISTICS IMAGINARY
INDGEN INT_2D INT_3D INT_TABULATED INTARR INTERPOL
INTERPOLATE INVERT IOCTL ISA ISHFT ISOCONTOUR
ISOSURFACE JOURNAL JUL2GREG JULDAY KEYWORD_SET KRIG2D
KURTOSIS KW_TEST L64INDGEN LABEL_DATE LABEL_REGION
LADFIT LAGUERRE LEEFILT LEGENDRE LINBCG LINDGEN
LINFIT LINKIMAGE LIST LIVE_CONTOUR LIVE_CONTROL
LIVE_DESTROY LIVE_EXPORT LIVE_IMAGE LIVE_INFO
LIVE_LINE LIVE_LOAD LIVE_OPLOT LIVE_PLOT
LIVE_PRINT LIVE_RECT LIVE_STYLE LIVE_SURFACE
LIVE_TEXT LJLCT LL_ARC_DISTANCE LMFIT LMGR LNGAMMA
LNP_TEST LOADCT LOCALE_GET LON64ARR LONARR LONG
LONG64 LSODE LU_COMPLEX LUDC LUMPROVE LUSOL
M_CORRELATE MACHAR MAKE_ARRAY MAKE_DLL MAP_2POINTS
MAP_CONTINENTS MAP_GRID MAP_IMAGE MAP_PATCH
MAP_PROJ_INFO MAP_SET MAX MATRIX_MULTIPLY MD_TEST MEAN
MEANABSDEV MEDIAN MEMORY MESH_CLIP MESH_DECIMATE
MESH_ISSOLID MESH_MERGE MESH_NUMTRIANGLES MESH_OBJ
MESH_SMOOTH MESH_SURFACEAREA MESH_VALIDATE
MESH_VOLUME MESSAGE MIN MIN_CURVE_SURF MK_HTML_HELP
MODIFYCT MOMENT MORPH_CLOSE MORPH_DISTANCE
MORPH_GRADIENT MORPH_HITORMISS MORPH_OPEN
MORPH_THIN MORPH_TOPHAT MPEG_CLOSE MPEG_OPEN
MPEG_PUT MPEG_SAVE MSG_CAT_CLOSE MSG_CAT_COMPILE
MSG_CAT_OPEN MULTI N_ELEMENTS N_PARAMS N_TAGS
NEWTON NORM OBJ_CLASS OBJ_DESTROY OBJ_ISA OBJ_NEW
OBJ_VALID OBJARR ON_ERROR ON_IOERROR ONLINE_HELP
OPEN OPENR OPENW OPENU OPLOT OPLOTERR ORDEREDHASH P_CORRELATE
PARTICLE_TRACE PCOMP PLOT PLOT_3DBOX PLOT_FIELD
PLOTERR PLOTS PNT_LINE POINT_LUN POLAR_CONTOUR
POLAR_SURFACE POLY POLY_2D POLY_AREA POLY_FIT
POLYFILL POLYFILLV POLYSHADE POLYWARP POPD POWELL
PRIMES PRINT PRINTF PRINTD PRODUCT PROFILE PROFILER
PROFILES PROJECT_VOL PS_SHOW_FONTS PSAFM PSEUDO
PTR_FREE PTR_NEW PTR_VALID PTRARR PUSHD QROMB
QROMO QSIMP QUERY_CSV R_CORRELATE R_TEST RADON RANDOMN
RANDOMU RANKS RDPIX READ READF READ_ASCII
READ_BINARY READ_BMP READ_CSV READ_DICOM READ_IMAGE
READ_INTERFILE READ_JPEG READ_PICT READ_PNG
READ_PPM READ_SPR READ_SRF READ_SYLK READ_TIFF
READ_WAV READ_WAVE READ_X11_BITMAP READ_XWD READS
READU REBIN RECALL_COMMANDS RECON3 REDUCE_COLORS
REFORM REGRESS REPLICATE REPLICATE_INPLACE
RESOLVE_ALL RESOLVE_ROUTINE RESTORE RETALL
REVERSE REWIND RK4 ROBERTS ROT ROTATE ROUND
ROUTINE_INFO RS_TEST S_TEST SAVE SAVGOL SCALE3
SCALE3D SCOPE_LEVEL SCOPE_TRACEBACK SCOPE_VARFETCH
SCOPE_VARNAME SEARCH2D SEARCH3D SET_PLOT SET_SHADING
SET_SYMBOL SETENV SETLOG SETUP_KEYS SFIT
SHADE_SURF SHADE_SURF_IRR SHADE_VOLUME SHIFT SHOW3
SHOWFONT SIGNUM SIN SINDGEN SINH SIZE SKEWNESS SKIPF
SLICER3 SLIDE_IMAGE SMOOTH SOBEL SOCKET SORT SPAWN
SPH_4PNT SPH_SCAT SPHER_HARM SPL_INIT SPL_INTERP
SPLINE SPLINE_P SPRSAB SPRSAX SPRSIN SPRSTP SQRT
STANDARDIZE STDDEV STOP STRARR STRCMP STRCOMPRESS
STREAMLINE STREGEX STRETCH STRING STRJOIN STRLEN
STRLOWCASE STRMATCH STRMESSAGE STRMID STRPOS
STRPUT STRSPLIT STRTRIM STRUCT_ASSIGN STRUCT_HIDE
STRUPCASE SURFACE SURFR SVDC SVDFIT SVSOL
SWAP_ENDIAN SWITCH SYSTIME T_CVF T_PDF T3D
TAG_NAMES TAN TANH TAPRD TAPWRT TEK_COLOR
TEMPORARY TETRA_CLIP TETRA_SURFACE TETRA_VOLUME
THIN THREED TIME_TEST2 TIMEGEN TM_TEST TOTAL TRACE
TRANSPOSE TRI_SURF TRIANGULATE TRIGRID TRIQL
TRIRED TRISOL TRNLOG TS_COEF TS_DIFF TS_FCAST
TS_SMOOTH TV TVCRS TVLCT TVRD TVSCL TYPENAME UINDGEN UINT
UINTARR UL64INDGEN ULINDGEN ULON64ARR ULONARR
ULONG ULONG64 UNIQ USERSYM VALUE_LOCATE VARIANCE
VAX_FLOAT VECTOR_FIELD VEL VELOVECT VERT_T3D VOIGT
VORONOI VOXEL_PROJ WAIT WARP_TRI WATERSHED WDELETE
WEOF WF_DRAW WHERE WIDGET_BASE WIDGET_BUTTON
WIDGET_CONTROL WIDGET_DRAW WIDGET_DROPLIST
WIDGET_EVENT WIDGET_INFO WIDGET_LABEL WIDGET_LIST
WIDGET_SLIDER WIDGET_TABLE WIDGET_TEXT WINDOW
WRITE_BMP WRITE_CSV WRITE_IMAGE WRITE_JPEG WRITE_NRIF
WRITE_PICT WRITE_PNG WRITE_PPM WRITE_SPR WRITE_SRF
WRITE_SYLK WRITE_TIFF WRITE_WAV WRITE_WAVE WRITEU
WSET WSHOW WTN WV_APPLET WV_CW_WAVELET WV_CWT
WV_DENOISE WV_DWT WV_FN_COIFLET WV_FN_DAUBECHIES
WV_FN_GAUSSIAN WV_FN_HAAR WV_FN_MORLET WV_FN_PAUL
WV_FN_SYMLET WV_IMPORT_DATA WV_IMPORT_WAVELET
WV_PLOT3D_WPS WV_PLOT_MULTIRES WV_PWT
WV_TOOL_DENOISE XBM_EDIT XDISPLAYFILE XDXF XFONT
XINTERANIMATE XLOADCT XMANAGER XMNG_TMPL XMTOOL
XOBJVIEW XPALETTE XPCOLOR XPLOT3D XREGISTERED XROI
XSQ_TEST XSURFACE XVAREDIT XVOLUME XVOLUME_ROTATE
XVOLUME_WRITE_IMAGE XYOUTS ZOOM ZOOM_24
)
end
state :root do
rule %r/\s+/, Text::Whitespace
# Normal comments
rule %r/;.*$/, Comment::Single
rule %r/\,\s*\,/, Error
rule %r/\!#{name}/, Name::Variable::Global
rule %r/[(),:\&\$]/, Punctuation
## Format statements are quite a strange beast.
## Better process them in their own state.
#rule %r/\b(FORMAT)(\s*)(\()/mi do |m|
# token Keyword, m[1]
# token Text::Whitespace, m[2]
# token Punctuation, m[3]
# push :format_spec
#end
rule %r(
[+-]? # sign
(
(\d+[.]\d*|[.]\d+)(#{exponent})?
| \d+#{exponent} # exponent is mandatory
)
(_#{kind_param})? # kind parameter
)xi, Num::Float
rule %r/\d+(B|S|U|US|LL|L|ULL|UL)?/i, Num::Integer
rule %r/"[0-7]+(B|O|U|ULL|UL|LL|L)?/i, Num::Oct
rule %r/'[0-9A-F]+'X(B|S|US|ULL|UL|U|LL|L)?/i, Num::Hex
rule %r/(#{kind_param}_)?'/, Str::Single, :string_single
rule %r/(#{kind_param}_)?"/, Str::Double, :string_double
rule %r{\#\#|\#|\&\&|\|\||/=|<=|>=|->|\@|\?|[-+*/<=~^{}]}, Operator
# Structures and the like
rule %r/(#{name})(\.)([^\s,]*)/i do
groups Name, Operator, Name
#delegate IDLang, m[3]
end
rule %r/(function|pro)((?:\s|\$\s)+)/i do
groups Keyword, Text::Whitespace
push :funcname
end
rule %r/#{name}/m do |m|
match = m[0].upcase
if self.class.keywords.include? match
token Keyword
elsif self.class.conditionals.include? match
token Keyword
elsif self.class.decorators.include? match
token Name::Decorator
elsif self.class.standalone_statements.include? match
token Keyword::Reserved
elsif self.class.operators.include? match
token Operator::Word
elsif self.class.routines.include? match
token Name::Builtin
else
token Name
end
end
end
state :funcname do
rule %r/#{name}/, Name::Function
rule %r/\s+/, Text::Whitespace
rule %r/(:+|\$)/, Operator
rule %r/;.*/, Comment::Single
# Be done with this state if we hit EOL or comma
rule %r/$/, Text::Whitespace, :pop!
rule %r/,/, Operator, :pop!
end
state :string_single do
rule %r/[^']+/, Str::Single
rule %r/''/, Str::Escape
rule %r/'/, Str::Single, :pop!
end
state :string_double do
rule %r/[^"]+/, Str::Double
rule %r/"/, Str::Double, :pop!
end
state :format_spec do
rule %r/'/, Str::Single, :string_single
rule %r/"/, Str::Double, :string_double
rule %r/\(/, Punctuation, :format_spec
rule %r/\)/, Punctuation, :pop!
rule %r/,/, Punctuation
rule %r/\s+/, Text::Whitespace
# Edit descriptors could be seen as a kind of "format literal".
rule %r/[^\s'"(),]+/, Literal
end
end
end
end
@@ -0,0 +1,210 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Idris < RegexLexer
title "Idris"
desc "The Idris programming language (idris-lang.org)"
tag 'idris'
aliases 'idr'
filenames '*.idr'
mimetypes 'text/x-idris'
def self.reserved_keywords
@reserved_keywords ||= %w(
_ data class instance namespace
infix[lr]? let where of with type
do if then else case in
)
end
def self.ascii
@ascii ||= %w(
NUL SOH [SE]TX EOT ENQ ACK BEL BS HT LF VT FF CR S[OI] DLE
DC[1-4] NAK SYN ETB CAN EM SUB ESC [FGRU]S SP DEL
)
end
def self.prelude_functions
@prelude_functions ||= %w(
abs acos all and any asin atan atan2 break ceiling compare concat
concatMap const cos cosh curry cycle div drop dropWhile elem
encodeFloat enumFrom enumFromThen enumFromThenTo enumFromTo exp
fail filter flip floor foldl foldl1 foldr foldr1 fromInteger fst
gcd getChar getLine head id init iterate last lcm length lines log
lookup map max maxBound maximum maybe min minBound minimum mod
negate not null or pi pred print product putChar putStr putStrLn
readFile recip repeat replicate return reverse scanl scanl1 sequence
sequence_ show sin sinh snd span splitAt sqrt succ sum tail take
takeWhile tan tanh uncurry unlines unwords unzip unzip3 words
writeFile zip zip3 zipWith zipWith3
)
end
state :basic do
rule %r/\s+/m, Text
rule %r/{-#/, Comment::Preproc, :comment_preproc
rule %r/{-/, Comment::Multiline, :comment
rule %r/^\|\|\|.*$/, Comment::Doc
rule %r/--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
end
# nested commenting
state :comment do
rule %r/-}/, Comment::Multiline, :pop!
rule %r/{-/, Comment::Multiline, :comment
rule %r/[^-{}]+/, Comment::Multiline
rule %r/[-{}]/, Comment::Multiline
end
state :comment_preproc do
rule %r/-}/, Comment::Preproc, :pop!
rule %r/{-/, Comment::Preproc, :comment
rule %r/[^-{}]+/, Comment::Preproc
rule %r/[-{}]/, Comment::Preproc
end
state :directive do
rule %r/\%(default)\s+(total|partial)/, Keyword # totality
rule %r/\%(access)\s+(public|abstract|private|export)/, Keyword # export
rule %r/\%(language)\s+(.*)/, Keyword # language
rule %r/\%(provide)\s+.*\s+(with)\s+/, Keyword # type
end
state :prelude do
rule %r/\b(Type|Exists|World|IO|IntTy|FTy|File|Mode|Dec|Bool|Ordering|Either|IsJust|List|Maybe|Nat|Stream|StrM|Not|Lazy|Inf)\s/, Keyword::Type
rule %r/\b(Eq|Ord|Num|MinBound|MaxBound|Integral|Applicative|Alternative|Cast|Foldable|Functor|Monad|Traversable|Uninhabited|Semigroup|Monoid)\s/, Name::Class
rule %r/\b(?:#{Idris.prelude_functions.join('|')})[ ]+(?![=:-])/, Name::Builtin
end
state :root do
mixin :basic
mixin :directive
rule %r/\bimport\b/, Keyword::Reserved, :import
rule %r/\bmodule\b/, Keyword::Reserved, :module
rule %r/\b(?:#{Idris.reserved_keywords.join('|')})\b/, Keyword::Reserved
rule %r/\b(Just|Nothing|Left|Right|True|False|LT|LTE|EQ|GT|GTE)\b/, Keyword::Constant
# function signature
rule %r/^[\w']+\s*:/, Name::Function
# should be below as you can override names defined in Prelude
mixin :prelude
rule %r/[_a-z][\w']*/, Name
rule %r/[A-Z][\w']*/, Keyword::Type
# lambda operator
rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
# special operators
rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Operator
# constructor/type operators
rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), Operator
# other operators
rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), Operator
rule %r/\d+(\.\d+)?(e[+-]?\d+)?/i, Num::Float
rule %r/0o[0-7]+/i, Num::Oct
rule %r/0x[\da-f]+/i, Num::Hex
rule %r/\d+/, Num::Integer
rule %r/'/, Str::Char, :character
rule %r/"/, Str, :string
rule %r/\[\s*\]/, Keyword::Type
rule %r/\(\s*\)/, Name::Builtin
# Quasiquotations
rule %r/(\[)([_a-z][\w']*)(\|)/ do |m|
token Operator, m[1]
token Name, m[2]
token Operator, m[3]
push :quasiquotation
end
rule %r/[\[\](),;`{}]/, Punctuation
end
state :import do
rule %r/\s+/, Text
rule %r/"/, Str, :string
# import X as Y
rule %r/([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
groups(
Name::Namespace, # X
Text, Keyword, # as
Text, Name # Y
)
pop!
end
# import X (functions)
rule %r/([A-Z][\w.]*)(\s+)(\()/ do
groups(
Name::Namespace, # X
Text,
Punctuation # (
)
goto :funclist
end
rule %r/[\w.]+/, Name::Namespace, :pop!
end
state :module do
rule %r/\s+/, Text
# module X
rule %r/([A-Z][\w.]*)/, Name::Namespace, :pop!
end
state :funclist do
mixin :basic
rule %r/[A-Z]\w*/, Keyword::Type
rule %r/(_[\w\']+|[a-z][\w\']*)/, Name::Function
rule %r/,/, Punctuation
rule %r/[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
rule %r/\(/, Punctuation, :funclist
rule %r/\)/, Punctuation, :pop!
end
state :character do
rule %r/\\/ do
token Str::Escape
goto :character_end
push :escape
end
rule %r/./ do
token Str::Char
goto :character_end
end
end
state :character_end do
rule %r/'/, Str::Char, :pop!
rule %r/./, Error, :pop!
end
state :quasiquotation do
rule %r/\|\]/, Operator, :pop!
rule %r/[^\|]+/m, Text
rule %r/\|/, Text
end
state :string do
rule %r/"/, Str, :pop!
rule %r/\\/, Str::Escape, :escape
rule %r/[^\\"]+/, Str
end
state :escape do
rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
rule %r/#{Idris.ascii.join('|')}/, Str::Escape, :pop!
rule %r/o[0-7]+/i, Str::Escape, :pop!
rule %r/x[\da-fA-F]+/i, Str::Escape, :pop!
rule %r/\d+/, Str::Escape, :pop!
rule %r/\s+\\/, Str::Escape, :pop!
end
end
end
end
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class IecST < RegexLexer
tag 'iecst'
title "IEC 61131-3 Structured Text"
desc 'Structured text is a programming language for PLCs (programmable logic controllers).'
filenames '*.awl', '*.scl', '*.st'
mimetypes 'text/x-iecst'
def self.keywords
blocks = %w(
PROGRAM CONFIGURATION INITIAL_STEP INTERFACE FUNCTION_BLOCK FUNCTION ACTION TRANSITION
TYPE STRUCT STEP NAMESPACE LIBRARY CHANNEL FOLDER RESOURCE
VAR_ACCESS VAR_CONFIG VAR_EXTERNAL VAR_GLOBAL VAR_INPUT VAR_IN_OUT VAR_OUTPUT VAR_TEMP VAR
CONST METHOD PROPERTY
CASE FOR IF REPEAT WHILE
)
@keywords ||= Set.new %w(
AT BEGIN BY CONSTANT CONTINUE DO ELSE ELSIF EXIT EXTENDS FROM GET GOTO IMPLEMENTS JMP
NON_RETAIN OF PRIVATE PROTECTED PUBLIC RETAIN RETURN SET TASK THEN TO UNTIL USING WITH
__CATCH __ENDTRY __FINALLY __TRY
) + blocks + blocks.map {|kw| "END_" + kw}
end
def self.types
@types ||= Set.new %w(
ANY ARRAY BOOL BYTE POINTER STRING
DATE DATE_AND_TIME DT TIME TIME_OF_DAY TOD
INT DINT LINT SINT UINT UDINT ULINT USINT
WORD DWORD LWORD
REAL LREAL
)
end
def self.literals
@literals ||= Set.new %w(TRUE FALSE NULL)
end
def self.operators
@operators ||= Set.new %w(AND EQ EXPT GE GT LE LT MOD NE NOT OR XOR)
end
state :whitespace do
# Spaces
rule %r/\s+/m, Text
# // Comments
rule %r((//).*$\n?), Comment::Single
# (* Comments *)
rule %r(\(\*.*?\*\))m, Comment::Multiline
# { Comments }
rule %r(\{.*?\})m, Comment::Special
end
state :root do
mixin :whitespace
rule %r/'[^']+'/, Literal::String::Single
rule %r/"[^"]+"/, Literal::String::Symbol
rule %r/%[IQM][XBWDL][\d.]*|%[IQ][\d.]*/, Name::Variable::Magic
rule %r/\b(?:D|DT|T|TOD)#[\d_shmd:]*/i, Literal::Date
rule %r/\b(?:16#[\d_a-f]+|0x[\d_a-f]+)\b/i, Literal::Number::Hex
rule %r/\b2#[01_]+/, Literal::Number::Bin
rule %r/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i, Literal::Number::Float
rule %r/\b[\d.,_]+/, Literal::Number
rule %r/\b[A-Z_]+\b/i do |m|
name = m[0].upcase
if self.class.keywords.include?(name)
token Keyword
elsif self.class.types.include?(name)
token Keyword::Type
elsif self.class.literals.include?(name)
token Literal
elsif self.class.operators.include?(name)
token Operator
else
token Name
end
end
rule %r/S?R?:?=>?|&&?|\*\*?|<[=>]?|>=?|[-:^\/+#]/, Operator
rule %r/\b[a-z_]\w*(?=\s*\()/i, Name::Function
rule %r/\b[a-z_]\w*\b/i, Name
rule %r/[()\[\].,;]/, Punctuation
end
end
end
end
@@ -0,0 +1,664 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class IgorPro < RegexLexer
tag 'igorpro'
filenames '*.ipf'
mimetypes 'text/x-igorpro'
title "IgorPro"
desc "WaveMetrics Igor Pro"
def self.keywords
@keywords ||= Set.new %w(
structure endstructure
threadsafe static
macro proc window menu function end
if else elseif endif switch strswitch endswitch
break return continue
for endfor do while
case default
try catch endtry
abortonrte
)
end
def self.preprocessor
@preprocessor ||= Set.new %w(
pragma include
define ifdef ifndef undef
if elif else endif
)
end
def self.igorDeclarations
@igorDeclarations ||= Set.new %w(
variable string wave strconstant constant
nvar svar dfref funcref struct
char uchar int16 uint16 int32 uint32 int64 uint64 float double
)
end
def self.igorConstants
@igorConstants ||= Set.new %w(
nan inf
)
end
def self.igorFunction
@igorFunction ||= Set.new %w(
AddListItem AiryA AiryAD AiryB AiryBD AnnotationInfo
AnnotationList AxisInfo AxisList AxisValFromPixel
AxonTelegraphAGetDataNum AxonTelegraphAGetDataString
AxonTelegraphAGetDataStruct AxonTelegraphGetDataNum
AxonTelegraphGetDataString AxonTelegraphGetDataStruct
AxonTelegraphGetTimeoutMs AxonTelegraphSetTimeoutMs
Base64Decode Base64Encode Besseli Besselj Besselk
Bessely BinarySearch BinarySearchInterp CTabList
CaptureHistory CaptureHistoryStart CheckName
ChildWindowList CleanupName ContourInfo ContourNameList
ContourNameToWaveRef ContourZ ControlNameList
ConvertTextEncoding CountObjects CountObjectsDFR
CreationDate CsrInfo CsrWave CsrWaveRef CsrXWave
CsrXWaveRef DataFolderDir DataFolderExists
DataFolderRefStatus DataFolderRefsEqual DateToJulian
Dawson DimDelta DimOffset DimSize Faddeeva FetchURL
FindDimLabel FindListItem FontList FontSizeHeight
FontSizeStringWidth FresnelCos FresnelSin FuncRefInfo
FunctionInfo FunctionList FunctionPath
GISGetAllFileFormats GISSRefsAreEqual Gauss Gauss1D
Gauss2D GetBrowserLine GetBrowserSelection
GetDataFolder GetDataFolderDFR GetDefaultFont
GetDefaultFontSize GetDefaultFontStyle GetDimLabel
GetEnvironmentVariable GetErrMessage GetFormula
GetIndependentModuleName GetIndexedObjName
GetIndexedObjNameDFR GetKeyState GetRTErrMessage
GetRTError GetRTLocInfo GetRTLocation GetRTStackInfo
GetScrapText GetUserData GetWavesDataFolder
GetWavesDataFolderDFR GizmoInfo GizmoScale GrepList
GrepString GuideInfo GuideNameList HDF5AttributeInfo
HDF5DatasetInfo HDF5LibraryInfo HDF5TypeInfo Hash
HyperG0F1 HyperG1F1 HyperG2F1 HyperGNoise HyperGPFQ
IgorInfo IgorVersion ImageInfo ImageNameList
ImageNameToWaveRef IndependentModuleList IndexToScale
IndexedDir IndexedFile Inf Integrate1D Interp2D
Interp3D ItemsInList JacobiCn JacobiSn JulianToDate
Laguerre LaguerreA LaguerreGauss LambertW LayoutInfo
LegendreA ListMatch ListToTextWave ListToWaveRefWave
LowerStr MCC_AutoBridgeBal MCC_AutoFastComp
MCC_AutoPipetteOffset MCC_AutoSlowComp
MCC_AutoWholeCellComp MCC_GetBridgeBalEnable
MCC_GetBridgeBalResist MCC_GetFastCompCap
MCC_GetFastCompTau MCC_GetHolding MCC_GetHoldingEnable
MCC_GetMode MCC_GetNeutralizationCap
MCC_GetNeutralizationEnable MCC_GetOscKillerEnable
MCC_GetPipetteOffset MCC_GetPrimarySignalGain
MCC_GetPrimarySignalHPF MCC_GetPrimarySignalLPF
MCC_GetRsCompBandwidth MCC_GetRsCompCorrection
MCC_GetRsCompEnable MCC_GetRsCompPrediction
MCC_GetSecondarySignalGain MCC_GetSecondarySignalLPF
MCC_GetSlowCompCap MCC_GetSlowCompTau
MCC_GetSlowCompTauX20Enable MCC_GetSlowCurrentInjEnable
MCC_GetSlowCurrentInjLevel
MCC_GetSlowCurrentInjSetlTime MCC_GetWholeCellCompCap
MCC_GetWholeCellCompEnable MCC_GetWholeCellCompResist
MCC_SelectMultiClamp700B MCC_SetBridgeBalEnable
MCC_SetBridgeBalResist MCC_SetFastCompCap
MCC_SetFastCompTau MCC_SetHolding MCC_SetHoldingEnable
MCC_SetMode MCC_SetNeutralizationCap
MCC_SetNeutralizationEnable MCC_SetOscKillerEnable
MCC_SetPipetteOffset MCC_SetPrimarySignalGain
MCC_SetPrimarySignalHPF MCC_SetPrimarySignalLPF
MCC_SetRsCompBandwidth MCC_SetRsCompCorrection
MCC_SetRsCompEnable MCC_SetRsCompPrediction
MCC_SetSecondarySignalGain MCC_SetSecondarySignalLPF
MCC_SetSlowCompCap MCC_SetSlowCompTau
MCC_SetSlowCompTauX20Enable MCC_SetSlowCurrentInjEnable
MCC_SetSlowCurrentInjLevel
MCC_SetSlowCurrentInjSetlTime MCC_SetTimeoutMs
MCC_SetWholeCellCompCap MCC_SetWholeCellCompEnable
MCC_SetWholeCellCompResist MPFXEMGPeak
MPFXExpConvExpPeak MPFXGaussPeak MPFXLorenzianPeak
MPFXVoigtPeak MacroList MandelbrotPoint MarcumQ
MatrixCondition MatrixDet MatrixDot MatrixRank
MatrixTrace ModDate NVAR_Exists NaN NameOfWave
NewFreeDataFolder NewFreeWave NormalizeUnicode
NumVarOrDefault NumberByKey OperationList PICTInfo
PICTList PadString PanelResolution ParamIsDefault
ParseFilePath PathList Pi PixelFromAxisVal PolygonArea
PossiblyQuoteName ProcedureText RemoveByKey
RemoveEnding RemoveFromList RemoveListItem
ReplaceNumberByKey ReplaceString ReplaceStringByKey
SQL2DBinaryWaveToTextWave SQLAllocHandle SQLAllocStmt
SQLBinaryWavesToTextWave SQLBindCol SQLBindParameter
SQLBrowseConnect SQLBulkOperations SQLCancel
SQLCloseCursor SQLColAttributeNum SQLColAttributeStr
SQLColumnPrivileges SQLColumns SQLConnect
SQLDataSources SQLDescribeCol SQLDescribeParam
SQLDisconnect SQLDriverConnect SQLDrivers SQLEndTran
SQLError SQLExecDirect SQLExecute SQLFetch
SQLFetchScroll SQLForeignKeys SQLFreeConnect SQLFreeEnv
SQLFreeHandle SQLFreeStmt SQLGetConnectAttrNum
SQLGetConnectAttrStr SQLGetCursorName SQLGetDataNum
SQLGetDataStr SQLGetDescFieldNum SQLGetDescFieldStr
SQLGetDescRec SQLGetDiagFieldNum SQLGetDiagFieldStr
SQLGetDiagRec SQLGetEnvAttrNum SQLGetEnvAttrStr
SQLGetFunctions SQLGetInfoNum SQLGetInfoStr
SQLGetStmtAttrNum SQLGetStmtAttrStr SQLGetTypeInfo
SQLMoreResults SQLNativeSql SQLNumParams
SQLNumResultCols SQLNumResultRowsIfKnown
SQLNumRowsFetched SQLParamData SQLPrepare
SQLPrimaryKeys SQLProcedureColumns SQLProcedures
SQLPutData SQLReinitialize SQLRowCount
SQLSetConnectAttrNum SQLSetConnectAttrStr
SQLSetCursorName SQLSetDescFieldNum SQLSetDescFieldStr
SQLSetDescRec SQLSetEnvAttrNum SQLSetEnvAttrStr
SQLSetPos SQLSetStmtAttrNum SQLSetStmtAttrStr
SQLSpecialColumns SQLStatistics SQLTablePrivileges
SQLTables SQLTextWaveTo2DBinaryWave
SQLTextWaveToBinaryWaves SQLUpdateBoundValues
SQLXOPCheckState SVAR_Exists ScreenResolution Secs2Date
Secs2Time SelectNumber SelectString
SetEnvironmentVariable SortList SpecialCharacterInfo
SpecialCharacterList SpecialDirPath SphericalBessJ
SphericalBessJD SphericalBessY SphericalBessYD
SphericalHarmonics StartMSTimer StatsBetaCDF
StatsBetaPDF StatsBinomialCDF StatsBinomialPDF
StatsCMSSDCDF StatsCauchyCDF StatsCauchyPDF StatsChiCDF
StatsChiPDF StatsCorrelation StatsDExpCDF StatsDExpPDF
StatsEValueCDF StatsEValuePDF StatsErlangCDF
StatsErlangPDF StatsErrorPDF StatsExpCDF StatsExpPDF
StatsFCDF StatsFPDF StatsFriedmanCDF StatsGEVCDF
StatsGEVPDF StatsGammaCDF StatsGammaPDF
StatsGeometricCDF StatsGeometricPDF StatsHyperGCDF
StatsHyperGPDF StatsInvBetaCDF StatsInvBinomialCDF
StatsInvCMSSDCDF StatsInvCauchyCDF StatsInvChiCDF
StatsInvDExpCDF StatsInvEValueCDF StatsInvExpCDF
StatsInvFCDF StatsInvFriedmanCDF StatsInvGammaCDF
StatsInvGeometricCDF StatsInvKuiperCDF
StatsInvLogNormalCDF StatsInvLogisticCDF
StatsInvMaxwellCDF StatsInvMooreCDF
StatsInvNBinomialCDF StatsInvNCChiCDF StatsInvNCFCDF
StatsInvNormalCDF StatsInvParetoCDF StatsInvPoissonCDF
StatsInvPowerCDF StatsInvQCDF StatsInvQpCDF
StatsInvRayleighCDF StatsInvRectangularCDF
StatsInvSpearmanCDF StatsInvStudentCDF
StatsInvTopDownCDF StatsInvTriangularCDF
StatsInvUsquaredCDF StatsInvVonMisesCDF
StatsInvWeibullCDF StatsKuiperCDF StatsLogNormalCDF
StatsLogNormalPDF StatsLogisticCDF StatsLogisticPDF
StatsMaxwellCDF StatsMaxwellPDF StatsMedian
StatsMooreCDF StatsNBinomialCDF StatsNBinomialPDF
StatsNCChiCDF StatsNCChiPDF StatsNCFCDF StatsNCFPDF
StatsNCTCDF StatsNCTPDF StatsNormalCDF StatsNormalPDF
StatsParetoCDF StatsParetoPDF StatsPermute
StatsPoissonCDF StatsPoissonPDF StatsPowerCDF
StatsPowerNoise StatsPowerPDF StatsQCDF StatsQpCDF
StatsRayleighCDF StatsRayleighPDF StatsRectangularCDF
StatsRectangularPDF StatsRunsCDF StatsSpearmanRhoCDF
StatsStudentCDF StatsStudentPDF StatsTopDownCDF
StatsTriangularCDF StatsTriangularPDF StatsTrimmedMean
StatsUSquaredCDF StatsVonMisesCDF StatsVonMisesNoise
StatsVonMisesPDF StatsWaldCDF StatsWaldPDF
StatsWeibullCDF StatsWeibullPDF StopMSTimer
StrVarOrDefault StringByKey StringFromList StringList
StudentA StudentT TDMAddChannel TDMAddGroup
TDMAppendDataValues TDMAppendDataValuesTime
TDMChannelPropertyExists TDMCloseChannel TDMCloseFile
TDMCloseGroup TDMCreateChannelProperty TDMCreateFile
TDMCreateFileProperty TDMCreateGroupProperty
TDMFilePropertyExists TDMGetChannelPropertyNames
TDMGetChannelPropertyNum TDMGetChannelPropertyStr
TDMGetChannelPropertyTime TDMGetChannelPropertyType
TDMGetChannelStringPropertyLen TDMGetChannels
TDMGetDataType TDMGetDataValues TDMGetDataValuesTime
TDMGetFilePropertyNames TDMGetFilePropertyNum
TDMGetFilePropertyStr TDMGetFilePropertyTime
TDMGetFilePropertyType TDMGetFileStringPropertyLen
TDMGetGroupPropertyNames TDMGetGroupPropertyNum
TDMGetGroupPropertyStr TDMGetGroupPropertyTime
TDMGetGroupPropertyType TDMGetGroupStringPropertyLen
TDMGetGroups TDMGetLibraryErrorDescription
TDMGetNumChannelProperties TDMGetNumChannels
TDMGetNumDataValues TDMGetNumFileProperties
TDMGetNumGroupProperties TDMGetNumGroups
TDMGroupPropertyExists TDMOpenFile TDMOpenFileEx
TDMRemoveChannel TDMRemoveGroup TDMReplaceDataValues
TDMReplaceDataValuesTime TDMSaveFile
TDMSetChannelPropertyNum TDMSetChannelPropertyStr
TDMSetChannelPropertyTime TDMSetDataValues
TDMSetDataValuesTime TDMSetFilePropertyNum
TDMSetFilePropertyStr TDMSetFilePropertyTime
TDMSetGroupPropertyNum TDMSetGroupPropertyStr
TDMSetGroupPropertyTime TableInfo TagVal TagWaveRef
TextEncodingCode TextEncodingName TextFile
ThreadGroupCreate ThreadGroupGetDF ThreadGroupGetDFR
ThreadGroupRelease ThreadGroupWait ThreadProcessorCount
ThreadReturnValue TraceFromPixel TraceInfo
TraceNameList TraceNameToWaveRef TrimString URLDecode
URLEncode UnPadString UniqueName
UnsetEnvironmentVariable UpperStr VariableList Variance
VoigtFunc VoigtPeak WaveCRC WaveDims WaveExists
WaveHash WaveInfo WaveList WaveMax WaveMin WaveName
WaveRefIndexed WaveRefIndexedDFR WaveRefWaveToList
WaveRefsEqual WaveTextEncoding WaveType WaveUnits
WhichListItem WinList WinName WinRecreation WinType
XWaveName XWaveRefFromTrace ZernikeR abs acos acosh
alog area areaXY asin asinh atan atan2 atanh beta betai
binomial binomialNoise binomialln cabs ceil cequal
char2num chebyshev chebyshevU cmplx cmpstr conj cos
cosIntegral cosh cot coth cpowi csc csch date date2secs
datetime defined deltax digamma dilogarithm ei enoise
equalWaves erf erfc erfcw exists exp expInt
expIntegralE1 expNoise fDAQmx_AI_GetReader
fDAQmx_AO_UpdateOutputs fDAQmx_CTR_Finished
fDAQmx_CTR_IsFinished fDAQmx_CTR_IsPulseFinished
fDAQmx_CTR_ReadCounter fDAQmx_CTR_ReadWithOptions
fDAQmx_CTR_SetPulseFrequency fDAQmx_CTR_Start
fDAQmx_ConnectTerminals fDAQmx_DIO_Finished
fDAQmx_DIO_PortWidth fDAQmx_DIO_Read fDAQmx_DIO_Write
fDAQmx_DeviceNames fDAQmx_DisconnectTerminals
fDAQmx_ErrorString fDAQmx_ExternalCalDate
fDAQmx_NumAnalogInputs fDAQmx_NumAnalogOutputs
fDAQmx_NumCounters fDAQmx_NumDIOPorts fDAQmx_ReadChan
fDAQmx_ReadNamedChan fDAQmx_ResetDevice
fDAQmx_ScanGetAvailable fDAQmx_ScanGetNextIndex
fDAQmx_ScanStart fDAQmx_ScanStop fDAQmx_ScanWait
fDAQmx_ScanWaitWithTimeout fDAQmx_SelfCalDate
fDAQmx_SelfCalibration fDAQmx_WF_IsFinished
fDAQmx_WF_WaitUntilFinished fDAQmx_WaveformStart
fDAQmx_WaveformStop fDAQmx_WriteChan factorial fakedata
faverage faverageXY floor gamma gammaEuler gammaInc
gammaNoise gammln gammp gammq gcd gnoise hcsr hermite
hermiteGauss imag interp inverseERF inverseERFC leftx
limit ln log logNormalNoise lorentzianNoise magsqr max
mean median min mod norm note num2char num2istr num2str
numpnts numtype p2rect pcsr pnt2x poissonNoise poly
poly2D qcsr r2polar real rightx round sawtooth
scaleToIndex sec sech sign sin sinIntegral sinc sinh
sqrt str2num stringCRC stringmatch strlen strsearch sum
tan tango_close_device tango_command_inout
tango_compute_image_proj tango_get_dev_attr_list
tango_get_dev_black_box tango_get_dev_cmd_list
tango_get_dev_status tango_get_dev_timeout
tango_get_error_stack tango_open_device
tango_ping_device tango_read_attribute
tango_read_attributes tango_reload_dev_interface
tango_resume_attr_monitor tango_set_attr_monitor_period
tango_set_dev_timeout tango_start_attr_monitor
tango_stop_attr_monitor tango_suspend_attr_monitor
tango_write_attribute tango_write_attributes tanh ticks
time trunc vcsr viAssertIntrSignal viAssertTrigger
viAssertUtilSignal viClear viClose viDisableEvent
viDiscardEvents viEnableEvent viFindNext viFindRsrc
viGetAttribute viGetAttributeString viGpibCommand
viGpibControlATN viGpibControlREN viGpibPassControl
viGpibSendIFC viIn16 viIn32 viIn8 viLock viMapAddress
viMapTrigger viMemAlloc viMemFree viMoveIn16 viMoveIn32
viMoveIn8 viMoveOut16 viMoveOut32 viMoveOut8 viOpen
viOpenDefaultRM viOut16 viOut32 viOut8 viPeek16
viPeek32 viPeek8 viPoke16 viPoke32 viPoke8 viRead
viReadSTB viSetAttribute viSetAttributeString
viStatusDesc viTerminate viUnlock viUnmapAddress
viUnmapTrigger viUsbControlIn viUsbControlOut
viVxiCommandQuery viWaitOnEvent viWrite wnoise x2pnt
xcsr zcsr zeromq_client_connect zeromq_client_connect
zeromq_client_recv zeromq_client_recv
zeromq_client_send zeromq_client_send
zeromq_handler_start zeromq_handler_start
zeromq_handler_stop zeromq_handler_stop
zeromq_server_bind zeromq_server_bind
zeromq_server_recv zeromq_server_recv
zeromq_server_send zeromq_server_send zeromq_set
zeromq_set zeromq_stop zeromq_stop
zeromq_test_callfunction zeromq_test_callfunction
zeromq_test_serializeWave zeromq_test_serializeWave
zeta
)
end
def self.igorOperation
@igorOperation ||= Set.new %w(
APMath Abort AddFIFOData AddFIFOVectData AddMovieAudio
AddMovieFrame AddWavesToBoxPlot AddWavesToViolinPlot
AdoptFiles Append AppendBoxPlot AppendImage
AppendLayoutObject AppendMatrixContour AppendText
AppendToGizmo AppendToGraph AppendToLayout
AppendToTable AppendViolinPlot AppendXYZContour
AutoPositionWindow AxonTelegraphFindServers
BackgroundInfo Beep BoundingBall BoxSmooth BrowseURL
BuildMenu Button CWT Chart CheckBox CheckDisplayed
ChooseColor Close CloseHelp CloseMovie CloseProc
ColorScale ColorTab2Wave Concatenate ControlBar
ControlInfo ControlUpdate
ConvertGlobalStringTextEncoding ConvexHull Convolve
CopyDimLabels CopyFile CopyFolder CopyScales Correlate
CreateAliasShortcut CreateBrowser Cross CtrlBackground
CtrlFIFO CtrlNamedBackground Cursor CurveFit
CustomControl DAQmx_AI_SetupReader DAQmx_AO_SetOutputs
DAQmx_CTR_CountEdges DAQmx_CTR_OutputPulse
DAQmx_CTR_Period DAQmx_CTR_PulseWidth DAQmx_DIO_Config
DAQmx_DIO_WriteNewData DAQmx_Scan DAQmx_WaveformGen
DPSS DSPDetrend DSPPeriodogram DWT Debugger
DebuggerOptions DefaultFont DefaultGuiControls
DefaultGuiFont DefaultTextEncoding DefineGuide
DelayUpdate DeleteAnnotations DeleteFile DeleteFolder
DeletePoints Differentiate Display DisplayHelpTopic
DisplayProcedure DoAlert DoIgorMenu DoUpdate DoWindow
DoXOPIdle DrawAction DrawArc DrawBezier DrawLine
DrawOval DrawPICT DrawPoly DrawRRect DrawRect DrawText
DrawUserShape Duplicate DuplicateDataFolder EdgeStats
Edit ErrorBars EstimatePeakSizes Execute
ExecuteScriptText ExperimentInfo ExperimentModified
ExportGizmo Extract FBinRead FBinWrite FFT FGetPos
FIFO2Wave FIFOStatus FMaxFlat FPClustering FReadLine
FSetPos FStatus FTPCreateDirectory FTPDelete
FTPDownload FTPUpload FastGaussTransform FastOp
FilterFIR FilterIIR FindAPeak FindContour
FindDuplicates FindLevel FindLevels FindPeak
FindPointsInPoly FindRoots FindSequence FindValue
FuncFit FuncFitMD GBLoadWave GISCreateVectorLayer
GISGetRasterInfo GISGetRegisteredFileInfo
GISGetVectorLayerInfo GISLoadRasterData
GISLoadVectorData GISRasterizeVectorData
GISRegisterFile GISTransformCoords GISUnRegisterFile
GISWriteFieldData GISWriteGeometryData GISWriteRaster
GPIB2 GPIBRead2 GPIBReadBinary2 GPIBReadBinaryWave2
GPIBReadWave2 GPIBWrite2 GPIBWriteBinary2
GPIBWriteBinaryWave2 GPIBWriteWave2 GetAxis GetCamera
GetFileFolderInfo GetGizmo GetLastUserMenuInfo
GetMarquee GetMouse GetSelection GetWindow GraphNormal
GraphWaveDraw GraphWaveEdit Grep GroupBox
HDF5CloseFile HDF5CloseGroup HDF5ConvertColors
HDF5CreateFile HDF5CreateGroup HDF5CreateLink HDF5Dump
HDF5DumpErrors HDF5DumpState HDF5FlushFile
HDF5ListAttributes HDF5ListGroup HDF5LoadData
HDF5LoadGroup HDF5LoadImage HDF5OpenFile HDF5OpenGroup
HDF5SaveData HDF5SaveGroup HDF5SaveImage
HDF5TestOperation HDF5UnlinkObject HDFInfo
HDFReadImage HDFReadSDS HDFReadVset Hanning
HideIgorMenus HideInfo HideProcedures HideTools
HilbertTransform Histogram ICA IFFT ITCCloseAll2
ITCCloseDevice2 ITCConfigAllChannels2
ITCConfigChannel2 ITCConfigChannelReset2
ITCConfigChannelUpload2 ITCFIFOAvailable2
ITCFIFOAvailableAll2 ITCGetAllChannelsConfig2
ITCGetChannelConfig2 ITCGetCurrentDevice2
ITCGetDeviceInfo2 ITCGetDevices2 ITCGetErrorString2
ITCGetSerialNumber2 ITCGetState2 ITCGetVersions2
ITCInitialize2 ITCOpenDevice2 ITCReadADC2
ITCReadDigital2 ITCReadTimer2 ITCSelectDevice2
ITCSetDAC2 ITCSetGlobals2 ITCSetModes2 ITCSetState2
ITCStartAcq2 ITCStopAcq2 ITCUpdateFIFOPosition2
ITCUpdateFIFOPositionAll2 ITCWriteDigital2
ImageAnalyzeParticles ImageBlend ImageBoundaryToMask
ImageComposite ImageEdgeDetection ImageFileInfo
ImageFilter ImageFocus ImageFromXYZ ImageGLCM
ImageGenerateROIMask ImageHistModification
ImageHistogram ImageInterpolate ImageLineProfile
ImageLoad ImageMorphology ImageRegistration
ImageRemoveBackground ImageRestore ImageRotate
ImageSave ImageSeedFill ImageSkeleton3d ImageSnake
ImageStats ImageThreshold ImageTransform
ImageUnwrapPhase ImageWindow IndexSort InsertPoints
Integrate Integrate2D IntegrateODE Interp3DPath
Interpolate2 Interpolate3D JCAMPLoadWave
JointHistogram KMeans KillBackground KillControl
KillDataFolder KillFIFO KillFreeAxis KillPICTs
KillPath KillStrings KillVariables KillWaves
KillWindow Label Layout LayoutPageAction
LayoutSlideShow Legend LinearFeedbackShiftRegister
ListBox LoadData LoadPICT LoadPackagePreferences
LoadWave Loess LombPeriodogram MCC_FindServers
MFR_CheckForNewBricklets MFR_CloseResultFile
MFR_CreateOverviewTable MFR_GetBrickletCount
MFR_GetBrickletData MFR_GetBrickletDeployData
MFR_GetBrickletMetaData MFR_GetBrickletRawData
MFR_GetReportTemplate MFR_GetResultFileMetaData
MFR_GetResultFileName MFR_GetVernissageVersion
MFR_GetVersion MFR_GetXOPErrorMessage
MFR_OpenResultFile
MLLoadWave Make MakeIndex MarkPerfTestTime
MatrixConvolve MatrixCorr MatrixEigenV MatrixFilter
MatrixGLM MatrixGaussJ MatrixInverse MatrixLLS
MatrixLUBkSub MatrixLUD MatrixLUDTD MatrixLinearSolve
MatrixLinearSolveTD MatrixMultiply MatrixOP
MatrixSVBkSub MatrixSVD MatrixSchur MatrixSolve
MatrixTranspose MeasureStyledText Modify ModifyBoxPlot
ModifyBrowser ModifyCamera ModifyContour ModifyControl
ModifyControlList ModifyFreeAxis ModifyGizmo
ModifyGraph ModifyImage ModifyLayout ModifyPanel
ModifyTable ModifyViolinPlot ModifyWaterfall
MoveDataFolder MoveFile MoveFolder MoveString
MoveSubwindow MoveVariable MoveWave MoveWindow
MultiTaperPSD MultiThreadingControl NC_CloseFile
NC_DumpErrors NC_Inquire NC_ListAttributes
NC_ListObjects NC_LoadData NC_OpenFile NI4882
NILoadWave NeuralNetworkRun NeuralNetworkTrain
NewCamera NewDataFolder NewFIFO NewFIFOChan
NewFreeAxis NewGizmo NewImage NewLayout NewMovie
NewNotebook NewPanel NewPath NewWaterfall Note
Notebook NotebookAction Open OpenHelp OpenNotebook
Optimize PCA ParseOperationTemplate PathInfo
PauseForUser PauseUpdate PlayMovie PlayMovieAction
PlaySound PopupContextualMenu PopupMenu Preferences
PrimeFactors Print PrintGraphs PrintLayout
PrintNotebook PrintSettings PrintTable Project
PulseStats PutScrapText Quit RatioFromNumber
Redimension Remez Remove RemoveContour RemoveFromGizmo
RemoveFromGraph RemoveFromLayout RemoveFromTable
RemoveImage RemoveLayoutObjects RemovePath Rename
RenameDataFolder RenamePICT RenamePath RenameWindow
ReorderImages ReorderTraces ReplaceText ReplaceWave
Resample ResumeUpdate Reverse Rotate SQLHighLevelOp
STFT Save SaveData SaveExperiment SaveGizmoCopy
SaveGraphCopy SaveNotebook SavePICT
SavePackagePreferences SaveTableCopy
SetActiveSubwindow SetAxis SetBackground
SetDashPattern SetDataFolder SetDimLabel SetDrawEnv
SetDrawLayer SetFileFolderInfo SetFormula
SetIdlePeriod SetIgorHook SetIgorMenuMode
SetIgorOption SetMarquee SetProcessSleep SetRandomSeed
SetScale SetVariable SetWaveLock SetWaveTextEncoding
SetWindow ShowIgorMenus ShowInfo ShowTools Silent
Sleep Slider Smooth SmoothCustom Sort SortColumns
SoundInRecord SoundInSet SoundInStartChart
SoundInStatus SoundInStopChart SoundLoadWave
SoundSaveWave SphericalInterpolate
SphericalTriangulate SplitString SplitWave Stack
StackWindows StatsANOVA1Test StatsANOVA2NRTest
StatsANOVA2RMTest StatsANOVA2Test
StatsAngularDistanceTest StatsChiTest
StatsCircularCorrelationTest StatsCircularMeans
StatsCircularMoments StatsCircularTwoSampleTest
StatsCochranTest StatsContingencyTable StatsDIPTest
StatsDunnettTest StatsFTest StatsFriedmanTest
StatsHodgesAjneTest StatsJBTest StatsKDE StatsKSTest
StatsKWTest StatsKendallTauTest
StatsLinearCorrelationTest StatsLinearRegression
StatsMultiCorrelationTest StatsNPMCTest
StatsNPNominalSRTest StatsQuantiles
StatsRankCorrelationTest StatsResample StatsSRTest
StatsSample StatsScheffeTest StatsShapiroWilkTest
StatsSignTest StatsTTest StatsTukeyTest
StatsVariancesTest StatsWRCorrelationTest
StatsWatsonUSquaredTest StatsWatsonWilliamsTest
StatsWheelerWatsonTest StatsWilcoxonRankTest String
StructFill StructGet StructPut SumDimension SumSeries
TDMLoadData TDMSaveData TabControl Tag TextBox
ThreadGroupPutDF ThreadStart TickWavesFromAxis Tile
TileWindows TitleBox ToCommandLine ToolsGrid
Triangulate3d URLRequest Unwrap VDT2 VDTClosePort2
VDTGetPortList2 VDTGetStatus2 VDTOpenPort2
VDTOperationsPort2 VDTRead2 VDTReadBinary2
VDTReadBinaryWave2 VDTReadHex2 VDTReadHexWave2
VDTReadWave2 VDTTerminalPort2 VDTWrite2
VDTWriteBinary2 VDTWriteBinaryWave2 VDTWriteHex2
VDTWriteHexWave2 VDTWriteWave2 VISAControl VISARead
VISAReadBinary VISAReadBinaryWave VISAReadWave
VISAWrite VISAWriteBinary VISAWriteBinaryWave
VISAWriteWave ValDisplay Variable WaveMeanStdv
WaveStats WaveTransform WignerTransform WindowFunction
XLLoadWave cd dir fprintf printf pwd sprintf sscanf
wfprintf
)
end
def self.object_name
/\b[a-z][a-z0-9_\.]*?\b/i
end
object = self.object_name
noLineBreak = /(?:[ \t]|(?:\\\s*[\r\n]))+/
operator = %r([\#$~!%^&*+=\|?:<>/-])
punctuation = /[{}()\[\],.;]/
number_float= /0x[a-f0-9]+/i
number_hex = /\d+\.\d+(e[\+\-]?\d+)?/
number_int = /[\d]+(?:_\d+)*/
state :root do
rule %r(//), Comment, :comments
rule %r/#{object}/ do |m|
if m[0].downcase =~ /function/
token Keyword::Declaration
push :parse_function
elsif self.class.igorDeclarations.include? m[0].downcase
token Keyword::Declaration
push :parse_variables
elsif self.class.keywords.include? m[0].downcase
token Keyword
elsif self.class.igorConstants.include? m[0].downcase
token Keyword::Constant
elsif self.class.igorFunction.include? m[0].downcase
token Name::Builtin
elsif self.class.igorOperation.include? m[0].downcase
token Keyword::Reserved
push :operationFlags
elsif m[0].downcase =~ /\b(v|s|w)_[a-z]+[a-z0-9]*/
token Name::Constant
else
token Name
end
end
mixin :preprocessor
mixin :waveFlag
mixin :characters
mixin :numbers
mixin :whitespace
end
state :preprocessor do
rule %r((\#)(#{object})) do |m|
if self.class.preprocessor.include? m[2].downcase
token Comment::Preproc
else
token Punctuation, m[1] #i.e. ModuleFunctions
token Name, m[2]
end
end
end
state :assignment do
mixin :whitespace
rule %r/\"/, Literal::String::Double, :string1 #punctuation for string
mixin :string2
rule %r/#{number_float}/, Literal::Number::Float, :pop!
rule %r/#{number_int}/, Literal::Number::Integer, :pop!
rule %r/[\(\[\{][^\)\]\}]+[\)\]\}]/, Generic, :pop!
rule %r/[^\s\/\(]+/, Generic, :pop!
rule(//) { pop! }
end
state :parse_variables do
mixin :whitespace
rule %r/[=]/, Punctuation, :assignment
rule object, Name::Variable
rule %r/[\[\]]/, Punctuation # optional variables in functions
rule %r/[,]/, Punctuation, :parse_variables
rule %r/\)/, Punctuation, :pop! # end of function
rule %r([/][a-z]+)i, Keyword::Pseudo, :parse_variables
rule(//) { pop! }
end
state :parse_function do
rule %r([/][a-z]+)i, Keyword::Pseudo # only one flag
mixin :whitespace
rule object, Name::Function
rule %r/[\(]/, Punctuation, :parse_variables
rule(//) { pop! }
end
state :operationFlags do
rule %r/#{noLineBreak}/, Text
rule %r/[=]/, Punctuation, :assignment
rule %r([/][a-z]+)i, Keyword::Pseudo, :operationFlags
rule %r/(as)(\s*)(#{object})/i do
groups Keyword::Type, Text, Name::Label
end
rule(//) { pop! }
end
# inline variable assignments (i.e. for Make) with strict syntax
state :waveFlag do
rule %r(
(/(?:wave|X|Y))
(\s*)(=)(\s*)
(#{object})
)ix do |m|
token Keyword::Pseudo, m[1]
token Text, m[2]
token Punctuation, m[3]
token Text, m[4]
token Name::Variable, m[5]
end
end
state :characters do
rule %r/\s/, Text
rule %r/#{operator}/, Operator
rule %r/#{punctuation}/, Punctuation
rule %r/\"/, Literal::String::Double, :string1 #punctuation for string
mixin :string2
end
state :numbers do
rule %r/#{number_float}/, Literal::Number::Float
rule %r/#{number_hex}/, Literal::Number::Hex
rule %r/#{number_int}/, Literal::Number::Integer
end
state :whitespace do
rule %r/#{noLineBreak}/, Text
end
state :string1 do
rule %r/%\w\b/, Literal::String::Other
rule %r/\\\\/, Literal::String::Escape
rule %r/\\\"/, Literal::String::Escape
rule %r/\\/, Literal::String::Escape
rule %r/[^"]/, Literal::String
rule %r/\"/, Literal::String::Double, :pop! #punctuation for string
end
state :string2 do
rule %r/\'[^']*\'/, Literal::String::Single
end
state :comments do
rule %r{([/]\s*)([@]\w+\b)}i do
# doxygen comments
groups Comment, Comment::Special
end
rule %r/[^\r\n]/, Comment
rule(//) { pop! }
end
end
end
end
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class INI < RegexLexer
title "INI"
desc 'the INI configuration format'
tag 'ini'
filenames '*.ini', '*.INI', '*.gitconfig', '*.cfg', '.editorconfig', '*.inf'
mimetypes 'text/x-ini', 'text/inf'
identifier = /[\w\-.]+/
state :basic do
rule %r/\s+/, Text::Whitespace
rule %r/[;#].*?\n/, Comment
rule %r/\\\n/, Str::Escape
end
state :root do
mixin :basic
rule %r/(#{identifier})(\s*)(=)/ do
groups Name::Property, Text::Whitespace, Punctuation
push :value
end
rule %r/\[.*?\]/, Name::Namespace
# standalone option, supported by some INI parsers
rule %r/(.+?)/, Name::Attribute
end
state :value do
rule %r/\n/, Text, :pop!
mixin :basic
rule %r/"/, Str, :dq
rule %r/'.*?'/, Str
mixin :esc_str
rule %r/[^\\\n]+/, Str
end
state :dq do
rule %r/"/, Str, :pop!
mixin :esc_str
rule %r/[^\\"]+/m, Str
end
state :esc_str do
rule %r/\\./m, Str::Escape
end
end
end
end
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class IO < RegexLexer
tag 'io'
title "Io"
desc 'The IO programming language (http://iolanguage.com)'
mimetypes 'text/x-iosrc'
filenames '*.io'
def self.detect?(text)
return true if text.shebang? 'io'
end
def self.constants
@constants ||= Set.new %w(nil false true)
end
def self.builtins
@builtins ||= Set.new %w(
args call clone do doFile doString else elseif for if list
method return super then
)
end
state :root do
rule %r/\s+/m, Text
rule %r(//.*), Comment::Single
rule %r(#.*), Comment::Single
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
rule %r(/[+]), Comment::Multiline, :nested_comment
rule %r/"(\\\\|\\"|[^"])*"/, Str
rule %r(:?:=), Keyword
rule %r/[()]/, Punctuation
rule %r([-=;,*+><!/|^.%&\[\]{}]), Operator
rule %r/[A-Z]\w*/, Name::Class
rule %r/[a-z_]\w*/ do |m|
name = m[0]
if self.class.constants.include? name
token Keyword::Constant
elsif self.class.builtins.include? name
token Name::Builtin
else
token Name
end
end
rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
rule %r/\d+/, Num::Integer
rule %r/@@?/, Keyword
end
state :nested_comment do
rule %r([^/+]+)m, Comment::Multiline
rule %r(/[+]), Comment::Multiline, :nested_comment
rule %r([+]/), Comment::Multiline, :pop!
end
end
end
end
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
load_lexer 'console.rb'
class IRBLexer < ConsoleLexer
tag 'irb'
aliases 'pry'
desc 'Shell sessions in IRB or Pry'
# unlike the superclass, we do not accept any options
@option_docs = {}
def output_lexer
@output_lexer ||= IRBOutputLexer.new(@options)
end
def lang_lexer
@lang_lexer ||= Ruby.new(@options)
end
def prompt_regex
%r(
^.*?
(
(irb|pry).*?[>"*] |
[>"*]>
)
)x
end
def allow_comments?
true
end
end
load_lexer 'ruby.rb'
class IRBOutputLexer < Ruby
tag 'irb_output'
start do
push :stdout
end
state :has_irb_output do
rule %r(=>), Punctuation, :pop!
rule %r/.+?(\n|$)/, Generic::Output
end
state :irb_error do
rule %r/.+?(\n|$)/, Generic::Error
mixin :has_irb_output
end
state :stdout do
rule %r/\w+?(Error|Exception):.+?(\n|$)/, Generic::Error, :irb_error
mixin :has_irb_output
end
prepend :root do
rule %r/#</, Keyword::Type, :irb_object
end
state :irb_object do
rule %r/>/, Keyword::Type, :pop!
mixin :root
end
end
end
end
@@ -0,0 +1,251 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
# Lexer adapted from https://github.com/pygments/pygments/blob/ad55974ce83b85dbb333ab57764415ab84169461/pygments/lexers/theorem.py
module Rouge
module Lexers
class Isabelle < RegexLexer
title "Isabelle"
desc 'Isabelle theories (isabelle.in.tum.de)'
tag 'isabelle'
aliases 'isa', 'Isabelle'
filenames '*.thy'
mimetypes 'text/x-isabelle'
def self.keyword_minor
@keyword_minor ||= Set.new %w(
and assumes attach avoids binder checking
class_instance class_relation code_module congs
constant constrains datatypes defines file fixes
for functions hints identifier if imports in
includes infix infixl infixr is keywords lazy
module_name monos morphisms no_discs_sels notes
obtains open output overloaded parametric permissive
pervasive rep_compat shows structure type_class
type_constructor unchecked unsafe where
)
end
def self.keyword_diag
@keyword_diag ||= Set.new %w(
ML_command ML_val class_deps code_deps code_thms
display_drafts find_consts find_theorems find_unused_assms
full_prf help locale_deps nitpick pr prf
print_abbrevs print_antiquotations print_attributes
print_binds print_bnfs print_bundles
print_case_translations print_cases print_claset
print_classes print_codeproc print_codesetup
print_coercions print_commands print_context
print_defn_rules print_dependencies print_facts
print_induct_rules print_inductives print_interps
print_locale print_locales print_methods print_options
print_orders print_quot_maps print_quotconsts
print_quotients print_quotientsQ3 print_quotmapsQ3
print_rules print_simpset print_state print_statement
print_syntax print_theorems print_theory print_trans_rules
prop pwd quickcheck refute sledgehammer smt_status
solve_direct spark_status term thm thm_deps thy_deps
try try0 typ unused_thms value values welcome
print_ML_antiquotations print_term_bindings values_prolog
)
end
def self.keyword_thy
@keyword_thy ||= Set.new %w(theory begin end)
end
def self.keyword_section
@keyword_section ||= Set.new %w(header chapter)
end
def self.keyword_subsection
@keyword_subsection ||= Set.new %w(section subsection subsubsection sect subsect subsubsect)
end
def self.keyword_theory_decl
@keyword_theory_decl ||= Set.new %w(
ML ML_file abbreviation adhoc_overloading arities
atom_decl attribute_setup axiomatization bundle
case_of_simps class classes classrel codatatype
code_abort code_class code_const code_datatype
code_identifier code_include code_instance code_modulename
code_monad code_printing code_reflect code_reserved
code_type coinductive coinductive_set consts context
datatype datatype_new datatype_new_compat declaration
declare default_sort defer_recdef definition defs
domain domain_isomorphism domaindef equivariance
export_code extract extract_type fixrec fun
fun_cases hide_class hide_const hide_fact hide_type
import_const_map import_file import_tptp import_type_map
inductive inductive_set instantiation judgment lemmas
lifting_forget lifting_update local_setup locale
method_setup nitpick_params no_adhoc_overloading
no_notation no_syntax no_translations no_type_notation
nominal_datatype nonterminal notation notepad oracle
overloading parse_ast_translation parse_translation
partial_function primcorec primrec primrec_new
print_ast_translation print_translation quickcheck_generator
quickcheck_params realizability realizers recdef record
refute_params setup setup_lifting simproc_setup
simps_of_case sledgehammer_params spark_end spark_open
spark_open_siv spark_open_vcg spark_proof_functions
spark_types statespace syntax syntax_declaration text
text_raw theorems translations type_notation
type_synonym typed_print_translation typedecl hoarestate
install_C_file install_C_types wpc_setup c_defs c_types
memsafe SML_export SML_file SML_import approximate
bnf_axiomatization cartouche datatype_compat
free_constructors functor nominal_function
nominal_termination permanent_interpretation
binds defining smt2_status term_cartouche
boogie_file text_cartouche
)
end
def self.keyword_theory_script
@keyword_theory_script ||= Set.new %w(inductive_cases inductive_simps)
end
def self.keyword_theory_goal
@keyword_theory_goal ||= Set.new %w(
ax_specification bnf code_pred corollary cpodef
crunch crunch_ignore
enriched_type function instance interpretation lemma
lift_definition nominal_inductive nominal_inductive2
nominal_primrec pcpodef primcorecursive
quotient_definition quotient_type recdef_tc rep_datatype
schematic_corollary schematic_lemma schematic_theorem
spark_vc specification subclass sublocale termination
theorem typedef wrap_free_constructors
)
end
def self.keyword_qed
@keyword_qed ||= Set.new %w(by done qed)
end
def self.keyword_abandon_proof
@keyword_abandon_proof ||= Set.new %w(sorry oops)
end
def self.keyword_proof_goal
@keyword_proof_goal ||= Set.new %w(have hence interpret)
end
def self.keyword_proof_block
@keyword_proof_block ||= Set.new %w(next proof)
end
def self.keyword_proof_chain
@keyword_proof_chain ||= Set.new %w(finally from then ultimately with)
end
def self.keyword_proof_decl
@keyword_proof_decl ||= Set.new %w(
ML_prf also include including let moreover note
txt txt_raw unfolding using write
)
end
def self.keyword_proof_asm
@keyword_proof_asm ||= Set.new %w(assume case def fix presume)
end
def self.keyword_proof_asm_goal
@keyword_proof_asm_goal ||= Set.new %w(guess obtain show thus)
end
def self.keyword_proof_script
@keyword_proof_script ||= Set.new %w(apply apply_end apply_trace back defer prefer)
end
state :root do
rule %r/\s+/, Text::Whitespace
rule %r/\(\*/, Comment, :comment
rule %r/\{\*|‹/, Text, :text
rule %r/::|\[|\]|-|[:()_=,|+!?]/, Operator
rule %r/[{}.]|\.\./, Operator::Word
def word(keywords)
return %r/\b(#{keywords.join('|')})\b/
end
rule %r/[a-zA-Z]\w*/ do |m|
sym = m[0]
if self.class.keyword_minor.include?(sym) ||
self.class.keyword_proof_script.include?(sym)
token Keyword::Pseudo
elsif self.class.keyword_diag.include?(sym)
token Keyword::Type
elsif self.class.keyword_thy.include?(sym) ||
self.class.keyword_theory_decl.include?(sym) ||
self.class.keyword_qed.include?(sym) ||
self.class.keyword_proof_goal.include?(sym) ||
self.class.keyword_proof_block.include?(sym) ||
self.class.keyword_proof_decl.include?(sym) ||
self.class.keyword_proof_chain.include?(sym) ||
self.class.keyword_proof_asm.include?(sym) ||
self.class.keyword_proof_asm_goal.include?(sym)
token Keyword
elsif self.class.keyword_section.include?(sym)
token Generic::Heading
elsif self.class.keyword_subsection.include?(sym)
token Generic::Subheading
elsif self.class.keyword_theory_goal.include?(sym) ||
self.class.keyword_theory_script.include?(sym)
token Keyword::Namespace
elsif self.class.keyword_abandon_proof.include?(sym)
token Generic::Error
else
token Name
end
end
rule %r/\\<\w*>/, Str::Symbol
rule %r/'[^\W\d][.\w']*/, Name::Variable
rule %r/0[xX][\da-fA-F][\da-fA-F_]*/, Num::Hex
rule %r/0[oO][0-7][0-7_]*/, Num::Oct
rule %r/0[bB][01][01_]*/, Num::Bin
rule %r/"/, Str, :string
rule %r/`/, Str::Other, :fact
# Everything except for (most) operators whitespaces may be name
rule %r/[^\s:|\[\]\-()=,+!?{}._][^\s:|\[\]\-()=,+!?{}]*/, Name
end
state :comment do
rule %r/[^(*)]+/, Comment
rule %r/\(\*/, Comment, :comment
rule %r/\*\)/, Comment, :pop!
rule %r/[(*)]/, Comment
end
state :text do
rule %r/[^{*}‹›]+/, Text
rule %r/\{\*|‹/, Text, :text
rule %r/\*\}|›/, Text, :pop!
rule %r/[{*}]/, Text
end
state :string do
rule %r/[^"\\]+/, Str
rule %r/\\<\w*>/, Str::Symbol
rule %r/\\"/, Str
rule %r/\\/, Str
rule %r/"/, Str, :pop!
end
state :fact do
rule %r/[^`\\]+/, Str::Other
rule %r/\\<\w*>/, Str::Symbol
rule %r/\\`/, Str::Other
rule %r/\\/, Str::Other
rule %r/`/, Str::Other, :pop!
end
end
end
end
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class ISBL < RegexLexer
title "ISBL"
desc "The ISBL programming language"
tag 'isbl'
filenames '*.isbl'
def self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'isbl/builtins.rb')
self.builtins
end
def self.constants
@constants ||= self.builtins["const"].merge(self.builtins["enum"]).collect!(&:downcase)
end
def self.interfaces
@interfaces ||= self.builtins["interface"].collect!(&:downcase)
end
def self.globals
@globals ||= self.builtins["global"].collect!(&:downcase)
end
def self.keywords
@keywords = Set.new %w(
and и else иначе endexcept endfinally endforeach конецвсе endif конецесли endwhile
конецпока except exitfor finally foreach все if если in в not не or или try while пока
)
end
state :whitespace do
rule %r/\s+/m, Text
rule %r(//.*?$), Comment::Single
rule %r(/[*].*?[*]/)m, Comment::Multiline
end
state :dotted do
mixin :whitespace
rule %r/[a-zа-яё_0-9]+/i do |m|
name = m[0]
if self.class.constants.include? name.downcase
token Name::Builtin
elsif in_state? :type
token Keyword::Type
else
token Name
end
pop!
end
end
state :type do
mixin :whitespace
rule %r/[a-zа-яё_0-9]+/i do |m|
name = m[0]
if self.class.interfaces.include? name.downcase
token Keyword::Type
else
token Name
end
pop!
end
rule %r/[.]/, Punctuation, :dotted
rule(//) { pop! }
end
state :root do
mixin :whitespace
rule %r/[:]/, Punctuation, :type
rule %r/[.]/, Punctuation, :dotted
rule %r/[\[\]();]/, Punctuation
rule %r([&*+=<>/-]), Operator
rule %r/\b[a-zа-яё_][a-zа-яё_0-9]*(?=[(])/i, Name::Function
rule %r/[a-zа-яё_!][a-zа-яё_0-9]*/i do |m|
name = m[0]
if self.class.keywords.include? name.downcase
token Keyword
elsif self.class.constants.include? name.downcase
token Name::Builtin
elsif self.class.globals.include? name.downcase
token Name::Variable::Global
else
token Name::Variable
end
end
rule %r/\b(\d+(\.\d+)?)\b/, Literal::Number
rule %r(["].*?["])m, Literal::String::Double
rule %r(['].*?['])m, Literal::String::Single
end
end
end
end
File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More