Skip to content

Instantly share code, notes, and snippets.

@dmatveev
Created September 23, 2010 18:21
Show Gist options
  • Save dmatveev/594088 to your computer and use it in GitHub Desktop.
Save dmatveev/594088 to your computer and use it in GitHub Desktop.
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