File tree Expand file tree Collapse file tree 13 files changed +157
-73
lines changed
lib/language/src/Language Expand file tree Collapse file tree 13 files changed +157
-73
lines changed Original file line number Diff line number Diff line change 1
1
# Copager2(仮)
2
2
3
- ## Bin
3
+ ## 記述例( [ app/src/Arithmetic.hs ] ( ./app/Arithmetic.hs ) )
4
4
5
- - [ Main] ( ./app ) : メインプログラム
5
+ ``` haskell
6
+ main :: IO ()
7
+ main = do
8
+ input <- getLine
9
+ result <- runProcessor mkProcessor input
10
+ case result of
11
+ Right sexp -> print sexp
12
+ Left err -> putStrLn $ " error: " ++ show err
13
+
14
+ mkProcessor :: ProcessorT IO ArithmeticToken ArithmeticRule (SExp _ _ )
15
+ mkProcessor = ProcessorT $ do
16
+ token <- lex
17
+ events <- parse token
18
+ consume events
19
+
20
+ ```
6
21
7
22
## Library
8
23
12
27
13
28
## Example
14
29
15
- ### 記述例( [ app/Main.hs ] ( ./app/Main.hs ) )
30
+ ### 普通のパーサ
16
31
17
- ``` haskell
18
- main :: IO ()
19
- main = do
20
- input <- getLine
21
- result <- runProcessor mkProcessor input
22
- case result of
23
- Left err -> putStrLn $ " error: " ++ show err
24
- Right sexp -> fmtPrint sexp
25
-
26
- mkProcessor :: ProcessorT IO ArithmeticToken ArithmeticRule () (SExp _ _ )
27
- mkProcessor = ProcessorT setup process where
28
- setup _ = (mkSLR1 Addition , empty)
29
- process = do
30
- token <- lex
31
- events <- parse token
32
- consume events
33
- ```
32
+ - [ lang-arithmetic] ( ./app/lang/src/Arithmetic.hs ) : 四則演算
33
+ - [ lang-json] ( ./app/lang/src/json.hs ) : JSON
34
+ - [ lang-pl0] ( ./app/lang/src/Pl0.hs ) : Pl/0
35
+ - [ lang-xml] ( ./app/lang/src/Xml.hs ) : Xml
34
36
35
- ### 実行
37
+ ### エラーハンドリング
36
38
37
- ```
38
- $ cabal run main
39
- (10 + 20) * 30
40
- - Addition
41
- - Multiplication
42
- - Multiplication
43
- - Number
44
- - Addition
45
- - Addition
46
- - Multiplication
47
- - Number: 10
48
- - Multiplication
49
- - Number: 20
50
- - Number: 30
51
- ```
39
+ - [ errh-panicmode] ( ./app/errh/src/PanicMode.hs ) : パニックモード
40
+ - [ errh-corchuelo] ( ./app/errh/src/Corchuelo.hs ) : Corchuelo (※)
Original file line number Diff line number Diff line change 1
1
cabal-version : 3.0
2
- name : errh-corchuelo
2
+ name : errh
3
3
version : 0.1.0.0
4
4
author : NakagamiYuta
5
5
maintainer : guguru0014@gmail.com
6
6
build-type : Simple
7
7
8
+ executable errh-panicmode
9
+ main-is : PanicMode.hs
10
+ hs-source-dirs : src
11
+ build-depends :
12
+ base,
13
+ mtl,
14
+ copager2,
15
+ language,
16
+ err-handling,
17
+
8
18
executable errh-corchuelo
9
- main-is : Main .hs
19
+ main-is : corchuelo .hs
10
20
hs-source-dirs : src
11
21
build-depends :
12
22
base,
File renamed without changes.
File renamed without changes.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ cabal-version : 3.0
2
+ name : lang
3
+ version : 0.1.0.0
4
+ author : NakagamiYuta
5
+ maintainer : guguru0014@gmail.com
6
+ build-type : Simple
7
+
8
+ executable lang-arithmetic
9
+ main-is : Arithmetic.hs
10
+ hs-source-dirs : src
11
+ build-depends :
12
+ base,
13
+ mtl,
14
+ copager2,
15
+ language,
16
+
17
+ executable lang-json
18
+ main-is : Json.hs
19
+ hs-source-dirs : src
20
+ build-depends :
21
+ base,
22
+ mtl,
23
+ copager2,
24
+ language,
25
+
26
+ executable lang-pl0
27
+ main-is : Pl0.hs
28
+ hs-source-dirs : src
29
+ build-depends :
30
+ base,
31
+ mtl,
32
+ copager2,
33
+ language,
34
+
35
+ executable lang-xml
36
+ main-is : Xml.hs
37
+ hs-source-dirs : src
38
+ build-depends :
39
+ base,
40
+ mtl,
41
+ copager2,
42
+ language,
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE PartialTypeSignatures #-}
2
+ {-# OPTIONS_GHC -Wno-partial-type-signatures #-}
3
+
4
+ import Prelude hiding (lex )
5
+
6
+ import Copager2.Prelude
7
+ import Copager2.Lex.RegexLex (lex )
8
+ import Copager2.Parse.LR.Common.Driver (parse )
9
+ import Copager2.IR.SExp (SExp , consume )
10
+
11
+ import Language.Json (JsonToken , JsonRule )
12
+
13
+ main :: IO ()
14
+ main = do
15
+ input <- getLine
16
+ result <- runProcessor mkProcessor input
17
+ case result of
18
+ Right sexp -> print sexp
19
+ Left err -> putStrLn $ " error: " ++ show err
20
+
21
+ mkProcessor :: ProcessorT IO JsonToken JsonRule (SExp _ _ )
22
+ mkProcessor = ProcessorT $ do
23
+ token <- lex
24
+ events <- parse token
25
+ consume events
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE PartialTypeSignatures #-}
2
+ {-# OPTIONS_GHC -Wno-partial-type-signatures #-}
3
+
4
+ import Prelude hiding (lex )
5
+
6
+ import Copager2.Prelude
7
+ import Copager2.Lex.RegexLex (lex )
8
+ import Copager2.Parse.LR.Common.Driver (parse )
9
+ import Copager2.IR.SExp (SExp , consume )
10
+
11
+ import Language.Pl0 (Pl0Token , Pl0Rule )
12
+
13
+ main :: IO ()
14
+ main = do
15
+ input <- getLine
16
+ result <- runProcessor mkProcessor input
17
+ case result of
18
+ Right sexp -> print sexp
19
+ Left err -> putStrLn $ " error: " ++ show err
20
+
21
+ mkProcessor :: ProcessorT IO Pl0Token Pl0Rule (SExp _ _ )
22
+ mkProcessor = ProcessorT $ do
23
+ token <- lex
24
+ events <- parse token
25
+ consume events
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE PartialTypeSignatures #-}
2
+ {-# OPTIONS_GHC -Wno-partial-type-signatures #-}
3
+
4
+ import Prelude hiding (lex )
5
+
6
+ import Copager2.Prelude
7
+ import Copager2.Lex.RegexLex (lex )
8
+ import Copager2.Parse.LR.Common.Driver (parse )
9
+ import Copager2.IR.SExp (SExp , consume )
10
+
11
+ import Language.Xml (XmlToken , XmlRule )
12
+
13
+ main :: IO ()
14
+ main = do
15
+ input <- getLine
16
+ result <- runProcessor mkProcessor input
17
+ case result of
18
+ Right sexp -> print sexp
19
+ Left err -> putStrLn $ " error: " ++ show err
20
+
21
+ mkProcessor :: ProcessorT IO XmlToken XmlRule (SExp _ _ )
22
+ mkProcessor = ProcessorT $ do
23
+ token <- lex
24
+ events <- parse token
25
+ consume events
You can’t perform that action at this time.
0 commit comments