Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed May 2, 2024
1 parent 5132cd3 commit 7630867
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 55 deletions.
6 changes: 4 additions & 2 deletions package/src/extensions/matchTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const voidTags = /^(?:area|base|w?br|col|embed|hr|img|input|link|meta|source|tra
* - Its ending position
* - Its tag name
* - Whether it's a closing tag
* - Whether it isn't self-closing
* - Whether it's not self-closing
*/
export type Tag = [Token, number, number, string, boolean, boolean]

Expand All @@ -27,7 +27,9 @@ export interface TagMatcher {
* - Its ending position
* - Its tag name
* - Whether it's a closing tag
* - Whether it isn't self-closing
* - Whether it's not self-closing
*
* The tags are sorted by their ending position
*/
readonly tags: Tag[]
/** Array mapping the index of a tag to the index of its matching tag. */
Expand Down
2 changes: 1 addition & 1 deletion package/src/languages/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import "./sql"
import "./swift"
import "./wasm"
import "./xml"
import "./yaml"
import "./yaml"
2 changes: 1 addition & 1 deletion package/src/prism/languages/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ languages.eta = languages.ejs = {
}
},
'escape': /<%%|%%>/,
[tokenize]: embeddedIn('markup')
[tokenize]: embeddedIn('html')
};
2 changes: 1 addition & 1 deletion package/src/prism/languages/etlua.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ languages.etlua = {
}
}
},
[tokenize]: embeddedIn('markup')
[tokenize]: embeddedIn('html')
};
18 changes: 10 additions & 8 deletions package/src/prism/languages/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|co
// full package (optional) + parent classes (optional)
var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;

var namespace = {
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
inside: {
'punctuation': /\./
}
};

var classInside = {
'namespace': {
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
inside: {
'punctuation': /\./
}
},
'namespace': namespace,
'punctuation': /\./
};

Expand Down Expand Up @@ -65,7 +67,7 @@ languages.java = {
pattern: RegExp(`(\\bimport\\s+)${classNamePrefix}(?:[A-Z]\\w*|\\*)(?=\\s*;)`),
lookbehind: true,
inside: {
'namespace': classInside.namespace,
'namespace': namespace,
'punctuation': /\./,
'operator': /\*/,
'class-name': /\w+/
Expand All @@ -76,7 +78,7 @@ languages.java = {
lookbehind: true,
alias: 'static',
inside: {
'namespace': classInside.namespace,
'namespace': namespace,
'static': /\b\w+$/,
'punctuation': /\./,
'operator': /\*/,
Expand Down
2 changes: 1 addition & 1 deletion package/src/prism/languages/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var expression = {
}
};

var parser = languages.parser = extend('markup', {
var parser = languages.parser = extend('html', {
'parser-comment': {
pattern: /(\s)#.*/,
lookbehind: true,
Expand Down
22 changes: 10 additions & 12 deletions package/src/prism/languages/pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ Object.assign(pug, {
'each': {
pattern: /^each .+? in\b/,
inside: {
'keyword': /\b(?:each|in)\b/,
'keyword': /^\w+|in$/,
'punctuation': /,/
}
},
'branch': {
pattern: /^(?:case|default|else|if|unless|when|while)\b/,
pattern: /^\w+/,
alias: 'keyword'
},
[rest]: js
Expand All @@ -126,7 +126,7 @@ Object.assign(pug, {
lookbehind: true,
inside: {
'keyword': /^mixin/,
'function': /\w+(?=\s*\(|\s*$)/,
'function': /\b\w+(?!\s*[^\s(])/,
'punctuation': /[().,]/
}
},
Expand Down Expand Up @@ -166,7 +166,7 @@ Object.assign(pug, {
pattern: /\([^)]+\)/,
inside: {
'attr-value': {
pattern: /(=\s*(?!\s))(?:\{[^}]*\}|[^,)\n]+)/,
pattern: /(=\s*(?!\s))(?:\{[^}]*\}|[^\n,)]+)/,
lookbehind: true,
inside: js
},
Expand All @@ -180,12 +180,10 @@ Object.assign(pug, {
'attr-class': /\.[\w-]+/
}
},
'code': [
{
pattern: /(^[ \t]*(?:-|!?=)).+/m,
lookbehind: true,
inside: js
}
],
'code': {
pattern: /(^[ \t]*(?:-|!?=)).+/m,
lookbehind: true,
inside: js
},
'punctuation': /[.!=|-]+/
})
});
2 changes: 1 addition & 1 deletion package/src/prism/languages/smarty.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ languages.smarty = {
alias: 'language-smarty',
inside: smarty
},
[tokenize]: embeddedIn('markup')
[tokenize]: embeddedIn('html')
}
53 changes: 25 additions & 28 deletions package/src/prism/languages/xeora.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ var variable = {
}
};

var blockPunctuation = {
pattern: /\$(?:\w:|C\[|C#\d)?|[[\]{:]/,
inside: {
'tag': /#\d/
}
};

insertBefore(xeora, 'markup-bracket', {
'constant': {
pattern: /\$(?:DomainContents|PageRenderDuration)\$/,
Expand All @@ -28,63 +35,53 @@ insertBefore(xeora, 'markup-bracket', {
},
'function-inline': {
pattern: /\$F:[\w.-]+\?[\w.-]+(?:,(?:(?:@[-#]*\w+\.[\w+.]\.*)*\|)*(?:(?:[\w+]|[-#*.~^]+[\w+]|=\S)(?:[^$=]|=+[^=])*=*|(?:@[-#]*\w+\.[\w+.]\.*)+(?:(?:[\w+]|[-#*~^][-#*.~^]*[\w+]|=\S)(?:[^$=]|=+[^=])*=*)?)?)?\$/,
alias: 'function',
inside: {
'variable': variable,
'punctuation': /\$\w:|[$?.,:|]/
},
alias: 'function'
}
},
'function-block': {
pattern: /\$XF:\{[\w.-]+\?[\w.-]+(?:,(?:(?:@[-#]*\w+\.[\w+.]\.*)*\|)*(?:(?:[\w+]|[-#*.~^]+[\w+]|=\S)(?:[^$=]|=+[^=])*=*|(?:@[-#]*\w+\.[\w+.]\.*)+(?:(?:[\w+]|[-#*~^][-#*.~^]*[\w+]|=\S)(?:[^$=]|=+[^=])*=*)?)?)?\}:XF\$/,
alias: 'function',
inside: {
'variable': variable,
'punctuation': /[{}$?.,:|]/
},
alias: 'function'
}
},
'directive-inline': {
pattern: /\$\w(?:#\d+\+?)?(?:\[[\w.-]+\])?:[-\w./]+\$/,
pattern: /\$\w(?:#\d+\+?)?(?:\[[\w.-]+\])?:[\w./-]+\$/,
alias: 'function',
inside: {
'punctuation': {
pattern: /\$(?:\w:|C(?:\[|#\d))?|[:{[\]]/,
inside: {
'tag': /#\d/
}
}
},
alias: 'function'
'punctuation': blockPunctuation
}
},
'directive-block-open': {
pattern: /\$\w+:\{|\$\w(?:#\d+\+?)?(?:\[[\w.-]+\])?:[\w.-]+:\{(?:![A-Z]+)?/,
alias: 'function',
inside: {
'punctuation': {
pattern: /\$(?:\w:|C\[|C#\d)?|[:{[\]]/,
inside: {
'tag': /#\d/
}
},
'punctuation': blockPunctuation,
'attribute': {
pattern: /![A-Z]+$/,
pattern: /![A-Z]+/,
alias: 'keyword',
inside: {
'punctuation': /!/
},
alias: 'keyword'
}
}
},
alias: 'function'
}
},
'directive-block-separator': {
pattern: /\}:[\w.-]+:\{/,
alias: 'function',
inside: {
'punctuation': /[:{}]/
},
alias: 'function'
}
},
'directive-block-close': {
pattern: /\}:[\w.-]+\$/,
alias: 'function',
inside: {
'punctuation': /[:{}$]/
},
alias: 'function'
}
}
});

0 comments on commit 7630867

Please sign in to comment.