Starting WikiText parser implementation via PetitParser2

This commit is contained in:
Offray Vladimir Luna Cárdenas 2021-08-15 20:58:22 -05:00
parent aa216f8816
commit a7001f732a
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,42 @@
Class {
#name : #WikiTextGrammar,
#superclass : #PP2CompositeNode,
#instVars : [
'document',
'link',
'linkOpen',
'linkContent',
'linkClose'
],
#category : #'TiddlyWiki-Model'
}
{ #category : #accessing }
WikiTextGrammar >> document [
^ link islandInSea star
]
{ #category : #accessing }
WikiTextGrammar >> link [
^ linkOpen, linkContent, linkClose ==> #second
]
{ #category : #accessing }
WikiTextGrammar >> linkClose [
^ ']]' asPParser
]
{ #category : #accessing }
WikiTextGrammar >> linkContent [
^ #any asPParser starLazy flatten
]
{ #category : #accessing }
WikiTextGrammar >> linkOpen [
^ '[[' asPParser
]
{ #category : #accessing }
WikiTextGrammar >> start [
^ document
]

View File

@ -0,0 +1,17 @@
Class {
#name : #WikiTextGrammarTest,
#superclass : #PP2CompositeNodeTest,
#category : #'TiddlyWiki-Model'
}
{ #category : #accessing }
WikiTextGrammarTest >> parserClass [
^ WikiTextGrammar
]
{ #category : #accessing }
WikiTextGrammarTest >> testLink [
self
parse: '[[Just testing]]'
rule: #link
]