feat: first chunk of lexer/parser translation.

This commit is contained in:
mattia
2025-02-16 20:49:20 +01:00
parent d386c50499
commit 4f8e83da9d
15 changed files with 2593 additions and 49 deletions

View File

@@ -1,6 +1,11 @@
lexer grammar InkBlotAntlrLexer;
Whitespace: [ \t]+ ;
// classic "white space" and "new line" - ink's new line also allows for some whitespace at start
WS: [ \t]+ ;
NL: WS? '\r'? '\n' ;
// one or more (potential whitespace followed by) newline(s); used e.g. for block sequencing
MULTILINE_WS: NL+ ;
// see InkParser_Content.cs, ContentTextNoEscape and ContentTextAllowingEcapeChar for the escape case
// this works for the base case where we're not parsing a string, nor a choice
@@ -19,4 +24,24 @@ CONTENT_TEXT_NO_ESCAPE_SIMPLE:
| '-' { InputStream.LA(1) != '>' }?
// same for threads (<-) and glue (<>)
| '<' { InputStream.LA(1) != '-' && InputStream.LA(1) != '>' }?
)+ ;
)+ ;
INLINE_LOGIC_START: '{' ;
INLINE_LOGIC_END: '}' ;
// All symbols for sequencing: either using the short-hand symbols (https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#types-of-alternatives)
// or using the multiline blocks (https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#multiline-blocks)
SEQUENCE_TYPE_SYMBOL_ANNOTATION: [!&~$ ] ;
ONCE: 'once' WS? ':' ;
CYCLE: 'cycle' WS? ':' ;
SHUFFLE: 'shuffle' WS? ':' ;
STOPPING: 'stopping' WS? ':' ;
SHUFFLE_ONCE: 'shuffle' WS 'once' WS? ':' ;
SHUFFLE_STOPPING: 'shuffle' WS 'stopping' WS? ':' ;
THREAD_ARROW: '<-' ;
DIVERT_ARROW: '->' ;
TUNNEL_ARROW: '->->' ;
// TODO: add all extra character ranges from InkParser_CharacterRanges (LatinBasic, LatinExtendedA, ...)
IDENTIFIER: [A-Za-z0-9_]+;