Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dart language support #68

Merged
merged 6 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Clojure } from './languages/clojure';
import { CPP } from './languages/cpp';
import { CS } from './languages/cs';
import { CSS } from './languages/css';
import { Dart } from './languages/dart';
import { Dockerfile } from './languages/dockerfile';
import { Elixir } from './languages/elixir';
import { Go } from './languages/go';
Expand Down Expand Up @@ -31,6 +32,7 @@ const languages: Record<string, LanguagePattern[]> = {
'C++': CPP,
'C#': CS,
CSS,
Dart,
Dockerfile,
Elixir,
Go,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ export const C: LanguagePattern[] = [
},
// Avoiding Lua confusion
{ pattern: /local\s(function|\w+)?/, type: 'not' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be \s+ instead of \s?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ga ada hubungannya sama dart

// Avoiding Dart confusion
{ pattern: /^(void\s)?main\(\)\s(async\s)?{/, type: 'not' },
];
2 changes: 2 additions & 0 deletions src/languages/cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ export const CPP: LanguagePattern[] = [
type: 'not',
},
{ pattern: /(const)?(\s+)?val(\s+)(.*)(:(\s)(.*)(\?)?)?(\s+)=(\s+)/, type: 'not' },
// Avoiding Dart confusion
{ pattern: /^(void\s)?main\(\)\s(async\s)?{/, type: 'not' },
];
2 changes: 2 additions & 0 deletions src/languages/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export const CS: LanguagePattern[] = [
{ pattern: /System\.(in|out)\.\w+/, type: 'not' },
// Avoiding Ruby confusion
{ pattern: /\bmodule\s\S/, type: 'not' },
// Avoiding Dart confusion
{ pattern: /^import\s("|')dart:\w+("|')/, type: 'not' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import statement can't be preceded with a whitespace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bisa aja sih sebenernya, but don't know

];
44 changes: 44 additions & 0 deletions src/languages/dart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { LanguagePattern } from '../types';

export const Dart: LanguagePattern[] = [
// Variable declaration
{
pattern:
/^\s*(const|final|var|dynamic|late)?\s*(int|double|String|bool|List<[A-Za-z [\](),]+>|HashMap<[A-Za-z [\](),]+>|Iterator<[A-Za-z [\](),]+>|Set<[A-Za-z [\](),]+>)?(\?)?\s\w+(\s=\s.+)?(;|,)$/,
type: 'keyword.variable',
},
{ pattern: /\bstdout.write\(.+\);/, type: 'keyword.print' },
{ pattern: /\bprint\(.+\);/, type: 'keyword.print' },
{ pattern: /^import\s("|')dart:\w+("|')/, type: 'meta.import', nearTop: true },
{ pattern: /^import\s("|')package:\w+("|')/, type: 'meta.import', nearTop: true },
{ pattern: /^library\s\w+;/, type: 'meta.module', nearTop: true },
{ pattern: /^(void\s)?main\(\)\s(async\s)?{/, type: 'keyword.function' },
// function with type definition
{
pattern:
/^\s*(List<[A-Za-z [\](),]+>|HashMap<[A-Za-z [\](),]+>|int|double|String|bool|void|Iterator<[A-Za-z [\](),]+>|Set<[A-Za-z [\](),]+>)\s\w+\(.+\)\s*\{$/,
type: 'keyword.function',
},
// arrow function
{
pattern:
/^\s*(int|double|String|bool|List<[A-Za-z [\](),]+>|HashMap<[A-Za-z [\](),]+>|Iterator<[A-Za-z [\](),]+>|Set<[A-Za-z [\](),]+>)\s\w+\(.+\)\s=>/,
type: 'keyword.function',
},
{ pattern: /\bnew\s(List|Map|Iterator|HashMap|Set)<\w+>\(\);$/, type: 'keyword.variable' },
{
pattern: /^(abstract\s)?class\s\w+\s(extends\s\w+\s)?(with\s\w+\s)?(implements\s\w+\s)?{(})?$/,
type: 'keyword.control',
},
{ pattern: /\bget\s\w+=>\w+/, type: 'keyword.control' },
{ pattern: /^\s*@override$/, type: 'keyword.control' },
{ pattern: /\bset\s\w+\(.+\)/, type: 'keyword.control' },
{ pattern: /^\s*Future<w+>\s\w+\(.+\)\sasync/, type: 'keyword.control' },
{ pattern: /^\s*await\sfor/, type: 'keyword.control' },
{ pattern: /^\s*typedef\s.+\s=/, type: 'keyword.control' },
// Avoiding confusion with C
{ pattern: /\blong\b/, type: 'not' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the long keyword surrounded by punctuation? If not, you might want to use \s instead.

{ pattern: /\s*function\b/, type: 'not' },
// Avoiding confusion with Java
{ pattern: /\bArrayList/, type: 'not' },
];
4 changes: 3 additions & 1 deletion src/languages/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Java: LanguagePattern[] = [
// while loop
{ pattern: /while\s+\(.+\)/, type: 'keyword.control' },
// void keyword
{ pattern: /void/g, type: 'keyword.other' },
{ pattern: /void/, type: 'keyword.other' },
// const
{ pattern: /const\s*\w+/, type: 'not' },
// pointer
Expand All @@ -53,4 +53,6 @@ export const Java: LanguagePattern[] = [
{ pattern: /fun main\((.*)?\) {/, type: 'not' },
{ pattern: /(inline(\s+))?fun(\s+)([A-Za-z0-9_])(\s+)?\((.*)\)(\s+)({|=)/, type: 'not' },
{ pattern: /(const)?(\s+)?val(\s+)(.*)(:(\s)(.*)(\?)?)?(\s+)=(\s+)/, type: 'not' },
// Avoiding Dart confusion
{ pattern: /^(void\s)?main\(\)\s{/, type: 'not' },
];
2 changes: 2 additions & 0 deletions src/languages/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ export const Javascript: LanguagePattern[] = [
{ pattern: /fun main\((.*)?\) {/, type: 'not' },
{ pattern: /(inline(\s+))?fun(\s+)([A-Za-z0-9_])(\s+)?\((.*)\)(\s+)({|=)/, type: 'not' },
{ pattern: /(const)?(\s+)?val(\s+)(.*)(:(\s)(.*)(\?)?)?(\s+)=(\s+)/, type: 'not' },
// Avoiding Dart confusion
{ pattern: /^(void\s)?main()\s{/, type: 'not' },
];
Loading