콘텐츠로 이동

문법 요약과 미지원 목록

표기: [ ] 생략 가능, { } 0회 이상 반복, | 선택, "…" 그대로 쓰는 글자. 각 항목의 세부 규칙과 오류는 연결된 장을 참고하세요.

CompilationUnit = [ "package" QualifiedName ";" ]
{ "import" QualifiedName [ "." "*" ] ";" }
{ TypeDecl | EnumDecl | SchemaDecl } ;
TypeDecl = { Annotation } { TypeModifier }
( "class" Ident [ TypeParams ] [ "extends" Type ] [ "implements" TypeList ] ClassBody
| "interface" Ident [ TypeParams ] [ "extends" TypeList ] InterfaceBody ) ;
TypeModifier = "public" | "protected" | "private" | "final" | "native" | "partial" ;
TypeParams = "<" Ident { "," Ident } ">" ;
TypeList = Type { "," Type } ;
EnumDecl = { Annotation } [ "public" ] "enum" Ident "{" EnumMember { "," EnumMember } [ "," ] "}" ;
EnumMember = Ident "=" StringLiteral ;
SchemaDecl = "schema" Ident Ident [ StringLiteral ] "{" SchemaBody "}" ;
ClassBody = "{" { Field | Constructor | Method } "}" ;
InterfaceBody = "{" { { MemberModifier } ReturnType Ident "(" [ Params ] ")" ";" } "}" ;
Field = { Annotation } { FieldModifier } Type Ident [ "=" Expr ] ";" ;
FieldModifier = "public" | "protected" | "private" | "static" | "final" | "const" ;
Constructor = { Annotation } { MemberModifier } Ident "(" [ Params ] ")" ( Block | ";" ) ;
Method = { Annotation } { MemberModifier } ReturnType Ident "(" [ Params ] ")" ( Block | ";" ) ;
MemberModifier = "public" | "protected" | "private" | "static" | "native" | "const" ;
ReturnType = Type | "void" | "var" ;
Params = ParamList | "{" ParamList "}" ;
ParamList = Param { "," Param } ;
Param = { Annotation } [ "required" ] Type Ident ;
Annotation = "@" QualifiedName [ "(" [ AnnotationArgs ] ")" ] ;
AnnotationArgs = AnnotationValue | NamedValue { "," NamedValue } ;
NamedValue = Ident "=" AnnotationValue ;
AnnotationValue = StringLiteral | [ "-" ] IntLiteral | "true" | "false" ;
RealizesAnnotation = "@" "Realizes" "(" QualifiedName ")" ;
Type = QualifiedName [ "<" Type { "," Type } ">" ] [ "?" ] ;
QualifiedName = Ident { "." Ident } ;

Annotation에는 별도로 RealizesAnnotation과 같은 형태의 @References(QualifiedName)도 포함됩니다. 인수는 리터럴이 아닌 심볼(@Realizes는 요구사항)이며 반복할 수 있습니다. @Description·@Notes·@Title은 인수로 text block도 받습니다. enum 앞에는 @Realizes·@References·@Description·@Notes·@Title과 설계 메모 어노테이션만 둘 수 있습니다. schema의 선택적 제목은 모델링 DSL(database, requirements, qa, test, dictionary, layout, sequence, infra, contract, wireframe, project)에 해당하고 종류별 본문·파일 규칙은 모델링 schema를 따릅니다.

함수 타입은 (A) -> R로 표현하며 0·1·2개의 인수 타입을 받습니다. 상세한 함수 타입·람다 규칙을 함께 읽으세요.

Block = "{" { Statement } "}" ;
Statement = LocalVar | Assignment | IfStmt | WhileStmt | DoWhileStmt | ForStmt
| ForInStmt
| "break" ";" | "continue" ";" | "return" [ Expr ] ";" | "throw" Expr ";"
| TryStmt | "print" "(" Expr ")" ";" | "await" Expr ";"
| CallExpr ";" | ConstructorCall ";" | SqlStatement ;
LocalVar = [ "final" ] ( Type | "var" ) Ident "=" Expr ";" ;
Assignment = Target "=" Expr ";" ;
Target = Ident | Expr "." Ident | Expr "[" Expr "]" ;
IfStmt = "if" "(" Expr ")" Block { "else" "if" "(" Expr ")" Block } [ "else" Block ] ;
WhileStmt = "while" "(" Expr ")" Block ;
DoWhileStmt = "do" Block "while" "(" Expr ")" ";" ;
ForStmt = "for" "(" [ ForInit ] ";" [ Expr ] ";" [ ForUpdate ] ")" Block ;
ForInit = ( Type | "var" ) Ident "=" Expr | Target "=" Expr ;
ForUpdate = Target "=" Expr ;
ForInStmt = "for" "(" ( Type | "var" ) Ident "in" Expr ")" Block ;
TryStmt = "try" Block ( CatchClause { CatchClause } [ "finally" Block ] | "finally" Block ) ;
CatchClause = "catch" "(" Type Ident ")" Block ;
SqlStatement = [ ( Type | "var" ) Ident "=" ] SqlKeyword SqlText ";" ;
SqlKeyword = "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "CREATE" ;
Expr = Lambda | Ternary ;
Lambda = ( Ident | "(" [ LambdaParams ] ")" ) "=>" ( Expr | Block ) ;
LambdaParams = Ident { "," Ident } | Type Ident { "," Type Ident } ;
Ternary = OrExpr [ "?" Expr ":" Expr ] ;
OrExpr = AndExpr { "||" AndExpr } ;
AndExpr = BitOr { "&&" BitOr } ;
BitOr = BitXor { "|" BitXor } ;
BitXor = BitAnd { "^" BitAnd } ;
BitAnd = Equality { "&" Equality } ;
Equality = Relational { ( "==" | "!=" ) Relational } ;
Relational = Shift { ( "<" | "<=" | ">" | ">=" ) Shift } ;
Shift = Additive { ( "<<" | ">>" | ">>>" ) Additive } ;
Additive = Multiplicative { ( "+" | "-" ) Multiplicative } ;
Multiplicative = Unary { ( "*" | "/" | "%" ) Unary } ;
Unary = ( "!" | "~" | "-" | "+" ) Unary | Postfix ;
Postfix = Primary { "." Ident [ Arguments ] | "[" Expr "]" } ;
Primary = Literal | Ident | Ident Arguments | ConstructorCall
| "this" | "super" | "(" Expr ")" | "await" Expr
| ListLiteral | SetLiteral | MapLiteral | EmbeddedBlock ;
ConstructorCall = QualifiedName [ "<" Type { "," Type } ">" ] Arguments ; (* 대문자로 시작하는 타입 이름 *)
Arguments = "(" [ Argument { "," Argument } ] ")" ;
Argument = Expr | Ident ":" Expr ; (* 위치 인수가 이름 있는 인수보다 앞 *)
ListLiteral = "[" [ Expr { "," Expr } ] "]" ;
SetLiteral = "{" Expr { "," Expr } "}" ;
MapLiteral = "{" Expr ":" Expr { "," Expr ":" Expr } "}" ;
EmbeddedBlock = ( "sql" | "json" | "html" | "css" ) "{" EmbeddedSource "}"
| "sql" '"""' SqlText '"""' ;
Literal = IntLiteral | LongLiteral | FloatLiteral | DoubleLiteral
| CharLiteral | StringLiteral | "true" | "false" | "null" ;

다른 언어에서 가져오기 쉬운 미지원 문법

섹션 제목: “다른 언어에서 가져오기 쉬운 미지원 문법”
분류 쓰지 않는 문법 진단 예 대신 쓰는 문법
객체 생성 new User() Legacy constructor keyword is not supported. Use TypeName(...). User()
반복 for (X x : xs) write for (T x in items) instead of the ':' form for (X x in xs); 대상별 생성 제한 확인
증감 i++, --i Increment and decrement are not supported i = i + 1;
복합 대입 x += 1 Compound assignment is not supported x = x + 1;
분기 switch switch is not supported if / else if
변수 int x; (초기값 없음) Unsupported method statement: int x int x = 0;
변수 int a = 1, b = 2; Cannot resolve initializer expression for variable 'a'. 한 줄에 하나
블록 { … } 단독 블록 Unsupported method statement: { … } 메서드로 분리
함수 최상위 함수 Unsupported top-level declaration: … 클래스의 static 메서드
함수 지역 함수 선언 미지원 클래스 메서드 또는 함수 타입의 람다
메서드 int f() => 1; Unsupported class member declaration: … int f() { return 1; }
메서드 제네릭 메서드 <T> T id(T x) Invalid method return type. 제네릭 클래스
메서드 기본값 매개변수 int a = 1 Invalid method parameter declaration. 오버로드
메서드 abstract, override, final 메서드 Invalid method return type. 인터페이스, 수식어 생략
클래스 중첩 클래스 Unsupported class member declaration: class Inner { } 최상위 클래스
클래스 extends A, B Invalid base class name … extends 하나 + implements 여러 개
생성자 super(…), this(…) 호출 No matching method for B.super. 자식 생성자에서 필드 직접 초기화
인터페이스 기본 구현 메서드 Unsupported interface member declaration. 구현 클래스에 작성
타입 배열 int[] Unsupported method statement: int[] xs = [1] List<int>
타입 cast (int) x Cannot resolve initializer expression … 지원 숫자 타입의 toInt()·toLong()
타입 object, any, dynamic Unknown type 'object'. 구체적인 타입·인터페이스
null a ?? b, a?.b 식을 해석하지 못함 a != null ? a : b
숫자 byte b = 1;, float f = 1.5; Cannot assign int to byte variable 'b'. int·1.5f 사용
숫자 1e5, .5 식을 해석하지 못함 100000.0, 0.5
문자열 보간 $"{x}", `${x}` Unexpected character "" + x
문자열 여러 줄 문자열 Unterminated string literal \n 사용
출력 Console.println(1) 현행 Console API에 없음 print(1) 또는 Console.write("" + 1)
이름 한글 식별자 Unexpected non-ASCII byte … 영문 식별자
문자열 비교 "a" < "b" Operator '<' cannot be applied to string and string. ==, !=만 사용
어노테이션 사용자 정의 어노테이션 Annotation semantic integration is not yet supported. 허용 목록만 사용

for-in, try/catch/finally와 null 확인 뒤의 타입 좁히기는 지원 기능입니다. 문법 지원과 생성 대상의 제한은 별개이며 문장과 null 허용 타입에서 각각 확인합니다.

메시지에 포함된 말 확인할 장
Unexpected character, non-ASCII, Unterminated 어휘 구조
package, import, Invalid class declaration, modifier, Unsupported class member 선언과 타입
Cannot assign, Unknown type, Generic type, null 선언과 타입
Unsupported method statement, must end with semicolon, Unreachable, For statement 문장
Operator, Ternary, No matching method, No matching constructor, named argument 식과 연산자
SQL, JSON, HTML_SOURCE, CSS_SOURCE, gRPC, schema 내장 언어와 schema
Annotation, EXTERNAL_, FRONTEND_STORE_CONTRACT, Partial 어노테이션과 문법 확장

단계별 오류 구분과 해결 순서는 오류와 예외를 참고하세요.