-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure API, update documentation
Change structure of API to have more descriptive names. Move abstracts and typedefs to separate files so now they are children of main parsihax package. Update README documentation. Signed-off-by: Tomas Slusny <[email protected]>
- Loading branch information
Showing
13 changed files
with
290 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.n | ||
/.vscode/ | ||
/bin/ | ||
/dump/ | ||
/dump/ | ||
.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
-lib monax | ||
-dce std | ||
-cp src | ||
parsi.Hax | ||
parsihax.ParseFunction | ||
parsihax.ParseObject | ||
parsihax.ParseResult | ||
parsihax.Parser | ||
-xml bin/parsihax.xml | ||
--next | ||
-cmd haxelib run dox -o bin/api -i bin --title "Parsihax - API documentation" -D source-path https://github.com/deathbeam/parsihax/blob/master/src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package parsihax; | ||
|
||
/** | ||
Parsing function created by chaining Parser combinators. | ||
**/ | ||
typedef ParseFunction<A> = String -> ?Int -> ParseResult<A>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package parsihax; | ||
|
||
import haxe.ds.Vector; | ||
|
||
/** | ||
The ParseObject object is a wrapper for a parser function. | ||
Externally, you use one to parse a string by calling | ||
`var result = SomeParseObject.apply('Me Me Me! Parse Me!');` | ||
**/ | ||
abstract ParseObject<T>(Vector<ParseFunction<T>>) { | ||
inline function new() this = new Vector(1); | ||
@:to inline function get_apply() : ParseFunction<T> return this[0]; | ||
inline function set_apply(param : ParseFunction<T>) return this[0] = param; | ||
|
||
/** | ||
Getting `ParseObject.apply` from a parser (or explicitly casting it to | ||
`ParseFunction` returns parsing function `String -> ?Int -> ParseResult<A>` | ||
(or just `ParseFunction`), that parses the string and returns `ParseResult<A>`. | ||
Changing `ParseObject.apply` value changes parser behaviour, but still keeps it's | ||
reference, what is really usefull in recursive parsers. | ||
**/ | ||
public var apply(get, set): ParseFunction<T>; | ||
|
||
/** | ||
Creates `ParseObject` from `ParseFunction` | ||
**/ | ||
@:noUsing @:from static inline public function to<T>(v : ParseFunction<T>) : ParseObject<T> { | ||
var ret = new ParseObject(); | ||
ret.apply = v; | ||
return ret; | ||
} | ||
|
||
/** | ||
Same as `Hax.then(l, r)` | ||
**/ | ||
@:noUsing @:op(A + B) static inline public function opAdd<A, B>(l: ParseObject<A>, r: ParseObject<B>): ParseObject<B> { | ||
return Parser.then(l, r); | ||
} | ||
|
||
/** | ||
Same as `Hax.or(l, r)` | ||
**/ | ||
@:noUsing @:op(A | B) static inline public function opOr<A>(l: ParseObject<A>, r: ParseObject<A>): ParseObject<A> { | ||
return Parser.or(l, r); | ||
} | ||
|
||
/** | ||
Same as `Hax.as(l, r)` | ||
**/ | ||
@:noUsing @:op(A / B) static inline public function opDiv<A>(l: ParseObject<A>, r: String): ParseObject<A> { | ||
return Parser.as(l, r); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package parsihax; | ||
|
||
/** | ||
A structure with a boolean `status` flag, indicating whether the parse | ||
succeeded. If it succeeded, the `value` attribute will contain the yielded | ||
value. Otherwise, the `index` and `expected` attributes will contain the | ||
offset of the parse error, and a sorted, unique array of messages indicating | ||
what was expected. | ||
The error structure can be passed along with the original source to | ||
`Parser.formatError` to obtain a human-readable error string. | ||
**/ | ||
typedef ParseResult<T> = { | ||
/** | ||
Flag, indicating whether the parse succeeded | ||
**/ | ||
var status : Bool; | ||
|
||
/** | ||
Offset of the parse error (in case of failed parse) | ||
**/ | ||
var index : Int; | ||
|
||
/** | ||
Yielded value of `Parser` (in case of successfull parse) | ||
**/ | ||
var value : T; | ||
|
||
/** | ||
Offset of last parse | ||
**/ | ||
var furthest : Int; | ||
|
||
/** | ||
A sorted, unique array of messages indicating what was expected (in case of failed parse) | ||
**/ | ||
var expected : Array<String>; | ||
} |
Oops, something went wrong.