diff --git a/config.yml b/config.yml index b17f864a7..ba28eb2a2 100644 --- a/config.yml +++ b/config.yml @@ -315,3 +315,20 @@ nodes: fields: - name: name - name: location + - name: RBS::AST::Ruby::Annotations::NodeTypeAssertion + fields: + - name: location + - name: prefix_location + - name: type + - name: RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation + fields: + - name: location + - name: prefix_location + - name: annotations + - name: method_type + - name: RBS::AST::Ruby::Annotations::MethodTypesAnnotation + fields: + - name: location + - name: prefix_location + - name: overloads + - name: vertical_bar_locations diff --git a/ext/rbs_extension/lexer.c b/ext/rbs_extension/lexer.c index 73984cf84..880786046 100644 --- a/ext/rbs_extension/lexer.c +++ b/ext/rbs_extension/lexer.c @@ -115,13 +115,13 @@ token rbsparser_next_token(lexstate *state) { } yy1: rbs_skip(state); -#line 144 "ext/rbs_extension/lexer.re" +#line 145 "ext/rbs_extension/lexer.re" { return next_eof_token(state); } #line 121 "ext/rbs_extension/lexer.c" yy2: rbs_skip(state); yy3: -#line 145 "ext/rbs_extension/lexer.re" +#line 146 "ext/rbs_extension/lexer.re" { return next_token(state, ErrorToken); } #line 127 "ext/rbs_extension/lexer.c" yy4: @@ -130,7 +130,7 @@ token rbsparser_next_token(lexstate *state) { if (yych == '\t') goto yy4; if (yych == ' ') goto yy4; yy5: -#line 143 "ext/rbs_extension/lexer.re" +#line 144 "ext/rbs_extension/lexer.re" { return next_token(state, tTRIVIA); } #line 136 "ext/rbs_extension/lexer.c" yy6: @@ -420,25 +420,34 @@ token rbsparser_next_token(lexstate *state) { rbs_skip(state); backup = *state; yych = peek(state); - if (yych <= '^') { - if (yych <= '?') goto yy3; - if (yych <= '@') goto yy102; - if (yych <= 'Z') goto yy103; - goto yy3; + if (yych <= '_') { + if (yych <= '@') { + if (yych <= '?') goto yy3; + goto yy102; + } else { + if (yych <= 'Z') goto yy103; + if (yych <= '^') goto yy3; + goto yy103; + } } else { - if (yych == '`') goto yy3; - if (yych <= 'z') goto yy103; - goto yy3; + if (yych <= 'q') { + if (yych <= '`') goto yy3; + goto yy103; + } else { + if (yych <= 'r') goto yy106; + if (yych <= 'z') goto yy103; + goto yy3; + } } yy36: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy36; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { @@ -450,50 +459,50 @@ token rbsparser_next_token(lexstate *state) { } } yy37: -#line 129 "ext/rbs_extension/lexer.re" +#line 130 "ext/rbs_extension/lexer.re" { return next_token(state, tUIDENT); } -#line 456 "ext/rbs_extension/lexer.c" +#line 465 "ext/rbs_extension/lexer.c" yy38: rbs_skip(state); yych = peek(state); - if (yych == ']') goto yy107; + if (yych == ']') goto yy109; #line 26 "ext/rbs_extension/lexer.re" { return next_token(state, pLBRACKET); } -#line 463 "ext/rbs_extension/lexer.c" +#line 472 "ext/rbs_extension/lexer.c" yy39: rbs_skip(state); #line 27 "ext/rbs_extension/lexer.re" { return next_token(state, pRBRACKET); } -#line 468 "ext/rbs_extension/lexer.c" +#line 477 "ext/rbs_extension/lexer.c" yy40: rbs_skip(state); #line 32 "ext/rbs_extension/lexer.re" { return next_token(state, pHAT); } -#line 473 "ext/rbs_extension/lexer.c" +#line 482 "ext/rbs_extension/lexer.c" yy41: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy110; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { if (yych <= '@') goto yy42; - if (yych <= 'Z') goto yy111; + if (yych <= 'Z') goto yy113; } else { - if (yych <= '_') goto yy113; + if (yych <= '_') goto yy115; if (yych <= '`') goto yy42; - if (yych <= 'z') goto yy108; + if (yych <= 'z') goto yy110; } } yy42: -#line 132 "ext/rbs_extension/lexer.re" +#line 133 "ext/rbs_extension/lexer.re" { return next_token(state, tULLIDENT); } -#line 497 "ext/rbs_extension/lexer.c" +#line 506 "ext/rbs_extension/lexer.c" yy43: yyaccept = 4; rbs_skip(state); @@ -501,54 +510,54 @@ token rbsparser_next_token(lexstate *state) { yych = peek(state); if (yych <= ' ') { if (yych <= 0x00000000) goto yy44; - if (yych <= 0x0000001F) goto yy114; + if (yych <= 0x0000001F) goto yy116; } else { - if (yych != ':') goto yy114; + if (yych != ':') goto yy116; } yy44: #line 39 "ext/rbs_extension/lexer.re" { return next_token(state, tOPERATOR); } -#line 512 "ext/rbs_extension/lexer.c" +#line 521 "ext/rbs_extension/lexer.c" yy45: rbs_skip(state); yych = peek(state); if (yych <= 'r') { - if (yych == 'l') goto yy115; + if (yych == 'l') goto yy117; goto yy53; } else { - if (yych <= 's') goto yy116; - if (yych <= 't') goto yy118; + if (yych <= 's') goto yy118; + if (yych <= 't') goto yy120; goto yy53; } yy46: -#line 128 "ext/rbs_extension/lexer.re" +#line 129 "ext/rbs_extension/lexer.re" { return next_token(state, tLIDENT); } -#line 527 "ext/rbs_extension/lexer.c" +#line 536 "ext/rbs_extension/lexer.c" yy47: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy119; + if (yych == 'o') goto yy121; goto yy53; yy48: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy120; + if (yych == 'l') goto yy122; goto yy53; yy49: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy121; + if (yych == 'e') goto yy123; goto yy53; yy50: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy122; - if (yych == 'x') goto yy123; + if (yych == 'n') goto yy124; + if (yych == 'x') goto yy125; goto yy53; yy51: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy124; + if (yych == 'a') goto yy126; goto yy53; yy52: rbs_skip(state); @@ -556,12 +565,12 @@ token rbsparser_next_token(lexstate *state) { yy53: if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; goto yy46; } else { if (yych <= '9') goto yy52; if (yych <= '<') goto yy46; - goto yy106; + goto yy108; } } else { if (yych <= '^') { @@ -577,72 +586,72 @@ token rbsparser_next_token(lexstate *state) { yy54: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy125; + if (yych == 'n') goto yy127; goto yy53; yy55: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy127; + if (yych == 'o') goto yy129; goto yy53; yy56: rbs_skip(state); yych = peek(state); - if (yych == 'i') goto yy128; + if (yych == 'i') goto yy130; goto yy53; yy57: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy129; + if (yych == 'u') goto yy131; goto yy53; yy58: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy130; - if (yych == 'u') goto yy131; + if (yych == 'r') goto yy132; + if (yych == 'u') goto yy133; goto yy53; yy59: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy132; - if (yych == 'i') goto yy133; + if (yych == 'e') goto yy134; + if (yych == 'i') goto yy135; goto yy53; yy60: rbs_skip(state); yych = peek(state); if (yych <= 'q') { - if (yych == 'o') goto yy134; + if (yych == 'o') goto yy136; goto yy53; } else { - if (yych <= 'r') goto yy135; - if (yych == 'y') goto yy136; + if (yych <= 'r') goto yy137; + if (yych == 'y') goto yy138; goto yy53; } yy61: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy137; - if (yych == 's') goto yy138; + if (yych == 'n') goto yy139; + if (yych == 's') goto yy140; goto yy53; yy62: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy139; + if (yych == 'o') goto yy141; goto yy53; yy63: rbs_skip(state); #line 28 "ext/rbs_extension/lexer.re" { return next_token(state, pLBRACE); } -#line 636 "ext/rbs_extension/lexer.c" +#line 645 "ext/rbs_extension/lexer.c" yy64: rbs_skip(state); #line 31 "ext/rbs_extension/lexer.re" { return next_token(state, pBAR); } -#line 641 "ext/rbs_extension/lexer.c" +#line 650 "ext/rbs_extension/lexer.c" yy65: rbs_skip(state); #line 29 "ext/rbs_extension/lexer.re" { return next_token(state, pRBRACE); } -#line 646 "ext/rbs_extension/lexer.c" +#line 655 "ext/rbs_extension/lexer.c" yy66: rbs_skip(state); yych = peek(state); @@ -679,19 +688,19 @@ token rbsparser_next_token(lexstate *state) { goto yy78; } } else { - goto yy155; + goto yy157; } } yy69: rbs_skip(state); -#line 106 "ext/rbs_extension/lexer.re" +#line 107 "ext/rbs_extension/lexer.re" { return next_token(state, tDQSTRING); } -#line 690 "ext/rbs_extension/lexer.c" +#line 699 "ext/rbs_extension/lexer.c" yy70: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy140; - if (yych == 'x') goto yy141; + if (yych == 'u') goto yy142; + if (yych == 'x') goto yy143; goto yy66; yy71: rbs_skip(state); @@ -723,9 +732,9 @@ token rbsparser_next_token(lexstate *state) { } } yy72: -#line 139 "ext/rbs_extension/lexer.re" +#line 140 "ext/rbs_extension/lexer.re" { return next_token(state, tGIDENT); } -#line 729 "ext/rbs_extension/lexer.c" +#line 738 "ext/rbs_extension/lexer.c" yy73: rbs_skip(state); goto yy72; @@ -735,18 +744,18 @@ token rbsparser_next_token(lexstate *state) { if (yych <= 'Z') { if (yych <= '(') { if (yych <= '\'') goto yy68; - goto yy142; + goto yy144; } else { - if (yych == '<') goto yy143; + if (yych == '<') goto yy145; goto yy68; } } else { if (yych <= 'z') { - if (yych <= '[') goto yy144; + if (yych <= '[') goto yy146; goto yy68; } else { - if (yych <= '{') goto yy145; - if (yych <= '|') goto yy146; + if (yych <= '{') goto yy147; + if (yych <= '|') goto yy148; goto yy68; } } @@ -764,16 +773,16 @@ token rbsparser_next_token(lexstate *state) { yy77: rbs_skip(state); yy78: -#line 107 "ext/rbs_extension/lexer.re" +#line 108 "ext/rbs_extension/lexer.re" { return next_token(state, tSQSTRING); } -#line 770 "ext/rbs_extension/lexer.c" +#line 779 "ext/rbs_extension/lexer.c" yy79: rbs_skip(state); yych = peek(state); if (yych <= '\'') { if (yych <= 0x00000000) goto yy68; if (yych <= '&') goto yy75; - goto yy147; + goto yy149; } else { if (yych == '\\') goto yy79; goto yy75; @@ -782,16 +791,16 @@ token rbsparser_next_token(lexstate *state) { rbs_skip(state); #line 36 "ext/rbs_extension/lexer.re" { return next_token(state, pSTAR2); } -#line 786 "ext/rbs_extension/lexer.c" +#line 795 "ext/rbs_extension/lexer.c" yy81: rbs_skip(state); #line 41 "ext/rbs_extension/lexer.re" { return next_token(state, pARROW); } -#line 791 "ext/rbs_extension/lexer.c" +#line 800 "ext/rbs_extension/lexer.c" yy82: rbs_skip(state); yych = peek(state); - if (yych == '.') goto yy148; + if (yych == '.') goto yy150; goto yy68; yy83: rbs_skip(state); @@ -799,18 +808,18 @@ token rbsparser_next_token(lexstate *state) { if (yych == '=') goto yy87; if (yych == '~') goto yy87; yy84: -#line 126 "ext/rbs_extension/lexer.re" +#line 127 "ext/rbs_extension/lexer.re" { return next_token(state, tSYMBOL); } -#line 805 "ext/rbs_extension/lexer.c" +#line 814 "ext/rbs_extension/lexer.c" yy85: rbs_skip(state); yych = peek(state); if (yych <= '"') { if (yych <= 0x00000000) goto yy68; if (yych <= '!') goto yy85; - goto yy149; + goto yy151; } else { - if (yych == '\\') goto yy150; + if (yych == '\\') goto yy152; goto yy85; } yy86: @@ -820,42 +829,42 @@ token rbsparser_next_token(lexstate *state) { if (yych <= 0x0000001F) { if (yych <= '\n') { if (yych <= 0x00000000) goto yy68; - if (yych <= 0x00000008) goto yy151; + if (yych <= 0x00000008) goto yy153; goto yy68; } else { if (yych == '\r') goto yy68; - goto yy151; + goto yy153; } } else { if (yych <= '#') { if (yych <= ' ') goto yy68; - if (yych <= '"') goto yy153; - goto yy151; + if (yych <= '"') goto yy155; + goto yy153; } else { if (yych == '%') goto yy68; - if (yych <= '\'') goto yy153; + if (yych <= '\'') goto yy155; goto yy68; } } } else { if (yych <= 'Z') { if (yych <= '/') { - if (yych == '-') goto yy151; - goto yy153; + if (yych == '-') goto yy153; + goto yy155; } else { - if (yych <= '9') goto yy151; - if (yych <= '>') goto yy153; - goto yy151; + if (yych <= '9') goto yy153; + if (yych <= '>') goto yy155; + goto yy153; } } else { if (yych <= '^') { - if (yych == '\\') goto yy153; + if (yych == '\\') goto yy155; goto yy68; } else { - if (yych <= 'z') goto yy151; + if (yych <= 'z') goto yy153; if (yych <= '}') goto yy68; - if (yych <= '~') goto yy153; - goto yy151; + if (yych <= '~') goto yy155; + goto yy153; } } } @@ -868,9 +877,9 @@ token rbsparser_next_token(lexstate *state) { if (yych <= '\'') { if (yych <= 0x00000000) goto yy68; if (yych <= '&') goto yy88; - goto yy154; + goto yy156; } else { - if (yych == '\\') goto yy156; + if (yych == '\\') goto yy158; goto yy88; } yy89: @@ -887,18 +896,18 @@ token rbsparser_next_token(lexstate *state) { rbs_skip(state); #line 45 "ext/rbs_extension/lexer.re" { return next_token(state, pCOLON2); } -#line 891 "ext/rbs_extension/lexer.c" +#line 900 "ext/rbs_extension/lexer.c" yy92: rbs_skip(state); yych = peek(state); if (yych <= ';') goto yy84; if (yych <= '<') goto yy87; - if (yych <= '=') goto yy157; + if (yych <= '=') goto yy159; goto yy84; yy93: rbs_skip(state); yych = peek(state); - if (yych == '=') goto yy158; + if (yych == '=') goto yy160; if (yych == '~') goto yy87; goto yy68; yy94: @@ -912,12 +921,12 @@ token rbsparser_next_token(lexstate *state) { yych = peek(state); if (yych <= '^') { if (yych <= '?') goto yy68; - if (yych <= '@') goto yy159; - if (yych <= 'Z') goto yy160; + if (yych <= '@') goto yy161; + if (yych <= 'Z') goto yy162; goto yy68; } else { if (yych == '`') goto yy68; - if (yych <= 'z') goto yy160; + if (yych <= 'z') goto yy162; goto yy68; } yy96: @@ -925,14 +934,14 @@ token rbsparser_next_token(lexstate *state) { yych = peek(state); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy162; + if (yych == '!') goto yy164; } else { if (yych <= '9') goto yy96; - if (yych == '=') goto yy162; + if (yych == '=') goto yy164; } } else { if (yych <= '^') { - if (yych <= '?') goto yy162; + if (yych <= '?') goto yy164; if (yych <= '@') goto yy97; if (yych <= 'Z') goto yy96; } else { @@ -941,13 +950,13 @@ token rbsparser_next_token(lexstate *state) { } } yy97: -#line 122 "ext/rbs_extension/lexer.re" +#line 123 "ext/rbs_extension/lexer.re" { return next_token(state, tSYMBOL); } -#line 947 "ext/rbs_extension/lexer.c" +#line 956 "ext/rbs_extension/lexer.c" yy98: rbs_skip(state); yych = peek(state); - if (yych == ']') goto yy158; + if (yych == ']') goto yy160; goto yy68; yy99: rbs_skip(state); @@ -963,256 +972,252 @@ token rbsparser_next_token(lexstate *state) { rbs_skip(state); #line 42 "ext/rbs_extension/lexer.re" { return next_token(state, pFATARROW); } -#line 967 "ext/rbs_extension/lexer.c" +#line 976 "ext/rbs_extension/lexer.c" yy102: rbs_skip(state); yych = peek(state); if (yych <= '^') { if (yych <= '@') goto yy68; - if (yych <= 'Z') goto yy163; + if (yych <= 'Z') goto yy165; goto yy68; } else { if (yych == '`') goto yy68; - if (yych <= 'z') goto yy163; + if (yych <= 'z') goto yy165; goto yy68; } yy103: rbs_skip(state); yych = peek(state); +yy104: if (yych <= 'Z') { - if (yych <= '/') goto yy104; + if (yych <= '/') goto yy105; if (yych <= '9') goto yy103; if (yych >= 'A') goto yy103; } else { if (yych <= '_') { if (yych >= '_') goto yy103; } else { - if (yych <= '`') goto yy104; + if (yych <= '`') goto yy105; if (yych <= 'z') goto yy103; } } -yy104: -#line 136 "ext/rbs_extension/lexer.re" - { return next_token(state, tAIDENT); } -#line 998 "ext/rbs_extension/lexer.c" yy105: - rbs_skip(state); -#line 133 "ext/rbs_extension/lexer.re" - { return next_token(state, tBANGIDENT); } -#line 1003 "ext/rbs_extension/lexer.c" +#line 137 "ext/rbs_extension/lexer.re" + { return next_token(state, tAIDENT); } +#line 1008 "ext/rbs_extension/lexer.c" yy106: rbs_skip(state); + yych = peek(state); + if (yych == 'b') goto yy167; + goto yy104; +yy107: + rbs_skip(state); #line 134 "ext/rbs_extension/lexer.re" + { return next_token(state, tBANGIDENT); } +#line 1018 "ext/rbs_extension/lexer.c" +yy108: + rbs_skip(state); +#line 135 "ext/rbs_extension/lexer.re" { return next_token(state, tEQIDENT); } -#line 1008 "ext/rbs_extension/lexer.c" -yy107: +#line 1023 "ext/rbs_extension/lexer.c" +yy109: rbs_skip(state); yych = peek(state); if (yych == '=') goto yy24; #line 47 "ext/rbs_extension/lexer.re" { return next_token(state, pAREF_OPR); } -#line 1015 "ext/rbs_extension/lexer.c" -yy108: +#line 1030 "ext/rbs_extension/lexer.c" +yy110: rbs_skip(state); yych = peek(state); -yy109: +yy111: if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy110; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy110; - if (yych <= 'Z') goto yy108; + if (yych <= '@') goto yy112; + if (yych <= 'Z') goto yy110; } else { - if (yych == '`') goto yy110; - if (yych <= 'z') goto yy108; + if (yych == '`') goto yy112; + if (yych <= 'z') goto yy110; } } -yy110: -#line 130 "ext/rbs_extension/lexer.re" +yy112: +#line 131 "ext/rbs_extension/lexer.re" { return next_token(state, tULLIDENT); } -#line 1039 "ext/rbs_extension/lexer.c" -yy111: +#line 1054 "ext/rbs_extension/lexer.c" +yy113: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { - if (yych <= '9') goto yy111; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy113; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy112; - if (yych <= 'Z') goto yy111; + if (yych <= '@') goto yy114; + if (yych <= 'Z') goto yy113; } else { - if (yych == '`') goto yy112; - if (yych <= 'z') goto yy111; + if (yych == '`') goto yy114; + if (yych <= 'z') goto yy113; } } -yy112: -#line 131 "ext/rbs_extension/lexer.re" +yy114: +#line 132 "ext/rbs_extension/lexer.re" { return next_token(state, tULIDENT); } -#line 1062 "ext/rbs_extension/lexer.c" -yy113: +#line 1077 "ext/rbs_extension/lexer.c" +yy115: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy165; - goto yy109; -yy114: + if (yych == 't') goto yy168; + goto yy111; +yy116: rbs_skip(state); yych = peek(state); if (yych <= 0x00000000) goto yy68; - if (yych == '`') goto yy166; - goto yy114; -yy115: + if (yych == '`') goto yy169; + goto yy116; +yy117: rbs_skip(state); yych = peek(state); - if (yych == 'i') goto yy167; + if (yych == 'i') goto yy170; goto yy53; -yy116: +yy118: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy117; + if (yych <= '@') goto yy119; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy117; + if (yych == '`') goto yy119; if (yych <= 'z') goto yy52; } } -yy117: +yy119: #line 96 "ext/rbs_extension/lexer.re" { return next_token(state, kAS); } -#line 1101 "ext/rbs_extension/lexer.c" -yy118: - rbs_skip(state); - yych = peek(state); - if (yych == 't') goto yy168; - goto yy53; -yy119: - rbs_skip(state); - yych = peek(state); - if (yych == 'o') goto yy169; - if (yych == 't') goto yy170; - goto yy53; +#line 1116 "ext/rbs_extension/lexer.c" yy120: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy172; + if (yych == 't') goto yy171; goto yy53; yy121: rbs_skip(state); yych = peek(state); - if (yych == 'f') goto yy173; + if (yych == 'o') goto yy172; + if (yych == 't') goto yy173; goto yy53; yy122: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy175; + if (yych == 'a') goto yy175; goto yy53; yy123: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy177; + if (yych == 'f') goto yy176; goto yy53; yy124: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy178; + if (yych == 'd') goto yy178; goto yy53; yy125: + rbs_skip(state); + yych = peek(state); + if (yych == 't') goto yy180; + goto yy53; +yy126: + rbs_skip(state); + yych = peek(state); + if (yych == 'l') goto yy181; + goto yy53; +yy127: rbs_skip(state); yych = peek(state); if (yych <= '^') { if (yych <= '9') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; if (yych >= '0') goto yy52; } else { if (yych <= '=') { - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } else { - if (yych <= '@') goto yy126; + if (yych <= '@') goto yy128; if (yych <= 'Z') goto yy52; } } } else { if (yych <= 'c') { - if (yych == '`') goto yy126; + if (yych == '`') goto yy128; if (yych <= 'b') goto yy52; - goto yy179; + goto yy182; } else { if (yych <= 's') { if (yych <= 'r') goto yy52; - goto yy180; + goto yy183; } else { - if (yych <= 't') goto yy181; + if (yych <= 't') goto yy184; if (yych <= 'z') goto yy52; } } } -yy126: +yy128: #line 77 "ext/rbs_extension/lexer.re" { return next_token(state, kIN); } -#line 1171 "ext/rbs_extension/lexer.c" -yy127: - rbs_skip(state); - yych = peek(state); - if (yych == 'd') goto yy182; - goto yy53; -yy128: - rbs_skip(state); - yych = peek(state); - if (yych == 'l') goto yy183; - goto yy53; +#line 1186 "ext/rbs_extension/lexer.c" yy129: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy185; + if (yych == 'd') goto yy185; goto yy53; yy130: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy187; - if (yych == 'i') goto yy188; + if (yych == 'l') goto yy186; goto yy53; yy131: rbs_skip(state); yych = peek(state); - if (yych == 'b') goto yy189; + if (yych == 't') goto yy188; goto yy53; yy132: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy190; + if (yych == 'e') goto yy190; + if (yych == 'i') goto yy191; goto yy53; yy133: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy191; + if (yych == 'b') goto yy192; goto yy53; yy134: rbs_skip(state); yych = peek(state); - if (yych == 'p') goto yy192; + if (yych == 'l') goto yy193; goto yy53; yy135: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy194; + if (yych == 'n') goto yy194; goto yy53; yy136: rbs_skip(state); @@ -1222,33 +1227,43 @@ token rbsparser_next_token(lexstate *state) { yy137: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy196; - if (yych == 't') goto yy197; + if (yych == 'u') goto yy197; goto yy53; yy138: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy198; + if (yych == 'p') goto yy198; goto yy53; yy139: rbs_skip(state); yych = peek(state); - if (yych == 'i') goto yy200; + if (yych == 'c') goto yy199; + if (yych == 't') goto yy200; goto yy53; yy140: + rbs_skip(state); + yych = peek(state); + if (yych == 'e') goto yy201; + goto yy53; +yy141: + rbs_skip(state); + yych = peek(state); + if (yych == 'i') goto yy203; + goto yy53; +yy142: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy201; + if (yych <= '9') goto yy204; goto yy68; } else { - if (yych <= 'F') goto yy201; + if (yych <= 'F') goto yy204; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy201; + if (yych <= 'f') goto yy204; goto yy68; } -yy141: +yy143: rbs_skip(state); yych = peek(state); if (yych <= '/') goto yy68; @@ -1256,37 +1271,37 @@ token rbsparser_next_token(lexstate *state) { if (yych <= '`') goto yy68; if (yych <= 'f') goto yy66; goto yy68; -yy142: - rbs_skip(state); - yych = peek(state); - if (yych <= 0x00000000) goto yy68; - if (yych == ')') goto yy202; - goto yy142; -yy143: - rbs_skip(state); - yych = peek(state); - if (yych <= 0x00000000) goto yy68; - if (yych == '>') goto yy203; - goto yy143; yy144: rbs_skip(state); yych = peek(state); if (yych <= 0x00000000) goto yy68; - if (yych == ']') goto yy204; + if (yych == ')') goto yy205; goto yy144; yy145: rbs_skip(state); yych = peek(state); if (yych <= 0x00000000) goto yy68; - if (yych == '}') goto yy205; + if (yych == '>') goto yy206; goto yy145; yy146: rbs_skip(state); yych = peek(state); if (yych <= 0x00000000) goto yy68; - if (yych == '|') goto yy206; + if (yych == ']') goto yy207; goto yy146; yy147: + rbs_skip(state); + yych = peek(state); + if (yych <= 0x00000000) goto yy68; + if (yych == '}') goto yy208; + goto yy147; +yy148: + rbs_skip(state); + yych = peek(state); + if (yych <= 0x00000000) goto yy68; + if (yych == '|') goto yy209; + goto yy148; +yy149: yyaccept = 5; rbs_skip(state); backup = *state; @@ -1299,466 +1314,471 @@ token rbsparser_next_token(lexstate *state) { if (yych == '\\') goto yy79; goto yy75; } -yy148: +yy150: rbs_skip(state); #line 38 "ext/rbs_extension/lexer.re" { return next_token(state, pDOT3); } -#line 1307 "ext/rbs_extension/lexer.c" -yy149: +#line 1322 "ext/rbs_extension/lexer.c" +yy151: rbs_skip(state); -#line 108 "ext/rbs_extension/lexer.re" +#line 109 "ext/rbs_extension/lexer.re" { return next_token(state, tDQSYMBOL); } -#line 1312 "ext/rbs_extension/lexer.c" -yy150: +#line 1327 "ext/rbs_extension/lexer.c" +yy152: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy207; - if (yych == 'x') goto yy208; + if (yych == 'u') goto yy210; + if (yych == 'x') goto yy211; goto yy85; -yy151: +yy153: rbs_skip(state); yych = peek(state); if (yych <= ',') { if (yych <= '\f') { - if (yych <= 0x00000000) goto yy152; - if (yych <= 0x00000008) goto yy151; - if (yych >= '\v') goto yy151; + if (yych <= 0x00000000) goto yy154; + if (yych <= 0x00000008) goto yy153; + if (yych >= '\v') goto yy153; } else { if (yych <= 0x0000001F) { - if (yych >= 0x0000000E) goto yy151; + if (yych >= 0x0000000E) goto yy153; } else { - if (yych == '#') goto yy151; + if (yych == '#') goto yy153; } } } else { if (yych <= '>') { - if (yych <= '-') goto yy151; - if (yych <= '/') goto yy152; - if (yych <= '9') goto yy151; + if (yych <= '-') goto yy153; + if (yych <= '/') goto yy154; + if (yych <= '9') goto yy153; } else { if (yych <= '^') { - if (yych <= 'Z') goto yy151; + if (yych <= 'Z') goto yy153; } else { - if (yych <= 'z') goto yy151; - if (yych >= 0x0000007F) goto yy151; + if (yych <= 'z') goto yy153; + if (yych >= 0x0000007F) goto yy153; } } } -yy152: -#line 125 "ext/rbs_extension/lexer.re" +yy154: +#line 126 "ext/rbs_extension/lexer.re" { return next_token(state, tSYMBOL); } -#line 1351 "ext/rbs_extension/lexer.c" -yy153: +#line 1366 "ext/rbs_extension/lexer.c" +yy155: rbs_skip(state); - goto yy152; -yy154: + goto yy154; +yy156: rbs_skip(state); -yy155: -#line 109 "ext/rbs_extension/lexer.re" +yy157: +#line 110 "ext/rbs_extension/lexer.re" { return next_token(state, tSQSYMBOL); } -#line 1360 "ext/rbs_extension/lexer.c" -yy156: +#line 1375 "ext/rbs_extension/lexer.c" +yy158: rbs_skip(state); yych = peek(state); if (yych <= '\'') { if (yych <= 0x00000000) goto yy68; if (yych <= '&') goto yy88; - goto yy209; + goto yy212; } else { - if (yych == '\\') goto yy156; + if (yych == '\\') goto yy158; goto yy88; } -yy157: +yy159: rbs_skip(state); yych = peek(state); if (yych == '>') goto yy87; goto yy84; -yy158: +yy160: rbs_skip(state); yych = peek(state); if (yych == '=') goto yy87; goto yy84; -yy159: +yy161: rbs_skip(state); yych = peek(state); if (yych <= '^') { if (yych <= '@') goto yy68; - if (yych <= 'Z') goto yy210; + if (yych <= 'Z') goto yy213; goto yy68; } else { if (yych == '`') goto yy68; - if (yych <= 'z') goto yy210; + if (yych <= 'z') goto yy213; goto yy68; } -yy160: +yy162: rbs_skip(state); yych = peek(state); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy212; + if (yych == '!') goto yy215; } else { - if (yych <= '9') goto yy160; - if (yych == '=') goto yy212; + if (yych <= '9') goto yy162; + if (yych == '=') goto yy215; } } else { if (yych <= '^') { - if (yych <= '?') goto yy212; - if (yych <= '@') goto yy161; - if (yych <= 'Z') goto yy160; + if (yych <= '?') goto yy215; + if (yych <= '@') goto yy163; + if (yych <= 'Z') goto yy162; } else { - if (yych == '`') goto yy161; - if (yych <= 'z') goto yy160; + if (yych == '`') goto yy163; + if (yych <= 'z') goto yy162; } } -yy161: -#line 123 "ext/rbs_extension/lexer.re" +yy163: +#line 124 "ext/rbs_extension/lexer.re" { return next_token(state, tSYMBOL); } -#line 1417 "ext/rbs_extension/lexer.c" -yy162: +#line 1432 "ext/rbs_extension/lexer.c" +yy164: rbs_skip(state); goto yy97; -yy163: +yy165: rbs_skip(state); yych = peek(state); if (yych <= 'Z') { - if (yych <= '/') goto yy164; - if (yych <= '9') goto yy163; - if (yych >= 'A') goto yy163; + if (yych <= '/') goto yy166; + if (yych <= '9') goto yy165; + if (yych >= 'A') goto yy165; } else { if (yych <= '_') { - if (yych >= '_') goto yy163; + if (yych >= '_') goto yy165; } else { - if (yych <= '`') goto yy164; - if (yych <= 'z') goto yy163; + if (yych <= '`') goto yy166; + if (yych <= 'z') goto yy165; } } -yy164: -#line 137 "ext/rbs_extension/lexer.re" +yy166: +#line 138 "ext/rbs_extension/lexer.re" { return next_token(state, tA2IDENT); } -#line 1439 "ext/rbs_extension/lexer.c" -yy165: +#line 1454 "ext/rbs_extension/lexer.c" +yy167: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy213; - goto yy109; -yy166: + if (yych == 's') goto yy216; + goto yy104; +yy168: + rbs_skip(state); + yych = peek(state); + if (yych == 'o') goto yy218; + goto yy111; +yy169: rbs_skip(state); #line 40 "ext/rbs_extension/lexer.re" { return next_token(state, tQIDENT); } -#line 1449 "ext/rbs_extension/lexer.c" -yy167: +#line 1469 "ext/rbs_extension/lexer.c" +yy170: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy214; + if (yych == 'a') goto yy219; goto yy53; -yy168: +yy171: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy215; + if (yych == 'r') goto yy220; goto yy53; -yy169: +yy172: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy216; + if (yych == 'l') goto yy221; goto yy53; -yy170: +yy173: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy171; + if (yych <= '@') goto yy174; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy171; + if (yych == '`') goto yy174; if (yych <= 'z') goto yy52; } } -yy171: +yy174: #line 71 "ext/rbs_extension/lexer.re" { return next_token(state, kBOT); } -#line 1487 "ext/rbs_extension/lexer.c" -yy172: +#line 1507 "ext/rbs_extension/lexer.c" +yy175: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy218; + if (yych == 's') goto yy223; goto yy53; -yy173: +yy176: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy174; + if (yych <= '@') goto yy177; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy174; + if (yych == '`') goto yy177; if (yych <= 'z') goto yy52; } } -yy174: +yy177: #line 73 "ext/rbs_extension/lexer.re" { return next_token(state, kDEF); } -#line 1515 "ext/rbs_extension/lexer.c" -yy175: +#line 1535 "ext/rbs_extension/lexer.c" +yy178: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy176; + if (yych <= '@') goto yy179; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy176; + if (yych == '`') goto yy179; if (yych <= 'z') goto yy52; } } -yy176: +yy179: #line 74 "ext/rbs_extension/lexer.re" { return next_token(state, kEND); } -#line 1538 "ext/rbs_extension/lexer.c" -yy177: +#line 1558 "ext/rbs_extension/lexer.c" +yy180: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy219; + if (yych == 'e') goto yy224; goto yy53; -yy178: +yy181: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy220; + if (yych == 's') goto yy225; goto yy53; -yy179: +yy182: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy221; + if (yych == 'l') goto yy226; goto yy53; -yy180: +yy183: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy222; + if (yych == 't') goto yy227; goto yy53; -yy181: +yy184: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy223; + if (yych == 'e') goto yy228; goto yy53; -yy182: +yy185: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy224; + if (yych == 'u') goto yy229; goto yy53; -yy183: +yy186: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy184; + if (yych <= '@') goto yy187; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy184; + if (yych == '`') goto yy187; if (yych <= 'z') goto yy52; } } -yy184: +yy187: #line 82 "ext/rbs_extension/lexer.re" { return next_token(state, kNIL); } -#line 1591 "ext/rbs_extension/lexer.c" -yy185: +#line 1611 "ext/rbs_extension/lexer.c" +yy188: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy186; + if (yych <= '@') goto yy189; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy186; + if (yych == '`') goto yy189; if (yych <= 'z') goto yy52; } } -yy186: +yy189: #line 83 "ext/rbs_extension/lexer.re" { return next_token(state, kOUT); } -#line 1614 "ext/rbs_extension/lexer.c" -yy187: +#line 1634 "ext/rbs_extension/lexer.c" +yy190: rbs_skip(state); yych = peek(state); - if (yych == 'p') goto yy225; + if (yych == 'p') goto yy230; goto yy53; -yy188: +yy191: rbs_skip(state); yych = peek(state); - if (yych == 'v') goto yy226; + if (yych == 'v') goto yy231; goto yy53; -yy189: +yy192: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy227; + if (yych == 'l') goto yy232; goto yy53; -yy190: +yy193: rbs_skip(state); yych = peek(state); - if (yych == 'f') goto yy228; + if (yych == 'f') goto yy233; goto yy53; -yy191: +yy194: rbs_skip(state); yych = peek(state); - if (yych == 'g') goto yy230; + if (yych == 'g') goto yy235; goto yy53; -yy192: +yy195: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy193; + if (yych <= '@') goto yy196; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy193; + if (yych == '`') goto yy196; if (yych <= 'z') goto yy52; } } -yy193: +yy196: #line 89 "ext/rbs_extension/lexer.re" { return next_token(state, kTOP); } -#line 1662 "ext/rbs_extension/lexer.c" -yy194: +#line 1682 "ext/rbs_extension/lexer.c" +yy197: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy231; + if (yych == 'e') goto yy236; goto yy53; -yy195: +yy198: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy233; + if (yych == 'e') goto yy238; goto yy53; -yy196: +yy199: rbs_skip(state); yych = peek(state); - if (yych == 'h') goto yy235; + if (yych == 'h') goto yy240; goto yy53; -yy197: +yy200: rbs_skip(state); yych = peek(state); - if (yych == 'y') goto yy236; + if (yych == 'y') goto yy241; goto yy53; -yy198: +yy201: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy199; + if (yych <= '@') goto yy202; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy199; + if (yych == '`') goto yy202; if (yych <= 'z') goto yy52; } } -yy199: +yy202: #line 95 "ext/rbs_extension/lexer.re" { return next_token(state, kUSE); } -#line 1705 "ext/rbs_extension/lexer.c" -yy200: +#line 1725 "ext/rbs_extension/lexer.c" +yy203: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy237; + if (yych == 'd') goto yy242; goto yy53; -yy201: +yy204: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy239; + if (yych <= '9') goto yy244; goto yy68; } else { - if (yych <= 'F') goto yy239; + if (yych <= 'F') goto yy244; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy239; + if (yych <= 'f') goto yy244; goto yy68; } -yy202: +yy205: rbs_skip(state); #line 54 "ext/rbs_extension/lexer.re" { return next_token(state, tANNOTATION); } -#line 1728 "ext/rbs_extension/lexer.c" -yy203: +#line 1748 "ext/rbs_extension/lexer.c" +yy206: rbs_skip(state); #line 57 "ext/rbs_extension/lexer.re" { return next_token(state, tANNOTATION); } -#line 1733 "ext/rbs_extension/lexer.c" -yy204: +#line 1753 "ext/rbs_extension/lexer.c" +yy207: rbs_skip(state); #line 55 "ext/rbs_extension/lexer.re" { return next_token(state, tANNOTATION); } -#line 1738 "ext/rbs_extension/lexer.c" -yy205: +#line 1758 "ext/rbs_extension/lexer.c" +yy208: rbs_skip(state); #line 53 "ext/rbs_extension/lexer.re" { return next_token(state, tANNOTATION); } -#line 1743 "ext/rbs_extension/lexer.c" -yy206: +#line 1763 "ext/rbs_extension/lexer.c" +yy209: rbs_skip(state); #line 56 "ext/rbs_extension/lexer.re" { return next_token(state, tANNOTATION); } -#line 1748 "ext/rbs_extension/lexer.c" -yy207: +#line 1768 "ext/rbs_extension/lexer.c" +yy210: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy240; + if (yych <= '9') goto yy245; goto yy68; } else { - if (yych <= 'F') goto yy240; + if (yych <= 'F') goto yy245; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy240; + if (yych <= 'f') goto yy245; goto yy68; } -yy208: +yy211: rbs_skip(state); yych = peek(state); if (yych <= '/') goto yy68; @@ -1766,411 +1786,430 @@ token rbsparser_next_token(lexstate *state) { if (yych <= '`') goto yy68; if (yych <= 'f') goto yy85; goto yy68; -yy209: +yy212: yyaccept = 6; rbs_skip(state); backup = *state; yych = peek(state); if (yych <= '\'') { - if (yych <= 0x00000000) goto yy155; + if (yych <= 0x00000000) goto yy157; if (yych <= '&') goto yy88; - goto yy154; + goto yy156; } else { - if (yych == '\\') goto yy156; + if (yych == '\\') goto yy158; goto yy88; } -yy210: +yy213: rbs_skip(state); yych = peek(state); if (yych <= '>') { if (yych <= '/') { - if (yych == '!') goto yy241; + if (yych == '!') goto yy246; } else { - if (yych <= '9') goto yy210; - if (yych == '=') goto yy241; + if (yych <= '9') goto yy213; + if (yych == '=') goto yy246; } } else { if (yych <= '^') { - if (yych <= '?') goto yy241; - if (yych <= '@') goto yy211; - if (yych <= 'Z') goto yy210; + if (yych <= '?') goto yy246; + if (yych <= '@') goto yy214; + if (yych <= 'Z') goto yy213; } else { - if (yych == '`') goto yy211; - if (yych <= 'z') goto yy210; + if (yych == '`') goto yy214; + if (yych <= 'z') goto yy213; } } -yy211: -#line 124 "ext/rbs_extension/lexer.re" +yy214: +#line 125 "ext/rbs_extension/lexer.re" { return next_token(state, tSYMBOL); } -#line 1806 "ext/rbs_extension/lexer.c" -yy212: +#line 1826 "ext/rbs_extension/lexer.c" +yy215: rbs_skip(state); - goto yy161; -yy213: + goto yy163; +yy216: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy242; - goto yy109; -yy214: + if (yych <= 'Z') { + if (yych <= '/') goto yy217; + if (yych <= '9') goto yy103; + if (yych >= 'A') goto yy103; + } else { + if (yych <= '_') { + if (yych >= '_') goto yy103; + } else { + if (yych <= '`') goto yy217; + if (yych <= 'z') goto yy103; + } + } +yy217: +#line 98 "ext/rbs_extension/lexer.re" + { return next_token(state, kATRBS); } +#line 1848 "ext/rbs_extension/lexer.c" +yy218: + rbs_skip(state); + yych = peek(state); + if (yych == 'd') goto yy247; + goto yy111; +yy219: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy243; + if (yych == 's') goto yy248; goto yy53; -yy215: +yy220: rbs_skip(state); yych = peek(state); - if (yych == '_') goto yy245; + if (yych == '_') goto yy250; goto yy53; -yy216: +yy221: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy217; + if (yych <= '@') goto yy222; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy217; + if (yych == '`') goto yy222; if (yych <= 'z') goto yy52; } } -yy217: +yy222: #line 70 "ext/rbs_extension/lexer.re" { return next_token(state, kBOOL); } -#line 1847 "ext/rbs_extension/lexer.c" -yy218: +#line 1886 "ext/rbs_extension/lexer.c" +yy223: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy246; + if (yych == 's') goto yy251; goto yy53; -yy219: +yy224: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy248; + if (yych == 'n') goto yy253; goto yy53; -yy220: +yy225: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy249; + if (yych == 'e') goto yy254; goto yy53; -yy221: +yy226: rbs_skip(state); yych = peek(state); - if (yych == 'u') goto yy251; + if (yych == 'u') goto yy256; goto yy53; -yy222: +yy227: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy252; + if (yych == 'a') goto yy257; goto yy53; -yy223: +yy228: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy253; + if (yych == 'r') goto yy258; goto yy53; -yy224: +yy229: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy254; + if (yych == 'l') goto yy259; goto yy53; -yy225: +yy230: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy255; + if (yych == 'e') goto yy260; goto yy53; -yy226: +yy231: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy256; + if (yych == 'a') goto yy261; goto yy53; -yy227: +yy232: rbs_skip(state); yych = peek(state); - if (yych == 'i') goto yy257; + if (yych == 'i') goto yy262; goto yy53; -yy228: +yy233: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy229; + if (yych <= '@') goto yy234; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy229; + if (yych == '`') goto yy234; if (yych <= 'z') goto yy52; } } -yy229: +yy234: #line 87 "ext/rbs_extension/lexer.re" { return next_token(state, kSELF); } -#line 1920 "ext/rbs_extension/lexer.c" -yy230: +#line 1959 "ext/rbs_extension/lexer.c" +yy235: rbs_skip(state); yych = peek(state); - if (yych == 'l') goto yy258; + if (yych == 'l') goto yy263; goto yy53; -yy231: +yy236: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy232; + if (yych <= '@') goto yy237; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy232; + if (yych == '`') goto yy237; if (yych <= 'z') goto yy52; } } -yy232: +yy237: #line 90 "ext/rbs_extension/lexer.re" { return next_token(state, kTRUE); } -#line 1948 "ext/rbs_extension/lexer.c" -yy233: +#line 1987 "ext/rbs_extension/lexer.c" +yy238: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy234; + if (yych <= '@') goto yy239; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy234; + if (yych == '`') goto yy239; if (yych <= 'z') goto yy52; } } -yy234: +yy239: #line 91 "ext/rbs_extension/lexer.re" { return next_token(state, kTYPE); } -#line 1971 "ext/rbs_extension/lexer.c" -yy235: +#line 2010 "ext/rbs_extension/lexer.c" +yy240: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy259; + if (yych == 'e') goto yy264; goto yy53; -yy236: +yy241: rbs_skip(state); yych = peek(state); - if (yych == 'p') goto yy260; + if (yych == 'p') goto yy265; goto yy53; -yy237: +yy242: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy238; + if (yych <= '@') goto yy243; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy238; + if (yych == '`') goto yy243; if (yych <= 'z') goto yy52; } } -yy238: +yy243: #line 94 "ext/rbs_extension/lexer.re" { return next_token(state, kVOID); } -#line 2004 "ext/rbs_extension/lexer.c" -yy239: +#line 2043 "ext/rbs_extension/lexer.c" +yy244: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy261; + if (yych <= '9') goto yy266; goto yy68; } else { - if (yych <= 'F') goto yy261; + if (yych <= 'F') goto yy266; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy261; + if (yych <= 'f') goto yy266; goto yy68; } -yy240: +yy245: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy262; + if (yych <= '9') goto yy267; goto yy68; } else { - if (yych <= 'F') goto yy262; + if (yych <= 'F') goto yy267; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy262; + if (yych <= 'f') goto yy267; goto yy68; } -yy241: +yy246: rbs_skip(state); - goto yy211; -yy242: + goto yy214; +yy247: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy263; - goto yy109; -yy243: + if (yych == 'o') goto yy268; + goto yy111; +yy248: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy244; + if (yych <= '@') goto yy249; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy244; + if (yych == '`') goto yy249; if (yych <= 'z') goto yy52; } } -yy244: +yy249: #line 66 "ext/rbs_extension/lexer.re" { return next_token(state, kALIAS); } -#line 2061 "ext/rbs_extension/lexer.c" -yy245: +#line 2100 "ext/rbs_extension/lexer.c" +yy250: rbs_skip(state); yych = peek(state); if (yych <= 'q') { - if (yych == 'a') goto yy264; + if (yych == 'a') goto yy269; goto yy53; } else { - if (yych <= 'r') goto yy265; - if (yych == 'w') goto yy266; + if (yych <= 'r') goto yy270; + if (yych == 'w') goto yy271; goto yy53; } -yy246: +yy251: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy247; + if (yych <= '@') goto yy252; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy247; + if (yych == '`') goto yy252; if (yych <= 'z') goto yy52; } } -yy247: +yy252: #line 72 "ext/rbs_extension/lexer.re" { return next_token(state, kCLASS); } -#line 2095 "ext/rbs_extension/lexer.c" -yy248: +#line 2134 "ext/rbs_extension/lexer.c" +yy253: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy267; + if (yych == 'd') goto yy272; goto yy53; -yy249: +yy254: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy250; + if (yych <= '@') goto yy255; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy250; + if (yych == '`') goto yy255; if (yych <= 'z') goto yy52; } } -yy250: +yy255: #line 76 "ext/rbs_extension/lexer.re" { return next_token(state, kFALSE); } -#line 2123 "ext/rbs_extension/lexer.c" -yy251: +#line 2162 "ext/rbs_extension/lexer.c" +yy256: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy269; + if (yych == 'd') goto yy274; goto yy53; -yy252: +yy257: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy270; + if (yych == 'n') goto yy275; goto yy53; -yy253: +yy258: rbs_skip(state); yych = peek(state); - if (yych == 'f') goto yy271; + if (yych == 'f') goto yy276; goto yy53; -yy254: +yy259: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy272; + if (yych == 'e') goto yy277; goto yy53; -yy255: +yy260: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy274; + if (yych == 'n') goto yy279; goto yy53; -yy256: +yy261: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy275; + if (yych == 't') goto yy280; goto yy53; -yy257: +yy262: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy276; + if (yych == 'c') goto yy281; goto yy53; -yy258: +yy263: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy278; + if (yych == 'e') goto yy283; goto yy53; -yy259: +yy264: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy279; + if (yych == 'c') goto yy284; goto yy53; -yy260: +yy265: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy280; + if (yych == 'e') goto yy285; goto yy53; -yy261: +yy266: rbs_skip(state); yych = peek(state); if (yych <= '@') { @@ -2183,149 +2222,149 @@ token rbsparser_next_token(lexstate *state) { if (yych <= 'f') goto yy66; goto yy68; } -yy262: +yy267: rbs_skip(state); yych = peek(state); if (yych <= '@') { if (yych <= '/') goto yy68; - if (yych <= '9') goto yy281; + if (yych <= '9') goto yy286; goto yy68; } else { - if (yych <= 'F') goto yy281; + if (yych <= 'F') goto yy286; if (yych <= '`') goto yy68; - if (yych <= 'f') goto yy281; + if (yych <= 'f') goto yy286; goto yy68; } -yy263: +yy268: rbs_skip(state); yych = peek(state); - if (yych == '_') goto yy282; - goto yy109; -yy264: + if (yych == '_') goto yy287; + goto yy111; +yy269: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy283; + if (yych == 'c') goto yy288; goto yy53; -yy265: +yy270: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy284; + if (yych == 'e') goto yy289; goto yy53; -yy266: +yy271: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy285; + if (yych == 'r') goto yy290; goto yy53; -yy267: +yy272: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy268; + if (yych <= '@') goto yy273; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy268; + if (yych == '`') goto yy273; if (yych <= 'z') goto yy52; } } -yy268: +yy273: #line 75 "ext/rbs_extension/lexer.re" { return next_token(state, kEXTEND); } -#line 2242 "ext/rbs_extension/lexer.c" -yy269: +#line 2281 "ext/rbs_extension/lexer.c" +yy274: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy286; + if (yych == 'e') goto yy291; goto yy53; -yy270: +yy275: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy288; + if (yych == 'c') goto yy293; goto yy53; -yy271: +yy276: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy289; + if (yych == 'a') goto yy294; goto yy53; -yy272: +yy277: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy273; + if (yych <= '@') goto yy278; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy273; + if (yych == '`') goto yy278; if (yych <= 'z') goto yy52; } } -yy273: +yy278: #line 81 "ext/rbs_extension/lexer.re" { return next_token(state, kMODULE); } -#line 2280 "ext/rbs_extension/lexer.c" -yy274: +#line 2319 "ext/rbs_extension/lexer.c" +yy279: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy290; + if (yych == 'd') goto yy295; goto yy53; -yy275: +yy280: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy292; + if (yych == 'e') goto yy297; goto yy53; -yy276: +yy281: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy277; + if (yych <= '@') goto yy282; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy277; + if (yych == '`') goto yy282; if (yych <= 'z') goto yy52; } } -yy277: +yy282: #line 86 "ext/rbs_extension/lexer.re" { return next_token(state, kPUBLIC); } -#line 2313 "ext/rbs_extension/lexer.c" -yy278: +#line 2352 "ext/rbs_extension/lexer.c" +yy283: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy294; + if (yych == 't') goto yy299; goto yy53; -yy279: +yy284: rbs_skip(state); yych = peek(state); - if (yych == 'k') goto yy295; + if (yych == 'k') goto yy300; goto yy53; -yy280: +yy285: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy296; + if (yych == 'd') goto yy301; goto yy53; -yy281: +yy286: rbs_skip(state); yych = peek(state); if (yych <= '@') { @@ -2338,365 +2377,365 @@ token rbsparser_next_token(lexstate *state) { if (yych <= 'f') goto yy85; goto yy68; } -yy282: +yy287: rbs_skip(state); yych = peek(state); - if (yych == '_') goto yy298; - goto yy109; -yy283: + if (yych == '_') goto yy303; + goto yy111; +yy288: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy300; + if (yych == 'c') goto yy305; goto yy53; -yy284: +yy289: rbs_skip(state); yych = peek(state); - if (yych == 'a') goto yy301; + if (yych == 'a') goto yy306; goto yy53; -yy285: +yy290: rbs_skip(state); yych = peek(state); - if (yych == 'i') goto yy302; + if (yych == 'i') goto yy307; goto yy53; -yy286: +yy291: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy287; + if (yych <= '@') goto yy292; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy287; + if (yych == '`') goto yy292; if (yych <= 'z') goto yy52; } } -yy287: +yy292: #line 78 "ext/rbs_extension/lexer.re" { return next_token(state, kINCLUDE); } -#line 2384 "ext/rbs_extension/lexer.c" -yy288: +#line 2423 "ext/rbs_extension/lexer.c" +yy293: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy303; + if (yych == 'e') goto yy308; goto yy53; -yy289: +yy294: rbs_skip(state); yych = peek(state); - if (yych == 'c') goto yy305; + if (yych == 'c') goto yy310; goto yy53; -yy290: +yy295: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy291; + if (yych <= '@') goto yy296; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy291; + if (yych == '`') goto yy296; if (yych <= 'z') goto yy52; } } -yy291: +yy296: #line 84 "ext/rbs_extension/lexer.re" { return next_token(state, kPREPEND); } -#line 2417 "ext/rbs_extension/lexer.c" -yy292: +#line 2456 "ext/rbs_extension/lexer.c" +yy297: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy293; + if (yych <= '@') goto yy298; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy293; + if (yych == '`') goto yy298; if (yych <= 'z') goto yy52; } } -yy293: +yy298: #line 85 "ext/rbs_extension/lexer.re" { return next_token(state, kPRIVATE); } -#line 2440 "ext/rbs_extension/lexer.c" -yy294: +#line 2479 "ext/rbs_extension/lexer.c" +yy299: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy306; + if (yych == 'o') goto yy311; goto yy53; -yy295: +yy300: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy307; + if (yych == 'e') goto yy312; goto yy53; -yy296: +yy301: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy297; + if (yych <= '@') goto yy302; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy297; + if (yych == '`') goto yy302; if (yych <= 'z') goto yy52; } } -yy297: +yy302: #line 93 "ext/rbs_extension/lexer.re" { return next_token(state, kUNTYPED); } -#line 2473 "ext/rbs_extension/lexer.c" -yy298: +#line 2512 "ext/rbs_extension/lexer.c" +yy303: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { - if (yych <= '9') goto yy108; - if (yych >= '=') goto yy106; + if (yych <= '9') goto yy110; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy299; - if (yych <= 'Z') goto yy108; + if (yych <= '@') goto yy304; + if (yych <= 'Z') goto yy110; } else { - if (yych == '`') goto yy299; - if (yych <= 'z') goto yy108; + if (yych == '`') goto yy304; + if (yych <= 'z') goto yy110; } } -yy299: +yy304: #line 97 "ext/rbs_extension/lexer.re" { return next_token(state, k__TODO__); } -#line 2496 "ext/rbs_extension/lexer.c" -yy300: +#line 2535 "ext/rbs_extension/lexer.c" +yy305: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy308; + if (yych == 'e') goto yy313; goto yy53; -yy301: +yy306: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy309; + if (yych == 'd') goto yy314; goto yy53; -yy302: +yy307: rbs_skip(state); yych = peek(state); - if (yych == 't') goto yy310; + if (yych == 't') goto yy315; goto yy53; -yy303: +yy308: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy304; + if (yych <= '@') goto yy309; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy304; + if (yych == '`') goto yy309; if (yych <= 'z') goto yy52; } } -yy304: +yy309: #line 79 "ext/rbs_extension/lexer.re" { return next_token(state, kINSTANCE); } -#line 2534 "ext/rbs_extension/lexer.c" -yy305: +#line 2573 "ext/rbs_extension/lexer.c" +yy310: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy311; + if (yych == 'e') goto yy316; goto yy53; -yy306: +yy311: rbs_skip(state); yych = peek(state); - if (yych == 'n') goto yy313; + if (yych == 'n') goto yy318; goto yy53; -yy307: +yy312: rbs_skip(state); yych = peek(state); - if (yych == 'd') goto yy315; + if (yych == 'd') goto yy320; goto yy53; -yy308: +yy313: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy317; + if (yych == 's') goto yy322; goto yy53; -yy309: +yy314: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy318; + if (yych == 'e') goto yy323; goto yy53; -yy310: +yy315: rbs_skip(state); yych = peek(state); - if (yych == 'e') goto yy319; + if (yych == 'e') goto yy324; goto yy53; -yy311: +yy316: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy312; + if (yych <= '@') goto yy317; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy312; + if (yych == '`') goto yy317; if (yych <= 'z') goto yy52; } } -yy312: +yy317: #line 80 "ext/rbs_extension/lexer.re" { return next_token(state, kINTERFACE); } -#line 2587 "ext/rbs_extension/lexer.c" -yy313: +#line 2626 "ext/rbs_extension/lexer.c" +yy318: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy314; + if (yych <= '@') goto yy319; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy314; + if (yych == '`') goto yy319; if (yych <= 'z') goto yy52; } } -yy314: +yy319: #line 88 "ext/rbs_extension/lexer.re" { return next_token(state, kSINGLETON); } -#line 2610 "ext/rbs_extension/lexer.c" -yy315: +#line 2649 "ext/rbs_extension/lexer.c" +yy320: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy316; + if (yych <= '@') goto yy321; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy316; + if (yych == '`') goto yy321; if (yych <= 'z') goto yy52; } } -yy316: +yy321: #line 92 "ext/rbs_extension/lexer.re" { return next_token(state, kUNCHECKED); } -#line 2633 "ext/rbs_extension/lexer.c" -yy317: +#line 2672 "ext/rbs_extension/lexer.c" +yy322: rbs_skip(state); yych = peek(state); - if (yych == 's') goto yy320; + if (yych == 's') goto yy325; goto yy53; -yy318: +yy323: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy321; + if (yych == 'r') goto yy326; goto yy53; -yy319: +yy324: rbs_skip(state); yych = peek(state); - if (yych == 'r') goto yy323; + if (yych == 'r') goto yy328; goto yy53; -yy320: +yy325: rbs_skip(state); yych = peek(state); - if (yych == 'o') goto yy325; + if (yych == 'o') goto yy330; goto yy53; -yy321: +yy326: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy322; + if (yych <= '@') goto yy327; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy322; + if (yych == '`') goto yy327; if (yych <= 'z') goto yy52; } } -yy322: +yy327: #line 68 "ext/rbs_extension/lexer.re" { return next_token(state, kATTRREADER); } -#line 2676 "ext/rbs_extension/lexer.c" -yy323: +#line 2715 "ext/rbs_extension/lexer.c" +yy328: rbs_skip(state); yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy324; + if (yych <= '@') goto yy329; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy324; + if (yych == '`') goto yy329; if (yych <= 'z') goto yy52; } } -yy324: +yy329: #line 69 "ext/rbs_extension/lexer.re" { return next_token(state, kATTRWRITER); } -#line 2699 "ext/rbs_extension/lexer.c" -yy325: +#line 2738 "ext/rbs_extension/lexer.c" +yy330: rbs_skip(state); yych = peek(state); if (yych != 'r') goto yy53; @@ -2704,25 +2743,25 @@ token rbsparser_next_token(lexstate *state) { yych = peek(state); if (yych <= '=') { if (yych <= '/') { - if (yych == '!') goto yy105; + if (yych == '!') goto yy107; } else { if (yych <= '9') goto yy52; - if (yych >= '=') goto yy106; + if (yych >= '=') goto yy108; } } else { if (yych <= '^') { - if (yych <= '@') goto yy326; + if (yych <= '@') goto yy331; if (yych <= 'Z') goto yy52; } else { - if (yych == '`') goto yy326; + if (yych == '`') goto yy331; if (yych <= 'z') goto yy52; } } -yy326: +yy331: #line 67 "ext/rbs_extension/lexer.re" { return next_token(state, kATTRACCESSOR); } -#line 2725 "ext/rbs_extension/lexer.c" +#line 2764 "ext/rbs_extension/lexer.c" } -#line 146 "ext/rbs_extension/lexer.re" +#line 147 "ext/rbs_extension/lexer.re" } diff --git a/ext/rbs_extension/lexer.h b/ext/rbs_extension/lexer.h index 55a8a3994..f5eb7bb5e 100644 --- a/ext/rbs_extension/lexer.h +++ b/ext/rbs_extension/lexer.h @@ -61,6 +61,7 @@ enum TokenType { kUSE, /* use */ kAS, /* as */ k__TODO__, /* __todo__ */ + kATRBS, /* @rbs */ tLIDENT, /* Identifiers starting with lower case */ tUIDENT, /* Identifiers starting with upper case */ diff --git a/ext/rbs_extension/lexer.re b/ext/rbs_extension/lexer.re index aa1b94746..4d58b5295 100644 --- a/ext/rbs_extension/lexer.re +++ b/ext/rbs_extension/lexer.re @@ -95,6 +95,7 @@ token rbsparser_next_token(lexstate *state) { "use" { return next_token(state, kUSE); } "as" { return next_token(state, kAS); } "__todo__" { return next_token(state, k__TODO__); } + "@rbs" { return next_token(state, kATRBS); } unicode_char = "\\u" [0-9a-fA-F]{4}; oct_char = "\\x" [0-9a-f]{1,2}; diff --git a/ext/rbs_extension/lexstate.c b/ext/rbs_extension/lexstate.c index ed32fd06a..c7389df80 100644 --- a/ext/rbs_extension/lexstate.c +++ b/ext/rbs_extension/lexstate.c @@ -60,6 +60,7 @@ static const char *RBS_TOKENTYPE_NAMES[] = { "kUSE", /* use */ "kAS", /* as */ "k__TODO__", /* __todo__ */ + "kATRBS", /* @rbs */ "tLIDENT", /* Identifiers starting with lower case */ "tUIDENT", /* Identifiers starting with upper case */ diff --git a/ext/rbs_extension/location.c b/ext/rbs_extension/location.c index 5b251bbc6..ed9073a33 100644 --- a/ext/rbs_extension/location.c +++ b/ext/rbs_extension/location.c @@ -314,8 +314,8 @@ void rbs__init_location(void) { rb_define_private_method(RBS_Location, "initialize", location_initialize, 3); rb_define_private_method(RBS_Location, "initialize_copy", location_initialize_copy, 1); rb_define_method(RBS_Location, "buffer", location_buffer, 0); - rb_define_method(RBS_Location, "start_pos", location_start_pos, 0); - rb_define_method(RBS_Location, "end_pos", location_end_pos, 0); + rb_define_method(RBS_Location, "_start_pos", location_start_pos, 0); + rb_define_method(RBS_Location, "_end_pos", location_end_pos, 0); rb_define_method(RBS_Location, "_add_required_child", location_add_required_child, 3); rb_define_method(RBS_Location, "_add_optional_child", location_add_optional_child, 3); rb_define_method(RBS_Location, "_add_optional_no_child", location_add_optional_no_child, 1); diff --git a/ext/rbs_extension/parser.c b/ext/rbs_extension/parser.c index 77f583c41..4cec458ed 100644 --- a/ext/rbs_extension/parser.c +++ b/ext/rbs_extension/parser.c @@ -1942,7 +1942,8 @@ static VALUE parse_variable_member(parserstate *state, position comment_pos, VAL switch (state->current_token.type) { - case tAIDENT: { + case tAIDENT: + case kATRBS: { range name_range = state->current_token.range; VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token)); @@ -1989,7 +1990,15 @@ static VALUE parse_variable_member(parserstate *state, position comment_pos, VAL }; parser_advance_assert(state, pDOT); - parser_advance_assert(state, tAIDENT); + if (state->next_token.type == tAIDENT || state->next_token.type == kATRBS) { + parser_advance(state); + } else { + raise_syntax_error( + state, + state->current_token, + "expected a instance variable name" + ); + } range name_range = state->current_token.range; VALUE name = ID2SYM(INTERN_TOKEN(state, state->current_token)); @@ -2098,7 +2107,7 @@ static VALUE parse_attribute_member(parserstate *state, position comment_pos, VA parser_advance_assert(state, pLPAREN); ivar_range.start = state->current_token.range.start; - if (parser_advance_if(state, tAIDENT)) { + if (parser_advance_if(state, tAIDENT) || parser_advance_if(state, kATRBS)) { ivar_name = ID2SYM(INTERN_TOKEN(state, state->current_token)); ivar_name_range = state->current_token.range; } else { @@ -2331,6 +2340,7 @@ static VALUE parse_module_members(parserstate *state) { case tAIDENT: case tA2IDENT: + case kATRBS: case kSELF: { member = parse_variable_member(state, annot_pos, annotations); break; @@ -2853,6 +2863,134 @@ VALUE parse_signature(parserstate *state) { return ret; } +/** + * @brief + * overload ::= {} annotations + */ +static void parse_method_overload(parserstate *state, VALUE *annotations, VALUE *method_type) { + position pos; + + parse_annotations(state, annotations, &pos); + *method_type = parse_method_type(state); +} + +/** + * @brief Parses inline method overload definitions and updates `overloads` and `bar_locations` + * + * inline_method_overloads ::= {} -- returns true + * | {} overload `|` ... `|` overload -- returns true + * | {<>} -- returns false + * + * + * @param state + * @param overloads + * @param bar_location + */ +static void parse_inline_method_overloads(parserstate *state, VALUE *overloads, VALUE *bar_locations) { + while (true) { + VALUE annotations = EMPTY_ARRAY; + VALUE method_type; + + parse_method_overload(state, &annotations, &method_type); + + VALUE overload = rbs_ast_members_method_definition_overload(annotations, method_type); + + rb_ary_push(*overloads, overload); + + if (state->next_token.type == pBAR) { + parser_advance(state); + melt_array(bar_locations); + rb_ary_push(*bar_locations, rbs_new_location(state->buffer, state->current_token.range)); + } else { + return; + } + } +} + +static VALUE parse_inline_leading_annotation(parserstate *state) { + switch (state->next_token.type) { + case pCOLON: { + // : + range colon_range = state->next_token.range; + parser_advance(state); + + VALUE annotations = EMPTY_ARRAY; + VALUE method_type; + + parse_method_overload(state, &annotations, &method_type); + + return rbs_ast_ruby_annotations_colon_method_type_annotation( + rbs_new_location(state->buffer, (range) { .start = colon_range.start, .end = state->current_token.range.end }), + rbs_new_location(state->buffer, colon_range), + annotations, + method_type + ); + } + case kATRBS: { + range rbs_range = state->next_token.range; + parser_advance(state); + + switch (state->next_token.type) { + case pLPAREN: + case pLBRACKET: + case pLBRACE: + case tANNOTATION: { + VALUE overloads = rb_ary_new(); + VALUE bar_locations = EMPTY_ARRAY; + + parse_inline_method_overloads(state, &overloads, &bar_locations); + + return rbs_ast_ruby_annotations_method_types_annotation( + rbs_new_location(state->buffer, (range) { .start = rbs_range.start, .end = state->current_token.range.end }), + rbs_new_location(state->buffer, rbs_range), + overloads, + bar_locations + ); + } + default: { + raise_syntax_error( + state, + state->next_token, + "unexpected token for @rbs annotation" + ); + } + } + } + default: { + raise_syntax_error( + state, + state->next_token, + "unexpected token for inline leading annotation" + ); + } + } +} + +static VALUE parse_inline_trailing_annotation(parserstate *state) { + range prefix_range = state->next_token.range; + + switch (state->next_token.type) { + case pCOLON: { + parser_advance(state); + + VALUE type = parse_type(state); + + return rbs_ast_ruby_annotations_node_type_assertion( + rbs_new_location(state->buffer, (range) { .start = prefix_range.start, .end = state->current_token.range.end }), + rbs_new_location(state->buffer, prefix_range), + type + ); + } + default: { + raise_syntax_error( + state, + state->next_token, + "unexpected token for inline trailing annotation" + ); + } + } +} + struct parse_type_arg { parserstate *parser; VALUE require_eof; @@ -2963,6 +3101,42 @@ rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) { return results; } +static VALUE parse_inline_leading_try(VALUE a) { + parserstate *parser = (parserstate *)a; + VALUE annotation = parse_inline_leading_annotation(parser); + + parser_advance_assert(parser, pEOF); + + return annotation; +} + +static VALUE rbsparser_parse_inline_leading_annotation(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables) { + VALUE string = rb_funcall(buffer, rb_intern("content"), 0); + StringValue(string); + lexstate *lexer = alloc_lexer(string, FIX2INT(start_pos), FIX2INT(end_pos)); + parserstate *parser = alloc_parser(buffer, lexer, FIX2INT(start_pos), FIX2INT(end_pos), variables); + + return rb_ensure(parse_inline_leading_try, (VALUE)parser, ensure_free_parser, (VALUE)parser); +} + +static VALUE parse_inline_trailing_try(VALUE a) { + parserstate *parser = (parserstate *)a; + VALUE annotation = parse_inline_trailing_annotation(parser); + + parser_advance_assert(parser, pEOF); + + return annotation; +} + +static VALUE rbsparser_parse_inline_trailing_annotation(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos, VALUE variables) { + VALUE string = rb_funcall(buffer, rb_intern("content"), 0); + StringValue(string); + lexstate *lexer = alloc_lexer(string, FIX2INT(start_pos), FIX2INT(end_pos)); + parserstate *parser = alloc_parser(buffer, lexer, FIX2INT(start_pos), FIX2INT(end_pos), variables); + + return rb_ensure(parse_inline_trailing_try, (VALUE)parser, ensure_free_parser, (VALUE)parser); +} + void rbs__init_parser(void) { RBS_Parser = rb_define_class_under(RBS, "Parser", rb_cObject); rb_gc_register_mark_object(RBS_Parser); @@ -2978,5 +3152,7 @@ void rbs__init_parser(void) { rb_define_singleton_method(RBS_Parser, "_parse_type", rbsparser_parse_type, 5); rb_define_singleton_method(RBS_Parser, "_parse_method_type", rbsparser_parse_method_type, 5); rb_define_singleton_method(RBS_Parser, "_parse_signature", rbsparser_parse_signature, 3); + rb_define_singleton_method(RBS_Parser, "_parse_inline_leading_annotation", rbsparser_parse_inline_leading_annotation, 4); + rb_define_singleton_method(RBS_Parser, "_parse_inline_trailing_annotation", rbsparser_parse_inline_trailing_annotation, 4); rb_define_singleton_method(RBS_Parser, "_lex", rbsparser_lex, 2); } diff --git a/include/rbs/constants.h b/include/rbs/constants.h index 995f5f923..8792debe4 100644 --- a/include/rbs/constants.h +++ b/include/rbs/constants.h @@ -14,6 +14,8 @@ extern VALUE RBS_AST; extern VALUE RBS_AST_Declarations; extern VALUE RBS_AST_Directives; extern VALUE RBS_AST_Members; +extern VALUE RBS_AST_Ruby; +extern VALUE RBS_AST_Ruby_Annotations; extern VALUE RBS_Types; extern VALUE RBS_Types_Bases; extern VALUE RBS_ParsingError; @@ -47,6 +49,9 @@ extern VALUE RBS_AST_Members_MethodDefinition_Overload; extern VALUE RBS_AST_Members_Prepend; extern VALUE RBS_AST_Members_Private; extern VALUE RBS_AST_Members_Public; +extern VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation; +extern VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation; +extern VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion; extern VALUE RBS_AST_TypeParam; extern VALUE RBS_MethodType; extern VALUE RBS_Namespace; diff --git a/include/rbs/ruby_objs.h b/include/rbs/ruby_objs.h index 102e57d40..47a284e5a 100644 --- a/include/rbs/ruby_objs.h +++ b/include/rbs/ruby_objs.h @@ -39,6 +39,9 @@ VALUE rbs_ast_members_method_definition_overload(VALUE annotations, VALUE method VALUE rbs_ast_members_prepend(VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment); VALUE rbs_ast_members_private(VALUE location); VALUE rbs_ast_members_public(VALUE location); +VALUE rbs_ast_ruby_annotations_colon_method_type_annotation(VALUE location, VALUE prefix_location, VALUE annotations, VALUE method_type); +VALUE rbs_ast_ruby_annotations_method_types_annotation(VALUE location, VALUE prefix_location, VALUE overloads, VALUE vertical_bar_locations); +VALUE rbs_ast_ruby_annotations_node_type_assertion(VALUE location, VALUE prefix_location, VALUE type); VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location); VALUE rbs_method_type(VALUE type_params, VALUE type, VALUE block, VALUE location); VALUE rbs_namespace(VALUE path, VALUE absolute); diff --git a/lib/rbs.rb b/lib/rbs.rb index 2a98abc6d..b4a8b6aa5 100644 --- a/lib/rbs.rb +++ b/lib/rbs.rb @@ -25,12 +25,15 @@ require "rbs/ast/members" require "rbs/ast/annotation" require "rbs/ast/visitor" +require "rbs/ast/ruby/comment_block" require "rbs/ast/ruby/helpers/constant_helper" require "rbs/ast/ruby/helpers/location_helper" +require "rbs/ast/ruby/annotations" require "rbs/ast/ruby/declarations" require "rbs/ast/ruby/members" require "rbs/source" require "rbs/inline_parser" +require "rbs/inline_parser/comment_association" require "rbs/environment" require "rbs/environment/use_map" require "rbs/environment/class_entry" diff --git a/lib/rbs/ast/ruby/annotations.rb b/lib/rbs/ast/ruby/annotations.rb new file mode 100644 index 000000000..442989182 --- /dev/null +++ b/lib/rbs/ast/ruby/annotations.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +module RBS + module AST + module Ruby + module Annotations + class Base + attr_reader :location, :prefix_location + + def initialize(location, prefix_location) + @location = location + @prefix_location = prefix_location + end + + def buffer + location.buffer + end + end + + class NodeTypeAssertion < Base + attr_reader :type + + def initialize(location:, prefix_location:, type:) + super(location, prefix_location) + @type = type + end + + def map_type_name + self.class.new( + location:, prefix_location:, + type: type.map_type_name { yield _1 } + ) #: self + end + end + + class ColonMethodTypeAnnotation < Base + attr_reader :annotations, :method_type + + def initialize(location:, prefix_location:, annotations:, method_type:) + super(location, prefix_location) + @annotations = annotations + @method_type = method_type + end + + def map_type_name + self.class.new( + location:, + prefix_location:, + annotations: annotations, + method_type: method_type.map_type {|type| type.map_type_name { yield _1 }} + ) #: self + end + end + + class MethodTypesAnnotation < Base + Overload = AST::Members::MethodDefinition::Overload + + attr_reader :overloads, :vertical_bar_locations + + def initialize(location:, prefix_location:, overloads:, vertical_bar_locations:) + super(location, prefix_location) + @overloads = overloads + @vertical_bar_locations = vertical_bar_locations + end + + def map_type_name(&block) + ovs = overloads.map do |overload| + Overload.new( + method_type: overload.method_type.map_type {|type| type.map_type_name { yield _1 } }, + annotations: overload.annotations + ) + end + + self.class.new(location:, prefix_location:, overloads: ovs, vertical_bar_locations:) #: self + end + end + end + end + end +end diff --git a/lib/rbs/ast/ruby/comment_block.rb b/lib/rbs/ast/ruby/comment_block.rb new file mode 100644 index 000000000..72a07ea5d --- /dev/null +++ b/lib/rbs/ast/ruby/comment_block.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +module RBS + module AST + module Ruby + class CommentBlock + attr_reader :name, :offsets, :comment_buffer + + def initialize(source_buffer, comments) + @name = source_buffer.name + + @offsets = [] + + # Assume the comment starts with a prefix whitespace + prefix_str = "# " + + ranges = [] #: Array[Range[Integer]] + + comments.each do |comment| + tuple = [comment, 2] #: [Prism::Comment, Integer] + + unless comment.location.slice.start_with?(prefix_str) + tuple[1] = 1 + end + + offsets << tuple + + start_char = comment.location.start_character_offset + tuple[1] + end_char = comment.location.end_character_offset + ranges << (start_char ... end_char) + end + + @comment_buffer = source_buffer.sub_buffer(lines: ranges) + end + + def leading? + comment = offsets[0][0] or raise + comment.location.start_line_slice.index(/\S/) ? false : true + end + + def trailing? + comment = offsets[0][0] or raise + comment.location.start_line_slice.index(/\S/) ? true : false + end + + def start_line + comments[0].location.start_line + end + + def end_line + comments[-1].location.end_line + end + + def line_starts + offsets.map do |comment, prefix_size| + comment.location.start_character_offset + prefix_size + end + end + + def self.build(buffer, comments) + blocks = [] #: Array[CommentBlock] + + comments = comments.filter {|comment| comment.is_a?(Prism::InlineComment) } + + until comments.empty? + block_comments = [] #: Array[Prism::Comment] + + until comments.empty? + comment = comments.first or raise + last_comment = block_comments.last + + if last_comment + if last_comment.location.end_line + 1 == comment.location.start_line + if last_comment.location.start_column == comment.location.start_column + unless comment.location.start_line_slice.index(/\S/) + block_comments << comments.shift + next + end + end + end + + break + else + block_comments << comments.shift + end + end + + unless block_comments.empty? + blocks << CommentBlock.new(buffer, block_comments.dup) + end + end + + blocks + end + + AnnotationSyntaxError = _ = Struct.new(:location, :error) + + def each_paragraph(variables, &block) + if block + if leading_annotation?(0) + yield_annotation(0, 0, 0, variables, &block) + else + yield_paragraph(0, 0, variables, &block) + end + else + enum_for :each_paragraph, variables + end + end + + def yield_paragraph(start_line, current_line, variables, &block) + # We already know at start_line..current_line are paragraph. + + while true + next_line = current_line + 1 + + if next_line >= comment_buffer.line_count + yield line_location(start_line, current_line) + return + end + + if leading_annotation?(next_line) + yield line_location(start_line, current_line) + return yield_annotation(next_line, next_line, next_line, variables, &block) + else + current_line = next_line + end + end + end + + def yield_annotation(start_line, end_line, current_line, variables, &block) + # We already know at start_line..end_line are annotation. + while true + next_line = current_line + 1 + + if next_line >= comment_buffer.line_count + annotation = parse_annotation_lines(start_line, end_line, variables) + yield annotation + + if end_line > current_line + yield_paragraph(end_line + 1, end_line + 1, variables, &block) + end + + return + end + + line_text = text(next_line) + if leading_spaces = line_text.index(/\S/) + if leading_spaces == 0 + # End of annotation + yield parse_annotation_lines(start_line, end_line, variables) + + if leading_annotation?(end_line + 1) + yield_annotation(end_line + 1, end_line + 1, end_line + 1, variables, &block) + else + yield_paragraph(end_line + 1, end_line + 1, variables, &block) + end + + return + else + current_line = next_line + end_line = next_line + end + else + current_line = next_line + end + end + end + + def text(comment_index) + range = comment_buffer.ranges[comment_index] + comment_buffer.content[range] or raise + end + + def line_location(start_line, end_line) + start_offset = comment_buffer.ranges[start_line].begin + end_offset = comment_buffer.ranges[end_line].end + Location.new(comment_buffer, start_offset, end_offset) + end + + def parse_annotation_lines(start_line, end_line, variables) + start_pos = comment_buffer.ranges[start_line].begin + end_pos = comment_buffer.ranges[end_line].end + begin + Parser.parse_inline_leading_annotation(comment_buffer, start_pos...end_pos, variables: variables) + rescue ParsingError => error + AnnotationSyntaxError.new(line_location(start_line, end_line), error) + end + end + + def trailing_annotation(variables) + if trailing? + comment = comments[0] or raise + if comment.location.slice.start_with?(/#[:\[]/) + begin + Parser.parse_inline_trailing_annotation(comment_buffer, 0...comment_buffer.last_position, variables: variables) + rescue ParsingError => error + location = line_location(0, offsets.size - 1) + AnnotationSyntaxError.new(location, error) + end + end + end + end + + def comments + offsets.map { _1[0]} + end + + def leading_annotation?(index) + if index < comment_buffer.line_count + text(index).start_with?(/@rbs\b/) and return true + + comment = offsets[index][0] + comment.location.slice.start_with?(/\#:/) and return true + end + + false + end + end + end + end +end diff --git a/lib/rbs/ast/ruby/members.rb b/lib/rbs/ast/ruby/members.rb index 03903b342..082d11713 100644 --- a/lib/rbs/ast/ruby/members.rb +++ b/lib/rbs/ast/ruby/members.rb @@ -14,16 +14,130 @@ def initialize(buffer) include Helpers::LocationHelper end + class MethodTypeAnnotation + attr_reader :type_annotations + + def initialize(type_annotations:) + @type_annotations = type_annotations + end + + def map_type_name(&block) + case type_annotations + when Array + updated_annots = type_annotations.map do |annotation| + annotation.map_type_name(&block) + end + when Annotations::NodeTypeAssertion + updated_annots = type_annotations.map_type_name(&block) + end + + MethodTypeAnnotation.new(type_annotations: updated_annots) #: self + end + + def self.build(leading_block, trailing_block, variables) + unused_annotations = [] #: Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError] + unused_trailing_annotation = nil #: Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil + + type_annotations = nil #: type_annotations + + if trailing_block + case annotation = trailing_block.trailing_annotation(variables) + when Annotations::NodeTypeAssertion + type_annotations = annotation + else + unused_trailing_annotation = annotation + end + end + + if leading_block + leading_block.each_paragraph(variables) do |paragraph| + next if paragraph.is_a?(Location) + + if paragraph.is_a?(CommentBlock::AnnotationSyntaxError) + unused_annotations << paragraph + next + end + + case paragraph + when Annotations::MethodTypesAnnotation, Annotations::ColonMethodTypeAnnotation + type_annotations = [] unless type_annotations + if type_annotations.is_a?(Array) + type_annotations << paragraph + next + end + end + + unused_annotations << paragraph + end + end + + [ + MethodTypeAnnotation.new( + type_annotations: type_annotations + ), + unused_annotations, + unused_trailing_annotation + ] + end + + def empty? + type_annotations.nil? + end + + def overloads + case type_annotations + when Annotations::NodeTypeAssertion + method_type = MethodType.new( + type_params: [], + type: Types::Function.empty(type_annotations.type), + block: nil, + location: nil + ) + + [ + AST::Members::MethodDefinition::Overload.new(annotations: [], method_type: method_type) + ] + when Array + type_annotations.flat_map do |annotation| + case annotation + when Annotations::ColonMethodTypeAnnotation + [ + AST::Members::MethodDefinition::Overload.new( + annotations: annotation.annotations, + method_type: annotation.method_type + ) + ] + when Annotations::MethodTypesAnnotation + annotation.overloads + end + end + when nil + method_type = MethodType.new( + type_params: [], + type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)), + block: nil, + location: nil + ) + + [ + AST::Members::MethodDefinition::Overload.new(method_type: method_type, annotations: []) + ] + end + end + end + class DefMember < Base Overload = AST::Members::MethodDefinition::Overload attr_reader :name attr_reader :node + attr_reader :method_type - def initialize(buffer, name, node) + def initialize(buffer, name, node, method_type) super(buffer) @name = name @node = node + @method_type = method_type end def location @@ -31,16 +145,7 @@ def location end def overloads - method_type = MethodType.new( - type_params: [], - type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)), - block: nil, - location: nil - ) - - [ - Overload.new(method_type: method_type, annotations: []) - ] + method_type.overloads end def overloading? diff --git a/lib/rbs/buffer.rb b/lib/rbs/buffer.rb index c5f48dcfe..7990a07d2 100644 --- a/lib/rbs/buffer.rb +++ b/lib/rbs/buffer.rb @@ -4,39 +4,53 @@ module RBS class Buffer attr_reader :name attr_reader :content + attr_reader :parent - def initialize(name:, content:) - @name = name - @content = content + def initialize(name: nil, content:, parent: nil) + case + when name && content + @name = name + @content = content + @parent = nil + when parent && content + @name = parent[0].name + @content = content + @parent = parent + end end def lines - @lines ||= content.lines + ranges.map { self.content[_1] || raise } #$ String + end + + def line_count + ranges.size end def ranges - @ranges ||= - begin - @ranges = [] - offset = 0 - lines.each do |line| - size = line.size - range = offset...(offset+size) - @ranges << range - offset += size - end - - if !content.end_with?("\n") && content.size > 0 - @ranges[-1] = @ranges[-1].begin...(@ranges[-1].end+1) - end - - @ranges + @ranges ||= begin + lines = content.lines + lines << "" if content.end_with?("\n") + + ranges = [] #: Array[Range[Integer]] + offset = 0 + + lines.each do |line| + size0 = line.size + line = line.chomp + range = offset...(offset+line.size) + ranges << range + + offset += size0 end + + ranges + end end def pos_to_loc(pos) index = ranges.bsearch_index do |range| - pos < range.end ? true : false + pos <= range.end ? true : false end if index @@ -49,7 +63,7 @@ def pos_to_loc(pos) def loc_to_pos(loc) line, column = loc - if range = ranges[line - 1] + if range = ranges.fetch(line - 1, nil) range.begin + column else last_position @@ -57,11 +71,77 @@ def loc_to_pos(loc) end def last_position - content.size + if ranges.empty? + 0 + else + ranges[-1].end + end end def inspect - "#" + "#" + end + + def rbs_location(location, loc2=nil) + if loc2 + Location.new(self, location.start_character_offset, loc2.end_character_offset) + else + Location.new(self, location.start_character_offset, location.end_character_offset) + end + end + + def sub_buffer(lines:) + buf = +"" + lines.each_with_index do |range, index| + start_pos = range.begin + end_pos = range.end + slice = content[start_pos...end_pos] or raise + if slice.include?("\n") + raise "Line #{index + 1} cannot contain newline character." + end + buf << slice + buf << "\n" + end + + buf.chomp! + + Buffer.new(content: buf, parent: [self, lines]) + end + + def parent_buffer + if parent + parent[0] + end + end + + def parent_position(position) + parent or raise "#parent_position is unavailable with buffer without parent" + return nil unless position <= last_position + + line, column = pos_to_loc(position) + parent_range = parent[1][line - 1] + parent_range.begin + column + end + + def absolute_position(position) + if parent_buffer + pos = parent_position(position) or return + parent_buffer.absolute_position(pos) + else + position + end + end + + def top_buffer + if parent_buffer + parent_buffer.top_buffer + else + self + end + end + + def detach + Buffer.new(name: name, content: content) end end end diff --git a/lib/rbs/environment.rb b/lib/rbs/environment.rb index e013c3529..a6475fa1e 100644 --- a/lib/rbs/environment.rb +++ b/lib/rbs/environment.rb @@ -673,7 +673,7 @@ def resolve_ruby_decl(resolver, decl, context:, prefix:) when AST::Ruby::Declarations::Base resolved.members << resolve_ruby_decl(resolver, member, context: inner_context, prefix: inner_prefix) when AST::Ruby::Members::Base - resolved.members << member + resolved.members << resolve_ruby_member(resolver, member, context: inner_context) else raise "Unknown member type: #{member.class}" end @@ -701,6 +701,20 @@ def resolve_ruby_decl(resolver, decl, context:, prefix:) end end + def resolve_ruby_member(resolver, member, context:) + case member + when AST::Ruby::Members::DefMember + AST::Ruby::Members::DefMember.new( + member.buffer, + member.name, + member.node, + member.method_type.map_type_name {|name, _, _| absolute_type_name(resolver, nil, name, context: context) } + ) + else + raise "Unknown member type: #{member.class}" + end + end + def resolve_member(resolver, map, member, context:) case member when AST::Members::MethodDefinition @@ -816,7 +830,7 @@ def resolve_type_params(resolver, map, params, context:) end def absolute_type_name(resolver, map, type_name, context:) - type_name = map.resolve(type_name) + type_name = map.resolve(type_name) if map resolver.resolve(type_name, context: context) || type_name end diff --git a/lib/rbs/inline_parser.rb b/lib/rbs/inline_parser.rb index 26348a8f3..a7a746024 100644 --- a/lib/rbs/inline_parser.rb +++ b/lib/rbs/inline_parser.rb @@ -27,6 +27,8 @@ def initialize(location, message) NonConstantClassName = _ = Class.new(Base) NonConstantModuleName = _ = Class.new(Base) TopLevelMethodDefinition = _ = Class.new(Base) + UnusedInlineAnnotation = _ = Class.new(Base) + AnnotationSyntaxError = _ = Class.new(Base) end def self.parse(buffer, prism) @@ -38,7 +40,7 @@ def self.parse(buffer, prism) end class Parser < Prism::Visitor - attr_reader :module_nesting, :result + attr_reader :module_nesting, :result, :comments include AST::Ruby::Helpers::ConstantHelper include AST::Ruby::Helpers::LocationHelper @@ -46,6 +48,7 @@ class Parser < Prism::Visitor def initialize(result) @result = result @module_nesting = [] + @comments = CommentAssociation.build(result.buffer, result.prism_result) end def buffer @@ -85,6 +88,10 @@ def visit_class_node(node) push_module_nesting(class_decl) do visit_child_nodes(node) end + + comments.each_enclosed_block(node) do |block| + report_unused_block(block) + end end def visit_module_node(node) @@ -101,6 +108,10 @@ def visit_module_node(node) push_module_nesting(module_decl) do visit_child_nodes(node) end + + comments.each_enclosed_block(node) do |block| + report_unused_block(block) + end end def visit_def_node(node) @@ -114,8 +125,24 @@ def visit_def_node(node) case current = current_module when AST::Ruby::Declarations::ClassDecl, AST::Ruby::Declarations::ModuleDecl - defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node) + leading_block = comments.leading_block!(node) + + if node.end_keyword_loc + # Not an end-less def + end_loc = node.rparen_loc || node.parameters&.location || node.name_loc + trailing_block = comments.trailing_block!(end_loc) + end + + method_type, leading_unuseds, trailing_unused = AST::Ruby::Members::MethodTypeAnnotation.build(leading_block, trailing_block, []) + report_unused_annotation(trailing_unused, *leading_unuseds) + + defn = AST::Ruby::Members::DefMember.new(buffer, node.name, node, method_type) current.members << defn + + # Skip other comments in `def` node + comments.each_enclosed_block(node) do |block| + comments.associated_blocks << block + end else diagnostics << Diagnostic::TopLevelMethodDefinition.new( rbs_location(node.name_loc), @@ -131,6 +158,32 @@ def insert_declaration(decl) result.declarations << decl end end + + def report_unused_annotation(*annotations) + annotations.each do |annotation| + case annotation + when AST::Ruby::CommentBlock::AnnotationSyntaxError + diagnostics << Diagnostic::AnnotationSyntaxError.new( + annotation.location, "Syntax error: " + annotation.error.error_message + ) + when AST::Ruby::Annotations::Base + diagnostics << Diagnostic::UnusedInlineAnnotation.new( + annotation.location, "Unused inline rbs annotation" + ) + end + end + end + + def report_unused_block(block) + block.each_paragraph([]) do |paragraph| + case paragraph + when Location + # noop + else + report_unused_annotation(paragraph) + end + end + end end end end diff --git a/lib/rbs/inline_parser/comment_association.rb b/lib/rbs/inline_parser/comment_association.rb new file mode 100644 index 000000000..91db2cd5a --- /dev/null +++ b/lib/rbs/inline_parser/comment_association.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +module RBS + class InlineParser + class CommentAssociation + attr_reader :blocks, :associated_blocks, :start_line_map, :end_line_map + + def initialize(blocks) + @blocks = blocks.sort_by {|block| block.start_line } + @associated_blocks = Set[].compare_by_identity + + @start_line_map = {} + @end_line_map = {} + + blocks.each do |block| + if block.leading? + end_line_map[block.end_line] = block + else + start_line_map[block.start_line] = block + end + end + end + + def self.build(buffer, result) + blocks = AST::Ruby::CommentBlock.build(buffer, result.comments) + new(blocks) + end + + class Reference + attr_reader :block + + def initialize(block, association) + @block = block + @associated_blocks = association + end + + def associate! + @associated_blocks << block + self + end + + def associated? + @associated_blocks.include?(block) + end + end + + def leading_block(node) + start_line = node.location.start_line + + if block = end_line_map.fetch(start_line - 1, nil) + Reference.new(block, associated_blocks) + end + end + + def leading_block!(node) + if ref = leading_block(node) + unless ref.associated? + ref.associate!.block + end + end + end + + def trailing_block(node) + location = + if node.is_a?(Prism::Node) + node.location + else + node + end #: Prism::Location + end_line = location.end_line + if block = start_line_map.fetch(end_line, nil) + Reference.new(block, associated_blocks) + end + end + + def trailing_block!(node) + if ref = trailing_block(node) + unless ref.associated? + ref.associate!.block + end + end + end + + def each_enclosed_block(node) + if block_given? + start_line = node.location.start_line + end_line = node.location.end_line + + if start_line+1 < end_line + ((start_line + 1)...end_line).each do |line| + if block = end_line_map.fetch(line, nil) + unless associated_blocks.include?(block) + associated_blocks << block + yield block + end + end + end + end + else + enum_for :each_enclosed_block, node + end + end + + def each_unassociated_block + if block_given? + blocks.each do |block| + unless associated_blocks.include?(block) + yield block + end + end + else + enum_for :each_unassociated_block + end + end + end + end +end diff --git a/lib/rbs/location_aux.rb b/lib/rbs/location_aux.rb index de0413686..7a5cf7988 100644 --- a/lib/rbs/location_aux.rb +++ b/lib/rbs/location_aux.rb @@ -28,6 +28,14 @@ def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil, buffer: nil, start WithChildren = self + def start_pos + buffer.absolute_position(_start_pos) || raise + end + + def end_pos + buffer.absolute_position(_end_pos) || raise + end + def name buffer.name end @@ -49,11 +57,11 @@ def end_column end def start_loc - @start_loc ||= buffer.pos_to_loc(start_pos) + @start_loc ||= buffer.top_buffer.pos_to_loc(start_pos) end def end_loc - @end_loc ||= buffer.pos_to_loc(end_pos) + @end_loc ||= buffer.top_buffer.pos_to_loc(end_pos) end def range @@ -61,7 +69,7 @@ def range end def source - @source ||= (buffer.content[range] || raise) + @source ||= (buffer.top_buffer.content[range] || raise) end def to_s @@ -134,5 +142,29 @@ def optional_key?(name) def required_key?(name) _required_keys.include?(name) end + + def local_location + loc = Location.new(buffer.detach, _start_pos, _end_pos) + + each_optional_key do |key| + value = self[key] + if value + loc.add_optional_child(key, value._start_pos...value._end_pos) + else + loc.add_optional_child(key, nil) + end + end + + each_required_key do |key| + value = self[key] or raise + loc.add_required_child(key, value._start_pos...value._end_pos) + end + + loc #: self + end + + def local_source + local_location.source + end end end diff --git a/lib/rbs/parser_aux.rb b/lib/rbs/parser_aux.rb index 8b746d39b..cb81cd204 100644 --- a/lib/rbs/parser_aux.rb +++ b/lib/rbs/parser_aux.rb @@ -110,5 +110,15 @@ def self.buffer(source) ).each_with_object({}) do |keyword, hash| #$ Hash[String, bot] hash[keyword] = _ = nil end + + def self.parse_inline_leading_annotation(source, range, variables: []) + buf = buffer(source) + _parse_inline_leading_annotation(buf, range.begin || 0, range.end || buf.last_position, variables) + end + + def self.parse_inline_trailing_annotation(source, range, variables: []) + buf = buffer(source) + _parse_inline_trailing_annotation(buf, range.begin || 0, range.end || buf.last_position, variables) + end end end diff --git a/sig/ast/ruby/annotations.rbs b/sig/ast/ruby/annotations.rbs new file mode 100644 index 000000000..433047f92 --- /dev/null +++ b/sig/ast/ruby/annotations.rbs @@ -0,0 +1,69 @@ +module RBS + module AST + module Ruby + module Annotations + type leading_annotation = ColonMethodTypeAnnotation + | MethodTypesAnnotation + + type trailing_annotation = NodeTypeAssertion + + type t = leading_annotation | trailing_annotation + + class Base + # Location that covers all of the annotation + # + attr_reader location: Location + + # Location of `@rbs`, `@rbs!`, or `:` prefix + # + attr_reader prefix_location: Location + + def initialize: (Location location, Location prefix_location) -> void + + def buffer: () -> Buffer + end + + # `: TYPE` annotation attached to nodes + # + class NodeTypeAssertion < Base + attr_reader type: Types::t + + def initialize: (location: Location, prefix_location: Location, type: Types::t) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + + # `: METHOD-TYPE` annotation in leading comments + # + class ColonMethodTypeAnnotation < Base + attr_reader annotations: Array[AST::Annotation] + + attr_reader method_type: MethodType + + def initialize: (location: Location, prefix_location: Location, annotations: Array[AST::Annotation], method_type: MethodType) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + + # `@rbs METHOD-TYPEs` annotation in leading comments + # + # ``` + # @rbs () -> void | %a{foo} () -> String + # ^^^^ -- prefix_location + # ^ -- vertical_bar_locations[0] + # ``` + class MethodTypesAnnotation < Base + class Overload = AST::Members::MethodDefinition::Overload + + attr_reader overloads: Array[Overload] + + attr_reader vertical_bar_locations: Array[Location] + + def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location]) -> void + + def map_type_name: () { (TypeName) -> TypeName } -> self + end + end + end + end +end diff --git a/sig/ast/ruby/comment_block.rbs b/sig/ast/ruby/comment_block.rbs new file mode 100644 index 000000000..7dd7bde03 --- /dev/null +++ b/sig/ast/ruby/comment_block.rbs @@ -0,0 +1,119 @@ +use Prism::Comment + +module RBS + module AST + module Ruby + # CommentBlock is a collection of comments + # + # ```ruby + # # Comment1 < block1 + # # Comment2 < + # + # # Comment3 < block2 + # ``` + # + # A comment block is a *leading* block or *trailing* block. + # + # ```ruby + # # This is leading block. + # # This is the second line of the leading block. + # + # foo # This is trailing block. + # # This is second line of the trailing block. + # ``` + # + # A leading block is a comment block where all of the comments are at the start of the line content. + # A trailing block is a comment block where the first comment of the block has something at the line before the comment. + # + class CommentBlock + attr_reader name: Pathname + + # Sub buffer of the contents of the comments + # + attr_reader comment_buffer: Buffer + + attr_reader offsets: Array[ + [ + Comment, + Integer, # -- prefix size + ] + ] + + def initialize: (Buffer source_buffer, Array[Comment]) -> void + + # Build comment block instances + def self.build: (Buffer, Array[Comment]) -> Array[instance] + + # Returns true if the comment block is a *leading* comment, which is attached to the successor node + def leading?: () -> bool + + # Returns true if the comment block is a *trailing* comment, which is attached to the predecessor node + def trailing?: () -> bool + + # The line number of the first comment in the block + def start_line: () -> Integer + + # The line number of the last comment in the block + def end_line: () -> Integer + + # The character index of `#comment_buffer` at the start of the lines + # + def line_starts: () -> Array[Integer] + + # Returns the text content of the comment + def text: (Integer index) -> String + + # Yields paragraph and annotation + # + # A paragraph is a sequence of lines that are separated by annotations. + # An annotation starts with a line starting with `@rbs` or `:`, and may continue with lines that has more leading spaces. + # + # ``` + # # Line 1 ^ Paragraph 1 + # # Line 2 | + # # | + # # Line 3 v + # # @rbs ... < Annotation 1 + # # @rbs ... ^ Annotation 2 + # # ... | + # # | + # # ... v + # # ^ Paragraph 2 + # # Line 4 | + # # Line 5 v + # ``` + # + def each_paragraph: (Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + | (Array[Symbol] variables) -> Enumerator[Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError] + + # Returns a trailing annotation if it exists + # + # * Returns `nil` if the block is not a type annotation + # * Returns an annotation if the block has a type annotation + # * Returns AnnotationSyntaxError if the annotation has a syntax error + # + def trailing_annotation: (Array[Symbol] variables) -> (AST::Ruby::Annotations::trailing_annotation | AnnotationSyntaxError | nil) + + class AnnotationSyntaxError + attr_reader location: Location + + attr_reader error: ParsingError + + def initialize: (Location, ParsingError) -> void + end + + private def yield_paragraph: (Integer start_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + + private def yield_annotation: (Integer start_line, Integer end_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void + + private def parse_annotation_lines: (Integer start_line, Integer end_line, Array[Symbol] variables) -> (AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) + + def comments: () -> Array[Comment] + + def line_location: (Integer start_line, Integer end_line) -> Location + + private def leading_annotation?: (Integer index) -> bool + end + end + end +end diff --git a/sig/ast/ruby/members.rbs b/sig/ast/ruby/members.rbs index d737d25f7..cf3cebd68 100644 --- a/sig/ast/ruby/members.rbs +++ b/sig/ast/ruby/members.rbs @@ -12,13 +12,41 @@ module RBS type t = DefMember + class MethodTypeAnnotation + type type_annotations = Annotations::NodeTypeAssertion | Array[Annotations::ColonMethodTypeAnnotation | Annotations::MethodTypesAnnotation] | nil + + attr_reader type_annotations: type_annotations + + def initialize: (type_annotations: type_annotations) -> void + + def map_type_name: { (TypeName) -> TypeName } -> self + + # Returns the method type annotations from the comment block + # + # Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation. + # + def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [ + MethodTypeAnnotation, + Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError], + Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil + ] + + # Returns `true` if it doesn't have any annotation + def empty?: () -> bool + + # Returns the method type overloads + # + def overloads: () -> Array[AST::Members::MethodDefinition::Overload] + end + class DefMember < Base class Overload = AST::Members::MethodDefinition::Overload attr_reader name: Symbol attr_reader node: Prism::DefNode + attr_reader method_type: MethodTypeAnnotation - def initialize: (Buffer, Symbol name, Prism::DefNode node) -> void + def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation) -> void def location: () -> Location diff --git a/sig/buffer.rbs b/sig/buffer.rbs index 9d23ad6aa..31230c39a 100644 --- a/sig/buffer.rbs +++ b/sig/buffer.rbs @@ -11,16 +11,40 @@ module RBS # The content of the buffer. attr_reader content: String - @lines: Array[String] - - @ranges: Array[Range[Integer]] + attr_reader parent: [Buffer, Array[Range[Integer]]]? def initialize: (name: Pathname name, content: String content) -> void + | (content: String content, parent: [Buffer, Array[Range[Integer]]] parent) -> void + # Array of lines of the content, without the EOL + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc") + # buffer.lines # => ["123", "abc"] + # ``` + # + # If the input has EOL at the end of the file, the `lines` has an empty string at the end. + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc\n") + # buffer.lines # => ["123", "abc", ""] + # ``` + # def lines: () -> Array[String] + @ranges: Array[Range[Integer]]? + # Array of ranges that stores the ranges of the each line, without the EOL + # + # ```rb + # buffer = Buffer.new(name: name, content: "123\nabc\n") + # buffer.ranges # => [0...3, 4...7, 8...8] + # ``` + # def ranges: () -> Array[Range[Integer]] + # Returns the number of the lines + def line_count: () -> Integer + # Translate position to location. def pos_to_loc: (Integer pos) -> loc @@ -28,5 +52,39 @@ module RBS def loc_to_pos: (loc loc) -> Integer def last_position: () -> Integer + + # Translate `Prism::Location` to `RBS::Location` attached to this buffer + # + # It assumes the `Prism::Location` has a source which is equivalent to `self`. + # + def rbs_location: (Prism::Location) -> Location + | (Prism::Location, Prism::Location) -> Location + + # Construct a buffer from substrings of this buffer. + # + # The returned buffer contains lines from given ranges. + # + # ```rb + # buffer = Buffer.new(name: name, content: < Buffer with content = 1\n34 + # buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline + # ``` + # + %a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer + + %a{pure} def parent_buffer: () -> Buffer? + + %a{pure} def parent_position: (Integer) -> Integer? + + %a{pure} def absolute_position: (Integer) -> Integer? + + %a{pure} def top_buffer: () -> Buffer + + %a{pure} def detach: () -> Buffer end end diff --git a/sig/environment.rbs b/sig/environment.rbs index 0d7e783aa..ec6f90fac 100644 --- a/sig/environment.rbs +++ b/sig/environment.rbs @@ -216,8 +216,10 @@ module RBS def resolve_ruby_decl: (Resolver::TypeNameResolver, AST::Ruby::Declarations::t, context: Resolver::context, prefix: Namespace) -> AST::Ruby::Declarations::t - def absolute_type: (Resolver::TypeNameResolver, UseMap map, Types::t, context: Resolver::context) -> Types::t + def resolve_ruby_member: (Resolver::TypeNameResolver, AST::Ruby::Members::t, context: Resolver::context) -> AST::Ruby::Members::t - def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName + def absolute_type: (Resolver::TypeNameResolver, UseMap? map, Types::t, context: Resolver::context) -> Types::t + + def absolute_type_name: (Resolver::TypeNameResolver, UseMap? map, TypeName, context: Resolver::context) -> TypeName end end diff --git a/sig/inline_parser.rbs b/sig/inline_parser.rbs index a7d05a14f..9783d41bd 100644 --- a/sig/inline_parser.rbs +++ b/sig/inline_parser.rbs @@ -32,9 +32,16 @@ module RBS class TopLevelMethodDefinition < Base end + class UnusedInlineAnnotation < Base + end + + class AnnotationSyntaxError < Base + end + type t = NotImplementedYet | NonConstantClassName | NonConstantModuleName | TopLevelMethodDefinition + | UnusedInlineAnnotation | AnnotationSyntaxError end def self.parse: (Buffer, Prism::ParseResult) -> Result @@ -46,6 +53,8 @@ module RBS include AST::Ruby::Helpers::LocationHelper + attr_reader comments: CommentAssociation + attr_reader result: Result attr_reader module_nesting: Array[module_context] @@ -63,6 +72,10 @@ module RBS def push_module_nesting: [T] (module_context) { () -> T } -> T def insert_declaration: (module_context) -> void + + def report_unused_annotation: (*AST::Ruby::Annotations::t | nil | AST::Ruby::CommentBlock::AnnotationSyntaxError) -> void + + def report_unused_block: (AST::Ruby::CommentBlock) -> void end end end diff --git a/sig/inline_parser/comment_association.rbs b/sig/inline_parser/comment_association.rbs new file mode 100644 index 000000000..00826469e --- /dev/null +++ b/sig/inline_parser/comment_association.rbs @@ -0,0 +1,71 @@ +use RBS::AST::Ruby::CommentBlock + +module RBS + class InlineParser + # CommentAssociation manages the association between `Prism::Node` and `CommentBlock` + # + class CommentAssociation + attr_reader blocks: Array[CommentBlock] + + attr_reader start_line_map: Hash[Integer, CommentBlock] + + attr_reader end_line_map: Hash[Integer, CommentBlock] + + # CommentBlocks that are already associated to a node, which cannot be associated to another node again + # + attr_reader associated_blocks: Set[CommentBlock] + + def self.build: (Buffer, Prism::Result) -> instance + + def initialize: (Array[CommentBlock]) -> void + + class Reference + attr_reader block: CommentBlock + + @associated_blocks: Set[CommentBlock] + + def initialize: (CommentBlock, Set[CommentBlock]) -> void + + def associate!: () -> self + + def associated?: () -> bool + end + + # Returns an unassociated CommentBlock that can be associated to given node + # + # Automatically updates association status. + # + def leading_block!: (Prism::Node) -> CommentBlock? + + # Returns a Reference that is associated to given node + # + # Updates association explicitly through the reference. + # + def leading_block: (Prism::Node) -> Reference? + + # Returns a CommentBlock that is associated to given node, or by its location + # + # Update association status. + # + def trailing_block!: (Prism::Node | Prism::Location) -> CommentBlock? + + # Returns a Reference that is associated to given node, or by its location + # + # Updates association explicitly through the reference. + # + def trailing_block: (Prism::Node | Prism::Location) -> Reference? + + # Yields leading CommentBlocks that is enclosed in the given node + # + # Note that `enclosed_blocks` works only after all of the *leading* blocks inside the node is associated. + # + # Update association status. + # + def each_enclosed_block: (Prism::Node) { (CommentBlock) -> void } -> void + | (Prism::Node) -> Enumerator[CommentBlock] + + def each_unassociated_block: () { (CommentBlock) -> void } -> void + | () -> Enumerator[CommentBlock] + end + end +end diff --git a/sig/location.rbs b/sig/location.rbs index e6d7fac45..d27bb616b 100644 --- a/sig/location.rbs +++ b/sig/location.rbs @@ -8,10 +8,16 @@ module RBS # The buffer this location points on. attr_reader buffer (): Buffer - # The index of character the range starts from. + # The absolute start index of character the range starts from + # + # It returns the index in the `buffer.top_buffer`. + # attr_reader start_pos (): Integer - # The index of character the range ends at. + # The absolute end index of character the range ends at + # + # It returns the index in the `buffer.top_buffer`. + # attr_reader end_pos (): Integer def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void @@ -24,26 +30,37 @@ module RBS # Returns the name of the buffer. def name: () -> untyped - # Line of the `start_pos` (1 origin) + # The *raw* index of character the range starts from. + attr_reader _start_pos (): Integer + + # The *raw* index of character the range ends at. + attr_reader _end_pos (): Integer + + # Line of the `start_pos` (1 origin, absolute) attr_reader start_line (): Integer - # Column of the `start_pos` (0 origin) + # Column of the `start_pos` (0 origin, absolute) attr_reader start_column (): Integer - # Line of the `end_pos` (1 origin) + # Line of the `end_pos` (1 origin, absolute) attr_reader end_line (): Integer - # Column of the `end_pos` (0 origin) + # Column of the `end_pos` (0 origin, absolute) attr_reader end_column (): Integer + # The absolute line-column pair of the start position + # attr_reader start_loc (): Buffer::loc @start_loc: Buffer::loc? + # The absolute line-column pair of the end position + # attr_reader end_loc (): Buffer::loc @end_loc: Buffer::loc? + # The absolute range of the start and end position attr_reader range (): Range[Integer] @range: Range[Integer]? @@ -97,6 +114,14 @@ module RBS def key?: (Symbol) -> bool + # Returns the location of the buffer, but the buffer is detached from the parent buffer + # + def local_location: () -> self + + # Returns the source of `#local_location` + # + def local_source: () -> String + private def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void diff --git a/sig/parser.rbs b/sig/parser.rbs index da9e94692..c19c09de3 100644 --- a/sig/parser.rbs +++ b/sig/parser.rbs @@ -82,6 +82,18 @@ module RBS KEYWORDS: Hash[String, bot] + # Parse a leading annotation and return it + # + # Raises an exception if the source text contains a syntax error. + # + def self.parse_inline_leading_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::leading_annotation + + # Parse a leading annotation and return it + # + # Raises an exception if the source text contains a syntax error. + # + def self.parse_inline_trailing_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::trailing_annotation + private def self.buffer: (String | Buffer source) -> Buffer @@ -94,6 +106,10 @@ module RBS def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]] + def self._parse_inline_leading_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::leading_annotation + + def self._parse_inline_trailing_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::trailing_annotation + class LocatedValue end end diff --git a/src/constants.c b/src/constants.c index dd1e2ee5c..139201a08 100644 --- a/src/constants.c +++ b/src/constants.c @@ -14,6 +14,8 @@ VALUE RBS_AST; VALUE RBS_AST_Declarations; VALUE RBS_AST_Directives; VALUE RBS_AST_Members; +VALUE RBS_AST_Ruby; +VALUE RBS_AST_Ruby_Annotations; VALUE RBS_Parser; VALUE RBS_Types; VALUE RBS_Types_Bases; @@ -47,6 +49,9 @@ VALUE RBS_AST_Members_MethodDefinition_Overload; VALUE RBS_AST_Members_Prepend; VALUE RBS_AST_Members_Private; VALUE RBS_AST_Members_Public; +VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation; +VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation; +VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion; VALUE RBS_AST_TypeParam; VALUE RBS_MethodType; VALUE RBS_Namespace; @@ -89,6 +94,8 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Declarations, RBS_AST, "Declarations"); IMPORT_CONSTANT(RBS_AST_Directives, RBS_AST, "Directives"); IMPORT_CONSTANT(RBS_AST_Members, RBS_AST, "Members"); + IMPORT_CONSTANT(RBS_AST_Ruby, RBS_AST, "Ruby"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations, RBS_AST_Ruby, "Annotations"); IMPORT_CONSTANT(RBS_Types, RBS, "Types"); IMPORT_CONSTANT(RBS_Types_Bases, RBS_Types, "Bases"); @@ -121,6 +128,9 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Members_Prepend, RBS_AST_Members, "Prepend"); IMPORT_CONSTANT(RBS_AST_Members_Private, RBS_AST_Members, "Private"); IMPORT_CONSTANT(RBS_AST_Members_Public, RBS_AST_Members, "Public"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, RBS_AST_Ruby_Annotations, "ColonMethodTypeAnnotation"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_MethodTypesAnnotation, RBS_AST_Ruby_Annotations, "MethodTypesAnnotation"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_NodeTypeAssertion, RBS_AST_Ruby_Annotations, "NodeTypeAssertion"); IMPORT_CONSTANT(RBS_AST_TypeParam, RBS_AST, "TypeParam"); IMPORT_CONSTANT(RBS_MethodType, RBS, "MethodType"); IMPORT_CONSTANT(RBS_Namespace, RBS, "Namespace"); diff --git a/src/ruby_objs.c b/src/ruby_objs.c index be3e717f8..027b6eb01 100644 --- a/src/ruby_objs.c +++ b/src/ruby_objs.c @@ -439,6 +439,47 @@ VALUE rbs_ast_members_public(VALUE location) { ); } +VALUE rbs_ast_ruby_annotations_colon_method_type_annotation(VALUE location, VALUE prefix_location, VALUE annotations, VALUE method_type) { + VALUE _init_kwargs = rb_hash_new(); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("prefix_location")), prefix_location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("annotations")), annotations); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("method_type")), method_type); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, + 1, + &_init_kwargs + ); +} + +VALUE rbs_ast_ruby_annotations_method_types_annotation(VALUE location, VALUE prefix_location, VALUE overloads, VALUE vertical_bar_locations) { + VALUE _init_kwargs = rb_hash_new(); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("prefix_location")), prefix_location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("overloads")), overloads); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("vertical_bar_locations")), vertical_bar_locations); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_MethodTypesAnnotation, + 1, + &_init_kwargs + ); +} + +VALUE rbs_ast_ruby_annotations_node_type_assertion(VALUE location, VALUE prefix_location, VALUE type) { + VALUE _init_kwargs = rb_hash_new(); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("location")), location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("prefix_location")), prefix_location); + rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("type")), type); + + return CLASS_NEW_INSTANCE( + RBS_AST_Ruby_Annotations_NodeTypeAssertion, + 1, + &_init_kwargs + ); +} + VALUE rbs_ast_type_param(VALUE name, VALUE variance, VALUE upper_bound, VALUE default_type, VALUE unchecked, VALUE location) { VALUE _init_kwargs = rb_hash_new(); rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("name")), name); diff --git a/templates/include/rbs/constants.h.erb b/templates/include/rbs/constants.h.erb index 7be88cdfa..8810c4b5c 100644 --- a/templates/include/rbs/constants.h.erb +++ b/templates/include/rbs/constants.h.erb @@ -7,6 +7,8 @@ extern VALUE RBS_AST; extern VALUE RBS_AST_Declarations; extern VALUE RBS_AST_Directives; extern VALUE RBS_AST_Members; +extern VALUE RBS_AST_Ruby; +extern VALUE RBS_AST_Ruby_Annotations; extern VALUE RBS_Types; extern VALUE RBS_Types_Bases; extern VALUE RBS_ParsingError; diff --git a/templates/src/constants.c.erb b/templates/src/constants.c.erb index 1a6ff9400..186ef0143 100644 --- a/templates/src/constants.c.erb +++ b/templates/src/constants.c.erb @@ -7,6 +7,8 @@ VALUE RBS_AST; VALUE RBS_AST_Declarations; VALUE RBS_AST_Directives; VALUE RBS_AST_Members; +VALUE RBS_AST_Ruby; +VALUE RBS_AST_Ruby_Annotations; VALUE RBS_Parser; VALUE RBS_Types; VALUE RBS_Types_Bases; @@ -27,6 +29,8 @@ void rbs__init_constants(void) { IMPORT_CONSTANT(RBS_AST_Declarations, RBS_AST, "Declarations"); IMPORT_CONSTANT(RBS_AST_Directives, RBS_AST, "Directives"); IMPORT_CONSTANT(RBS_AST_Members, RBS_AST, "Members"); + IMPORT_CONSTANT(RBS_AST_Ruby, RBS_AST, "Ruby"); + IMPORT_CONSTANT(RBS_AST_Ruby_Annotations, RBS_AST_Ruby, "Annotations"); IMPORT_CONSTANT(RBS_Types, RBS, "Types"); IMPORT_CONSTANT(RBS_Types_Bases, RBS_Types, "Bases"); diff --git a/test/rbs/ast/ruby/comment_block_test.rb b/test/rbs/ast/ruby/comment_block_test.rb new file mode 100644 index 000000000..2072de1b0 --- /dev/null +++ b/test/rbs/ast/ruby/comment_block_test.rb @@ -0,0 +1,204 @@ +require "test_helper" + +class RBS::AST::Ruby::CommentBlockTest < Test::Unit::TestCase + include TestHelper + + include RBS::AST::Ruby + + def parse_comments(source) + buffer = RBS::Buffer.new(name: Pathname("a.rb"), content: source) + [buffer, Prism.parse_comments(source)] + end + + def test__buffer__single_line + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!", block.comment_buffer.content + assert_equal [[comments[0], 2]], block.offsets + end + + def test__buffer__multi_line_prefix + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + # This is the second line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!\nThis is the second line.", block.comment_buffer.content + assert_equal [[comments[0], 2], [comments[1], 2]], block.offsets + end + + def test__buffer__multi_line_prefix_inconsistent + buffer, comments = parse_comments(<<~RUBY) + # Hello, world! + # This is the second line. + #This is the third line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "Hello, world!\n This is the second line.\nThis is the third line.", block.comment_buffer.content + assert_equal [[comments[0], 2], [comments[1], 2], [comments[2], 1]], block.offsets + end + + def test__buffer__multi_line_prefix_header_line + buffer, comments = parse_comments(<<~RUBY) + #### + # Hello, world! + # This is the second line. + RUBY + + block = CommentBlock.new(buffer, comments) + + assert_equal "###\nHello, world!\nThis is the second line.", block.comment_buffer.content + assert_equal [[comments[0], 1], [comments[1], 2], [comments[2], 2]], block.offsets + end + + def test_build + buffer, comments = parse_comments(<<~RUBY) + # Comment1 + # Comment2 + + # Comment3 + foo() # Comment4 + # Comment5 + + bar() # Comment6 + baz() # Comment7 + RUBY + + blocks = CommentBlock.build(buffer, comments) + + assert_equal 5, blocks.size + + assert_equal <<~COMMENT.chomp, blocks[0].comment_buffer.content + Comment1 + Comment2 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[1].comment_buffer.content + Comment3 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[2].comment_buffer.content + Comment4 + Comment5 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[3].comment_buffer.content + Comment6 + COMMENT + assert_equal <<~COMMENT.chomp, blocks[4].comment_buffer.content + Comment7 + COMMENT + end + + def test_each_paragraph + buffer, comments = parse_comments(<<~RUBY) + # Line 1 + # + # @rbs () -> void + # @rbs () + # -> Array[ + # String + # + # ] + # + # Line 2 + # Line 3 + # + # @rbs () + # + # Line 4 + RUBY + + block = CommentBlock.new(buffer, comments) + + paragraphs = block.each_paragraph([]).to_a + + paragraphs[0].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "Line 1\n", paragraph.local_source + end + paragraphs[1].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::MethodTypesAnnotation, paragraph + assert_equal "@rbs () -> void", paragraph.location.local_source + end + paragraphs[2].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::MethodTypesAnnotation, paragraph + assert_equal "@rbs ()\n -> Array[\n String\n\n ]", paragraph.location.local_source + end + paragraphs[3].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nLine 2\nLine 3\n", paragraph.local_source + end + paragraphs[4].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::CommentBlock::AnnotationSyntaxError, paragraph + assert_equal "@rbs ()", paragraph.location.local_source + end + paragraphs[5].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nLine 4", paragraph.local_source + end + end + + def test_each_paragraph_colon + buffer, comments = parse_comments(<<~RUBY) + # : Foo + # + #: %a{foo} + # () -> Bar + # + # Bar + RUBY + + block = CommentBlock.new(buffer, comments) + + paragraphs = block.each_paragraph([]).to_a + + paragraphs[0].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal ": Foo\n", paragraph.local_source + end + paragraphs[1].tap do |paragraph| + assert_instance_of RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation, paragraph + assert_equal ": %a{foo}\n () -> Bar", paragraph.location.local_source + end + paragraphs[2].tap do |paragraph| + assert_instance_of RBS::Location, paragraph + assert_equal "\nBar", paragraph.local_source + end + end + + def test_trailing_annotation + buffer, comments = parse_comments(<<~RUBY) + foo #: String + + foo #: String[ + + foo # This is some comment + + #: String + RUBY + + blocks = CommentBlock.build(buffer, comments) + + blocks[0].trailing_annotation([]).tap do |annotation| + assert_instance_of RBS::AST::Ruby::Annotations::NodeTypeAssertion, annotation + end + + blocks[1].trailing_annotation([]).tap do |annotation| + assert_instance_of CommentBlock::AnnotationSyntaxError, annotation + end + + blocks[2].trailing_annotation([]).tap do |annotation| + assert_nil annotation + end + + blocks[3].trailing_annotation([]).tap do |annotation| + assert_nil annotation + end + end +end diff --git a/test/rbs/buffer_test.rb b/test/rbs/buffer_test.rb index a3fbc01c6..03bb1baad 100644 --- a/test/rbs/buffer_test.rb +++ b/test/rbs/buffer_test.rb @@ -9,8 +9,8 @@ def test_buffer abc CONTENT - assert_equal ["123\n", "abc\n"], buffer.lines - assert_equal [0...4, 4...8], buffer.ranges + assert_equal ["123", "abc", ""], buffer.lines + assert_equal [0...3, 4...7, 8...8], buffer.ranges assert_equal [1, 0], buffer.pos_to_loc(0) assert_equal [1, 1], buffer.pos_to_loc(1) @@ -41,8 +41,8 @@ def test_buffer def test_buffer_with_no_eol buffer = Buffer.new(name: Pathname("foo.rbs"), content: "123\nabc") - assert_equal ["123\n", "abc"], buffer.lines - assert_equal [0...4, 4...8], buffer.ranges + assert_equal ["123", "abc"], buffer.lines + assert_equal [0...3, 4...7], buffer.ranges assert_equal [1, 0], buffer.pos_to_loc(0) assert_equal [1, 1], buffer.pos_to_loc(1) @@ -67,4 +67,33 @@ def test_buffer_with_no_eol assert_equal 7, buffer.last_position end + + def test_sub_buffer + buffer = Buffer.new(name: Pathname("foo.rbs"), content: <<~CONTENT) + 123 + abc + CONTENT + + buffer.sub_buffer(lines: [1...3, 5...7]).tap do |sub_buffer| + assert_equal <<~CONTENT.chomp, sub_buffer.content + 23 + bc + CONTENT + + assert_equal 1, sub_buffer.parent_position(0) + assert_equal 2, sub_buffer.parent_position(1) + assert_equal 3, sub_buffer.parent_position(2) + assert_equal 5, sub_buffer.parent_position(3) + assert_equal 6, sub_buffer.parent_position(4) + assert_equal 7, sub_buffer.parent_position(5) + + assert_equal [1, 0], sub_buffer.pos_to_loc(0) + assert_equal [1, 1], sub_buffer.pos_to_loc(1) + assert_equal [1, 2], sub_buffer.pos_to_loc(2) + assert_equal [2, 0], sub_buffer.pos_to_loc(3) + assert_equal [2, 1], sub_buffer.pos_to_loc(4) + assert_equal [2, 2], sub_buffer.pos_to_loc(5) + assert_equal [3, 0], sub_buffer.pos_to_loc(6) + end + end end diff --git a/test/rbs/definition_builder_test.rb b/test/rbs/definition_builder_test.rb index 62509636b..9aa9ac20b 100644 --- a/test/rbs/definition_builder_test.rb +++ b/test/rbs/definition_builder_test.rb @@ -3201,7 +3201,7 @@ module A end end - def test_inline_decl__class_def + def test_inline_decl__class_def__untyped SignatureManager.new do |manager| manager.add_ruby_file("inherited.rbs", <<~RUBY) class A @@ -3226,4 +3226,31 @@ def hello(x) = 123 end end end + + def test_inline_decl__class_def__typed + SignatureManager.new do |manager| + manager.add_ruby_file("inherited.rbs", <<~RUBY) + class A + # @rbs (String) -> Integer + def hello(x) = 123 + end + RUBY + + manager.build do |env| + builder = DefinitionBuilder.new(env: env) + + builder.build_instance(type_name("::A")).tap do |definition| + definition.methods[:hello].tap do |method| + assert_equal type_name("::A"), method.defined_in + assert_equal type_name("::A"), method.implemented_in + + assert_equal [parse_method_type("(::String) -> ::Integer")], method.method_types + assert_equal [parse_method_type("(::String) -> ::Integer")], method.defs.map(&:type) + + assert_equal [], method.annotations + end + end + end + end + end end diff --git a/test/rbs/inline_annotation_parsing_test.rb b/test/rbs/inline_annotation_parsing_test.rb new file mode 100644 index 000000000..4a2444f63 --- /dev/null +++ b/test/rbs/inline_annotation_parsing_test.rb @@ -0,0 +1,82 @@ +require "test_helper" + +class RBS::InlineAnnotationParsingTest < Test::Unit::TestCase + include RBS + + include TestHelper + + def test_parse__trailing_assertion + Parser.parse_inline_trailing_annotation(": String", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::NodeTypeAssertion, annot + assert_equal ": String", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "String", annot.type.location.source + end + end + + def test_error__trailing_assertion + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(": String[", 0...) + end + + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(":", 0...) + end + + assert_raises RBS::ParsingError do + Parser.parse_inline_trailing_annotation(": String is a ", 0...) + end + end + + def test_parse__colon_method_type_annotation + Parser.parse_inline_leading_annotation(": (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ColonMethodTypeAnnotation, annot + assert_equal ": (String) -> void", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "(String) -> void", annot.method_type.location.source + assert_empty annot.annotations + end + + Parser.parse_inline_leading_annotation(": %a{a} %a{b} (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::ColonMethodTypeAnnotation, annot + assert_equal ": %a{a} %a{b} (String) -> void", annot.location.source + assert_equal ":", annot.prefix_location.source + assert_equal "(String) -> void", annot.method_type.location.source + assert_equal ["a", "b"], annot.annotations.map(&:string) + end + end + + def test_parse__rbs_method_types_annotation + Parser.parse_inline_leading_annotation("@rbs %a{a} (String) -> void", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::MethodTypesAnnotation, annot + assert_equal "@rbs %a{a} (String) -> void", annot.location.source + assert_equal "@rbs", annot.prefix_location.source + annot.overloads[0].tap do |overload| + assert_equal "(String) -> void", overload.method_type.location.source + assert_equal ["a"], overload.annotations.map(&:string) + end + assert_empty annot.vertical_bar_locations + end + + Parser.parse_inline_leading_annotation("@rbs %a{a} (String) -> void | [T] (T) -> T", 0...).tap do |annot| + assert_instance_of AST::Ruby::Annotations::MethodTypesAnnotation, annot + assert_equal "@rbs %a{a} (String) -> void | [T] (T) -> T", annot.location.source + assert_equal "@rbs", annot.prefix_location.source + annot.overloads[0].tap do |overload| + assert_equal "(String) -> void", overload.method_type.location.source + assert_equal ["a"], overload.annotations.map(&:string) + end + annot.overloads[1].tap do |overload| + assert_equal "[T] (T) -> T", overload.method_type.location.source + assert_equal [], overload.annotations.map(&:string) + end + assert_equal ["|"], annot.vertical_bar_locations.map(&:source) + end + end + + def test_error__unknown_annotation + assert_raises RBS::ParsingError do + Parser.parse_inline_leading_annotation("@rbs super String", 0...) + end + end +end diff --git a/test/rbs/inline_parser_test.rb b/test/rbs/inline_parser_test.rb index 0386f4f7b..444a8e017 100644 --- a/test/rbs/inline_parser_test.rb +++ b/test/rbs/inline_parser_test.rb @@ -139,4 +139,100 @@ def self.foo; end assert_equal "Singleton method definition is not supported yet", diagnostic.message end end + + def test_parse__def_return_type_assertion + result = parse(<<~RUBY) + class Foo + def foo #: void + "" + end + + def bar = "" #: void + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void"], member.overloads.map { _1.method_type.to_s } + end + + decl.members[1].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["(?) -> untyped"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_error__def_return_type_assertion + result = parse(<<~RUBY) + class Foo + def foo #: void[ + "" + end + end + RUBY + + assert_any!(result.diagnostics) do |diagnostic| + assert_instance_of RBS::InlineParser::Diagnostic::AnnotationSyntaxError, diagnostic + assert_equal ": void[", diagnostic.location.source + assert_equal "Syntax error: expected a token `pEOF`", diagnostic.message + end + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["(?) -> untyped"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_parse__def_colon_method_type + result = parse(<<~RUBY) + class Foo + #: () -> void + # + def foo + "" + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void"], member.overloads.map { _1.method_type.to_s } + end + end + end + + def test_parse__def_method_types + result = parse(<<~RUBY) + class Foo + # @rbs () -> void + # | (String) -> bot + def foo(x = nil) + "" + end + end + RUBY + + assert_empty result.diagnostics + + result.declarations[0].tap do |decl| + decl.members[0].tap do |member| + assert_instance_of RBS::AST::Ruby::Members::DefMember, member + assert_instance_of Array, member.annotations + assert_equal ["() -> void", "(String) -> bot"], member.overloads.map { _1.method_type.to_s } + end + end + end end diff --git a/test/rbs/location_test.rb b/test/rbs/location_test.rb index ffcbe2b44..5d8e8e4d2 100644 --- a/test/rbs/location_test.rb +++ b/test/rbs/location_test.rb @@ -89,6 +89,78 @@ def test_location_inspect assert_include loc.inspect, "source=\"class Foo\"" end + def test_sub_buffer_location + buffer = buffer() + # 01 + # bc + buffer = buffer.sub_buffer(lines: [0...2, 5...7]) + + loc = Location.new(buffer, 0, 5) + + # Raw positions + assert_equal 0, loc._start_pos + assert_equal 5, loc._end_pos + + # Absolute positions + assert_equal 0, loc.start_pos + assert_equal 7, loc.end_pos + assert_equal [1, 0], loc.start_loc + assert_equal [2, 3], loc.end_loc + + assert_equal "123\nabc", loc.source + + loc.add_optional_child(:opt, 0...2) + loc[:opt].tap do |loc| + assert_equal 0, loc.start_pos + assert_equal 2, loc.end_pos + assert_equal "12", loc.source + end + + loc.add_required_child(:req, 1...4) + loc[:req].tap do |loc| + assert_equal 1, loc.start_pos + assert_equal 6, loc.end_pos + assert_equal "23\nab", loc.source + end + end + + def test_sub_buffer_local_location + buffer = buffer() + # 01 + # bc + buffer = buffer.sub_buffer(lines: [0...2, 5...7]) + + loc = Location.new(buffer, 0, 5) + loc.add_optional_child(:opt, 0...2) + loc.add_required_child(:req, 1...4) + + loc = loc.local_location + + # Raw positions + assert_equal 0, loc._start_pos + assert_equal 5, loc._end_pos + + # Absolute positions in sub buffer + assert_equal 0, loc.start_pos + assert_equal 5, loc.end_pos + assert_equal [1, 0], loc.start_loc + assert_equal [2, 2], loc.end_loc + + assert_equal "12\nbc", loc.source + + loc[:opt].tap do |loc| + assert_equal 0, loc.start_pos + assert_equal 2, loc.end_pos + assert_equal "12", loc.source + end + + loc[:req].tap do |loc| + assert_equal 1, loc.start_pos + assert_equal 4, loc.end_pos + assert_equal "2\nb", loc.source + end + end + private def buffer(content: nil) diff --git a/test/rbs/parser_test.rb b/test/rbs/parser_test.rb index 5de729450..dd5bc1848 100644 --- a/test/rbs/parser_test.rb +++ b/test/rbs/parser_test.rb @@ -62,7 +62,7 @@ def test_interface_mixin end def test_type_error_for_content - buffer = RBS::Buffer.new(content: 1, name: nil) + buffer = RBS::Buffer.new(content: 1, name: Pathname("a.rbs")) assert_raises TypeError do RBS::Parser.parse_signature(buffer) end diff --git a/test/rbs/signature_parsing_test.rb b/test/rbs/signature_parsing_test.rb index 96e082ca8..193c32726 100644 --- a/test/rbs/signature_parsing_test.rb +++ b/test/rbs/signature_parsing_test.rb @@ -2279,4 +2279,16 @@ def foo: (?) { () -> void } -> void end end end + + def test_inline_keyword__rbs + Parser.parse_signature(<<~RBS) + class Foo + @rbs: untyped + self.@rbs: untyped + + attr_reader rbs (@rbs): untyped + attr_reader self.rbs (@rbs): untyped + end + RBS + end end