Skip to content

Commit

Permalink
First version with MicInlineSpaceBlock and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Oct 1, 2024
1 parent 634eab9 commit e4f4ddd
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 12 deletions.
12 changes: 11 additions & 1 deletion src/Microdown-Tests/MicInlineSpaceBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,15 @@ MicInlineSpaceBlockTest >> testParagraphWithInlineSpace [
| root |
root := self parser parse: 'a paragraph with an inline space here <br> it continues after here.'.
self assert: root children size equals: 1.
self assert: root children first children size equals: 3
self assert: root children first children size equals: 3.
self assert: root children first children second class equals: MicInlineSpaceBlock
]

{ #category : 'tests' }
MicInlineSpaceBlockTest >> testParagraphWithInlineSpaceAndOthers [

| root |
root := self parser parse: '_a paragraph_ with an *inline* space here <br> it continues after here.'.
self assert: root children size equals: 1.
self assert: root children first children size equals: 6
]
11 changes: 10 additions & 1 deletion src/Microdown-Tests/MicInlineTokenStreamTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ MicInlineTokenStreamTest >> testTokenize_InlineSpace [

| tokens |
tokens := (MicInlineTokenStream on: 'aa', InlineSpace ,'bbb') contents.
self assert: tokens second string equals: (InlineSpace ,'bbb').
self assert: tokens second string equals: InlineSpace.
self assert: tokens second delimiter equals: (MicInlineDelimiter at: InlineSpace)
]

{ #category : 'tests' }
MicInlineTokenStreamTest >> testTokenize_InlineSpaceWithSpaceAround [

| tokens |
tokens := (MicInlineTokenStream on: 'aa ', InlineSpace ,' bbb') contents.
self assert: tokens second string equals: InlineSpace.
self assert: tokens second delimiter equals: (MicInlineDelimiter at: InlineSpace)
]

Expand Down
5 changes: 5 additions & 0 deletions src/Microdown/MicInlineDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ MicInlineDelimiter >> markupAsRegex [
self subclassResponsibility
]

{ #category : 'printing' }
MicInlineDelimiter >> printOn: stream [
stream << $« << self markup <<
]

{ #category : 'adding' }
MicInlineDelimiter >> storeRegex [

Expand Down
3 changes: 2 additions & 1 deletion src/Microdown/MicInlineParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ MicInlineParser >> joinTextNodesOf: children [

{ #category : 'parsing' }
MicInlineParser >> parse: aString [
"I return an array of inline blocks"
"Returns an array of inline blocks"

| tokenStream |
tokenStream := MicInlineTokenStream on: aString.
^ (self parseChildrenIn: tokenStream) asArray
Expand Down
6 changes: 6 additions & 0 deletions src/Microdown/MicInlineSpaceBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Class {
#tag : 'InlineParser'
}

{ #category : 'parsing' }
MicInlineSpaceBlock class >> parse: delimiter stream: aTokenStream for: aParser [

^ self new
]

{ #category : 'visiting' }
MicInlineSpaceBlock >> accept: aVisitor [

Expand Down
55 changes: 55 additions & 0 deletions src/Microdown/MicInlineSpaceDelimiter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Class {
#name : 'MicInlineSpaceDelimiter',
#superclass : 'MicInlineDelimiter',
#pools : [
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
#tag : 'InlineParser'
}

{ #category : 'initialization' }
MicInlineSpaceDelimiter class >> initializeDelimiters [

"line break"
self new addMe



]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> blockClass [

^ MicInlineSpaceBlock
]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> isEvaluated [

^ false
]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> isOpener [

^ true
]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> isRawkind [

^ false
]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> markup [
^ InlineSpace
]

{ #category : 'accessing' }
MicInlineSpaceDelimiter >> markupAsRegex [

^ InlineSpace
]
8 changes: 0 additions & 8 deletions src/Microdown/MicInlineStandardDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ MicInlineStandardDelimiter class >> initializeDelimiters [
self new markup: NameCloserUrlOpener; blockClass: MicRawBlock ; closer: URLCloserMarkup; addMe.
self new markup: URLCloserMarkup; blockClass: nil ; closer: nil; addMe.

"line break"
self new markup: InlineSpace; blockClass: MicInlineSpaceBlock; closer: nil; addMe



]
Expand Down Expand Up @@ -105,8 +102,3 @@ MicInlineStandardDelimiter >> markupAsRegex [
ifFalse: [ markup do: [ :char| str nextPut: $\; nextPut: char ] ].
^ str contents
]

{ #category : 'printing' }
MicInlineStandardDelimiter >> printOn: stream [
stream << $« << markup <<
]
2 changes: 2 additions & 0 deletions src/Microdown/MicInlineTokenStream.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ MicInlineTokenStream >> addText: matchedString [

{ #category : 'initialization' }
MicInlineTokenStream >> initialize [

super initialize.
tokens := OrderedCollection new
]

Expand Down
4 changes: 3 additions & 1 deletion src/Microdown/MicSharedPool.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ MicSharedPool class >> initialize [
UnorderedListPlusMarkup := '+ '.
UnorderedListStarMarkup := '* '.

self initializeRawParagraph.

"Argument list"

ArgumentListDelimiter := '&'.
Expand Down Expand Up @@ -131,7 +133,7 @@ MicSharedPool class >> initialize [
NameCloserUrlOpener := ']('.
FixiousTextDelimiter := 0 asCharacter asString.

self initializeRawParagraph.



Delimiters := { AnchorReferenceCloserMarkup .
Expand Down
1 change: 1 addition & 0 deletions src/Microdown/MicrodownParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ MicrodownParser class >> builder [
{ #category : 'examples' }
MicrodownParser class >> example [
<sampleInstance>

^ self parse: self comment
]

Expand Down

0 comments on commit e4f4ddd

Please sign in to comment.