Skip to content

Instantly share code, notes, and snippets.

@rofl0r
Created September 12, 2010 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rofl0r/575761 to your computer and use it in GitHub Desktop.
Save rofl0r/575761 to your computer and use it in GitHub Desktop.
import text/BufferFile
import structs/ArrayList
main: func(args: ArrayList<String>) {
for (x in 1..args size) {
b := Buffer new()
if (!(b fromFile(args get(x)))) Exception new("file not found") throw()
("filesize is " + b size toString()) println()
openB := 0
closeB := 0
openP := 0
closeP := 0
line := 0
linestart := 0
for (i in 0..b size) {
match(((b data + i) as Char*)@) {
case '{' =>
openB += 1
if (openP != closeP) raise ("opening curly brace while parenthesis count doesnt match @line #" + line toString())
case '}' =>
closeB += 1
case '(' =>
openP += 1
case ')' =>
closeP += 1
case '\n' =>
line += 1
printf("%d:", line)
c := b clone()
c substring( linestart, i )
c println()
printf("{:%d }:%d (:%d ):%d\n", openB, closeB, openP, closeP)
linestart = i
}
}
printf("{:%d }:%d (:%d ):%d\n", openB, closeB, openP, closeP)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment