-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The lexer may now optionally treat ';', '#', or '%' as the start of a line comment. Fix #1
- Loading branch information
Showing
19 changed files
with
485 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
com.io7m.jsx.parser.api/src/main/java/com/io7m/jsx/api/lexer/JSXLexerComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright © 2016 <code@io7m.com> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jsx.api.lexer; | ||
|
||
/** | ||
* The available types of comments. | ||
*/ | ||
|
||
public enum JSXLexerComment | ||
{ | ||
/** | ||
* Comments start with {@code #} | ||
*/ | ||
|
||
COMMENT_HASH('#'), | ||
|
||
/** | ||
* Comments start with {@code %} | ||
*/ | ||
|
||
COMMENT_PERCENT('%'), | ||
|
||
/** | ||
* Comments start with {@code ;} | ||
*/ | ||
|
||
COMMENT_SEMICOLON(';'); | ||
|
||
private final int token; | ||
|
||
/** | ||
* @return The comment character codepoint | ||
*/ | ||
|
||
public int token() | ||
{ | ||
return this.token; | ||
} | ||
|
||
JSXLexerComment( | ||
final int in_token) | ||
{ | ||
this.token = in_token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
com.io7m.jsx.parser.api/src/main/java/com/io7m/jsx/api/tokens/TokenComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright © 2016 <code@io7m.com> http://io7m.com | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
package com.io7m.jsx.api.tokens; | ||
|
||
import com.io7m.jlexing.core.LexicalPosition; | ||
import com.io7m.jsx.api.lexer.JSXLexerComment; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A comment. | ||
*/ | ||
|
||
public final class TokenComment implements TokenType | ||
{ | ||
private final LexicalPosition<Path> lex; | ||
private final String text; | ||
private final JSXLexerComment comment; | ||
|
||
/** | ||
* @param in_lex The lexical information | ||
* @param in_comment The comment type | ||
* @param in_text The token text | ||
*/ | ||
|
||
public TokenComment( | ||
final LexicalPosition<Path> in_lex, | ||
final JSXLexerComment in_comment, | ||
final String in_text) | ||
{ | ||
this.lex = Objects.requireNonNull(in_lex, "Lexical information"); | ||
this.comment = Objects.requireNonNull(in_comment, "Comment"); | ||
this.text = Objects.requireNonNull(in_text, "Text"); | ||
} | ||
|
||
/** | ||
* @return The comment type | ||
*/ | ||
|
||
public JSXLexerComment comment() | ||
{ | ||
return this.comment; | ||
} | ||
|
||
@Override | ||
public LexicalPosition<Path> lexical() | ||
{ | ||
return this.lex; | ||
} | ||
|
||
/** | ||
* @return The text content of the token | ||
*/ | ||
|
||
public String text() | ||
{ | ||
return this.text; | ||
} | ||
|
||
@Override | ||
public <A, E extends Exception> A matchToken( | ||
final TokenMatcherType<A, E> m) | ||
throws E | ||
{ | ||
return m.comment(this); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
final StringBuilder builder = new StringBuilder(64); | ||
builder.append("[TokenComment "); | ||
builder.append(this.lex); | ||
builder.append(": "); | ||
builder.append(this.text); | ||
builder.append("]"); | ||
return Objects.requireNonNull(builder.toString(), "Result string"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.