This is an automated email from the ASF dual-hosted git repository.
kpumuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/thrift-website.git
The following commit(s) were added to refs/heads/main by this push:
new ec4cf9d Added Thrift lexer
ec4cf9d is described below
commit ec4cf9dea0adca4033254b31d3c4cd0792cf12d2
Author: Dmytro Shteflyuk <[email protected]>
AuthorDate: Sat Apr 18 10:53:11 2026 -0400
Added Thrift lexer
---
_plugins/thrift.rb | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++
index.md | 2 +-
2 files changed, 124 insertions(+), 1 deletion(-)
diff --git a/_plugins/thrift.rb b/_plugins/thrift.rb
new file mode 100644
index 0000000..37a0c51
--- /dev/null
+++ b/_plugins/thrift.rb
@@ -0,0 +1,123 @@
+require 'rouge'
+require 'set'
+
+module Rouge
+ module Lexers
+ class Thrift < RegexLexer
+ desc 'Apache Thrift (https://thrift.apache.org/)'
+ tag 'thrift'
+ filenames '*.thrift'
+
+ mimetypes 'text/x-thrift', 'application/x-thrift'
+
+ def self.declarations
+ @declarations ||= Set.new %w(
+ include cpp_include namespace
+ const enum typedef struct union exception service
+ php_namespace xsd_namespace
+ )
+ end
+
+ def self.keywords
+ @keywords ||= Set.new %w(
+ smalltalk.category smalltalk.prefix
+
+ extends oneway throws
+ senum xsd_all
+ )
+ end
+
+ def self.keywords_type
+ @keywords_type ||= Set.new %w(
+ c_glib cocoa cpp csharp delphi go haxe java js lua
+ netstd perl php py py.twisted rb st xsd
+
+ required optional void
+ xsd_optional xsd_nillable xsd_attrs
+ python.immutable
+
+ )
+ end
+
+ def self.builtins
+ @builtins ||= Set.new %w(
+ bool byte i8 i16 i32 i64 double string binary uuid slist map set
+ list cpp_type
+ )
+ end
+
+ # Literal
+ # [37] Literal ::= ('"' [^"]* '"') | ("'" [^']* "'")
+ #
+ # Identifier
+ # [38] Identifier ::= ( Letter | '_' ) ( Letter | Digit | '.' |
'_' )*
+ # [39] STIdentifier ::= ( Letter | '_' ) ( Letter | Digit | '.' |
'_' | '-' )*
+ #
+ # List Separator
+ # [40] ListSeparator ::= ',' | ';'
+ #
+ # Letters and Digits
+ # [41] Letter ::= ['A'-'Z'] | ['a'-'z']
+ # [42] Digit ::= ['0'-'9']
+
+
+
+
+
+ # [32] ConstValue ::= IntConstant | DoubleConstant | Literal |
Identifier | ConstList | ConstMap
+ #
+ # [33] IntConstant ::= ('+' | '-')? Digit+
+ #
+ # [34] DoubleConstant ::= ('+' | '-')? Digit* ('.' Digit+)? ( ('E' |
'e') IntConstant )?
+ #
+ # [35] ConstList ::= '[' (ConstValue ListSeparator?)* ']'
+ #
+ # [36] ConstMap ::= '{' (ConstValue ':' ConstValue
ListSeparator?)* '}'
+ #
+ double = /[+-]?(?:(?:\d+\.\d+|\.\d+)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)/
+ name = /[a-z_][a-z0-9_.]*/i
+ st_identifier = /[a-z_][a-z0-9_.-]*/i
+
+ state :comment do
+ rule /[^*]+/, Comment
+ rule %r([*]/), Comment, :pop!
+ rule /[*]+/, Comment
+ end
+
+ state :comments_and_whitespace do
+ rule %r(/[*]), Comment, :comment
+ rule %r(//.*$), Comment
+ rule %r(#.*$), Comment
+ rule /\s+/, Text
+ end
+
+ state :root do
+ mixin :comments_and_whitespace
+
+ rule /(smalltalk\.(?:category|prefix))(\s+)(#{st_identifier})/ do
+ groups Keyword, Text, Name
+ end
+
+ rule name do |m|
+ if self.class.keywords.include?(m[0])
+ token Keyword
+ elsif self.class.keywords_type.include?(m[0])
+ token Keyword::Type
+ elsif self.class.declarations.include?(m[0])
+ token Keyword::Declaration
+ elsif self.class.builtins.include?(m[0])
+ token Name::Builtin
+ else
+ token Name
+ end
+ end
+
+ rule /[()\[\]{};:=,<>*]/, Punctuation
+ rule /'.*?'/, Str
+ rule /".*?"/, Str
+ rule double, Num::Float
+ rule /[+-]?\d+/, Num::Integer
+ end
+ end
+ end
+end
diff --git a/index.md b/index.md
index baec2d6..07149fc 100644
--- a/index.md
+++ b/index.md
@@ -77,7 +77,7 @@ title: Home
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1">
- {% remote_snippet tutorial/tutorial.thrift text 123,150 %}
+ {% remote_snippet tutorial/tutorial.thrift thrift 123,150 %}
</div>
<div class="tab-pane" id="2">
{% remote_snippet tutorial/py/PythonClient.py py 35,55 %}