Skip to content
This repository has been archived by the owner on Jul 26, 2018. It is now read-only.

0.4.5 update #15

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

0.4.5 update #15

wants to merge 13 commits into from

Conversation

rurban
Copy link

@rurban rurban commented Oct 2, 2013

Highlights:
less memory leaks, default parse_new
default yyerror filename "" => "-"
remove G from YY_ERROR and YY_INPUT 1st arg
initialize input, filename, lineno in parse_new
skip -vv verbose printing for typical lexer rules
add main in default trailer with -DYY_MAIN, build samples

add improvements from upstream peg-0.1.13:
add predicates have access to yytext
use __inline on Win32
proper ~{ error } block
use C89 escape for ESC
enclose user actions in braces to allow local variables to be declared in C89

Reini Urban added 13 commits September 30, 2013 18:10
The generated parsers do not leak.

Since the nodes are cyclic, mark a freed node with -1.
Also free temp yyqq buffers.
Sequences and Alternates still leaking.
Add a Variable node for the name
provide a default yyparse_new
create better indented c code
cleanup parser memory
add yyprintfokrule, yyprintfvokrule, yyprintfvfailrule
fix greg.c bootstrap. edit greg-new.c and compile.c for bootstrapping
  and do make greg-new
remaining leaks: 16kb in Alternates,Sequences
default yyerror filename "<stdin>" => "-"
remove G from YY_ERROR and YY_INPUT 1st arg
use G->input as new default input stream for YY_INPUT and YY_ERROR
initialize input, filename, lineno in parse_new
add filename to yyparse for diagnostics
yyqq: escape % to %%
add Node Variable for the variable names
skip -vv verbose printing for typical lexer rules
This fixes potion using a different prefix
almost all leg samples build and work now, just test.leg not
add predicates have access to yytext from git-svn-id: http://piumarta.com/svn2/peg/trunk@92 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a
(peg-0.1.13)
revert yyerror changes: now along peg/leg upstream, just file:line at the end (as in perl)
improve yyinit(&g): memset(0), not memcpy malloced g
so pair yyinit with yydeinit with stack allocated G, or yyparse_new/yyparse_free with heap allocated G
use readChar and helpers from peg-0.1.13
use __inline on Win32
improve Predicate layout
update Query from peg: use readable names,
fix test.leg: ending Alternate label
use the upstream peg error Action block feature,
get rid of the added errblock field from every node.
add erract sample and testcase
from git-svn-id: http://piumarta.com/svn2/peg/trunk@52 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a
…o be declared in C89

from git-svn-id: http://piumarta.com/svn2/peg/trunk@51 4d4069a9-7f2f-0410-87d9-cbc5f9740c0a
This is now matching peg-0.1.13
seperates -DP from -Dp in frontends (parser rules, from parser matches, from lexer matches)
@nddrylliog
Copy link
Member

Thanks for the (huge) PR — I'll have to check how well nagaqueen fares on your version.

When you mean 'proper' error blocks, do you mean that they behave the same, but that instead of being attached to every kind of node, they're just a node of their own now? (hence smaller memory footprint, etc.) I haven't had time to understand all the changes yet.

@rurban
Copy link
Author

rurban commented Oct 4, 2013

yes, 'proper' error blocks mean 1. only one special Error node and action instead
of being attached to every node, and 2. using the upstream version, not our own :)

re Makefile 3rd line: hmm, since it's only commented I thought of leaving it there.

@nddrylliog
Copy link
Member

yes, 'proper' error blocks mean 1. only one special Error node and action instead
of being attached to every node, and 2. using the upstream version, not our own :)

Yup, I noticed a few things were borrowed from upstream. What I'm really wondering is how functionally equivalent they are. An incompatible change would be painful for both nagaqueen & other greg users.

@rurban
Copy link
Author

rurban commented Oct 7, 2013

The only incompatibility is:

  • remove G from YY_ERROR and YY_INPUT 1st arg
    regarding greg 0.4.4

upstream leg always used to differ from our YY_ERROR and YY_INPUT.
He recently added an optional context variable, which resembles our struct _GREG being passed around,
and also renamed the internal struct members.

@nddrylliog
Copy link
Member

See that's why I think more details are needed in your changelog, along with migration instructions for users. And any rename fo internal struct members might need to be documented if they could have been used.

For example, the YY_INPUT in NagaQueen does need the _GREG struct because it has this 'read routine' thing that allows reading from file or from a memory block in a cross-platform fashion: https://github.com/nddrylliog/nagaqueen/blob/master/grammar/nagaqueen.leg#L136 - it that can't be done with your 0.4.5 update, that's a step back.

I'm all for getting closer to (or at least keeping track of) Ian's changes, but I want to see the implications.

@rurban
Copy link
Author

rurban commented Oct 7, 2013

The only action for greg users is to remove the 1st G arg from YY_ERROR and YY_INPUT.

Rationale: Whenever YY_ERROR and YY_INPUT is used there already is G available, there's no need to
pass it around as the macro arg. This is also consistent with all other YY_* macros. Most of them do not pass G around.
E.g.

#define YY_ERROR(message) yyerror(G, message)
define YY_BEGIN        ( G->begin= G->pos, 1)

The required patch for nagaqueen.leg is as follows:

diff --git a/grammar/nagaqueen.leg b/grammar/nagaqueen.leg
index 480a15d..f43ef63 100644
--- a/grammar/nagaqueen.leg
+++ b/grammar/nagaqueen.leg
@@ -36,7 +36,7 @@ void GC_free(void *);

 #define rewindWhiteSpace { \
     /* only rewind if at end of file */ \
-    if (core->eof == 1) { \
+    if (G->data->eof == 1) { \
       int originalPos = G->pos; \
       char *c = G->buf + G->pos; \
       /* rewind until we reach something non-whitespace */ \
@@ -50,12 +50,12 @@ void GC_free(void *);

 // Throw error at current parsing pos. Used when nothing valid matches.
 #define throwError(val, message) \
-    nq_error(core->this, (val), (message), G->pos + G->offset)
+    nq_error(G->data->this, (val), (message), G->pos + G->offset)

 // Throw error at last matched token pos. Used with invalid tokens being
 // parsed for more helpful messages (e.g. misplaced suffixes).
 #define throwTokenError(val, message) \
-    nq_error(core->this, (val), (message), core->token[0])
+    nq_error(G->data->this, (val), (message), core->token[0])

 #define missingOp(c) { \
     rewindWhiteSpace; \
@@ -133,7 +133,7 @@ static int _nq_fread(void *ptr, size_t size, NagaQueenCore *core) {
 #define YY_XTYPE NagaQueenCore *
 #define YY_XVAR core

-#define YY_INPUT(buf, result, max_size, core) yyInput(buf, &result, max_size, core)
+#define YY_INPUT(buf, result, max_size) yyInput(buf, &result, max_size, (G->data))

 void yyInput(char *buf, int *result, int max_size, NagaQueenCore *core) {
     (*result) = core->io.read(buf, max_size, core);

@rurban
Copy link
Author

rurban commented Oct 8, 2013

I'll revert the YY_INPUT and YY_ERROR api changes, so that the impact will be minimal. I'm persuaded.

@nddrylliog
Copy link
Member

no it's okay, the diff you provided for nagaqueen looks good, I just haven't had time to merge it yet. I will soon.

@nddrylliog
Copy link
Member

@rurban Your version seems to work fine with the nagaqueen patch you've provided, which is cool with me.

However, I've tried (unsuccessfully) to merge your changes with the changes we've had on this repo - our forks have diverged, please rebase your changes on the latest master here so that it applies cleanly.

(For clarification: I spent about an hour resolving merge conflicts and when I was done, I got a greg that segfaults - I'm just not that well-versed in greg anymore to know what's going on exactly, nor do I have the time. Since you're proposing a lot of changes/fixes I think it's only fair if you do the merging yourself.)

@tokuhirom
Copy link

e@rurban what's the current status about this?

@rurban
Copy link
Author

rurban commented Nov 19, 2013

Please hold. I tried to make greg safe for GC usage (re-entrant eval), but
failed, and have no time right now. In a few weeks.

On Mon, Nov 18, 2013 at 5:38 PM, Tokuhiro Matsuno
[email protected]:

e@rurban what's the current status about this?


Reply to this email directly or view it on GitHubhttps://github.com//pull/15#issuecomment-28751346
.

Reini Urban
http://cpanel.net/ http://www.perl-compiler.org/

@tokuhirom
Copy link

ping?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants