mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated DevGuide (markdown)
15
DevGuide.md
15
DevGuide.md
@@ -101,15 +101,22 @@ Ok, modules loaded: ShellCheck.Parser, ShellCheck.AST, ShellCheck.ASTLib, ShellC
|
|||||||
*ShellCheck.Parser>
|
*ShellCheck.Parser>
|
||||||
```
|
```
|
||||||
|
|
||||||
This has given us a REPL where we can call parsing functions. There's a convenient `debugParse` function that will take a parser and a string, and give the result. The main parser function is `readScript`:
|
This has given us a REPL where we can call parsing functions. There's a convenient `debugParseScript` function that will take a string and give the complete parser result (minus noisy token positions):
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
*ShellCheck.Parser> debugParse readScript "sort file > tmp"
|
*ShellCheck.Parser> debugParseScript "sort file > tmp"
|
||||||
Right (T_Annotation (Id 1) [] (T_Script (Id 0) "" [T_Pipeline (Id 3) [] [T_Redirecting (Id 4) [T_FdRedirect (Id 10) "" (T_IoFile (Id 11) (T_Greater (Id 12)) (T_NormalWord (Id 13) [T_Literal (Id 14) "tmp"]))] (T_SimpleCommand (Id 5) [] [T_NormalWord (Id 6) [T_Literal (Id 7) "sort"],T_NormalWord (Id 8) [T_Literal (Id 9) "file"]])]]))
|
ParseResult {prComments = [], prTokenPositions = fromList [(Id 0,Position {posFile = "removed for clarity", posLine = -1, posColumn = -1})], prRoot = Just (T_Annotation (Id 1) [] (T_Script (Id 0) "" [T_Pipeline (Id 3) [] [T_Redirecting (Id 4) [T_FdRedirect (Id 10) "" (T_IoFile (Id 11) (T_Greater (Id 12)) (T_NormalWord (Id 13) [T_Literal (Id 14) "tmp"]))] (T_SimpleCommand (Id 5) [] [T_NormalWord (Id 6) [T_Literal (Id 7) "sort"],T_NormalWord (Id 8) [T_Literal (Id 9) "file"]])]]))}
|
||||||
*ShellCheck.Parser>
|
*ShellCheck.Parser>
|
||||||
```
|
```
|
||||||
|
|
||||||
Not very pretty, but we can see the part we're interested in:
|
Alternatively, if we've looked at the unit tests and found the parser responsible for a syntax element, we can use `debugParse` to call it directly:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
*ShellCheck.Parser> debugParse readIoRedirect "> tmp"
|
||||||
|
Right (T_FdRedirect (Id 0) "" (T_IoFile (Id 1) (T_Greater (Id 2)) (T_NormalWord (Id 3) [T_Literal (Id 4) "tmp"])))
|
||||||
|
```
|
||||||
|
|
||||||
|
Neither is very pretty, but we can see the part we're interested in:
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
(T_IoFile (Id 11) (T_Greater (Id 12)) (T_NormalWord (Id 13) [T_Literal (Id 14) "tmp"]))
|
(T_IoFile (Id 11) (T_Greater (Id 12)) (T_NormalWord (Id 13) [T_Literal (Id 14) "tmp"]))
|
||||||
|
Reference in New Issue
Block a user