[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gnuplot 049f953 044/184: Use absolute locations in all jum
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gnuplot 049f953 044/184: Use absolute locations in all jump/call/choice/commit instructions. |
Date: |
Sun, 29 Aug 2021 11:03:12 -0400 (EDT) |
branch: elpa/gnuplot
commit 049f953c6ff922179979b8466ea1d5fd1ba51869
Author: Jonathan Oddie <j.j.oddie@gmail.com>
Commit: Jonathan Oddie <j.j.oddie@gmail.com>
Use absolute locations in all jump/call/choice/commit instructions.
---
gnuplot-context.el | 71 ++++++++++++++++++++++++++----------------------
gnuplot-debug-context.el | 5 ++++
gnuplot-test-context.el | 26 ++++++------------
3 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/gnuplot-context.el b/gnuplot-context.el
index e40d72a..69b431f 100644
--- a/gnuplot-context.el
+++ b/gnuplot-context.el
@@ -411,9 +411,10 @@ These have to be compiled from the Gnuplot source tree
using
(eval-when-compile
- ;; Compile a single pattern into a list of instructions. Leaves any
- ;; calls to other rules as symbolic instructions (call SYMBOL); these
- ;; are resolved into offsets by `gnuplot-compile-grammar', below.
+ ;; Compile a single pattern into a list of instructions. Leaves
+ ;; calls to other rules as symbolic instructions (call SYMBOL) and
+ ;; jumps, commits etc. as relative offsets; these are resolved into
+ ;; absolute locations by `gnuplot-compile-grammar', below.
(defun gnuplot-compile-pattern (pat)
(cond
;; Strings match a single token literally
@@ -620,7 +621,7 @@ These have to be compiled from the Gnuplot source tree using
(setf (aref object-code i) '(return)
i (1+ i))))
- ;; Resolve symbolic jumps
+ ;; Resolve symbolic and relative jumps
(let ((pattern-name nil))
(dotimes (i (length object-code))
(let ((inst (aref object-code i)))
@@ -628,16 +629,25 @@ These have to be compiled from the Gnuplot source tree
using
((label)
(setq pattern-name (cadr inst)))
- ((jump call)
- (if (symbolp (cadr inst))
- (let* ((name (cadr inst))
- (location (gethash name name->offset)))
- (if (not location)
- (error
- (concat "gnuplot-compile-grammar: "
- "No rule found for symbol `%s' in pattern
`%s'")
- name pattern-name))
- (setcdr inst `(,location t ,name)))))))))
+ ((jump call choice commit)
+ (cond
+ ((symbolp (cadr inst))
+ (let* ((name (cadr inst))
+ (location (gethash name name->offset)))
+ (if (not location)
+ (error
+ (concat "gnuplot-compile-grammar: "
+ "No rule found for symbol `%s' in pattern
`%s'")
+ name pattern-name))
+ (setcdr inst `(,location ,name))))
+
+ ((numberp (cadr inst))
+ (let* ((offset (cadr inst))
+ (location (+ offset i)))
+ (setcdr inst `(,location))))
+
+ (t
+ (error "gnuplot-compile-grammar: bad instruction %s"
inst))))))))
object-code))))
;;; The grammar.
@@ -1657,7 +1667,7 @@ Set by `gnuplot-match-pattern'. See also
`gnuplot-info-at-point'.")
Each entry is of the form (NAME BEGIN END), where NAME is the
name specified in the (capture NAME PATTERN) form in the
-`gnuplop-compiled-grammar' source, BEGIN is the tail of the token
+`gnuplot-compiled-grammar' source, BEGIN is the tail of the token
list beginning the capture group, and END is the tail of the
token list just after the end of the capture group.")
@@ -1770,20 +1780,17 @@ there."
(fail)
(advance)))
- ;; (jump OFFSET FIXED): jump to instruction at PC + OFFSET,
- ;; or directly to OFFSET if FIXED is non-nil
+ ;; (jump LOCATION): jump to instruction at LOCATION
((jump)
- (let ((offset (cadr inst))
- (fixed (caddr inst)))
- (setq jump (if fixed offset (+ pc offset)))))
+ (let ((location (cadr inst)))
+ (setq jump location)))
- ;; (call OFFSET FIXED): push the next instruction as a
- ;; return location and jump like (jump), above
+ ;; (call LOCATION): push the next instruction as a
+ ;; return location and jump
((call)
- (let ((offset (cadr inst))
- (fixed (caddr inst)))
+ (let ((location (cadr inst)))
(push `(return ,(+ pc 1)) stack)
- (setq jump (if fixed offset (+ pc offset)))))
+ (setq jump location)))
;; (return): return to address at topmost RETURN record on
;; stack, or stop matching and return if stack is empty
@@ -1799,22 +1806,22 @@ there."
(r-pc (cadr r)))
(setq jump r-pc))))
- ;; (choice OFFSET): push PC + OFFSET onto the stack of
+ ;; (choice LOCATION): push LOCATION onto the stack of
;; backtracking points and continue at next instruction
((choice)
- (let ((offset (cadr inst)))
- (push `(,stack ,tokens ,(+ pc offset) ,gnuplot-captures
+ (let ((location (cadr inst)))
+ (push `(,stack ,tokens ,location ,gnuplot-captures
,progress)
backtrack)))
- ;; (commit OFFSET): discard most recent backtrack point
- ;; and jump to PC + OFFSET
+ ;; (commit LOCATION): discard most recent backtrack point
+ ;; and jump to LOCATION
((commit)
- (let ((offset (cadr inst)))
+ (let ((location (cadr inst)))
(if (not backtrack)
(error "no more backtrack points in commit"))
(pop backtrack)
- (setq jump (+ pc offset))))
+ (setq jump location)))
;; (fail): force this match to fail, going back to most
;; recent backtrack point
diff --git a/gnuplot-debug-context.el b/gnuplot-debug-context.el
index 780b3b7..4f4dda1 100644
--- a/gnuplot-debug-context.el
+++ b/gnuplot-debug-context.el
@@ -1,3 +1,8 @@
+;;
+;; debugging utilities for the gnuplot-mode context matcher
+;;
+
+(require 'gnuplot-test-context) ; for gnuplot-simplify-tokens
(defun gnuplot-unload ()
(interactive)
diff --git a/gnuplot-test-context.el b/gnuplot-test-context.el
index df4e83f..58c6723 100644
--- a/gnuplot-test-context.el
+++ b/gnuplot-test-context.el
@@ -41,10 +41,10 @@
(intern (gnuplot-token-id token)))))
tokens))
-;; compile a single pattern to vector form
+;; compile a single pattern to usable form
(eval-when-compile
(defun gnuplot-compile-pattern-1 (pattern)
- (vconcat (gnuplot-compile-pattern pattern) [(return)])))
+ (gnuplot-compile-grammar `((rule ,pattern)) 'rule)))
;; match a string
(defun gnuplot-match-string (string rule)
@@ -194,10 +194,6 @@
("," :none)
("]" :none)))
-(deftest gnuplot-parenthesized-expression ()
- (should-match parenthesized-expression
- ("(sum = sum + $2, sum/2)")))
-
(deftest gnuplot-function-call ()
(should-match function-call
"abs(2)"
@@ -232,6 +228,11 @@
("x=y=3, garbage" '(\, garbage))
("f(a) = y(x) = 5")))
+;; parenthesized exprs (including assignments)
+(deftest gnuplot-parenthesized-expression ()
+ (should-match parenthesized-expression
+ ("(sum = sum + $2, sum/2)")))
+
;; axis ranges
(deftest gnuplot-axis-range ()
(should-match axis-range
@@ -299,25 +300,15 @@
(deftest gnuplot-plot-command ()
(should-match plot-command
("plot sin(x) with impulses")
-
("plot x w points, x**2")
-
("plot [ ] [-2:5] tan(x), 'data.1' with l")
-
("plot 'leastsq.dat' w i")
-
("plot 'exper.dat' w lines, 'exper.dat' notitle w errorbars")
-
("plot sin(x) with linesp lt 1 pt 3, cos(x) with linesp lt 1 pt 4")
-
("plot 'data' with points pointtype 3 pointsize 2")
-
("plot 'data' using 1:2:4 with points pt 5 pointsize variable")
-
("plot 'd1' t \"good\" w l lt 2 lw 3, 'd2' t \"bad\" w l lt 2 lw 1")
-
("plot x*x with filledcurve closed, 40 with filledcurve y1=10")
-
("plot x*x, (x>=-5 && x<=5 ? 40 : 1/0) with filledcurve y1=10 lt 8")))
;;; set cntrparam
@@ -332,8 +323,7 @@
("cntrparam levels 10")
("cntrparam levels incremental 100,50")))
-
-
+
;;
;; test by parsing all the demos
;;
- [nongnu] elpa/gnuplot 566e92f 027/184: Fixed a dumb bug in gnuplot-indent-line., (continued)
- [nongnu] elpa/gnuplot 566e92f 027/184: Fixed a dumb bug in gnuplot-indent-line., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot aba40f1 034/184: Document the change to `gnuplot-make-regexp', ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 72ccda3 017/184: Improved syntax parsing and highlighting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 2387f12 016/184: Restored some XEmacs compatibility that I broke., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot df865fc 013/184: Slight change to font-lock regexps, and use buffer-local variables, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 0faec4f 022/184: Check that gnuplot-process is not nil in gnuplot-close-down, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 57fd4a2 036/184: Attempt to fix issue #9, void-function gnuplot-start-comint-function, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot ca241a7 035/184: Merge remote-tracking branch 'origin/devel' into devel, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 7f29578 023/184: Minor improvements to movement-by-command functions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 8d367f5 028/184: Better assignment-matching regexp (?), ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 049f953 044/184: Use absolute locations in all jump/call/choice/commit instructions.,
ELPA Syncer <=
- [nongnu] elpa/gnuplot 40efb8e 067/184: Make loading of gnuplot work with and without gnuplot-context., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 0d2079a 056/184: Fixed a regression in 7cb3975 relating to scanning stack at end-of-command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 2bf9779 063/184: Remove macro hacks for ancient Emacs versions, as per issue #12, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot cf513f9 049/184: Added (require 'eldoc) to gnuplot-context.el. Improved documentation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot a7cfd1d 055/184: Abbreviate "print" command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot ae5e628 074/184: Make context completion work on xemacs (21.4), ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 6e0ed5f 050/184: Added x2label, y2label to grammar, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 89e5445 053/184: Add customization options to turn context completion on and off., ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot ffe6c66 059/184: First shot at implementing inline plot images in process buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/gnuplot 5030976 051/184: Alter header to conform to package.el specifications, ELPA Syncer, 2021/08/29