This DIY recipe will “parse” a form by normalizing tokens to lower case, but then simply reporting the same analysis for every token it sees. It illustrates how simple the basic framework for building a parser is: two steps are all it takes.
1. Define your parser type
Use CitableParserBuilder, and define your parser as a subtype of CitableParser.
In Julia, it could look like this if your parser object contained no information beyond a labelling string.
using CitableParserBuilder
struct FakeParser <: CitableParser
label::AbstractString
end
2. Implement parsetoken
The second step is to import CitableParserBuilder: parsetoken and then define a method of parsetoken for your parser’s type. You’re done! You can now use parsetoken and all the other functions of the ParserTrait.
In the following cell, we’ll wrap the whole package in a module named DIYParser, then use DIYParser along with CitableParserBuilder and Orthography to parse a token.
module DIYParserusingCitableParserBuilder, OrthographyimportCitableParserBuilder: parsetokenexport FakeParserstruct FakeParser <: CitableParser label::AbstractStringendfunctionparsetoken(s::AbstractString, parser::FakeParser, ortho::T) where {T <: OrthographicSystem}# Returns only the same analysis no matter# what the token is [Analysis( s,LexemeUrn("fakeparser.nolexemeanalysis"),FormUrn("fakeparser.noformanalysis"),StemUrn("fakeparser.nostemanalysis"),RuleUrn("fakeparser.noruleanalysis"),lowercase(s), "A" ) ]endend# end of module# Use the new module along with CitableParserBuilder:using.DIYParser, CitableParserBuilder, OrthographyfakeParser =FakeParser("Parser generating dummy values")tokenparses =parsetoken("Word", fakeParser, simpleAscii())