Forum > Third party

Gold Parser Lazarus Engine problems

(1/4) > >>

avra:
I have built a FCL grammar as mentioned in this thread:
http://forum.lazarus.freepascal.org/index.php/topic,33830.msg296041.html#msg296041

There are no warnings nor errors, and I can successfuly test the grammar in Gold Test Window. However when I compile the grammar and try to parse the same code in LazarusGoldEngine (which can also be found in thread mentioned above) I get parsing errors.

This is a minimal grammar to demonstrate the problem (nice to see that BNF color highlighting works in this forum):

--- Code: bnf  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---"Case Sensitive" = False"Start Symbol" = <range> Comment Block   @= { Nesting = All, Advance = Character }Comment Start    = '{'Comment End      = '}'Comment Line     = '//'                ASSIGN           = ':='SEMI             = ';'LEFTPAR          = '('RIGHTPAR         = ')'DOUBLEPOINT      = '..' <range>        ::= RANGE ASSIGN LEFTPAR 0 DOUBLEPOINT 100 RIGHTPAR SEMI
I compile it in Gold to create CGT file, and load CGT file into Lazarus GoldEngine.

1) Now, if I use this code as test input:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---RANGE := (0..100);I get this error while parsing in Lazarus GoldEngine:

--- Quote ---Line 1: Syntax Error: Expecting the following tokens: LEFTPAR
--- End quote ---
RANGE and ASSIGN tokens are recognized, but LEFTPAR not although it is there.

2) Also if I use a comment line as test input:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// some comment lineI get this error while parsing in Lazarus GoldEngine:

--- Quote ---Line 1: Lexical Error: Cannot recognize token: s
--- End quote ---

Problem 1 is a major one, and currently a deal breaker since I could not figure out how to overcome it. Problem 2 is a minor one and it looks like GoldEngine ignores whole comment group defined in Gold. Not pleasant, and it would be nice if it could be fixed, but I think that i could eventually overcome it with some effort.

Problems are the same with both old non-generics Lazarus GoldEngine version and new Thaddy's version with generics.

I do hope that someone can take a look at this and help since I would really hate to drop GoldEngine  :'(

Thaddy:
The compiled grammars from 5.2 do not always work correctly. Compiled grammars from 1.0 do.
I will try to analyze the problem. Can you attach a cgt?

avra:

--- Quote from: Thaddy on September 03, 2018, 12:35:42 pm ---The compiled grammars from 5.2 do not always work correctly. Compiled grammars from 1.0 do.
--- End quote ---
I didn't know that. :o I do not have a 1.0 but I do have an old 3.0.1. I will try and report back.


--- Quote from: Thaddy on September 03, 2018, 12:35:42 pm ---I will try to analyze the problem. Can you attach a cgt?
--- End quote ---
Of course. Thanks a lot for looking into this problem.  :)

avra:

--- Quote from: avra on September 03, 2018, 12:57:39 pm ---
--- Quote from: Thaddy on September 03, 2018, 12:35:42 pm ---The compiled grammars from 5.2 do not always work correctly. Compiled grammars from 1.0 do.
--- End quote ---
I didn't know that. :o I do not have a 1.0 but I do have an old 3.0.1. I will try and report back.
--- End quote ---
You were right. Old version 3.0.1 runs better, although with some quircks.

I had to remove comment group from grammar since old version does not support it. Here is a new grammar:

--- Code: bnf  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---"Case Sensitive" = False"Start Symbol" = <range> ASSIGN           = ':='SEMI             = ';'LEFTPAR          = '('RIGHTPAR         = ')'DOUBLEPOINT      = '..' <range>        ::= 'RANGE' ASSIGN LEFTPAR 0 DOUBLEPOINT 100 RIGHTPAR SEMI
It compiles in both old and new Gold without errors or warnings, and testing inside of both versions works without any problem. I have attached CGT files from both Gold versions. When running Lazarus GoldEngine with these CGT files and this input:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---RANGE := (0..100);then
a) with 3.0.1 parsing works and AST is shown (but only if there is at least one blank or newline after last character ';' - which seams as a 3.0.1 bug)
b) with 5.2.0 parsing does not work with the same error as before:

--- Quote ---Line 1: Syntax Error: Expecting the following tokens: LEFTPAR
--- End quote ---

Hope this helps a little  ::)

avra:
I have tested my FCL grammar with 3.0.1 and GoldEngine and it works. I haven't yet figured out exact rule for appending some whitespace character at the end of the line (or file?) to overcome the mentioned bug but hopefully that will be sorted out. So, now I have a work around and will continue to invest time in Gold Parser, being it 3.0.1 or 5.20. Whatever.

Thank you Thaddy !!!  8) ;) 8)

Btw. I have to correct my self and say that 3.0.1 supports comment groups. Only comment attributes are not supported. Meaning, this is not compatible with 3.01:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Comment Block   @= { Nesting = All, Advance = Character }Good enough for me!  ::)

Navigation

[0] Message Index

[#] Next page

Go to full version