Skip to content

Commit

Permalink
Commit work in progress on links
Browse files Browse the repository at this point in the history
  • Loading branch information
ReMinoer committed Dec 20, 2019
1 parent e14cb48 commit 863fa12
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 118 deletions.
47 changes: 18 additions & 29 deletions DashLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,22 @@ ITALIC_OPEN: '/[' WS?;
QUOTE_OPEN: '"[' WS?;
OBSOLETE_OPEN: '#[' WS?;

DIRECT_EXTERNAL_LINK_CLOSE: WS? ']>>';
EXTERNAL_LINK_NUMBER_CLOSE: WS? ']>' NUMBER;
EXTERNAL_LINK_CLOSE: WS? ']>';
DIRECT_LINK_CLOSE: WS? ']>>';
LINK_CLOSE_NUMBER: WS? ']>' NUMBER;
LINK_CLOSE: WS? ']>';
LINK_MIDDLE: WS? '](' WS? -> pushMode(LinkAddress);

DIRECT_INTERNAL_LINK_CLOSE: WS? ']<<';
INTERNAL_LINK_NUMBER_CLOSE: WS? ']<' NUMBER;
INTERNAL_LINK_CLOSE: WS? ']<';
INTERNAL_ADDRESS_OPEN: '@(' WS? -> pushMode(InternalAddress);

LINK_MIDDLE: WS? '](' WS? -> pushMode(LinkAdress);
ADDRESS_OPEN: '@(' WS? -> pushMode(TargetAdress);
REFERENCE_CLOSE: WS? ']*';
REFERENCE_CLOSE_NUMBER: WS? ']' NUMBER;

NOTE_LINK_CLOSE: WS? ']' '*'+;
NUMBER_NOTE_LINK_CLOSE: WS? ']' NUMBER;
ADDRESS_ENTRY_NUMBER: WS? '>' NUMBER ':' WS?;
ADDRESS_ENTRY: WS? '>:' WS?;
NOTE_ENTRY_NUMBER: WS? NUMBER ':' WS?;
NOTE_ENTRY: WS? '*'+ ':' WS?;

EXTERNAL_LINK_NUMBER_TARGET: '>' NUMBER ':' WS?;
EXTERNAL_LINK_TARGET: '>:' WS?;
INTERNAL_LINK_NUMBER_TARGET: '<' NUMBER ':' WS?;
INTERNAL_LINK_TARGET: '<:' WS?;
NOTE_NUMBER_TARGET: NUMBER ':' WS?;
NOTE_TARGET: '*'+ ':' WS?;

WORD: ~('-'|'\n'|'\r'|' '|'\t'|'<'|'{'|'['|']'|'~')+;
WORD: ~('-'|'\n'|'\r'|' '|'\t'|'<'|'{'|'['|']'|'#'|'@')+;

fragment NUMBER: [0-9]+;
fragment VOID: (' '|'\t'|'\n'|'\r')+;
Expand Down Expand Up @@ -121,15 +115,10 @@ HEADER_MODE_TITLE: '-'+;
HEADER_MODE_CONTENT: (WS? ('<' HEADER_MODE_CONTENT WS? '>' | ~('>'|' '|'\t'|'\n'|'\r')+))+;
HEADER_MODE_CLOSE: WS? '>' WS? '>' WS? -> popMode;

mode InternalLinkTarget;
INTERNAL_LINK_TARGET_CONTENT: (WS? ('(' INTERNAL_LINK_TARGET_CONTENT WS? ')' | ~(')'|' '|'\t'|'\n'|'\r')+))+;
INTERNAL_LINK_TARGET_CLOSE: WS? ')>' WS? -> popMode;

mode LinkAdress;
LINK_ADRESS_CONTENT: (WS? ('(' LINK_ADRESS_CONTENT WS? ')' | ~(')'|' '|'\t'|'\n'|'\r')+))+;
EXTERNAL_LINK_ADRESS_CLOSE: WS? ')>' WS? -> popMode;
INTERNAL_LINK_ADRESS_CLOSE: WS? ')<' WS? -> popMode;
mode LinkAddress;
LINK_ADDRESS_CONTENT: (WS? ('(' LINK_ADDRESS_CONTENT WS? ')' | ~(')'|' '|'\t'|'\n'|'\r')+))+;
LINK_ADDRESS_CLOSE: WS? ')>' WS? -> popMode;

mode TargetAdress;
TARGET_ADRESS_CONTENT: (WS? ('(' TARGET_ADRESS_CONTENT WS? ')' | ~(')'|' '|'\t'|'\n'|'\r')+))+;
TARGET_ADRESS_CLOSE: WS? ')' WS? -> popMode;
mode InternalAddress;
INTERNAL_ADDRESS_CONTENT: (WS? ('(' INTERNAL_ADDRESS_CONTENT WS? ')' | ~(')'|' '|'\t'|'\n'|'\r')+))+;
INTERNAL_ADDRESS_CLOSE: WS? ')' -> popMode;
77 changes: 26 additions & 51 deletions DashParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ parse:
| dashExtensionMode
| modeClose
| paragraphInline
| ( externalLinkTarget
| noteTarget
| ( adressEntry
| noteEntry
| media
| paragraph
)
Expand All @@ -74,8 +74,8 @@ parse:
| dashExtensionMode
| modeClose
| paragraphInline
| ( externalLinkTarget
| noteTarget
| ( adressEntry
| noteEntry
| media
| NEWLINE paragraph
)
Expand All @@ -94,11 +94,9 @@ line:
( WS?
( commentBlock
| commentInline
| directExternalLink
| externalLink
| directInternalLink
| internalLink
| noteLink
| directLink
| link
| reference
| media
| bold
| italic
Expand All @@ -116,11 +114,9 @@ emphasisLine:
( WS?
( commentBlock
| commentInline
| directExternalLink
| externalLink
| directInternalLink
| internalLink
| noteLink
| directLink
| link
| reference
| media
| bold
| italic
Expand All @@ -138,11 +134,9 @@ linkLine:
( WS?
( commentBlock
| commentInline
| directExternalLink
| externalLink
| directInternalLink
| internalLink
| noteLink
| directLink
| link
| reference
| media
| bold
| italic
Expand All @@ -165,15 +159,12 @@ linkOthers:
| WORD
| NEWLINE
| MODE_CLOSE
| DIRECT_EXTERNAL_LINK_CLOSE
| EXTERNAL_LINK_NUMBER_CLOSE
| EXTERNAL_LINK_CLOSE
| DIRECT_INTERNAL_LINK_CLOSE
| INTERNAL_LINK_NUMBER_CLOSE
| INTERNAL_LINK_CLOSE
| DIRECT_LINK_CLOSE
| LINK_CLOSE_NUMBER
| LINK_CLOSE
| LINK_MIDDLE
| NOTE_LINK_CLOSE
| NUMBER_NOTE_LINK_CLOSE
| REFERENCE_CLOSE_NUMBER
| REFERENCE_CLOSE
);

header: HEADER_OPEN headerContent? HEADER_CLOSE;
Expand All @@ -197,33 +188,17 @@ quote: QUOTE_OPEN emphasisLine SELECTION_CLOSE;
obsolete: OBSOLETE_OPEN emphasisLine SELECTION_CLOSE;
emphasis: HEADER_OPEN headerContent HEADER_CLOSE SELECTION_OPEN emphasisLine SELECTION_CLOSE;

directExternalLink: SELECTION_OPEN linkLine DIRECT_EXTERNAL_LINK_CLOSE;
externalLink:
SELECTION_OPEN
linkLine
( (LINK_MIDDLE linkAdress EXTERNAL_LINK_ADRESS_CLOSE)
| EXTERNAL_LINK_CLOSE
| EXTERNAL_LINK_NUMBER_CLOSE
);

directInternalLink: SELECTION_OPEN linkLine DIRECT_INTERNAL_LINK_CLOSE;
internalLink:
SELECTION_OPEN
linkLine
( (LINK_MIDDLE linkAdress INTERNAL_LINK_ADRESS_CLOSE)
| INTERNAL_LINK_CLOSE
| INTERNAL_LINK_NUMBER_CLOSE
);

linkAdress: LINK_ADRESS_CONTENT;
link: SELECTION_OPEN linkLine ((LINK_MIDDLE linkAddress LINK_ADDRESS_CLOSE) | LINK_CLOSE | LINK_CLOSE_NUMBER);
directLink: SELECTION_OPEN linkLine DIRECT_LINK_CLOSE;
linkAddress: LINK_ADDRESS_CONTENT;

noteLink: SELECTION_OPEN linkLine (NOTE_LINK_CLOSE | NUMBER_NOTE_LINK_CLOSE);
address: INTERNAL_ADDRESS_OPEN addressContent INTERNAL_ADDRESS_CLOSE;
addressContent: INTERNAL_ADDRESS_CONTENT;

address: ADDRESS_OPEN addressContent TARGET_ADRESS_CLOSE;
addressContent: TARGET_ADRESS_CONTENT;
reference: SELECTION_OPEN linkLine (REFERENCE_CLOSE | REFERENCE_CLOSE_NUMBER);

externalLinkTarget: EXTERNAL_LINK_TARGET line;
noteTarget: (NOTE_TARGET | NOTE_NUMBER_TARGET) line;
adressEntry: (ADDRESS_ENTRY | ADDRESS_ENTRY_NUMBER) line;
noteEntry: (NOTE_ENTRY | NOTE_ENTRY_NUMBER) line;

commentInline: COMMENT_INLINE_OPEN commentInlineContent COMMENT_INLINE_CLOSE;
commentInlineContent: COMMENT_INLINE_CONTENT;
Expand Down
68 changes: 35 additions & 33 deletions doc.dh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<> Dash Language Documentation
<> Document Advanced Syntax Hypertextual

@(adress)

< Note >
That documentation was generated from a [document]> write in Dash by a convertion tool named [Dast]>.

Expand Down Expand Up @@ -129,9 +131,9 @@
-> Also very important stuff
2-> Second list
- Point D
$- First item
$- Second item
$- Third item
0- First item
0- Second item
0- Third item
- Point E
-> Conclusion

Expand Down Expand Up @@ -222,27 +224,27 @@
<...>


<-> External links
<-> Links

You can put external links in your text by using {[content]>}.
You can put links in your text by using {[content]>}.
That link will use the adress provided by the next line beginning by {>: adress}.

<< .dash-+ >>

[Link text]>
...

>: http://www.google.com/

<...>

You can complete that syntax with a numeric index if you want to use an adress line defined anywhere in the document, or used multiple times, or just be more explicit.
You can complete that syntax with a numeric index if you want to use an adress line not defined immediatly after, or used multiple times, or just be more explicit.

<< .dash-+ >>

>1: http://www.google.com/
...

[Link text]>1 and [same link text]>1

>1: http://www.google.com/

<...>

You can also indicate the adress directly on the link with {[content](adress)>}.
Expand All @@ -253,47 +255,39 @@

<...>


<-> Internal links

Internal links works the same than external links but with some differencies:

- {>} is replaced by {<}.
- Instead of an adress, you must provide an identifier.

That identifier must be used as an internal adress somewhere in the document with {@(identifier)}.
Those links can be external or internal. External links use a web adress or a file path as adress (like above). Internal links use any text as identifier. That identifier can be used as an internal adress somewhere in the document with {@(identifier)}.

<< .dash-+ >>

[Link text]<
...
<: target
...
@(target) A paragraph
[Link text]>

>: target

@(target) Targeted paragraph

<...>
<< .dash-+ >>

[Link text]>1 and [same link text]>1

<1: target
...
[Link text]<1 and [same link text]<1
...
@(target) A paragraph
>1: target

@(target) Targeted paragraph

<...>
<< .dash-+ >>

@(target) Targeted paragraph

[Link text](target)<
...
@(target) A paragraph
[Link text](target)>

<...>

<-> Notes

You can reference a note with {[content]*}.
The referenced [note]* will be the next line beginning by {*: note}.
If you use a number instead of {*}, it will reference the next note in text with [that number]1 or, if it didn't exist, the previous one.
If you use a number instead of {*}, it will reference the next note in text with [that number]1.

*: Here is a first note.
1: Here is a second note.
Expand All @@ -308,6 +302,14 @@

<...>

Like links, you can also inline the note with the following syntax: {[content](note)*}.

<< .dash-+ >>

[WWW](World Wide Web)* is born at [CERN](Conseil Européen pour la Recherche Nucléaire)*.

<...>


<-> Media

Expand Down
10 changes: 5 additions & 5 deletions test-syntax.dh.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
*- Item 3

I'm a [text]* with [notes]** and *[bold] words.
You can also use [ids]3 or redirect to [links]2.
You can [also](Important word)* use [ids]3 or redirect to [links]2.

2 : [www.google.fr]>
3 : Note about ids
Expand All @@ -100,10 +100,10 @@ Click [here]> to see the rest of the [article](www.journalist.com/article/super_
>1: www.journalist.com/article/news
>: www.journalist.com/article/super_news#anchor

See in the [next section](s2)< or the [last one]<.
Or come back to the [first section]<1.
<1: first
<: last
See in the [next section](s2)> or the [last one]>.
Or come back to the [first section]>1.
>1: first
>: last
...
Like I said, @(s2)I'm the next section !
@(last)Or in the last one !
Expand Down

0 comments on commit 863fa12

Please sign in to comment.