Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
peg/examples/FileExample.fan
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (31 sloc)
782 Bytes
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
using peg | |
using util | |
class FileExample : AbstractMain | |
{ | |
@Arg { help="grammar text file" } | |
File? g | |
@Arg { help="input file" } | |
File? in | |
@Opt { help="how many times to parse" } | |
Int n := 1 | |
@Opt { help="uses list handler (NullHandler is used otherwise)" } | |
Bool list := false | |
override Int run() { | |
grammar := Grammar.fromStr(g.readAllStr) | |
input := in.mmap | |
m := Match.unknown | |
echo("Preparation finished") | |
start := Duration.now | |
n.times { | |
input.seek(0) | |
h := list ? ListHandler() : NullHandler() | |
echo("Handler type: $h.typeof") | |
p := Parser(grammar, h).run(input) | |
m = p.match | |
} | |
d := Duration.now - start | |
echo("Match: $m") | |
echo("Duration: $d.toLocale (${d.toMillis}ms)") | |
return 0 | |
} | |
} |