Skip to content

Imperative backends misprint mixfix lists #358

@andreasabel

Description

@andreasabel

Affects backends:

For the grammar

[].  [Integer] ::= "";
(:). [Integer] ::= "-" Integer ";" [Integer];

and the input

- 1;
- 2;
- 3;

the backends C/C++/Java render the parsed syntax tree wrongly as:

1 - 2 - 3 - 

Haskell does the right job (reproducing the input), and OCaml almost, with some extra space before the semicolon:

- 1 ;
- 2 ;
- 3 ;

The imperative backends seem to assume that the only terminal in the (:) rule is the separator.

bnfc/source/src/BNFC/CF.hs

Lines 735 to 744 in e91a342

-- | Gets the separator for a list.
getCons :: [Rule] -> String
getCons rs = case find (isConsFun . funRule) rs of
Just (Rule _ _ cats _) -> seper cats
Nothing -> error $ "getCons: no construction function found in "
++ intercalate ", " (map (show . funRule) rs)
where
seper [] = []
seper (Right x:_) = x
seper (Left _:xs) = seper xs

(Found this bug by trying to understand getCons.)

Metadata

Metadata

Assignees

Labels

CC++HaskellJavalistsConcerning list categories and separator/terminator/delimiter pragmasprinterConcerning the generated printer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions