Skip to content

Commit

Permalink
Haml: Regexp optimisation + don't use captures if not needed + fix ty…
Browse files Browse the repository at this point in the history
…po in comment
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent e74e00c commit 23e3b43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions components/prism-haml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
// Multiline stuff should appear before the rest

'multiline-comment': {
pattern: /((?:^|\r?\n|\r)([\t ]*))(?:\/|-#).*((?:\r?\n|\r)\2[\t ]+.+)*/,
pattern: /((?:^|\r?\n|\r)([\t ]*))(?:\/|-#).*(?:(?:\r?\n|\r)\2[\t ]+.+)*/,
lookbehind: true,
alias: 'comment'
},

'multiline-code': [
{
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*((?:\r?\n|\r)\2[\t ]+.*,[\t ]*)*((?:\r?\n|\r)\2[\t ]+.+)/,
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*(?:(?:\r?\n|\r)\2[\t ]+.*,[\t ]*)*(?:(?:\r?\n|\r)\2[\t ]+.+)/,
lookbehind: true,
inside: {
rest: Prism.languages.ruby
}
},
{
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*((?:\r?\n|\r)\2[\t ]+.*\|[\t ]*)*/,
pattern: /((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*(?:(?:\r?\n|\r)\2[\t ]+.*\|[\t ]*)*/,
lookbehind: true,
inside: {
rest: Prism.languages.ruby
Expand All @@ -35,7 +35,7 @@

// See at the end of the file for known filters
'filter': {
pattern: /((?:^|\r?\n|\r)([\t ]*)):[\w-]+((?:\r?\n|\r)(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/,
pattern: /((?:^|\r?\n|\r)([\t ]*)):[\w-]+(?:(?:\r?\n|\r)(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/,
lookbehind: true,
inside: {
'filter-name': {
Expand Down Expand Up @@ -63,7 +63,7 @@
inside: {
'attributes': [
{
// Lookbehind tries to prevent interpolations for breaking it all
// Lookbehind tries to prevent interpolations from breaking it all
// Allows for one nested group of braces
pattern: /(^|[^#])\{(?:\{[^}]+\}|[^}])+\}/,
lookbehind: true,
Expand All @@ -75,7 +75,7 @@
pattern: /\([^)]+\)/,
inside: {
'attr-value': {
pattern: /(=\s*)(?:"(?:\\?.)*?"|[^)\s]+)/,
pattern: /(=\s*)(?:"(?:\\.|[^\\"\r\n])*"|[^)\s]+)/,
lookbehind: true
},
'attr-name': /[\w:-]+(?=\s*!?=|\s*[,)])/,
Expand Down Expand Up @@ -116,7 +116,7 @@
}
};

var filter_pattern = '((?:^|\\r?\\n|\\r)([\\t ]*)):{{filter_name}}((?:\\r?\\n|\\r)(?:\\2[\\t ]+.+|\\s*?(?=\\r?\\n|\\r)))+';
var filter_pattern = '((?:^|\\r?\\n|\\r)([\\t ]*)):{{filter_name}}(?:(?:\\r?\\n|\\r)(?:\\2[\\t ]+.+|\\s*?(?=\\r?\\n|\\r)))+';

// Non exhaustive list of available filters and associated languages
var filters = [
Expand Down
2 changes: 1 addition & 1 deletion components/prism-haml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23e3b43

Please sign in to comment.