[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator 0416ca9 134/434: Added information abo
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator 0416ca9 134/434: Added information about lex-analyzer in README |
Date: |
Mon, 29 Nov 2021 15:59:26 -0500 (EST) |
branch: externals/parser-generator
commit 0416ca9ed4549cfd2c1b281763878e940fc21698
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Added information about lex-analyzer in README
---
README.md | 70 +++++++++++++++++++++++++++++-
test/parser-generator-lex-analyzer-test.el | 48 +++++++++++++++-----
2 files changed, 107 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index cbff6e6..7a87dbe 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,75 @@ This is just started, so most stuff are *WIP*.
## Lexical Analysis
-We use a regular-language based lexical analyzer that can be implemented by a
finite-state-machine (FSM).
+We use a regular-language based lexical analyzer that can be implemented by a
finite-state-machine (FSM). Set lexical analysis function by setting variable
`parser-generator-lex-analyzer--function`. Optionally set reset function by
setting variable `parser-generator-lex-analyzer--reset-function`. The lexical
analysis is indexed on variable `parser-generator-lex-analyzer--index`. All
parsers expect a list of tokens as response from lexical-analysis.
+
+### Peek next look-ahead
+
+Returns the look-ahead number of next terminals in stream.
+
+``` emacs-lisp
+(require 'ert)
+(setq
+ parser-generator-lex-analyzer--function
+ (lambda (index length)
+ (let* ((string '(a a b b b))
+ (string-length (length string))
+ (max-index (+ index length))
+ (tokens))
+ (while (and
+ (< index string-length)
+ (< index max-index))
+ (push (nth index string) tokens)
+ (setq index (1+ index)))
+ (nreverse tokens))))
+(parser-generator-lex-analyzer--reset)
+(setq parser-generator--look-ahead-number 1)
+ (should
+ (equal
+ '(a)
+ (parser-generator-lex-analyzer--peek-next-look-ahead)))
+
+ (setq parser-generator--look-ahead-number 2)
+ (should
+ (equal
+ '(a b)
+ (parser-generator-lex-analyzer--peek-next-look-ahead)))
+
+```
+
+### Pop token
+
+Returns the next token in stream and moves index one forward.
+
+``` emacs-lisp
+(require 'ert)
+(setq
+ parser-generator-lex-analyzer--function
+ (lambda (index length)
+ (let* ((string '(a b))
+ (string-length (length string))
+ (max-index (+ index length))
+ (tokens))
+ (while (and
+ (< index string-length)
+ (< index max-index))
+ (push (nth index string) tokens)
+ (setq index (1+ index)))
+ (nreverse tokens))))
+(parser-generator-lex-analyzer--reset)
+(should
+ (equal
+ '(a)
+ (parser-generator-lex-analyzer--pop-token)))
+ (should
+ (equal
+ '(b)
+ (parser-generator-lex-analyzer--pop-token)))
+ (should
+ (equal
+ nil
+ (parser-generator-lex-analyzer--pop-token)))
+```
## Syntax Analysis / Parsing
diff --git a/test/parser-generator-lex-analyzer-test.el
b/test/parser-generator-lex-analyzer-test.el
index 0638e47..f68722c 100644
--- a/test/parser-generator-lex-analyzer-test.el
+++ b/test/parser-generator-lex-analyzer-test.el
@@ -20,7 +20,19 @@
(should-error
(parser-generator-lex-analyzer--peek-next-look-ahead))
- (setq parser-generator-lex-analyzer--function (lambda (index length)
(substring "abcdefghijklmnopqrstuvxz" index (+ index length))))
+ (setq
+ parser-generator-lex-analyzer--function
+ (lambda (index length)
+ (let* ((string '(a b c d))
+ (string-length (length string))
+ (max-index (+ index length))
+ (tokens))
+ (while (and
+ (< index string-length)
+ (< index max-index))
+ (push (nth index string) tokens)
+ (setq index (1+ index)))
+ (nreverse tokens))))
(should-error
(parser-generator-lex-analyzer--peek-next-look-ahead))
(parser-generator-lex-analyzer--reset)
@@ -30,7 +42,19 @@
(setq parser-generator--look-ahead-number 1)
(should
(equal
- "a"
+ '(a)
+ (parser-generator-lex-analyzer--peek-next-look-ahead)))
+
+ (setq parser-generator--look-ahead-number 2)
+ (should
+ (equal
+ '(a b)
+ (parser-generator-lex-analyzer--peek-next-look-ahead)))
+
+ (setq parser-generator--look-ahead-number 10)
+ (should
+ (equal
+ '(a b c d)
(parser-generator-lex-analyzer--peek-next-look-ahead)))
(message "Ended tests for
(parser-generator-lex-analyzer--peek-next-look-ahead)"))
@@ -48,23 +72,27 @@
(setq
parser-generator-lex-analyzer--function
(lambda (index length)
- (let* ((string "ab")
- (string-length (length string)))
- (when (> string-length index)
- (if (>= string-length (+ index length))
- (substring string index (+ index length))
- (substring string index (1- string-length)))))))
+ (let* ((string '(a b))
+ (string-length (length string))
+ (max-index (+ index length))
+ (tokens))
+ (while (and
+ (< index string-length)
+ (< index max-index))
+ (push (nth index string) tokens)
+ (setq index (1+ index)))
+ (nreverse tokens))))
(should-error
(parser-generator-lex-analyzer--pop-token))
(parser-generator-lex-analyzer--reset)
(should
(equal
- "a"
+ '(a)
(parser-generator-lex-analyzer--pop-token)))
(should
(equal
- "b"
+ '(b)
(parser-generator-lex-analyzer--pop-token)))
(should
(equal
- [elpa] externals/parser-generator 186d7bb 065/434: Renamed function lr-items to lr-items-for-prefix, (continued)
- [elpa] externals/parser-generator 186d7bb 065/434: Renamed function lr-items to lr-items-for-prefix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9792eeb 069/434: Added TODO items, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 08b40cd 071/434: Updated header levels in README, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 5da1b28 079/434: Added TODO item, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 79565f4 089/434: Fixed sorting of columns in GOTO-table, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 043e375 095/434: Refactored LR-parser into stand-alone file, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 4f81d98 107/434: Sorting each row in action-table, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 62f54f1 110/434: Added failing unit test for e-free-first function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ee0ef5d 115/434: Added failing unit test for Algorithm 5.7, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator b0e9111 125/434: Started on lex-analyzer function, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0416ca9 134/434: Added information about lex-analyzer in README,
ELPA Syncer <=
- [elpa] externals/parser-generator b756e1a 135/434: Added example of parsing using LR algorithm, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator cee559d 139/434: Added separate document for lexical analysis documentation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator de0ed95 142/434: Updated README.md, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fa7089e 144/434: Re-factored lex analyzer function to not use length argument, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7eb9a4a 156/434: Fixed issue with indexing productions when they have SDT, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 19667b3 158/434: Added failing unit test for translation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a8a4e7f 166/434: Minor fix, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator c0310bf 169/434: Added error-handling to lexical analyser, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator dfbd97f 184/434: More tweaking of f-set generation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 13d76ae 207/434: Passed tests for generating list permutations of length k, ELPA Syncer, 2021/11/29