Giter Site home page Giter Site logo

Parsing error? about cstparser.jl HOT 7 CLOSED

ChrisRackauckas avatar ChrisRackauckas commented on July 30, 2024
Parsing error?

from cstparser.jl.

Comments (7)

pfitzseb avatar pfitzseb commented on July 30, 2024 1

FEFF is the big-endian UTF-16 BOM. Seems reasonable to only support UTF-8 encoded files to me.

from cstparser.jl.

ChrisRackauckas avatar ChrisRackauckas commented on July 30, 2024

Same thing seems to show up many places.

https://github.com/SciML/OrdinaryDiffEq.jl/runs/5853304680?check_suite_focus=true#step:4:104
https://github.com/SciML/OrdinaryDiffEq.jl/blob/v6.8.0/src/OrdinaryDiffEq.jl#L303

etc.

from cstparser.jl.

simeonschaub avatar simeonschaub commented on July 30, 2024

The culprit here seems to be a format character at the start of the file, which Julia's parser just ignores:

julia> CSTParser.parse("\ufeffusing Test")
  1:13  errortoken
  1:3    errortoken( CSTParser.UnexpectedToken)
  1:3     errortoken( CSTParser.Unknown)
  4:13   using
  4:7       1:0   OP: .
  4:7      Test

julia> Meta.parse("\ufeffusing Test")
:(using Test)

from cstparser.jl.

pfitzseb avatar pfitzseb commented on July 30, 2024

Nvm, this actually is UTF-8 with BOM:

julia> first(codeunits(read("src/OrdinaryDiffEq.jl", String)), 6)
6-element Vector{UInt8}:
 0xef
 0xbb
 0xbf
 0x22
 0x22
 0x22

It's somewhat arguable that we should support that.

from cstparser.jl.

StefanKarpinski avatar StefanKarpinski commented on July 30, 2024

Julia itself just treats U+FEFF as a space:

julia> Meta.parse("[1\ufeff2]")
:([1 2])

That's a simple approach that allows it as a BOM as well since parsing doesn't care about space at the beginning of a file.

from cstparser.jl.

pfitzseb avatar pfitzseb commented on July 30, 2024

JuliaLang/Tokenize.jl#197 does that.
One potential issue with that approach is that JuliaFormatter is likely to remove the unnecessary leading space, which some Microsoft tools apparently don't like.

from cstparser.jl.

StefanKarpinski avatar StefanKarpinski commented on July 30, 2024

Maybe it would make sense to treat a leading BOM as a special token that JuliaFormatter knows to retain. Or the logic could be changed from deleting leading whitespace to trimming leading whitespace to just the BOM if there is a BOM.

from cstparser.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.