Skip to content

Commit

Permalink
adding some options
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke committed Nov 18, 2012
1 parent 0f8303c commit a0b080e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ocello.*
.*
*.log
*.err
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ void main() {

Magic? yes.

## Documentation

### Options

You can pass parameters to cello.
For the moment only two are supported:

* indent: the indentation string to use (eg. " " or "\n")
* debug: some debug messages - for development only

Example:

```CoffeeScript
src = C(indent: " ", debug: yes) ->
main = ->
```


## TODO

* Find a way to support typed parameters (eg. type inference?)
Expand Down
54 changes: 32 additions & 22 deletions lib/cello.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions src/cello.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
exports.toAST = toAST = (f) -> jsp.parse f.toString()


term = (n) ->

indent = (n=0,ch='\t') ->
tmp = ""
for [0...n]
tmp += ch
tmp

debug = no
CParser = (func,options={}) ->

C = (func) ->
debug = options.debug ? no
indentationStr = options.indent ? '\t'

indent = (n=0) ->
tmp = ""
if indentationStr
for [0...n]
tmp += indentationStr
tmp


src = func.toString()
# convert th
src = "var ROOT = #{src};"
Expand Down Expand Up @@ -116,4 +115,11 @@ C = (func) ->
output = headers + output
output

exports.C = C
exports.C = C = (input) ->
options = {}
if isFunction input
CParser input, options
else
options = input
(input) -> CParser input, options

2 changes: 1 addition & 1 deletion src/test.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{C} = require 'cello'

src = C ->
src = C(indent: " ", debug: yes) ->
include 'stdio.h'
include 'stdlib.h'
int x = 40
Expand Down

0 comments on commit a0b080e

Please sign in to comment.