CypressReader.st
author Jan Vrany <jan.vrany@labware.com>
Wed, 08 Jul 2020 11:26:45 +0100
changeset 29 443911ff729a
parent 21 c88f472e1c23
permissions -rw-r--r--
Move some extensions to stx:libcompat

"{ Package: 'stx:goodies/cypress' }"

CypressAbstractReader subclass:#CypressReader
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Cypress-New-Reader & Writer'
!

!CypressReader class methodsFor:'documentation'!

documentation
"
    A reader to read packages in Cypress format.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]
        'Cypress spec' - https://github.com/CampSmalltalk/Cypress/wiki


"
! !

!CypressReader methodsFor:'reading-private'!

readMethod: name from: directory
    | mthdfile mthd |

    mthdfile := directory / name.
    mthdfile exists ifFalse:[
        mthdfile := mthdfile withSuffix: self defaultFileSuffixForMethod.
    ].
    mthdfile exists ifFalse:[
        self error: 'No such method in ', directory pathName.
        ^nil.
    ].

    mthd := CypressMethod new.
    mthdfile readingFileDo:[:s|
        | line |
        "Method file starts with following four lines: 
                1. a single double-quote 
                2. 'notice: ' + the contents of the copyrightLine property (see above) 
                3. 'category: ' + method category/protocol 
                4. a single double-quote"

        (line := s nextLine) ~= '"' ifTrue:[ self error: 'Malformed method file'. ^nil].
        ((line := s nextLine) startsWith:'notice: ') ifTrue:[ self error: 'Malformed method file - expecing notice on second line'. ^nil].
        ((line := s nextLine) startsWith:'category: ') ifTrue:[ self error: 'Malformed method file - expecing category on third line'. ^nil].
        mthd category: (line copyFrom: 'category: ' size + 1).
        (line := s nextLine) ~= '"' ifTrue:[ self error: 'Malformed method file'. ^nil].
        mthd source: s upToEnd.
    ].
    ^mthd

    "Created: / 18-09-2012 / 10:03:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!CypressReader class methodsFor:'documentation'!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !