rouge 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/Gemfile +2 -0
  2. data/lib/rouge/cli.rb +15 -0
  3. data/lib/rouge/demos/matlab +6 -0
  4. data/lib/rouge/demos/ocaml +12 -0
  5. data/lib/rouge/demos/scala +3 -0
  6. data/lib/rouge/demos/sml +4 -0
  7. data/lib/rouge/demos/vb +4 -0
  8. data/lib/rouge/formatters/html.rb +13 -17
  9. data/lib/rouge/formatters/terminal256.rb +2 -2
  10. data/lib/rouge/lexer.rb +12 -14
  11. data/lib/rouge/lexers/coffeescript.rb +2 -4
  12. data/lib/rouge/lexers/common_lisp.rb +2 -4
  13. data/lib/rouge/lexers/erlang.rb +4 -13
  14. data/lib/rouge/lexers/factor.rb +25 -24
  15. data/lib/rouge/lexers/gherkin.rb +6 -6
  16. data/lib/rouge/lexers/groovy.rb +1 -2
  17. data/lib/rouge/lexers/haml.rb +2 -2
  18. data/lib/rouge/lexers/haskell.rb +18 -20
  19. data/lib/rouge/lexers/http.rb +13 -12
  20. data/lib/rouge/lexers/ini.rb +1 -2
  21. data/lib/rouge/lexers/java.rb +1 -2
  22. data/lib/rouge/lexers/lua.rb +1 -1
  23. data/lib/rouge/lexers/make.rb +4 -5
  24. data/lib/rouge/lexers/markdown.rb +4 -12
  25. data/lib/rouge/lexers/matlab.rb +71 -0
  26. data/lib/rouge/lexers/matlab/builtins.rb +10 -0
  27. data/lib/rouge/lexers/nginx.rb +3 -4
  28. data/lib/rouge/lexers/objective_c.rb +1 -1
  29. data/lib/rouge/lexers/ocaml.rb +109 -0
  30. data/lib/rouge/lexers/perl.rb +2 -5
  31. data/lib/rouge/lexers/php.rb +5 -5
  32. data/lib/rouge/lexers/php/builtins.rb +4 -2
  33. data/lib/rouge/lexers/puppet.rb +1 -2
  34. data/lib/rouge/lexers/python.rb +5 -11
  35. data/lib/rouge/lexers/racket.rb +1 -3
  36. data/lib/rouge/lexers/ruby.rb +8 -8
  37. data/lib/rouge/lexers/rust.rb +3 -3
  38. data/lib/rouge/lexers/sass/common.rb +4 -4
  39. data/lib/rouge/lexers/scala.rb +141 -0
  40. data/lib/rouge/lexers/scheme.rb +1 -3
  41. data/lib/rouge/lexers/sed.rb +4 -4
  42. data/lib/rouge/lexers/shell.rb +1 -2
  43. data/lib/rouge/lexers/smalltalk.rb +6 -7
  44. data/lib/rouge/lexers/sml.rb +236 -6
  45. data/lib/rouge/lexers/tex.rb +1 -4
  46. data/lib/rouge/lexers/toml.rb +1 -2
  47. data/lib/rouge/lexers/vb.rb +162 -0
  48. data/lib/rouge/lexers/viml.rb +1 -1
  49. data/lib/rouge/lexers/yaml.rb +10 -11
  50. data/lib/rouge/regex_lexer.rb +77 -92
  51. data/lib/rouge/token.rb +3 -3
  52. data/lib/rouge/util.rb +4 -4
  53. data/lib/rouge/version.rb +1 -1
  54. metadata +13 -4
@@ -40,12 +40,14 @@ module Rouge
40
40
  b["Exif"] = Set.new %w(exif_imagetype exif_imagetype exif_read_data exif_tagname exif_thumbnail read_exif_data exif_imagetype)
41
41
  b["Expect"] = Set.new %w(expect_expectl expect_expectl expect_popen expect_expectl)
42
42
  b["FAM"] = Set.new %w(fam_cancel_monitor fam_cancel_monitor fam_close fam_monitor_collection fam_monitor_directory fam_monitor_file fam_next_event fam_open fam_pending fam_resume_monitor fam_suspend_monitor fam_cancel_monitor)
43
+ b["Fann"] = Set.new %w(fann_cascadetrain_on_data fann_cascadetrain_on_data fann_cascadetrain_on_file fann_clear_scaling_params fann_copy fann_create_from_file fann_create_shortcut_array fann_create_shortcut fann_create_sparse_array fann_create_sparse fann_create_standard_array fann_create_standard fann_create_train_from_callback fann_create_train fann_descale_input fann_descale_output fann_descale_train fann_destroy_train fann_destroy fann_duplicate_train_data fann_get_activation_function fann_get_activation_steepness fann_get_bias_array fann_get_bit_fail_limit fann_get_bit_fail fann_get_cascade_activation_functions_count fann_get_cascade_activation_functions fann_get_cascade_activation_steepnesses_count fann_get_cascade_activation_steepnesses fann_get_cascade_candidate_change_fraction fann_get_cascade_candidate_limit fann_get_cascade_candidate_stagnation_epochs fann_get_cascade_max_cand_epochs fann_get_cascade_max_out_epochs fann_get_cascade_min_cand_epochs fann_get_cascade_min_out_epochs fann_get_cascade_num_candidate_groups fann_get_cascade_num_candidates fann_get_cascade_output_change_fraction fann_get_cascade_output_stagnation_epochs fann_get_cascade_weight_multiplier fann_get_connection_array fann_get_connection_rate fann_get_errno fann_get_errstr fann_get_layer_array fann_get_learning_momentum fann_get_learning_rate fann_get_MSE fann_get_network_type fann_get_num_input fann_get_num_layers fann_get_num_output fann_get_quickprop_decay fann_get_quickprop_mu fann_get_rprop_decrease_factor fann_get_rprop_delta_max fann_get_rprop_delta_min fann_get_rprop_delta_zero fann_get_rprop_increase_factor fann_get_sarprop_step_error_shift fann_get_sarprop_step_error_threshold_factor fann_get_sarprop_temperature fann_get_sarprop_weight_decay_shift fann_get_total_connections fann_get_total_neurons fann_get_train_error_function fann_get_train_stop_function fann_get_training_algorithm fann_init_weights fann_length_train_data fann_merge_train_data fann_num_input_train_data fann_num_output_train_data fann_print_error fann_randomize_weights fann_read_train_from_file fann_reset_errno fann_reset_errstr fann_reset_MSE fann_run fann_save_train fann_save fann_scale_input_train_data fann_scale_input fann_scale_output_train_data fann_scale_output fann_scale_train_data fann_scale_train fann_set_activation_function_hidden fann_set_activation_function_layer fann_set_activation_function_output fann_set_activation_function fann_set_activation_steepness_hidden fann_set_activation_steepness_layer fann_set_activation_steepness_output fann_set_activation_steepness fann_set_bit_fail_limit fann_set_callback fann_set_cascade_activation_functions fann_set_cascade_activation_steepnesses fann_set_cascade_candidate_change_fraction fann_set_cascade_candidate_limit fann_set_cascade_candidate_stagnation_epochs fann_set_cascade_max_cand_epochs fann_set_cascade_max_out_epochs fann_set_cascade_min_cand_epochs fann_set_cascade_min_out_epochs fann_set_cascade_num_candidate_groups fann_set_cascade_output_change_fraction fann_set_cascade_output_stagnation_epochs fann_set_cascade_weight_multiplier fann_set_error_log fann_set_input_scaling_params fann_set_learning_momentum fann_set_learning_rate fann_set_output_scaling_params fann_set_quickprop_decay fann_set_quickprop_mu fann_set_rprop_decrease_factor fann_set_rprop_delta_max fann_set_rprop_delta_min fann_set_rprop_delta_zero fann_set_rprop_increase_factor fann_set_sarprop_step_error_shift fann_set_sarprop_step_error_threshold_factor fann_set_sarprop_temperature fann_set_sarprop_weight_decay_shift fann_set_scaling_params fann_set_train_error_function fann_set_train_stop_function fann_set_training_algorithm fann_set_weight_array fann_set_weight fann_shuffle_train_data fann_subset_train_data fann_test_data fann_test fann_train_epoch fann_train_on_data fann_train_on_file fann_train fann_cascadetrain_on_data)
43
44
  b["FrontBase"] = Set.new %w(fbsql_affected_rows fbsql_affected_rows fbsql_autocommit fbsql_blob_size fbsql_change_user fbsql_clob_size fbsql_close fbsql_commit fbsql_connect fbsql_create_blob fbsql_create_clob fbsql_create_db fbsql_data_seek fbsql_database_password fbsql_database fbsql_db_query fbsql_db_status fbsql_drop_db fbsql_errno fbsql_error fbsql_fetch_array fbsql_fetch_assoc fbsql_fetch_field fbsql_fetch_lengths fbsql_fetch_object fbsql_fetch_row fbsql_field_flags fbsql_field_len fbsql_field_name fbsql_field_seek fbsql_field_table fbsql_field_type fbsql_free_result fbsql_get_autostart_info fbsql_hostname fbsql_insert_id fbsql_list_dbs fbsql_list_fields fbsql_list_tables fbsql_next_result fbsql_num_fields fbsql_num_rows fbsql_password fbsql_pconnect fbsql_query fbsql_read_blob fbsql_read_clob fbsql_result fbsql_rollback fbsql_rows_fetched fbsql_select_db fbsql_set_characterset fbsql_set_lob_mode fbsql_set_password fbsql_set_transaction fbsql_start_db fbsql_stop_db fbsql_table_name fbsql_tablename fbsql_username fbsql_warnings fbsql_affected_rows)
44
45
  b["FDF"] = Set.new %w(fdf_add_doc_javascript fdf_add_doc_javascript fdf_add_template fdf_close fdf_create fdf_enum_values fdf_errno fdf_error fdf_get_ap fdf_get_attachment fdf_get_encoding fdf_get_file fdf_get_flags fdf_get_opt fdf_get_status fdf_get_value fdf_get_version fdf_header fdf_next_field_name fdf_open_string fdf_open fdf_remove_item fdf_save_string fdf_save fdf_set_ap fdf_set_encoding fdf_set_file fdf_set_flags fdf_set_javascript_action fdf_set_on_import_javascript fdf_set_opt fdf_set_status fdf_set_submit_form_action fdf_set_target_frame fdf_set_value fdf_set_version fdf_add_doc_javascript)
45
46
  b["Fileinfo"] = Set.new %w(finfo_buffer finfo_buffer finfo_close finfo_file finfo_open finfo_set_flags mime_content_type finfo_buffer)
46
47
  b["filePro"] = Set.new %w(filepro_fieldcount filepro_fieldcount filepro_fieldname filepro_fieldtype filepro_fieldwidth filepro_retrieve filepro_rowcount filepro filepro_fieldcount)
47
48
  b["Filesystem"] = Set.new %w(basename basename chgrp chmod chown clearstatcache copy delete dirname disk_free_space disk_total_space diskfreespace fclose feof fflush fgetc fgetcsv fgets fgetss file_exists file_get_contents file_put_contents file fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype flock fnmatch fopen fpassthru fputcsv fputs fread fscanf fseek fstat ftell ftruncate fwrite glob is_dir is_executable is_file is_link is_readable is_uploaded_file is_writable is_writeable lchgrp lchown link linkinfo lstat mkdir move_uploaded_file parse_ini_file parse_ini_string pathinfo pclose popen readfile readlink realpath_cache_get realpath_cache_size realpath rename rewind rmdir set_file_buffer stat symlink tempnam tmpfile touch umask unlink basename)
48
49
  b["Filter"] = Set.new %w(filter_has_var filter_has_var filter_id filter_input_array filter_input filter_list filter_var_array filter_var filter_has_var)
50
+ b["FPM"] = Set.new %w(fastcgi_finish_request fastcgi_finish_request fastcgi_finish_request)
49
51
  b["FriBiDi"] = Set.new %w(fribidi_log2vis fribidi_log2vis fribidi_log2vis)
50
52
  b["FTP"] = Set.new %w(ftp_alloc ftp_alloc ftp_cdup ftp_chdir ftp_chmod ftp_close ftp_connect ftp_delete ftp_exec ftp_fget ftp_fput ftp_get_option ftp_get ftp_login ftp_mdtm ftp_mkdir ftp_nb_continue ftp_nb_fget ftp_nb_fput ftp_nb_get ftp_nb_put ftp_nlist ftp_pasv ftp_put ftp_pwd ftp_quit ftp_raw ftp_rawlist ftp_rename ftp_rmdir ftp_set_option ftp_site ftp_size ftp_ssl_connect ftp_systype ftp_alloc)
51
53
  b["Function handling"] = Set.new %w(call_user_func_array call_user_func_array call_user_func create_function forward_static_call_array forward_static_call func_get_arg func_get_args func_num_args function_exists get_defined_functions register_shutdown_function register_tick_function unregister_tick_function call_user_func_array)
@@ -113,8 +115,8 @@ module Rouge
113
115
  b["NSAPI"] = Set.new %w(nsapi_request_headers nsapi_request_headers nsapi_response_headers nsapi_virtual nsapi_request_headers)
114
116
  b["OAuth"] = Set.new %w(oauth_get_sbs oauth_get_sbs oauth_urlencode oauth_get_sbs)
115
117
  b["Object Aggregation"] = Set.new %w(aggregate_info aggregate_info aggregate_methods_by_list aggregate_methods_by_regexp aggregate_methods aggregate_properties_by_list aggregate_properties_by_regexp aggregate_properties aggregate aggregation_info deaggregate aggregate_info)
116
- b["OCI8"] = Set.new %w(oci_bind_array_by_name oci_bind_by_name oci_cancel oci_client_version oci_close oci_commit oci_connect oci_define_by_name oci_error oci_execute oci_fetch_all oci_fetch_array oci_fetch_assoc oci_fetch_object oci_fetch_row oci_fetch oci_field_is_null oci_field_name oci_field_precision oci_field_scale oci_field_size oci_field_type_raw oci_field_type oci_free_descriptor oci_free_statement oci_internal_debug oci_lob_copy oci_lob_is_equal oci_new_collection oci_new_connect oci_new_cursor oci_new_descriptor oci_num_fields oci_num_rows oci_parse oci_password_change oci_pconnect oci_result oci_rollback oci_server_version oci_set_action oci_set_client_identifier oci_set_client_info oci_set_edition oci_set_module_name oci_set_prefetch oci_statement_type)
117
- b["OPcache"] = Set.new %w(opcache_invalidate opcache_invalidate opcache_reset opcache_invalidate)
118
+ b["OCI8"] = Set.new %w(oci_bind_array_by_name oci_bind_array_by_name oci_bind_by_name oci_cancel oci_client_version oci_close oci_commit oci_connect oci_define_by_name oci_error oci_execute oci_fetch_all oci_fetch_array oci_fetch_assoc oci_fetch_object oci_fetch_row oci_fetch oci_field_is_null oci_field_name oci_field_precision oci_field_scale oci_field_size oci_field_type_raw oci_field_type oci_free_descriptor oci_free_statement oci_get_implicit_resultset oci_internal_debug oci_lob_copy oci_lob_is_equal oci_new_collection oci_new_connect oci_new_cursor oci_new_descriptor oci_num_fields oci_num_rows oci_parse oci_password_change oci_pconnect oci_result oci_rollback oci_server_version oci_set_action oci_set_client_identifier oci_set_client_info oci_set_edition oci_set_module_name oci_set_prefetch oci_statement_type oci_bind_array_by_name)
119
+ b["OPcache"] = Set.new %w(opcache_compile_file opcache_compile_file opcache_invalidate opcache_reset opcache_compile_file)
118
120
  b["OpenAL"] = Set.new %w(openal_buffer_create openal_buffer_create openal_buffer_data openal_buffer_destroy openal_buffer_get openal_buffer_loadwav openal_context_create openal_context_current openal_context_destroy openal_context_process openal_context_suspend openal_device_close openal_device_open openal_listener_get openal_listener_set openal_source_create openal_source_destroy openal_source_get openal_source_pause openal_source_play openal_source_rewind openal_source_set openal_source_stop openal_stream openal_buffer_create)
119
121
  b["OpenSSL"] = Set.new %w(openssl_cipher_iv_length openssl_cipher_iv_length openssl_csr_export_to_file openssl_csr_export openssl_csr_get_public_key openssl_csr_get_subject openssl_csr_new openssl_csr_sign openssl_decrypt openssl_dh_compute_key openssl_digest openssl_encrypt openssl_error_string openssl_free_key openssl_get_cipher_methods openssl_get_md_methods openssl_get_privatekey openssl_get_publickey openssl_open openssl_pbkdf2 openssl_pkcs12_export_to_file openssl_pkcs12_export openssl_pkcs12_read openssl_pkcs7_decrypt openssl_pkcs7_encrypt openssl_pkcs7_sign openssl_pkcs7_verify openssl_pkey_export_to_file openssl_pkey_export openssl_pkey_free openssl_pkey_get_details openssl_pkey_get_private openssl_pkey_get_public openssl_pkey_new openssl_private_decrypt openssl_private_encrypt openssl_public_decrypt openssl_public_encrypt openssl_random_pseudo_bytes openssl_seal openssl_sign openssl_verify openssl_x509_check_private_key openssl_x509_checkpurpose openssl_x509_export_to_file openssl_x509_export openssl_x509_free openssl_x509_parse openssl_x509_read openssl_cipher_iv_length)
120
122
  b["Output Control"] = Set.new %w(flush flush ob_clean ob_end_clean ob_end_flush ob_flush ob_get_clean ob_get_contents ob_get_flush ob_get_length ob_get_level ob_get_status ob_gzhandler ob_implicit_flush ob_list_handlers ob_start output_add_rewrite_var output_reset_rewrite_vars flush)
@@ -67,8 +67,7 @@ module Rouge
67
67
  rule %r([<>!+*/-]), Operator
68
68
 
69
69
  rule /(class|include)(\s*)(#{qualname})/ do
70
- group Keyword; group Text
71
- group Name::Class
70
+ groups Keyword, Text, Name::Class
72
71
  end
73
72
 
74
73
  rule /node\b/, Keyword, :regex_allowed
@@ -52,9 +52,7 @@ module Rouge
52
52
  state :root do
53
53
  rule /\n+/m, Text
54
54
  rule /^(:)(\s*)([ru]{,2}""".*?""")/mi do
55
- group Punctuation
56
- group Text
57
- group Str::Doc
55
+ groups Punctuation, Text, Str::Doc
58
56
  end
59
57
 
60
58
  rule /[^\S\n]+/, Text
@@ -69,26 +67,22 @@ module Rouge
69
67
  rule /(?:#{keywords.join('|')})\b/, Keyword
70
68
 
71
69
  rule /(def)((?:\s|\\\s)+)/ do
72
- group Keyword # def
73
- group Text # whitespae
70
+ groups Keyword, Text
74
71
  push :funcname
75
72
  end
76
73
 
77
74
  rule /(class)((?:\s|\\\s)+)/ do
78
- group Keyword
79
- group Text
75
+ groups Keyword, Text
80
76
  push :classname
81
77
  end
82
78
 
83
79
  rule /(from)((?:\s|\\\s)+)/ do
84
- group Keyword::Namespace
85
- group Text
80
+ groups Keyword::Namespace, Text
86
81
  push :fromimport
87
82
  end
88
83
 
89
84
  rule /(import)((?:\s|\\\s)+)/ do
90
- group Keyword::Namespace
91
- group Text
85
+ groups Keyword::Namespace, Text
92
86
  push :import
93
87
  end
94
88
 
@@ -510,9 +510,7 @@ module Rouge
510
510
  rule /(?:'|#|`|,@|,|\.)/, Operator
511
511
 
512
512
  rule /(['#])(\s*)(\()/m do
513
- group Str::Symbol
514
- group Text
515
- group Punctuation
513
+ groups Str::Symbol, Text, Punctuation
516
514
  end
517
515
 
518
516
  # () [] {} are all permitted as like pairs
@@ -42,8 +42,8 @@ module Rouge
42
42
  interp = /[rQWxI]/ === m[1]
43
43
  toktype = Str::Other
44
44
 
45
- debug { " open: #{open.inspect}" }
46
- debug { " close: #{close.inspect}" }
45
+ puts " open: #{open.inspect}" if @debug
46
+ puts " close: #{close.inspect}" if @debug
47
47
 
48
48
  # regexes
49
49
  if m[1] == 'r'
@@ -241,17 +241,17 @@ module Rouge
241
241
  tolerant, heredoc_name = @heredoc_queue.first
242
242
  check = tolerant ? m[2].strip : m[2].rstrip
243
243
 
244
- group Str::Heredoc
245
-
246
244
  # check if we found the end of the heredoc
247
- if check == heredoc_name
248
- group Name::Constant
245
+ line_tok = if check == heredoc_name
249
246
  @heredoc_queue.shift
250
247
  # if there's no more, we're done looking.
251
248
  pop! if @heredoc_queue.empty?
249
+ Name::Constant
252
250
  else
253
- group Str::Heredoc
251
+ Str::Heredoc
254
252
  end
253
+
254
+ groups(Str::Heredoc, line_tok)
255
255
  end
256
256
 
257
257
  rule /[#\\\n]/, Str::Heredoc
@@ -269,7 +269,7 @@ module Rouge
269
269
  <<? | >>? | <=>? | >= | ===?
270
270
  )
271
271
  )x do |m|
272
- debug { "matches: #{[m[0], m[1], m[2], m[3]].inspect}" }
272
+ puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
273
273
  groups Name::Class, Operator, Name::Function
274
274
  pop!
275
275
  end
@@ -87,7 +87,7 @@ module Rouge
87
87
  rule /([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
88
88
  rule /[.]\s*#{id}/, Name::Property
89
89
  rule /(#{id})(::)/m do
90
- group Name::Namespace; group Punctuation
90
+ groups Name::Namespace, Punctuation
91
91
  end
92
92
 
93
93
  # macros
@@ -109,13 +109,13 @@ module Rouge
109
109
 
110
110
  rule /[\[{(]/ do |m|
111
111
  @macro_delims[delim_map[m[0]]] += 1
112
- debug { " macro_delims: #{@macro_delims.inspect}" }
112
+ puts " macro_delims: #{@macro_delims.inspect}" if @debug
113
113
  token Punctuation
114
114
  end
115
115
 
116
116
  rule /[\]})]/ do |m|
117
117
  @macro_delims[m[0]] -= 1
118
- debug { " macro_delims: #{@macro_delims.inspect}" }
118
+ puts " macro_delims: #{@macro_delims.inspect}" if @debug
119
119
  pop! if macro_closed?
120
120
  token Punctuation
121
121
  end
@@ -8,14 +8,14 @@ module Rouge
8
8
  rule /@for\b/, Keyword, :for
9
9
  rule /@(debug|warn|if|while)/, Keyword, :value
10
10
  rule /(@mixin)(\s+)(#{id})/ do
11
- group Keyword; group Text; group Name::Function
11
+ groups Keyword, Text, Name::Function
12
12
  push :value
13
13
  end
14
14
 
15
15
  rule /@extend\b/, Keyword, :selector
16
16
 
17
17
  rule /(@include)(\s+)(#{id})/ do
18
- group Keyword; group Text; group Name::Decorator
18
+ groups Keyword, Text, Name::Decorator
19
19
  push :value
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ module Rouge
23
23
 
24
24
  # $variable: assignment
25
25
  rule /([$]#{id})([ \t]*)(:)/ do
26
- group Name::Variable; group Text; group Punctuation
26
+ groups Name::Variable, Text, Punctuation
27
27
  push :value
28
28
  end
29
29
  end
@@ -157,7 +157,7 @@ module Rouge
157
157
  mixin :attr_common
158
158
 
159
159
  rule /([ \t]*)(:)/ do
160
- group Text; group Punctuation
160
+ groups Text, Punctuation
161
161
  push :value
162
162
  end
163
163
  end
@@ -0,0 +1,141 @@
1
+ # -*- coding: utf-8 #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Scala < RegexLexer
6
+ desc "The Scala programming language (scala-lang.org)"
7
+ tag 'scala'
8
+ aliases 'scala'
9
+ filenames '*.scala', '*.sbt'
10
+
11
+ mimetypes 'text/x-scala', 'application/x-scala'
12
+
13
+ # As documented in the ENBF section of the scala specification
14
+ # http://www.scala-lang.org/docu/files/ScalaReference.pdf
15
+ whitespace = /\p{Space}/
16
+ letter = /[\p{L}$_]/
17
+ upper = /[\p{Lu}$_]/
18
+ digits = /[0-9]/
19
+ parens = /[(){}\[\]]/
20
+ delims = %r([‘’".;,])
21
+
22
+ # negative lookahead to filter out other classes
23
+ op = %r(
24
+ (?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims})
25
+ [\u0020-\u007F\p{Sm}\p{So}]
26
+ )x
27
+
28
+ idrest = %r(#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?)x
29
+
30
+ keywords = %w(
31
+ abstract case catch def do else extends final finally for forSome
32
+ if implicit lazy match new override private protected requires return
33
+ sealed super this throw try val var while with yield
34
+ )
35
+
36
+ state :root do
37
+ rule /(class|trait|object)(\s+)/ do
38
+ groups Keyword, Text
39
+ push :class
40
+ end
41
+ rule /'#{idrest}[^']/, Str::Symbol
42
+ rule /[^\S\n]+/, Text
43
+
44
+ rule %r(//.*?\n), Comment::Single
45
+ rule %r(/\*), Comment::Multiline, :comment
46
+
47
+ rule /@#{idrest}/, Name::Decorator
48
+ rule %r(
49
+ (#{keywords.join("|")})\b|
50
+ (<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\s)|$)
51
+ )x, Keyword
52
+ rule /:(?!#{op})/, Keyword, :type
53
+ rule /#{upper}#{idrest}\b/, Name::Class
54
+ rule /(true|false|null)\b/, Keyword::Constant
55
+ rule /(import|package)(\s+)/ do
56
+ groups Keyword, Text
57
+ push :import
58
+ end
59
+
60
+ rule /(type)(\s+)/ do
61
+ groups Keyword, Text
62
+ push :type
63
+ end
64
+
65
+ rule /""".*?"""(?!")/m, Str
66
+ rule /"(\\\\|\\"|[^"])*"/, Str
67
+ rule /'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'/, Str::Char
68
+
69
+ rule idrest, Name
70
+ rule /`[^`]+`/, Name
71
+
72
+ rule /\[/, Operator, :typeparam
73
+ rule /[\(\)\{\};,.#]/, Operator
74
+ rule /#{op}+/, Operator
75
+
76
+ rule /([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?/, Num::Float
77
+ rule /([0-9][0-9]*[fFdD])/, Num::Float
78
+ rule /0x[0-9a-fA-F]+/, Num::Hex
79
+ rule /[0-9]+L?/, Num::Integer
80
+ rule /\n/, Text
81
+ end
82
+
83
+ state :class do
84
+ rule /(#{idrest}|#{op}+|`[^`]+`)(\s*)(\[)/ do
85
+ groups Name::Class, Text, Operator
86
+ push :typeparam
87
+ end
88
+
89
+ rule /\s+/, Text
90
+ rule /{/, Operator, :pop!
91
+ rule /\(/, Operator, :pop!
92
+ rule %r(//.*?\n), Comment::Single, :pop!
93
+ rule %r(#{idrest}|#{op}+|`[^`]+`), Name::Class, :pop!
94
+ end
95
+
96
+ state :type do
97
+ rule /\s+/, Text
98
+ rule /<[%:]|>:|[#_\u21D2]|forSome|type/, Keyword
99
+ rule /([,\);}]|=>|=)(\s*)/ do
100
+ groups Operator, Text
101
+ pop!
102
+ end
103
+ rule /[\(\{]/, Operator, :type
104
+
105
+ typechunk = /(?:#{idrest}|#{op}+\`[^`]+`)/
106
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)(\[)/ do
107
+ groups Keyword::Type, Text, Operator
108
+ pop!
109
+ push :typeparam
110
+ end
111
+
112
+ rule /(#{typechunk}(?:\.#{typechunk})*)(\s*)$/ do
113
+ groups Keyword::Type, Text
114
+ pop!
115
+ end
116
+
117
+ rule %r(//.*?\n), Comment::Single, :pop!
118
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
119
+ end
120
+
121
+ state :typeparam do
122
+ rule /[\s,]+/, Text
123
+ rule /<[%:]|=>|>:|[#_\u21D2]|forSome|type/, Keyword
124
+ rule /([\]\)\}])/, Operator, :pop!
125
+ rule /[\(\[\{]/, Operator, :typeparam
126
+ rule /\.|#{idrest}|#{op}+|`[^`]+`/, Keyword::Type
127
+ end
128
+
129
+ state :comment do
130
+ rule %r([^/\*]+), Comment::Multiline
131
+ rule %r(/\*), Comment::Multiline, :comment
132
+ rule %r(\*/), Comment::Multiline, :pop!
133
+ rule %r([*/]), Comment::Multiline
134
+ end
135
+
136
+ state :import do
137
+ rule %r((#{idrest}|\.)+), Name::Namespace, :pop!
138
+ end
139
+ end
140
+ end
141
+ end
@@ -79,9 +79,7 @@ module Rouge
79
79
  rule /(?:'|#|`|,@|,|\.)/, Operator
80
80
 
81
81
  rule /(['#])(\s*)(\()/m do
82
- group Str::Symbol
83
- group Text
84
- group Punctuation
82
+ groups Str::Symbol, Text, Punctuation
85
83
  end
86
84
 
87
85
  rule /\(/, Punctuation, :command
@@ -95,14 +95,14 @@ module Rouge
95
95
 
96
96
  # commands that take a text segment as an argument
97
97
  rule /([aic])(\s*)/ do
98
- group Keyword; group Text; goto :text
98
+ groups Keyword, Text; goto :text
99
99
  end
100
100
 
101
101
  rule /[pd]/, Keyword
102
102
 
103
103
  # commands that take a number argument
104
104
  rule /([qQl])(\s+)(\d+)/i do
105
- group Keyword; group Text; group Num
105
+ groups Keyword, Text, Num
106
106
  pop!
107
107
  end
108
108
 
@@ -111,13 +111,13 @@ module Rouge
111
111
 
112
112
  # commands that take a filename argument
113
113
  rule /([rRwW])(\s+)(\S+)/ do
114
- group Keyword; group Text; group Name
114
+ groups Keyword, Text, Name
115
115
  pop!
116
116
  end
117
117
 
118
118
  # commands that take a label argument
119
119
  rule /([:btT])(\s+)(\S+)/ do
120
- group Keyword; group Text; group Name::Label
120
+ groups Keyword, Text, Name::Label
121
121
  pop!
122
122
  end
123
123
  end
@@ -39,8 +39,7 @@ module Rouge
39
39
  rule /^\S*[\$%>#] +/, Generic::Prompt
40
40
 
41
41
  rule /(\b\w+)(=)/ do |m|
42
- group Name::Variable
43
- group Operator
42
+ groups Name::Variable, Operator
44
43
  end
45
44
 
46
45
  rule /[\[\]{}()=]/, Operator
@@ -12,14 +12,14 @@ module Rouge
12
12
 
13
13
  state :root do
14
14
  rule /(<)(\w+:)(.*?)(>)/ do
15
- group Punctuation; group Keyword; group Text; group Punctuation
15
+ groups Punctuation, Keyword, Text, Punctuation
16
16
  end
17
17
 
18
18
  # mixin :squeak_fileout
19
19
  mixin :whitespaces
20
20
  mixin :method_definition
21
21
  rule /([|])([\w\s]*)([|])/ do
22
- group Punctuation; group Name::Variable; group Punctuation
22
+ groups Punctuation, Name::Variable, Punctuation
23
23
  end
24
24
  mixin :objects
25
25
  rule /\^|:=|_/, Operator
@@ -30,23 +30,22 @@ module Rouge
30
30
 
31
31
  state :method_definition do
32
32
  rule /([a-z]\w*:)(\s*)(\w+)/i do
33
- group Name::Function; group Text; group Name::Variable
33
+ groups Name::Function, Text, Name::Variable
34
34
  end
35
35
 
36
36
  rule /^(\s*)(\b[a-z]\w*\b)(\s*)$/i do
37
- group Text; group Name::Function; group Text
37
+ groups Text, Name::Function, Text
38
38
  end
39
39
 
40
40
  rule %r(^(\s*)(#{ops}+)(\s*)(\w+)(\s*)$) do
41
- group Text; group Name::Function;
42
- group Text; group Name::Variable; group Text;
41
+ groups Text, Name::Function, Text, Name::Variable, Text
43
42
  end
44
43
  end
45
44
 
46
45
  state :block_variables do
47
46
  mixin :whitespaces
48
47
  rule /(:)(\s*)(\w+)/ do
49
- group Operator; group Text; group Name::Variable
48
+ groups Operator, Text, Name::Variable
50
49
  end
51
50
 
52
51
  rule /[|]/, Punctuation, :pop!
@@ -18,7 +18,11 @@ module Rouge
18
18
  )
19
19
  end
20
20
 
21
- id = /[a-z][\w']*/i
21
+ def self.symbolic_reserved
22
+ @symbolic_reserved ||= Set.new %w(: | = => -> # :>)
23
+ end
24
+
25
+ id = /[\w']+/i
22
26
  symbol = %r([!%&$#/:<=>?@\\~`^|*+-]+)
23
27
 
24
28
  def self.analyze_text(text)
@@ -75,10 +79,11 @@ module Rouge
75
79
  state :core do
76
80
  rule /[()\[\]{},;_]|[.][.][.]/, Punctuation
77
81
  rule /#"/, Str::Char, :char
82
+ rule /"/, Str::Double, :string
78
83
  rule /~?0x[0-9a-fA-F]+/, Num::Hex
79
84
  rule /0wx[0-9a-fA-F]+/, Num::Hex
80
85
  rule /0w\d+/, Num::Integer
81
- rule /~?\d+[.]\d+[eE]~?\d+/, Num::Float
86
+ rule /~?\d+([.]\d+)?[eE]~?\d+/, Num::Float
82
87
  rule /~?\d+[.]\d+/, Num::Float
83
88
  rule /~?\d+/, Num::Integer
84
89
 
@@ -98,10 +103,28 @@ module Rouge
98
103
  push :dotted
99
104
  end
100
105
 
101
- state :dotted do
102
- rule /(#{id})([.])/ do |m|
103
- groups(token_for_id_with_dot(m[1]), Punctuation)
104
- end
106
+ rule id do |m|
107
+ token token_for_id(m[0])
108
+ end
109
+
110
+ rule symbol do |m|
111
+ token token_for_id(m[0])
112
+ end
113
+ end
114
+
115
+ state :dotted do
116
+ rule /(#{id})([.])/ do |m|
117
+ groups(token_for_id_with_dot(m[1]), Punctuation)
118
+ end
119
+
120
+ rule id do |m|
121
+ token token_for_id(m[0])
122
+ pop!
123
+ end
124
+
125
+ rule symbol do |m|
126
+ token token_for_id(m[0])
127
+ pop!
105
128
  end
106
129
  end
107
130
 
@@ -109,6 +132,213 @@ module Rouge
109
132
  rule /#!.*?\n/, Comment::Preproc
110
133
  rule(//) { push :main }
111
134
  end
135
+
136
+ state :main do
137
+ mixin :whitespace
138
+
139
+ rule /\b(val|and)\b(?!')/, Keyword::Reserved, :vname
140
+ rule /\b(fun)\b(?!')/ do
141
+ token Keyword::Reserved
142
+ goto :main_fun
143
+ push :fname
144
+ end
145
+
146
+ mixin :delimiters
147
+ mixin :core
148
+ end
149
+
150
+ state :main_fun do
151
+ mixin :whitespace
152
+ rule /\b(fun|and)\b(?!')/, Keyword::Reserved, :fname
153
+ rule /\bval\b(?!')/ do
154
+ token Keyword::Reserved
155
+ goto :main
156
+ push :vname
157
+ end
158
+
159
+ rule /[|]/, Punctuation, :fname
160
+ rule /\b(case|handle)\b(?!')/ do
161
+ token Keyword::Reserved
162
+ goto :main
163
+ end
164
+
165
+ mixin :delimiters
166
+ mixin :core
167
+ end
168
+
169
+ state :has_escapes do
170
+ rule /\\[\\"abtnvfr]/, Str::Escape
171
+ rule /\\\^[\x40-\x5e]/, Str::Escape
172
+ rule /\\[0-9]{3}/, Str::Escape
173
+ rule /\\u\h{4}/, Str::Escape
174
+ rule /\\\s+\\/, Str::Interpol
175
+ end
176
+
177
+ state :string do
178
+ rule /[^"\\]+/, Str::Double
179
+ rule /"/, Str::Double, :pop!
180
+ mixin :has_escapes
181
+ end
182
+
183
+ state :char do
184
+ rule /[^"\\]+/, Str::Char
185
+ rule /"/, Str::Char, :pop!
186
+ mixin :has_escapes
187
+ end
188
+
189
+ state :breakout do
190
+ rule /(?=\w+\b(#{SML.keywords.to_a.join('|')})\b(?!'))/ do
191
+ pop!
192
+ end
193
+ end
194
+
195
+ state :sname do
196
+ mixin :whitespace
197
+ mixin :breakout
198
+ rule id, Name::Namespace
199
+ rule(//) { pop! }
200
+ end
201
+
202
+ state :has_annotations do
203
+ rule /'[\w']*/, Name::Decorator
204
+ rule /[(]/, Punctuation, :tyvarseq
205
+ end
206
+
207
+ state :fname do
208
+ mixin :whitespace
209
+ mixin :has_annotations
210
+
211
+ rule id, Name::Function, :pop!
212
+ rule symbol, Name::Function, :pop!
213
+ end
214
+
215
+ state :vname do
216
+ mixin :whitespace
217
+ mixin :has_annotations
218
+
219
+ rule /(#{id})(\s*)(=(?!#{symbol}))/m do
220
+ groups Name::Variable, Text, Punctuation
221
+ pop!
222
+ end
223
+
224
+ rule /(#{symbol})(\s*)(=(?!#{symbol}))/m do
225
+ groups Name::Variable, Text, Punctuation
226
+ end
227
+
228
+ rule id, Name::Variable, :pop!
229
+ rule symbol, Name::Variable, :pop!
230
+
231
+ rule(//) { pop! }
232
+ end
233
+
234
+ state :tname do
235
+ mixin :whitespace
236
+ mixin :breakout
237
+ mixin :has_annotations
238
+
239
+ rule /'[\w']*/, Name::Decorator
240
+ rule /[(]/, Punctuation, :tyvarseq
241
+
242
+ rule %r(=(?!#{symbol})) do
243
+ token Punctuation
244
+ goto :typbind
245
+ end
246
+
247
+ rule id, Keyword::Type
248
+ rule symbol, Keyword::Type
249
+ end
250
+
251
+ state :typbind do
252
+ mixin :whitespace
253
+
254
+ rule /\b(and)\b(?!')/ do
255
+ token Keyword::Reserved
256
+ goto :tname
257
+ end
258
+
259
+ mixin :breakout
260
+ mixin :core
261
+ end
262
+
263
+ state :dname do
264
+ mixin :whitespace
265
+ mixin :breakout
266
+ mixin :has_annotations
267
+
268
+ rule /(=)(\s*)(datatype)\b/ do
269
+ groups Punctuation, Text, Keyword::Reserved
270
+ pop!
271
+ end
272
+
273
+ rule %r(=(?!#{symbol})) do
274
+ token Punctuation
275
+ goto :datbind
276
+ push :datcon
277
+ end
278
+
279
+ rule id, Keyword::Type
280
+ rule symbol, Keyword::Type
281
+ end
282
+
283
+ state :datbind do
284
+ mixin :whitespace
285
+ rule /\b(and)\b(?!')/ do
286
+ token Keyword::Reserved; goto :dname
287
+ end
288
+ rule /\b(withtype)\b(?!')/ do
289
+ token Keyword::Reserved; goto :tname
290
+ end
291
+ rule /\bof\b(?!')/, Keyword::Reserved
292
+ rule /([|])(\s*)(#{id})/ do
293
+ groups(Punctuation, Text, Name::Class)
294
+ end
295
+
296
+ rule /([|])(\s+)(#{symbol})/ do
297
+ groups(Punctuation, Text, Name::Class)
298
+ end
299
+
300
+ mixin :breakout
301
+ mixin :core
302
+ end
303
+
304
+ state :ename do
305
+ mixin :whitespace
306
+ rule /(exception|and)(\s+)(#{id})/ do
307
+ groups Keyword::Reserved, Text, Name::Class
308
+ end
309
+
310
+ rule /(exception|and)(\s*)(#{symbol})/ do
311
+ groups Keyword::Reserved, Text, Name::Class
312
+ end
313
+
314
+ rule /\b(of)\b(?!')/, Keyword::Reserved
315
+ mixin :breakout
316
+ mixin :core
317
+ end
318
+
319
+ state :datcon do
320
+ mixin :whitespace
321
+ rule id, Name::Class, :pop!
322
+ rule symbol, Name::Class, :pop!
323
+ end
324
+
325
+ state :tyvarseq do
326
+ mixin :whitespace
327
+ rule /'[\w']*/, Name::Decorator
328
+ rule id, Name
329
+ rule /,/, Punctuation
330
+ rule /[)]/, Punctuation, :pop!
331
+ rule symbol, Name
332
+ end
333
+
334
+ state :comment do
335
+ rule /[^(*)]+/, Comment::Multiline
336
+ rule /[(][*]/ do
337
+ token Comment::Multiline; push
338
+ end
339
+ rule /[*][)]/, Comment::Multiline, :pop!
340
+ rule /[(*)]/, Comment::Multiline
341
+ end
112
342
  end
113
343
  end
114
344
  end