Skip to content

LexVisualProlog: language updates; simplification & bug fix#178

Closed
tholp wants to merge 0 commit intoScintillaOrg:masterfrom
tholp:master
Closed

LexVisualProlog: language updates; simplification & bug fix#178
tholp wants to merge 0 commit intoScintillaOrg:masterfrom
tholp:master

Conversation

@tholp
Copy link
Copy Markdown

@tholp tholp commented Jun 15, 2023

This adds lexer support for embedded syntax in Visual Prolog. It also simplifies the number of states involved in the styling. And finally it deals with some bugs related to line-by-line styling and handling of line separations.

It respects the possibility to use it for other ISO/swi Prolog.

@nyamatongwe nyamatongwe added the prolog Caused by the visual prolog lexer label Jun 15, 2023
@nyamatongwe
Copy link
Copy Markdown
Member

I expect the most noticeable change from this PR is that string contents and the quotes around strings are now separate lexical classes with potentially different appearance.

This PR undoes 94cf367 for After which is an unused struct.

There are other data type (lineState), function (getLexicalClass), and variable(lexicalClasses) definitions in this that are globally visible which can cause name clashes and multiple definition errors. For functions and variables, static can be used to prevent visibility to other modules but that doesn't work for class definitions. An unnamed namespace can be wrapped around all the definitions in the file except for lmVisualProlog to hide them from other modules. There is no need for static inside the unnamed namespace.

using namespace Lexilla;

namespace {
...
}

LexerModule lmVisualProlog(SCLEX_VISUALPROLOG, LexerVisualProlog::LexerFactoryVisualProlog, "visualprolog", visualPrologWordLists);

g++ and clang++ dislike getState:

clang++ -D_CRT_SECURE_NO_DEPRECATE=1 -DNDEBUG -I ../include -I ../../scintilla/include -I ../src -I ../lexlib --std=c++17 -O3 -Wpedantic -Wall -Wextra   -c ../lexers/LexVisualProlog.cxx -o LexVisualProlog.o
../lexers/LexVisualProlog.cxx:320:64: warning: '&' within '|' [-Wbitwise-op-parentheses]
        return verbatim << 31 | closingQuote << 16 | kindStack & 0xFFFF;
                                                   ~ ~~~~~~~~~~^~~~~~~~
../lexers/LexVisualProlog.cxx:320:64: note: place parentheses around the '&' expression to silence this warning
        return verbatim << 31 | closingQuote << 16 | kindStack & 0xFFFF;
                                                               ^
                                                     (                 )
1 warning generated.

@tholp
Copy link
Copy Markdown
Author

tholp commented Jun 16, 2023

Yes, that is the most "visible" change (I forgot to mention it).
I have mapped old and new states to give the best possible styling in e.g. Notepad++ (though I don't think they have moved to this version yet).

String and verbatim strings have same style now (what used to be the verbatim style) and the quotes have the old string style.

I have updated the code according to your comments.

(Putting it inside an anonymous namespace made Visual Studio reformat a number of things).

@nyamatongwe
Copy link
Copy Markdown
Member

Putting it inside an anonymous namespace made Visual Studio reformat a number of things

Visual Studio puts these in a separate undo transaction and if you press Undo immediately after, just the formatting reverts. The changes show you have Visual Studio formatting options (Options | Text Editor | C/C++ | Code Style | Formatting) different from how you have previously formatted this code. I'll probably split out an initial formatting commit so the main commit is mostly behavioural changes.

@tholp
Copy link
Copy Markdown
Author

tholp commented Jun 18, 2023

I assume/guess that will mean creating another PR. And then rebasing this one on top of that?

@nyamatongwe
Copy link
Copy Markdown
Member

I assume/guess that will mean creating another PR. And then rebasing this one on top of that?

I've not had much success with fixing things up inside the GitHub PR process. I have a copy of your end state and I'll use WinMerge to compare to a reformat (either with Visual Studio or astyle), commit that; then move other differences into a second commit. I want to make it easy to see the real differences and ignore the formatting differences.

nyamatongwe added a commit that referenced this pull request Jun 19, 2023
Default + left align pointers, space around binary operators, indented case.
No semantic changes.
nyamatongwe pushed a commit that referenced this pull request Jun 19, 2023
and SCE_VISUALPROLOG_PLACEHOLDER.
Styling of string literals changed with no differentiation between literals with quotes and those
that are prefixed with "@".
Quote characters are in a separate style (SCE_VISUALPROLOG_STRING_QUOTE)
to contents (SCE_VISUALPROLOG_STRING).
SCE_VISUALPROLOG_CHARACTER, SCE_VISUALPROLOG_CHARACTER_TOO_MANY,
SCE_VISUALPROLOG_CHARACTER_ESCAPE_ERROR, SCE_VISUALPROLOG_STRING_EOL_OPEN,
and SCE_VISUALPROLOG_STRING_VERBATIM_SPECIAL were removed (replaced with
SCE_VISUALPROLOG_UNUSED[1-5]).
@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Jun 19, 2023
@nyamatongwe
Copy link
Copy Markdown
Member

Is there documentation that can be linked for embedded and placeholder? I couldn't find anything in the VisualProlog Language Reference.

@tholp tholp closed this Jun 19, 2023
@tholp
Copy link
Copy Markdown
Author

tholp commented Jun 19, 2023

No, (currently) embedded syntax + placeholders is an undocumented feature.

Unfortunately, it turned-out that placeholders always need "manual" qualification to resolve ambiguities, and that is quite cumbersome to deal with. So even though we use it ourselves, I am not sure if other people will start using it (which is of course self-fulfilling until I write some documentation (but even then)).

@nyamatongwe nyamatongwe removed the committed Issue fixed in repository but not in release label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prolog Caused by the visual prolog lexer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants