diff --git a/parsec.html b/parsec.html
index fb5b766..8c88049 100644
--- a/parsec.html
+++ b/parsec.html
@@ -93,7 +93,46 @@
-Parsing Example (1)
+Parsing in Programming Languages
+Complexity:
+
+
+
+
+
+
+Splitting |
+CSV |
+Array, Map |
+
+
+Regexp |
+email |
++ Fixed Layout Tree |
+
+
+Parser |
+Programming language |
++ Most Data Structure |
+
+
+
+
+
+Parser & culture
+In Haskell Parser are really easy to use.
+Generally:
+
+- In most languages: split then regexp then parse
+- In Haskell: split then parse
+
+
+
+Parsing Example
From String:
(1+3)*(1+5+9)
To data structure:
@@ -108,11 +147,38 @@
-Parsec(s)
-In reality there is many choices:
-- attoparsec: fast
-- Bytestring-lexing: fast
-- Parsec 3: powerful, nice error reporting
+Parser Libraries
+In reality there are many choices:
+
+
+
+attoparsec |
+fast |
+
+
+Bytestring-lexing |
+fast |
+
+
+Parsec 3 |
+powerful, nice error reporting |
+
+
+
+
+
+
+spaces are meaningful
+f x -- ⇔ f(x) in C-like languages
+f x y -- ⇔ f(x,y)
+
+
+
+Don't mind strange operators (<*>
, <$>
).
Consider them like separators, typically commas.
They are just here to deal with types.
+Informally:
+toto <$> x <*> y <*> z
+ -- ⇔ toto x y z
+ -- ⇔ toto(x,y,z) in C-like languages
A Parsec Example
@@ -129,25 +195,48 @@ unexpected " "
expecting digit
+Comparison with Regexp (Parsec)
+data IP = IP Word8 Word8 Word8 Word8
+ip = IP <$>
+ number <* char '.' <*>
+ number <* char '.' <*>
+ number <* char '.' <*>
+ number
+number = do
+ x <- read <$> many1 digit
+ guard (0 <= x && x < 256)
+ return (fromIntegral x)
+
+
+Comparison with Regexp (Perl Regexp)
+# remark: 888.999.999.999 is accepted
+\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
+
+# exact but difficult to read
+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
+ (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
+Also, regexp are unityped by nature.
+
+
Monadic style
number :: Parser String
number = many1 digit
number' :: Parser Int
number' = do
- string_of_number <- many1 digit
- return (read string_of_number)
+ -- digitString :: String
+ digitString <- many1 digit
+ return (read digitString)
"32" :: [Char] -- number on "32"
32 :: Int -- number' on "32"
-Combining Monadic style
-
S = aSb∣ε
+Combining Monadic style (S = aSb | ε)
s = (do
- a <- char 'a'
- mid <- S
- b <- char 'b'
- return (a:mid) ++ b:[])
+ a <- string "a"
+ mid <- s
+ b <- string "b"
+ return (a ++ mid ++ b)
<|> string ""
"" -- s on ""
"aaabbb" -- s on "aaabbb"
@@ -158,8 +247,7 @@ unexpected end of input
expecting "b"
-Applicative style
-
S = aSb∣ε
+Combining Applicative style (S = aSb | ε)
s = concat3 <$> string "a" <*> s <*> char "b"
<|> string ""
where
@@ -183,20 +271,20 @@ monadicParseIP = do
d3 <- number
char '.'
d4 <- number
- return (IP d1 d2 d3 d4)
+ return (IP d1 d2 d3 d4)
Write number correctly
number :: Parser Int
number = do
- x <- read <$> many1 digit
+ x <- read <$> many1 digit
guard (0 <= x && x < 256) <?>
- "Number between 0 and 255 (here " ++ show x ++ ")"
- return (fromIntegral x)
+ "Number between 0 and 255 (here " ++ show x ++ ")"
+ return (fromIntegral x)
>>> test parseIP "parseIP" "823.32.80.113"
"parseIP" (line 1, column 4):
unexpected "."
-expecting digit or Number between 0 and 255 (here 823)
+expecting digit or Number between 0 and 255 (here 823)
So
diff --git a/parsec/.gitignore b/parsec/.gitignore
index d78b704..9b79981 100644
--- a/parsec/.gitignore
+++ b/parsec/.gitignore
@@ -1 +1,2 @@
_html
+_tmp
diff --git a/parsec/_tmp/10_Introduction/020_intro-000.md b/parsec/_tmp/10_Introduction/020_intro-000.md
deleted file mode 100644
index b32b645..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-000.md
+++ /dev/null
@@ -1,7 +0,0 @@
-## Parsing
-
-Latin pars (ōrātiōnis), meaning part (of speech).
-
-- **analysing a string of symbols**
-- **formal grammar**.
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-001.md b/parsec/_tmp/10_Introduction/020_intro-001.md
deleted file mode 100644
index 56efb7b..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-001.md
+++ /dev/null
@@ -1,12 +0,0 @@
-## Parsing Example (1)
-
-From String:
-
-``` haskell
-(1+3)*(1+5+9)
-```
-
-To data structure:
-
-![AST](parsec/img/mp/AST.png)\
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-002.md b/parsec/_tmp/10_Introduction/020_intro-002.md
deleted file mode 100644
index 6354d30..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-002.md
+++ /dev/null
@@ -1,10 +0,0 @@
-## Parsec
-
-> Parsec lets you construct parsers by combining high-order Combinators
-> to create larger expressions.
->
-> Combinator parsers are written and used within the same programming language
-> as the rest of the program.
->
-> The parsers are first-class citizens of the languages [...]"
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-003.md b/parsec/_tmp/10_Introduction/020_intro-003.md
deleted file mode 100644
index 2051f8a..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-003.md
+++ /dev/null
@@ -1,8 +0,0 @@
-## Parsec(s)
-
-In reality there is many choices:
-
- - attoparsec: fast
- - Bytestring-lexing: fast
- - Parsec 3: powerful, nice error reporting
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-004.md b/parsec/_tmp/10_Introduction/020_intro-004.md
deleted file mode 100644
index a626e85..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-004.md
+++ /dev/null
@@ -1,19 +0,0 @@
-## A Parsec Example
-
-``` haskell
-whitespaces = many (oneOf "\t ")
-number = many1 digit
-symbol = oneOf "!#$%&|*+-/:<=>?@^_~"
-```
-
-``` haskell
-" \t " -- whitespaces on " \t "
-"" -- whitespaces on "32"
-"32" -- number on "32"
-
--- number on " \t 32 "
-"number" (line 1, column 1):
-unexpected " "
-expecting digit
-```
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-005.md b/parsec/_tmp/10_Introduction/020_intro-005.md
deleted file mode 100644
index 0e38ba0..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-005.md
+++ /dev/null
@@ -1,17 +0,0 @@
-## Monadic style
-
-``` haskell
-number :: Parser String
-number = many1 digit
-
-number' :: Parser Int
-number' = do
- string_of_number <- many1 digit
- return (read string_of_number)
-```
-
-``` haskell
-"32" :: [Char] -- number on "32"
-32 :: Int -- number' on "32"
-```
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-006.md b/parsec/_tmp/10_Introduction/020_intro-006.md
deleted file mode 100644
index 7802e8c..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-006.md
+++ /dev/null
@@ -1,24 +0,0 @@
-## Combining Monadic style
-
-$$ S = aSb | ε $$
-
-``` haskell
-s = (do
- a <- char 'a'
- mid <- S
- b <- char 'b'
- return (a:mid) ++ b:[])
- <|> string ""
-
-```
-
-``` haskell
-"" -- s on ""
-"aaabbb" -- s on "aaabbb"
-"aabb" -- s on "aabbb"
--- s on "aaabb"
-S (line1 1, column 4):
-unexpected end of input
-expecting "b"
-```
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-007.md b/parsec/_tmp/10_Introduction/020_intro-007.md
deleted file mode 100644
index 3fc7358..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-007.md
+++ /dev/null
@@ -1,11 +0,0 @@
-## Applicative style
-
-$$ S = aSb | ε $$
-
-``` haskell
-s = concat3 <$> string "a" <*> s <*> char "b"
- <|> string ""
- where
- concat3 x y z = x ++ y ++ z
-```
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-008.md b/parsec/_tmp/10_Introduction/020_intro-008.md
deleted file mode 100644
index 01fbbd9..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-008.md
+++ /dev/null
@@ -1,22 +0,0 @@
-## Applicative Style usefull with Data types
-
-``` haskell
-data IP = IP Int Int Int Int
-
-parseIP = IP <$>
- number <* char '.' <*>
- number <* char '.' <*>
- number <* char '.' <*>
- number
-
-monadicParseIP = do
- d1 <- number
- char '.'
- d2 <- number
- char '.'
- d3 <- number
- char '.'
- d4 <- number
- return (IP d1 d2 d3 d4)
-```
-
diff --git a/parsec/_tmp/10_Introduction/020_intro-009.md b/parsec/_tmp/10_Introduction/020_intro-009.md
deleted file mode 100644
index d48edd4..0000000
--- a/parsec/_tmp/10_Introduction/020_intro-009.md
+++ /dev/null
@@ -1,17 +0,0 @@
-## Write number correctly
-
-``` haskell
-number :: Parser Int
-number = do
- x <- read <$> many1 digit
- guard (0 <= x && x < 256) >
- "Number between 0 and 255 (here " ++ show x ++ ")"
- return (fromIntegral x)
-```
-
-``` haskell
->>> test parseIP "parseIP" "823.32.80.113"
-"parseIP" (line 1, column 4):
-unexpected "."
-expecting digit or Number between 0 and 255 (here 823)
-```
diff --git a/parsec/_tmp/10_Introduction/030_advanced-000.md b/parsec/_tmp/10_Introduction/030_advanced-000.md
deleted file mode 100644
index 9f09790..0000000
--- a/parsec/_tmp/10_Introduction/030_advanced-000.md
+++ /dev/null
@@ -1,9 +0,0 @@
-## So
-
-- combination of simple parsers
-- error messages with `(>)`
-- embed result in data type using Applicative style
-- Not shown, use another monad with the parser
-
-Time to do something cool
-
diff --git a/parsec/_tmp/10_Introduction/030_advanced-001.md b/parsec/_tmp/10_Introduction/030_advanced-001.md
deleted file mode 100644
index 6012060..0000000
--- a/parsec/_tmp/10_Introduction/030_advanced-001.md
+++ /dev/null
@@ -1,4 +0,0 @@
-## A Simple DSL
-
-Let's write a minimal DSL
-
diff --git a/parsec/_tmp/10_Introduction/030_advanced-002.md b/parsec/_tmp/10_Introduction/030_advanced-002.md
deleted file mode 100644
index 13867de..0000000
--- a/parsec/_tmp/10_Introduction/030_advanced-002.md
+++ /dev/null
@@ -1,14 +0,0 @@
-## Useful definitions
-
-`try` tries to parse and backtracks if it fails.
-
-``` haskell
-(<||>) parser1 parser2 = try parser1 <|> parser2
-```
-
-`lexeme`, just skip spaces.
-
-``` haskell
-lexeme parser = whitespaces *> parser <* whitespaces
-```
-
diff --git a/parsec/_tmp/10_Introduction/030_advanced-003.md b/parsec/_tmp/10_Introduction/030_advanced-003.md
deleted file mode 100644
index f500ab5..0000000
--- a/parsec/_tmp/10_Introduction/030_advanced-003.md
+++ /dev/null
@@ -1,7 +0,0 @@
-## Data Structure
-
-Remember from text to data structure
-
-``` haskell
-data Tree = Node Element [Tree]
-```
diff --git a/parsec/content/020_intro.md b/parsec/content/020_intro.md
index 8d59fc7..72906ec 100644
--- a/parsec/content/020_intro.md
+++ b/parsec/content/020_intro.md
@@ -5,7 +5,26 @@ Latin pars (ōrātiōnis), meaning part (of speech).
- **analysing a string of symbols**
- **formal grammar**.
-## Parsing Example (1)
+## Parsing in Programming Languages
+
+Complexity:
+
+Method Typical Example Output Data Structure
+----------- ---------------------- ---------------------
+Splitting CSV Array, Map
+Regexp email + Fixed Layout Tree
+Parser Programming language + Most Data Structure
+
+## Parser & culture
+
+In Haskell Parser are really easy to use.
+
+Generally:
+
+- In most languages: **split** then **regexp** then **parse**
+- In Haskell: **split** then **parse**
+
+## Parsing Example
From String:
@@ -27,13 +46,38 @@ To data structure:
>
> The parsers are first-class citizens of the languages [...]"
-## Parsec(s)
+## Parser Libraries
-In reality there is many choices:
+In reality there are many choices:
- - attoparsec: fast
- - Bytestring-lexing: fast
- - Parsec 3: powerful, nice error reporting
+----------------- ------------------------------
+attoparsec fast
+Bytestring-lexing fast
+Parsec 3 powerful, nice error reporting
+----------------- ------------------------------
+
+## Haskell Remarks (1)
+
+spaces are meaningful
+
+``` haskell
+f x -- ⇔ f(x) in C-like languages
+f x y -- ⇔ f(x,y)
+```
+
+## Haskell Remarks (2)
+
+Don't mind strange operators (`<*>`, `<$>`).
+Consider them like separators, typically commas.
+They are just here to deal with types.
+
+Informally:
+
+``` haskell
+toto <$> x <*> y <*> z
+ -- ⇔ toto x y z
+ -- ⇔ toto(x,y,z) in C-like languages
+```
## A Parsec Example
@@ -54,6 +98,34 @@ unexpected " "
expecting digit
```
+## Comparison with Regexp (Parsec)
+
+``` haskell
+data IP = IP Word8 Word8 Word8 Word8
+ip = IP <$>
+ number <* char '.' <*>
+ number <* char '.' <*>
+ number <* char '.' <*>
+ number
+number = do
+ x <- read <$> many1 digit
+ guard (0 <= x && x < 256)
+ return (fromIntegral x)
+```
+
+## Comparison with Regexp (Perl Regexp)
+
+``` perl
+# remark: 888.999.999.999 is accepted
+\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
+
+# exact but difficult to read
+\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
+ (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
+```
+
+Also, regexp are _unityped_ by nature.
+
## Monadic style
``` haskell
@@ -62,8 +134,9 @@ number = many1 digit
number' :: Parser Int
number' = do
- string_of_number <- many1 digit
- return (read string_of_number)
+ -- digitString :: String
+ digitString <- many1 digit
+ return (read digitString)
```
``` haskell
@@ -71,16 +144,14 @@ number' = do
32 :: Int -- number' on "32"
```
-## Combining Monadic style
-
-$$ S = aSb | ε $$
+## Combining Monadic style (S = aSb | ε)
``` haskell
s = (do
- a <- char 'a'
- mid <- S
- b <- char 'b'
- return (a:mid) ++ b:[])
+ a <- string "a"
+ mid <- s
+ b <- string "b"
+ return (a ++ mid ++ b)
<|> string ""
```
@@ -95,9 +166,7 @@ unexpected end of input
expecting "b"
```
-## Applicative style
-
-$$ S = aSb | ε $$
+## Combining Applicative style (S = aSb | ε)
``` haskell
s = concat3 <$> string "a" <*> s <*> char "b"
diff --git a/parsec/gen b/parsec/gen
index 45acacd..e744330 100755
--- a/parsec/gen
+++ b/parsec/gen
@@ -31,7 +31,6 @@ for slide in **/*.{md,html}(.N); do
md) i=0
for tmpfic in $(splitMarkdown $slide); do
((i++))
- print "Split $tmpfic"
dst="$( print -- ${tmpfic:r}.html | sed 's#'$tmpdir'#'$htmldir'#' )"
pandoc -f markdown -t html $tmpfic > $dst
done ;;
diff --git a/themes/style/y/main.css b/themes/style/y/main.css
index d5659c2..8c058b9 100644
--- a/themes/style/y/main.css
+++ b/themes/style/y/main.css
@@ -794,7 +794,12 @@ body.deck-container {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box; }
- .deck-container table tr td {
+ .deck-container table tr th {
+ border-bottom: solid 1px #657b83;
+ color: #93a1a1;
+ background: #002b36;
+ font-style: italic; }
+ .deck-container table tr td, .deck-container table tr th {
padding: 2px 0.5em; }
.deck-container table tr:nth-child(odd) {
background-color: #073642; }
diff --git a/themes/style/y/main.sass b/themes/style/y/main.sass
index 253ac69..d069d24 100644
--- a/themes/style/y/main.sass
+++ b/themes/style/y/main.sass
@@ -1034,8 +1034,14 @@ body.deck-container
box-sizing: border-box
-moz-box-sizing: border-box
-webkit-box-sizing: border-box
- table tr td
- padding: 2px .5em
+ table tr
+ th
+ border-bottom: solid 1px $base00
+ color: $base1
+ background: $base03
+ font-style: italic
+ td,th
+ padding: 2px .5em
table tr
&:nth-child(odd)
background-color: $secondBackgroundColor