Skip to content
Permalink
Browse files
Dart: Added string interpolation and improved metadata (#3197)
  • Loading branch information
RunDevelopment committed Nov 22, 2021
1 parent 86028ad commit e1370357cc6a01166c099d5df2142395ca21dc70
Showing with 237 additions and 26 deletions.
  1. +24 −12 components/prism-dart.js
  2. +1 −1 components/prism-dart.min.js
  3. +134 −6 tests/languages/dart/metadata_feature.test
  4. +78 −7 tests/languages/dart/string_feature.test
@@ -22,16 +22,6 @@
};

Prism.languages.dart = Prism.languages.extend('clike', {
'string': [
{
pattern: /r?("""|''')[\s\S]*?\1/,
greedy: true
},
{
pattern: /r?(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
}
],
'class-name': [
className,
{
@@ -46,10 +36,32 @@
'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
});

Prism.languages.insertBefore('dart', 'function', {
Prism.languages.insertBefore('dart', 'string', {
'string-literal': {
pattern: /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/,
greedy: true,
inside: {
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
lookbehind: true,
inside: {
'punctuation': /^\$\{?|\}$/,
'expression': {
pattern: /[\s\S]+/,
inside: Prism.languages.dart
}
}
},
'string': /[\s\S]+/
}
},
'string': undefined
});

Prism.languages.insertBefore('dart', 'class-name', {
'metadata': {
pattern: /@\w+/,
alias: 'symbol'
alias: 'function'
}
});

Some generated files are not rendered by default. Learn more.

@@ -1,20 +1,148 @@
@deprecated
@override
@todo('seth', 'make this do something')
@ToDo('seth', 'make this do something')

@DataTable("sale_orders")
class SaleOrder {
@DataColumn("sale_order_date")
DateTime date;
}

@table
class Product {
@column
String name;
}

const DataColumn column = const DataColumn();

const DataTable table = const DataTable();

class DataTable {
final String name;

const DataTable([this.name]);
}

class DataColumn {
final String name;

const DataColumn([this.name]);
}

----------------------------------------------------

[
["metadata", "@deprecated"],

["metadata", "@override"],
["metadata", "@todo"],

["metadata", "@ToDo"],
["punctuation", "("],
["string", "'seth'"],
["string-literal", [
["string", "'seth'"]
]],
["punctuation", ","],
["string", "'make this do something'"],
["punctuation", ")"]
["string-literal", [
["string", "'make this do something'"]
]],
["punctuation", ")"],

["metadata", "@DataTable"],
["punctuation", "("],
["string-literal", [
["string", "\"sale_orders\""]
]],
["punctuation", ")"],

["keyword", "class"],
["class-name", ["SaleOrder"]],
["punctuation", "{"],

["metadata", "@DataColumn"],
["punctuation", "("],
["string-literal", [
["string", "\"sale_order_date\""]
]],
["punctuation", ")"],

["class-name", ["DateTime"]],
" date",
["punctuation", ";"],

["punctuation", "}"],

["metadata", "@table"],
["keyword", "class"], ["class-name", ["Product"]], ["punctuation", "{"],
["metadata", "@column"],
["class-name", ["String"]], " name", ["punctuation", ";"],
["punctuation", "}"],

["keyword", "const"],
["class-name", ["DataColumn"]],
" column ",
["operator", "="],
["keyword", "const"],
["class-name", ["DataColumn"]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "const"],
["class-name", ["DataTable"]],
" table ",
["operator", "="],
["keyword", "const"],
["class-name", ["DataTable"]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "class"],
["class-name", ["DataTable"]],
["punctuation", "{"],

["keyword", "final"],
["class-name", ["String"]],
" name",
["punctuation", ";"],

["keyword", "const"],
["class-name", ["DataTable"]],
["punctuation", "("],
["punctuation", "["],
["keyword", "this"],
["punctuation", "."],
"name",
["punctuation", "]"],
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "class"],
["class-name", ["DataColumn"]],
["punctuation", "{"],

["keyword", "final"],
["class-name", ["String"]],
" name",
["punctuation", ";"],

["keyword", "const"],
["class-name", ["DataColumn"]],
["punctuation", "("],
["punctuation", "["],
["keyword", "this"],
["punctuation", "."],
"name",
["punctuation", "]"],
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"]
]

----------------------------------------------------

Checks for metadata.
Checks for metadata.
@@ -8,18 +8,89 @@ bar"""
'''foo
bar'''

'$string has ${string.length} letters'
"cookie has ${cookie.number_of_chips} chips"

----------------------------------------------------

[
["string", "\"\""], ["string", "''"],
["string", "r\"\""], ["string", "r''"],
["string", "\"\"\"\"\"\""], ["string", "''''''"],
["string", "r\"\"\"\"\"\""], ["string", "r''''''"],
["string", "\"fo\\\"o\""], ["string", "'fo\\'o'"],
["string", "\"\"\"foo\r\nbar\"\"\""], ["string", "'''foo\r\nbar'''"]
["string-literal", [
["string", "\"\""]
]],
["string-literal", [
["string", "''"]
]],

["string-literal", [
["string", "r\"\""]
]],
["string-literal", [
["string", "r''"]
]],

["string-literal", [
["string", "\"\"\"\"\"\""]
]],
["string-literal", [
["string", "''''''"]
]],

["string-literal", [
["string", "r\"\"\"\"\"\""]
]],
["string-literal", [
["string", "r''''''"]
]],

["string-literal", [
["string", "\"fo\\\"o\""]
]],
["string-literal", [
["string", "'fo\\'o'"]
]],

["string-literal", [
["string", "\"\"\"foo\r\nbar\"\"\""]
]],

["string-literal", [
["string", "'''foo\r\nbar'''"]
]],

["string-literal", [
["string", "'"],
["interpolation", [
["punctuation", "$"],
["expression", ["string"]]
]],
["string", " has "],
["interpolation", [
["punctuation", "${"],
["expression", [
"string",
["punctuation", "."],
"length"
]],
["punctuation", "}"]
]],
["string", " letters'"]
]],
["string-literal", [
["string", "\"cookie has "],
["interpolation", [
["punctuation", "${"],
["expression", [
"cookie",
["punctuation", "."],
"number_of_chips"
]],
["punctuation", "}"]
]],
["string", " chips\""]
]]
]

----------------------------------------------------

Checks for single quoted and double quoted strings,
multi-line strings and "raw" strings.
multi-line strings and "raw" strings.

0 comments on commit e137035

Please sign in to comment.