rouge 3.0.0 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +17 -3
- data/bin/rougify +1 -0
- data/lib/rouge.rb +67 -42
- data/lib/rouge/cli.rb +87 -18
- data/lib/rouge/demos/ada +26 -0
- data/lib/rouge/demos/apex +9 -0
- data/lib/rouge/demos/armasm +12 -0
- data/lib/rouge/demos/batchfile +3 -0
- data/lib/rouge/demos/bbcbasic +6 -0
- data/lib/rouge/demos/bpf +7 -0
- data/lib/rouge/demos/brainfuck +5 -0
- data/lib/rouge/demos/clean +6 -0
- data/lib/rouge/demos/cmhg +8 -0
- data/lib/rouge/demos/crystal +45 -0
- data/lib/rouge/demos/csvs +8 -0
- data/lib/rouge/demos/cuda +11 -0
- data/lib/rouge/demos/cypher +5 -0
- data/lib/rouge/demos/cython +6 -0
- data/lib/rouge/demos/datastudio +21 -0
- data/lib/rouge/demos/ecl +18 -0
- data/lib/rouge/demos/eex +1 -0
- data/lib/rouge/demos/elm +4 -0
- data/lib/rouge/demos/epp +4 -0
- data/lib/rouge/demos/escape +3 -0
- data/lib/rouge/demos/freefem +16 -0
- data/lib/rouge/demos/gdscript +18 -0
- data/lib/rouge/demos/ghc-cmm +23 -0
- data/lib/rouge/demos/ghc-core +26 -0
- data/lib/rouge/demos/hack +5 -0
- data/lib/rouge/demos/haxe +5 -0
- data/lib/rouge/demos/hcl +7 -0
- data/lib/rouge/demos/hocon +8 -0
- data/lib/rouge/demos/hql +5 -0
- data/lib/rouge/demos/isbl +4 -0
- data/lib/rouge/demos/jsl +3 -0
- data/lib/rouge/demos/jsp +29 -0
- data/lib/rouge/demos/liquid +0 -1
- data/lib/rouge/demos/lustre +6 -0
- data/lib/rouge/demos/lutin +18 -0
- data/lib/rouge/demos/m68k +16 -0
- data/lib/rouge/demos/magik +6 -0
- data/lib/rouge/demos/mason +22 -0
- data/lib/rouge/demos/mathematica +8 -0
- data/lib/rouge/demos/minizinc +23 -0
- data/lib/rouge/demos/msgtrans +4 -0
- data/lib/rouge/demos/nasm +6 -6
- data/lib/rouge/demos/nesasm +11 -0
- data/lib/rouge/demos/objective_cpp +17 -0
- data/lib/rouge/demos/openedge +4 -0
- data/lib/rouge/demos/opentype_feature_file +6 -0
- data/lib/rouge/demos/plist +1 -132
- data/lib/rouge/demos/powershell +12 -48
- data/lib/rouge/demos/q +6 -0
- data/lib/rouge/demos/reasonml +12 -0
- data/lib/rouge/demos/rego +8 -0
- data/lib/rouge/demos/robot_framework +27 -0
- data/lib/rouge/demos/sas +13 -0
- data/lib/rouge/demos/slice +10 -0
- data/lib/rouge/demos/solidity +13 -0
- data/lib/rouge/demos/sparql +6 -0
- data/lib/rouge/demos/sqf +14 -0
- data/lib/rouge/demos/supercollider +11 -0
- data/lib/rouge/demos/terraform +16 -0
- data/lib/rouge/demos/ttcn3 +6 -0
- data/lib/rouge/demos/vcl +12 -0
- data/lib/rouge/demos/xojo +14 -0
- data/lib/rouge/demos/xpath +2 -0
- data/lib/rouge/demos/xquery +22 -0
- data/lib/rouge/demos/yang +17 -0
- data/lib/rouge/formatter.rb +39 -2
- data/lib/rouge/formatters/html.rb +21 -2
- data/lib/rouge/formatters/html_inline.rb +1 -0
- data/lib/rouge/formatters/html_legacy.rb +1 -0
- data/lib/rouge/formatters/html_line_table.rb +53 -0
- data/lib/rouge/formatters/html_linewise.rb +7 -11
- data/lib/rouge/formatters/html_pygments.rb +2 -0
- data/lib/rouge/formatters/html_table.rb +21 -31
- data/lib/rouge/formatters/null.rb +1 -0
- data/lib/rouge/formatters/terminal256.rb +23 -5
- data/lib/rouge/formatters/terminal_truecolor.rb +37 -0
- data/lib/rouge/formatters/tex.rb +92 -0
- data/lib/rouge/guesser.rb +2 -0
- data/lib/rouge/guessers/disambiguation.rb +48 -0
- data/lib/rouge/guessers/filename.rb +2 -0
- data/lib/rouge/guessers/glob_mapping.rb +3 -1
- data/lib/rouge/guessers/mimetype.rb +2 -0
- data/lib/rouge/guessers/modeline.rb +3 -1
- data/lib/rouge/guessers/source.rb +3 -1
- data/lib/rouge/guessers/util.rb +2 -0
- data/lib/rouge/lexer.rb +71 -15
- data/lib/rouge/lexers/abap.rb +13 -11
- data/lib/rouge/lexers/actionscript.rb +35 -34
- data/lib/rouge/lexers/ada.rb +162 -0
- data/lib/rouge/lexers/apache.rb +13 -15
- data/lib/rouge/lexers/apache/keywords.rb +15 -0
- data/lib/rouge/lexers/apex.rb +126 -0
- data/lib/rouge/lexers/apiblueprint.rb +2 -0
- data/lib/rouge/lexers/apple_script.rb +17 -14
- data/lib/rouge/lexers/armasm.rb +145 -0
- data/lib/rouge/lexers/awk.rb +26 -25
- data/lib/rouge/lexers/batchfile.rb +164 -0
- data/lib/rouge/lexers/bbcbasic.rb +112 -0
- data/lib/rouge/lexers/biml.rb +6 -4
- data/lib/rouge/lexers/bpf.rb +118 -0
- data/lib/rouge/lexers/brainfuck.rb +53 -0
- data/lib/rouge/lexers/bsl.rb +13 -12
- data/lib/rouge/lexers/c.rb +36 -58
- data/lib/rouge/lexers/ceylon.rb +7 -34
- data/lib/rouge/lexers/cfscript.rb +27 -26
- data/lib/rouge/lexers/clean.rb +156 -0
- data/lib/rouge/lexers/clojure.rb +15 -14
- data/lib/rouge/lexers/cmake.rb +16 -14
- data/lib/rouge/lexers/cmhg.rb +34 -0
- data/lib/rouge/lexers/coffeescript.rb +90 -49
- data/lib/rouge/lexers/common_lisp.rb +39 -38
- data/lib/rouge/lexers/conf.rb +7 -6
- data/lib/rouge/lexers/console.rb +92 -38
- data/lib/rouge/lexers/coq.rb +27 -23
- data/lib/rouge/lexers/cpp.rb +24 -13
- data/lib/rouge/lexers/crystal.rb +430 -0
- data/lib/rouge/lexers/csharp.rb +29 -29
- data/lib/rouge/lexers/css.rb +24 -23
- data/lib/rouge/lexers/csvs.rb +44 -0
- data/lib/rouge/lexers/cuda.rb +35 -0
- data/lib/rouge/lexers/cypher.rb +108 -0
- data/lib/rouge/lexers/cython.rb +151 -0
- data/lib/rouge/lexers/d.rb +64 -63
- data/lib/rouge/lexers/dart.rb +34 -33
- data/lib/rouge/lexers/datastudio.rb +138 -0
- data/lib/rouge/lexers/diff.rb +10 -4
- data/lib/rouge/lexers/digdag.rb +3 -1
- data/lib/rouge/lexers/docker.rb +12 -11
- data/lib/rouge/lexers/dot.rb +19 -18
- data/lib/rouge/lexers/ecl.rb +175 -0
- data/lib/rouge/lexers/eex.rb +52 -0
- data/lib/rouge/lexers/eiffel.rb +21 -20
- data/lib/rouge/lexers/elixir.rb +52 -36
- data/lib/rouge/lexers/elm.rb +90 -0
- data/lib/rouge/lexers/epp.rb +51 -0
- data/lib/rouge/lexers/erb.rb +5 -4
- data/lib/rouge/lexers/erlang.rb +1 -0
- data/lib/rouge/lexers/escape.rb +58 -0
- data/lib/rouge/lexers/factor.rb +41 -40
- data/lib/rouge/lexers/fortran.rb +36 -34
- data/lib/rouge/lexers/freefem.rb +240 -0
- data/lib/rouge/lexers/fsharp.rb +34 -32
- data/lib/rouge/lexers/gdscript.rb +171 -0
- data/lib/rouge/lexers/ghc_cmm.rb +340 -0
- data/lib/rouge/lexers/ghc_core.rb +151 -0
- data/lib/rouge/lexers/gherkin.rb +17 -14
- data/lib/rouge/lexers/gherkin/keywords.rb +2 -0
- data/lib/rouge/lexers/glsl.rb +2 -5
- data/lib/rouge/lexers/go.rb +3 -2
- data/lib/rouge/lexers/gradle.rb +1 -0
- data/lib/rouge/lexers/graphql.rb +78 -60
- data/lib/rouge/lexers/groovy.rb +24 -25
- data/lib/rouge/lexers/hack.rb +49 -0
- data/lib/rouge/lexers/haml.rb +26 -29
- data/lib/rouge/lexers/handlebars.rb +32 -20
- data/lib/rouge/lexers/haskell.rb +78 -62
- data/lib/rouge/lexers/haxe.rb +246 -0
- data/lib/rouge/lexers/hcl.rb +163 -0
- data/lib/rouge/lexers/hocon.rb +86 -0
- data/lib/rouge/lexers/hql.rb +139 -0
- data/lib/rouge/lexers/html.rb +36 -33
- data/lib/rouge/lexers/http.rb +10 -9
- data/lib/rouge/lexers/hylang.rb +15 -14
- data/lib/rouge/lexers/idlang.rb +34 -32
- data/lib/rouge/lexers/igorpro.rb +481 -225
- data/lib/rouge/lexers/ini.rb +13 -12
- data/lib/rouge/lexers/io.rb +10 -9
- data/lib/rouge/lexers/irb.rb +6 -5
- data/lib/rouge/lexers/isbl.rb +97 -0
- data/lib/rouge/lexers/isbl/builtins.rb +17 -0
- data/lib/rouge/lexers/java.rb +30 -26
- data/lib/rouge/lexers/javascript.rb +59 -61
- data/lib/rouge/lexers/jinja.rb +39 -22
- data/lib/rouge/lexers/jsl.rb +55 -0
- data/lib/rouge/lexers/json.rb +54 -11
- data/lib/rouge/lexers/json_doc.rb +8 -5
- data/lib/rouge/lexers/jsonnet.rb +19 -18
- data/lib/rouge/lexers/jsp.rb +120 -0
- data/lib/rouge/lexers/jsx.rb +18 -16
- data/lib/rouge/lexers/julia.rb +192 -74
- data/lib/rouge/lexers/kotlin.rb +79 -27
- data/lib/rouge/lexers/lasso.rb +54 -58
- data/lib/rouge/lexers/lasso/keywords.rb +14 -0
- data/lib/rouge/lexers/liquid.rb +116 -118
- data/lib/rouge/lexers/literate_coffeescript.rb +3 -2
- data/lib/rouge/lexers/literate_haskell.rb +6 -5
- data/lib/rouge/lexers/llvm.rb +66 -49
- data/lib/rouge/lexers/lua.rb +43 -4
- data/lib/rouge/lexers/lua/builtins.rb +2 -0
- data/lib/rouge/lexers/lustre.rb +79 -0
- data/lib/rouge/lexers/lutin.rb +33 -0
- data/lib/rouge/lexers/m68k.rb +143 -0
- data/lib/rouge/lexers/magik.rb +127 -0
- data/lib/rouge/lexers/make.rb +57 -34
- data/lib/rouge/lexers/markdown.rb +67 -39
- data/lib/rouge/lexers/mason.rb +110 -0
- data/lib/rouge/lexers/mathematica.rb +96 -0
- data/lib/rouge/lexers/mathematica/builtins.rb +13 -0
- data/lib/rouge/lexers/matlab.rb +26 -17
- data/lib/rouge/lexers/matlab/builtins.rb +4 -4
- data/lib/rouge/lexers/minizinc.rb +87 -0
- data/lib/rouge/lexers/moonscript.rb +4 -3
- data/lib/rouge/lexers/mosel.rb +64 -63
- data/lib/rouge/lexers/msgtrans.rb +26 -0
- data/lib/rouge/lexers/mxml.rb +19 -18
- data/lib/rouge/lexers/nasm.rb +43 -169
- data/lib/rouge/lexers/nesasm.rb +78 -0
- data/lib/rouge/lexers/nginx.rb +15 -14
- data/lib/rouge/lexers/nim.rb +4 -2
- data/lib/rouge/lexers/nix.rb +48 -42
- data/lib/rouge/lexers/objective_c.rb +5 -178
- data/lib/rouge/lexers/objective_c/common.rb +184 -0
- data/lib/rouge/lexers/objective_cpp.rb +31 -0
- data/lib/rouge/lexers/ocaml.rb +29 -64
- data/lib/rouge/lexers/ocaml/common.rb +53 -0
- data/lib/rouge/lexers/openedge.rb +429 -0
- data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
- data/lib/rouge/lexers/pascal.rb +6 -5
- data/lib/rouge/lexers/perl.rb +103 -68
- data/lib/rouge/lexers/php.rb +94 -54
- data/lib/rouge/lexers/php/builtins.rb +183 -174
- data/lib/rouge/lexers/plain_text.rb +2 -1
- data/lib/rouge/lexers/plist.rb +16 -14
- data/lib/rouge/lexers/pony.rb +21 -20
- data/lib/rouge/lexers/powershell.rb +191 -639
- data/lib/rouge/lexers/praat.rb +76 -75
- data/lib/rouge/lexers/prolog.rb +27 -19
- data/lib/rouge/lexers/prometheus.rb +32 -30
- data/lib/rouge/lexers/properties.rb +13 -12
- data/lib/rouge/lexers/protobuf.rb +23 -22
- data/lib/rouge/lexers/puppet.rb +33 -32
- data/lib/rouge/lexers/python.rb +124 -98
- data/lib/rouge/lexers/q.rb +17 -14
- data/lib/rouge/lexers/qml.rb +13 -12
- data/lib/rouge/lexers/r.rb +13 -13
- data/lib/rouge/lexers/racket.rb +47 -22
- data/lib/rouge/lexers/reasonml.rb +65 -0
- data/lib/rouge/lexers/rego.rb +45 -0
- data/lib/rouge/lexers/robot_framework.rb +249 -0
- data/lib/rouge/lexers/ruby.rb +88 -71
- data/lib/rouge/lexers/rust.rb +47 -46
- data/lib/rouge/lexers/sas.rb +563 -0
- data/lib/rouge/lexers/sass.rb +11 -10
- data/lib/rouge/lexers/sass/common.rb +41 -40
- data/lib/rouge/lexers/scala.rb +67 -40
- data/lib/rouge/lexers/scheme.rb +19 -18
- data/lib/rouge/lexers/scss.rb +6 -5
- data/lib/rouge/lexers/sed.rb +31 -30
- data/lib/rouge/lexers/shell.rb +83 -62
- data/lib/rouge/lexers/sieve.rb +10 -9
- data/lib/rouge/lexers/slice.rb +32 -0
- data/lib/rouge/lexers/slim.rb +27 -26
- data/lib/rouge/lexers/smalltalk.rb +34 -33
- data/lib/rouge/lexers/smarty.rb +20 -19
- data/lib/rouge/lexers/sml.rb +68 -67
- data/lib/rouge/lexers/solidity.rb +185 -0
- data/lib/rouge/lexers/sparql.rb +129 -0
- data/lib/rouge/lexers/sqf.rb +109 -0
- data/lib/rouge/lexers/sqf/commands.rb +15 -0
- data/lib/rouge/lexers/sql.rb +47 -26
- data/lib/rouge/lexers/supercollider.rb +116 -0
- data/lib/rouge/lexers/swift.rb +63 -38
- data/lib/rouge/lexers/tap.rb +22 -20
- data/lib/rouge/lexers/tcl.rb +28 -27
- data/lib/rouge/lexers/terraform.rb +128 -0
- data/lib/rouge/lexers/tex.rb +20 -19
- data/lib/rouge/lexers/toml.rb +59 -20
- data/lib/rouge/lexers/tsx.rb +1 -0
- data/lib/rouge/lexers/ttcn3.rb +119 -0
- data/lib/rouge/lexers/tulip.rb +38 -36
- data/lib/rouge/lexers/turtle.rb +36 -38
- data/lib/rouge/lexers/twig.rb +1 -0
- data/lib/rouge/lexers/typescript.rb +12 -0
- data/lib/rouge/lexers/typescript/common.rb +1 -0
- data/lib/rouge/lexers/vala.rb +19 -18
- data/lib/rouge/lexers/varnish.rb +168 -0
- data/lib/rouge/lexers/vb.rb +28 -27
- data/lib/rouge/lexers/verilog.rb +27 -28
- data/lib/rouge/lexers/vhdl.rb +13 -12
- data/lib/rouge/lexers/viml.rb +15 -14
- data/lib/rouge/lexers/viml/keywords.rb +2 -0
- data/lib/rouge/lexers/vue.rb +19 -12
- data/lib/rouge/lexers/wollok.rb +27 -26
- data/lib/rouge/lexers/xml.rb +18 -21
- data/lib/rouge/lexers/xojo.rb +61 -0
- data/lib/rouge/lexers/xpath.rb +332 -0
- data/lib/rouge/lexers/xquery.rb +145 -0
- data/lib/rouge/lexers/yaml.rb +64 -61
- data/lib/rouge/lexers/yang.rb +147 -0
- data/lib/rouge/plugins/redcarpet.rb +9 -2
- data/lib/rouge/regex_lexer.rb +27 -25
- data/lib/rouge/template_lexer.rb +1 -0
- data/lib/rouge/tex_theme_renderer.rb +132 -0
- data/lib/rouge/text_analyzer.rb +1 -0
- data/lib/rouge/theme.rb +5 -0
- data/lib/rouge/themes/base16.rb +1 -0
- data/lib/rouge/themes/bw.rb +41 -0
- data/lib/rouge/themes/colorful.rb +1 -0
- data/lib/rouge/themes/github.rb +1 -0
- data/lib/rouge/themes/gruvbox.rb +1 -0
- data/lib/rouge/themes/igor_pro.rb +1 -0
- data/lib/rouge/themes/magritte.rb +78 -0
- data/lib/rouge/themes/molokai.rb +1 -0
- data/lib/rouge/themes/monokai.rb +1 -0
- data/lib/rouge/themes/monokai_sublime.rb +4 -1
- data/lib/rouge/themes/pastie.rb +2 -1
- data/lib/rouge/themes/thankful_eyes.rb +2 -1
- data/lib/rouge/themes/tulip.rb +2 -1
- data/lib/rouge/token.rb +31 -22
- data/lib/rouge/util.rb +3 -2
- data/lib/rouge/version.rb +2 -1
- data/rouge.gemspec +8 -1
- metadata +141 -7
- data/lib/rouge/lexers/apache/keywords.yml +0 -764
- data/lib/rouge/lexers/lasso/keywords.yml +0 -446
data/lib/rouge/lexers/conf.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Rouge
|
4
5
|
module Lexers
|
@@ -12,12 +13,12 @@ module Rouge
|
|
12
13
|
|
13
14
|
# short and sweet
|
14
15
|
state :root do
|
15
|
-
rule /#.*?\n/, Comment
|
16
|
-
rule /".*?"/, Str::Double
|
17
|
-
rule /'.*?'/, Str::Single
|
18
|
-
rule /[a-z]\w*/i, Name
|
19
|
-
rule /\d+/, Num
|
20
|
-
rule /[^\
|
16
|
+
rule %r/#.*?\n/, Comment
|
17
|
+
rule %r/".*?"/, Str::Double
|
18
|
+
rule %r/'.*?'/, Str::Single
|
19
|
+
rule %r/[a-z]\w*/i, Name
|
20
|
+
rule %r/\d+/, Num
|
21
|
+
rule %r/[^\w#"']+/, Text
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/rouge/lexers/console.rb
CHANGED
@@ -1,17 +1,53 @@
|
|
1
1
|
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Rouge
|
4
5
|
module Lexers
|
6
|
+
# The {ConsoleLexer} class is intended to lex content that represents the
|
7
|
+
# text that would display in a console/terminal. As distinct from the
|
8
|
+
# {Shell} lexer, {ConsoleLexer} will try to parse out the prompt from each
|
9
|
+
# line before passing the remainder of the line to the language lexer for
|
10
|
+
# the shell (by default, the {Shell} lexer).
|
11
|
+
#
|
12
|
+
# The {ConsoleLexer} class accepts five options:
|
13
|
+
# 1. **lang**: the shell language to lex (default: `shell`);
|
14
|
+
# 2. **output**: the output language (default: `plaintext?token=Generic.Output`);
|
15
|
+
# 3. **prompt**: comma-separated list of strings that indicate the end of a
|
16
|
+
# prompt (default: `$,#,>,;`);
|
17
|
+
# 4. **comments**: whether to enable comments.
|
18
|
+
# 5. **error**: comma-separated list of strings that indicate the start of an
|
19
|
+
# error message
|
20
|
+
#
|
21
|
+
# The comments option, if enabled, will lex lines that begin with a `#` as a
|
22
|
+
# comment. Please note that this option will only work if the prompt is
|
23
|
+
# either not manually specified or, if manually specified, does not include
|
24
|
+
# the `#` character.
|
25
|
+
#
|
26
|
+
# Most Markdown lexers that recognise GitHub-Flavored Markdown syntax, will
|
27
|
+
# pass the language string to Rouge as written in the original document.
|
28
|
+
# This allows an end user to pass options to {ConsoleLexer} by passing them
|
29
|
+
# as CGI-style parameters as in the example below.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# <pre>Here's some regular text.
|
33
|
+
#
|
34
|
+
# ```console?comments=true
|
35
|
+
# # This is a comment
|
36
|
+
# $ cp foo bar
|
37
|
+
# ```
|
38
|
+
#
|
39
|
+
# Some more regular text.</pre>
|
5
40
|
class ConsoleLexer < Lexer
|
6
41
|
tag 'console'
|
7
42
|
aliases 'terminal', 'shell_session', 'shell-session'
|
8
43
|
filenames '*.cap'
|
9
|
-
desc 'A generic lexer for shell sessions. Accepts ?lang and ?output lexer options, a ?prompt option,
|
44
|
+
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.'
|
10
45
|
|
11
46
|
option :lang, 'the shell language to lex (default: shell)'
|
12
47
|
option :output, 'the output language (default: plaintext?token=Generic.Output)'
|
13
48
|
option :prompt, 'comma-separated list of strings that indicate the end of a prompt. (default: $,#,>,;)'
|
14
49
|
option :comments, 'enable hash-comments at the start of a line - otherwise interpreted as a prompt. (default: false, implied by ?prompt not containing `#`)'
|
50
|
+
option :error, 'comma-separated list of strings that indicate the start of an error message'
|
15
51
|
|
16
52
|
def initialize(*)
|
17
53
|
super
|
@@ -19,20 +55,7 @@ module Rouge
|
|
19
55
|
@lang = lexer_option(:lang) { 'shell' }
|
20
56
|
@output = lexer_option(:output) { PlainText.new(token: Generic::Output) }
|
21
57
|
@comments = bool_option(:comments) { :guess }
|
22
|
-
|
23
|
-
|
24
|
-
def prompt_regex
|
25
|
-
@prompt_regex ||= begin
|
26
|
-
/^#{prompt_prefix_regex}(?:#{end_chars.map(&Regexp.method(:escape)).join('|')})/
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def end_chars
|
31
|
-
@end_chars ||= if @prompt.any?
|
32
|
-
@prompt.reject { |c| c.empty? }
|
33
|
-
else
|
34
|
-
%w($ # > ;)
|
35
|
-
end
|
58
|
+
@error = list_option(:error) { nil }
|
36
59
|
end
|
37
60
|
|
38
61
|
# whether to allow comments. if manually specifying a prompt that isn't
|
@@ -46,11 +69,23 @@ module Rouge
|
|
46
69
|
end
|
47
70
|
end
|
48
71
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
72
|
+
def comment_regex
|
73
|
+
/\A\s*?#/
|
74
|
+
end
|
75
|
+
|
76
|
+
def end_chars
|
77
|
+
@end_chars ||= if @prompt.any?
|
78
|
+
@prompt.reject { |c| c.empty? }
|
79
|
+
elsif allow_comments?
|
80
|
+
%w($ > ;)
|
52
81
|
else
|
53
|
-
|
82
|
+
%w($ # > ;)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def error_regex
|
87
|
+
@error_regex ||= if @error.any?
|
88
|
+
/^(?:#{@error.map(&Regexp.method(:escape)).join('|')})/
|
54
89
|
end
|
55
90
|
end
|
56
91
|
|
@@ -67,6 +102,10 @@ module Rouge
|
|
67
102
|
end
|
68
103
|
end
|
69
104
|
|
105
|
+
def line_regex
|
106
|
+
/(\\.|[^\\])*?(\n|$)/m
|
107
|
+
end
|
108
|
+
|
70
109
|
def output_lexer
|
71
110
|
@output_lexer ||= case @output
|
72
111
|
when nil
|
@@ -80,25 +119,12 @@ module Rouge
|
|
80
119
|
end
|
81
120
|
end
|
82
121
|
|
83
|
-
def line_regex
|
84
|
-
/(\\.|[^\\])*?(\n|$)/m
|
85
|
-
end
|
86
|
-
|
87
|
-
def comment_regex
|
88
|
-
/\A\s*?#/
|
89
|
-
end
|
90
|
-
|
91
|
-
def stream_tokens(input, &output)
|
92
|
-
input = StringScanner.new(input)
|
93
|
-
lang_lexer.reset!
|
94
|
-
output_lexer.reset!
|
95
|
-
|
96
|
-
process_line(input, &output) while !input.eos?
|
97
|
-
end
|
98
|
-
|
99
122
|
def process_line(input, &output)
|
100
123
|
input.scan(line_regex)
|
101
124
|
|
125
|
+
# As a nicety, support the use of elisions in input text. A user can
|
126
|
+
# write a line with only `<...>` or one or more `.` characters and
|
127
|
+
# Rouge will treat it as a comment.
|
102
128
|
if input[0] =~ /\A\s*(?:<[.]+>|[.]+)\s*\z/
|
103
129
|
puts "console: matched snip #{input[0].inspect}" if @debug
|
104
130
|
output_lexer.reset!
|
@@ -115,22 +141,50 @@ module Rouge
|
|
115
141
|
# before we pass to the lang lexer so it can determine where
|
116
142
|
# the "real" beginning of the line is
|
117
143
|
$' =~ /\A\s*/
|
118
|
-
yield Text, $& unless $&.empty?
|
144
|
+
yield Text::Whitespace, $& unless $&.empty?
|
119
145
|
|
120
|
-
lang_lexer.
|
146
|
+
lang_lexer.continue_lex($', &output)
|
121
147
|
elsif comment_regex =~ input[0].strip
|
122
148
|
puts "console: matched comment #{input[0].inspect}" if @debug
|
123
149
|
output_lexer.reset!
|
124
150
|
lang_lexer.reset!
|
125
151
|
|
126
152
|
yield Comment, input[0]
|
153
|
+
elsif error_regex =~ input[0]
|
154
|
+
puts "console: matched error #{input[0].inspect}" if @debug
|
155
|
+
output_lexer.reset!
|
156
|
+
lang_lexer.reset!
|
157
|
+
|
158
|
+
yield Generic::Error, input[0]
|
127
159
|
else
|
128
160
|
puts "console: matched output #{input[0].inspect}" if @debug
|
129
161
|
lang_lexer.reset!
|
130
162
|
|
131
|
-
output_lexer.
|
163
|
+
output_lexer.continue_lex(input[0], &output)
|
132
164
|
end
|
133
165
|
end
|
166
|
+
|
167
|
+
def prompt_prefix_regex
|
168
|
+
if allow_comments?
|
169
|
+
/[^<#]*?/m
|
170
|
+
else
|
171
|
+
/.*?/m
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def prompt_regex
|
176
|
+
@prompt_regex ||= begin
|
177
|
+
/^#{prompt_prefix_regex}(?:#{end_chars.map(&Regexp.method(:escape)).join('|')})/
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def stream_tokens(input, &output)
|
182
|
+
input = StringScanner.new(input)
|
183
|
+
lang_lexer.reset!
|
184
|
+
output_lexer.reset!
|
185
|
+
|
186
|
+
process_line(input, &output) while !input.eos?
|
187
|
+
end
|
134
188
|
end
|
135
189
|
end
|
136
190
|
end
|
data/lib/rouge/lexers/coq.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Rouge
|
4
5
|
module Lexers
|
@@ -57,7 +58,7 @@ module Rouge
|
|
57
58
|
|
58
59
|
def self.keyopts
|
59
60
|
@keyopts ||= Set.new %w(
|
60
|
-
:= => -> /\\ \\/ _ ; :> :
|
61
|
+
:= => -> /\\ \\/ _ ; :> : ⇒ → ↔ ⇔ ≔ ≡ ∀ ∃ ∧ ∨ ¬ ⊤ ⊥ ⊢ ⊨ ∈
|
61
62
|
)
|
62
63
|
end
|
63
64
|
|
@@ -89,8 +90,8 @@ module Rouge
|
|
89
90
|
set_options = /(Set|Unset)(\s+)(Universe|Printing|Implicit|Strict)(\s+)(Polymorphism|All|Notations|Arguments|Universes|Implicit)(\s*)\./m
|
90
91
|
|
91
92
|
state :root do
|
92
|
-
rule /[(][*](?![)])/, Comment, :comment
|
93
|
-
rule /\s+/m, Text::Whitespace
|
93
|
+
rule %r/[(][*](?![)])/, Comment, :comment
|
94
|
+
rule %r/\s+/m, Text::Whitespace
|
94
95
|
rule module_type do |m|
|
95
96
|
token Keyword , 'Module'
|
96
97
|
token Text::Whitespace , m[1]
|
@@ -112,42 +113,45 @@ module Rouge
|
|
112
113
|
@continue = false
|
113
114
|
push :continue_id
|
114
115
|
end
|
115
|
-
rule
|
116
|
-
rule /\\\//, Operator
|
117
|
-
|
116
|
+
rule %r(/\\), Operator
|
117
|
+
rule %r/\\\//, Operator
|
118
|
+
|
119
|
+
rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
|
120
|
+
rule %r/\d[\d_]*/, Num::Integer
|
121
|
+
|
122
|
+
rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
|
123
|
+
rule %r/'/, Keyword
|
124
|
+
rule %r/"/, Str::Double, :string
|
125
|
+
rule %r/[~?]#{id}/, Name::Variable
|
126
|
+
|
127
|
+
rule %r/./ do |m|
|
118
128
|
match = m[0]
|
119
129
|
if self.class.keyopts.include? match
|
120
130
|
token Punctuation
|
121
|
-
|
131
|
+
elsif match =~ operator
|
122
132
|
token Operator
|
133
|
+
else
|
134
|
+
token Error
|
123
135
|
end
|
124
136
|
end
|
125
|
-
|
126
|
-
rule /-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
|
127
|
-
rule /\d[\d_]*/, Num::Integer
|
128
|
-
|
129
|
-
rule /'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
|
130
|
-
rule /'/, Keyword
|
131
|
-
rule /"/, Str::Double, :string
|
132
|
-
rule /[~?]#{id}/, Name::Variable
|
133
137
|
end
|
134
138
|
|
135
139
|
state :comment do
|
136
|
-
rule /[^(*)]+/, Comment
|
140
|
+
rule %r/[^(*)]+/, Comment
|
137
141
|
rule(/[(][*]/) { token Comment; push }
|
138
|
-
rule /[*][)]/, Comment, :pop!
|
139
|
-
rule /[(*)]/, Comment
|
142
|
+
rule %r/[*][)]/, Comment, :pop!
|
143
|
+
rule %r/[(*)]/, Comment
|
140
144
|
end
|
141
145
|
|
142
146
|
state :string do
|
143
|
-
rule /[
|
147
|
+
rule %r/(?:\\")+|[^"]/, Str::Double
|
144
148
|
mixin :escape_sequence
|
145
|
-
rule /\\\n/, Str::Double
|
146
|
-
rule /"/, Str::Double, :pop!
|
149
|
+
rule %r/\\\n/, Str::Double
|
150
|
+
rule %r/"/, Str::Double, :pop!
|
147
151
|
end
|
148
152
|
|
149
153
|
state :escape_sequence do
|
150
|
-
rule /\\[\\"'ntbr]/, Str::Escape
|
154
|
+
rule %r/\\[\\"'ntbr]/, Str::Escape
|
151
155
|
end
|
152
156
|
|
153
157
|
state :continue_id do
|
@@ -170,7 +174,7 @@ module Rouge
|
|
170
174
|
@continue = false
|
171
175
|
pop!
|
172
176
|
end
|
173
|
-
rule // do
|
177
|
+
rule %r// do
|
174
178
|
if @continue
|
175
179
|
token Name::Constant , @name
|
176
180
|
else
|
data/lib/rouge/lexers/cpp.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Rouge
|
4
5
|
module Lexers
|
@@ -16,15 +17,15 @@ module Rouge
|
|
16
17
|
'*.cc', '*.hh',
|
17
18
|
'*.cxx', '*.hxx',
|
18
19
|
'*.pde', '*.ino',
|
19
|
-
'*.tpp'
|
20
|
+
'*.tpp', '*.h'
|
20
21
|
mimetypes 'text/x-c++hdr', 'text/x-c++src'
|
21
22
|
|
22
23
|
def self.keywords
|
23
24
|
@keywords ||= super + Set.new(%w(
|
24
|
-
asm auto catch const_cast delete dynamic_cast explicit export
|
25
|
-
|
26
|
-
reinterpret_cast restrict size_of static_cast
|
27
|
-
|
25
|
+
asm auto catch const_cast delete dynamic_cast explicit export friend
|
26
|
+
mutable namespace new operator private protected public
|
27
|
+
reinterpret_cast restrict size_of static_cast this throw throws
|
28
|
+
typeid typename using virtual final override
|
28
29
|
|
29
30
|
alignas alignof constexpr decltype noexcept static_assert
|
30
31
|
thread_local try
|
@@ -48,7 +49,7 @@ module Rouge
|
|
48
49
|
|
49
50
|
prepend :root do
|
50
51
|
# Offload C++ extensions, http://offload.codeplay.com/
|
51
|
-
rule /(?:__offload|__blockingoffload|__outer)\b/, Keyword::Pseudo
|
52
|
+
rule %r/(?:__offload|__blockingoffload|__outer)\b/, Keyword::Pseudo
|
52
53
|
end
|
53
54
|
|
54
55
|
# digits with optional inner quotes
|
@@ -56,23 +57,33 @@ module Rouge
|
|
56
57
|
dq = /\d('?\d)*/
|
57
58
|
|
58
59
|
prepend :statements do
|
59
|
-
rule /class\b/, Keyword, :classname
|
60
|
+
rule %r/(class|struct)\b/, Keyword, :classname
|
61
|
+
rule %r/template\b/, Keyword, :template
|
62
|
+
rule %r/\d+(\.\d+)?(?:h|(?:min)|s|(?:ms)|(?:us)|(?:ns))/, Num::Other
|
60
63
|
rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
|
61
64
|
rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
|
62
|
-
rule /0x\h('?\h)*[lu]*/i, Num::Hex
|
63
|
-
rule /
|
64
|
-
rule
|
65
|
-
rule
|
66
|
-
rule
|
65
|
+
rule %r/0x\h('?\h)*[lu]*/i, Num::Hex
|
66
|
+
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
|
67
|
+
rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
|
68
|
+
rule %r/#{dq}[lu]*/i, Num::Integer
|
69
|
+
rule %r/\bnullptr\b/, Name::Builtin
|
70
|
+
rule %r/(?:u8|u|U|L)?R"([a-zA-Z0-9_{}\[\]#<>%:;.?*\+\-\/\^&|~!=,"']{,16})\(.*?\)\1"/m, Str
|
67
71
|
end
|
68
72
|
|
69
73
|
state :classname do
|
70
74
|
rule id, Name::Class, :pop!
|
71
75
|
|
72
76
|
# template specification
|
73
|
-
rule /\s*(?=>)/m, Text, :pop!
|
77
|
+
rule %r/\s*(?=>)/m, Text, :pop!
|
78
|
+
rule %r/[.]{3}/, Operator
|
74
79
|
mixin :whitespace
|
75
80
|
end
|
81
|
+
|
82
|
+
state :template do
|
83
|
+
rule %r/>/, Punctuation, :pop!
|
84
|
+
rule %r/typename\b/, Keyword, :classname
|
85
|
+
mixin :root
|
86
|
+
end
|
76
87
|
end
|
77
88
|
end
|
78
89
|
end
|
@@ -0,0 +1,430 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Crystal < RegexLexer
|
7
|
+
title "Crystal"
|
8
|
+
desc "Crystal The Programming Language (crystal-lang.org)"
|
9
|
+
tag 'crystal'
|
10
|
+
aliases 'cr'
|
11
|
+
filenames '*.cr'
|
12
|
+
|
13
|
+
mimetypes 'text/x-crystal', 'application/x-crystal'
|
14
|
+
|
15
|
+
def self.detect?(text)
|
16
|
+
return true if text.shebang? 'crystal'
|
17
|
+
end
|
18
|
+
|
19
|
+
state :symbols do
|
20
|
+
# symbols
|
21
|
+
rule %r(
|
22
|
+
: # initial :
|
23
|
+
@{0,2} # optional ivar, for :@foo and :@@foo
|
24
|
+
[a-z_]\w*[!?]? # the symbol
|
25
|
+
)xi, Str::Symbol
|
26
|
+
|
27
|
+
# special symbols
|
28
|
+
rule %r(:(?:\*\*|[-+]@|[/\%&\|^`~]|\[\]=?|<<|>>|<=?>|<=?|===?)),
|
29
|
+
Str::Symbol
|
30
|
+
|
31
|
+
rule %r/:'(\\\\|\\'|[^'])*'/, Str::Symbol
|
32
|
+
rule %r/:"/, Str::Symbol, :simple_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
state :sigil_strings do
|
36
|
+
# %-sigiled strings
|
37
|
+
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
|
38
|
+
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
|
39
|
+
rule %r/%([rqswQWxiI])?([^\w\s])/ do |m|
|
40
|
+
open = Regexp.escape(m[2])
|
41
|
+
close = Regexp.escape(delimiter_map[m[2]] || m[2])
|
42
|
+
interp = /[rQWxI]/ === m[1]
|
43
|
+
toktype = Str::Other
|
44
|
+
|
45
|
+
puts " open: #{open.inspect}" if @debug
|
46
|
+
puts " close: #{close.inspect}" if @debug
|
47
|
+
|
48
|
+
# regexes
|
49
|
+
if m[1] == 'r'
|
50
|
+
toktype = Str::Regex
|
51
|
+
push :regex_flags
|
52
|
+
end
|
53
|
+
|
54
|
+
token toktype
|
55
|
+
|
56
|
+
push do
|
57
|
+
rule %r/\\[##{open}#{close}\\]/, Str::Escape
|
58
|
+
# nesting rules only with asymmetric delimiters
|
59
|
+
if open != close
|
60
|
+
rule %r/#{open}/ do
|
61
|
+
token toktype
|
62
|
+
push
|
63
|
+
end
|
64
|
+
end
|
65
|
+
rule %r/#{close}/, toktype, :pop!
|
66
|
+
|
67
|
+
if interp
|
68
|
+
mixin :string_intp_escaped
|
69
|
+
rule %r/#/, toktype
|
70
|
+
else
|
71
|
+
rule %r/[\\#]/, toktype
|
72
|
+
end
|
73
|
+
|
74
|
+
rule %r/[^##{open}#{close}\\]+/m, toktype
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
state :strings do
|
80
|
+
mixin :symbols
|
81
|
+
rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
|
82
|
+
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
|
83
|
+
rule %r/"/, Str::Double, :simple_string
|
84
|
+
rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
|
85
|
+
end
|
86
|
+
|
87
|
+
state :regex_flags do
|
88
|
+
rule %r/[mixounse]*/, Str::Regex, :pop!
|
89
|
+
end
|
90
|
+
|
91
|
+
# double-quoted string and symbol
|
92
|
+
[[:string, Str::Double, '"'],
|
93
|
+
[:sym, Str::Symbol, '"'],
|
94
|
+
[:backtick, Str::Backtick, '`']].each do |name, tok, fin|
|
95
|
+
state :"simple_#{name}" do
|
96
|
+
mixin :string_intp_escaped
|
97
|
+
rule %r/[^\\#{fin}#]+/m, tok
|
98
|
+
rule %r/[\\#]/, tok
|
99
|
+
rule %r/#{fin}/, tok, :pop!
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
keywords = %w(
|
104
|
+
BEGIN END alias begin break case defined\? do else elsif end
|
105
|
+
ensure for if ifdef in next redo rescue raise retry return super then
|
106
|
+
undef unless until when while yield lib fun type of as
|
107
|
+
)
|
108
|
+
|
109
|
+
keywords_pseudo = %w(
|
110
|
+
initialize new loop include extend raise attr_reader attr_writer
|
111
|
+
attr_accessor alias_method attr catch throw private module_function
|
112
|
+
public protected true false nil __FILE__ __LINE__
|
113
|
+
getter getter? getter! property property? property! struct record
|
114
|
+
)
|
115
|
+
|
116
|
+
builtins_g = %w(
|
117
|
+
abort ancestors at_exit
|
118
|
+
caller catch chomp chop clone constants
|
119
|
+
display dup eval exec exit extend fail fork format freeze
|
120
|
+
getc gets global_variables gsub hash id included_modules
|
121
|
+
inspect instance_eval instance_method instance_methods
|
122
|
+
lambda loop method method_missing
|
123
|
+
methods module_eval name object_id open p print printf
|
124
|
+
proc putc puts raise rand
|
125
|
+
readline readlines require scan select self send
|
126
|
+
sleep split sprintf srand sub syscall system
|
127
|
+
test throw to_a to_s trap warn
|
128
|
+
)
|
129
|
+
|
130
|
+
builtins_q = %w(
|
131
|
+
eql equal include is_a iterator kind_of nil
|
132
|
+
)
|
133
|
+
|
134
|
+
builtins_b = %w(chomp chop exit gsub sub)
|
135
|
+
|
136
|
+
start do
|
137
|
+
push :expr_start
|
138
|
+
@heredoc_queue = []
|
139
|
+
end
|
140
|
+
|
141
|
+
state :whitespace do
|
142
|
+
mixin :inline_whitespace
|
143
|
+
rule %r/\n\s*/m, Text, :expr_start
|
144
|
+
rule %r/#.*$/, Comment::Single
|
145
|
+
|
146
|
+
rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
|
147
|
+
end
|
148
|
+
|
149
|
+
state :inline_whitespace do
|
150
|
+
rule %r/[ \t\r]+/, Text
|
151
|
+
end
|
152
|
+
|
153
|
+
state :root do
|
154
|
+
mixin :whitespace
|
155
|
+
rule %r/__END__/, Comment::Preproc, :end_part
|
156
|
+
|
157
|
+
rule %r/0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
|
158
|
+
rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
|
159
|
+
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
|
160
|
+
rule %r/\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
|
161
|
+
rule %r/[\d]+(?:_\d+)*/, Num::Integer
|
162
|
+
|
163
|
+
rule %r/@\[([^\]]+)\]/, Name::Decorator
|
164
|
+
|
165
|
+
# names
|
166
|
+
rule %r/@@[a-z_]\w*/i, Name::Variable::Class
|
167
|
+
rule %r/@[a-z_]\w*/i, Name::Variable::Instance
|
168
|
+
rule %r/\$\w+/, Name::Variable::Global
|
169
|
+
rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
|
170
|
+
rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
|
171
|
+
rule %r/::/, Operator
|
172
|
+
|
173
|
+
mixin :strings
|
174
|
+
|
175
|
+
rule %r/(?:#{keywords.join('|')})\b/, Keyword, :expr_start
|
176
|
+
rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
|
177
|
+
|
178
|
+
rule %r(
|
179
|
+
(module)
|
180
|
+
(\s+)
|
181
|
+
([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)
|
182
|
+
)x do
|
183
|
+
groups Keyword, Text, Name::Namespace
|
184
|
+
end
|
185
|
+
|
186
|
+
rule %r/(def\b)(\s*)/ do
|
187
|
+
groups Keyword, Text
|
188
|
+
push :funcname
|
189
|
+
end
|
190
|
+
|
191
|
+
rule %r/(class\b)(\s*)/ do
|
192
|
+
groups Keyword, Text
|
193
|
+
push :classname
|
194
|
+
end
|
195
|
+
|
196
|
+
rule %r/(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
|
197
|
+
rule %r/(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
|
198
|
+
rule %r/(?<!\.)(?:#{builtins_g.join('|')})\b/,
|
199
|
+
Name::Builtin, :method_call
|
200
|
+
|
201
|
+
mixin :has_heredocs
|
202
|
+
|
203
|
+
# `..` and `...` for ranges must have higher priority than `.`
|
204
|
+
# Otherwise, they will be parsed as :method_call
|
205
|
+
rule %r/\.{2,3}/, Operator, :expr_start
|
206
|
+
|
207
|
+
rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
|
208
|
+
rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
|
209
|
+
groups Punctuation, Text, Name::Function
|
210
|
+
push :method_call
|
211
|
+
end
|
212
|
+
|
213
|
+
rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
|
214
|
+
rule %r/[a-zA-Z_]\w*/, Name, :method_call
|
215
|
+
rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
|
216
|
+
Operator, :expr_start
|
217
|
+
rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
|
218
|
+
rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
|
219
|
+
rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
|
220
|
+
rule %r<[\])}]>, Punctuation
|
221
|
+
end
|
222
|
+
|
223
|
+
state :has_heredocs do
|
224
|
+
rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
|
225
|
+
token Operator, m[1]
|
226
|
+
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
|
227
|
+
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
|
228
|
+
push :heredoc_queue unless state? :heredoc_queue
|
229
|
+
end
|
230
|
+
|
231
|
+
rule %r/(<<[-~]?)(["'])(\2)/ do |m|
|
232
|
+
token Operator, m[1]
|
233
|
+
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
|
234
|
+
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
|
235
|
+
push :heredoc_queue unless state? :heredoc_queue
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
state :heredoc_queue do
|
240
|
+
rule %r/(?=\n)/ do
|
241
|
+
goto :resolve_heredocs
|
242
|
+
end
|
243
|
+
|
244
|
+
mixin :root
|
245
|
+
end
|
246
|
+
|
247
|
+
state :resolve_heredocs do
|
248
|
+
mixin :string_intp_escaped
|
249
|
+
|
250
|
+
rule %r/\n/, Str::Heredoc, :test_heredoc
|
251
|
+
rule %r/[#\\\n]/, Str::Heredoc
|
252
|
+
rule %r/[^#\\\n]+/, Str::Heredoc
|
253
|
+
end
|
254
|
+
|
255
|
+
state :test_heredoc do
|
256
|
+
rule %r/[^#\\\n]*$/ do |m|
|
257
|
+
tolerant, heredoc_name = @heredoc_queue.first
|
258
|
+
check = tolerant ? m[0].strip : m[0].rstrip
|
259
|
+
|
260
|
+
# check if we found the end of the heredoc
|
261
|
+
puts " end heredoc check #{check.inspect} = #{heredoc_name.inspect}" if @debug
|
262
|
+
if check == heredoc_name
|
263
|
+
@heredoc_queue.shift
|
264
|
+
# if there's no more, we're done looking.
|
265
|
+
pop! if @heredoc_queue.empty?
|
266
|
+
token Name::Constant
|
267
|
+
else
|
268
|
+
token Str::Heredoc
|
269
|
+
end
|
270
|
+
|
271
|
+
pop!
|
272
|
+
end
|
273
|
+
|
274
|
+
rule(//) { pop! }
|
275
|
+
end
|
276
|
+
|
277
|
+
state :funcname do
|
278
|
+
rule %r/\s+/, Text
|
279
|
+
rule %r/\(/, Punctuation, :defexpr
|
280
|
+
rule %r(
|
281
|
+
(?:([a-zA-Z_]\w*)(\.))?
|
282
|
+
(
|
283
|
+
[a-zA-Z_]\w*[!?]? |
|
284
|
+
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
|
285
|
+
<<? | >>? | <=>? | >= | ===?
|
286
|
+
)
|
287
|
+
)x do |m|
|
288
|
+
puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
|
289
|
+
groups Name::Class, Operator, Name::Function
|
290
|
+
pop!
|
291
|
+
end
|
292
|
+
|
293
|
+
rule(//) { pop! }
|
294
|
+
end
|
295
|
+
|
296
|
+
state :classname do
|
297
|
+
rule %r/\s+/, Text
|
298
|
+
rule %r/\(/ do
|
299
|
+
token Punctuation
|
300
|
+
push :defexpr
|
301
|
+
push :expr_start
|
302
|
+
end
|
303
|
+
|
304
|
+
# class << expr
|
305
|
+
rule %r/<</ do
|
306
|
+
token Operator
|
307
|
+
goto :expr_start
|
308
|
+
end
|
309
|
+
|
310
|
+
rule %r/[A-Z_]\w*/, Name::Class, :pop!
|
311
|
+
|
312
|
+
rule(//) { pop! }
|
313
|
+
end
|
314
|
+
|
315
|
+
state :ternary do
|
316
|
+
rule(/:(?!:)/) { token Punctuation; goto :expr_start }
|
317
|
+
|
318
|
+
mixin :root
|
319
|
+
end
|
320
|
+
|
321
|
+
state :defexpr do
|
322
|
+
rule %r/(\))(\.|::)?/ do
|
323
|
+
groups Punctuation, Operator
|
324
|
+
pop!
|
325
|
+
end
|
326
|
+
rule %r/\(/ do
|
327
|
+
token Punctuation
|
328
|
+
push :defexpr
|
329
|
+
push :expr_start
|
330
|
+
end
|
331
|
+
|
332
|
+
mixin :root
|
333
|
+
end
|
334
|
+
|
335
|
+
state :in_interp do
|
336
|
+
rule %r/}/, Str::Interpol, :pop!
|
337
|
+
mixin :root
|
338
|
+
end
|
339
|
+
|
340
|
+
state :string_intp do
|
341
|
+
rule %r/[#][{]/, Str::Interpol, :in_interp
|
342
|
+
rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
|
343
|
+
end
|
344
|
+
|
345
|
+
state :string_intp_escaped do
|
346
|
+
mixin :string_intp
|
347
|
+
rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
|
348
|
+
Str::Escape
|
349
|
+
rule %r/\\./, Str::Escape
|
350
|
+
end
|
351
|
+
|
352
|
+
state :method_call do
|
353
|
+
rule %r(/) do
|
354
|
+
token Operator
|
355
|
+
goto :expr_start
|
356
|
+
end
|
357
|
+
|
358
|
+
rule(/(?=\n)/) { pop! }
|
359
|
+
|
360
|
+
rule(//) { goto :method_call_spaced }
|
361
|
+
end
|
362
|
+
|
363
|
+
state :method_call_spaced do
|
364
|
+
mixin :whitespace
|
365
|
+
|
366
|
+
rule %r([%/]=) do
|
367
|
+
token Operator
|
368
|
+
goto :expr_start
|
369
|
+
end
|
370
|
+
|
371
|
+
rule %r((/)(?=\S|\s*/)) do
|
372
|
+
token Str::Regex
|
373
|
+
goto :slash_regex
|
374
|
+
end
|
375
|
+
|
376
|
+
mixin :sigil_strings
|
377
|
+
|
378
|
+
rule(%r((?=\s*/))) { pop! }
|
379
|
+
|
380
|
+
rule(/\s+/) { token Text; goto :expr_start }
|
381
|
+
rule(//) { pop! }
|
382
|
+
end
|
383
|
+
|
384
|
+
state :expr_start do
|
385
|
+
mixin :inline_whitespace
|
386
|
+
|
387
|
+
rule %r(/) do
|
388
|
+
token Str::Regex
|
389
|
+
goto :slash_regex
|
390
|
+
end
|
391
|
+
|
392
|
+
# char operator. ?x evaulates to "x", unless there's a digit
|
393
|
+
# beforehand like x>=0?n[x]:""
|
394
|
+
rule %r(
|
395
|
+
[?](\\[MC]-)* # modifiers
|
396
|
+
(\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
|
397
|
+
(?!\w)
|
398
|
+
)x, Str::Char, :pop!
|
399
|
+
|
400
|
+
# special case for using a single space. Ruby demands that
|
401
|
+
# these be in a single line, otherwise it would make no sense.
|
402
|
+
rule %r/(\s*)(%[rqswQWxiI]? \S* )/ do
|
403
|
+
groups Text, Str::Other
|
404
|
+
pop!
|
405
|
+
end
|
406
|
+
|
407
|
+
mixin :sigil_strings
|
408
|
+
|
409
|
+
rule(//) { pop! }
|
410
|
+
end
|
411
|
+
|
412
|
+
state :slash_regex do
|
413
|
+
mixin :string_intp
|
414
|
+
rule %r(\\\\), Str::Regex
|
415
|
+
rule %r(\\/), Str::Regex
|
416
|
+
rule %r([\\#]), Str::Regex
|
417
|
+
rule %r([^\\/#]+)m, Str::Regex
|
418
|
+
rule %r(/) do
|
419
|
+
token Str::Regex
|
420
|
+
goto :regex_flags
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
state :end_part do
|
425
|
+
# eat up the rest of the stream as Comment::Preproc
|
426
|
+
rule %r/.+/m, Comment::Preproc, :pop!
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|