Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/furqansoftware/scanlib
Input validator and code generator
https://github.com/furqansoftware/scanlib
go golang toph
Last synced: 19 days ago
JSON representation
Input validator and code generator
- Host: GitHub
- URL: https://github.com/furqansoftware/scanlib
- Owner: FurqanSoftware
- License: bsd-3-clause
- Created: 2021-02-13T11:51:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T16:38:31.000Z (12 months ago)
- Last Synced: 2024-04-09T22:18:00.299Z (9 months ago)
- Topics: go, golang, toph
- Language: Go
- Homepage:
- Size: 506 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Scanlib
Use Scanspec Validate input files and generate input code in different programming languages.
## Scanspec
Learn more about Scanspec [here](https://help.toph.co/drafts/scanspec).
### Examples
#### Two Integers
```
3 2
``````
var A, B int
scan A, B
check A >= 0, A < 10, B >= 0, B < 20
eol
eof
`````` cpp
// Generated using Scanlib#include
using namespace std;
int main() {
int A, B;
cin >> A;
cin >> B;
return 0;
}
`````` py
# Generated using ScanlibA, B = map(int, input().split())
```#### R, C, and Grid
```
3 5
**...
..*..
....*
``````
var R, C int
scan R, C
check R >= 1, R < 25, C >= 1, C < 25
eol
var G [R]string
for i := 0 ... R
scan G[i]
check len(G[i]) == C
check re(G[i], "^[*.]+$")
eol
end
eof
`````` cpp
// Generated using Scanlib#include
#includeusing namespace std;
int main() {
int R, C;
cin >> R;
cin >> C;
string G[R];
for (int i = 0; i < R; ++i) {
cin >> G[i];
}
return 0;
}
`````` py
# Generated using ScanlibR, C = map(int, input().split())
G = [""] * R
for i in range(0, R):
G[i] = input()
```### Specification
#### Comments
A comment begins with the # character, and ends at the end of the line. A comment cannot begin within a string literal.
```
# This is a comment
```#### Keywords
```
check eof eol for scan var
```#### Types
```
bool
int
int64
float32
float64
string
[]T
```#### Check Statements
```
check n > 0, n < 1000
check e > 0, f < 5.0
```#### Variable Declarations
```
var n int
var e, f float64
var a, b string
var G [R]string
```#### Scan Statements
```
scan n
scan a, e
scan e, f, n
scan G[2]
```#### If Statements
```
if q == 1
scan i, G[i]
else if q == 2
scan a
else if q == 3
scan l, h
else
scan G[q]
end
```#### For Range Statements
```
for i := 0 ... n
scan G[i]
end
```#### For Scan/Scanln Statements
```
var s string
var i int
for scan s, i
# Scans s and i repeatedly until EOF
end
``````
var s string
for scanln s
# Scans line to s repeatedly until EOF
end
```#### EOL Statements
The following indicates end of line.
```
eol
```
#### EOL StatementsThe following indicates end of file.
```
eof
```#### Built-in Functions
```
len(a): Returns the length of array a.
re(s, x): Returns true if string s matches regular expression x.
pow(n, e): Returns n raised to the power of e. Result is int or int64 if both n and e are int or int64, otherwise float64.
toInt64(s, b=10): Parses string s in base b and returns in int64.
```## TODO
- [x] If Statements
- [ ] C Generator
- [x] Go Generator
- [ ] Graph Checks
- [ ] CLI Tool
- and more...