Skip to content

Commit

Permalink
syntax: removing #! as a comment character.
Browse files Browse the repository at this point in the history
We don't need two types of comments and shebang (#!) is handled
natively by the lexer, so the original reason for #! is not valid.
  • Loading branch information
mrjbq7 committed Sep 10, 2015
1 parent 5fdc98c commit 59caf87
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 134 deletions.
3 changes: 1 addition & 2 deletions basis/help/cookbook/cookbook.factor
Expand Up @@ -29,7 +29,6 @@ $nl
"\"character strings\""
"{ 1 2 3 }"
"! by the way, this is a comment"
"#! and so is this"
}
{ $references
{ "Factor's syntax can be extended, the parser can be called reflectively, and the " { $link . } " word is in fact a general facility for turning almost any object into a form which can be parsed back in again. If this interests you, consult the following sections:" }
Expand Down Expand Up @@ -238,7 +237,7 @@ command-line get [
{ $code "USE: regexp" "save" }
"Now, the " { $snippet "grep.factor" } " script will start up much faster. See " { $link "images" } " for details."
{ $heading "Executable scripts" }
"It is also possible to make executable scripts. A Factor file can begin with a comment like the following:"
"It is also possible to make executable scripts. A Factor file can begin with a 'shebang' like the following:"
{ $code "#!/usr/bin/env factor" }
"If the text file is made executable, then it can be run, assuming the " { $snippet "factor" } " binary is in your " { $snippet "$PATH" } "."
{ $references
Expand Down
4 changes: 2 additions & 2 deletions basis/io/backend/unix/multiplexers/epoll/epoll.factor
Expand Up @@ -9,8 +9,8 @@ IN: io.backend.unix.multiplexers.epoll

TUPLE: epoll-mx < mx events ;

#! We read up to 256 events at a time. This is an arbitrary
#! constant...
! We read up to 256 events at a time. This is an arbitrary
! constant...
CONSTANT: max-events 256

: <epoll-mx> ( -- mx )
Expand Down
2 changes: 1 addition & 1 deletion basis/json/writer/writer.factor
Expand Up @@ -21,7 +21,7 @@ f json-escape-slashes? set-global
SYMBOL: json-escape-unicode?
f json-escape-unicode? set-global

#! Writes the object out to a stream in JSON format
! Writes the object out to a stream in JSON format
GENERIC# stream-json-print 1 ( obj stream -- )

: json-print ( obj -- )
Expand Down
2 changes: 1 addition & 1 deletion basis/peg/ebnf/ebnf-tests.factor
Expand Up @@ -516,7 +516,7 @@ foo=<foreign any-char> 'd'
[ "fail" "foo" set "foo='a'" ebnf-parser parse transform drop t ] with-scope
] unit-test

#! Tokenizer tests
! Tokenizer tests
{ V{ "a" CHAR: b } } [
"ab" [EBNF tokenizer=default foo="a" . EBNF]
] unit-test
Expand Down
10 changes: 5 additions & 5 deletions basis/peg/peg.factor
Expand Up @@ -86,11 +86,11 @@ SYMBOL: lrstack

reset-pegs

#! An entry in the table of memoized parse results
#! ast = an AST produced from the parse
#! or the symbol 'fail'
#! or a left-recursion object
#! pos = the position in the input string of this entry
! An entry in the table of memoized parse results
! ast = an AST produced from the parse
! or the symbol 'fail'
! or a left-recursion object
! pos = the position in the input string of this entry
TUPLE: memo-entry ans pos ;

TUPLE: left-recursion seed rule-id head next ;
Expand Down
4 changes: 2 additions & 2 deletions basis/tools/errors/errors.factor
Expand Up @@ -5,8 +5,8 @@ summary accessors continuations make math.parser io.styles namespaces
compiler.errors prettyprint source-files.errors.debugger command-line ;
IN: tools.errors

#! Tools for source-files.errors. Used by tools.tests and others
#! for error reporting
! Tools for source-files.errors. Used by tools.tests and others
! for error reporting

: errors. ( errors -- )
group-by-source-file sort-errors
Expand Down
1 change: 0 additions & 1 deletion core/bootstrap/syntax.factor
Expand Up @@ -10,7 +10,6 @@ IN: bootstrap.syntax
{
"!"
"\""
"#!"
"("
":"
";"
Expand Down
2 changes: 1 addition & 1 deletion core/parser/parser-tests.factor
Expand Up @@ -57,7 +57,7 @@ unit-test
unit-test

! Test EOL comments in multiline strings.
{ "Hello" } [ "#! This calls until-eol.\n\"Hello\"" eval( -- string ) ] unit-test
{ "Hello" } [ "! This calls until-eol.\n\"Hello\"" eval( -- string ) ] unit-test

{ word } [ \ f class-of ] unit-test

Expand Down
2 changes: 1 addition & 1 deletion core/sequences/sequences.factor
Expand Up @@ -278,7 +278,7 @@ INSTANCE: repetition immutable-sequence

ERROR: integer-length-expected obj ;

#! The check-length call forces partial dispatch
! The check-length call forces partial dispatch
: check-length ( n -- n )
dup integer? [ integer-length-expected ] unless ; inline

Expand Down
15 changes: 0 additions & 15 deletions core/syntax/syntax-docs.factor
Expand Up @@ -29,7 +29,6 @@ $nl
ARTICLE: "syntax-comments" "Comments"
{ $subsections
POSTPONE: !
POSTPONE: #!
} ;

ARTICLE: "syntax-immediate" "Parse time evaluation"
Expand Down Expand Up @@ -664,20 +663,6 @@ HELP: !
{ $values { "comment" "characters" } }
{ $description "Discards all input until the end of the line." } ;

{ POSTPONE: ! POSTPONE: #! } related-words

HELP: #!
{ $syntax "#!comment..." }
{ $values { "comment" "characters" } }
{ $description "Discards all input until the end of the line." }
{ $notes "To allow Unix-style \"shebang\" scripts to work as expected, " { $snippet "#!" } " is parsed as a separate token regardless of following whitespace if it appears at the beginning of a line."
{ $example
"#!/usr/bin/env/factor"
"USING: io ;"
"\"Hello world\" print"
"Hello world"
} } ;

HELP: NAN:
{ $syntax "NAN: payload" }
{ $values { "payload" "64-bit hexadecimal integer" } }
Expand Down
2 changes: 0 additions & 2 deletions core/syntax/syntax.factor
Expand Up @@ -50,8 +50,6 @@ IN: bootstrap.syntax

"!" [ lexer get next-line ] define-core-syntax

"#!" [ POSTPONE: ! ] define-core-syntax

"IN:" [ scan-token set-current-vocab ] define-core-syntax

"<PRIVATE" [ begin-private ] define-core-syntax
Expand Down
2 changes: 1 addition & 1 deletion extra/bitcoin/client/client.factor
Expand Up @@ -134,6 +134,6 @@ PRIVATE>
: stop ( -- )
"stop" { } bitcoin-request drop ;

#! requires patched bitcoind
! requires patched bitcoind
:: list-transactions ( count include-generated -- seq )
"listtransactions" { count include-generated } bitcoin-request ;
10 changes: 5 additions & 5 deletions extra/crypto/aes/aes-tests.factor
Expand Up @@ -4,7 +4,7 @@ USING: accessors byte-arrays.hex crypto.aes crypto.aes.private
crypto.aes.utils grouping kernel sequences tools.test ;
IN: crypto.aes.tests

#! fips-197 test vectors
! fips-197 test vectors
CONSTANT: plaintext HEX{ 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34 }
CONSTANT: key HEX{ 2b 7e 15 16 28 ae d2 a6 ab f7 15 88 09 cf 4f 3c }

Expand Down Expand Up @@ -145,10 +145,10 @@ CONSTANT: key HEX{ 2b 7e 15 16 28 ae d2 a6 ab f7 15 88 09 cf 4f 3c }
0x4141c382 0x9999b029 0x2d2d775a 0x0f0f111e 0xb0b0cb7b 0x5454fca8 0xbbbbd66d 0x16163a2c
} } [ t-table ] unit-test

#! NOT TESTED:
#! ui32
#! set-t
#! set-d
! NOT TESTED:
! ui32
! set-t
! set-d

{ { 0x01020304 0x02030401 0x03040102 0x04010203 } } [
{ 0x01010101 0x02020202 0x03030303 0x04040404 } shift-rows
Expand Down
50 changes: 25 additions & 25 deletions extra/crypto/aes/aes.factor
Expand Up @@ -8,8 +8,8 @@ sequences.unrolled ;
IN: crypto.aes

CONSTANT: AES_BLOCK_SIZE 16
#! FIPS-197 AES
#! input block, state, output block -- 4 32-bit words
! FIPS-197 AES
! input block, state, output block -- 4 32-bit words
CONSTANT: FIPS-197 {
{ 128 10 } ! aes-128 -- Key(4) Block(4) Rounds(10)
{ 192 12 } ! aes-192 -- Key(6) Block(4) Rounds(12)
Expand Down Expand Up @@ -61,19 +61,19 @@ CONSTANT: FIPS-197 {
256 0 <array>
dup 256 [ dup sbox nth rot set-nth ] with each-integer ;

#! applies sbox to each byte of word
! applies sbox to each byte of word
: subword ( word -- word' )
[ gb0 sbox nth ] keep [ gb1 sbox nth ] keep
[ gb2 sbox nth ] keep gb3 sbox nth >ui32 ;

#! applies inverse sbox to each byte of word
! applies inverse sbox to each byte of word
: inv-subword ( word -- word' )
[ gb0 inv-sbox nth ] keep [ gb1 inv-sbox nth ] keep
[ gb2 inv-sbox nth ] keep gb3 inv-sbox nth >ui32 ;

: rotword ( n -- n ) 8 bitroll-32 ;

#! round constants, 2^n over GF(2^8)
! round constants, 2^n over GF(2^8)
: rcon ( -- array )
{
0x00 0x01 0x02 0x04 0x08 0x10
Expand All @@ -82,12 +82,12 @@ CONSTANT: FIPS-197 {

: (rcon-nth) ( n -- rcon[n] ) rcon nth 24 shift ;

#! Galois field product related
! Galois field product related
: xtime ( x -- x' )
[ 1 shift ]
[ 0x80 bitand 0 = 0 0x1b ? ] bi bitxor 8 bits ;

#! generate t-box
! generate t-box
:: set-t ( T i -- )
i sbox nth :> a1
a1 xtime :> a2
Expand All @@ -102,7 +102,7 @@ MEMO:: t-table ( -- array )
1024 0 <array>
dup 256 [ set-t ] with each-integer ;

#! generate inverse t-box
! generate inverse t-box
:: set-d ( D i -- )
i inv-sbox nth :> a1
a1 xtime :> a2
Expand Down Expand Up @@ -132,8 +132,8 @@ MEMO:: d-table ( -- array )
: t-transform ( a0 a1 a2 a3 -- word' ) t-table (transform) ;
: d-transform ( a0 a1 a2 a3 -- word' ) d-table (transform) ;

#! key schedule
#! expands an 128/192/256 bit key into an 176/208/240 byte schedule
! key schedule
! expands an 128/192/256 bit key into an 176/208/240 byte schedule

SYMBOL: aes-expand-inner
HOOK: key-expand-round aes-expand-inner ( temp i -- temp' )
Expand Down Expand Up @@ -166,8 +166,8 @@ M: aes-256-key key-expand-round ( temp i -- temp' )
6 > [ aes-256-key ] [ aes-128-key ] if
] tri ;

#! K -- input key (byte-array), Nr -- number of rounds
#! output: sched, Nb(Nr+1) byte key schedule
! K -- input key (byte-array), Nr -- number of rounds
! output: sched, Nb(Nr+1) byte key schedule
: (expand-enc-key) ( K Nr -- sched )
[ bytes>words ] dip
[ drop (init-round) ]
Expand All @@ -182,7 +182,7 @@ TUPLE: aes-state nrounds key state ;

: <aes> ( nrounds key state -- aes-state ) \ aes-state boa ;

#! grabs the 4n...4(n+1) words of the key
! grabs the 4n...4(n+1) words of the key
: (key-at-nth-round) ( nth aes -- seq )
[ 4 * dup 4 + ] [ key>> ] bi* <slice> ;

Expand All @@ -198,18 +198,18 @@ SINGLETON: aes-decrypt
SINGLETON: aes-encrypt


#! rotates the 2nd row left by one element
#! rotates the 3rd row left by two elements
#! rotates the 4th row left by three elements
#!
#! Kind of ugly because the algorithm is specified and
#! implemented in terms of columns. This approach is very
#! efficient in terms of execution and only requires one new
#! word to implement.
#!
#! The alternative is to split into arrays of bytes, transpose,
#! rotate each row n times, transpose again, and then
#! smash them back into 4-byte words.
! rotates the 2nd row left by one element
! rotates the 3rd row left by two elements
! rotates the 4th row left by three elements
!
! Kind of ugly because the algorithm is specified and
! implemented in terms of columns. This approach is very
! efficient in terms of execution and only requires one new
! word to implement.
!
! The alternative is to split into arrays of bytes, transpose,
! rotate each row n times, transpose again, and then
! smash them back into 4-byte words.
:: (shift-rows) ( c0 c1 c2 c3 -- c0' c1' c2' c3' )
c3 gb0 c2 gb1 c1 gb2 c0 gb3 >ui32 ! c0'
c0 gb0 c3 gb1 c2 gb2 c1 gb3 >ui32 ! c1'
Expand Down
14 changes: 7 additions & 7 deletions extra/crypto/aes/utils/utils.factor
Expand Up @@ -9,13 +9,13 @@ IN: crypto.aes.utils
: gb2 ( a -- a2 ) -16 shift gb0 ; inline
: gb3 ( a -- a3 ) -24 shift gb0 ; inline

#! pack 4 bytes into 32-bit unsigned int
#! a3 is msb
! pack 4 bytes into 32-bit unsigned int
! a3 is msb
: >ui32 ( a0 a1 a2 a3 -- a )
[ 8 shift ] [ 16 shift ] [ 24 shift ] tri*
bitor bitor bitor 32 bits ;

#! inverse of ui32
! inverse of ui32
: ui32> ( word -- a0 a1 a2 a3 )
[ gb0 ] keep [ gb1 ] keep [ gb2 ] keep gb3 ; inline

Expand All @@ -35,8 +35,8 @@ IN: crypto.aes.utils
} cleave .h .h .h .h ;


#! given 4 columns, output the first diagonal, i.e.
#! C[0,0] C[1,1] C[2,2] C[3,3]
! given 4 columns, output the first diagonal, i.e.
! C[0,0] C[1,1] C[2,2] C[3,3]
: first-diag ( c0 c1 c2 c3 -- a0 a1 a2 a3 )
{ [ gb3 ] [ gb2 ] [ gb1 ] [ gb0 ] } spread ;

Expand All @@ -45,8 +45,8 @@ IN: crypto.aes.utils
: third-diag ( c0 c1 c2 c3 -- a0 a1 a2 a3 ) (4rot) second-diag ;
: fourth-diag ( c0 c1 c2 c3 -- a0 a1 a2 a3 ) (4rot) third-diag ;

#! given 4 columns, output the first reverse diagonal, i.e.
#! C[0,0] C[3,1] C[2,2] C[1,3]
! given 4 columns, output the first reverse diagonal, i.e.
! C[0,0] C[3,1] C[2,2] C[1,3]
:: (-rev) ( c0 c1 c2 c3 -- c0 c3 c2 c1 ) c0 c3 c2 c1 ; inline
: -first-diag ( c0 c1 c2 c3 -- a0 a1 a2 a3 ) (-rev) first-diag ;
: -second-diag ( c0 c1 c2 c3 -- a0 a1 a2 a3 ) (-rev) (4rot) first-diag ;
Expand Down
5 changes: 1 addition & 4 deletions extra/fjsc/fjsc.factor
Expand Up @@ -113,10 +113,7 @@ DEFER: expression-parser

: comment-parser ( -- parser )
[
[
"#!" token sp ,
"!" token sp ,
] choice* hide ,
"!" token hide ,
[
dup CHAR: \n = swap CHAR: \r = or not
] satisfy repeat0 ,
Expand Down
6 changes: 3 additions & 3 deletions extra/irc/messages/base/base.factor
Expand Up @@ -106,9 +106,9 @@ M: irc-message set-irc-command
[ ?define-irc-parameters ] [ ?define-irc-trailing ] 2bi* ;
PRIVATE>

#! SYNTAX: name string parameters ;
#! IRC: type "COMMAND" slot1 ...;
#! IRC: type "COMMAND" slot1 ... : trailing-slot;
! SYNTAX: name string parameters ;
! IRC: type "COMMAND" slot1 ...;
! IRC: type "COMMAND" slot1 ... : trailing-slot;
SYNTAX: IRC:
scan-new-class
[ scan-object register-irc-message-type ] keep
Expand Down
4 changes: 2 additions & 2 deletions extra/parser-combinators/parser-combinators.factor
Expand Up @@ -186,8 +186,8 @@ M: or-parser parse ( input parser1 -- list )

TUPLE: sp-parser p1 ;

#! Return a parser that first skips all whitespace before
#! calling the original parser.
! Return a parser that first skips all whitespace before
! calling the original parser.
C: sp sp-parser

M: sp-parser parse ( input parser -- list )
Expand Down
26 changes: 13 additions & 13 deletions extra/peg/javascript/parser/parser.factor
Expand Up @@ -4,20 +4,20 @@ USING: kernel accessors sequences
peg peg.ebnf peg.javascript.ast peg.javascript.tokenizer ;
IN: peg.javascript.parser

#! Grammar for JavaScript. Based on OMeta-JS example from:
#! http://jarrett.cs.ucla.edu/ometa-js/#JavaScript_Compiler
! Grammar for JavaScript. Based on OMeta-JS example from:
! http://jarrett.cs.ucla.edu/ometa-js/#JavaScript_Compiler

#! The interesting thing about this parser is the mixing of
#! a default and non-default tokenizer. The JavaScript tokenizer
#! removes all newlines. So when operating on tokens there is no
#! need for newline and space skipping in the grammar. But JavaScript
#! uses the newline in the 'automatic semicolon insertion' rule.
#!
#! If a statement ends in a newline, sometimes the semicolon can be
#! skipped. So we define an 'nl' rule using the default tokenizer.
#! This operates a character at a time. Using this 'nl' in the parser
#! allows us to detect newlines when we need to for the semicolon
#! insertion rule, but ignore it in all other places.
! The interesting thing about this parser is the mixing of
! a default and non-default tokenizer. The JavaScript tokenizer
! removes all newlines. So when operating on tokens there is no
! need for newline and space skipping in the grammar. But JavaScript
! uses the newline in the 'automatic semicolon insertion' rule.
!
! If a statement ends in a newline, sometimes the semicolon can be
! skipped. So we define an 'nl' rule using the default tokenizer.
! This operates a character at a time. Using this 'nl' in the parser
! allows us to detect newlines when we need to for the semicolon
! insertion rule, but ignore it in all other places.
EBNF: javascript
tokenizer = default
nl = "\r\n" | "\n"
Expand Down

0 comments on commit 59caf87

Please sign in to comment.