better git ignore + update

This commit is contained in:
Yann Esposito (Yogsototh) 2013-10-07 22:34:27 +02:00
parent c62a03b6fd
commit 3387bb886c
20 changed files with 211 additions and 224 deletions

View file

@ -93,7 +93,46 @@
</ul>
</section>
<section class="slide">
<h2 id="parsing-example-1">Parsing Example (1)</h2>
<h2 id="parsing-in-programming-languages">Parsing in Programming Languages</h2>
<p>Complexity:</p>
<table>
<thead>
<tr class="header">
<th align="left">Method</th>
<th align="left">Typical Example</th>
<th align="left">Output Data Structure</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">Splitting</td>
<td align="left">CSV</td>
<td align="left">Array, Map</td>
</tr>
<tr class="even">
<td align="left">Regexp</td>
<td align="left">email</td>
<td align="left">+ Fixed Layout Tree</td>
</tr>
<tr class="odd">
<td align="left">Parser</td>
<td align="left">Programming language</td>
<td align="left">+ Most Data Structure</td>
</tr>
</tbody>
</table>
</section>
<section class="slide">
<h2 id="parser-culture">Parser <span class="and">&amp;</span> culture</h2>
<p>In Haskell Parser are really easy to use.</p>
<p>Generally:</p>
<ul>
<li>In most languages: <strong>split</strong> then <strong>regexp</strong> then <strong>parse</strong></li>
<li>In Haskell: <strong>split</strong> then <strong>parse</strong></li>
</ul>
</section>
<section class="slide">
<h2 id="parsing-example">Parsing Example</h2>
<p>From String:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">(<span class="dv">1</span><span class="fu">+</span><span class="dv">3</span>)<span class="fu">*</span>(<span class="dv">1</span><span class="fu">+</span><span class="dv">5</span><span class="fu">+</span><span class="dv">9</span>)</code></pre>
<p>To data structure:</p>
@ -108,11 +147,38 @@
</blockquote>
</section>
<section class="slide">
<h2 id="parsecs">Parsec(s)</h2>
<p>In reality there is many choices:</p>
<pre><code>- attoparsec: fast
- Bytestring-lexing: fast
- Parsec 3: powerful, nice error reporting</code></pre>
<h2 id="parser-libraries">Parser Libraries</h2>
<p>In reality there are many choices:</p>
<table>
<tbody>
<tr class="odd">
<td align="left">attoparsec</td>
<td align="left">fast</td>
</tr>
<tr class="even">
<td align="left">Bytestring-lexing</td>
<td align="left">fast</td>
</tr>
<tr class="odd">
<td align="left">Parsec 3</td>
<td align="left">powerful, nice error reporting</td>
</tr>
</tbody>
</table>
</section>
<section class="slide">
<h2 id="haskell-remarks-1">Haskell Remarks (1)</h2>
<p>spaces are meaningful</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">f x <span class="co">-- ⇔ f(x) in C-like languages</span>
f x y <span class="co">-- ⇔ f(x,y)</span></code></pre>
</section>
<section class="slide">
<h2 id="haskell-remarks-2">Haskell Remarks (2)</h2>
<p>Don't mind strange operators (<code>&lt;*&gt;</code>, <code>&lt;$&gt;</code>).<br />Consider them like separators, typically commas.<br />They are just here to deal with types.</p>
<p>Informally:</p>
<pre class="sourceCode haskell"><code class="sourceCode haskell">toto <span class="fu">&lt;$&gt;</span> x <span class="fu">&lt;*&gt;</span> y <span class="fu">&lt;*&gt;</span> z
<span class="co">-- ⇔ toto x y z</span>
<span class="co">-- ⇔ toto(x,y,z) in C-like languages</span></code></pre>
</section>
<section class="slide">
<h2 id="a-parsec-example">A Parsec Example</h2>
@ -129,25 +195,48 @@ unexpected <span class="st">&quot; &quot;</span>
expecting digit</code></pre>
</section>
<section class="slide">
<h2 id="comparison-with-regexp-parsec">Comparison with Regexp (Parsec)</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">IP</span> <span class="fu">=</span> <span class="dt">IP</span> <span class="dt">Word8</span> <span class="dt">Word8</span> <span class="dt">Word8</span> <span class="dt">Word8</span>
ip <span class="fu">=</span> <span class="dt">IP</span> <span class="fu">&lt;$&gt;</span>
number <span class="fu">&lt;*</span> char <span class="ch">&#39;.&#39;</span> <span class="fu">&lt;*&gt;</span>
number <span class="fu">&lt;*</span> char <span class="ch">&#39;.&#39;</span> <span class="fu">&lt;*&gt;</span>
number <span class="fu">&lt;*</span> char <span class="ch">&#39;.&#39;</span> <span class="fu">&lt;*&gt;</span>
number
number <span class="fu">=</span> <span class="kw">do</span>
x <span class="ot">&lt;-</span> read <span class="fu">&lt;$&gt;</span> many1 digit
guard (<span class="dv">0</span> <span class="fu">&lt;=</span> x <span class="fu"><span class="and">&amp;</span><span class="and">&amp;</span></span> x <span class="fu">&lt;</span> <span class="dv">256</span>)
return (fromIntegral x)</code></pre>
</section>
<section class="slide">
<h2 id="comparison-with-regexp-perl-regexp">Comparison with Regexp (Perl Regexp)</h2>
<pre class="sourceCode perl"><code class="sourceCode perl"><span class="co"># remark: 888.999.999.999 is accepted</span>
\b\d{<span class="dv">1</span>,<span class="dv">3</span>}\.\d{<span class="dv">1</span>,<span class="dv">3</span>}\.\d{<span class="dv">1</span>,<span class="dv">3</span>}\.\d{<span class="dv">1</span>,<span class="dv">3</span>}\b
<span class="co"># exact but difficult to read</span>
\b(?:(?:<span class="dv">25</span>[<span class="dv">0-5</span>]|<span class="dv">2</span>[<span class="dv">0-4</span>][<span class="dv">0-9</span>]|[<span class="dv">01</span>]?[<span class="dv">0-9</span>][<span class="dv">0-9</span>]?)\.){<span class="dv">3</span>}
(?:<span class="dv">25</span>[<span class="dv">0-5</span>]|<span class="dv">2</span>[<span class="dv">0-4</span>][<span class="dv">0-9</span>]|[<span class="dv">01</span>]?[<span class="dv">0-9</span>][<span class="dv">0-9</span>]?)\b</code></pre>
<p>Also, regexp are <em>unityped</em> by nature.</p>
</section>
<section class="slide">
<h2 id="monadic-style">Monadic style</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">number ::</span> <span class="dt">Parser</span> <span class="dt">String</span>
number <span class="fu">=</span> many1 digit
<span class="ot">number&#39; ::</span> <span class="dt">Parser</span> <span class="dt">Int</span>
number&#39; <span class="fu">=</span> <span class="kw">do</span>
string_of_number <span class="ot">&lt;-</span> many1 digit
<span class="fu">return</span> (<span class="fu">read</span> string_of_number)</code></pre>
<span class="co">-- digitString :: String</span>
digitString <span class="ot">&lt;-</span> many1 digit
return (read digitString)</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="st">&quot;32&quot;</span><span class="ot"> ::</span> [<span class="dt">Char</span>] <span class="co">-- number on &quot;32&quot;</span>
<span class="dv">32</span><span class="ot"> ::</span> <span class="dt">Int</span> <span class="co">-- number&#39; on &quot;32&quot;</span></code></pre>
</section>
<section class="slide">
<h2 id="combining-monadic-style">Combining Monadic style</h2>
<p><br /><span class="math"><em>S</em>=<em>a</em><em>S</em><em>b</em><em>ε</em></span><br /></p>
<h2 id="combining-monadic-style-s-asb-ε">Combining Monadic style (S = aSb | ε)</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell">s <span class="fu">=</span> (<span class="kw">do</span>
a <span class="ot">&lt;-</span> char <span class="ch">&#39;a&#39;</span>
mid <span class="ot">&lt;-</span> <span class="dt">S</span>
b <span class="ot">&lt;-</span> char <span class="ch">&#39;b&#39;</span>
<span class="fu">return</span> (a<span class="fu">:</span>mid) <span class="fu">++</span> b<span class="fu">:</span>[])
a <span class="ot">&lt;-</span> string <span class="st">&quot;a&quot;</span>
mid <span class="ot">&lt;-</span> s
b <span class="ot">&lt;-</span> string <span class="st">&quot;b&quot;</span>
return (a <span class="fu">++</span> mid <span class="fu">++</span> b)
<span class="fu">&lt;|&gt;</span> string <span class="st">&quot;&quot;</span></code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="st">&quot;&quot;</span> <span class="co">-- s on &quot;&quot;</span>
<span class="st">&quot;aaabbb&quot;</span> <span class="co">-- s on &quot;aaabbb&quot;</span>
@ -158,8 +247,7 @@ unexpected end <span class="kw">of</span> input
expecting <span class="st">&quot;b&quot;</span></code></pre>
</section>
<section class="slide">
<h2 id="applicative-style">Applicative style</h2>
<p><br /><span class="math"><em>S</em>=<em>a</em><em>S</em><em>b</em><em>ε</em></span><br /></p>
<h2 id="combining-applicative-style-s-asb-ε">Combining Applicative style (S = aSb | ε)</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell">s <span class="fu">=</span> concat3 <span class="fu">&lt;$&gt;</span> string <span class="st">&quot;a&quot;</span> <span class="fu">&lt;*&gt;</span> s <span class="fu">&lt;*&gt;</span> char <span class="st">&quot;b&quot;</span>
<span class="fu">&lt;|&gt;</span> string <span class="st">&quot;&quot;</span>
<span class="kw">where</span>
@ -183,20 +271,20 @@ monadicParseIP <span class="fu">=</span> <span class="kw">do</span>
d3 <span class="ot">&lt;-</span> number
char <span class="ch">&#39;.&#39;</span>
d4 <span class="ot">&lt;-</span> number
<span class="fu">return</span> (<span class="dt">IP</span> d1 d2 d3 d4)</code></pre>
return (<span class="dt">IP</span> d1 d2 d3 d4)</code></pre>
</section>
<section class="slide">
<h2 id="write-number-correctly">Write number correctly</h2>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">number ::</span> <span class="dt">Parser</span> <span class="dt">Int</span>
number <span class="fu">=</span> <span class="kw">do</span>
x <span class="ot">&lt;-</span> <span class="fu">read</span> <span class="fu">&lt;$&gt;</span> many1 digit
x <span class="ot">&lt;-</span> read <span class="fu">&lt;$&gt;</span> many1 digit
guard (<span class="dv">0</span> <span class="fu">&lt;=</span> x <span class="fu"><span class="and">&amp;</span><span class="and">&amp;</span></span> x <span class="fu">&lt;</span> <span class="dv">256</span>) <span class="fu">&lt;?&gt;</span>
<span class="st">&quot;Number between 0 and 255 (here &quot;</span> <span class="fu">++</span> <span class="fu">show</span> x <span class="fu">++</span> <span class="st">&quot;)&quot;</span>
<span class="fu">return</span> (<span class="fu">fromIntegral</span> x)</code></pre>
<span class="st">&quot;Number between 0 and 255 (here &quot;</span> <span class="fu">++</span> show x <span class="fu">++</span> <span class="st">&quot;)&quot;</span>
return (fromIntegral x)</code></pre>
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="fu">&gt;&gt;&gt;</span> test parseIP <span class="st">&quot;parseIP&quot;</span> <span class="st">&quot;823.32.80.113&quot;</span>
<span class="st">&quot;parseIP&quot;</span> (line <span class="dv">1</span>, column <span class="dv">4</span>)<span class="fu">:</span>
unexpected <span class="st">&quot;.&quot;</span>
expecting digit <span class="fu">or</span> <span class="dt">Number</span> between <span class="dv">0</span> <span class="fu">and</span> <span class="dv">255</span> (here <span class="dv">823</span>)</code></pre>
expecting digit or <span class="dt">Number</span> between <span class="dv">0</span> and <span class="dv">255</span> (here <span class="dv">823</span>)</code></pre>
</section>
<section class="slide">
<h2 id="so">So</h2>

1
parsec/.gitignore vendored
View file

@ -1 +1,2 @@
_html
_tmp

View file

@ -1,7 +0,0 @@
## Parsing
Latin pars (ōrātiōnis), meaning part (of speech).
- **analysing a string of symbols**
- **formal grammar**.

View file

@ -1,12 +0,0 @@
## Parsing Example (1)
From String:
``` haskell
(1+3)*(1+5+9)
```
To data structure:
![AST](parsec/img/mp/AST.png)\

View file

@ -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 [...]"

View file

@ -1,8 +0,0 @@
## Parsec(s)
In reality there is many choices:
- attoparsec: fast
- Bytestring-lexing: fast
- Parsec 3: powerful, nice error reporting

View file

@ -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
```

View file

@ -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"
```

View file

@ -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"
```

View file

@ -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
```

View file

@ -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)
```

View file

@ -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)
```

View file

@ -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

View file

@ -1,4 +0,0 @@
## A Simple DSL
Let's write a minimal DSL

View file

@ -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
```

View file

@ -1,7 +0,0 @@
## Data Structure
Remember from text to data structure
``` haskell
data Tree = Node Element [Tree]
```

View file

@ -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"

View file

@ -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 ;;

View file

@ -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; }

View file

@ -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