Skip to content

Commit

Permalink
Twig: optimized regexps + fixed operators + added missing operators/k…
Browse files Browse the repository at this point in the history
…eywords
  • Loading branch information
Golmote committed Sep 2, 2015
1 parent aa90b68 commit 2d8271f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
35 changes: 17 additions & 18 deletions components/prism-twig.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
Prism.languages.twig = {
'comment': /\{#[\s\S]*?#\}/,
'tag': {
pattern: /(\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\})/,
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/,
inside: {
'punctuation': /^('|")|('|")$/
}
},
'keyword': /\b(if)\b/,
'boolean': /\b(true|false|null)\b/,
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
'operator': /==|=|!=|<|>|>=|<=|\+|\-|~|\*|\/|\/\/|%|\*\*|\|/,
'space-operator': {
pattern: /(\s)(\b(not|b\-and|b\-xor|b\-or|and|or|in|matches|starts with|ends with|is)\b|\?|:|\?:)(?=\s)/,
lookbehind: true,
inside: {
'operator': /.*/
'punctuation': /^['"]|['"]$/
}
},
'keyword': /\b(?:even|if|odd)\b/,
'boolean': /\b(?:true|false|null)\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)/,
lookbehind: true
},
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
],
'property': /\b[a-zA-Z_][a-zA-Z0-9_]*\b/,
'punctuation': /\(|\)|\[\]|\[|\]|\{|\}|:|\.|,/
'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 2d8271f

Please sign in to comment.