Skip to content

Commit

Permalink
增加Haskell语法 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZQBCWG authored Nov 8, 2024
1 parent a03f783 commit f30f73a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
> `## 日期`
> `### 语法 - 版本`
> …</details>
## 2024-11-8
### haskell - 1.0.0
#### New | 新语法

+ 新增语法高亮:[Haskell](mtsx/haskell.mtsx)

___
## 2024-10-28
### dotenv - [1.0.1](https://github.com/guobao2333/MT-syntax-highlight/commit/30140d2)
#### Fixed | 修复
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
+ 新增语法高亮:[GoLang(冷色调)](mtsx/golang.mtsx)

虽然已有内置golang语法,但此语法高亮作者写了一个冷色调的配色以及匹配模式,不过只有亮色,而我为此语法补充了暗色的风格。
### Haskell - [1.0.0]
#### New | 新语法

+ 新增语法高亮:[Haskell](mtsx/haskell.mtsx)
# Update Plan | 更新计划
- [x] Envionment Variable
- [x] Markdown(GFM)
Expand Down
42 changes: 42 additions & 0 deletions mtsx/haskell.mtsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ################# LICENCE START ################
// Copyright (c) 2024 ZQBCWG

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ################# LICENCE END ##################
{
name: ["Haskell", ".hs"]
styles: [
"keyword" > "keyword"
"type" > "type"
"functionName" > "tagName"
"operator" > "operator"
"comment" > "comment"
"string" > "string"
"number" > "number"
]
comment: {startsWith: "--"}
comment: {startsWith: "{-", endsWith: "-}"}
defines: [
"identifier": /\b[a-zA-Z_][a-zA-Z0-9_']*\b/
]
contains: [
{match: /\b(?:[0-9]+|0[xX][0-9a-fA-F]+)\b/, 0: "number"}
{match: /--.*/, 0: "comment"}
{match: /\{-[^}]*-\}/, 0: "comment"}
{match: keywordsToRegex("let in where case of data type newtype deriving instance class do if then else import module as"), 0: "keyword"}
{match: /\b([A-Z][a-zA-Z0-9']*)\b/, 0: "type"}
{match: include("identifier") + /(?=\s*::)/, 0: "functionName"}
{match: /(::|->|<-|=>|=|\+|-|\*|\/|==|\/=|<=|>=|&&|\|\|)/, 0: "operator"}
{match: /".*?"/, 0: "string"}
]
}
8 changes: 7 additions & 1 deletion preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@

![light亮色模式](golang/light.webp)
![dark暗色模式](golang/dark.webp)
</details>
</details>
<details>
<summary>Haskell</summary>

![light亮色模式](haskell/light.webp)
![dark暗色模式](haskell/dark.webp)
</details>
Binary file added preview/haskell/dark.webp
Binary file not shown.
Binary file added preview/haskell/light.webp
Binary file not shown.
27 changes: 27 additions & 0 deletions preview/haskell/preview.hs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Data.List (elemIndices, sort)
import Data.Set (fromList, toList)
import System.Console.Haskeline (InputT, runInputT, defaultSettings, getInputLine, outputStr, outputStrLn)
-- 一些注释
rows :: Int
rows = 9
board :: Board
board = blank
type Board = [[Piece]]
type Position = (Int, Int)
data Piece = B | B' | O | O' | X | X' | AO | AO' | AX | AX'
deriving (Eq, Show)

data m = PushO | PushX | PushA | Push'
deriving (Eq, Show)
data Tree a = Node a [Tree a]
deriving Show
a :: m -> m
a PushO = PushX
a PushX = PushO
minimax :: ((Int, Position), (Board, Int, Int)) -> Int -> Move -> Bool -> (Label, Label) -> Tree ((Label, Int, Position), (Board, Int, Int))
minimax ((h, p), (b, hO, hX)) n m f (alpha, beta) | win (b, hO, hX) /= "" || n == 0 || (n == 1 && not (ascending b)) = Node (((hO, hX), h, p), (b, hO, hX)) []
| otherwise = Node ((bestLabel (map (\(Node ((l, _, _), _) _) -> l) lts) m, h, p), (b, hO, hX)) lts
where lts = alphabeta hpxs n m f (alpha, beta)
hpxs = map (\(h', p', Just b') -> ((h', p'), (if ascending b then settleAscend else id) (initiateAscend b' p', hO, hX))) $ filter (\(_, _, mb) -> mb /= Nothing) $ take breadth [(h', p', move b m p') | (h', p') <- heuristic (b, hO, hX) m f]

alphabeta :: [((Int, Position), (Board, Int, Int))] -> Int -> Move -> Bool -> (Label, Label) -> [Tree ((Label, Int, Position), (Board, Int, Int))]

0 comments on commit f30f73a

Please sign in to comment.