Skip to content

Commit

Permalink
Add D2 language support (#6435)
Browse files Browse the repository at this point in the history
Add d2 language support

Co-authored-by: Colin Seymour <colin@github.com>
  • Loading branch information
goto1134 and lildude authored May 30, 2023
1 parent 5a62830 commit 60a76ee
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
[submodule "vendor/grammars/d.tmbundle"]
path = vendor/grammars/d.tmbundle
url = https://github.com/textmate/d.tmbundle
[submodule "vendor/grammars/d2-vscode"]
path = vendor/grammars/d2-vscode
url = https://github.com/terrastruct/d2-vscode.git
[submodule "vendor/grammars/dart-syntax-highlight"]
path = vendor/grammars/dart-syntax-highlight
url = https://github.com/dart-lang/dart-syntax-highlight
Expand Down
3 changes: 3 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ vendor/grammars/cython:
- source.cython
vendor/grammars/d.tmbundle:
- source.d
vendor/grammars/d2-vscode:
- source.d2
- text.html.markdown.d2
vendor/grammars/dart-syntax-highlight:
- source.dart
vendor/grammars/data-weave-tmLanguage:
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,16 @@ D-ObjDump:
tm_scope: objdump.x86asm
ace_mode: assembly_x86
language_id: 81
D2:
type: markup
color: "#526ee8"
extensions:
- ".d2"
aliases:
- d2lang
tm_scope: source.d2
ace_mode: text
language_id: 37531557
DIGITAL Command Language:
type: programming
aliases:
Expand Down
55 changes: 55 additions & 0 deletions samples/D2/anthias-diagram-overview.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
direction: down

classes: {
containers: {
shape: rectangle
}
}

user: "User" {
shape: person
}

database: "SQLite3" {
shape: cylinder
}

a {
label: null
style.fill: transparent
style.stroke: transparent
}

b {
label: null
style.fill: transparent
style.stroke: transparent
}

b.display: "Display (Monitor or TV)" {
style.3d: true
}

anthias-nginx.class: containers
b.anthias-viewer.class: containers
a.anthias-server.class: containers
a.anthias-websocket.class: containers
a.anthias-celery.class: containers
a.redis.class: containers

user -> anthias-nginx
anthias-nginx <-> a.anthias-server
anthias-nginx -> a.anthias-websocket

a.anthias-server <-> a.anthias-celery
a.anthias-websocket <-> a.anthias-server
a.anthias-celery -> a.redis: "in-memory data"
a.redis <-> a.anthias-server

b.anthias-viewer <-> database: "assets data"

a.anthias-server <-> b.anthias-viewer: "assets data"
a.anthias-server <-> database
a.anthias-celery <-> database

b.anthias-viewer -> b.display: "current asset"
148 changes: 148 additions & 0 deletions samples/D2/calc_algo.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

cTrnDao: CalcTrnDao {
q: Query {
ByTime
ByCategory
ByAccount
ByPurpose
}
sql: "SQL: O(trns.count) time | O(trns.notDel.count) space" {
"SELECT amount, currency, type FROM transactions WHERE ..."
}
trns: "List<CalcTrn>" {
CalcTrn {
shape: class

amount: Double
currency: String
type: TransactionType
}
}

q -> sql -> trns
}

rawStatsFlow: RawStatsFlow {
in: Input {
shape: class
trns: List<CalcTrn>
}

p: "Process: O(trns.count) time | O(currs.unique.count) space" {
"trns.forEach { aggregate incomes, expense by currencies + count them }"
}

out: RawStats {
shape: class
incomes: Map<CurrencyCode, Double>
expenses: Map<CurrencyCode, Double>
incomesCount: Int
expensesCount: Int
}

in -> p -> out
}

cTrndao.trns -> rawStatsFlow.in.trns

# RatesFlow
ratesDao: RatesDao {
sql: "SQL: O(rates.count) time | O(rates.baseCurr.count) space" {
"SELECT rate, currency FROM exchange_rates WHERE baseCurrency = ?"
}
out: "List<Rate>" {
Rate {
shape: class
rate: Double
currency: String
}
}
sql -> out
}

ratesOverrideDao: RateOverrideDao {
sql: "SQL: O(rates.override.count) time | O(rates.override.baseCurr.count) space" {
"SELECT rate, currency FROM exchange_rates_override WHERE baseCurrency = ? AND sync != $DELETING"
}
out: "List<Rate>" {
Rate {
shape: class
rate: Double
currency: String
}
}
sql -> out
}

ratesFlow: RatesFlow {
deps: Dependencies {
ratesDao
ratesOverrideDao
baseCurrencyFlow
}
p: "Process: O(rates.override.count) time | O(1) space" {
1: "baseCurrency.flatMapLatest {}"
2: "combine(rateDao.findByBaseCurr(), ratesOverridedao.findByBaseCurr())"
3: "Override rate with the manual set ones"

1 -> 2 -> 3

}
out: "RatesData" {
shape: class
baseCurrency: String
rates: Map<CurrencyCode, Double>
}

deps.ratesDao -> p: Reacts
deps.ratesOverrideDao -> p: Reacts
deps.baseCurrencyFlow -> p: Reacts
p -> out
}

ratesDao -> ratesFlow.deps
ratesOverrideDao -> ratesFlow.deps


# ExchangeStatsFlow
exFlow: ExchangeStatsFlow {
deps: Dependencies {
ratesFlow: "rates: RatesFlow"
}

in: Input {
shape: class
rawStats: RawStats
outputCurrency: String
}

p: "Process: O(curr.unique.count) space-time" {
incs_loop: "rawStats.incomes.forEach {}"
incs_exchange: "exchange to output currency"
incs_sum: "sum & count"

incs_loop -> incs_exchange -> incs_sum

exps_loop: "rawStats.expenses.forEach {}"
exps_exchange: "exchange to output currency"
exps_sum: "sum & count"

exps_loop -> exps_exchange -> exps_sum
}

out: Stats {
shape: class
income: Value
expense: Value
incomesCount: Int
expensesCount: Int
}

deps.ratesFlow -> p: Reacts to rates changes
in.rawStats -> p
p.incs_sum -> out
p.exps_sum -> out
}

ratesFlow.out -> exFlow.deps.ratesFlow: Reacts
rawStatsFlow.out -> exFlow.in.rawStats
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Cython:** [textmate/cython.tmbundle](https://github.com/textmate/cython.tmbundle)
- **D:** [textmate/d.tmbundle](https://github.com/textmate/d.tmbundle)
- **D-ObjDump:** [nanoant/assembly.tmbundle](https://github.com/nanoant/assembly.tmbundle)
- **D2:** [terrastruct/d2-vscode](https://github.com/terrastruct/d2-vscode)
- **DM:** [PJB3005/atomic-dreams](https://github.com/PJB3005/atomic-dreams)
- **DNS Zone:** [sixty4k/st2-zonefile](https://github.com/sixty4k/st2-zonefile)
- **DTrace:** [textmate/c.tmbundle](https://github.com/textmate/c.tmbundle)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/d2-vscode
Submodule d2-vscode added at 8f1fef
35 changes: 35 additions & 0 deletions vendor/licenses/git_submodule/d2-vscode.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: d2-vscode
version: 8f1fef4f732ffbf8a2cf70676c15bc9791c010a7
type: git_submodule
homepage: https://github.com/terrastruct/d2-vscode.git
license: bsd-3-clause
licenses:
- sources: LICENSE.txt
text: |
Copyright 2022 Terrastruct, Inc.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
notices: []

0 comments on commit 60a76ee

Please sign in to comment.