authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-22 21:43:44+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-22 21:52:22+02:00
log4758e0c9a662b59e071b52fbcc931fae138292d7
tree213b5c63302f77c46356b5913a138c6a19131934
parentd83698ab54947c79c90d54c27e5a6d52c12fc52f
signaturelock-open Commit is signed but in an unrecognized format.

update docgen to use new ast


1 files changed, 134 insertions(+), 121 deletions(-)

doc/docgen.zig+134-121
...@@ -781,106 +781,119 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:...@@ -781,106 +781,119 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
781 next_tok_is_fn = false;781 next_tok_is_fn = false;
782782
783 const token = tokenizer.next();783 const token = tokenizer.next();
784 if (mem.indexOf(u8, src[index..token.loc.start], "//")) |comment_start_off| {
785 // render one comment
786 const comment_start = index + comment_start_off;
787 const comment_end_off = mem.indexOf(u8, src[comment_start .. token.loc.start], "\n");
788 const comment_end = if (comment_end_off) |o| comment_start + o else token.loc.start;
789
790 try writeEscaped(out, src[index..comment_start]);
791 try out.writeAll("<span class=\"tok-comment\">");
792 try writeEscaped(out, src[comment_start .. comment_end]);
793 try out.writeAll("</span>");
794 index = comment_end;
795 tokenizer.index = index;
796 continue;
797 }
798
784 try writeEscaped(out, src[index..token.loc.start]);799 try writeEscaped(out, src[index..token.loc.start]);
785 switch (token.id) {800 switch (token.tag) {
786 .Eof => break,801 .eof => break,
787802
788 .Keyword_align,803 .keyword_align,
789 .Keyword_and,804 .keyword_and,
790 .Keyword_asm,805 .keyword_asm,
791 .Keyword_async,806 .keyword_async,
792 .Keyword_await,807 .keyword_await,
793 .Keyword_break,808 .keyword_break,
794 .Keyword_catch,809 .keyword_catch,
795 .Keyword_comptime,810 .keyword_comptime,
796 .Keyword_const,811 .keyword_const,
797 .Keyword_continue,812 .keyword_continue,
798 .Keyword_defer,813 .keyword_defer,
799 .Keyword_else,814 .keyword_else,
800 .Keyword_enum,815 .keyword_enum,
801 .Keyword_errdefer,816 .keyword_errdefer,
802 .Keyword_error,817 .keyword_error,
803 .Keyword_export,818 .keyword_export,
804 .Keyword_extern,819 .keyword_extern,
805 .Keyword_for,820 .keyword_for,
806 .Keyword_if,821 .keyword_if,
807 .Keyword_inline,822 .keyword_inline,
808 .Keyword_noalias,823 .keyword_noalias,
809 .Keyword_noinline,824 .keyword_noinline,
810 .Keyword_nosuspend,825 .keyword_nosuspend,
811 .Keyword_opaque,826 .keyword_opaque,
812 .Keyword_or,827 .keyword_or,
813 .Keyword_orelse,828 .keyword_orelse,
814 .Keyword_packed,829 .keyword_packed,
815 .Keyword_anyframe,830 .keyword_anyframe,
816 .Keyword_pub,831 .keyword_pub,
817 .Keyword_resume,832 .keyword_resume,
818 .Keyword_return,833 .keyword_return,
819 .Keyword_linksection,834 .keyword_linksection,
820 .Keyword_callconv,835 .keyword_callconv,
821 .Keyword_struct,836 .keyword_struct,
822 .Keyword_suspend,837 .keyword_suspend,
823 .Keyword_switch,838 .keyword_switch,
824 .Keyword_test,839 .keyword_test,
825 .Keyword_threadlocal,840 .keyword_threadlocal,
826 .Keyword_try,841 .keyword_try,
827 .Keyword_union,842 .keyword_union,
828 .Keyword_unreachable,843 .keyword_unreachable,
829 .Keyword_usingnamespace,844 .keyword_usingnamespace,
830 .Keyword_var,845 .keyword_var,
831 .Keyword_volatile,846 .keyword_volatile,
832 .Keyword_allowzero,847 .keyword_allowzero,
833 .Keyword_while,848 .keyword_while,
834 .Keyword_anytype,849 .keyword_anytype,
835 => {850 => {
836 try out.writeAll("<span class=\"tok-kw\">");851 try out.writeAll("<span class=\"tok-kw\">");
837 try writeEscaped(out, src[token.loc.start..token.loc.end]);852 try writeEscaped(out, src[token.loc.start..token.loc.end]);
838 try out.writeAll("</span>");853 try out.writeAll("</span>");
839 },854 },
840855
841 .Keyword_fn => {856 .keyword_fn => {
842 try out.writeAll("<span class=\"tok-kw\">");857 try out.writeAll("<span class=\"tok-kw\">");
843 try writeEscaped(out, src[token.loc.start..token.loc.end]);858 try writeEscaped(out, src[token.loc.start..token.loc.end]);
844 try out.writeAll("</span>");859 try out.writeAll("</span>");
845 next_tok_is_fn = true;860 next_tok_is_fn = true;
846 },861 },
847862
848 .Keyword_undefined,863 .keyword_undefined,
849 .Keyword_null,864 .keyword_null,
850 .Keyword_true,865 .keyword_true,
851 .Keyword_false,866 .keyword_false,
852 => {867 => {
853 try out.writeAll("<span class=\"tok-null\">");868 try out.writeAll("<span class=\"tok-null\">");
854 try writeEscaped(out, src[token.loc.start..token.loc.end]);869 try writeEscaped(out, src[token.loc.start..token.loc.end]);
855 try out.writeAll("</span>");870 try out.writeAll("</span>");
856 },871 },
857872
858 .StringLiteral,873 .string_literal,
859 .MultilineStringLiteralLine,874 .multiline_string_literal_line,
860 .CharLiteral,875 .char_literal,
861 => {876 => {
862 try out.writeAll("<span class=\"tok-str\">");877 try out.writeAll("<span class=\"tok-str\">");
863 try writeEscaped(out, src[token.loc.start..token.loc.end]);878 try writeEscaped(out, src[token.loc.start..token.loc.end]);
864 try out.writeAll("</span>");879 try out.writeAll("</span>");
865 },880 },
866881
867 .Builtin => {882 .builtin => {
868 try out.writeAll("<span class=\"tok-builtin\">");883 try out.writeAll("<span class=\"tok-builtin\">");
869 try writeEscaped(out, src[token.loc.start..token.loc.end]);884 try writeEscaped(out, src[token.loc.start..token.loc.end]);
870 try out.writeAll("</span>");885 try out.writeAll("</span>");
871 },886 },
872887
873 .LineComment,888 .doc_comment,
874 .DocComment,889 .container_doc_comment,
875 .ContainerDocComment,
876 .ShebangLine,
877 => {890 => {
878 try out.writeAll("<span class=\"tok-comment\">");891 try out.writeAll("<span class=\"tok-comment\">");
879 try writeEscaped(out, src[token.loc.start..token.loc.end]);892 try writeEscaped(out, src[token.loc.start..token.loc.end]);
880 try out.writeAll("</span>");893 try out.writeAll("</span>");
881 },894 },
882895
883 .Identifier => {896 .identifier => {
884 if (prev_tok_was_fn) {897 if (prev_tok_was_fn) {
885 try out.writeAll("<span class=\"tok-fn\">");898 try out.writeAll("<span class=\"tok-fn\">");
886 try writeEscaped(out, src[token.loc.start..token.loc.end]);899 try writeEscaped(out, src[token.loc.start..token.loc.end]);
...@@ -908,71 +921,71 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:...@@ -908,71 +921,71 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
908 }921 }
909 },922 },
910923
911 .IntegerLiteral,924 .integer_literal,
912 .FloatLiteral,925 .float_literal,
913 => {926 => {
914 try out.writeAll("<span class=\"tok-number\">");927 try out.writeAll("<span class=\"tok-number\">");
915 try writeEscaped(out, src[token.loc.start..token.loc.end]);928 try writeEscaped(out, src[token.loc.start..token.loc.end]);
916 try out.writeAll("</span>");929 try out.writeAll("</span>");
917 },930 },
918931
919 .Bang,932 .bang,
920 .Pipe,933 .pipe,
921 .PipePipe,934 .pipe_pipe,
922 .PipeEqual,935 .pipe_equal,
923 .Equal,936 .equal,
924 .EqualEqual,937 .equal_equal,
925 .EqualAngleBracketRight,938 .equal_angle_bracket_right,
926 .BangEqual,939 .bang_equal,
927 .LParen,940 .l_paren,
928 .RParen,941 .r_paren,
929 .Semicolon,942 .semicolon,
930 .Percent,943 .percent,
931 .PercentEqual,944 .percent_equal,
932 .LBrace,945 .l_brace,
933 .RBrace,946 .r_brace,
934 .LBracket,947 .l_bracket,
935 .RBracket,948 .r_bracket,
936 .Period,949 .period,
937 .PeriodAsterisk,950 .period_asterisk,
938 .Ellipsis2,951 .ellipsis2,
939 .Ellipsis3,952 .ellipsis3,
940 .Caret,953 .caret,
941 .CaretEqual,954 .caret_equal,
942 .Plus,955 .plus,
943 .PlusPlus,956 .plus_plus,
944 .PlusEqual,957 .plus_equal,
945 .PlusPercent,958 .plus_percent,
946 .PlusPercentEqual,959 .plus_percent_equal,
947 .Minus,960 .minus,
948 .MinusEqual,961 .minus_equal,
949 .MinusPercent,962 .minus_percent,
950 .MinusPercentEqual,963 .minus_percent_equal,
951 .Asterisk,964 .asterisk,
952 .AsteriskEqual,965 .asterisk_equal,
953 .AsteriskAsterisk,966 .asterisk_asterisk,
954 .AsteriskPercent,967 .asterisk_percent,
955 .AsteriskPercentEqual,968 .asterisk_percent_equal,
956 .Arrow,969 .arrow,
957 .Colon,970 .colon,
958 .Slash,971 .slash,
959 .SlashEqual,972 .slash_equal,
960 .Comma,973 .comma,
961 .Ampersand,974 .ampersand,
962 .AmpersandEqual,975 .ampersand_equal,
963 .QuestionMark,976 .question_mark,
964 .AngleBracketLeft,977 .angle_bracket_left,
965 .AngleBracketLeftEqual,978 .angle_bracket_left_equal,
966 .AngleBracketAngleBracketLeft,979 .angle_bracket_angle_bracket_left,
967 .AngleBracketAngleBracketLeftEqual,980 .angle_bracket_angle_bracket_left_equal,
968 .AngleBracketRight,981 .angle_bracket_right,
969 .AngleBracketRightEqual,982 .angle_bracket_right_equal,
970 .AngleBracketAngleBracketRight,983 .angle_bracket_angle_bracket_right,
971 .AngleBracketAngleBracketRightEqual,984 .angle_bracket_angle_bracket_right_equal,
972 .Tilde,985 .tilde,
973 => try writeEscaped(out, src[token.loc.start..token.loc.end]),986 => try writeEscaped(out, src[token.loc.start..token.loc.end]),
974987
975 .Invalid, .Invalid_ampersands, .Invalid_periodasterisks => return parseError(988 .invalid, .invalid_ampersands, .invalid_periodasterisks => return parseError(
976 docgen_tokenizer,989 docgen_tokenizer,
977 source_token,990 source_token,
978 "syntax error",991 "syntax error",