Search code examples
erlangyecc

{:error, {:undefined, :standard_syntax_parser, ['syntax error before: ', []]}}


So I am trying to use yecc.

Terminals string string_delimeter.

Nonterminals value string_content.

Rootsymbol value.

value -> string : extract_value('$1').

value -> string_delimeter string_content string_delimeter : '$2'.
string_content -> value string_content : ['$1' | '$2'].
string_content -> value : '$1'.

Erlang code.

extract_value({_, Value}) -> Value.

For the input:

[string_delimeter: '\'', string: 'test', string_delimeter: '\'']

I get

{:error, {:undefined, :standard_syntax_parser, ['syntax error before: ', []]}}

If I delete any (left or right) string_delimeter surrounding string_content:

value -> string_delimeter string_content string_delimeter : '$2'.

value -> string_delimeter string_content : '$2'.

for

[string_delimeter: '\'', string: 'test']

it returns

{:ok, 'test'}

I don't really understand this behaviour, where is the issue?


Solution

  • I did not figure why this is a problem in yecc: token_1 token_2 token_1 I really wish I would know, but I have a way around this:

    Terminals string string_delimeter whitespace.
    
    
    Nonterminals value string_content.
    
    
    Rootsymbol value.
    
    value -> string : extract_value('$1').
    
    value -> string_delimeter string_content : '$2'.
    string_content -> string_content string_delimeter : '$1'.
    string_content -> value whitespace string_content : ['$1' | '$3'].
    string_content -> value : ['$1'].
    
    Erlang code.
    
    extract_value({_, Value}) -> Value.