Skip to content

Commit

Permalink
Merge pull request #2629 from masatake/tcl-var-recognition
Browse files Browse the repository at this point in the history
Tcl: strict the way to recognize variable expansions
  • Loading branch information
masatake authored Aug 29, 2020
2 parents b763385 + 964a762 commit 36a6dd1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Units/parser-tcl.r/dollar-in-regex.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proc1 input.tcl /^proc proc1 {} {$/;" p
proc2 input.tcl /^proc proc2 {} {}$/;" p
proc3 input.tcl /^proc proc3 {} {$/;" p
proc4 input.tcl /^proc proc4 {} {}$/;" p
17 changes: 17 additions & 0 deletions Units/parser-tcl.r/dollar-in-regex.d/input.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Taken from #2627 submitted by @surmish
proc proc1 {} {
if {[regexp {[0-9]$} ""]} {
echo "matched"
}
}

proc proc2 {} {}

proc proc3 {} {
set abc "hello"
puts ${abc}
}

proc proc4 {} {}

proc3
2 changes: 2 additions & 0 deletions Units/parser-tcl.r/escaping.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc1 input.tcl /^proc proc1 {} {$/;" p
proc2 input.tcl /^proc proc2 {} {}$/;" p
6 changes: 6 additions & 0 deletions Units/parser-tcl.r/escaping.d/input.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Taken from a comment in #2627 submitted by @surmish.
proc proc1 {} {
expr {[string first "\\" $varName]==0}
}

proc proc2 {} {}
19 changes: 14 additions & 5 deletions parsers/tcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ static void readString (vString *string)
case EOF:
return;
case '\\':
vStringPut (string, c);
escaped = true;
if (escaped)
{
vStringPut (string, c);
escaped = false;
}
else
escaped = true;
break;
case '"':
vStringPut (string, c);
Expand Down Expand Up @@ -283,19 +288,23 @@ static void readToken0 (tokenInfo *const token, struct sTclParserState *pstate)
if (c0 == EOF)
break;

tokenPutc (token, c0);
if (c0 == '{')
{

tokenPutc (token, c0);
while ((c0 = getcFromInputFile ()) != EOF)
{
tokenPutc (token, c0);
if (c0 == '}')
break;
}
}
else
else if (isalnum (c0))
{
tokenPutc (token, c0);
readIdentifier (token->string);
}
else
ungetcToInputFile (c0);
break;
}
default:
Expand Down

0 comments on commit 36a6dd1

Please sign in to comment.