rouge 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func main() {
6
+ fmt.Println("Hello, 世界")
7
+ }
@@ -61,6 +61,7 @@ module Rouge
61
61
  end
62
62
 
63
63
  identifier = %r([\w!$%*+,<=>?/.-]+)
64
+ keyword = %r([\w!\#$%*+,<=>?/.-]+)
64
65
 
65
66
  def name_token(name)
66
67
  return 'Keyword' if self.class.keywords.include?(name)
@@ -77,10 +78,10 @@ module Rouge
77
78
  rule /0x-?[0-9a-fA-F]+/, 'Literal.Number.Hex'
78
79
 
79
80
  rule /"(\\.|[^"])*"/, 'Literal.String'
80
- rule /'#{identifier}/, 'Literal.String.Symbol'
81
+ rule /'#{keyword}/, 'Literal.String.Symbol'
82
+ rule /:#{keyword}/, 'Name.Constant'
81
83
  rule /\\(.|[a-z]+)/i, 'Literal.String.Char'
82
84
 
83
- rule /:#{identifier}/, 'Name.Constant'
84
85
 
85
86
  rule /~@|[`\'#^~&]/, 'Operator'
86
87
 
@@ -0,0 +1,175 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Go < RegexLexer
4
+ desc 'The Go programming language (http://golang.org)'
5
+ tag 'go'
6
+ aliases 'go', 'golang'
7
+ filenames '*.go'
8
+
9
+ mimetypes 'text/x-go', 'application/x-go'
10
+
11
+ def self.analyze_text(text)
12
+ return 0
13
+ end
14
+
15
+ # Characters
16
+
17
+ WHITE_SPACE = /[\s\t\r\n]+/
18
+
19
+ NEWLINE = /\n/
20
+ UNICODE_CHAR = /[^\n]/
21
+ UNICODE_LETTER = /[[:alpha:]]/
22
+ UNICODE_DIGIT = /[[:digit:]]/
23
+
24
+ # Letters and digits
25
+
26
+ LETTER = /#{UNICODE_LETTER}|_/
27
+ DECIMAL_DIGIT = /[0-9]/
28
+ OCTAL_DIGIT = /[0-7]/
29
+ HEX_DIGIT = /[0-9A-Fa-f]/
30
+
31
+ # Comments
32
+
33
+ LINE_COMMENT = /\/\/(?:(?!#{NEWLINE}).)*/
34
+ GENERAL_COMMENT = /\/\*(?:(?!\*\/).)*\*\//m
35
+ COMMENT = /#{LINE_COMMENT}|#{GENERAL_COMMENT}/
36
+
37
+ # Keywords
38
+
39
+ KEYWORD = /\b(?:
40
+ break | default | func
41
+ | interface | select | case
42
+ | defer | go | map
43
+ | struct | chan | else
44
+ | goto | package | switch
45
+ | const | fallthrough | if
46
+ | range | type | continue
47
+ | for | import | return
48
+ | var
49
+ )\b/x
50
+
51
+ # Identifiers
52
+
53
+ IDENTIFIER = / (?!#{KEYWORD})
54
+ #{LETTER}(?:#{LETTER}|#{UNICODE_DIGIT})* /x
55
+
56
+ # Operators and delimiters
57
+
58
+ OPERATOR = / \+= | \+\+ | \+ | &\^= | &\^
59
+ | &= | && | & | == | =
60
+ | \!= | \! | -= | -- | -
61
+ | \|= | \|\| | \| | <= | <-
62
+ | <<= | << | < | \*= | \*
63
+ | \^= | \^ | >>= | >> | >=
64
+ | > | \/ | \/= | := | %
65
+ | %= | \.\.\. | \. | :
66
+ /x
67
+
68
+ SEPARATOR = / \( | \) | \[ | \] | \{
69
+ | \} | , | ;
70
+ /x
71
+
72
+ # Integer literals
73
+
74
+ DECIMAL_LIT = /[0-9]#{DECIMAL_DIGIT}*/
75
+ OCTAL_LIT = /0#{OCTAL_DIGIT}*/
76
+ HEX_LIT = /0[xX]#{HEX_DIGIT}+/
77
+ INT_LIT = /#{HEX_LIT}|#{DECIMAL_LIT}|#{OCTAL_LIT}/
78
+
79
+ # Floating-point literals
80
+
81
+ DECIMALS = /#{DECIMAL_DIGIT}+/
82
+ EXPONENT = /[eE][+\-]?#{DECIMALS}/
83
+ FLOAT_LIT = / #{DECIMALS} \. #{DECIMALS}? #{EXPONENT}?
84
+ | #{DECIMALS} #{EXPONENT}
85
+ | \. #{DECIMALS} #{EXPONENT}?
86
+ /x
87
+
88
+ # Imaginary literals
89
+
90
+ IMAGINARY_LIT = /(?:#{DECIMALS}|#{FLOAT_LIT})i/
91
+
92
+ # Rune literals
93
+
94
+ ESCAPED_CHAR = /\\[abfnrtv\\'"]/
95
+ LITTLE_U_VALUE = /\\u#{HEX_DIGIT}{4}/
96
+ BIG_U_VALUE = /\\U#{HEX_DIGIT}{8}/
97
+ UNICODE_VALUE = / #{UNICODE_CHAR} | #{LITTLE_U_VALUE}
98
+ | #{BIG_U_VALUE} | #{ESCAPED_CHAR}
99
+ /x
100
+ OCTAL_BYTE_VALUE = /\\#{OCTAL_DIGIT}{3}/
101
+ HEX_BYTE_VALUE = /\\x#{HEX_DIGIT}{2}/
102
+ BYTE_VALUE = /#{OCTAL_BYTE_VALUE}|#{HEX_BYTE_VALUE}/
103
+ CHAR_LIT = /'(?:#{UNICODE_VALUE}|#{BYTE_VALUE})'/
104
+ ESCAPE_SEQUENCE = / #{ESCAPED_CHAR}
105
+ | #{LITTLE_U_VALUE}
106
+ | #{BIG_U_VALUE}
107
+ | #{HEX_BYTE_VALUE}
108
+ /x
109
+
110
+ # String literals
111
+
112
+ RAW_STRING_LIT = /`(?:#{UNICODE_CHAR}|#{NEWLINE})*`/
113
+ INTERPRETED_STRING_LIT = / "(?: (?!")
114
+ (?: #{UNICODE_VALUE} | #{BYTE_VALUE} )
115
+ )*" /x
116
+ STRING_LIT = /#{RAW_STRING_LIT}|#{INTERPRETED_STRING_LIT}/
117
+
118
+ # Predeclared identifiers
119
+
120
+ PREDECLARED_TYPES = /\b(?:
121
+ bool | byte | complex64
122
+ | complex128 | error | float32
123
+ | float64 | int8 | int16
124
+ | int32 | int64 | int
125
+ | rune | string | uint8
126
+ | uint16 | uint32 | uint64
127
+ | uintptr | uint
128
+ )\b/x
129
+
130
+ PREDECLARED_CONSTANTS = /\b(?:true|false|iota|nil)\b/
131
+
132
+ PREDECLARED_FUNCTIONS = /\b(?:
133
+ append | cap | close | complex
134
+ | copy | delete | imag | len
135
+ | make | new | panic | print
136
+ | println | real | recover
137
+ )\b/x
138
+
139
+ state :simple_tokens do
140
+ rule(COMMENT, "Comment")
141
+ rule(KEYWORD, "Keyword")
142
+ rule(PREDECLARED_TYPES, "Keyword.Type")
143
+ rule(PREDECLARED_FUNCTIONS, "Name.Builtin")
144
+ rule(PREDECLARED_CONSTANTS, "Name.Constant")
145
+ rule(IMAGINARY_LIT, "Literal.Number")
146
+ rule(FLOAT_LIT, "Literal.Number")
147
+ rule(INT_LIT, "Literal.Number")
148
+ rule(CHAR_LIT, "Literal.String.Char")
149
+ rule(OPERATOR, "Operator")
150
+ rule(SEPARATOR, "Punctuation")
151
+ rule(IDENTIFIER, "Name")
152
+ rule(WHITE_SPACE, "Other")
153
+ end
154
+
155
+ state :root do
156
+ mixin :simple_tokens
157
+
158
+ rule(/`/, "Literal.String", :raw_string)
159
+ rule(/"/, "Literal.String", :interpreted_string)
160
+ end
161
+
162
+ state :interpreted_string do
163
+ rule(ESCAPE_SEQUENCE, "Literal.String.Escape")
164
+ rule(/\\./, "Error")
165
+ rule(/"/, "Literal.String", :pop!)
166
+ rule(/./, "Literal.String")
167
+ end
168
+
169
+ state :raw_string do
170
+ rule(/`/, "Literal.String", :pop!)
171
+ rule(/./m, "Literal.String")
172
+ end
173
+ end
174
+ end
175
+ end
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.3.3"
3
+ "0.3.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-10 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -101,6 +101,7 @@ files:
101
101
  - lib/rouge/lexers/gherkin/keywords.rb
102
102
  - lib/rouge/lexers/io.rb
103
103
  - lib/rouge/lexers/lua/builtins.rb
104
+ - lib/rouge/lexers/go.rb
104
105
  - lib/rouge/lexers/python.rb
105
106
  - lib/rouge/lexers/cpp.rb
106
107
  - lib/rouge/lexers/sql.rb
@@ -141,6 +142,7 @@ files:
141
142
  - lib/rouge/demos/clojure
142
143
  - lib/rouge/demos/java
143
144
  - lib/rouge/demos/csharp
145
+ - lib/rouge/demos/go
144
146
  - lib/rouge/demos/javascript
145
147
  - lib/rouge/demos/sed
146
148
  - lib/rouge/demos/common_lisp