private PackedFieldDeclValue<Unresolved, Untyped> parsePackedFieldValue( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 3 && l_expr.get(1) instanceof SExpressionSymbolType) { final SExpressionSymbolType f_name = (SExpressionSymbolType) l_expr.get(1); final FieldName name = parseFieldName(f_name); final TypeExprType<Unresolved, Untyped> te = this.parseTypeExpression(l_expr.get(2)); return new PackedFieldDeclValue<>(Unresolved.get(), name, te); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (field <field-name> <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
private RecordFieldDeclValue<Unresolved, Untyped> parseRecordFieldValue( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 3 && l_expr.get(1) instanceof SExpressionSymbolType) { final SExpressionSymbolType f_name = (SExpressionSymbolType) l_expr.get(1); final FieldName name = JPRAParser.parseFieldName(f_name); final TypeExprType<Unresolved, Untyped> te = this.parseTypeExpression(l_expr.get(2)); return new RecordFieldDeclValue<>(Unresolved.get(), name, te); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (field <field-name> <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
@Override public Integer list( final SExpressionListType xs) throws IOException { if (xs.isSquare()) { w.print("["); } else { w.print("("); } final int max = xs.size(); for (int index = 0; index < max; ++index) { final SExpressionType es = xs.get(index); JSXSerializerTrivial.serializeWithWriter(es, w); if ((index + 1) < max) { w.print(" "); } } if (xs.isSquare()) { w.print("]"); } else { w.print(")"); } return Integer.valueOf(0); }
private RecordFieldDeclValue<Unresolved, Untyped> parseRecordFieldValue( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 3 && l_expr.get(1) instanceof SExpressionSymbolType) { final SExpressionSymbolType f_name = (SExpressionSymbolType) l_expr.get(1); final FieldName name = parseFieldName(f_name); final TypeExprType<Unresolved, Untyped> te = this.parseTypeExpression(l_expr.get(2)); return new RecordFieldDeclValue<>(Unresolved.get(), name, te); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (field <field-name> <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
@Override public Integer list( final SExpressionListType xs) throws IOException { if (xs.isSquare()) { w.print("["); } else { w.print("("); } final int max = xs.size(); for (int index = 0; index < max; ++index) { final SExpressionType es = xs.get(index); serializeWithWriter(es, w); if ((index + 1) < max) { w.print(" "); } } if (xs.isSquare()) { w.print("]"); } else { w.print(")"); } return Integer.valueOf(0); }
private PackedFieldDeclPaddingBits<Unresolved, Untyped> parsePackedPaddingBits( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 2) { final SizeExprType<Unresolved, Untyped> s = this.parseSizeExpression(l_expr.get(1)); return new PackedFieldDeclPaddingBits<>( JPRAParser.getExpressionLexical(l_expr), s); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (padding-bits <size-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
private RecordFieldDeclPaddingOctets<Unresolved, Untyped> parseRecordPaddingOctets( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 2) { final SizeExprType<Unresolved, Untyped> s = this.parseSizeExpression(l_expr.get(1)); return new RecordFieldDeclPaddingOctets<>( getExpressionLexical(l_expr), s); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (padding-octets <size-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
private PackedFieldDeclPaddingBits<Unresolved, Untyped> parsePackedPaddingBits( final SExpressionListType l_expr, final int e_count) throws JPRACompilerParseException { if (e_count == 2) { final SizeExprType<Unresolved, Untyped> s = this.parseSizeExpression(l_expr.get(1)); return new PackedFieldDeclPaddingBits<>( getExpressionLexical(l_expr), s); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(l_expr, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (padding-bits <size-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(l_expr, sb.toString()); } catch (final IOException x) { throw new UnreachableCodeException(x); } }
private SizeExprType<Unresolved, Untyped> parseSizeInBits( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Assertive.require(JPRAParser.SIZE_IN_BITS.equals(se.getText())); if (le.size() == 2) { return new SizeExprInBits<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (size-in-bits <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private SizeExprType<Unresolved, Untyped> parseSizeInOctets( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Assertive.require(JPRAParser.SIZE_IN_OCTETS.equals(se.getText())); if (le.size() == 2) { return new SizeExprInOctets<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (size-in-octets <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private SizeExprType<Unresolved, Untyped> parseSizeInOctets( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Preconditions.checkPreconditionV( Objects.equals(SIZE_IN_OCTETS, se.text()), "Text must be %s", SIZE_IN_OCTETS); if (le.size() == 2) { return new SizeExprInOctets<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (size-in-octets <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private StatementCommandType<Unresolved, Untyped> parseCommandType( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Assertive.require(JPRAParser.COMMAND_TYPE.equals(se.getText())); if (le.size() == 2) { return new StatementCommandType<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (:type <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private StatementCommandSize<Unresolved, Untyped> parseCommandSize( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Assertive.require(JPRAParser.COMMAND_SIZE.equals(se.getText())); if (le.size() == 2) { return new StatementCommandSize<>(this.parseSizeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (:size <size-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private StatementCommandType<Unresolved, Untyped> parseCommandType( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Preconditions.checkPreconditionV( Objects.equals(COMMAND_TYPE, se.text()), "Text must be %s", COMMAND_TYPE); if (le.size() == 2) { return new StatementCommandType<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (:type <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private SizeExprType<Unresolved, Untyped> parseSizeInBits( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Preconditions.checkPreconditionV( Objects.equals(SIZE_IN_BITS, se.text()), "Text must be %s", SIZE_IN_BITS); if (le.size() == 2) { return new SizeExprInBits<>(this.parseTypeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (size-in-bits <type-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private StatementCommandSize<Unresolved, Untyped> parseCommandSize( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Preconditions.checkPreconditionV( Objects.equals(COMMAND_SIZE, se.text()), "Text must be %s", COMMAND_SIZE); if (le.size() == 2) { return new StatementCommandSize<>(this.parseSizeExpression(le.get(1))); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (:size <size-expression>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
private TypeExprType<Unresolved, Untyped> parseTypeFloat( final SExpressionListType le, final SExpressionSymbolType se) throws JPRACompilerParseException { Assertive.require(JPRAParser.FLOAT.equals(se.getText())); if (le.size() == 2) { final SExpressionType s_expr = le.get(1); return new TypeExprFloat<>( Untyped.get(), JPRAParser.getExpressionLexical(s_expr), this.parseSizeExpression(s_expr)); } try (final ByteArrayOutputStream bao = new ByteArrayOutputStream(256)) { this.serial.serialize(le, bao); final StringBuilder sb = new StringBuilder(128); sb.append("Syntax error."); sb.append(System.lineSeparator()); sb.append(" Expected: (float <size-in-bits>)"); sb.append(System.lineSeparator()); sb.append(" Got: "); sb.append(bao.toString(StandardCharsets.UTF_8.name())); throw JPRACompilerParseException.syntaxError(le, sb.toString()); } catch (final IOException e) { throw new UnreachableCodeException(e); } }
@Override public SizeExprType<Unresolved, Untyped> list( final SExpressionListType le) throws JPRACompilerParseException { if (le.size() == 0) { throw JPRACompilerParseException.expectedNonEmptyList(le); } final SExpressionSymbolType se = JPRAParser.requireSymbol(le.get(0)); JPRAParser.checkSizeFunction(se); switch (se.getText()) { case JPRAParser.SIZE_IN_BITS: { return JPRAParser.this.parseSizeInBits(le, se); } case JPRAParser.SIZE_IN_OCTETS: { return JPRAParser.this.parseSizeInOctets(le, se); } } throw new UnreachableCodeException(); }
@Override public SizeExprType<Unresolved, Untyped> list( final SExpressionListType le) throws JPRACompilerParseException { if (le.size() == 0) { throw JPRACompilerParseException.expectedNonEmptyList(le); } final SExpressionSymbolType se = requireSymbol(le.get(0)); checkSizeFunction(se); switch (se.text()) { case SIZE_IN_BITS: { return JPRAParser.this.parseSizeInBits(le, se); } case SIZE_IN_OCTETS: { return JPRAParser.this.parseSizeInOctets(le, se); } default: throw new UnreachableCodeException(); } }
@Override public StatementType<Unresolved, Untyped> parseStatement( final SExpressionType expr) throws JPRACompilerParseException { NullCheck.notNull(expr); final SExpressionListType le = JPRAParser.requireList(expr); if (le.size() == 0) { throw JPRACompilerParseException.expectedNonEmptyList(le); } final SExpressionSymbolType se = JPRAParser.requireSymbol(le.get(0)); JPRAParser.checkKeyword(se); switch (se.getText()) { case JPRAParser.PACKAGE_BEGIN: return this.parsePackageBegin(le, se); case JPRAParser.PACKAGE_END: return this.parsePackageEnd(le, se); case JPRAParser.IMPORT: return this.parsePackageImport(le, se); case JPRAParser.RECORD: return this.parseRecord(le, se); case JPRAParser.PACKED: return this.parsePacked(le, se); case JPRAParser.COMMAND_SIZE: return this.parseCommandSize(le, se); case JPRAParser.COMMAND_TYPE: return this.parseCommandType(le, se); } throw new UnreachableCodeException(); }