Skip to content

Commit

Permalink
added support for inline markup, fixes #523, fixes #624 (#655)
Browse files Browse the repository at this point in the history
* added support for inline markup, fixes #523, fixes #624
  • Loading branch information
AlexHaxe authored Aug 27, 2022
1 parent 0e04dfb commit 9a9ee35
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "651ecf3",
"version": "779b005",
"resolveLibs": "scoped"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## dev branch / next version (1.x.x)

## version 1.14.0 (2022-08-27)

- Added support for inline markup, fixes [#523](https://github.com/HaxeCheckstyle/haxe-formatter/issues/523) + [#624](https://github.com/HaxeCheckstyle/haxe-formatter/issues/624) ([#655](https://github.com/HaxeCheckstyle/haxe-formatter/issues/655))

## version 1.13.1 (2022-04-26)

- Fixed conditional line ends / wrapping ([#654](https://github.com/HaxeCheckstyle/haxe-formatter/issues/654))
Expand Down
6 changes: 3 additions & 3 deletions haxe_libraries/tokentree.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:/tokentree#1.1.2" into tokentree/1.1.2/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.1.2/haxelib/src
-D tokentree=1.1.2
# @install: lix --silent download "haxelib:/tokentree#1.2.0" into tokentree/1.2.0/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.2.0/haxelib/src
-D tokentree=1.2.0
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"style"
],
"description": "A code formatter for Haxe",
"version": "1.13.1",
"releasenote": "fixed conditional line ends / wrapping, fixed whitespace after from/to with arrow functions - see CHANGELOG for details.",
"version": "1.14.0",
"releasenote": "added support for inline markup - see CHANGELOG for details.",
"contributors": [
"AlexHaxe",
"Gama11"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@haxecheckstyle/haxe-formatter",
"version": "1.13.1",
"version": "1.14.0",
"description": "A code formatter for Haxe",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions src/formatter/codedata/ParsedCode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class ParsedCode {
skipCount = 1;
case Binop(OpGte):
skipCount = 1;
case Const(CMarkup(_)):
var skipIndex = index + 1;
while (true) {
if (tokens[skipIndex].pos.min >= token.pos.max) {
break;
}
skipCount++;
skipIndex++;
}
case Const(CInt(v)):
if (v.startsWith("-")) {
skipCount = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/import.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package formatter;

#if (tokentree && !macro)
import byte.ByteData;
import haxe.io.Bytes;
import haxe.macro.Expr;
import byte.ByteData;
import haxeparser.Data;
import tokentree.TokenTree;
import tokentree.TokenTreeAccessHelper;
Expand Down
6 changes: 3 additions & 3 deletions test/TestCaseMacro.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import haxe.macro.Expr;
import haxe.macro.Context;
import haxe.io.Path;
import sys.io.File;
import haxe.macro.Context;
import haxe.macro.Expr;
import sys.FileSystem;
import sys.io.File;

class TestCaseMacro {
#if macro
Expand Down
76 changes: 76 additions & 0 deletions test/testcases/other/inline_markup.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{}

---

function inline_markup() {
<xml a=// </xml>

static var SRC =
<obj class="foo" padding-left={value} color="blue">
@exampleText("!")
<custom(55) public id="sub" custom-color="#ff0 0.5" active/>
<custom(66) if( anotherCustom )/>
</obj>;

super (<xml />);
super (<xml><xml /></xml>);

<xml></xml>;
<xml ></xml>;
<xml > </xml>;

<div some="attributes"/>;
<foo>$${x < foo ? "a" : "b"}</foo>;

<xml><xml></xml></xml>;
<xml><yml></xml>;

<xml/>;
<xml abc />;

static var SRC = <syntax-test>
for( x in arr )
<custom(x)/>
for( y in arr ) {
<custom(y)/>
<custom(y)/>
}
</syntax-test>
}

---

function inline_markup() {
<xml a=// </xml>

static var SRC = <obj class="foo" padding-left={value} color="blue">
@exampleText("!")
<custom(55) public id="sub" custom-color="#ff0 0.5" active/>
<custom(66) if( anotherCustom )/>
</obj>;

super(<xml />);
super(<xml><xml /></xml>);

<xml></xml>;
<xml ></xml>;
<xml > </xml>;

<div some="attributes"/>;
<foo>$${x < foo ? "a" : "b"}</foo>;

<xml><xml></xml></xml>;
<xml><yml></xml>;

<xml/>;
<xml abc />;

static var SRC = <syntax-test>
for( x in arr )
<custom(x)/>
for( y in arr ) {
<custom(y)/>
<custom(y)/>
}
</syntax-test>
}
50 changes: 50 additions & 0 deletions test/testcases/other/issue_523_inline_markup.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"indentation": {
"character": " "
},
"sameLine": {
"ifBody": "keep",
"elseIf": "keep",
"elseBody": "keep",
"forBody": "keep",
"whileBody": "keep"
}
}

---

class Test {
function main() {
final user = "usr";

XmlTools.toString(
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:foo="https://foo.bar/baz">
<soap:Header>
<foo:Foo>
<foo:User>${user}</foo:User>
</foo:Foo>
</soap:Header>
<soap:Body>
</soap:Body>
</soap:Envelope>
);
}
}

---

class Test {
function main() {
final user = "usr";

XmlTools.toString(<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:foo="https://foo.bar/baz">
<soap:Header>
<foo:Foo>
<foo:User>${user}</foo:User>
</foo:Foo>
</soap:Header>
<soap:Body>
</soap:Body>
</soap:Envelope>);
}
}
33 changes: 33 additions & 0 deletions test/testcases/other/issue_624_inline_markup.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{}

---

// https://heaps.io/documentation/domkit.html
class SampleView extends h2d.Flow implements h2d.domkit.Object {

static var SRC =
<sample-view layout="vertical">
Hello World!
<bitmap src={tile} public id="mybmp"/>
</sample-view>

public function new(tile:h2d.Tile,?parent) {
super(parent);
initComponent();
}
}

---

// https://heaps.io/documentation/domkit.html
class SampleView extends h2d.Flow implements h2d.domkit.Object {
static var SRC = <sample-view layout="vertical">
Hello World!
<bitmap src={tile} public id="mybmp"/>
</sample-view>

public function new(tile:h2d.Tile, ?parent) {
super(parent);
initComponent();
}
}

0 comments on commit 9a9ee35

Please sign in to comment.