@@ -27,11 +27,26 @@ import { Definition, Noun, PartialVerb } from "./type.ts";
2727
2828const RESERVED_SYMBOLS = "#()*+/:;<=>@[\\]^`{|}~" ;
2929
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+ ) ;
3348const comment = checkedSequence (
34- matchString ( "#" , "hash sign" ) ,
49+ hashSign ,
3550 match ( / [ ^ \n ] * ?(? = \r ? \n | $ ) / , "comment content" ) ,
3651) ;
3752const spaces = checkedSequence (
@@ -40,26 +55,13 @@ const spaces = checkedSequence(
4055) ;
4156const ignore = allWithCheck (
4257 new CheckedParser (
43- choiceOnlyOne ( comment . check , spaces . check ) ,
58+ choiceOnlyOne ( hashSign , spaces . check ) ,
4459 choiceWithCheck ( spaces , comment ) ,
4560 ) ,
4661) ;
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+ }
6365const keyword = memoize ( < T extends string > ( keyword : T ) =>
6466 lex ( withPosition ( match ( / [ a - z \- ] + / , `"${ keyword } "` ) ) )
6567 . map ( ( positioned ) =>
@@ -79,7 +81,7 @@ const unescapedWord = sequence(
7981 choiceWithCheck ( checkedCharacter , escape ) ,
8082 allWithCheck (
8183 new CheckedParser (
82- choiceOnlyOne ( wordCharacter , backtick , comment . check ) ,
84+ choiceOnlyOne ( wordCharacter , backtick , hashSign ) ,
8385 choiceWithCheck ( checkedCharacter , escape , comment . map ( ( ) => "" ) ) ,
8486 ) ,
8587 ) ,
0 commit comments