diff --git a/Tmain/optscript-scope.d/exit-expected.txt b/Tmain/optscript-scope.d/exit-expected.txt new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/Tmain/optscript-scope.d/exit-expected.txt @@ -0,0 +1 @@ +0 diff --git a/Tmain/optscript-scope.d/input.unknown b/Tmain/optscript-scope.d/input.unknown new file mode 100644 index 0000000000..1ae77bed3a --- /dev/null +++ b/Tmain/optscript-scope.d/input.unknown @@ -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 diff --git a/Tmain/optscript-scope.d/run.sh b/Tmain/optscript-scope.d/run.sh new file mode 100755 index 0000000000..f05f1c83cf --- /dev/null +++ b/Tmain/optscript-scope.d/run.sh @@ -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 diff --git a/Tmain/optscript-scope.d/stderr-expected.txt b/Tmain/optscript-scope.d/stderr-expected.txt new file mode 100644 index 0000000000..e2c071a1eb --- /dev/null +++ b/Tmain/optscript-scope.d/stderr-expected.txt @@ -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 diff --git a/Tmain/optscript-scope.d/stdout-expected.txt b/Tmain/optscript-scope.d/stdout-expected.txt new file mode 100644 index 0000000000..3334b3eb17 --- /dev/null +++ b/Tmain/optscript-scope.d/stdout-expected.txt @@ -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 diff --git a/Tmain/optscript-scope.d/unknown.ctags b/Tmain/optscript-scope.d/unknown.ctags new file mode 100644 index 0000000000..313ecb05ed --- /dev/null +++ b/Tmain/optscript-scope.d/unknown.ctags @@ -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 = +}} diff --git a/main/lregex.c b/main/lregex.c index 2d6c84f509..8d23ea568a 100644 --- a/main/lregex.c +++ b/main/lregex.c @@ -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;