Skip to content

Commit

Permalink
#57 Treat \r\n new lines as equivalent to \n so the tests work.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdipardo authored and nyamatongwe committed Feb 4, 2022
1 parent 3a45e7b commit 5c86536
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/LexillaHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ <h3>
Released 7 December 2021.
</li>
<li>
Bash: Treat \r\n line ends the same as \n. This makes testing easier.
<a href="https://github.com/ScintillaOrg/lexilla/issues/57">Issue #57</a>.
</li>
<li>
Batch: Recognise "::" comments when second command on line.
<a href="https://sourceforge.net/p/scintilla/bugs/2304/">Bug #2304</a>.
</li>
Expand Down
8 changes: 4 additions & 4 deletions lexers/LexBash.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
sc.SetState(SCE_SH_DEFAULT);
break;
case SCE_SH_COMMENTLINE:
if (sc.atLineEnd && sc.chPrev != '\\') {
if (sc.MatchLineEnd() && sc.chPrev != '\\') {
sc.SetState(SCE_SH_DEFAULT);
}
break;
Expand Down Expand Up @@ -678,13 +678,13 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
if (sc.atLineStart) {
sc.SetState(SCE_SH_HERE_Q);
int prefixws = 0;
while (sc.ch == '\t' && !sc.atLineEnd) { // tabulation prefix
while (sc.ch == '\t' && !sc.MatchLineEnd()) { // tabulation prefix
sc.Forward();
prefixws++;
}
if (prefixws > 0)
sc.SetState(SCE_SH_HERE_Q);
while (!sc.atLineEnd) {
while (!sc.MatchLineEnd()) {
sc.Forward();
}
char s[HERE_DELIM_MAX];
Expand Down Expand Up @@ -794,7 +794,7 @@ void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int
}

// Must check end of HereDoc state 1 before default state is handled
if (HereDoc.State == 1 && sc.atLineEnd) {
if (HereDoc.State == 1 && sc.MatchLineEnd()) {
// Begin of here-doc (the line after the here-doc delimiter):
// Lexically, the here-doc starts from the next line after the >>, but the
// first line of here-doc seem to follow the style of the last EOL sequence
Expand Down
4 changes: 4 additions & 0 deletions test/examples/bash/SciTE.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lexer.*.bsh=bash
fold=1
fold.comment=1
keywords.*.bsh=case cat do done echo else esac exit export fi find for if in set then while
34 changes: 34 additions & 0 deletions test/examples/bash/x.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -e
# -----------------------------------------------------------------------------
# Voluptatem dolore magnam eius quisquam eius dolor labore. Porro dolor amet ut.
# Numquam labore amet modi. Dolorem velit numquam porro est quiquia ipsum quisquam.
# Magnam consectetur est voluptatem aliquam adipisci. Sed dolorem quaerat quiquia.
# -----------------------------------------------------------------------------
export PYTHONPATH="scripts:$PYTHONPATH"

if [[ -z "$1" ]]; then
PROJECT_DIR=$(rlwrap -S "Enter source path: " -e '' -i -o cat)
PROJECT_PATH="$(pwd)/$PROJECT_DIR"
else
PROJECT_PATH="$(pwd)/${1}"
fi

OUT_FILE=${PROJECT_PATH}/testing.txt

(cat<<EOF
Last run $(date +'%Y-%m-%d') at $(date +'%H:%M:%S.%2N')
EOF
) > $OUT_FILE

find "$PROJECT_PATH/src" -maxdepth 1 -type f |\
while read -r f; do
{
python3 -c "print();print('='*50)";\
echo `basename "$f"` | tr -d 'x';\
python3 -c "print('='*50)";\
python3 "$f";\
} >> $OUT_FILE
done

INVALID_NUMBER=0#0000
35 changes: 35 additions & 0 deletions test/examples/bash/x.bsh.folded
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
0 400 0 #!/usr/bin/env bash
0 400 0 set -e
2 400 0 + # -----------------------------------------------------------------------------
0 401 0 | # Voluptatem dolore magnam eius quisquam eius dolor labore. Porro dolor amet ut.
0 401 0 | # Numquam labore amet modi. Dolorem velit numquam porro est quiquia ipsum quisquam.
0 401 0 | # Magnam consectetur est voluptatem aliquam adipisci. Sed dolorem quaerat quiquia.
0 401 0 | # -----------------------------------------------------------------------------
0 400 0 export PYTHONPATH="scripts:$PYTHONPATH"
1 400 0
2 400 0 + if [[ -z "$1" ]]; then
0 401 0 | PROJECT_DIR=$(rlwrap -S "Enter source path: " -e '' -i -o cat)
0 401 0 | PROJECT_PATH="$(pwd)/$PROJECT_DIR"
0 401 0 | else
0 401 0 | PROJECT_PATH="$(pwd)/${1}"
0 401 0 | fi
1 400 0
0 400 0 OUT_FILE=${PROJECT_PATH}/testing.txt
1 400 0
2 400 0 + (cat<<EOF
0 401 0 | Last run $(date +'%Y-%m-%d') at $(date +'%H:%M:%S.%2N')
0 401 0 | EOF
0 400 0 ) > $OUT_FILE
1 400 0
0 400 0 find "$PROJECT_PATH/src" -maxdepth 1 -type f |\
2 400 0 + while read -r f; do
2 401 0 + {
0 402 0 | python3 -c "print();print('='*50)";\
0 402 0 | echo `basename "$f"` | tr -d 'x';\
0 402 0 | python3 -c "print('='*50)";\
0 402 0 | python3 "$f";\
0 402 0 | } >> $OUT_FILE
0 401 0 | done
1 400 0
0 400 0 INVALID_NUMBER=0#0000
0 400 0
34 changes: 34 additions & 0 deletions test/examples/bash/x.bsh.styled
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{2}#!/usr/bin/env bash{0}
{4}set{0} {8}-e{0}
{2}# -----------------------------------------------------------------------------{0}
{2}# Voluptatem dolore magnam eius quisquam eius dolor labore. Porro dolor amet ut.{0}
{2}# Numquam labore amet modi. Dolorem velit numquam porro est quiquia ipsum quisquam.{0}
{2}# Magnam consectetur est voluptatem aliquam adipisci. Sed dolorem quaerat quiquia.{0}
{2}# -----------------------------------------------------------------------------{0}
{4}export{0} {8}PYTHONPATH{7}={5}"scripts:$PYTHONPATH"{0}

{4}if{0} {7}[[{0} {4}-z{0} {5}"$1"{0} {7}]];{0} {4}then{0}
{8}PROJECT_DIR{7}={11}$(rlwrap -S "Enter source path: " -e '' -i -o cat){0}
{8}PROJECT_PATH{7}={5}"$(pwd)/$PROJECT_DIR"{0}
{4}else{0}
{8}PROJECT_PATH{7}={5}"$(pwd)/${1}"{0}
{4}fi{0}

{8}OUT_FILE{7}={10}${PROJECT_PATH}{7}/{8}testing.txt{0}

{7}({8}cat{12}<<EOF{13}
Last run $(date +'%Y-%m-%d') at $(date +'%H:%M:%S.%2N')
EOF{0}
{7}){0} {7}>{0} {9}$OUT_FILE{0}

{4}find{0} {5}"$PROJECT_PATH/src"{0} {7}-{8}maxdepth{0} {3}1{0} {7}-{8}type{0} {8}f{0} {7}|\{0}
{4}while{0} {8}read{0} {8}-r{0} {8}f{7};{0} {4}do{0}
{7}{{0}
{8}python3{0} {8}-c{0} {5}"print();print('='*50)"{7};\{0}
{4}echo{0} {11}`basename "$f"`{0} {7}|{0} {8}tr{0} {8}-d{0} {6}'x'{7};\{0}
{8}python3{0} {8}-c{0} {5}"print('='*50)"{7};\{0}
{8}python3{0} {5}"$f"{7};\{0}
{7}}{0} {7}>>{0} {9}$OUT_FILE{0}
{4}done{0}

{8}INVALID_NUMBER{7}={1}0#0000{0}

0 comments on commit 5c86536

Please sign in to comment.