MichaelHatherly / CommonMark.jl

A CommonMark-compliant Markdown parser for Julia.
Other
84 stars 11 forks source link

Bug in MathRule? #7

Closed bramtayl closed 4 years ago

bramtayl commented 4 years ago
using CommonMark

parser = Parser()
enable!(parser, MathRule())
parser(
"""
Interpolate using `\\\$`
"""
)

I get

BoundsError: attempt to access String
  at index [23]
checkbounds at basic.jl:194 [inlined]
codeunit at string.jl:89 [inlined]
getindex at string.jl:210 [inlined]
peek at parsers.jl:14 [inlined]
read(::CommonMark.InlineParser, ::Type{Char}) at parsers.jl:20
parse_inline(::CommonMark.InlineParser, ::CommonMark.Node) at inlines.jl:108
parse_inlines(::CommonMark.InlineParser, ::CommonMark.Node) at inlines.jl:121
parse at inlines.jl:129 [inlined]
process_inlines(::Parser, ::CommonMark.Node) at blocks.jl:416
parse(::Parser, ::Base.GenericIOBuffer{Array{UInt8,1}}; kws::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at blocks.jl:446
parse at blocks.jl:427 [inlined]
#_#25 at blocks.jl:451 [inlined]
Parser at blocks.jl:451 [inlined]
#_#24 at blocks.jl:450 [inlined]
(::Parser)(::String) at blocks.jl:450
top-level scope at test.jl:5

I'm not 100% sure this is a bug, but if it's not, maybe there could be a nicer error? This came from one of the JuliaFormatter tests

MichaelHatherly commented 4 years ago

I'm not 100% sure this is a bug, but if it's not, maybe there could be a nicer error?

Anything that throws an error can be thought of as a bug. We should be producing a result regardless of the input, similar to how other markdown parsers generally operate.

This one looks like a overread error, probably due to some missing backtracking when math syntax fails to parse. I'll have a fix shortly.