rouge-lexers-wenyan 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94de9e72802c096c9dda17b9807a9d6bb8b6c916e4b80c7ef1cb0a19b7b799ca
4
+ data.tar.gz: b60f8c1e89b6d8f90b1a5774d9d0cf540e32ab767d226818bde4a9f5e4e118cd
5
+ SHA512:
6
+ metadata.gz: 0b49612af0f71dc708e5ae4590f58d76188caf3604983f2d729f0d7ab9f0dc05299c55b29e03a2bf494e0ac76200c669221d85d6f5a0439ee072e53c6c65c546
7
+ data.tar.gz: cad18f6e9c1af6e11292f06e697c810432a5441d6b1f5c7cb8f39117fa5b67e47f27b2cdfc67ab83fd91af3be5e0680163fd9bb5cad57253ed053cbe217de7ef
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 DGCK81LNN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ 為是三遍。
2
+ 吾有一言。曰「「問天地好在」」。書之。
3
+ 云云。
@@ -0,0 +1,222 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Wenyan < RegexLexer
6
+ title 'Wenyan'
7
+ desc 'Programming language for the ancient Chinese (wy-lang.org)'
8
+ tag 'wenyan'
9
+ aliases 'wy', '文言'
10
+ filenames '*.wy', '*.文言', '*.經', '*.篇', '*.章', '*.書'
11
+
12
+ private
13
+ def comment_or(token)
14
+ if in_state?(:comment_start) || in_state?(:comment_string) then Comment
15
+ else token
16
+ end
17
+ end
18
+
19
+ id_regex = Javascript.id_regex
20
+
21
+ state :root do
22
+ mixin :whitespace
23
+ mixin :simple_literals
24
+ mixin :keywords
25
+ mixin :string
26
+ mixin :identifier
27
+
28
+ # unrecognized, may be macros
29
+ rule %r/./, Text
30
+ end
31
+
32
+ state :whitespace do # mixin
33
+ rule %r/\s+/, Text::Whitespace
34
+ rule %r/[。、]/ do
35
+ token comment_or(Punctuation)
36
+ end
37
+ end
38
+
39
+ state :simple_literals do # mixin
40
+ rule %r/[零一二三四五六七八九十百千萬億兆京垓秭穣穰溝澗正載極又分釐毫絲忽微纖沙塵埃渺漠〇]+/, \
41
+ Literal::Number
42
+ rule %r/[陰陽]/, Literal
43
+ end
44
+
45
+ state :keywords do # mixin
46
+ # special handling for some keywords
47
+ rule %r/([吾今]有)(\s*)(一)(\s*)(術)/ do
48
+ groups Keyword, Text, Literal::Number, Text, Keyword::Type
49
+ push do
50
+ mixin :whitespace
51
+ rule %r/(名之曰)(\s*)(「)(\s*)(#{id_regex})(\s*)(」)/ do
52
+ groups Keyword, Text, Punctuation, Text, Name::Function, Text, \
53
+ Punctuation
54
+ end
55
+ rule %r//, Text, :pop!
56
+ end
57
+ end
58
+ rule %r/(是謂)(\s*)(「)(\s*)(#{id_regex})(\s*)(」)(\s*)(之術也)/ do
59
+ groups Keyword, Text, Punctuation, Text, Name::Function, Text,\
60
+ Punctuation, Text, Keyword
61
+ end
62
+ rule %r/(施|以施)(\s*)(「)(\s*)(#{id_regex})(\s*)(」)/ do
63
+ groups Keyword, Text, Punctuation, Text, Name::Function, Text, \
64
+ Punctuation
65
+ end
66
+ mixin :macro_definition
67
+ rule %r/[注疏批]曰/, Comment, :comment_start
68
+
69
+ # other keywords and operators
70
+ keywords1 = %w[ 若 也 遍 凡 豈 ]
71
+ keywords2 = %w[ 云云 若非 或若 為是 乃止 乃得 之書 方悟 之義 嗚呼 之禍 ]
72
+ keywords3 = %w[ 恆為是 是術曰 必先得 乃得矣 吾嘗觀 之禍歟 乃作罷 ]
73
+ keywords4 = %w[ 若其然者 乃止是遍 乃歸空無 姑妄行此 如事不諧 ]
74
+ keywords5 = %w[ 若其不然者 不知何禍歟 ]
75
+ declare1 = %w[ 夫 曰 有 今 噫 ]
76
+ declare2 = %w[ 吾有 今有 物之 是謂 ]
77
+ declare3 = %w[ 名之曰 之術也 之物也 ]
78
+ declare4 = %w[ 欲行是術 其物如是 ]
79
+ declare5 = %w[ 乃行是術曰 ]
80
+ types = %w[ 數 言 爻 列 術 物 元 ]
81
+ operators1 = %w[ 以 於 加 減 乘 除 變 充 銜 之 施 取 ]
82
+ operators2 = %w[ 書之 昔之 是矣 等於 大於 小於 之長 中之 ]
83
+ operators3 = %w[ 不等於 不大於 不小於 之其餘 ]
84
+ operators4 = %w[ 所餘幾何 中有陽乎 中無陰乎 ]
85
+ # (we have to use these regexps because whitespace is, apparently,
86
+ # optional in wenyan-lang)
87
+ rule Regexp.new(keywords5.join('|')), Keyword
88
+ rule Regexp.new(declare5.join('|')), Keyword::Declaration
89
+ rule Regexp.new(keywords4.join('|')), Keyword
90
+ rule Regexp.new(declare4.join('|')), Keyword::Declaration
91
+ rule Regexp.new(operators4.join('|')), Operator::Word
92
+ rule Regexp.new(keywords3.join('|')), Keyword
93
+ rule Regexp.new(declare3.join('|')), Keyword::Declaration
94
+ rule Regexp.new(operators3.join('|')), Operator::Word
95
+ rule Regexp.new(keywords2.join('|')), Keyword
96
+ rule Regexp.new(declare2.join('|')), Keyword::Declaration
97
+ rule Regexp.new(operators2.join('|')), Operator::Word
98
+ rule Regexp.new(keywords1.join('|')), Keyword
99
+ rule Regexp.new(declare1.join('|')), Keyword::Declaration
100
+ rule Regexp.new(types.join('|')), Keyword::Type
101
+ rule Regexp.new(operators1.join('|')), Operator::Word
102
+ rule %r/其/, Keyword::Constant
103
+ rule %r/者/, Keyword::Pseudo
104
+ end
105
+
106
+ state :identifier do # mixin
107
+ rule %r/(「)(\s*)(#{id_regex})(\s*)(」)/ do
108
+ groups Punctuation, Text, Name::Variable, Text, Punctuation
109
+ end
110
+ rule %r/「/ do
111
+ token Punctuation
112
+ # not actually an identifier, use Javascript lexer to lex it
113
+ @javascript ||= Javascript.new
114
+ @javascript.reset!
115
+ @javascript.push(:expr_start)
116
+ push do
117
+ rule %r/[^」]+/ do
118
+ delegate @javascript
119
+ end
120
+ rule %r/」/, Punctuation, :pop!
121
+ end
122
+ end
123
+ end
124
+
125
+ state :macro_definition do # mixin
126
+ rule %r/或云|蓋謂/ do
127
+ token Keyword
128
+ push do
129
+ rule %r/「「|『/ do
130
+ token Str
131
+ push :macro_definition_content
132
+ push :macro_definition_content
133
+ end
134
+ rule %r//, Text, :pop!
135
+ end
136
+ end
137
+ end
138
+
139
+ state :macro_definition_content do
140
+ rule %r/[^『』「」]+/, Str
141
+ rule %r/「[甲乙丙丁戊己庚辛壬癸]」/, Str::Escape
142
+ rule %r/「/, Str, :macro_definition_content
143
+ rule %r/」/, Str, :pop!
144
+ rule %r/『/ do
145
+ token Str
146
+ push :macro_definition_content
147
+ push :macro_definition_content
148
+ end
149
+ rule %r/』/ do
150
+ pop!
151
+ if state?(:macro_definition_content)
152
+ pop!
153
+ token Str
154
+ else
155
+ token Error
156
+ end
157
+ end
158
+ rule %r/./m, Str
159
+ end
160
+
161
+ state :comment_start do
162
+ mixin :whitespace
163
+ rule %r/「「|『/ do
164
+ token Comment
165
+ goto :comment_string
166
+ push :string_content
167
+ end
168
+
169
+ # Strictly speaking, comments without quotation marks is not valid
170
+ # syntax, and therefore the behavior is undefined (and in fact very
171
+ # confusing in the actual compiler); but for the purpose of this lexer
172
+ # we'll just pretend they are single line comments. Which they are not.
173
+ rule %r/.*?$/, Comment, :pop!
174
+ end
175
+
176
+ state :comment_string do
177
+ rule %r//, Text, :pop!
178
+ end
179
+
180
+ state :string do # mixin
181
+ rule %r/「「|『/ do
182
+ token comment_or(Str)
183
+ push :string_content
184
+ end
185
+ end
186
+
187
+ state :string_content do
188
+ rule %r/[^『』「」]+/ do
189
+ token comment_or(Str)
190
+ end
191
+ rule %r/「「|『/ do
192
+ token comment_or(Str::Escape)
193
+ push :string_nested
194
+ end
195
+ rule %r/」{2,3}|』/ do
196
+ token comment_or(Str)
197
+ pop!
198
+ end
199
+ rule %r/./m do
200
+ token comment_or(Str)
201
+ end
202
+ end
203
+
204
+ state :string_nested do
205
+ rule %r/[^『』「」]+/ do
206
+ token comment_or(Str)
207
+ end
208
+ rule %r/「「|『/ do
209
+ token comment_or(Str::Escape)
210
+ push :string_nested
211
+ end
212
+ rule %r/」」|』/ do
213
+ token comment_or(Str::Escape)
214
+ pop!
215
+ end
216
+ rule %r/./m do
217
+ token comment_or(Str)
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
@@ -0,0 +1 @@
1
+ require_relative "rouge/lexers/wenyan"
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rouge-lexers-wenyan"
3
+ s.version = "1.4.1"
4
+ s.summary =
5
+ "Rouge lexer for Wenyan, programming language for the ancient Chinese"
6
+ s.description = <<~END
7
+ == Rouge::Lexers::Wenyan
8
+ {Rouge}[https://github.com/rouge-ruby/rouge] lexer for
9
+ {Wenyan}[https://wy-lang.org/], programming language for the ancient Chinese.
10
+ END
11
+ s.authors = ["DGCK81LNN"]
12
+ s.email = "triluolnn@163.com"
13
+ s.files = Dir[
14
+ "Gemfile",
15
+ "LICENSE",
16
+ "rouge-lexers-wenyan.gemspec",
17
+ "lib/**/*",
18
+ ]
19
+ s.homepage = "https://github.com/DGCK81LNN/rouge-lexers-wenyan"
20
+ s.license = "MIT"
21
+ s.metadata = {
22
+ "bug_tracker_uri" => "https://github.com/DGCK81LNN/rouge-lexers-wenyan/issues",
23
+ "source_code_uri" => "https://github.com/DGCK81LNN/rouge-lexers-wenyan",
24
+ }
25
+
26
+ s.add_runtime_dependency "rouge", ">=3.0", "<5.0"
27
+ s.add_development_dependency "rake", "~>13.0"
28
+ s.add_development_dependency "minitest", "~>5.16"
29
+ s.add_development_dependency "minitest-power_assert", "~>0.3"
30
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rouge-lexers-wenyan
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
+ platform: ruby
6
+ authors:
7
+ - DGCK81LNN
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rouge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '13.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest-power_assert
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.3'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.3'
75
+ description: |
76
+ == Rouge::Lexers::Wenyan
77
+ {Rouge}[https://github.com/rouge-ruby/rouge] lexer for
78
+ {Wenyan}[https://wy-lang.org/], programming language for the ancient Chinese.
79
+ email: triluolnn@163.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - Gemfile
85
+ - LICENSE
86
+ - lib/rouge-lexers-wenyan.rb
87
+ - lib/rouge/demos/wenyan
88
+ - lib/rouge/lexers/wenyan.rb
89
+ - rouge-lexers-wenyan.gemspec
90
+ homepage: https://github.com/DGCK81LNN/rouge-lexers-wenyan
91
+ licenses:
92
+ - MIT
93
+ metadata:
94
+ bug_tracker_uri: https://github.com/DGCK81LNN/rouge-lexers-wenyan/issues
95
+ source_code_uri: https://github.com/DGCK81LNN/rouge-lexers-wenyan
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.3.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Rouge lexer for Wenyan, programming language for the ancient Chinese
115
+ test_files: []