@@ -27,11 +27,26 @@ import { Definition, Noun, PartialVerb } from "./type.ts";
27
27
28
28
const RESERVED_SYMBOLS = "#()*+/:;<=>@[\\]^`{|}~" ;
29
29
30
- function lex < T > ( parser : Parser < T > ) : Parser < T > {
31
- return parser . skip ( ignore ) ;
32
- }
30
+ const hashSign = matchString ( "#" , "hash sign" ) ;
31
+ const backtick = matchString ( "`" , "backtick" ) ;
32
+ const colon = matchString ( ":" , "colon" ) ;
33
+
34
+ const tokiPonaWord = lex ( match ( / [ a - z ] [ a - z A - Z ] * / , "word" ) ) ;
35
+ const openParenthesis = lex ( matchString ( "(" , "open parenthesis" ) ) ;
36
+ const closeParenthesis = lex ( matchString ( ")" , "close parenthesis" ) ) ;
37
+ const openBracket = lex ( matchString ( "[" , "open bracket" ) ) ;
38
+ const closeBracket = lex ( matchString ( "]" , "close bracket" ) ) ;
39
+ const comma = lex ( matchString ( "," , "comma" ) ) ;
40
+ const semicolon = lex ( matchString ( ";" , "semicolon" ) ) ;
41
+ const slash = lex ( matchString ( "/" , "slash" ) ) ;
42
+
43
+ const character = match ( / ./ u, "character" ) ;
44
+ const wordCharacter = match (
45
+ new RegExp ( `[^${ escapeRegex ( RESERVED_SYMBOLS ) } ]` ) ,
46
+ "word character" ,
47
+ ) ;
33
48
const comment = checkedSequence (
34
- matchString ( "#" , "hash sign" ) ,
49
+ hashSign ,
35
50
match ( / [ ^ \n ] * ?(? = \r ? \n | $ ) / , "comment content" ) ,
36
51
) ;
37
52
const spaces = checkedSequence (
@@ -40,26 +55,13 @@ const spaces = checkedSequence(
40
55
) ;
41
56
const ignore = allWithCheck (
42
57
new CheckedParser (
43
- choiceOnlyOne ( comment . check , spaces . check ) ,
58
+ choiceOnlyOne ( hashSign , spaces . check ) ,
44
59
choiceWithCheck ( spaces , comment ) ,
45
60
) ,
46
61
) ;
47
- const backtick = matchString ( "`" , "backtick" ) ;
48
- const colon = matchString ( ":" , "colon" ) ;
49
- const character = match ( / ./ u, "character" ) ;
50
- const wordCharacter = match (
51
- new RegExp ( `[^${ escapeRegex ( RESERVED_SYMBOLS ) } ]` ) ,
52
- "word character" ,
53
- ) ;
54
- const tokiPonaWord = lex ( match ( / [ a - z ] [ a - z A - Z ] * / , "word" ) ) ;
55
- const openParenthesis = lex ( matchString ( "(" , "open parenthesis" ) ) ;
56
- const closeParenthesis = lex ( matchString ( ")" , "close parenthesis" ) ) ;
57
- const openBracket = lex ( matchString ( "[" , "open bracket" ) ) ;
58
- const closeBracket = lex ( matchString ( "]" , "close bracket" ) ) ;
59
- const comma = lex ( matchString ( "," , "comma" ) ) ;
60
- const semicolon = lex ( matchString ( ";" , "semicolon" ) ) ;
61
- const slash = lex ( matchString ( "/" , "slash" ) ) ;
62
-
62
+ function lex < T > ( parser : Parser < T > ) : Parser < T > {
63
+ return parser . skip ( ignore ) ;
64
+ }
63
65
const keyword = memoize ( < T extends string > ( keyword : T ) =>
64
66
lex ( withPosition ( match ( / [ a - z \- ] + / , `"${ keyword } "` ) ) )
65
67
. map ( ( positioned ) =>
@@ -79,7 +81,7 @@ const unescapedWord = sequence(
79
81
choiceWithCheck ( checkedCharacter , escape ) ,
80
82
allWithCheck (
81
83
new CheckedParser (
82
- choiceOnlyOne ( wordCharacter , backtick , comment . check ) ,
84
+ choiceOnlyOne ( wordCharacter , backtick , hashSign ) ,
83
85
choiceWithCheck ( checkedCharacter , escape , comment . map ( ( ) => "" ) ) ,
84
86
) ,
85
87
) ,
0 commit comments