Giter Site home page Giter Site logo

Comments (2)

nyamatongwe avatar nyamatongwe commented on July 17, 2024

SetLineState in Scintilla allows setting lines past the end to make it simpler to implement lexers. TestLexers is a bit stricter to help uncover problems but its probably reasonable to allow writing just one past the maximum line. Possibly

@@ -196,6 +196,9 @@ int SCI_METHOD TestDocument::GetLineState(Sci_Position line) const {
 }
 
 int SCI_METHOD TestDocument::SetLineState(Sci_Position line, int state) {
+	if (line == static_cast<Sci_Position>(lineLevels.size())) {
+		return 0;
+	}
 	return lineStates.at(line) = state;
 }

or

@@ -123,7 +123,7 @@ void TestDocument::Set(std::string_view sv) {
 	if (lineStarts.back() != Length()) {
 		lineStarts.push_back(Length());
 	}
-	lineStates.resize(lineStarts.size());
+	lineStates.resize(lineStarts.size() + 1);
 	lineLevels.resize(lineStarts.size(), 0x400);
 }

from lexilla.

rdipardo avatar rdipardo commented on July 17, 2024

Amending the TestDocument module does the trick.

After applying the second option (since they're equivalent and single exit points are ideal), we're left with the following:

Lexing verilog/AllStyles.vh
~/lexilla/test/examples/verilog/AllStyles.vh:66: different styles between \r and \n at 870: 11, 0
~/lexilla/test/examples/verilog/AllStyles.vh:67: different styles between \r and \n at 879: 11, 0
~/lexilla/test/examples/verilog/AllStyles.vh:68: different styles between \r and \n at 888: 11, 0
~/lexilla/test/examples/verilog/AllStyles.vh:69: different styles between \r and \n at 896: 11, 0
~/lexilla/test/examples/verilog/AllStyles.vh:70: different styles between \r and \n at 905: 11, 0

~/lexilla/test/examples/verilog/AllStyles.vh:1: has different styles with \n versus \r\n line ends

Modernizing all cases of StyleContext::atLineEnd to ::MatchLineEnd() resolves most of these, leaving a single issue of unclean style switching in the middle of DOS EOLs in the case of SCE_V_STRINGEOL. Because StyleContext::ForwardSetState() will only advance the width of a single character, a conditional call to ::Forward() is needed to span the entire CRLF:

} else if (sc.atLineEnd) {
sc.ChangeState(SCE_V_STRINGEOL|activitySet);
sc.ForwardSetState(SCE_V_DEFAULT|activitySet);

The diagnostic is not very revealing:

Lexing verilog/AllStyles.vh
~/lexilla/test/examples/verilog/AllStyles.vh:73: different styles between \r and \n at 937: 12, 0

~/lexilla/test/examples/verilog/AllStyles.vh:1: has different styles with \n versus \r\n line ends

This was one case where visual inspection was more productive. In LF mode, SCE_V_STRINGEOL would fill the line; in CRLF mode, it was trimmed to the length of the string + 1 for the severed CR.

0002-LexerVerilog-Don-t-split-CRLFs-when-terminating-string-EOL-state.patch.txt

from lexilla.

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.