You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/04/03 11:53:18 UTC
[incubator-annotator] 03/09: Add debug tool for parser
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch fragment-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 16308314883d4a133cc396596b180877e26550af
Author: Gerben <ge...@treora.com>
AuthorDate: Fri Apr 3 12:42:29 2020 +0200
Add debug tool for parser
---
packages/fragment-identifier/src/fragment.pegjs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/packages/fragment-identifier/src/fragment.pegjs b/packages/fragment-identifier/src/fragment.pegjs
index 8e6d22c..c19c6bd 100644
--- a/packages/fragment-identifier/src/fragment.pegjs
+++ b/packages/fragment-identifier/src/fragment.pegjs
@@ -1,3 +1,17 @@
+{
+ function debug(input, range) {
+ // Prints the location of the parser.
+ // Use e.g. in an action: { debug(input, range); return text(); }
+ const [start, end] = range();
+ const underline = (end > start + 1)
+ ? ' '.repeat(start) + '\\' + '_'.repeat(end - start - 2) + '/'
+ : ' '.repeat(start) + '^';
+ console.log(input);
+ console.log(underline);
+ }
+}
+
+
start =
top