Skip to content

Commit d5ca406

Browse files
committed
Parsing Stack Dump
1 parent ebffee7 commit d5ca406

File tree

4 files changed

+99
-14
lines changed

4 files changed

+99
-14
lines changed

.vscode/tasks.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Build",
8+
"type": "shell",
9+
10+
"command": "./run.sh",
11+
12+
"problemMatcher": "$gcc",
13+
"group": {
14+
"kind": "build",
15+
"isDefault": true
16+
},
17+
"presentation": {
18+
"clear": true
19+
}
20+
}
21+
]
22+
}

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ Let's parse the [NuttX Stack Dump](https://gist.github.com/lupyuen/a715e4e77c011
202202
203203
TODO: Spot interesting addresses like 8000ad8a, c0202010
204204
205+
Let's try this...
206+
207+
```text
208+
[ 6.242000] stack_dump: 0xc02027e0: c0202010 00000000 00000001 00000000 00000000 00000000 8000ad8a 00000000
209+
```
210+
211+
212+
205213
# Compile PureScript to JavaScript in Web Browser
206214
207215
Here's how we compile PureScript to JavaScript inside our Web Browser...

run.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e # Exit when any command fails
4+
set -x # Echo commands
5+
6+
spago run

src/Main.purs

+63-14
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,69 @@ printResults :: Effect Unit
2020
printResults = do
2121
log "" -- empty blank line to separate output from function call
2222

23-
log "### Example Content 1 ###"
24-
doBoth "fail" ((fail "example failure message") :: Parser Unit) exampleContent1
25-
doBoth "numberOfAs" numberOfAs exampleContent1
26-
doBoth "removePunctuation" removePunctuation exampleContent1
27-
doBoth "replaceVowelsWithUnderscore" replaceVowelsWithUnderscore exampleContent1
28-
doBoth "tokenizeContentBySpaceChars" tokenizeContentBySpaceChars exampleContent1
29-
doBoth "extractWords" extractWords exampleContent1
30-
doBoth "badExtractWords" badExtractWords exampleContent1
31-
doBoth "quotedLetterExists" quotedLetterExists exampleContent1
32-
33-
log
34-
"\n\
35-
\### Example Content 2 ###"
36-
doBoth "parseCSV" parseCSV exampleContent2
23+
-- Parse the NuttX Stack Dump
24+
doRunParser "parseStackDump" parseStackDump "[ 6.242000] stack_dump: 0xc02027e0: c0202010 00000000 00000001 00000000 00000000 00000000 8000ad8a 00000000"
25+
26+
-- log "### Example Content 1 ###"
27+
-- doBoth "fail" ((fail "example failure message") :: Parser Unit) exampleContent1
28+
-- doBoth "numberOfAs" numberOfAs exampleContent1
29+
-- doBoth "removePunctuation" removePunctuation exampleContent1
30+
-- doBoth "replaceVowelsWithUnderscore" replaceVowelsWithUnderscore exampleContent1
31+
-- doBoth "tokenizeContentBySpaceChars" tokenizeContentBySpaceChars exampleContent1
32+
-- doBoth "extractWords" extractWords exampleContent1
33+
-- doBoth "badExtractWords" badExtractWords exampleContent1
34+
-- doBoth "quotedLetterExists" quotedLetterExists exampleContent1
35+
36+
-- log
37+
-- "\n\
38+
-- \### Example Content 2 ###"
39+
-- doBoth "parseCSV" parseCSV exampleContent2
40+
41+
-- parseStackDump :: Parser CsvContent
42+
parseStackDump = do
43+
let
44+
commaThenSpaces = string "," *> skipSpaces
45+
csvColumn = regex "[^,]+"
46+
47+
-- now we're on line 2
48+
idNumber <- csvColumn
49+
-- idNumber <- csvColumn <* commaThenSpaces
50+
-- firstName <- csvColumn <* commaThenSpaces
51+
-- lastName <- csvColumn <* commaThenSpaces
52+
-- age <- csvColumn <* commaThenSpaces
53+
54+
-- lookAhead will parse the content ahead of us,
55+
-- then reset the position of the string
56+
-- to what it was before it.
57+
-- originalEmail <- lookAhead $ regex "[^\n]+"
58+
59+
-- let
60+
-- parseAlphanumericChars = regex "[a-zA-Z0-9]+"
61+
-- parsePeriodsAndPlusesAsEmptyStrings =
62+
-- "" <$ ((string ".") <|> (string "+"))
63+
-- parseListOfParts =
64+
-- many1
65+
-- ( parseAlphanumericChars
66+
-- <|> parsePeriodsAndPlusesAsEmptyStrings
67+
-- )
68+
69+
-- usernameWithoutPeriodsOrPluses <- fold <$> parseListOfParts
70+
-- void $ string "@"
71+
-- domainName <- fold <$> (many1 ((regex "[a-zA-Z0-9]+") <|> (string ".")))
72+
-- void $ string "\n"
73+
74+
-- -- Ensure we hit the end of the string content via 'end-of-file'
75+
-- void eof
76+
77+
-- now return the parsed content
78+
pure
79+
{ idNumber
80+
-- , firstName
81+
-- , lastName
82+
-- , age
83+
-- , originalEmail
84+
-- , modifiedEmail: usernameWithoutPeriodsOrPluses <> "@" <> domainName
85+
}
3786

3887
-- Example Content 1
3988

0 commit comments

Comments
 (0)