Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checks
- | newEntries newFields newMacros toBeDeleted toBeInclude error |
- macros := OrderedCollection new.
- macrosUsage := Dictionary new.
- entries := OrderedCollection new.
- errorStream := WriteStream on: String new.
- [eof] whileFalse: [ self bibtexBlockToCZEntry: self getBibtexBlock ].
- newEntries := OrderedCollection new.
- macroKeys := macros collect: [ :each | each key key ].
- entries do: [ :assoc |
- toBeInclude := true.
- error := false.
- "checks if the type of the entry is a correct bibtex type"
- (self checkBibtexType: assoc key)
- ifFalse: [
- error := true.
- toBeInclude := false ].
- newFields := OrderedCollection new.
- fieldKeys := OrderedCollection new.
- assoc key fields do: [ :field |
- toBeDeleted := false.
- "checks the macros referenced in the entry and removes fields with undefined macros"
- (self checkMacroReferenced: field)
- ifFalse: [ toBeDeleted := true ].
- toBeDeleted ifFalse: [
- "removes empty fields"
- (self checkEmptyField: field)
- ifFalse: [ toBeDeleted := true ] ].
- "removes duplicate fields"
- (self chechDuplicateField: field)
- ifFalse: [ toBeDeleted := true ].
- toBeDeleted
- ifFalse: [ newFields add: field ]
- ifTrue: [ error := true ]
- ].
- assoc key fields: newFields.
- "checks if the entry contains all the fields needed by it's type"
- ((typeFieldsMatching at: (assoc key type)) value: (assoc key fields collect: [ :each | each key ]))
- ifFalse: [
- errorStream nextPutAll: 'Error: Entry does not contain all needed fields'; cr.
- error := true.
- toBeInclude := false ].
- "checks if the key is unique and changes it if it's not"
- keys at: assoc key key put: ((keys at: assoc key key ifAbsent: 0) + 1).
- ((keys at: assoc key key) > 1)
- ifTrue: [ | key |
- key := assoc key key.
- assoc key key: '###',(assoc key key, '_',(keys at: assoc key key) asString,'###' ).
- errorStream nextPutAll: 'Warning: duplicate key: ', key, ' changed to: ', assoc key key; cr.
- error := true ].
- "checks if the entry respects all the rules"
- rules do: [ :rule |
- (rule value value: assoc key)
- ifFalse: [
- errorStream nextPutAll: 'Error : entry does not respect the rule: ', rule key; cr.
- error := true.
- toBeInclude := false ] ].
- "displays the errors and creates the collection with safe entries"
- error ifTrue: [
- errorStream nextPut: Character tab; nextPutAll: 'for :'; cr; nextPutAll: assoc value; cr.
- toBeInclude
- ifTrue: [
- newEntries add: assoc key.
- errorStream nextPutAll: '(There are only warnings, the entry is not deleted)'; cr; cr ]
- ifFalse: [
- errorStream nextPutAll: '(There are errors, the entry is deleted)'; cr; cr ]
- ]
- ].
- "removes unused macros"
- newMacros := OrderedCollection new.
- macros do: [ :assoc |
- (macrosUsage at: assoc key key)
- ifFalse: [ errorStream nextPutAll: 'Unused macro:'; cr; nextPutAll: assoc value; cr; cr ]
- ifTrue: [ newMacros add: assoc ]
- ].
- macros := newMacros
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement