Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cram tests #34

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e36a03
Cram tests
Dec 16, 2014
953e956
Updated readme for documentaiton on cram
Dec 17, 2014
e138cd2
CRam
Dec 17, 2014
b5b0834
Added test, and folder for tests
Dec 17, 2014
94247b4
More tests
Dec 20, 2014
53acc84
make map to JavaScript like. map keys should be strings only.
matz Dec 15, 2014
daaae5b
add y.output (yacc debug output) to .gitignore
matz Dec 15, 2014
749b23a
Added Gitter badge
gitter-badger Dec 15, 2014
9c735b9
add more description of data-flow building in README.md; ref #22
matz Dec 16, 2014
38f11ce
Don't use bison-bridge
mattn Dec 16, 2014
71999a8
Fix "make test". Add Streem example file.
practicalswift Dec 16, 2014
70b49d0
Improve consistency in choice of indentation character.
practicalswift Dec 16, 2014
afcf9bb
Change file extension to .strm in light of decision in issue #24.
practicalswift Dec 17, 2014
e19f1dd
Set up Travis so it runs `make` with both clang and gcc
nickserv Dec 18, 2014
da959d3
Add a build status badge to the readme (using matz's repo)
nickserv Dec 18, 2014
152f8d9
Set yyin to file if provided.
halogenandtoast Dec 18, 2014
f190821
add example directory and move src/example.strm -> example/fizzbuzz.s…
matz Dec 19, 2014
9fdab36
Move Makefile to the root of the repo
nickserv Dec 20, 2014
1fcd514
Fix the Makefile so it controls files relative to the root directory
nickserv Dec 20, 2014
651fa3c
Update Makefile location for Travis, Vagrant, and the documentation
nickserv Dec 20, 2014
a06d962
use our own version of strdup/strndup; close #28
matz Dec 20, 2014
e230daa
Change Travis' test script to `make test`; close #45
matz Dec 20, 2014
1eb9487
Map tests now working. Now up to date with main
Dec 20, 2014
feaa1aa
"=" should be a token; fix #51
matz Dec 20, 2014
9620921
File extention change
Dec 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cscope.out
/src/y.tab.c
/src/lex.yy.c
/src/parse.tab.c
/src/y.output
/bin
/build
/lib
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: c
compiler:
- clang
- gcc
script: make test
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
YACC = bison -y
LEX = flex
TARGET = bin/streem

all : $(TARGET)

.PHONY : all

test : all
$(TARGET) example/fizzbuzz.strm
.PHONY : test

src/y.tab.c : src/parse.y
$(YACC) -o src/y.tab.c src/parse.y

src/lex.yy.c : src/lex.l
$(LEX) -o src/lex.yy.c src/lex.l

src/parse.o : src/y.tab.c src/lex.yy.c
$(CC) -g -c src/y.tab.c -o src/parse.o

$(TARGET) : src/parse.o
mkdir -p "$$(dirname $(TARGET))"
$(CC) -g src/parse.o -o $(TARGET)

clean :
rm -f src/y.output src/y.tab.c
rm -f src/lex.yy.c
rm -f src/*.o $(TARGET)
.PHONY : clean
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Streem - stream based concurrent scripting language

[![Build Status](https://travis-ci.org/matz/streem.svg?branch=master)](https://travis-ci.org/matz/streem)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/matz/streem?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Streem is a concurrent scripting language based on a programming model
similar to shell, with influences from Ruby, Erlang and other
functional programming languages.
Expand All @@ -10,7 +13,12 @@ In Streem, a simple `cat` program looks like this:
STDIN | STDOUT
```

And a simple FizzBuzz will look like this:
Streem is a (sort of) DSL for data flows. Above code means
building data-flow connection between `STDIN` and `STDOUT`.
Actual data processing will be done in the event loop
invoked after program execution.

For another example, a simple FizzBuzz will look like this:

```
seq(100) | {|x|
Expand All @@ -29,6 +37,10 @@ seq(100) | {|x|
} | STDOUT
```

The second part in the pipeline (`{|x|...}`) is a function
object. If a function object is connected in the pipeline,
it will be invoked for each elements in the stream.

# Note

Streem is still in the design stage. It's not working yet. Stay tuned.
Expand All @@ -38,11 +50,11 @@ Streem is still in the design stage. It's not working yet. Stay tuned.
* bison
* flex
* gcc / clang
* cram (python, pip)

# How to compile

```
cd src
make
```

Expand All @@ -53,6 +65,26 @@ you have granted non-exclusive right to your contributed code under
MIT license. Use <http://github.com/matz/streem/issues> for
discussion.

# How to test

## Cram

[Cram](https://bitheap.org/cram/) is a testing framework for testing command line applications.

Cram tests look like snippets of interactive shell sessions. Cram runs each command and compares the command output in the test with the command's actual output.

## Install Cram Testing Framework

```
$ sudo pip install cram
```

## Running tests

```
$ cram tests/*.t -E
```

# License

Streem is distributed under MIT license.
Expand Down
14 changes: 14 additions & 0 deletions example/fizzbuzz.strm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
seq(100) | {|x|
if x % 15 == 0 {
"FizzBuzz"
}
else if x % 3 == 0 {
"Fizz"
}
else if x % 5 == 0 {
"Buzz"
}
else {
x
}
} | STDOUT
30 changes: 0 additions & 30 deletions src/Makefile

This file was deleted.

96 changes: 65 additions & 31 deletions src/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,81 @@
** See Copyright Notice in LICENSE file.
*/

%option bison-bridge
%{
#define YY_DECL int yylex(YYSTYPE *yylval)

static char*
strdup0(const char *s)
{
size_t len = strlen(s);
char *p;

p = (char*)malloc(len+1);
if (p) {
strcpy(p, s);
}
return p;
}

static char*
strndup0(const char *s, size_t n)
{
size_t i, len;
const char *p = s;
char *new;

for (i=0; i<n && *p; i++,p++)
;
new = (char*)malloc(i+1);
if (new) {
memcpy(new, s, i);
new[i] = '\0';
}
return new;
}
%}

%option noyywrap

TRAIL [\t \n]*
%%
"+"{TRAIL} return op_plus;
"-"{TRAIL} return op_minus;
"*"{TRAIL} return op_mult;
"/"{TRAIL} return op_div;
"%"{TRAIL} return op_mod;
"=="{TRAIL} return op_eq;
"!="{TRAIL} return op_neq;
"<"{TRAIL} return op_lt;
"<="{TRAIL} return op_le;
">"{TRAIL} return op_gt;
">="{TRAIL} return op_ge;
"&&"{TRAIL} return op_and;
"||"{TRAIL} return op_or;
"|"{TRAIL} return op_bar;
"&"{TRAIL} return op_amper;
"<-"{TRAIL} return op_lasgn;
"->"{TRAIL} return op_rasgn;
"+"{TRAIL} return op_plus;
"-"{TRAIL} return op_minus;
"*"{TRAIL} return op_mult;
"/"{TRAIL} return op_div;
"%"{TRAIL} return op_mod;
"=="{TRAIL} return op_eq;
"!="{TRAIL} return op_neq;
"<"{TRAIL} return op_lt;
"<="{TRAIL} return op_le;
">"{TRAIL} return op_gt;
">="{TRAIL} return op_ge;
"&&"{TRAIL} return op_and;
"||"{TRAIL} return op_or;
"|"{TRAIL} return op_bar;
"&"{TRAIL} return op_amper;
"<-"{TRAIL} return op_lasgn;
"->"{TRAIL} return op_rasgn;
"="{TRAIL} return '=';

if{TRAIL} return keyword_if;
{TRAIL}else{TRAIL} return keyword_else;
break{TRAIL} return keyword_break;
emit{TRAIL} return keyword_emit;
return{TRAIL} return keyword_return;
nil{TRAIL} return keyword_nil;
true{TRAIL} return keyword_true;
false{TRAIL} return keyword_false;
if{TRAIL} return keyword_if;
{TRAIL}else{TRAIL} return keyword_else;
break{TRAIL} return keyword_break;
emit{TRAIL} return keyword_emit;
return{TRAIL} return keyword_return;
nil{TRAIL} return keyword_nil;
true{TRAIL} return keyword_true;
false{TRAIL} return keyword_false;

[A-Za-z_][A-Za-z0-9_]* {
yylval->str = strdup(yytext);
yylval->str = strdup0(yytext);
return identifier;
};

{TRAIL}\.{TRAIL} return '.';
[(\[{,;]{TRAIL} return yytext[0];
[)\]}] return yytext[0];
"\n" return '\n';
[(\[{,;:]{TRAIL} return yytext[0];
[)\]}] return yytext[0];
"\n" return '\n';

(([1-9][0-9]*)|0)(\.[0-9]*)? {
double temp;
Expand All @@ -54,7 +88,7 @@ false{TRAIL} return keyword_false;
};

\"([^\\\"]|\\.)*\" {
yylval->str = strndup(yytext+1, strlen(yytext)-2);
yylval->str = strndup0(yytext+1, strlen(yytext)-2);
return lit_string;
};

Expand Down
25 changes: 15 additions & 10 deletions src/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static void yyerror(parser_state *p, const char *s);
keyword_nil
keyword_true
keyword_false
op_lasgn
op_rasgn
op_lasgn
op_rasgn
op_plus
op_minus
op_mult
Expand All @@ -54,9 +54,9 @@ static void yyerror(parser_state *p, const char *s);
op_amper

%token
lit_number
lit_string
identifier
lit_number
lit_string
identifier

/*
* precedence table
Expand Down Expand Up @@ -152,12 +152,13 @@ primary : lit_number
| primary '.' identifier '(' opt_args ')'
| primary '.' identifier
| keyword_if expr '{' compstmt '}' opt_else
| keyword_nil
| keyword_true
| keyword_false
| keyword_nil
| keyword_true
| keyword_false
;

map : expr ':' expr
map : lit_string ':' expr
| identifier ':' expr
;

map_args : map
Expand Down Expand Up @@ -204,7 +205,11 @@ main(int argc, const char**argv)
{
int n;

// yydebug = 1;
if (argc > 1) {
yyin = fopen(argv[1], "r");
}

yydebug = 1;
n = yyparse(NULL);
if (n == 0) {
printf("Syntax OK\n");
Expand Down
Loading