Skip to content

Commit

Permalink
Merge pull request #4170 from masatake/optsctipt--fix-scopedepth-op
Browse files Browse the repository at this point in the history
optscropt: fix _scopedepth operator
  • Loading branch information
masatake authored Jan 6, 2025
2 parents e31feb0 + ee4ed04 commit 4cf6106
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 2 deletions.
1 change: 1 addition & 0 deletions Tmain/optscript-scope.d/exit-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Tmain/optscript-scope.d/input.unknown
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* TITLE 0
+ Subtitle 0.0
+ Subtitle 0.1
- subsubtitle 0.1.0
- subsubtitle 0.1.1
+ Subtitle 0.2
- subsubtitle 0.2.0
* TITLE 1
+ Subtitle 1.0
- subsubtitle 1.0.0
- subsubtitle 1.0.1
12 changes: 12 additions & 0 deletions Tmain/optscript-scope.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright: 2024 Masatake YAMATO
# License: GPL-2

CTAGS=$1

. ../utils.sh

${CTAGS} --quiet --options=NONE \
--sort=no --fields=+n \
--options=./unknown.ctags \
--language-force=UnknownX \
-o - input.unknown
56 changes: 56 additions & 0 deletions Tmain/optscript-scope.d/stderr-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
section-enter
0
scopetop: OK
scopeNth0: OK
section-leave
1
subsection-enter
1
scopeNth1: OK
subsection-leave
2
subsection-enter
2
scopetop: OK
scopeNth0: OK
scopeNth1: OK
subsection-leave
2
subsubsection-enter
2
subsubsection-leave
3
subsubsection-enter
3
subsubsection-leave
3
subsection-enter
3
scopetop: OK
scopeNth0: OK
scopeNth1: OK
subsection-leave
2
subsubsection-enter
2
subsubsection-leave
3
section-enter
3
scopetop: OK
scopeNth0: OK
section-leave
1
subsection-enter
1
scopeNth1: OK
subsection-leave
2
subsubsection-enter
2
subsubsection-leave
3
subsubsection-enter
3
subsubsection-leave
3
11 changes: 11 additions & 0 deletions Tmain/optscript-scope.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
TITLE 0 input.unknown /^* TITLE 0$/;" s line:1
Subtitle 0.0 input.unknown /^+ Subtitle 0.0$/;" t line:2 section:TITLE 0
Subtitle 0.1 input.unknown /^+ Subtitle 0.1$/;" t line:3 section:TITLE 0
subsubtitle 0.1.0 input.unknown /^- subsubtitle 0.1.0$/;" u line:4 subsection:TITLE 0.Subtitle 0.1
subsubtitle 0.1.1 input.unknown /^- subsubtitle 0.1.1$/;" u line:5 subsection:TITLE 0.Subtitle 0.1
Subtitle 0.2 input.unknown /^+ Subtitle 0.2$/;" t line:6 section:TITLE 0
subsubtitle 0.2.0 input.unknown /^- subsubtitle 0.2.0$/;" u line:7 subsection:TITLE 0.Subtitle 0.2
TITLE 1 input.unknown /^* TITLE 1$/;" s line:8
Subtitle 1.0 input.unknown /^+ Subtitle 1.0$/;" t line:9 section:TITLE 1
subsubtitle 1.0.0 input.unknown /^- subsubtitle 1.0.0$/;" u line:10 subsection:TITLE 1.Subtitle 1.0
subsubtitle 1.0.1 input.unknown /^- subsubtitle 1.0.1$/;" u line:11 subsection:TITLE 1.Subtitle 1.0
56 changes: 56 additions & 0 deletions Tmain/optscript-scope.d/unknown.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--langdef=UnknownX
--kinddef-UnknownX=s,section,sections
--kinddef-UnknownX=t,subsection,subsections
--kinddef-UnknownX=u,subsubsection,subsubsections

--regex-UnknownX=/^\* (.*)$/\1/s/{{
/section-enter = _scopedepth =
. _scopeset
_scopetop {
(scopetop: OK) =
. eq {
(scopeNth0: OK) =
} {
(scopeNth0: FAILED) =
} ifelse
} {
(scopetop: FAILED) =
} ifelse
/section-leave = _scopedepth =
}}

--regex-UnknownX=/^\+ (.*)$/\1/t/{{
/subsection-enter = _scopedepth =
_scopedepth 3 eq {
_scopepop
} if
_scopedepth 2 eq {
0 _scopeNth _scopetop {
(scopetop: OK) =
eq {
(scopeNth0: OK) =
} {
(scopeNth0: FAILED) =
} ifelse
} {
(scopetop: FAILED) =
} ifelse
_scopepop
} if
. _scopepush
1 _scopeNth . :scope eq {
(scopeNth1: OK) =
} {
(scopeNth1: FAILED) =
} ifelse
/subsection-leave = _scopedepth =
}}

--regex-UnknownX=/^\- (.*)$/\1/u/{{
/subsubsection-enter = _scopedepth =
_scopedepth 3 eq {
_scopepop
} if
. _scopepush
/subsubsection-leave = _scopedepth =
}}
5 changes: 3 additions & 2 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -3858,17 +3858,18 @@ static EsObject* lrop_get_scope_depth (OptVM *vm, EsObject *name)
{
struct lregexControlBlock *lcb = get_current_lcb (vm);
int scope = lcb->currentScope;
int depth = 0;

while (scope != CORK_NIL)
{
tagEntryInfo *e = getEntryInCorkQueue (scope);
if (!e)
break;

depth++;
scope = e->extensionFields.scopeIndex;
}

EsObject *q = es_integer_new (scope);
EsObject *q = es_integer_new (depth);
if (es_error_p(q))
return q;

Expand Down

0 comments on commit 4cf6106

Please sign in to comment.