Created
September 23, 2010 18:21
-
-
Save dmatveev/594088 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
PackageLoader fileInPackage: #PetitParser. | |
Object subclass: InfoParser [ | |
InfoParser class >> fileParser [ | |
<category: 'parsers'> | |
^self sectionParser trim star | |
=> [:nodes | Dictionary from: nodes] | |
] | |
InfoParser class >> sectionParser [ | |
<category: 'parsers'> | |
| end any parser inside | | |
end := '}}' asParser. | |
parser := PP.PPUnresolvedParser new. | |
inside := end not, (parser / #any asParser). | |
parser def: ('{{' asParser, self commandParser, inside star flatten, end) | |
=> [:nodes | nodes second -> nodes third]. | |
^parser | |
] | |
InfoParser class >> commandParser [ | |
<category: 'parsers'> | |
^($: asParser, #letter asParser plus flatten, Character space asParser optional) | |
=> [:nodes | nodes second]. | |
] | |
InfoParser class >> process: aStream [ | |
<category: 'instance creation'> | |
^self fileParser parse: (aStream contents) | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment