Git Product home page Git Product logo

scanlib's Introduction

Scanlib

Use Scanspec Validate input files and generate input code in different programming languages.

Scanspec

Learn more about Scanspec here.

Examples

Two Integers

3 2
var A, B int
scan A, B
check A >= 0, A < 10, B >= 0, B < 20
eol
eof
// Generated using Scanlib

#include <iostream>

using namespace std;

int main() {
	int A, B;
	cin >> A;
	cin >> B;
	
	return 0;
}
# Generated using Scanlib

A, 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
// Generated using Scanlib

#include <iostream>
#include <string>

using 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;
}
# Generated using Scanlib

R, 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 Statements

The 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

  • If Statements
  • C Generator
  • Go Generator
  • Graph Checks
  • CLI Tool
  • and more...

scanlib's People

Contributors

hjr265 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scanlib's Issues

Checking space formatting of input

Suppose problem statement says an array is given input as N space-separated integers in a single line.

Any suggestion on how we can check if test cases strictly follow such claim?

Mainly, I want to check if there is a single space between two integers, no space at start or end of the array, all integers are in a single line etc.

One way for doing this currently is taking the whole line input as a string and parse the integers from their manually (provided each character in the string can be accessed separately). We can then use regex on the string to check the space formatting and such.

If something like sscanf or stringstream from C/C++ is supported, then it would be much easier as the parsing from string would not need manual handling then while we can still use the regex on the string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.