From 39917997a171ce12ace0ea14395dd5f25e393038 Mon Sep 17 00:00:00 2001 From: Theo Butler Date: Tue, 18 Apr 2017 15:59:09 -0400 Subject: [PATCH] use fork for dependencies --- bundle.json | 2 +- changelog.pony | 6 +++--- changelog_parser.pony | 2 +- main.pony | 22 ++++++++++++---------- tests/main.pony | 26 ++++++++++++++++---------- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/bundle.json b/bundle.json index ec0e41f..8d885bd 100644 --- a/bundle.json +++ b/bundle.json @@ -2,7 +2,7 @@ "deps": [ { "type": "github", - "repo": "sylvanc/peg" + "repo": "theodus/peg" } ] } \ No newline at end of file diff --git a/changelog.pony b/changelog.pony index 9bda8a8..20c06f6 100644 --- a/changelog.pony +++ b/changelog.pony @@ -1,4 +1,4 @@ -use ".deps/sylvanc/peg" +use ".deps/theodus/peg" class Changelog let unreleased: Release @@ -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 @@ -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 diff --git a/changelog_parser.pony b/changelog_parser.pony index 8c89c74..c79ce36 100644 --- a/changelog_parser.pony +++ b/changelog_parser.pony @@ -1,4 +1,4 @@ -use ".deps/sylvanc/peg" +use ".deps/theodus/peg" primitive ChangelogParser fun apply(): Parser val => diff --git a/main.pony b/main.pony index 4db2734..cfc8a3d 100644 --- a/main.pony +++ b/main.pony @@ -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 @@ -103,7 +103,8 @@ 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 + "'") @@ -111,17 +112,18 @@ actor Main 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) diff --git a/tests/main.pony b/tests/main.pony index b50e224..ef8d95b 100644 --- a/tests/main.pony +++ b/tests/main.pony @@ -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) @@ -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") @@ -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 => @@ -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 @@ -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)