From 30a786cf5ffdaae51c4ef3b31b78bb5df6997f6f Mon Sep 17 00:00:00 2001 From: yuri1969 <1969yuri1969@gmail.com> Date: Wed, 22 Mar 2023 23:06:07 +0100 Subject: [PATCH 1/3] Fix incorrect key:value detection --- src/basic-languages/yaml/yaml.test.ts | 50 +++++++++++++++++++++++++++ src/basic-languages/yaml/yaml.ts | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/basic-languages/yaml/yaml.test.ts b/src/basic-languages/yaml/yaml.test.ts index 6a0aa846..db7810bd 100644 --- a/src/basic-languages/yaml/yaml.test.ts +++ b/src/basic-languages/yaml/yaml.test.ts @@ -473,5 +473,55 @@ testTokenization('yaml', [ { startIndex: 10, type: 'comment.yaml' } ] } + ], + + // ': ' in double-quoted Value + [ + { + line: 'key: "va: lue"', + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + } + ] + } + ], + + // ': ' in single-quoted Value + [ + { + line: "key: 'va: lue'", + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + } + ] + } ] ]); diff --git a/src/basic-languages/yaml/yaml.ts b/src/basic-languages/yaml/yaml.ts index 466be144..51b8f50a 100644 --- a/src/basic-languages/yaml/yaml.ts +++ b/src/basic-languages/yaml/yaml.ts @@ -86,7 +86,7 @@ export const language = { [/@numberDate(?![ \t]*\S+)/, 'number.date'], // Key:Value pair - [/(".*?"|'.*?'|.*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']], + [/(".*?"|'.*?'|[^'"]*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']], { include: '@flowScalars' }, From c7ce77ba1843a0509db546b035babf43ac0b73ac Mon Sep 17 00:00:00 2001 From: yuri1969 <1969yuri1969@gmail.com> Date: Sat, 25 Mar 2023 17:37:03 +0100 Subject: [PATCH 2/3] Fix values mixed with comments --- src/basic-languages/yaml/yaml.test.ts | 110 ++++++++++++++++++++++++++ src/basic-languages/yaml/yaml.ts | 2 +- 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/basic-languages/yaml/yaml.test.ts b/src/basic-languages/yaml/yaml.test.ts index db7810bd..938d010a 100644 --- a/src/basic-languages/yaml/yaml.test.ts +++ b/src/basic-languages/yaml/yaml.test.ts @@ -458,6 +458,7 @@ testTokenization('yaml', [ { startIndex: 4, type: 'operators.yaml' }, { startIndex: 5, type: 'white.yaml' }, { startIndex: 6, type: 'string.yaml' }, + { startIndex: 28, type: 'white.yaml' }, { startIndex: 29, type: 'comment.yaml' } ] } @@ -470,6 +471,7 @@ testTokenization('yaml', [ { startIndex: 6, type: 'operators.yaml' }, { startIndex: 7, type: 'white.yaml' }, { startIndex: 8, type: 'string.yaml' }, + { startIndex: 9, type: 'white.yaml' }, { startIndex: 10, type: 'comment.yaml' } ] } @@ -523,5 +525,113 @@ testTokenization('yaml', [ } ] } + ], + + // '#' in single-quoted Value + [ + { + line: "key: 'va#lue'", + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + } + ] + } + ], + + // '#' in double-quoted Value + [ + { + line: 'key: "va#lue"', + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + } + ] + } + ], + + // '#' in Value + [ + { + line: 'key: va#lue', + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + } + ] + } + ], + + // Comment following Value + [ + { + line: 'key: value #comment', + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + }, + { + startIndex: 10, + type: 'white.yaml' + }, + { + startIndex: 11, + type: 'comment.yaml' + } + ] + } ] ]); diff --git a/src/basic-languages/yaml/yaml.ts b/src/basic-languages/yaml/yaml.ts index 51b8f50a..fd2b6bba 100644 --- a/src/basic-languages/yaml/yaml.ts +++ b/src/basic-languages/yaml/yaml.ts @@ -92,7 +92,7 @@ export const language = { // String nodes [ - /[^#]+/, + /.+?(?=(\s+#|$))/, { cases: { '@keywords': 'keyword', From 788b6a2982b009d01862eec72e08b6603f80b9ab Mon Sep 17 00:00:00 2001 From: yuri1969 <1969yuri1969@gmail.com> Date: Sat, 25 Mar 2023 18:12:24 +0100 Subject: [PATCH 3/3] Fix ': ' within a comment --- src/basic-languages/yaml/yaml.test.ts | 35 ++++++++++++++++++++++++++- src/basic-languages/yaml/yaml.ts | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/basic-languages/yaml/yaml.test.ts b/src/basic-languages/yaml/yaml.test.ts index 938d010a..76845651 100644 --- a/src/basic-languages/yaml/yaml.test.ts +++ b/src/basic-languages/yaml/yaml.test.ts @@ -602,7 +602,7 @@ testTokenization('yaml', [ } ], - // Comment following Value + // Comment following Value [ { line: 'key: value #comment', @@ -633,5 +633,38 @@ testTokenization('yaml', [ } ] } + ], + + // ': ' in Comment following Value + [ + { + line: 'key: value #comment: also comment', + tokens: [ + { + startIndex: 0, + type: 'type.yaml' + }, + { + startIndex: 3, + type: 'operators.yaml' + }, + { + startIndex: 4, + type: 'white.yaml' + }, + { + startIndex: 5, + type: 'string.yaml' + }, + { + startIndex: 10, + type: 'white.yaml' + }, + { + startIndex: 11, + type: 'comment.yaml' + } + ] + } ] ]); diff --git a/src/basic-languages/yaml/yaml.ts b/src/basic-languages/yaml/yaml.ts index fd2b6bba..5d187d14 100644 --- a/src/basic-languages/yaml/yaml.ts +++ b/src/basic-languages/yaml/yaml.ts @@ -86,7 +86,7 @@ export const language = { [/@numberDate(?![ \t]*\S+)/, 'number.date'], // Key:Value pair - [/(".*?"|'.*?'|[^'"]*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']], + [/(".*?"|'.*?'|[^#'"]*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']], { include: '@flowScalars' },