|
1 | 1 | # Scanlib |
2 | 2 |
|
3 | | -Use Scanspec to validate input files and generate input parsing code in Go, C++14, and Python 3. |
| 3 | +Use Scanspec to validate input files and generate input parsing code in C99, C++14, Go, and Python 3. |
4 | 4 |
|
5 | 5 | ## Scanspec |
6 | 6 |
|
|
22 | 22 | eof |
23 | 23 | ``` |
24 | 24 |
|
25 | | -``` go |
26 | | -package main |
27 | | - |
28 | | -import "fmt" |
| 25 | +``` c |
| 26 | +#include <stdio.h> |
29 | 27 |
|
30 | | -func main() { |
31 | | - var A, B int |
32 | | - fmt.Scan(&A, &B) |
| 28 | +int main() { |
| 29 | + int A, B; |
| 30 | + scanf("%d %d", &A, &B); |
33 | 31 |
|
| 32 | + return 0; |
34 | 33 | } |
35 | 34 | ``` |
36 | 35 |
|
37 | 36 | ``` cpp |
38 | | -// Generated using Scanlib |
39 | | - |
40 | 37 | #include <iostream> |
41 | 38 |
|
42 | 39 | using namespace std; |
43 | 40 |
|
44 | 41 | int main() { |
45 | 42 | int A, B; |
46 | | - cin >> A; |
47 | | - cin >> B; |
| 43 | + cin >> A >> B; |
48 | 44 |
|
49 | 45 | return 0; |
50 | 46 | } |
51 | 47 | ``` |
52 | 48 |
|
53 | | -``` py |
54 | | -# Generated using Scanlib |
| 49 | +``` go |
| 50 | +package main |
| 51 | + |
| 52 | +import "fmt" |
| 53 | + |
| 54 | +func main() { |
| 55 | + var A, B int |
| 56 | + fmt.Scan(&A, &B) |
| 57 | + |
| 58 | +} |
| 59 | +``` |
55 | 60 |
|
| 61 | +``` py |
56 | 62 | A, B = map(int, input().split()) |
57 | 63 | ``` |
58 | 64 |
|
|
81 | 87 | ``` |
82 | 88 |
|
83 | 89 | ``` cpp |
84 | | -// Generated using Scanlib |
85 | | - |
86 | 90 | #include <iostream> |
87 | 91 | #include <string> |
88 | 92 |
|
89 | 93 | using namespace std; |
90 | 94 |
|
91 | 95 | int main() { |
92 | 96 | int R, C; |
93 | | - cin >> R; |
94 | | - cin >> C; |
| 97 | + cin >> R >> C; |
95 | 98 | string G[R]; |
96 | 99 | for (int i = 0; i < R; ++i) { |
97 | 100 | cin >> G[i]; |
98 | 101 | } |
99 | | - |
| 102 | + |
100 | 103 | return 0; |
101 | 104 | } |
102 | 105 | ``` |
103 | 106 |
|
104 | 107 | ``` py |
105 | | -# Generated using Scanlib |
106 | | - |
107 | 108 | R, C = map(int, input().split()) |
108 | 109 | G = [""] * R |
109 | 110 | for i in range(0, R): |
@@ -138,11 +139,22 @@ string |
138 | 139 | []T |
139 | 140 | ``` |
140 | 141 |
|
| 142 | +#### Operators |
| 143 | + |
| 144 | +``` |
| 145 | ++ - * / ** |
| 146 | +== != < > <= >= |
| 147 | +&& || |
| 148 | +``` |
| 149 | + |
| 150 | +The `**` operator performs exponentiation. |
| 151 | + |
141 | 152 | #### Check Statements |
142 | 153 |
|
143 | 154 | ``` |
144 | 155 | check n > 0, n < 1000 |
145 | 156 | check e > 0, f < 5.0 |
| 157 | +check n ** 2 < 1000000 |
146 | 158 | ``` |
147 | 159 |
|
148 | 160 | #### Variable Declarations |
@@ -241,10 +253,24 @@ sum(a...): Returns the sum of the arguments. Accepts int, int64, and []int value |
241 | 253 | toInt64(s, b=10): Parses string s in base b and returns in int64. |
242 | 254 | ``` |
243 | 255 |
|
| 256 | +## CLI |
| 257 | + |
| 258 | +``` |
| 259 | +go install git.furqansoftware.net/toph/scanlib/cmd/scanlib@latest |
| 260 | +``` |
| 261 | + |
| 262 | +Evaluate a Scanspec file against an input file: |
| 263 | + |
| 264 | +``` |
| 265 | +scanlib scanspec input.txt |
| 266 | +``` |
| 267 | + |
| 268 | +Or read input from stdin: |
| 269 | + |
| 270 | +``` |
| 271 | +echo "3 2" | scanlib scanspec |
| 272 | +``` |
| 273 | + |
244 | 274 | ## TODO |
245 | 275 |
|
246 | | -- [x] If Statements |
247 | | -- [x] C Generator |
248 | | -- [x] Go Generator |
249 | 276 | - [ ] Graph Checks |
250 | | -- [x] CLI Tool |
|
0 commit comments