Skip to content

Commit

Permalink
clean up of lang::box::*
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 1, 2024
1 parent 2c83b82 commit a1ed555
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 179 deletions.
134 changes: 25 additions & 109 deletions src/org/rascalmpl/library/lang/box/syntax/Box.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -5,119 +5,35 @@
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
}
@contributor{Jurgen J. Vinju - [email protected] - CWI}
@contributor{Bert Lisser - [email protected] (CWI)}

module lang::box::\syntax::Box

start syntax Main = Boxx WhitespaceAndComment*;

syntax Boxx
= StrCon
| BoxOperator box_operator "[" Boxx* list "]"
| FontOperator font_operator "[" Boxx* list "]"
| "LBL" "[" StrCon "," Boxx "]"
| "REF" "[" StrCon "," Boxx "]"
| "CNT" "[" StrCon "," StrCon "]"
// | "O" SOptions "[" Boxx BoxString Boxx "]"
;


lexical StrCon
= [\"] StrChar* chars [\"]
;

lexical StrChar
= "\\" [\" \' \< \> \\ b f n r t]
| ![\" \' \< \> \\]
@synopsis{Every kind of boxes encodes one or more parameterized two-dimensional text constraints.}
@description{
* `H` puts their elements next to each other one the same line separated by `hs` spaces.
* `V` puts their elements below each other on their own line, separated by `vs` empty lines.
* `HOV` acts like `H` as long as the elements all fit on one line, otherwise it becomes a `V`
* `HV` acts like H until the line is full, and then continues on the next line like `V`.
* `I` is a `V` box that indents every line in the output with `is` spaces
* `WD` produces a number of spaces exactly as wide as the wides line of the constituent boxes
* `A` is a table formatter. The list of Rows is formatted with `H` but each cell is aligned vertically with the rows above and below.
* `SPACE` produces `space` spaces
* `L` produces the literal word. This word may only contain printable characters and no spaces; this is a required property that the formatting algorithm depends on for correctness.
}
data Box(int hs=1, int vs=0, int is=2)
= H(list[Box] boxes)
| V(list[Box] boxes)
| HOV(list[Box] boxes)
| HV(list[Box] boxes)
| I(list[Box] boxes)
| WD(list[Box] boxes)
| A(list[Row] rows, list[Alignment] columns=[l() | [R(list[Box] cs), *_] := rows, _ <- cs] /* learns the amount of columns from the first row */)
| SPACE(int space)
| L(str word)
;


lexical NatCon = [0-9]+ ;

syntax BoxOperator
= "A" AlignmentOptions alignments SpaceOption* options
| "R"
| "H" SpaceOption* options
| "V" SpaceOption* options
| "HV" SpaceOption* options
| "HOV" SpaceOption* options
| "I" SpaceOption* options
| "WD"
/*
| "COMM"
| "F" FontOption* options
| "G" GroupOption* options
| "SL" GroupOption* options
*/
;

syntax FontOperator
= "KW"
| "VAR"
| "NUM"
| "MATH"
| "ESC"
| "COMM"
| "STRING"
;

syntax AlignmentOption
= "l" SpaceOption* options
| "c" SpaceOption* options
| "r" SpaceOption* options
;

syntax AlignmentOptions
= "(" {AlignmentOption ","}* ")"
;

syntax SpaceSymbol
= "hs"
| "vs"
| "is"
| "ts"
;

syntax SpaceOption
= SpaceSymbol "=" NatCon
;
data Row = R(list[Box] cells);

syntax Context
= "H"
| "V"
;
/*
syntax FontValue
= NatCon
| FontId
;
syntax FontOption
=
FontParam "=" FontValue
;
syntax FontParam
= "fn"
| "fm"
| "se"
| "sh"
| "sz"
| "cl"
;
data Alignment = l() | r() | c();

*/
syntax GroupOption
= "gs" "=" NatCon
| "op" "=" BoxOperator
;

layout WhiteSpace =
WhitespaceAndComment*
!>> [\ \t\n\r]
!>> "%"
;

lexical WhitespaceAndComment
= [\ \t\n\r]
| "%" [!%]* "%"
| "%%" [!\n]* "\n"
;
39 changes: 0 additions & 39 deletions src/org/rascalmpl/library/lang/box/util/Box.rsc

This file was deleted.

2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/lang/box/util/Box2Text.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module lang::box::util::Box2Text
import util::Math;
import List;
import String;
import lang::box::util::Box;
import lang::box::\syntax::Box;

@synopsis{Converts boxes into a string by finding an "optimal" two-dimensional layout}
@description{
Expand Down
1 change: 0 additions & 1 deletion src/org/rascalmpl/library/lang/box/util/End.html

This file was deleted.

2 changes: 0 additions & 2 deletions src/org/rascalmpl/library/lang/box/util/End.tex

This file was deleted.

4 changes: 0 additions & 4 deletions src/org/rascalmpl/library/lang/box/util/Start.html

This file was deleted.

23 changes: 0 additions & 23 deletions src/org/rascalmpl/library/lang/box/util/Start.tex

This file was deleted.

0 comments on commit a1ed555

Please sign in to comment.