Skip to content

Commit

Permalink
use fork for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Apr 18, 2017
1 parent 7e13ff9 commit 3991799
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"deps": [
{
"type": "github",
"repo": "sylvanc/peg"
"repo": "theodus/peg"
}
]
}
6 changes: 3 additions & 3 deletions changelog.pony
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ".deps/sylvanc/peg"
use ".deps/theodus/peg"

class Changelog
let unreleased: Release
Expand Down Expand Up @@ -48,7 +48,7 @@ class Release

new create(ast: AST) ? =>
let t = ast.children(0) as Token
heading = t.source.trim(t.offset, t.offset + t.length)
heading = t.source.content.trim(t.offset, t.offset + t.length)
fixed = try Section(ast.children(1) as AST) else None end
added = try Section(ast.children(2) as AST) else None end
changed = try Section(ast.children(3) as AST) else None end
Expand Down Expand Up @@ -78,7 +78,7 @@ class Section
entries =
try
let t = ast.children(1) as Token
t.source.trim(t.offset, t.offset + t.length)
t.source.content.trim(t.offset, t.offset + t.length)
else
""
end
Expand Down
2 changes: 1 addition & 1 deletion changelog_parser.pony
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ".deps/sylvanc/peg"
use ".deps/theodus/peg"

primitive ChangelogParser
fun apply(): Parser val =>
Expand Down
22 changes: 12 additions & 10 deletions main.pony
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use "files"
use "options"
use "time"
use ".deps/sylvanc/peg"
use ".deps/theodus/peg"

/*
1. have a part that can validate a changelog file
Expand Down Expand Up @@ -103,25 +103,27 @@ actor Main

fun check_version(version: String) ? =>
// chack if version is valid
match ChangelogParser.version().parse(version)
let source = Source.from_string(version)
match recover val ChangelogParser.version().parse(source) end
| (_, let t: Token) => None
else
_env.err.print("invalid version number: '" + version + "'")
error
end

fun parse(): AST ? =>
with
file = OpenFile(FilePath(_env.root as AmbientAuth, _filename)) as File
do
let source: String = file.read_string(file.size())
match ChangelogParser().eof().parse(source, 0, true, NoParser)
try
let source = Source(FilePath(_env.root as AmbientAuth, _filename))
match
recover val
ChangelogParser().parse(source)
end
| (_, let ast: AST) =>
//_env.out.print(recover val Printer(ast) end)
ast
| (let offset: USize, let r: Parser) =>
_env.err.writev(
Error(_filename, source, offset, "SYNTAX", r.error_msg()))
| (let offset: USize, let r: Parser val) =>
let e = recover val SyntaxError(source, offset, r) end
_env.err.writev(PegFormatError.console(e))
error
else
_env.err.print("unable to parse file: " + _filename)
Expand Down
26 changes: 16 additions & 10 deletions tests/main.pony
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use "files"
use "ponytest"
use ".."
use "../.deps/sylvanc/peg"
use "../.deps/theodus/peg"

actor Main is TestList
new create(env: Env) => PonyTest(env, this)
Expand All @@ -22,12 +22,14 @@ class ParseTest
fun run(tests: Array[(String, String)]) =>
for (source, expected) in tests.values() do
_h.log("test: " + source)
match _parser.parse(source)
let source' = Source.from_string(source)
match recover val _parser.parse(source') end
| (_, let r: (AST | Token | NotPresent)) =>
let result = recover val Printer(r) end
_h.assert_eq[String](expected, result)
| (let offset: USize, let r: Parser) =>
_Logv(_h, Error("", source, offset, "SYNTAX", r.error_msg()))
| (let offset: USize, let r: Parser val) =>
let e = recover val SyntaxError(source', offset, r) end
_Logv(_h, PegFormatError.console(e))
_h.assert_eq[String](expected, "")
| (_, Skipped) => _h.log("skipped")
| (_, Lex) => _h.log("lex")
Expand Down Expand Up @@ -85,14 +87,15 @@ class iso _TestParseChangelog is UnitTest
fun name(): String => "parse CHANGELOG"

fun apply(h: TestHelper) ? =>
let p = ChangelogParser().eof()
let p = recover val ChangelogParser() end
let testfile = "CHANGELOG.md"

with file = OpenFile(
FilePath(h.env.root as AmbientAuth, testfile)) as File
do
let source: String = file.read_string(file.size())
match p.parse(source, 0, true, NoParser) // TODO fix defaults
let source' = Source.from_string(source)
match recover val p.parse(source') end
| (let n: USize, let r: (AST | Token | NotPresent)) =>
match r
| let ast: AST =>
Expand All @@ -102,8 +105,9 @@ class iso _TestParseChangelog is UnitTest
h.log(recover val Printer(r) end)
h.fail()
end
| (let offset: USize, let r: Parser) =>
_Logv(h, Error("", source, offset, "SYNTAX", r.error_msg()))
| (let offset: USize, let r: Parser val) =>
let e = recover val SyntaxError(source', offset, r) end
_Logv(h, PegFormatError.console(e))
h.fail()
end
else
Expand All @@ -112,11 +116,13 @@ class iso _TestParseChangelog is UnitTest

primitive _Logv
fun apply(h: TestHelper, bsi: ByteSeqIter) =>
for bs in bsi.values() do
h.log(
let str = recover String end
for bs in bsi.values() do
str.append(
match bs
| let s: String => s
| let a: Array[U8] val => String.from_array(a)
else ""
end)
end
h.log(consume str)

0 comments on commit 3991799

Please sign in to comment.