Layout in Rascal

前端 未结 1 1316
不知归路
不知归路 2021-01-25 23:17

When I import the Lisra recipe,

import demo::lang::Lisra::Syntax;

This creates the syntax:

layout Whitespace      = [\\t-\\n\\r         


        
相关标签:
1条回答
  • 2021-01-26 00:23

    When you define a start non-terminal Rascal defines two non-terminals in one go:

    rascal>start syntax A = "a";
    ok
    

    One non-terminal is A, the other is start[A]. Given a layout non-terminal in scope, say L, the latter is automatically defined by (something like) this rule:

    syntax start[A] = L before A top L after;
    

    If you call a parser or wish to parse a concrete fragment, you can use either non-terminal:

    parse(#start[A], " a ") // parse using the start non-terminal and extra layout
    parse(A, "a") // parse only an A
    (start[A]) ` a ` // concrete fragment for the start-non-terminal
    (A) `a` // concrete fragment for only an A
    [start[A]] " a "
    [A] "a"
    
    0 讨论(0)
提交回复
热议问题