Skip to content

Commit

Permalink
Twig: Regexp optimisation and simplification + don't use captures if …
Browse files Browse the repository at this point in the history
…not needed
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent 08139ad commit 0b10fd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions components/prism-twig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ Prism.languages.twig = {
pattern: /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/,
inside: {
'ld': {
pattern: /^(?:\{\{\-?|\{%\-?\s*\w+)/,
pattern: /^(?:\{\{-?|\{%-?\s*\w+)/,
inside: {
'punctuation': /^(?:\{\{|\{%)\-?/,
'punctuation': /^(?:\{\{|\{%)-?/,
'keyword': /\w+/
}
},
'rd': {
pattern: /\-?(?:%\}|\}\})$/,
pattern: /-?(?:%\}|\}\})$/,
inside: {
'punctuation': /.*/
}
},
'string': {
pattern: /("|')(?:\\?.)*?\1/,
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
inside: {
'punctuation': /^['"]|['"]$/
}
},
'keyword': /\b(?:even|if|odd)\b/,
'boolean': /\b(?:true|false|null)\b/,
'number': /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+([Ee][-+]?\d+)?)\b/,
'number': /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(?:[Ee][-+]?\d+)?)\b/,
'operator': [
{
pattern: /(\s)(?:and|b\-and|b\-xor|b\-or|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
pattern: /(\s)(?:and|b-and|b-xor|b-or|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
lookbehind: true
},
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
],
'property': /\b[a-zA-Z_][a-zA-Z0-9_]*\b/,
'property': /\b[a-zA-Z_]\w*\b/,
'punctuation': /[()\[\]{}:.,]/
}
},
Expand Down
2 changes: 1 addition & 1 deletion components/prism-twig.min.js

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

0 comments on commit 0b10fd0

Please sign in to comment.