Skip to content

Commit

Permalink
add modes.MATCH_NOTHING_RE
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Jan 6, 2021
1 parent 61122dd commit 60734e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Expand Up @@ -8,8 +8,15 @@ Language grammar improvements:

- enh(swift) Improved highlighting for operator and precedencegroup declarations. (#2938) [Steven Van Impe][]

Parser:

- add `modes.MATCH_NOTHING_RE` that will never match
- This can be used with `end` to hold a mode open (it must then be ended with
`endsParent` in one of it's children modes) [Josh Goebel][]

[Michael Newton]: https://github.com/miken32
[Steven Van Impe]: https://github.com/svanimpe/
[Josh Goebel]: https://github.com/joshgoebel


## Version 10.5.0
Expand Down
10 changes: 2 additions & 8 deletions src/languages/swift.js
Expand Up @@ -416,11 +416,8 @@ export default function(hljs) {
// https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID380
const OPERATOR_DECLARATION = {
beginKeywords: 'operator',
end: hljs.MATCH_NOTHING_RE,
contains: [
{
match: /\s+/,
relevance: 0
},
{
className: 'title',
match: Swift.operator,
Expand All @@ -433,11 +430,8 @@ export default function(hljs) {
// https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID550
const PRECEDENCEGROUP = {
beginKeywords: 'precedencegroup',
end: hljs.MATCH_NOTHING_RE,
contains: [
{
match: /\s+/,
relevance: 0
},
{
className: 'title',
match: Swift.typeIdentifier,
Expand Down
1 change: 1 addition & 0 deletions src/lib/modes.js
Expand Up @@ -2,6 +2,7 @@ import { inherit } from './utils.js';
import * as regex from './regex.js';

// Common regexps
export const MATCH_NOTHING_RE = /\b\B/;
export const IDENT_RE = '[a-zA-Z]\\w*';
export const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*';
export const NUMBER_RE = '\\b\\d+(\\.\\d+)?';
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -58,6 +58,7 @@ interface ModesAPI {
// built in regex
IDENT_RE: string
UNDERSCORE_IDENT_RE: string
MATCH_NOTHING_RE: string
NUMBER_RE: string
C_NUMBER_RE: string
BINARY_NUMBER_RE: string
Expand Down

0 comments on commit 60734e7

Please sign in to comment.